hi ****
from a input.mp4 file, I have do a batch that generate
input.avi
input.wav
The input.avi is generated by a avisynth+virtualdub procedure
the input.wav is generated using ffmpeg with this commanline
v:\automazioneclip\core\ffmpeg.exe -y -i input.mp4 -af "pan=stereo:c0=c0:c1=c1,volume=1" -c:a pcm_s16le input.wav
but sometimes I get that the lenght of the audio file is slightly different between the one the video files: 1 or 2 or 3 frames more or less
Please is there a way to do that:
once generated the .avi file, ffmpeg chech the lenght of the input.avi and do the input.wav so that it match the same lenght of the input.avi
So finally the lenght of the audio part is exactly the same of the video part
Can I do that with ffmpeg? thanks
+ Reply to Thread
Results 1 to 6 of 6
-
-
You really ought to figure out the source of that difference before you decide what to do about it. If the audio in the original mp4 begins a few frames before the video you'd really need to cut a section from the beginning, if it extends a few frames after you'd cut from the end.
I too think you should use AVISynth for this, it will automatically convert the audio to PCM and output it into the AVI completely in sync with the video, adding or removing samples to fit. -
At the moment I cannot test if is in sync or out of sync: however is not very important because this is a routine of the batch that consider only the loser input files. The main input are .mxf or mp4 gopro files: they are shure in sync and audio-no problem.
The routine of the batch that consider loser files is:
[...]
Code::Make_File_generic <VCF_FILENAME> <AVS_FILENAME> <FILENAME> <ORG_FILENAME> echo generic routine Set "genericProgressive=0" Set "genericInterlaced=0" Set "genericFPS25=0" Set "goproFile=0" v:\automazioneclip\virtualdub\mediainfo.exe %4 dumpinfo:unicodefile.txt TYPE unicodefile.txt>mediainfo.txt findstr /c:"Scan type : Progressive" "mediainfo.txt" IF NOT ERRORLEVEL 1 (set "genericProgressive=1") findstr /c:"Scan type : Interlaced" "mediainfo.txt" IF NOT ERRORLEVEL 1 (set "genericInterlaced=1") findstr /c:"Frame rate : 25.000 fps" "mediainfo.txt" IF NOT ERRORLEVEL 1 (set "genericFPS25=1") findstr /c:"Title : GoPro AVC" "mediainfo.txt" IF NOT ERRORLEVEL 1 (set "goproFile=1") findstr /c:"Scan type : MBAFF" "mediainfo.txt" IF NOT ERRORLEVEL 1 (set "MBAAF=1") rem *** TRY extract audio from *.* OTHER TYPE uso di FFMBC anziche ffmpeg perchè così non ce errore di 1 frame piu corto rispetto alla traccia video*** rem v:\automazioneclip\core\ffmpeg.exe -y -i %4 -map_channel 0.1.0 -c:a pcm_s16le "%DestFolder%\%~n1_SD.wav" rem v:\automazioneclip\core\ffmbc -y -i %4 -map 0.1 -acodec pcm_s16le "%DestFolder%\%~n1_gen_SD.wav" rem *** TRY extract audio from .MXF IMX SD FILE *** Set "TokenS=0" IF "%~x4"==".MXF" Set "TokenS=1" IF "%~x4"==".mxf" Set "TokenS=1" If "%TokenS%"=="1" (if "%V_Width%"=="720" (v:\automazioneclip\core\ffmpeg.exe -loglevel fatal -y -i %4 -map_channel 0.1.0 -map_channel 0.1.1 -af "volume=volume=9dB:precision=fixed" "%DestFolder%\%~n1_SD.wav")) If "%TokenS%"=="1" (if "%V_Width%"=="720" (v:\automazioneclip\core\ffmpeg.exe -loglevel fatal -y -i %4 -map_channel 0.1.2 -map_channel 0.1.3 -af "volume=volume=9dB:precision=fixed" "%DestFolder%\%~n1ch3ch4_SD.wav")) rem *** TRY extract audio from .MXF XDCAM-HD 4:2:2 FILE *** Set "TokenS=0" IF "%~x4"==".MXF" Set "TokenS=1" IF "%~x4"==".mxf" Set "TokenS=1" If "%TokenS%"=="1" (if "%V_Width%"=="1920" (v:\automazioneclip\core\ffmpeg.exe -y -i %4 -filter_complex "[0:1] [0:2] amerge,volume=1.5" -c:a pcm_s16le "%DestFolder%\%~n1_SD.wav")) If "%TokenS%"=="1" (if "%V_Width%"=="1920" (v:\automazioneclip\core\ffmpeg.exe -y -i %4 -filter_complex "[0:3] [0:4] amerge,volume=1.5" -c:a pcm_s16le "%DestFolder%\%~n1ch3ch4_SD.wav")) rem *** TRY extract audio from .MXF DVCAM *** Set "TokenS=0" IF "%~x4"==".MXF" Set "TokenS=1" IF "%~x4"==".mxf" Set "TokenS=1" If "%TokenS%"=="1" (if "%dvcam%"=="1" (v:\automazioneclip\core\ffmpeg.exe -y -i %4 -filter_complex "[0:1] [0:2] amerge,volume=1.5" -c:a pcm_s16le "%DestFolder%\%~n1_SD.wav")) If "%TokenS%"=="1" (if "%dvcam%"=="1" (v:\automazioneclip\core\ffmpeg.exe -y -i %4 -filter_complex "[0:3] [0:4] amerge,volume=1.5" -c:a pcm_s16le "%DestFolder%\%~n1ch3ch4_SD.wav")) rem *** TRY extract audio from GOPRO MP4 file *** Set "TokenS=0" IF "%~x4"==".MP4" Set "TokenS=1" IF "%~x4"==".mp4" Set "TokenS=1" IF "%goproFile%"=="1" Set "TokenS=1" If "%TokenS%"=="1" (v:\automazioneclip\core\ffmpeg.exe -y -i %4 -filter_complex "[0:1] volume=1.5" -c:a pcm_s16le "%DestFolder%\%~n1_SD.wav") rem *** TRY extract audio from *.* OTHER TYPE *** v:\automazioneclip\core\ffmpeg.exe -y -i %4 -af "pan=stereo:c0=c0:c1=c1,volume=1" -c:a pcm_s16le "%DestFolder%\%~n1_gen_SD.wav" echo *** from various format to MorganMJPEG AVI SD 720x576i@25fps using Avisynth+Virtualdub *** rem ***Make The .vcf Script File*** echo VirtualDub.audio.SetSource^(0^);>%1 echo VirtualDub.audio.SetMode^(0^);>>%1 echo VirtualDub.audio.SetInterleave^(1,500,1,0,0^);>>%1 echo VirtualDub.audio.SetClipMode^(1,1^);>>%1 echo VirtualDub.audio.SetEditMode^(1^);>>%1 echo VirtualDub.audio.SetConversion^(0,0,0,0,0^);>>%1 echo VirtualDub.audio.SetVolume^(^);>>%1 echo VirtualDub.audio.SetCompression^(^);>>%1 echo VirtualDub.audio.EnableFilterGraph^(0^);>>%1 echo VirtualDub.video.SetInputFormat^(0^);>>%1 echo VirtualDub.video.SetOutputFormat^(11^);>>%1 echo VirtualDub.video.SetMode^(1^);>>%1 echo VirtualDub.video.SetSmartRendering^(0^);>>%1 echo VirtualDub.video.SetPreserveEmptyFrames^(0^);>>%1 echo VirtualDub.video.SetFrameRate2^(0,0,1^);>>%1 echo VirtualDub.video.SetIVTC^(0, 0, 0, 0^);>>%1 echo VirtualDub.video.SetCompression^(0x6a6d7674,0,10000,0^);>>%1 echo VirtualDub.video.SetCompData^(28,"TUpQRxgAAAAAAAAAAgAAAAgAAAACAAAAAQAAAA=="^);>>%1 echo VirtualDub.video.filters.Clear^(^);>>%1 echo VirtualDub.video.filters.Add^("deinterlace"^);>>%1 echo VirtualDub.video.filters.instance[0].Config^(0,1,1^);>>%1 echo VirtualDub.video.filters.Add^("resize"^);>>%1 echo VirtualDub.video.filters.instance[1].Config^(720,576,0,4,3,0,320,240,4,3,0,135,1,0x000000^);>>%1 echo VirtualDub.video.filters.Add^("interlace"^);>>%1 echo VirtualDub.video.filters.instance[2].Config^(0, 0^);>>%1 echo VirtualDub.audio.filters.Clear^(^);>>%1 echo VirtualDub.audio.filters.Clear^(^);>>%1 if NOT "%TimeCode%"=="" echo VirtualDub.project.ClearTextInfo^(^);>>%1 if NOT "%TimeCode%"=="" echo VirtualDub.project.AddTextInfo^("ISMP", "%TIMECODE%"^);>>%1 echo VirtualDub.SaveAVI^("%DestFolder%\\%~n1_gen_SD.avi"^);>>%1 echo VirtualDub.Close^(^);>>%1 rem ***Make The .avs Script File*** echo Import("C:\Program Files\AviSynth\plugins\IResize.avsi")>%2 echo FFVideoSource^(%4^)>>%2 IF "%genericProgressive%"=="1" (echo ConvertToYUY2^(interlaced=false^)>>%2) else (echo ConvertToYUY2^(interlaced=true^)>>%2) if "%dvcam%"=="1" echo ReverseFieldDominance^(^)>>%2 echo src = last >>%2 echo src = src.width==720^&^&src.height==608?src.crop^(0,32,0,0^):src >>%2 echo src = src.width==1920 ^&^& src.height==1088 ? src.crop^(0,0,1920,1080^): src >>%2 echo src = src.width^>720 ^|^| src.height^>608?src.ColorMatrix^(mode="Rec.709->Rec.601"^): src >>%2 Set "TokenS=0" IF "%goproFile%"=="1" set "TokenS=1" IF "%MBAAF%"=="1" set "TokenS=1" IF "%TokenS%"=="1" set "goproFileORmbaaf=1" IF "%goproFileORmbaaf%"=="1" (echo src.width!=720 ^|^| src.height!=576 ? src.IResize^(720,576^): src >>%2) else (echo src.width!=720 ^|^| src.height!=576 ? src.LanczosResize^(720,576^): src >>%2) IF NOT "%genericFPS25%"=="1" echo SmoothFPS2^(50000,1000^)>>%2 IF NOT "%genericFPS25%"=="1" echo AssumeTFF^(^).SeparateFields^(^).SelectEvery^(4,0,3^).Weave^(^) >>%2 echo AssumeFPS^(25^)>>%2 echo processing source file %4 rem ***Call VirtualDub*** if NOT EXIST %VD_LOC% ( echo Um, where the cat-hell is VirtualDubMod? pause ) %VD_LOC% /min %2 /s %1 for %%v in ("%DestFolder%\\%~n1_gen_SD.avi") do ( if %%~zv LSS 128 ( echo ERROR!!! Extra Small File Size Detected!!! pause ) ) v:\automazioneclip\virtualdub\cfourcc.exe -i "%CD%\%~n1_gen_SD.avi" -u MJPG -d MJPG DEL "%DestFolder%\*.ffindex" DEL "%DestFolder%\*.VCF" DEL "%DestFolder%\*.avs" v:\automazioneclip\virtualdub\cfourcc.exe -i "%CD%\%~n1_gen_SD.avi" -u MJPG -d MJPG goto :eof
This treat all .flv, mpeg-in-avi, asf, mpg etc.. files that need to be transcoded into pal (or HD in another script) and is not too important the audio-video sync
I can move the line
ffmpeg.exe -y -i %4 -af "pan=stereo:c0=c0:c1=c1,volume=1" -c:a pcm_s16le "%DestFolder%\%~n1_gen_SD.wav
after the video process so that I have the input.avi files before the ffmpeg audio elaboration
So I would say: is there a way to tell to ffmpeg that have to cut (or fill) the audio file so that duration is the same of the video file? of course without "stretch" the audio, is enought fill or cut with silence in audio
For example: virtualdub have jet generate a video file that have duration of 25 second and 3 frames, but ffmpeg generate a file of 25seconds and 5 frames ----> so ffmpeg have to cut 2 frames at the end so that duration of the audio .wav file is exactly the same of the video .avi fileLast edited by marcorocchini; 25th Oct 2014 at 13:08.