PDA

View Full Version : MP4 : Match Audio Length to Video Length, [avs | neroAACenc | BePipe | mp4box ]


Umamio
11th March 2009, 05:58
Using NeroAACenc with an avs source through BePipe with the following arguments:

-ignorelength -lc -br %audio_bitrate% -if -

always produces an audio file with a duration a few milliseconds (1 or 2 frames with respect to the film) longer than the video.

I am wondering if there is a way to prevent this from occuring or to specify explicitly at what duration encoding of the audio should stop.

Alternatively, on muxing with mp4box is there a way to trim the audio to match video length? If so, can mp4box determine video length (in milliseconds) if fps is specified and automatically find the trim point, or do I need to provide this value?

XPecto
11th March 2009, 06:36
i've the Similar Problem.
Video Has the fixed length but audio kinda ripples 3 - 4 seconds when i play in mplayerc.

i tried to introduce delay and also tried to mux in mkv but...

Can Any body help us out??

Umamio
11th March 2009, 08:23
I don't know if we're having identical problems Xpecto, I don't have any trouble with sync or wobbling but audio duration is always greater than video duration by a very small amount
e.g:

Video: 00:00:45.480
Audio: 00:00:45.603

tebasuna51
11th March 2009, 13:05
There is a know bug in Bepipe (http://forum.doom9.org/showthread.php?p=903234#post903234).
The last buffer send to the encoder can be incomplete but is send complete, then there are extrabytes at end.
The RiffChunkSize in wav header is incorrect.

These extrabytes (zeroes) can have variable (but limited) length and produce one or more extra frames of silence at end of audio track.
Most the times isn't a problem, but you can use Wavi instead Bepipe to do the job.

XPecto
11th March 2009, 13:07
My original Clip is 25:12 long, which when played is normal. But when i extract streams i have something like this:
Video: 25:12
Audio: 25:17

tebasuna51
11th March 2009, 13:30
@XPecto, your problem never can be caused by Bepipe (the buffer used is less than 1 second).

Open other thread and specify the encoders/muxers used in your process.

XPecto
11th March 2009, 18:44
Alright!

Umamio
25th March 2009, 13:42
tebasuna51, I finally got around to trying wavi (v. 1.06 (http://sourceforge.net/projects/wavi-avi2wav/)) but I still have the problem of audio being approximately 100ms longer.

Running "info" on my avs clip indicates audio and video are of equal duration, I also tried with an extra "trim", hoping blindly that it might make some difference but sadly the issue remains.

http://emamio.dreamhosters.com/px/Doom9-AudioDurationIssue.png

Is it a known issue with wavi also or is it possible that specific types of source trigger the problem?

Avisynth Script
Clip="Huffy_Sample"
AviSource(Clip+".avi")
crop( 6, 6, -6, -6)
BilinearResize(192,144)
ConvertToYV12()
ConvertToMono
ResampleAudio(22050)

Batch File / Command Line

:::::::::
::Vars::
:::::::::
set audio_bitrate=22000
set BePipe="C:\Program Files\megui\tools\bepipe\BePipe.exe"
set neroAAC="C:\Program Files\megui\tools\neroAACenc\neroAACEnc.exe"
set x264="C:\Program Files\megui\tools\x264\x264.exe"
set MP4box="C:\Program Files\megui\tools\MP4Box\MP4box.exe"
set AP="C:\Program Files\megui\tools\atomicParsley\AtomicParsley.exe"
set MediaInfo="C:\Program Files\megui\tools\mediaInfo\MediaInfo.exe"
set Wavi="C:\Program Files\megui\tools\wavi\wavi.exe"
set encProfileV=--crf 22.2 --level 1.3 --no-cabac --partitions p8x8,b8x8
\ --qpmin 16 --vbv-bufsize 512 --vbv-maxrate 768 --me umh --merange 12 --threads auto --thread-input --sar 1:1 --progress
set encProfileA=-ignorelength -lc -br %audio_bitrate% -if -
set video_ext=264
set audio_ext=aac

:::::::::::::::::::::
:: Encode Audio ::
:::::::::::::::::::::
%Wavi% "Sample.avs" -|%NeroAAC% %encProfileA% -of "Sample.%audio_ext%"
:: Alternatively
:: %BePipe% --script "Import(^Sample.avs^)"|%NeroAAC% %encProfileA% -of "Sample.%audio_ext%"

:::::::::::::::::::::
:: Encode Video ::
:::::::::::::::::::::
%x264% %encProfileV% --output "Sample.%video_ext%" "Sample.avs"

::::::::::
:: Mux ::
::::::::::
%MP4box% -fps 25 -add "Sample.%video_ext%:name=Video:lang=en:par=1:1" -add "Sample.%audio_ext%:name=Audio:lang=en" "Sample.mp4" -new -v

:::::::::::::::::::::::::
:: Delete Temp Files ::
:::::::::::::::::::::::::
del "Sample.%audio_ext%"
del "Sample.%video_ext%"
del "Sample.avs"

::::::::::::::::::::::::
:: Add Itunes Tags ::
::::::::::::::::::::::::
%AP% "Sample.mp4" --stik "TV Show" --TVShowName "How to do Cartwheels While Eating Spinach" --overWrite

:::::::::::::::::::::::::
:: Generate File Info ::
:::::::::::::::::::::::::
%MediaInfo% --output=HTML -f "Sample.mp4" --LogFile="Sample.htm"

tebasuna51
25th March 2009, 14:03
The problem was solved in wavi: http://forum.doom9.org/showthread.php?p=1018317#post1018317

Maybe is a decoder issue, please put your avs.

Umamio
25th March 2009, 14:19
I get the same results using DirectShowSource (goes through ffdshow)
(edited previous post to include avs script and batch file)

Edit:
I've also just tried wavi on a completely unrelated source file (DVD material)
Using NicAC3Source for the audio and the same audio video duration discrepancy is produced.

I will try again without the ConvertToMono or AudioResample and see if there is a difference

Results of Trial with Different Material (using same batch file):

Sample.avs

v1 = DGdecode_Mpeg2Source("D1.d2v")
a1 = NicAC3Source("D1 T80 2_0ch 256Kbps DELAY 0ms.ac3")

S1 = AudioDub(v1,a1)

S1.Trim(0,1400)

http://emamio.dreamhosters.com/px/Doom9-AudioDurationIssue-2.png

tebasuna51
25th March 2009, 16:55
But you are talking about MediaInfo info!
It is not accurate.

Decode the m4a file with NeroAacDec and you obtain the 56.04 seconds wav file (tested).

Some aac decoders can also produce little delay and end silence.

BTW, use the last:
* Nero AAC Encoder *
* Copyright 2008 Nero AG *
* All Rights Reserved Worldwide *
* *
* Package build date: Sep 17 2008 *
* Package version: 1.3.3.0 *

and use a proper:
set audio_ext=m4a
because NeroAacEnc can't output .aac files (ADTS headers, or others), always output audio in mp4 container

Umamio
25th March 2009, 17:52
Updated my neroAACenc and changed the file extension.

The problem isn't so much the mediaInfo results but that Quicktime (erroneously) reports the same audio duration and its default behaviour is to show white frames while the extra (non-existent?) audio plays to completion.

I do not mind, as I do not use quicktime, but the people receiving the material use quicktime exclusively and, as it's usually very short form content (< 15s), they notice and are bothered by the extra white frames.

I know it's not up to you to fix quicktime or mediainfo, but is there a way I can truncate the reported audio length to these applications? Or a way to specify the exact audio length during muxing that you are aware of?

tebasuna51
26th March 2009, 03:10
I can't help you about this.

I know there are problems between QuickTime and Nero encoder, this post is very similar: http://www.hydrogenaudio.org/forums/index.php?showtopic=68279&view=findpost&p=606632

Read also this: http://forum.doom9.org/showthread.php?p=1238262#post1238262

Umamio
26th March 2009, 11:09
Thanks for the links! I will try and find out if there is a switch to disable writing gapless info to chapter list.

By the way, aside from the .net framework dependency and the extrabytes, what are the main technical differences between bepipe and wavi?

tebasuna51
26th March 2009, 13:35
- Last Bepipe code is missing, then we can't modify anything.
- Bepipe can parse the command line parameters to write a temporal .avs file to send to AviSynth
- Wavi have the code available at SourceForge.
- You need write an avs file for Wavi.
- The last Wavi versions are lightly more quick than Bepipe (at least for me)
- Wavi support some parameters to control the audio header:
/R - Write a raw file of samples without the WAV header.

/X - Write an extended WAV header containing the default
channel mask for multi-channel audio.

/M <mask> - Write an extended WAV header containing the
specified channel mask for multi-channel audio.

- You can use .avi files instead .avs, then the default audio VFW decoder is used to output the uncompressed audio data.