From 08431c7635699da2c5129929d7dd3f6b71b431bf Mon Sep 17 00:00:00 2001
From: Mole Shang <135e2@135e2.dev>
Date: Thu, 10 Aug 2023 12:56:04 +0800
Subject: utils/ffmpeg: fix regression and temporarily disable debug log

---
 src/utils/ffmpeg.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'src/utils')

diff --git a/src/utils/ffmpeg.c b/src/utils/ffmpeg.c
index 694400c..98d2ba1 100644
--- a/src/utils/ffmpeg.c
+++ b/src/utils/ffmpeg.c
@@ -152,7 +152,7 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
     ret = av_read_frame(input1_format_context, &packet);
     if (ret < 0)
       break;
-    in_stream = input1_format_context->streams[stream_index];
+    in_stream = input1_format_context->streams[packet.stream_index];
     if (packet.stream_index >= number_of_streams ||
         streams_list[packet.stream_index] < 0) {
       av_packet_unref(&packet);
@@ -161,7 +161,7 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
     packet.stream_index = streams_list[packet.stream_index];
     out_stream = output_format_context->streams[packet.stream_index];
     /* copy packet */
-    log_packet(input1_format_context, &packet, "in");
+    // log_packet(input1_format_context, &packet, "in");
     packet.pts = av_rescale_q_rnd(packet.pts, in_stream->time_base,
                                   out_stream->time_base,
                                   AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
@@ -171,7 +171,7 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
     packet.duration = av_rescale_q(packet.duration, in_stream->time_base,
                                    out_stream->time_base);
     packet.pos = -1;
-    log_packet(output_format_context, &packet, "out");
+    // log_packet(output_format_context, &packet, "out");
 
     ret = av_interleaved_write_frame(output_format_context, &packet);
     if (ret < 0) {
@@ -269,6 +269,9 @@ int remux(const char *in_filename, const char *out_filename) {
     goto end;
   }
 
+  DEBUG_PRINT("duration: %.2Lf\n",
+              (long double)ifmt_ctx->duration / AV_TIME_BASE);
+
   av_dump_format(ifmt_ctx, 0, in_filename, 0);
 
   avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);
@@ -347,12 +350,12 @@ int remux(const char *in_filename, const char *out_filename) {
 
     pkt->stream_index = stream_mapping[pkt->stream_index];
     out_stream = ofmt_ctx->streams[pkt->stream_index];
-    log_packet(ifmt_ctx, pkt, "in");
+    // log_packet(ifmt_ctx, pkt, "in");
 
     /* copy packet */
     av_packet_rescale_ts(pkt, in_stream->time_base, out_stream->time_base);
     pkt->pos = -1;
-    log_packet(ofmt_ctx, pkt, "out");
+    // log_packet(ofmt_ctx, pkt, "out");
 
     ret = av_interleaved_write_frame(ofmt_ctx, pkt);
     /* pkt is now blank (av_interleaved_write_frame() takes ownership of
-- 
cgit v1.2.3