packet.pts = std::max(packet.pts, last_input_pts[input_stream_index]);
packet.dts = std::max(packet.dts, last_input_dts[input_stream_index]);
last_input_pts[input_stream_index] = packet.pts;
last_input_dts[input_stream_index] = packet.dts;
AVPacket outputPacket;
av_init_packet(&outputPacket);
av_packet_ref(&outputPacket, &packet);
int64_t new_pts = av_rescale_q(packet.pts, input_time_base, output_time_base);
int64_t new_dts = av_rescale_q(packet.dts, input_time_base, output_time_base);
new_pts = std::max(new_pts, last_output_pts[output_stream_index]);
new_dts = std::max(new_dts, last_output_dts[output_stream_index]);
outputPacket.pts = new_pts;
outputPacket.dts = new_dts;
last_output_pts[output_stream_index] = new_pts;
last_output_dts[output_stream_index] = new_dts;
av_write_frame(outputFormatContext, &outputPacket);
av_packet_unref(&outputPacket);
// Sleep for synchronization
std::this_thread::sleep_until(std::chrono::system_clock::now() +
std::chrono::duration<int64_t, std::micro>(
av_rescale_q(new_pts - last_output_pts[0], output_time_base, {1, 1000000})));
}
av_packet_unref(&packet);
报错:
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 18932940 >= 18932940
[rtp_mpegts @ 0x556d71bf6080] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 18956539 >= 18956539
输入信息:
ffprobe h264-aac-768x320.mp4
ffprobe version 4.4.2 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
configuration: --prefix=/home/zouyl/work/ffmpeg/ffmpeg-4.4.2/build --enable-shared --enable-gpl --enable-nonfree --enable-libopus --enable-libx264 --extra-cflags=-I/home/zouyl/work/ffmpeg/x264/build/include --extra-ldflags=-L/home/zouyl/work/ffmpeg/x264/build/lib --enable-libx265 --enable-libfdk-aac --enable-libvpx --enable-sdl2 --enable-ffplay
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'h264-aac-768x320.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.76.100
Duration: 00:03:30.65, start: 0.000000, bitrate: 248 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 768x320 [SAR 1:1 DAR 12:5], 212 kb/s, 25 fps, 25 tbr, 16k tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 30 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]