[FFmpeg-devel] [PATCH] Implement in lavc a flag which makes avcodec_open() to choose the best framerate

Stefano Sabatini stefano.sabatini-lala
Sun Sep 21 12:52:57 CEST 2008


On date Saturday 2008-09-20 23:16:11 +0200, Michael Niedermayer encoded:
> On Sat, Sep 20, 2008 at 06:38:22PM +0200, Stefano Sabatini wrote:
> > On date Friday 2008-09-19 01:13:51 +0200, Michael Niedermayer encoded:
> > [...]
> > > This implementation isnt exact, it in many corner cases will not
> > > return the correct element.
> > > Examples would be, when it is farther away than INT_MAX
> > > another example may be a list of
> > > 1/INT_MAX, 1/(INT_MAX-1), ...
> > > compared to INT_MAX
> > > your code would fail to be to seperate them
> > 
> > As for the second problem, in that case the error will be the same for
> > all that values, but it is still possible to understand which is
> > nearest to the value if they are both greater or lesser than q.
> > 
> > q= target value
> > q1= nearest value already found
> > q2= new value to check
> > 
> > 1) q1 ...  q2  ... q
> > q > q1 && q2 > q1 => choose q2
> > 
> > 2) q ... q2 ... q1
> > q < q1 && q2 < q1 => choose q2
> > 
> > Both conditions are catched by the expression
> > cmp(q1, q) * cmp(q2, q1) == 1
> > 
> > In the case:
> > 3) q1 ... q ... q2
> > and
> > 4) q2 ... q ... q1
> > 
> > always q2 is choosen.
> > 
> > For these last two cases I'm not sure if we can do something better.
> 
> iam not sure if its worth it but it surely can be done, one way is ...
> 
> to decide
> n1/d1 ... N/D ... n2/d2
> 
> you have to decide on which side of (n1/d1 + n2/d2)/2,  N/D is.
> 
> (n1/d1 + n2/d2)/2 = (n1d2 + n2d1)/(2d1d2) = A/B
> A and B here are 64bit
> 
> To know which of the 2 points is closer we need to awnser A/B < N/D
> 
> which is the same as
> 
> (AD)/B < N
> 
> (AD)/B can be calculated with av_rescale2() and is exact for our purpose
> when the correct rounding mode is used.
> 
> But as said, iam not sure if this is worth it, in practice the simple
> variant is likely sufficient, it mostly depends on how ugly above would
> look in C ...

It's still looks nice if we introduce a new function, like in the
patch below.

Regards.
-- 
FFmpeg = Fostering Frightening Mythic Portable Elaborated Guru
-------------- next part --------------
A non-text attachment was scrubbed...
Name: implement-nearest-q-03.patch
Type: text/x-diff
Size: 3575 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080921/017d3f78/attachment.patch>



More information about the ffmpeg-devel mailing list