1

I'm using ffmpeg to create several single splitscreen videos out of 2 separate videos. The 2 videos have audio so I want to extract the 2 video's audio streams as 2 separate mp3s and also create a thumbnail out of the finished splitscreen video. Is it possible to do these 3 actions in one pass?

Here is the code I'd use to create the splitscreen video:

ffmpeg -i input0.mov -i input1.mov -filter_complex "[0]scale=640x360[v0];[1]scale=640x360[v1];[v0][v1] xstack=inputs=2:layout=0_0|w0_0|[v]" -map "[v]" -an output.mp4

Here is the code I'd use to create the thumbnail of the resultant splitscreen video:

ffmpeg -y -i input.mp4 -vframes 1 OUTPUT.jpg

Here is the code I'd use to create one mp3

ffmpeg -i input0.mov output0.mp3

1 Answer 1

1

Combined command:

ffmpeg -i input0.mov -i input1.mov -filter_complex "[0]scale=640x360[v0];[1]scale=640x360[v1];[v0][v1]hstack,split[video][image]" -map "[video]" output.mp4 -map 0:a audio0.mp3 -map 1:a audio1.mp3 -map "[image]" -frames:v 1 image.jpg

For a 4 videos into a 2x2 layout:

ffmpeg -i input0.mov -i input1.mov -i input2.mov -i input3.mov -filter_complex "[0]scale=640x360[v0];[1]scale=640x360[v1];[2]scale=640x360[v2];[3]scale=640x360[v3];[v0][v1][v2][v3]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0,split[video][image]" -map "[video]" output.mp4 -map 0:a audio0.mp3 -map 1:a audio1.mp3 -map 2:a audio2.mp3 -map 3:a audio3.mp3 -map "[image]" -frames:v 1 image.jpg
4
  • Your answer works for the split screen video and 2 separate mp3s if I exclude: "image.jpg" at the end Unfortunately if I add "image.jpg" it makes the video and audio about 1 frame long and doesn't create a thumbnail of the finished resultant splitscreen video, just input1.mov. Any ideas?
    – Ben Hardy
    Apr 26, 2020 at 21:38
  • @BenHardy See updated answer. Wasn't able to test the first iteration and I forgot a few things.
    – llogan
    Apr 27, 2020 at 17:35
  • This works perfectly. Could this code be adapted for 4 videos? </>
    – Ben Hardy
    Apr 27, 2020 at 20:36
  • @BenHardy See updated answer.
    – llogan
    Apr 27, 2020 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.