Conquerist
6th May 2007, 06:07
Hi,
I am trying to encode movies and video files, some of which are in x264+ac3 mkv and some are xvid+vbr mp3 avis, to an ipod. I am personnaly not a big fan of apple and their products, but this is my dad's and i'm just trying to do him a favor. iTunes and converters such as videora have caused me such annoyance that i've written my own batch script to transcode files to x264+aac mp4.
Here's the script (the input file is %1, which I just drag and drop onto the batch file's icon):
@echo off
::set working directory
F:
cd "temp\ipod x264"
::find aspect ratio and crop accordingly
::get width
MediaInfo.exe --Inform=Video;file://x.txt %1 > tempfile
copy setx.bat + tempfile $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat
del tempfile
::get hight
MediaInfo.exe --Inform=Video;file://y.txt %1 > tempfile
copy sety.bat + tempfile $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat
del tempfile
::calculate new height to crop file to 320xYYY. i could also encode it at 320x240 and use a SAR flag,
but that doesn't make sense, because the ipod screen is only 320x240 big.
set /a ar = (1000 * x) / y
set /a resy = (320 * 1000) / ar
::find out if a space is in a filename, because otherwise avisynth goes crazy with missing/not missing quotation marks
::this is necesarry because otherwise either files without or with spaces would not work. i've tried every combination
of carot marks and quotation marks around the %1 and i've found this to be the only working solution
set filename=%1
set quote=%filename:~-1%
set quote=%quote:"=%
::write avisynth scripts for the audio and the video
if %quote%a == a (
echo DirectShowSource^(%1^).BilinearResize^(320,%resy%^).ConvertToYV12^(^) > video.avs
echo DirectShowSource^(%1^).Normalize > audio.avs
)
if not %quote%a == a (
echo DirectShowSource^("%1"^).BilinearResize^(320,%resy%^).ConvertToYV12^(^) > video.avs
echo DirectShowSource^("%1"^).Normalize > audio.avs
)
::encode to ipod-spec h264 video in a mp4 container. modified based on megui ipod profile
x264 --pass 1 --bitrate 768 --stats ".stats" --level 1.3 --no-cabac --subme 6 --analyse p8x8,b8x8
--qpmin 16 --vbv-maxrate 768 --me umh --merange 12 --threads auto --thread-input --progress
--no-psnr --output NUL "F:\Temp\ipod x264\video.avs"
x264 --pass 2 --bitrate 768 --stats ".stats" --level 1.3 --no-cabac --subme 6 --analyse p8x8,b8x8
--qpmin 16 --vbv-maxrate 768 --me umh --merange 12 --threads auto --thread-input --progress
--no-psnr --output "F:\Temp\ipod x264\video.mp4" "F:\Temp\ipod x264\video.avs"
::encode audio into aac with the nero aac encoder
bepipe.exe --script "import(^audio.avs^)" | "neroAacEnc.exe" -br 128000 -lc -if - -of audio.mp4
::multiplex the audio and the video
MP4Box.exe -new -add video.mp4#video -add audio.mp4#audio muxed.mp4
::write the file-info, for debug purposes
mediainfo %1 > original.txt
mediainfo video.mp4 > video.txt
mediainfo audio.mp4 > audio.txt
mediainfo muxed.mp4 > muxed.txt
::keep temp files for debug purposes
goto end
::delete temp files
del .stats
del video.mp4
del audio.mp4
del video.avs
del audio.avs
:end
pause
Please say so if any part of the script seems unclear.
Enough of the introduction; Here's my problem: everything with x264+ac3 in mkv converts without problems. However, with avis, i get a big error!
First and foremost, the encoded video (both video.mp4 and muxed.mp4) plays too fast. The remaining time is filled with a repeat of the last second of video. I know that it is the video that plays too fast and not the audio that plays too slow, because i've tried all combinations of dubbing the original avi, the avs, video.mp4 (the x264 output) and muxed.mp4 (the mp4box output) with all audios (original avi, audio.avs, audio.mp4, muxed.mp4) using mpc's open file -> dub feature. All of the combinations which use either video.mp4 or muxed.mp4 for the video play too fast, which causes the audio to be out of sync. The error is along the scale of 1-2 second in a 21 minute file.
Even though I am not a 100% certain that x264 is to blame, I believe it is, because it is the output of x264, not of bepipe or avisynth or neroeaacenc or mp4box which causes the wrong output.
I thought that an incorrect fps in x264 was to blame. Therefore, I created the mediainfo > xxx.txt lines to see the fps at all stages of the conversion. It was always 23.976 (the NTSC framerate). So i don't think that's the cause of my problem. I even specified the framerate of 23.976 in x264 using the --fps switch and got the same problem.
The problem might also be vbr audio in avi, but because i use directshowsource (which uses directshow) and not avisource (which uses vfw) in avisynth, i don' think that's a problem either. I am sure it is not a problem, because dubbing the original avi file with audio.mp4 is in sync.
Does anyone know what my problem is?
Thank you for reading this long post and thanks in advance for all your solution/help/advice of which i've found so much just by searchign the doom9 forums. I apologize if this has been posted and answered before, but I couldn't find a similar problem using the search feature.
Attached is the output of the media info > txt functions. Note the inconsistent play lengths on all of the files.
PS: i get the same problem if i encode it using megui and use the integrated mp4box gui instead of my own script
I am trying to encode movies and video files, some of which are in x264+ac3 mkv and some are xvid+vbr mp3 avis, to an ipod. I am personnaly not a big fan of apple and their products, but this is my dad's and i'm just trying to do him a favor. iTunes and converters such as videora have caused me such annoyance that i've written my own batch script to transcode files to x264+aac mp4.
Here's the script (the input file is %1, which I just drag and drop onto the batch file's icon):
@echo off
::set working directory
F:
cd "temp\ipod x264"
::find aspect ratio and crop accordingly
::get width
MediaInfo.exe --Inform=Video;file://x.txt %1 > tempfile
copy setx.bat + tempfile $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat
del tempfile
::get hight
MediaInfo.exe --Inform=Video;file://y.txt %1 > tempfile
copy sety.bat + tempfile $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat
del tempfile
::calculate new height to crop file to 320xYYY. i could also encode it at 320x240 and use a SAR flag,
but that doesn't make sense, because the ipod screen is only 320x240 big.
set /a ar = (1000 * x) / y
set /a resy = (320 * 1000) / ar
::find out if a space is in a filename, because otherwise avisynth goes crazy with missing/not missing quotation marks
::this is necesarry because otherwise either files without or with spaces would not work. i've tried every combination
of carot marks and quotation marks around the %1 and i've found this to be the only working solution
set filename=%1
set quote=%filename:~-1%
set quote=%quote:"=%
::write avisynth scripts for the audio and the video
if %quote%a == a (
echo DirectShowSource^(%1^).BilinearResize^(320,%resy%^).ConvertToYV12^(^) > video.avs
echo DirectShowSource^(%1^).Normalize > audio.avs
)
if not %quote%a == a (
echo DirectShowSource^("%1"^).BilinearResize^(320,%resy%^).ConvertToYV12^(^) > video.avs
echo DirectShowSource^("%1"^).Normalize > audio.avs
)
::encode to ipod-spec h264 video in a mp4 container. modified based on megui ipod profile
x264 --pass 1 --bitrate 768 --stats ".stats" --level 1.3 --no-cabac --subme 6 --analyse p8x8,b8x8
--qpmin 16 --vbv-maxrate 768 --me umh --merange 12 --threads auto --thread-input --progress
--no-psnr --output NUL "F:\Temp\ipod x264\video.avs"
x264 --pass 2 --bitrate 768 --stats ".stats" --level 1.3 --no-cabac --subme 6 --analyse p8x8,b8x8
--qpmin 16 --vbv-maxrate 768 --me umh --merange 12 --threads auto --thread-input --progress
--no-psnr --output "F:\Temp\ipod x264\video.mp4" "F:\Temp\ipod x264\video.avs"
::encode audio into aac with the nero aac encoder
bepipe.exe --script "import(^audio.avs^)" | "neroAacEnc.exe" -br 128000 -lc -if - -of audio.mp4
::multiplex the audio and the video
MP4Box.exe -new -add video.mp4#video -add audio.mp4#audio muxed.mp4
::write the file-info, for debug purposes
mediainfo %1 > original.txt
mediainfo video.mp4 > video.txt
mediainfo audio.mp4 > audio.txt
mediainfo muxed.mp4 > muxed.txt
::keep temp files for debug purposes
goto end
::delete temp files
del .stats
del video.mp4
del audio.mp4
del video.avs
del audio.avs
:end
pause
Please say so if any part of the script seems unclear.
Enough of the introduction; Here's my problem: everything with x264+ac3 in mkv converts without problems. However, with avis, i get a big error!
First and foremost, the encoded video (both video.mp4 and muxed.mp4) plays too fast. The remaining time is filled with a repeat of the last second of video. I know that it is the video that plays too fast and not the audio that plays too slow, because i've tried all combinations of dubbing the original avi, the avs, video.mp4 (the x264 output) and muxed.mp4 (the mp4box output) with all audios (original avi, audio.avs, audio.mp4, muxed.mp4) using mpc's open file -> dub feature. All of the combinations which use either video.mp4 or muxed.mp4 for the video play too fast, which causes the audio to be out of sync. The error is along the scale of 1-2 second in a 21 minute file.
Even though I am not a 100% certain that x264 is to blame, I believe it is, because it is the output of x264, not of bepipe or avisynth or neroeaacenc or mp4box which causes the wrong output.
I thought that an incorrect fps in x264 was to blame. Therefore, I created the mediainfo > xxx.txt lines to see the fps at all stages of the conversion. It was always 23.976 (the NTSC framerate). So i don't think that's the cause of my problem. I even specified the framerate of 23.976 in x264 using the --fps switch and got the same problem.
The problem might also be vbr audio in avi, but because i use directshowsource (which uses directshow) and not avisource (which uses vfw) in avisynth, i don' think that's a problem either. I am sure it is not a problem, because dubbing the original avi file with audio.mp4 is in sync.
Does anyone know what my problem is?
Thank you for reading this long post and thanks in advance for all your solution/help/advice of which i've found so much just by searchign the doom9 forums. I apologize if this has been posted and answered before, but I couldn't find a similar problem using the search feature.
Attached is the output of the media info > txt functions. Note the inconsistent play lengths on all of the files.
PS: i get the same problem if i encode it using megui and use the integrated mp4box gui instead of my own script