<div dir="ltr">Hi,<div><br></div><div>it looks like all the "missing" frames are duplicated by the ffmpeg.</div><div>Interestingly it even does it with the "-vsync vfr" oprion.</div><div>I tried using "-vsync passthrough", but I got an error:</div><div><br></div><div>[mjpeg @ 0x2bb1720] Invalid pts (0) <= last (0)<br></div><div><br></div><div>which doesn't make too much sense.</div><div>With png output I get similar errors:</div><div><br></div><div><div>[image2 @ 0x2e5aa80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 8 >= 8</div><div>[image2 @ 0x2e5aa80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 11 >= 11</div><div>[image2 @ 0x2e5aa80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 23 >= 23</div><div>[image2 @ 0x2e5aa80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 50 >= 50</div><div>[image2 @ 0x2e5aa80] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 64 >= 64</div></div><div><br></div><div>But at least it continues the decoding.</div><div><br></div><div>I think the error texts are silly, but otherwise I found the solution to my problem, so thanks for listening. </div><div><br></div><div>Best,</div><div>Tr3wory</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 13, 2015 at 11:05 AM, Tr3wory <span dir="ltr"><<a href="mailto:tr3w@freemail.hu" target="_blank">tr3w@freemail.hu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>My code currently does nothing other than decode the packets to AVFrame-s and count the number of decoded frames.</div><div>Something like this (I removed the error checking and other not interesting stuff):</div><div><br></div><div><div><div>    av_register_all();</div><div><br></div><div>    AVFormatContext* formatCtx = NULL;</div><div><br></div><div>    avformat_open_input(&formatCtx,filename,NULL,NULL);</div><div><br></div><div>    avformat_find_stream_info(formatCtx,NULL);</div><div><br></div><div>    // Find the first video stream</div><div>    int videoStreamIdx = -1;</div><div>    for (int i = 0; i < formatCtx->nb_streams; ++i)</div><div>        if (formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {</div><div>            videoStreamIdx = i;</div><div>            break;</div><div>        }</div><div><br></div><div>    if (videoStreamIdx == -1) { /* Error handling */ }</div><div><br></div><div>    AVCodec* codec = avcodec_find_decoder(formatCtx->streams[videoStreamIdx]->codec->codec_id);</div><div><br></div><div>    AVCodecContext* codecCtx = avcodec_alloc_context3(codec);</div><div><br></div><div>    avcodec_copy_context(codecCtx, formatCtx->streams[videoStreamIdx]->codec);</div><div><br></div><div>    avcodec_open2(codecCtx,codec,NULL);</div><div><br></div><div>    AVPacket packet;</div><div>    AVFrame* frame = av_frame_alloc();</div><div><br></div><div>    int avError;</div><div>    int frameNo = 0;</div><div>    while ((avError = av_read_frame(formatCtx, &packet)) >= 0) {</div><div><br></div><div>        if (packet.stream_index == videoStreamIdx) {</div><div>            int isFrameFinished = 0;</div><div>            avcodec_decode_video2(codecCtx,frame,&isFrameFinished,&packet);</div><div><br></div><div>            if (isFrameFinished) {</div><div>                ++frameNo;</div><div>            }</div><div>        }</div><div>        av_free_packet(&packet);</div><div>    }</div><div><br></div><div>    if (codec->capabilities & AV_CODEC_CAP_DELAY) {</div><div>        // Flush codec buffer</div><div>        av_init_packet(&packet);</div><div>        packet.data = NULL;</div><div>        packet.size = 0;</div><div><br></div><div>        int isFrameFinished = 0;</div><div>        while ((avcodec_decode_video2(codecCtx,frame,&isFrameFinished,&packet) >= 0) && isFrameFinished) {</div><div>                ++frameNo;</div><div>        }</div><div>        av_free_packet(&packet);</div><div>    }</div><div><br></div><div>    avcodec_free_context(&codecCtx);</div><div>    avformat_close_input(&formatCtx);</div></div></div><div><br></div><div>This code gives me 21239 frames.</div><div><br></div><div>I called ffmpeg like this:<br>~/BUILD/ffmpeg/bin/ffmpeg -i testvideo.mp4 images/frame-%05d.jpeg<br></div><div><br></div><div>This produced 21839 jpeg images.</div><div><br></div><div>Versions:</div><div><div>ffmpeg version N-75147-g9d742d2 Copyright (c) 2000-2015 the FFmpeg developers</div><div>  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)</div><div>  configuration: --prefix='~/BUILD/ffmpeg'</div><div>  libavutil      55.  1.100 / 55.  1.100</div><div>  libavcodec     57.  1.100 / 57.  1.100</div><div>  libavformat    57.  0.100 / 57.  0.100</div><div>  libavdevice    57.  0.100 / 57.  0.100</div><div>  libavfilter     6.  1.100 /  6.  1.100</div><div>  libswscale      4.  0.100 /  4.  0.100</div><div>  libswresample   2.  0.100 /  2.  0.100</div></div><div><br></div><div>Any thoughts?</div><div><br></div><div>Best,</div><div>Tr3wory</div><div><div class="h5"><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 12, 2015 at 2:44 PM, Mohamed Moanis <span dir="ltr"><<a href="mailto:mohamed_moanis@outlook.com" target="_blank">mohamed_moanis@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div><div dir="ltr"><br><div>>From: <a href="mailto:tr3w@freemail.hu" target="_blank">tr3w@freemail.hu</a><br>>Date: Sat, 12 Sep 2015 13:31:27 +0200<br>>To: <a href="mailto:libav-user@ffmpeg.org" target="_blank">libav-user@ffmpeg.org</a><br>>Subject: [Libav-user] Fwd: Frame number mismatch<br>><br><div dir="ltr"><div><div><div><div dir="ltr"><span style="font-size:12pt">></span>Hi all!<div>></div><div><span style="font-size:12pt">></span>I'm unfortunate enough that I have a steady stream of midly corrupted/badly encoded mp4/h264 videos what I need to process. I <span style="font-size:12pt">></span><span style="font-size:12pt">wrote a simple program based on some tutorial on the internet which reads all the video frames using av_read_frame and </span><span style="font-size:12pt">></span><span style="font-size:12pt">avcodec_decode_video2, I even flush the internal buffer of the decoder with some empty packets in the end. (No errors in the </span><span style="font-size:12pt">></span><span style="font-size:12pt">process, no corrupted frames...)</span></div><div>></div><div><span style="font-size:12pt">></span>It looks good and well until I run the ffmpeg standalone tool (compiled from the same source three) with jpg output, which <span style="font-size:12pt">></span><span style="font-size:12pt">produces 600 more frames than my frame reader (from a 24k frame long video). (All frames look valid, but maybe duplicated...)</span></div><div>></div><div><span style="font-size:12pt">></span>What ffmpeg does differently? Did I miss something? (Like a flag in AVFrame which tells me to duplicate, or some options in the <span style="font-size:12pt">></span><span style="font-size:12pt">decoder?)</span></div><div>></div><div><span style="font-size:12pt">></span>Thanks for your help!</div><div>></div><div><span style="font-size:12pt">></span>Best,</div><div><span style="font-size:12pt">></span>Tr3wory</div></div>
</div></div></div>What your frame reader does, does it just write frames as jpegs?</div><div dir="ltr">and what are the arguments to ffmpeg!</div><div dir="ltr"><br></div><div dir="ltr">please give more explanation for the problem</div>
<br>_______________________________________________
Libav-user mailing list
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a></div>                                     </div></div>
<br>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>