Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine a .mp4 video with a .wav audio with an offset in ffmpeg from command line?

I've got a TV clip in mp4 format containing audio and video, and an WAV audio_commentary track.

I've been trying to combine them in ffmpeg and then play it online with a flash player (which can only take h264 format)

What's the best ffmpeg command to accomplish this? My inputs are MP4 video, WAV audio, and an offset in seconds, the time the audio commentary starts relative to the start of the mp4 video.

I tried

ffmpeg -i input_audio.wav -i input_vid.mp4 -vcodec copy output.mp4

and

ffmpeg -vcodec copy -ss offset -i input_audio.wav -i input_video.mp4 output.mp4

nether of these do what I want and output the video in the h264 format that is good for flash players- Is there a way to do this from command line in ffmpeg?

like image 362
minder42 Avatar asked Jan 29 '12 00:01

minder42


1 Answers

In ffmpeg audio media stream can be delayed with -itsoffset option as the following:

ffmpeg -i input_vid.mp4 -itsoffset 00:00:05.0 -i input_audio.wav 
    -vcodec copy -acodec copy output.mp4

To change video or audio codecs, specify them in -vcodec and -acodec options. This command will produce output video using h264 and mp3:

ffmpeg -i input_vid.mp4 -itsoffset 00:00:05.0 -i input_audio.wav 
    -vcodec libx264 -acodec libmp3lame output.mp4

See delaying the audio or the video for more information.

like image 50
Dmitry Shkuropatsky Avatar answered Oct 22 '22 02:10

Dmitry Shkuropatsky