X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mux.cpp;fp=mux.cpp;h=534d56abd8e0dfb7fd667d9fb60788b83049f409;hb=16c71cac0d5c81e84271222d1ed0c501fe723d56;hp=eff336f5799d01706fd7f9c4a2a0fc99356303f6;hpb=1a0b54800329dd7131c4973b0850442f7ea4af28;p=nageru diff --git a/mux.cpp b/mux.cpp index eff336f..534d56a 100644 --- a/mux.cpp +++ b/mux.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -86,7 +87,10 @@ Mux::~Mux() void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts) { AVPacket pkt_copy; - av_copy_packet(&pkt_copy, &pkt); + if (av_copy_packet(&pkt_copy, &pkt) < 0) { + fprintf(stderr, "av_copy_packet() failed\n"); + exit(1); + } if (pkt.stream_index == 0) { pkt_copy.pts = av_rescale_q(pts, AVRational{1, TIMEBASE}, avstream_video->time_base); pkt_copy.dts = av_rescale_q(dts, AVRational{1, TIMEBASE}, avstream_video->time_base); @@ -106,9 +110,12 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts) } } - if (av_interleaved_write_frame(avctx, &pkt_copy) < 0) { - fprintf(stderr, "av_interleaved_write_frame() failed\n"); - exit(1); + { + lock_guard lock(ctx_mu); + if (av_interleaved_write_frame(avctx, &pkt_copy) < 0) { + fprintf(stderr, "av_interleaved_write_frame() failed\n"); + exit(1); + } } av_packet_unref(&pkt_copy);