[Libav-user] Fwd: Frame number mismatch

Tr3wory tr3w at freemail.hu
Mon Sep 14 14:28:37 CEST 2015


Hi,

it looks like all the "missing" frames are duplicated by the ffmpeg.
Interestingly it even does it with the "-vsync vfr" oprion.
I tried using "-vsync passthrough", but I got an error:

[mjpeg @ 0x2bb1720] Invalid pts (0) <= last (0)

which doesn't make too much sense.
With png output I get similar errors:

[image2 @ 0x2e5aa80] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 8 >= 8
[image2 @ 0x2e5aa80] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 11 >= 11
[image2 @ 0x2e5aa80] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 23 >= 23
[image2 @ 0x2e5aa80] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 50 >= 50
[image2 @ 0x2e5aa80] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 64 >= 64

But at least it continues the decoding.

I think the error texts are silly, but otherwise I found the solution to my
problem, so thanks for listening.

Best,
Tr3wory



On Sun, Sep 13, 2015 at 11:05 AM, Tr3wory <tr3w at freemail.hu> wrote:

> Hi,
>
> My code currently does nothing other than decode the packets to AVFrame-s
> and count the number of decoded frames.
> Something like this (I removed the error checking and other not
> interesting stuff):
>
>     av_register_all();
>
>     AVFormatContext* formatCtx = NULL;
>
>     avformat_open_input(&formatCtx,filename,NULL,NULL);
>
>     avformat_find_stream_info(formatCtx,NULL);
>
>     // Find the first video stream
>     int videoStreamIdx = -1;
>     for (int i = 0; i < formatCtx->nb_streams; ++i)
>         if (formatCtx->streams[i]->codec->codec_type ==
> AVMEDIA_TYPE_VIDEO) {
>             videoStreamIdx = i;
>             break;
>         }
>
>     if (videoStreamIdx == -1) { /* Error handling */ }
>
>     AVCodec* codec =
> avcodec_find_decoder(formatCtx->streams[videoStreamIdx]->codec->codec_id);
>
>     AVCodecContext* codecCtx = avcodec_alloc_context3(codec);
>
>     avcodec_copy_context(codecCtx,
> formatCtx->streams[videoStreamIdx]->codec);
>
>     avcodec_open2(codecCtx,codec,NULL);
>
>     AVPacket packet;
>     AVFrame* frame = av_frame_alloc();
>
>     int avError;
>     int frameNo = 0;
>     while ((avError = av_read_frame(formatCtx, &packet)) >= 0) {
>
>         if (packet.stream_index == videoStreamIdx) {
>             int isFrameFinished = 0;
>             avcodec_decode_video2(codecCtx,frame,&isFrameFinished,&packet);
>
>             if (isFrameFinished) {
>                 ++frameNo;
>             }
>         }
>         av_free_packet(&packet);
>     }
>
>     if (codec->capabilities & AV_CODEC_CAP_DELAY) {
>         // Flush codec buffer
>         av_init_packet(&packet);
>         packet.data = NULL;
>         packet.size = 0;
>
>         int isFrameFinished = 0;
>         while
> ((avcodec_decode_video2(codecCtx,frame,&isFrameFinished,&packet) >= 0) &&
> isFrameFinished) {
>                 ++frameNo;
>         }
>         av_free_packet(&packet);
>     }
>
>     avcodec_free_context(&codecCtx);
>     avformat_close_input(&formatCtx);
>
> This code gives me 21239 frames.
>
> I called ffmpeg like this:
> ~/BUILD/ffmpeg/bin/ffmpeg -i testvideo.mp4 images/frame-%05d.jpeg
>
> This produced 21839 jpeg images.
>
> Versions:
> ffmpeg version N-75147-g9d742d2 Copyright (c) 2000-2015 the FFmpeg
> developers
>   built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
>   configuration: --prefix='~/BUILD/ffmpeg'
>   libavutil      55.  1.100 / 55.  1.100
>   libavcodec     57.  1.100 / 57.  1.100
>   libavformat    57.  0.100 / 57.  0.100
>   libavdevice    57.  0.100 / 57.  0.100
>   libavfilter     6.  1.100 /  6.  1.100
>   libswscale      4.  0.100 /  4.  0.100
>   libswresample   2.  0.100 /  2.  0.100
>
> Any thoughts?
>
> Best,
> Tr3wory
>
>
> On Sat, Sep 12, 2015 at 2:44 PM, Mohamed Moanis <
> mohamed_moanis at outlook.com> wrote:
>
>>
>> >From: tr3w at freemail.hu
>> >Date: Sat, 12 Sep 2015 13:31:27 +0200
>> >To: libav-user at ffmpeg.org
>> >Subject: [Libav-user] Fwd: Frame number mismatch
>> >
>> >Hi all!
>> >
>> >I'm unfortunate enough that I have a steady stream of midly
>> corrupted/badly encoded mp4/h264 videos what I need to process. I >wrote
>> a simple program based on some tutorial on the internet which reads all the
>> video frames using av_read_frame and >avcodec_decode_video2, I even
>> flush the internal buffer of the decoder with some empty packets in the
>> end. (No errors in the >process, no corrupted frames...)
>> >
>> >It looks good and well until I run the ffmpeg standalone tool (compiled
>> from the same source three) with jpg output, which >produces 600 more
>> frames than my frame reader (from a 24k frame long video). (All frames look
>> valid, but maybe duplicated...)
>> >
>> >What ffmpeg does differently? Did I miss something? (Like a flag in
>> AVFrame which tells me to duplicate, or some options in the >decoder?)
>> >
>> >Thanks for your help!
>> >
>> >Best,
>> >Tr3wory
>> What your frame reader does, does it just write frames as jpegs?
>> and what are the arguments to ffmpeg!
>>
>> please give more explanation for the problem
>>
>> _______________________________________________ Libav-user mailing list
>> Libav-user at ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20150914/d2946691/attachment.html>


More information about the Libav-user mailing list