I tried to concatenate a number of video files:
$ melt file01.mp4 file02.mp4 filen.mp4 170_ot_proof.mp4 170_thanks.mp4 -consumer "avformat:total.mp4" acodec=libmp3lame vcodec=libx264
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
+---------------------------------------------------------------------+
| H = back 1 minute, L = forward 1 minute |
| h = previous frame, l = next frame |
| g = start of clip, j = next clip, k = previous clip |
| 0 = restart, q = quit, space = play |
+---------------------------------------------------------------------+
[mp4 @ 0x7fc5b4001180] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[mp4 @ 0x7fc5b4001180] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[mp4 @ 0x7fc5b4001180] Timestamps are unset in a packet for stream 1. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0x7fc5b4001180] Encoder did not produce proper pts, making some up.
Current Position: 4599
The problem is that the produced file is 1 frame too long:
$ function get_fps() {melt "$1" -consumer xml | grep length | sed 's/[^0-9]//g';}
$ get_fps "total.mp4"
4601
$ tot=0; for file in file01.mp4 file02.mp4 filen.mp4 170_ot_proof.mp4 170_thanks.mp4; do tot=$(($tot + $(get_fps "$file"))); done; echo $tot
4600
After inspecting with KDEnlive, it seems like the added frame is in the last clip, not sure if it's just the last frame that is duplicated or another one.
This always occurs for the same set of files, but if I remove some files the issue is not always here… I made sure to set all files at 24fps.
I really don't understand what's going wrong here. Any idea?
Edit
On the other hand, ffprobe gives:
$ ffprobe -select_streams v -show_streams ../total.mp4 | grep nb_frame
nb_frames=4600
and this also gives the same number (but takes much more time, like if it were decoding the video instead of reading the headers):
$ ffprobe -v error -select_streams v:0 -count_frames -show_entries stream=nb_read_frames -print_format csv ../total.mp4
stream,4600
I also tried to use cv2.CAP_PROP_FRAME_COUNT
that also gives me 4600, so I'm a bit lost… If KDEnlive/melt give a different number than ffprobe, who should I trust?