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

Stefano Sabatini stefano.sabatini-lala
Sat Sep 20 18:38:22 CEST 2008


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.

Surprisingly, I discovered that this mechanism also addresses the
first problem, indeed if we have more than one value whose distance is
greater than MAX_INT, this will correspond to case 1) or 2), so we're
able to understand which of the values is nearest to q.

Attached patch.

Regards.
-- 
FFmpeg = Fantastic and Frenzy Mean Pitiless Exuberant Gem
-------------- next part --------------
A non-text attachment was scrubbed...
Name: implement-nearest-q-02.patch
Type: text/x-diff
Size: 2506 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080920/0399eeaa/attachment.patch>



More information about the ffmpeg-devel mailing list