[FFmpeg-user] FFmpeg: "Error muxing a packet" when trying to concatenate two GoPro videos. Why?

Franck Dernoncourt franck.dernoncourt at gmail.com
Mon Dec 9 22:22:48 EET 2024


Problem statement

I was trying to fix that problem: FFmpeg messes up
<https://superuser.com/q/1864065/116475> the original stream order of
a.MP4 when
running:

ffmpeg -sseof -1 -i a.MP4 -map 0:v -map 0:a -map 0:3 -c copy
-copy_unknown a_last_1_second.MP4

This causes my attempt to concatenate two GoPro videos losslessly with that
FFmpeg command to fail:

ffmpeg -safe 0 -f concat -i "list_videos.txt" -map 0:v -map 0:a -map
0:2 -copy_unknown -c copy "ab.mp4"

with list_videos.txt containing:

file 'a.MP4'
file 'b.MP4'

since a_last_1_second.mp4 and b.MP4 doesn't have the same stream order.
------------------------------
My failed fix

The fix I was trying to implement relies on that logic: let's use FFmpeg to
also mess up the original stream order of b.MP4, so that both a.MP4 and
b.MP4's stream orders are equally messed up to ensure smooth concatenation.

Example: I'll use that GoPro video file
<https://ia803401.us.archive.org/19/items/images-for-questions/GoPro_file_example.MP4>
(18.5
MiB) to be both a.MP4 and b.MP4 to make it easier to test.

Step 1: extract the last second of a.MP4:

ffmpeg -sseof -1 -i a.MP4 -map 0:v -map 0:a -map 0:3 -c copy
-copy_unknown a_only_the_last_1sec.MP4

Step 2: Since FFmpeg messes up <https://superuser.com/q/1864065/116475> the
original stream order of a.MP4, we can rely on FFmpeg to also mess up the
original stream order of b.MP4 (otherwise, concatenate may not work due to
different stream orders):

ffmpeg -i "b.mp4" -map 0:v -map 0:a -map 0:3 -copy_unknown -c copy
"b_with_messed_up_stream_order.mp4"

Step 3: concatenate b_with_messed_up_stream_order.mp4 and
a_only_the_last_1sec.MP4:

ffmpeg -safe 0 -f concat -i "list_videos.txt" -map 0:v -map 0:a -map
0:2 -copy_unknown -c copy "ab.mp4"

where list_videos.txt contains:

b_with_messed_up_stream_order.mp4
a_only_the_last_1sec.MP4

Tested with ffmpeg version 7.1-full_build-www.gyan.dev on Windows 10 Pro
21H2.

However, when trying to concatenate b_with_messed_up_stream_order.mp4 and
a_only_the_last_1sec.MP4, I get this error:

[concat @ 00000170886fbc00] DTS 59062 < 86086 out of order
[aost#0:1/copy @ 0000017088c6fd00] Non-monotonic DTS; previous:
137216, current: 95109; changing to 137217. This may result in
incorrect timestamps in the output file.
[mp4 @ 0000017088c6f040] Application provided invalid, non
monotonically increasing dts to muxer in stream 2: 2002 >= 1902
[dost#0:2/copy @ 0000017088777e40] Error submitting a packet to the
muxer: Invalid argument
    Last message repeated 1 times
[out#0/mp4 @ 0000017088de77c0] Error muxing a packet
[out#0/mp4 @ 0000017088de77c0] Task finished with error code: -22
(Invalid argument)
[out#0/mp4 @ 0000017088de77c0] Terminating thread with return code -22
(Invalid argument)
[out#0/mp4 @ 0000017088de77c0] video:18878KiB audio:67KiB
subtitle:0KiB other streams:26KiB global headers:0KiB muxing overhead:
unknown
frame=   87 fps=0.0 q=-1.0 Lsize=   18969KiB time=00:00:02.06
bitrate=75113.0kbits/s speed=12.7x
Conversion failed!

Why?


More information about the ffmpeg-user mailing list