]> git.sesse.net Git - nageru/commitdiff
Slightly more verbose error messages in Mux when a libavformat error happens.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 19 Jul 2022 21:24:55 +0000 (23:24 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 19 Jul 2022 21:24:55 +0000 (23:24 +0200)
shared/mux.cpp

index adec53de7923171842d90822a7ec8600b9e78fd0..b9ca553ee1b2ac1731d1345cd7df8e0e162f308a 100644 (file)
@@ -123,9 +123,12 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const
        for (pair<string, string> 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<AVPacket *>(&pkt)) < 0) {
-               fprintf(stderr, "av_interleaved_write_frame() failed\n");
-               abort();
+       int err = av_interleaved_write_frame(avctx, const_cast<AVPacket *>(&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) {