summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2024-03-02 15:52:21 +0800
committerMole Shang <[email protected]>2024-03-02 15:54:25 +0800
commitce6c2dcbaff65ef5f9f817f3a8c50c8a1a8094eb (patch)
tree30affa9db654d66b62ae62053bcf1b90857e9636 /src/utils
parent74ebee5d3a81a39766ba8cd436a548449ea887b0 (diff)
downloadhinata-ce6c2dcbaff65ef5f9f817f3a8c50c8a1a8094eb.tar.gz
hinata-ce6c2dcbaff65ef5f9f817f3a8c50c8a1a8094eb.tar.bz2
hinata-ce6c2dcbaff65ef5f9f817f3a8c50c8a1a8094eb.zip
utils/ffmpeg: fix remux progress
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/ffmpeg.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/utils/ffmpeg.c b/src/utils/ffmpeg.c
index db11f87..9085caf 100644
--- a/src/utils/ffmpeg.c
+++ b/src/utils/ffmpeg.c
@@ -70,8 +70,6 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
goto end;
}
- stat_g->total = input1_format_context->duration / AV_TIME_BASE;
-
avformat_alloc_output_context2(&output_format_context, NULL, NULL, outfn);
if (!output_format_context) {
append_log("Could not create output context\n");
@@ -153,6 +151,9 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
LOG("ffmpeg", "Error occurred when opening output file\n");
goto end;
}
+
+ stat_g->cur = 0ull;
+ stat_g->total = input1_format_context->duration / AV_TIME_BASE;
while (1) {
AVStream *in_stream, *out_stream;
ret = av_read_frame(input1_format_context, &packet);
@@ -178,9 +179,8 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
out_stream->time_base);
packet.pos = -1;
// log_packet(output_format_context, &packet, "out");
- stat_g->cur = (stat_g->cur <= stat_g->total)
- ? av_q2d(in_stream->time_base) * packet.pts
- : stat_g->total;
+ if (stat_g->cur <= stat_g->total)
+ stat_g->cur = av_q2d(in_stream->time_base) * packet.pts;
ret = av_interleaved_write_frame(output_format_context, &packet);
if (ret < 0) {
@@ -189,6 +189,9 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
}
av_packet_unref(&packet);
}
+
+ stat_g->cur = 0ull;
+ stat_g->total = input2_format_context->duration / AV_TIME_BASE;
while (1) {
AVStream *in_stream, *out_stream;
ret = av_read_frame(input2_format_context, &packet);
@@ -216,9 +219,8 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) {
out_stream->time_base);
packet.pos = -1;
// log_packet(output_format_context, &packet, "out");
- stat_g->cur = (stat_g->cur <= stat_g->total)
- ? av_q2d(in_stream->time_base) * packet.pts
- : stat_g->total;
+ if (stat_g->cur <= stat_g->total)
+ stat_g->cur = av_q2d(in_stream->time_base) * packet.pts;
ret = av_interleaved_write_frame(output_format_context, &packet);
if (ret < 0) {
LOG("ffmpeg", "Error muxing packet\n");
@@ -282,6 +284,8 @@ int remux(const char *in_filename, const char *out_filename) {
DEBUG_PRINT("duration: %.2Lf\n",
(long double)ifmt_ctx->duration / AV_TIME_BASE);
+
+ stat_g->cur = 0ull;
stat_g->total = ifmt_ctx->duration / AV_TIME_BASE;
av_dump_format(ifmt_ctx, 0, in_filename, 0);
@@ -368,9 +372,8 @@ int remux(const char *in_filename, const char *out_filename) {
av_packet_rescale_ts(pkt, in_stream->time_base, out_stream->time_base);
pkt->pos = -1;
// log_packet(ofmt_ctx, pkt, "out");
- stat_g->cur = (stat_g->cur <= stat_g->total)
- ? av_q2d(in_stream->time_base) * pkt->pts
- : stat_g->total;
+ if (stat_g->cur <= stat_g->total)
+ stat_g->cur = av_q2d(in_stream->time_base) * pkt->pts;
ret = av_interleaved_write_frame(ofmt_ctx, pkt);
/* pkt is now blank (av_interleaved_write_frame() takes ownership of
* its contents and resets pkt), so that no unreferencing is necessary.