[FFmpeg-user] How to retain correct frame order when concatenating?

Flopsy flopsy at tfwno.gf
Tue Oct 29 14:39:14 EET 2024


Hi!

I'm trying to concatenate these two single frame videos 
[https://files.catbox.moe/v85pqy.zip], but they always end up in the 
wrong order.

I've tried with the following command:

> ffmpeg -y -f concat -i filelist.txt -c copy outf.mkv

...where filelist.txt contains:

> file '0012890a_9680.mkv'
> file '0012890a_692070.mkv'

But this gives me a 2 frame video with the frame order reversed. 
Examining the file with `ffprobe -show_frames`, it does indeed show the 
frames in reverse (some lines omitted):

> [FRAME]
> key_frame=1
> pts=42
> pts_time=0.042000
> best_effort_timestamp=42
> best_effort_timestamp_time=0.042000
> duration=41
> duration_time=0.041000
> pkt_pos=28240
> pkt_size=88803
>
> [FRAME]
> key_frame=1
> pts=0
> pts_time=0.000000
> best_effort_timestamp=0
> best_effort_timestamp_time=0.000000
> duration=41
> duration_time=0.041000
> pkt_pos=7976
> pkt_size=20246
It's interesting to note that, according to `pkt_pos`, the frames are 
written in correct order, and the PTS is also correct, however the order 
listed is somehow incorrect.

If I reverse the order of the frames in filelist.txt, I get the order 
expected. So it seems like ffmpeg really wants to put the second frame 
first.

I've also tried adding `-bsf:v setts=ts=N` to the ffmpeg command - the 
resulting PTS for the frames are 1 and 0, indicating correct packet 
order, but frames listed in reverse.

I've also tried with mkvmerge, but get the same result (command: 
`mkvmerge --output outm.mkv 0012890a_9680.mkv + 0012890a_692070.mkv 
--append-to 1:0:0:0`)

Does anyone know what's going on and how to get the frames in the 
correct order?



More information about the ffmpeg-user mailing list