>From 7c137642c591bd6179b3a924a7f5142f8d634828 Mon Sep 17 00:00:00 2001
From: Stefano Sabatini <stefasab@gmail.com>
Date: Fri, 20 Jan 2012 17:06:26 +0100
Subject: [PATCH] ffmpeg.c: use timestamp.h utilities

---
 ffmpeg.c |   37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 89f5893..b3179c1 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -23,6 +23,8 @@
  * multimedia converter based on the FFmpeg libraries
  */
 
+#define DEBUG_TS
+
 #include "config.h"
 #include <ctype.h>
 #include <string.h>
@@ -49,6 +51,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/libm.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/timestamp.h"
 #include "libavformat/os_support.h"
 #include "libswresample/swresample.h"
 
@@ -1091,6 +1094,15 @@ static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
         av_free_packet(&pkt);
     }
 
+#ifdef DEBUG_TS
+    {
+            char buf1[AV_TS_MAX_STRING_SIZE], buf2[AV_TS_MAX_STRING_SIZE];
+            fprintf(stderr, "encoder -> type:audio");
+            fprintf(stderr, " pkt_pts:%s pkt_pts_time:%s", av_ts2str(buf1, pkt.pts), av_ts2timestr(buf2, pkt.pts, &ost->st->time_base));
+            fprintf(stderr, " pkt_dts:%s pkt_dts_time:%s\n", av_ts2str(buf1, pkt.dts), av_ts2timestr(buf2, pkt.dts, &ost->st->time_base));
+    }
+#endif
+
     if (frame)
         ost->sync_opts += frame->nb_samples;
 
@@ -1560,10 +1572,15 @@ static void do_video_out(AVFormatContext *s,
                 pkt.size = ret;
                 if (enc->coded_frame->pts != AV_NOPTS_VALUE)
                     pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
-/*av_log(NULL, AV_LOG_DEBUG, "encoder -> %"PRId64"/%"PRId64"\n",
-   pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1,
-   pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/
 
+#ifdef DEBUG_TS
+            {
+                char buf1[AV_TS_MAX_STRING_SIZE], buf2[AV_TS_MAX_STRING_SIZE];
+                fprintf(stderr, "encoder -> type:video");
+                fprintf(stderr, " pkt_pts:%s pkt_pts_time:%s", av_ts2str(buf1, pkt.pts), av_ts2timestr(buf2, pkt.pts, &ost->st->time_base));
+                fprintf(stderr, " pkt_dts:%s pkt_dts_time:%s\n", av_ts2str(buf1, pkt.dts), av_ts2timestr(buf2, pkt.dts, &ost->st->time_base));
+            }
+#endif
                 if (enc->coded_frame->key_frame)
                     pkt.flags |= AV_PKT_FLAG_KEY;
                 write_frame(s, &pkt, ost);
@@ -3012,10 +3029,16 @@ static int transcode(OutputFile *output_files, int nb_output_files,
         if (pkt.dts != AV_NOPTS_VALUE)
             pkt.dts *= ist->ts_scale;
 
-        //fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n",
-        //        ist->next_pts,
-        //        pkt.dts, input_files[ist->file_index].ts_offset,
-        //        ist->st->codec->codec_type);
+#ifdef DEBUG_TS
+        {
+            char buf1[AV_TS_MAX_STRING_SIZE], buf2[AV_TS_MAX_STRING_SIZE];
+            fprintf(stderr, "demuxer -> ist_index:%d type:%s", ist_index, av_get_media_type_string(ist->st->codec->codec_type));
+            fprintf(stderr, " next_pts:%s next_pts_time:%s", av_ts2str(buf1, ist->next_pts), av_ts2timestr(buf2, ist->next_pts, &ist->st->time_base));
+            fprintf(stderr, " pkt_pts:%s pkt_pts_time:%s",   av_ts2str(buf1, pkt.pts), av_ts2timestr(buf2, pkt.pts, &ist->st->time_base));
+            fprintf(stderr, " pkt_dts:%s pkt_dts_time:%s", av_ts2str(buf1, pkt.dts), av_ts2timestr(buf2, pkt.dts, &ist->st->time_base));
+            fprintf(stderr, " off:%"PRId64"\n", input_files[ist->file_index].ts_offset);
+        }
+#endif
         if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE
             && (is->iformat->flags & AVFMT_TS_DISCONT)) {
             int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q);
-- 
1.7.5.4

