>From f7ba7daa66ed3cb79ab425d0494889be8ad685f7 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 |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 88a4761..1243df6 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"
 
@@ -1095,6 +1098,13 @@ static int encode_audio_frame(AVFormatContext *s, OutputStream *ost,
         av_free_packet(&pkt);
     }
 
+#ifdef DEBUG_TS
+    fprintf(stderr, "encoder -> type:audio "
+            "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
+            av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base),
+            av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base));
+#endif
+
     if (frame)
         ost->sync_opts += frame->nb_samples;
 
@@ -1564,10 +1574,13 @@ 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
+                fprintf(stderr, "encoder -> type:video "
+                        "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n",
+                        av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ost->st->time_base),
+                        av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ost->st->time_base));
+#endif
                 if (enc->coded_frame->key_frame)
                     pkt.flags |= AV_PKT_FLAG_KEY;
                 write_frame(s, &pkt, ost);
@@ -3020,10 +3033,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
+        fprintf(stderr, "demuxer -> ist_index:%d type:%s "
+                "next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%"PRId64"\n",
+                ist_index, av_get_media_type_string(ist->st->codec->codec_type),
+                av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &ist->st->time_base),
+                av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base),
+                av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base),
+                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

