[FFmpeg-user] Problems getting the very last frames of videos using av_read_frame

Peter Rennert p.rennert at cs.ucl.ac.uk
Fri Oct 31 06:39:38 CET 2014


I had a close look through

https://www.ffmpeg.org/doxygen/2.1/doc_2examples_2demuxing_8c-example.html

and compared it to what the wrapper is doing. They are pretty similar, 
the biggest difference I could spot so far was in

https://bitbucket.org/groakat/ffvideo/src/b45143f755ac8da1e6ed4f52a11217af1e093d54/ffvideo/ffvideo.pyx?at=default#cl-353

Which means whenever the wrapper starts looping over the frames, it 
starts using av_seek_frame, rather than just to open the video file again.

I noticed a while ago that when doing an accurate seek (in 
get_frame_at_pts of the wrapper) the dts of the stream has an offset, 
therefore I needed to put this hack in, to make the seek precise:

https://bitbucket.org/groakat/ffvideo/src/b45143f755ac8da1e6ed4f52a11217af1e093d54/ffvideo/ffvideo.pyx?at=default#cl-345

The number of frames missing at the end seems to coincide with the +9 
that I hacked into that loop to account for the offset I observed. Back 
then I could not make out where that offset comes from. Now when I read 
the code and the ffmpeg documentation again, I still cannot find why 
there should be an offset. On the other hand, av_read_frame should not 
care about that at all, because it should just return the next frame in 
the stream, regardless of any dts, no?

Anyway, I will continue the bug hunt at Monday. Any suggestions are 
still welcome :)

On 31/10/14 01:09, Peter Rennert wrote:
> I rebuild ffmpeg and cleared the issues with
>
> WARNING: library configuration mismatch
>
> (there was indeed libav installed because of a dependency..)
>
> After rebuilding the wrapper, the issue is exactly the same.
>
>
> On 30/10/14 13:48, Peter Rennert wrote:
>> Hi Moritz,
>>
>> Thanks for looking into this.
>>
>> On 30/10/14 13:40, Moritz Barsnick wrote:
>>> On Thu, Oct 30, 2014 at 12:15:34 +0000, Peter Rennert wrote:
>>>
>>>> except for the last frames. It seems as av_read_frame only reads until
>>>> the last key frame and does not go beyond it.
>>> Do you ever see "Unable to decode video picture: %d" from
>>> https://bitbucket.org/groakat/ffvideo/src/b45143f755ac8da1e6ed4f52a11217af1e093d54/ffvideo/ffvideo.pyx?at=default#cl-233 
>>>
>>> ???
>> No, I never saw that Error being raised.
>>
>>>
>>> There's an example in ffmpeg's doc/ directory, named
>>> demuxing_decoding.c, which uses your described av_read_frame() loop,
>>> and succeeds at reading all 1000 frames.
>> Thanks for that lead. I will follow that up and report the results 
>> later.
>>
>>>
>>> So the issue is probably somewhere in the python wrapper.
>>>
>>>> ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
>>>>     built on Apr  9 2014 16:32:16 with gcc 4.8 (Ubuntu/Linaro 
>>>> 4.8.1-10ubuntu9)
>>> This is quite a bit too old to gain support on this list. :)
>> I will rebuild ffmpeg, and see if it persists.
>>
>>>
>>>>     WARNING: library configuration mismatch
>>> and is apparently using libraries from a different build, which is not
>>> a good idea.
>>>
>>> The first suggestion would be to build lastest git, and ensure you're
>>> not using "stale" libraries from older installs.
>>>
>>> (I don't have enough knowledge to tell you more about how to use libav
>>> properly, I only know the examples. Anyway, there's a separate list for
>>> libav issues: https://ffmpeg.org/mailman/listinfo/libav-user )
>> To my knowledge I am not using libav. At least when I last checked ;).
>>
>>
>>> Moritz
>>> _______________________________________________
>>> ffmpeg-user mailing list
>>> ffmpeg-user at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
>> _______________________________________________
>> ffmpeg-user mailing list
>> ffmpeg-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user


On 31/10/14 01:09, Peter Rennert wrote:
> I rebuild ffmpeg and cleared the issues with
>
> WARNING: library configuration mismatch
>
> (there was indeed libav installed because of a dependency..)
>
> After rebuilding the wrapper, the issue is exactly the same.
>
>
> On 30/10/14 13:48, Peter Rennert wrote:
>> Hi Moritz,
>>
>> Thanks for looking into this.
>>
>> On 30/10/14 13:40, Moritz Barsnick wrote:
>>> On Thu, Oct 30, 2014 at 12:15:34 +0000, Peter Rennert wrote:
>>>
>>>> except for the last frames. It seems as av_read_frame only reads until
>>>> the last key frame and does not go beyond it.
>>> Do you ever see "Unable to decode video picture: %d" from
>>> https://bitbucket.org/groakat/ffvideo/src/b45143f755ac8da1e6ed4f52a11217af1e093d54/ffvideo/ffvideo.pyx?at=default#cl-233 
>>>
>>> ???
>> No, I never saw that Error being raised.
>>
>>>
>>> There's an example in ffmpeg's doc/ directory, named
>>> demuxing_decoding.c, which uses your described av_read_frame() loop,
>>> and succeeds at reading all 1000 frames.
>> Thanks for that lead. I will follow that up and report the results 
>> later.
>>
>>>
>>> So the issue is probably somewhere in the python wrapper.
>>>
>>>> ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
>>>>     built on Apr  9 2014 16:32:16 with gcc 4.8 (Ubuntu/Linaro 
>>>> 4.8.1-10ubuntu9)
>>> This is quite a bit too old to gain support on this list. :)
>> I will rebuild ffmpeg, and see if it persists.
>>
>>>
>>>>     WARNING: library configuration mismatch
>>> and is apparently using libraries from a different build, which is not
>>> a good idea.
>>>
>>> The first suggestion would be to build lastest git, and ensure you're
>>> not using "stale" libraries from older installs.
>>>
>>> (I don't have enough knowledge to tell you more about how to use libav
>>> properly, I only know the examples. Anyway, there's a separate list for
>>> libav issues: https://ffmpeg.org/mailman/listinfo/libav-user )
>> To my knowledge I am not using libav. At least when I last checked ;).
>>
>>
>>> Moritz
>>> _______________________________________________
>>> ffmpeg-user mailing list
>>> ffmpeg-user at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
>> _______________________________________________
>> ffmpeg-user mailing list
>> ffmpeg-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user



More information about the ffmpeg-user mailing list