I have 2 video files (flv). One has the video and the other has the audio. I wrote a script using ffmpeg that extracts the audio as mp3, then merges it with the video flv. It works, except that my audio and video are out of sync because the audio is longer than the video. They started recording the meeting's audio before the video.
For completeness, here are my 2 commands:
msg "Extracting Audio"
./ffmpeg -loglevel panic -i cameraVoip*.flv -vn -acodec mp3 output_audio.mp3
msg "Merging Audio with Video"
./ffmpeg -loglevel panic -i output_audio.mp3 -i screenshare*.flv -acodec copy -vcodec copy output_video.flv
This got me to thinking, ffmpeg is combining the 2 files together from the beginning of each file. Is there a way I can tell it match from the end, and ignore extra at the beginning?
I know I could edit each file to get them to the same size, but I'd like to make this as automated as possible.
Best Answer
if you just do
ffmpeg -i inputfile
it will give you informational output including the length of the stream (there is also affprobe
command that you may or may not have that does the same thing, and may have more output control).So you'll need to parse this output to get the length of each original file, and then use the
-itsoffset
option with what you learn.so you'll end up with something like (untested):