From: Michael Niedermayer <[email protected]>

---

refreshed after recent avconv changes

 avconv.c |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/avconv.c b/avconv.c
index 787ca9c..6805366 100644
--- a/avconv.c
+++ b/avconv.c
@@ -1720,21 +1720,31 @@ static int transcode_audio(InputStream *ist, AVPacket 
*pkt, int *got_output)
     return ret;
 }
 
-static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, 
int64_t *pkt_pts)
+static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output,
+                           int64_t *pkt_pts, int64_t *pkt_dts)
 {
     AVFrame *decoded_frame, *filtered_frame = NULL;
     void *buffer_to_free = NULL;
     int i, ret = 0;
     float quality;
+    int64_t tmp_pts = AV_NOPTS_VALUE;
 #if CONFIG_AVFILTER
     int frame_available = 1;
 #endif
 
     if (!(decoded_frame = avcodec_alloc_frame()))
         return AVERROR(ENOMEM);
-    pkt->pts  = *pkt_pts;
-    pkt->dts  = ist->pts;
-    *pkt_pts  = AV_NOPTS_VALUE;
+
+    pkt->pts = *pkt_pts;
+    pkt->dts = *pkt_dts;
+    *pkt_pts = AV_NOPTS_VALUE;
+
+    if (*pkt_dts != AV_NOPTS_VALUE && ist->st->codec->time_base.num != 0) {
+        int ticks = ist->st->parser ? ist->st->parser->repeat_pict+1 : 
ist->st->codec->ticks_per_frame;
+        *pkt_dts += ((int64_t)AV_TIME_BASE * ist->st->codec->time_base.num
+                      * ticks) / ist->st->codec->time_base.den;
+    } else
+        *pkt_dts = AV_NOPTS_VALUE;
 
     ret = avcodec_decode_video2(ist->st->codec,
                                 decoded_frame, got_output, pkt);
@@ -1747,8 +1757,11 @@ static int transcode_video(InputStream *ist, AVPacket 
*pkt, int *got_output, int
         av_freep(&decoded_frame);
         return ret;
     }
-    ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, 
decoded_frame->pkt_pts,
-                                                 decoded_frame->pkt_dts);
+    tmp_pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts,
+                                decoded_frame->pkt_dts);
+    if (tmp_pts != AV_NOPTS_VALUE)
+        ist->next_pts = ist->pts = tmp_pts;
+
     if (pkt->duration)
         ist->next_pts += av_rescale_q(pkt->duration, ist->st->time_base, 
AV_TIME_BASE_Q);
     else if (ist->st->codec->time_base.num != 0) {
@@ -1847,6 +1860,7 @@ static int output_packet(InputStream *ist,
 {
     int i;
     int got_output;
+    int64_t pkt_dts = AV_NOPTS_VALUE;
     int64_t pkt_pts = AV_NOPTS_VALUE;
     AVPacket avpkt;
 
@@ -1863,9 +1877,14 @@ static int output_packet(InputStream *ist,
         avpkt = *pkt;
     }
 
-    if(pkt->dts != AV_NOPTS_VALUE)
-        ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, 
AV_TIME_BASE_Q);
-    if(pkt->pts != AV_NOPTS_VALUE)
+    if (pkt->dts != AV_NOPTS_VALUE) {
+        if (ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO
+            || !ist->decoding_needed)
+            ist->next_pts = ist->pts =
+                  av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+        pkt_dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
+    }
+    if (pkt->pts != AV_NOPTS_VALUE)
         pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q);
 
     //while we have more to decode or while the decoder did output something 
on EOF
@@ -1886,7 +1905,8 @@ static int output_packet(InputStream *ist,
             ret = transcode_audio    (ist, &avpkt, &got_output);
             break;
         case AVMEDIA_TYPE_VIDEO:
-            ret = transcode_video    (ist, &avpkt, &got_output, &pkt_pts);
+            ret = transcode_video    (ist, &avpkt, &got_output, &pkt_pts,
+                                      &pkt_dts);
             break;
         case AVMEDIA_TYPE_SUBTITLE:
             ret = transcode_subtitles(ist, &avpkt, &got_output);
-- 
1.7.8

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to