0

16 days ago I had this problem: Concatenating mka files but keeping timestamp which I fixed by using amix, a delay by using start_pts from ffprobe.

Today I have a new challenge like this, but with video.

So I have a bunch of mkv videos. Each time a person joins a chat, a mkv is recorded, but if the person refreshes the page a new mkv is created with start_pts and start_time to what it actually is. Also if the meeting started and a person joins after a minute, the start_time is set to 1 minute. I need to merge all those mkv and pad them with blank screen when there is no feed.

Like in the above example, if a person joins after a minute, the first minute is a blank screen. Also if the participant leaves and re-joins after 10 seconds, those 10 seconds are blank again.

Any ideas on how to do that with ffmpeg?

Concrete example of files:

0PA84c5c3f412769b311d44b159941b2d22.mkv - start_pts: 742 start_time: 0.742000
2PA73d94e8cb0f41c3002fadd6c04b4a88f.mkv - start_pts: 30761 start_time: 30.761000
3PAcd35e470325618fa8a3fb8bb5a41403e.mkv - start_pts: 50940 start_time: 50.940000
4PAddccde7b8847ecc43d5e8643b7903dba.mkv - start_pts: 69243 start_time: 69.243000

The end file would result in a file with length 69.243000, first 0.742 seconds are blank and also the gaps between should also be blank.

So far i've tried:

ffmpeg -i 0PA84c5c3f412769b311d44b159941b2d22.mkv -i 2PA73d94e8cb0f41c3002fadd6c04b4a88f.mkv -i 3PAcd35e470325618fa8a3fb8bb5a41403e.mkv -i 4PAddccde7b8847ecc43d5e8643b7903dba.mkv -filter_complex "[0:v] [1:v] [2:v] [3:v] concat=n=4:v=1 [v]" -map "[v]" test.mkv

This works but without those gaps i mentioned.

Filip
  • 346
  • 1
  • 4
  • 15
  • Filip, I encountered the same problem in the same scenario as you, have you solved it somehow? I have tried the solution below, but the size of the result gaps is not correct, maybe I am referring to incorrect reference fields? – Marco Sacchi Apr 26 '22 at 13:13

1 Answers1

0

You can get the length of the files with ffprobe and calculate the length of the gaps. Then create those gaps with the color filter and concat them between the videos.

Here is the command:

ffmpeg -i 1.mkv -i 2.mkv -i 3.mkv -filter_complex"\
color=s=1280x720,trim=0:0.742[gap0];\
color=s=1208x720,trim=0:5[gap1];\
color=s=1208x720,trim=0:2[gap2];\
[gap0][0:v][gap1][1:v][gap2][2:v]concat=6:v=1 [v]"\
-map [v] out.mkv
Dirk V
  • 1,373
  • 12
  • 24
  • hmm this could work. will try to play it it now. Also do you know how can i resize all videos to the smallest one with concat? Cause for example if user changes webcam and has another resolution, concat complains about it. My idea: loop through all the videos, get the smallest resolution of all of them then all concated videos should be that resolution – Filip Aug 13 '20 at 12:43
  • What you could do it using the `scale` filter to resize all the videos. You could make them fit in a box for example like so: `[0:v]scale=w='if(gt(iw/ih,${w}/${h}),${w},-2)':h='if(gt(iw/ih,${w}/${h}),-2,${h})':eval=init[out]` with ${w} ${h} your output with and height. This way it doesn't matter what resolution they have, they will be scaled and keep their ratio. – Dirk V Aug 13 '20 at 12:55
  • You then probably also need a `pad` to fill the empty space and the an exact output – Dirk V Aug 13 '20 at 12:58
  • You could also use ffprobe to get the dimensions of the videos beforehand – Dirk V Aug 14 '20 at 00:24