0

I have two videos and two audios

1:- video 1 - length:- 60 sec || audio 1 - length:- 15 sec

2:- video - length:- 86 sec || audio 2 - length:- 18 sec

Play video1 and audio1 together, if audio1 is ended then restart that audio till video1 end. this will final video 1.

same way,

play video2 and audio2 together, if audio2 is ended then restart that audio till video2 end. this will final video 2.

after that concatenate those final video 1 and final video 2 and create single video as output.

Thank you in advance.

2
  • 1
    Will the videos and audios always have the same attributes (format, width, height, sample rate, channel layout, etc), or will they vary? Fastest way to get answer you can copy and paste is by showing file and ffmpeg info with: ffmpeg -n -i video1 -i audio1 -i video2 -i audio2 Commented Dec 12, 2020 at 19:15
  • Video and audio attributes are vary every time user choose video. this is just an example. I am creating output video from this kind of audio and video. help me! Commented Dec 14, 2020 at 10:55

1 Answer 1

1
  1. Because your inputs are arbitrary you need to make them the same before concatenation.

    ffmpeg -i video1 -stream_loop -1 -i audio1 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp1.mp4 ffmpeg -i video2 -stream_loop -1 -i audio2 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp2.mp4 
  2. Concatenate.

    Make input.txt:

    file 'temp1.mp4' file 'temp2.mp4' 

    Run ffmpeg:

    ffmpeg -f concat -i input.txt -c copy -movflags +faststart output.mp4 

As a "single line command" as requested (but make input.txt first):

ffmpeg -i video1 -stream_loop -1 -i audio1 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp1.mp4 && ffmpeg -i video2 -stream_loop -1 -i audio2 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp2.mp4 && ffmpeg -f concat -safe 0 -i input.txt -c copy -movflags +faststart output.mp4 
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for answer. but I need this using single line command. because I want to show the progress of that operation too. is that any way for doing this with single line command?
@KashyapRathod See updated answer for "single line command".
Tank you so much, this is working fine. I got the error ''The system cannot find the file specified.' then is change last line from '&& ffmpeg -f concat -safe 0 -i <(printf "file '%s'\n" temp*.mp4) -c copy -movflags +faststart output.mp4' to '&& ffmpeg -i temp1.mp4 -i temp2.mp4 -filter_complex [0][1]concat=n=2 output.mp4' and done. Thank you so much again.
@KashyapRathod I guess printf and/or bash doesn't work on Andriod. Your command is slow and will reduce quality because it will unnecessarily re-encode the video. The first two ffmpeg commands in my answer make the videos have the same attributes so they can be concatenated by the third ffmpeg command without needing to be re-encoded. See updated answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.