I am attempting to convert an avi file to an mp4 with ffmpeg on which mediainfo reports a 216 ms audio delay for the audio track. The avi file has only one video and one audio stream. I am using ffmpeg version 0.8.10 on FC 16, the version available from rpmfusion. The command I am attempting is:
ffmpeg -i test.avi -itsoffset 0.216 -i test.avi -map 0.0 -map 1.1 -ab 128k -vcodec libx264 -r 25.00 -b 1268k -s 512x368 new.mp4
The command runs and produces a file but it still has the audio delay. I can get around it by transcoding the audio and video separately and inserting the delay with mp4box but I would prefer a single shorter step with just ffmpeg as I am not overly concerned with the audio quality. Any one know what I may be doing wrong ?
+ Reply to Thread
Results 1 to 8 of 8
-
-
I'll never understand the frustration people put themselves through with scripting/command line stuff. Why don't you just open the video in software like VDub or AviDemux, correct the audio skew....this way you can actually hear and see that the (often incorrectly reported by stuff like MediaInfo) skew values are correct?
-
The main reason is that I have many, many videos to convert and it would be far to tedius to transcode them manually. This time I had 252 which took 3 days to complete via a script. I wouldn't have had enough time available in a month to do it manually. 7 came out wrong with audio delay issues and took me a couple of hours to correct but had the above step worked, all would have been correct on the first run. Dealing with a few errors is easy compared to doing it manually. As I mentioned, it can be done in three steps and work as I know now after the fact, but that would have probably turned three automated days into 5, hence the reason for the question. Aside from that, As a Unix sysadmin by day, my one goal is to always do as little work as possible. I would rather spend an hour writing a script to do 5 minute manual fix than do it manually. That may sound stupid but invariably it saves time down the road as seemingly one off issues tend to repeat themselves.
-
The formatting of the map options looks wrong. Try using colons instead.
To delay the audio:
ffmpeg -i test.avi -itsoffset 0.216 -i test.avi -map 0:0 -map 1:1 -vcodec libx264 -r 25 -b:v 1268k -s 512x368 -acodec copy audio_delayed.mp4
To delay the video:
ffmpeg -i test.avi -itsoffset 0.216 -i test.avi -map 1:0 -map 0:1 -vcodec libx264 -r 25 -b:v 1268k -s 512x368 -acodec copy video_delayed.mp4
Caveats;
- you should be using a recent version of ffmpeg as the syntax has changed over time.
- itsoffset doesn't seem to support negative values, so use one of the examples above.
- if you're trying to automate the process, the hard-coded mapping options might cause problems with source files containing multiple audio/video streams. You might inadvertently get the directors commentary/wrong language or the encode may fail completely.
- encoding to aac is often problematic. I'd recommend either using '-acodec copy' to copy an existing aac stream without re-encoding, or transcode the audio to another format like mp3 using -acodec libmp3lame. -
Thanks Intracube for your response. With "-acodec copy" the audio worked but using libmp3lame it was still off. I'll run some more tests to make sure I am not doing something wrong.
-
No, it's my fault (and the stupidity of ffmpeg).
When copying the audio without transcoding, my examples in post #4 are correct. But when re-encoding the audio, the ffmpeg formatting needs to be different.
For the latter, the mapping options stay the same, and the itsoffset parameter does allow negative values... I overlooked this as I didn't try all possible combinations of delaying the audio/video and coping/transcoding.
These should work when converting the audio:
delays audio:
ffmpeg -i test.avi -itsoffset -1 -i test.avi -map 1:0 -map 0:1 -vcodec libx264 -r 25 -b:v 1268k -s 512x368 -acodec libmp3lame audio_delayed.mp4
delays video:
ffmpeg -i test.avi -itsoffset 1 -i test.avi -map 1:0 -map 0:1 -vcodec libx264 -r 25 -b:v 1268k -s 512x368 -acodec libmp3lame video_delayed.mp4
EDIT: fixed typo in this example
EDIT2: Both the examples above will shift the audio/video by one second.
Sorry if I've caused you an evening of banging your head on your desk
If my examples don't work as expected, get back to me - I still haven't tried all possible combinations.
I should add a final warning that this technique might not work with all container formats and on all media players/hardware devices. I'll try and find out if this is likely to be a problem.
--
and hech54, whatever you're thinking, don't say it!!Last edited by intracube; 21st May 2012 at 05:39. Reason: fixed typo, added formatting, more info
-
Code:
ffmpeg -y -ss -5 -i "H:\Output\video.avi" -i "H:\Output\audio.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -r 25 -f avi "H:\Output\test.avi"
Code:ffmpeg -y -itsoffset -00:00:05.0 -i "H:\Output\video.avi" -i "H:\Output\audio.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -r 25 -f avi "H:\Output\test.avi"
Code:ffmpeg -y -i "H:\Output\video.avi" -ss 5 -i "H:\Output\audio.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -r 25 -f avi "H:\Output\test.avi"
Code:ffmpeg -y -ss 5 -i "H:\Output\23_35_40_9910_07.avi" -i "H:\Output\iId_1_aid_1_DELAY_5000ms_23_35_40_9910_06.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -metadata handler_name="Hybrid 2013.05.10.1" -r 25 -f avi "H:\Output\test_ss5.avi"
Code:ffmpeg -y -i "H:\Output\video.avi" -ss -5 -i "H:\Output\audio.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -r 25 -f avi "H:\Output\test.avi"
Code:ffmpeg -y -itsoffset 00:00:05.0 -i "H:\Output\video.avi" -i "H:\Output\audio.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -r 25 -f avi "H:\Output\test.avi"
Code:ffmpeg -y -i "H:\Output\video.avi" -itsoffset 00:00:05.0 -i "H:\Output\audio.mp3" -vcodec copy -acodec copy -map 0:0 -map 1:0 -r 25 -f avi "H:\Output\test.avi"
=> haven't found a way to start the video 5 seconds before the audio
(btw. found no way to handle multiple delays with multiple audio streams)
Similar Threads
-
Best Program to Remove Audio from VOB and insert another Audio
By Zhuge Liang in forum Authoring (DVD)Replies: 1Last Post: 16th Feb 2012, 02:42 -
Using the DGAVCdec audio delay value when muxing with ffmpeg
By johnnyquid in forum Video ConversionReplies: 2Last Post: 23rd Jul 2011, 09:58 -
How do you insert an audio clip between audio clips in AVS Video Editor
By johnharlin in forum EditingReplies: 1Last Post: 19th Apr 2011, 01:17 -
Adding audio (wav) to video (avi) (want to delay start of audio)
By Lanton in forum Newbie / General discussionsReplies: 2Last Post: 12th Apr 2010, 12:50 -
ffmpeg: HowTo add option for a 'delay -x' in the param string ?
By vhelp in forum AudioReplies: 1Last Post: 17th Feb 2008, 12:52