[FFmpeg-devel] Patch: fix timestamp handling problem

Jeff 163jogh at 163.com
Sun Apr 9 15:53:27 EEST 2017


Hi all,


I find that the latest ffmpeg could not handle timestamp propertly for some inputs.


After some digging, I finally catch first exception in commit 8f6f232. The problem
was introduced by  applying the new decode API -- avcodec_send_packet() and
avcodec_receive_frame().


Since the new decoding flow detect input ending by the return value of 
avcodec_receive_frame(). It should restore the stream dts/pts after last call
to avcodec_receive_frame(), that last call return a null output and break the
while loop. Otherwise, stream dts/pts would be set to next_dts/next_pts.


Bellow is the patch, which is also attached.
================================



From c9e552ebadf20acfd6296fc760ac8b825cc9b1fd Mon Sep 17 00:00:00 2001

From: "jeff.zheng" <163jogh at 163.com>

Date: Sun, 9 Apr 2017 19:47:59 +0800

Subject: [PATCH] ffmpeg: fix timestamp handling problem




The problem was introduced in commit 8f6f232 by appling the new

decode API. Stream dts/pts should be set to the value of last

decoded packet of the stream rather than next_dts/next_pts.

---

 ffmpeg.c | 6 ++++++

 1 file changed, 6 insertions(+)




diff --git a/ffmpeg.c b/ffmpeg.c

index e4b94b2fa0..66156b5394 100644

--- a/ffmpeg.c

+++ b/ffmpeg.c

@@ -2615,12 +2615,16 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo

             ist->next_pts = ist->pts = ist->dts;

     }

 

+    int64_t last_pts = ist->pts;

+    int64_t last_dts = ist->dts;

     // while we have more to decode or while the decoder did output something on EOF

     while (ist->decoding_needed) {

         int64_t duration = 0;

         int got_output = 0;

         int decode_failed = 0;

 

+        last_pts = ist->pts;

+        last_dts = ist->dts;

         ist->pts = ist->next_pts;

         ist->dts = ist->next_dts;

 

@@ -2699,6 +2703,8 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo

 

         repeating = 1;

     }

+    ist->pts = last_pts;

+    ist->dts = last_dts;

 

     /* after flushing, send an EOF on all the filter inputs attached to the stream */

     /* except when looping we need to flush but not to send an EOF */

-- 

2.11.0 (Apple Git-81)




================================




Thanks!

Jeff.Zheng
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-ffmpeg-fix-timestamp-handling-problem.patch
Type: application/octet-stream
Size: 1501 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170409/18b75caf/attachment.obj>


More information about the ffmpeg-devel mailing list