Ffmpeg and video vs audio time

Asked

Viewed 247 times

0

I am with a simple application that performs the download of a video + audio and ' concatenate ' ( Join ) the same with the tool Ffmpeg, the problem is that most of the time the user will download a song larger than the video in question and then it gets a video of 10 seconds and the rest is a screen locked with background sound ... someone would know to inform me the parameters + explanation so that I concaten the song exactly on video length ?

Current code :

ffmpeg -i {0}.{1} -i {2}.{3} -vcodec copy -acodec copy {4}.{5} && rm -rf {0}.{1} {2}.{3}

Research : Video and Audio file format

1 answer

1


Assuming you are using via CLI, if the video is shorter than the audio you can simply use:

-shortest (output)

"Finish encoding when the shortest input stream ends."


I believe this is enough, for test I used via Powershell:

.\ffmpeg.exe `
-i "River - 6815.mp4" -i "Frontliner - Around The World (Extended Mix).wav" `
-c:v copy -c:a aac -map 0:0 -map 1:0 -shortest "resultado.mp4"

The video (River - 6815.mp4) has 13 seconds, while the music (Frontliner - Around The World (Extended Mix)) is 4 minutes and 51 seconds long.

The final video (result.mp4) was with 13 seconds in total and the video and audio was connected normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.