Tuesday 28 August 2018

FFMPEG add audio to a video but clip it to the video length


I'm trying to create a video from an image sequence and add audio with FFMPEG


The frame sequence is only 25 frames long but the audio is several minutes. I want FFMPEG to clip the audio to the length of the frame sequence.


This is the command I have tried:


ffmpeg -i input_images%04d.jpg -pix_fmt yuv420p -vcodec mjpeg -qmin 1 -qmax 1 -r 25 -i audio_file.mp3 -ar 22050 -ab 192k -aframes 25 output.mov

This results in a video with the first image sequence but the full length audio. -aframes is ignored. Any ideas?



Answer



From the FFmpeg documentation:


ffmpeg -i in%04d.jpg -i in.mp3 -shortest out.mov

The -shortest option finishes encoding when the shortest input stream ends.


When you're merging video and audio files, you can also copy the bitstreams to avoid encoding:


ffmpeg -i video.mp4 -i audio.m4a -c copy -map 0:v -map 1:a output.mp4

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...