From be64de78195bebafed2912533246df57e851ed5a Mon Sep 17 00:00:00 2001 From: Mole Shang <135e2@135e2.dev> Date: Thu, 10 Aug 2023 21:57:44 +0800 Subject: utils/ffmpeg: log errors in logger --- src/utils/ffmpeg.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/utils/ffmpeg.c') diff --git a/src/utils/ffmpeg.c b/src/utils/ffmpeg.c index 8a6d114..db11f87 100644 --- a/src/utils/ffmpeg.c +++ b/src/utils/ffmpeg.c @@ -107,7 +107,7 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) { } ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar); if (ret < 0) { - append_log("Failed to copy codec parameters\n"); + LOG("ffmpeg", "Failed to copy codec parameters\n"); goto end; } } @@ -125,13 +125,13 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) { stream_index++; out_stream = avformat_new_stream(output_format_context, NULL); if (!out_stream) { - append_log("Failed allocating output stream\n"); + LOG("ffmpeg", "Failed allocating output stream\n"); ret = AVERROR_UNKNOWN; goto end; } ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar); if (ret < 0) { - append_log("Failed to copy codec parameters\n"); + LOG("ffmpeg", "Failed to copy codec parameters\n"); goto end; } } @@ -143,14 +143,14 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) { if (!(output_format_context->oformat->flags & AVFMT_NOFILE)) { ret = avio_open(&output_format_context->pb, outfn, AVIO_FLAG_WRITE); if (ret < 0) { - append_log("Could not open output file '%s'", outfn); + LOG("ffmpeg", "Could not open output file '%s'", outfn); goto end; } } ret = avformat_write_header(output_format_context, &opts); if (ret < 0) { - append_log("Error occurred when opening output file\n"); + LOG("ffmpeg", "Error occurred when opening output file\n"); goto end; } while (1) { @@ -184,7 +184,7 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) { ret = av_interleaved_write_frame(output_format_context, &packet); if (ret < 0) { - append_log("Error muxing packet\n"); + LOG("ffmpeg", "Error muxing packet\n"); break; } av_packet_unref(&packet); @@ -221,7 +221,7 @@ int merge_av(const char *videofn, const char *audiofn, const char *outfn) { : stat_g->total; ret = av_interleaved_write_frame(output_format_context, &packet); if (ret < 0) { - append_log("Error muxing packet\n"); + LOG("ffmpeg", "Error muxing packet\n"); break; } av_packet_unref(&packet); @@ -237,16 +237,16 @@ end: avformat_free_context(output_format_context); av_freep(&streams_list); if (ret < 0 && ret != AVERROR_EOF) { - append_log("Error occurred: %s\n", av_err2str(ret)); + LOG("ffmpeg", "Error occurred: %s\n", av_err2str(ret)); return 1; } // Delete seperate files if (remove(videofn) != 0) { - append_log("Error deleting partial file %s\n", videofn); + LOG("ffmpeg", "Error deleting partial file %s\n", videofn); } if (remove(audiofn) != 0) { - append_log("Error deleting partial file %s\n", audiofn); + LOG("ffmpeg", "Error deleting partial file %s\n", audiofn); } return 0; } @@ -262,7 +262,7 @@ int remux(const char *in_filename, const char *out_filename) { pkt = av_packet_alloc(); if (!pkt) { - fprintf(stderr, "Could not allocate AVPacket\n"); + LOG("ffmpeg", "Could not allocate AVPacket\n"); return 1; } @@ -271,12 +271,12 @@ int remux(const char *in_filename, const char *out_filename) { "concat,file,http,https,tcp,tls,crypto", 0); if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, &opts)) < 0) { - fprintf(stderr, "Could not open input file '%s'\n", in_filename); + LOG("ffmpeg", "Could not open input file '%s'\n", in_filename); goto end; } if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) { - fprintf(stderr, "Failed to retrieve input stream information.\n"); + LOG("ffmpeg", "Failed to retrieve input stream information.\n"); goto end; } @@ -288,7 +288,7 @@ int remux(const char *in_filename, const char *out_filename) { avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename); if (!ofmt_ctx) { - fprintf(stderr, "Could not create output context.\n"); + LOG("ffmpeg", "Could not create output context.\n"); ret = AVERROR_UNKNOWN; goto end; } @@ -318,14 +318,14 @@ int remux(const char *in_filename, const char *out_filename) { out_stream = avformat_new_stream(ofmt_ctx, NULL); if (!out_stream) { - fprintf(stderr, "Failed allocating output stream\n"); + LOG("ffmpeg", "Failed allocating output stream\n"); ret = AVERROR_UNKNOWN; goto end; } ret = avcodec_parameters_copy(out_stream->codecpar, in_codecpar); if (ret < 0) { - fprintf(stderr, "Failed to copy codec parameters\n"); + LOG("ffmpeg", "Failed to copy codec parameters\n"); goto end; } out_stream->codecpar->codec_tag = 0; @@ -335,14 +335,14 @@ int remux(const char *in_filename, const char *out_filename) { if (!(ofmt->flags & AVFMT_NOFILE)) { ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE); if (ret < 0) { - fprintf(stderr, "Could not open output file '%s'", out_filename); + LOG("ffmpeg", "Could not open output file '%s'", out_filename); goto end; } } ret = avformat_write_header(ofmt_ctx, &opts); if (ret < 0) { - fprintf(stderr, "Error occurred when opening output file\n"); + LOG("ffmpeg", "Error occurred when opening output file\n"); goto end; } @@ -376,7 +376,7 @@ int remux(const char *in_filename, const char *out_filename) { * its contents and resets pkt), so that no unreferencing is necessary. * This would be different if one used av_write_frame(). */ if (ret < 0) { - fprintf(stderr, "Error muxing packet\n"); + LOG("ffmpeg", "Error muxing packet\n"); break; } } @@ -395,13 +395,13 @@ end: av_freep(&stream_mapping); if (ret < 0 && ret != AVERROR_EOF) { - fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); + LOG("ffmpeg", "Error occurred: %s\n", av_err2str(ret)); return 1; } // Delete seperate files if (remove(in_filename) != 0) { - append_log("Error deleting partial file %s\n", in_filename); + LOG("ffmpeg", "Error deleting partial file %s\n", in_filename); } return 0; -- cgit v1.2.3