FFmpeg and video vs. audio time

0

I have a simple application that downloads a video + audio and 'concatenates' them with the tool FFmpeg , the problem is that most of the time the user will download a song bigger than the video in question and then there is 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 I concatenate the song exactly the length of the video?

Current code:

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

Search: Video and Audio file format

    
asked by anonymous 05.07.2017 / 21:25

1 answer

2

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 think this is enough, for testing 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, whereas the song ( Frontliner - Around The World (Extended Mix) is 4 minutes 51 seconds long.

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

    
06.07.2017 / 01:53