X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmux.cpp;h=f6452795f4ab80ff51b6b9e391191c3c6194e90d;hb=23a236b4b2c551376b90c31d9a6cf72025da368c;hp=e122e2bb32c998556c377291c1d1d513badd9e98;hpb=e20bf0f86703779f11d575f44173ff73544e1c2d;p=nageru diff --git a/shared/mux.cpp b/shared/mux.cpp index e122e2b..f645279 100644 --- a/shared/mux.cpp +++ b/shared/mux.cpp @@ -53,12 +53,14 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const AVStream *avstream_video = avformat_new_stream(avctx, nullptr); if (avstream_video == nullptr) { fprintf(stderr, "avformat_new_stream() failed\n"); - exit(1); + abort(); } avstream_video->time_base = AVRational{1, time_base}; avstream_video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (video_codec == CODEC_H264) { avstream_video->codecpar->codec_id = AV_CODEC_ID_H264; + } else if (video_codec == CODEC_AV1) { + avstream_video->codecpar->codec_id = AV_CODEC_ID_AV1; } else if (video_codec == CODEC_NV12) { avstream_video->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; avstream_video->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag(AV_PIX_FMT_NV12); @@ -94,12 +96,12 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const AVStream *avstream_audio = avformat_new_stream(avctx, nullptr); if (avstream_audio == nullptr) { fprintf(stderr, "avformat_new_stream() failed\n"); - exit(1); + abort(); } avstream_audio->time_base = AVRational{1, time_base}; if (avcodec_parameters_copy(avstream_audio->codecpar, audio_codecpar) < 0) { fprintf(stderr, "avcodec_parameters_copy() failed\n"); - exit(1); + abort(); } streams.push_back(avstream_audio); } @@ -108,7 +110,7 @@ Mux::Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const AVStream *avstream_subtitles = avformat_new_stream(avctx, nullptr); if (avstream_subtitles == nullptr) { fprintf(stderr, "avformat_new_stream() failed\n"); - exit(1); + abort(); } avstream_subtitles->time_base = AVRational{1, time_base}; avstream_subtitles->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; @@ -123,9 +125,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"); - exit(1); + 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; @@ -166,7 +171,7 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational t av_init_packet(&pkt_copy); if (av_packet_ref(&pkt_copy, &pkt) < 0) { fprintf(stderr, "av_copy_packet() failed\n"); - exit(1); + abort(); } if (stream_index_override != -1) { pkt_copy.stream_index = stream_index_override; @@ -205,9 +210,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) {