VideoHelp Forum
+ Reply to Thread
Results 1 to 8 of 8
Thread
  1. Member
    Join Date
    Apr 2011
    Location
    U.S.A
    Search Comp PM
    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 ?
    Quote Quote  
  2. Member hech54's Avatar
    Join Date
    Jul 2001
    Location
    Yank in Europe
    Search PM
    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?
    Quote Quote  
  3. Member
    Join Date
    Apr 2011
    Location
    U.S.A
    Search Comp PM
    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.
    Quote Quote  
  4. Member
    Join Date
    Oct 2010
    Location
    England
    Search Comp PM
    Originally Posted by bhurt View Post
    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 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.
    Quote Quote  
  5. Member
    Join Date
    Apr 2011
    Location
    U.S.A
    Search Comp PM
    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.
    Quote Quote  
  6. Member
    Join Date
    Oct 2010
    Location
    England
    Search Comp PM
    Originally Posted by bhurt View Post
    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
    Quote Quote  
  7. personally I use 'hh:mm:ss.zzz' coding to specify delays with ffmpeg when multiplexing,... afaik that formating should also work when reencoding,..
    Quote Quote  
  8. 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"
    and
    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"
    and
    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"
    all do the same: they start the audio 5 seconds before the video

    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"
    -> cuts off the first 5 seconds of the video

    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"
    -> cuts of the first 5 seconds of the audio stream

    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"
    and
    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"
    -> both extend the playtime by 5 seconds, both video and audio end before


    => 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)
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!