TudorT
TudorT

Reputation: 476

Is it possible to merge video files with FFmpeg interlaced not concatenated?

I am trying to create a video file that has the frames from 2 source mp4 video files interlaced like this:

I1 I2 P1 P2 I1 I2 P1 P2 I1 I2 P1 P2 ...

where I = Intra, P = predicted, and the numbers are from which source file they come.

Is this possible with FFmpeg commands? If not, if I use the ffplay code from read_thread, how do I put the content returned from av_read_frame into a proper video file?

Thanks

Upvotes: 0

Views: 386

Answers (1)

GalaDOS
GalaDOS

Reputation: 158

You can't do this without transcoding. Here is a simple example for videos with same resolution and framerate:

ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex "[0:v][1:v]blend=all_expr='ifnot(mod(N,2),A,B)'[out]" -map [out] out.mp4

Check this page for detail.

Update:

As Gyan's comment said, the command above will drop half the frames. So double the fps before interleave maybe better if you do not want to lost any information. Asume the input videos are constant 30 fps:

ffmpeg -i 1.mp4 -i 2.mp4 -filter_complex "[0:v]framerate=60[in0];[1:v]framerate=60[in1];[in0][in1]blend=all_expr='ifnot(mod(N,2),A,B)'[out]" -map [out] out.mp4

Upvotes: 1

Related Questions