From: Steinar H. Gunderson Date: Tue, 19 Jul 2022 21:24:55 +0000 (+0200) Subject: Slightly more verbose error messages in Mux when a libavformat error happens. X-Git-Tag: 2.2.0~21 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=d9227b65e7e68c8bc34e34e89ee840d2ec9d480d Slightly more verbose error messages in Mux when a libavformat error happens. --- diff --git a/shared/mux.cpp b/shared/mux.cpp index adec53d..b9ca553 100644 --- a/shared/mux.cpp +++ b/shared/mux.cpp @@ -123,9 +123,12 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const for (pair opt : opts) { av_dict_set(&options, opt.first.c_str(), opt.second.c_str(), 0); } - if (avformat_write_header(avctx, &options) < 0) { - fprintf(stderr, "avformat_write_header() failed\n"); - abort(); + int err = avformat_write_header(avctx, &options); + if (err < 0) { + char errbuf[AV_ERROR_MAX_STRING_SIZE]; + av_strerror(err, errbuf, sizeof(errbuf)); + fprintf(stderr, "avformat_write_header() failed: %s\n", errbuf); + exit(EXIT_FAILURE); } for (MuxMetrics *metric : metrics) { metric->metric_written_bytes += avctx->pb->pos; @@ -205,9 +208,12 @@ void Mux::write_packet_or_die(const AVPacket &pkt, int64_t unscaled_pts) } } int64_t old_pos = avctx->pb->pos; - if (av_interleaved_write_frame(avctx, const_cast(&pkt)) < 0) { - fprintf(stderr, "av_interleaved_write_frame() failed\n"); - abort(); + int err = av_interleaved_write_frame(avctx, const_cast(&pkt)); + if (err < 0) { + char errbuf[AV_ERROR_MAX_STRING_SIZE]; + av_strerror(err, errbuf, sizeof(errbuf)); + fprintf(stderr, "av_interleaved_write_frame() failed: %s\n", errbuf); + exit(EXIT_FAILURE); } avio_flush(avctx->pb); for (MuxMetrics *metric : metrics) {