Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
21st October 2011, 07:05 | #1 | Link |
Registered User
Join Date: Jul 2011
Posts: 224
|
Guide AviSynth encode x264 trim splice cut commercials autocrop srt subtitle sync
This guide shows how to use AviSynth to encode x264, and cut out commercials in the process.
You may need to adjust the paths or rename files to reflect where you installed AviSynth, I installed AviSynth directly to my 'E:\' partition eg: E:\AviSynth E:\AviSynth\plugins My batch files are directly in my AviSynth folder: E:\AviSynth\bd.bat E:\AviSynth\bd-go.bat software required: Code:
AviSynth 2.6 ffms2.dll (put in AvisSynth plugins folder) NicAudio.dll (put in AvisSynth plugins folder) AutoCrop.dll (put in AvisSynth plugins folder) ffmpeg (E:\AviSynth\ffmpeg\bin\ffmpeg.exe) mkvtoolnix (E:\AviSynth\mkvtoolnix\mkvmerge.exe) x264 (E:\AviSynth\x264.exe) avs2pipe (E:\AviSynth\avs2pipe.exe) http://forum.doom9.org/showthread.php?p=1527344 trimsrt (E:\AviSynth\trimsrt.exe) http://forum.doom9.org/showthread.php?t=162828 neroAacEnc (E:\AviSynth\neroAacEnc.exe) *or* qaac (E:\AviSynth\qaac.exe) There are also some codecs that are required, but if you install CCCP http://www.cccp-project.net/ it will take care of them all. bd.bat <in-file> <fps> <audio-stream-id> <audio-channels> <out-file> <frame1A> <frame1B> <frame2A> <frame2B> example: bd.bat E:\yyh\BDMV\STREAM\00039.m2ts 23.976 0:2 6 004 2832 16675 16872 31270 The above line will take me from the 00039.m2ts file to a trimmed, spliced, cropped, and x264 encoded 004.mkv file with Quicktime TVBR AAC encoded audio (or neroaac), and a trim and adjusted .srt subtitle file if applicable. to determine which audio stream you want and how many channels it has use ffmpeg (for 5.1 use 6, for stereo use 2): Code:
E:\AviSynth\ffmpeg\bin\ffmpeg -i E:\yyh\BDMV\STREAM\00036.m2ts Code:
SET FPS=%~2 if "%~2"=="23.976" SET FPS=24000/1001 del bd.avs echo A = RaWavSource("E:\AviSynth\job.wav")>>bd.avs echo V = FFVideoSource("E:\AviSynth\job.mkv")>>bd.avs echo AudioDub(V, A)>>bd.avs if not "%~6"=="" echo AlignedSplice(Trim(%6, %7), Trim(%8, %9))>>bd.avs echo AutoCrop(0,2,2,0,0,0,0,30,5,0,-1,0)>>bd.avs E:\AviSynth\ffmpeg\bin\ffmpeg -i %1 -vn -sn -y -map %3 -drc_scale 0 -ac %4 -async 1 -acodec pcm_s24le -f wav job.wav E:\AviSynth\ffmpeg\bin\ffmpeg -i %1 -an -sn -y -vcodec copy -f rawvideo job.h264 E:\AviSynth\mkvtoolnix\mkvmerge -o E:\AviSynth\job.mkv --engage keep_bitstream_ar_info --default-duration 0:%FPS%fps --compression 0:none -d 0 -A -S -T --no-global-tags --no-chapters E:\AviSynth\job.h264 E:\AviSynth\avs2pipe -wav bd.avs | qaac --tvbr 90 --quality 2 --rate keep --ignorelength - -o job.m4a ::E:\AviSynth\avs2pipe -wav bd.avs | neroAacEnc.exe -q 0.5 -ignorelength -if - -of job.m4a E:\AviSynth\x264 --preset veryslow --crf 22.0 --ref 5 --bframes 16 --no-fast-pskip --output "jobz.mkv" "E:\AviSynth\bd.avs" E:\AviSynth\mkvtoolnix\mkvmerge -o E:\AviSynth\%5.mkv --engage keep_bitstream_ar_info --compression 1:none -d 1 -A -S -T --no-global-tags --no-chapters E:\AviSynth\jobz.mkv --compression 1:none -a 1 -D -S -T --no-global-tags --no-chapters E:\AviSynth\job.m4a ::E:\AviSynth\trimsrt -i %5.srt -f %FPS% -t %6,%7,%8,%9 ::E:\AviSynth\mkvtoolnix\mkvmerge -o E:\AviSynth\%5.mkv --engage keep_bitstream_ar_info --compression 1:none -d 1 -A -S -T --no-global-tags --no-chapters E:\AviSynth\jobz.mkv --compression 1:none -a 1 -D -S -T --no-global-tags --no-chapters E:\AviSynth\job.m4a --compression 0:none -s 0 -D -A -T --no-global-tags --no-chapters E:\AviSynth\%5new.srt I use --crf 22.0 for Bluray and --crf 20.0 for DVD, some people will use lower or higher, you have to figure out what works for you: https://trac.handbrake.fr/wiki/ConstantQuality To make use of trimsrt uncomment the last two lines in bd.bat by removing the two :: from the beginning of that line, and comment out the mkvmerge line before the last two lines To use trimsrt you have to have the .srt file in the same output directory as the other files (job.mkv, job.wav, bd.bat). Also the .srt file has to have the same filename as your output filename for the finished mkv bd.bat E:\yyh\BDMV\STREAM\00039.m2ts 004 2832 16675 16872 31270 (in this example the output file name is 004, so you would need to name the .srt file 004.srt prior to running bd.bat or bd-go.bat, which means you have to prepare your subs first) With the bd.bat batch file I can queue up as many jobs as I want, by making another batch file that calls bd.bat eg: bd-go.bat: Code:
CALL bd.bat E:\yyh\BDMV\STREAM\00036.m2ts 23.976 0:2 6 001 2112 17685 17854 30940 CALL bd.bat E:\yyh\BDMV\STREAM\00037.m2ts 23.976 0:2 6 002 2833 16127 16296 31296 CALL bd.bat E:\yyh\BDMV\STREAM\00038.m2ts 23.976 0:2 6 003 2832 16463 16632 31295 CALL bd.bat E:\yyh\BDMV\STREAM\00039.m2ts 23.976 0:2 6 004 2832 16703 16872 31295 CALL bd.bat E:\yyh\BDMV\STREAM\00040.m2ts 23.976 0:2 6 005 2856 17471 17640 31295 CALL bd.bat E:\yyh\BDMV\STREAM\00041.m2ts 23.976 0:2 6 006 2832 16727 16896 31295 CALL bd.bat E:\yyh\BDMV\STREAM\00042.m2ts 23.976 0:2 6 007 2856 16367 16536 31295 CALL bd.bat E:\yyh\BDMV\STREAM\00043.m2ts 23.976 0:2 6 008 2856 15935 16104 31295 CALL bd.bat <in-file> <fps> <audio-stream-id> <audio-channels> <out-file> <frame1A> <frame1B> <frame2A> <frame2B> <frame1A> <frame1B> is the frame range to keep before the commercial and, <frame2A> <frame2B> is the frame range to keep after the commercial To figure out the frame range that I needed I used Avidemux, but you could also use AvsP: http://avisynth.org/qwerpoi/ (it has a trim editor with a preview window so you can see exactly what you will get) The Frame Range is optional, if you would like to encode the entire file you can (although if you dont need the frame ranges there are easier ways to do all this) Last edited by xekon; 27th October 2011 at 07:03. |
21st October 2011, 15:49 | #2 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
- If you use:
... echo A = RaWavSource("E:\AviSynth\job.wav")>>bd.avs ... E:\AviSynth\eac3to\eac3to %1 2: job.mkv 3: job.wav ... This work for all audio input: pcm, dts, dtshd, dtsma, truehd, ac3, eac3 (RaWavSource included in NicAudio.dll) - For what: mkvmerge.exe ... --aac-is-sbr 1:1 ? When you encode with neroAacEnc.exe -q 0.5 the output is always AAC-LC, without SBR part.
__________________
BeHappy, AviSynth audio transcoder. |
21st October 2011, 18:50 | #3 | Link |
Registered User
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
|
you have to be very careful when trim...often commercial audio is 2.0 ac3 and the tv show is 5.1 ac3...even one 2.0 ac3 frame will ruin the audio...anyway some tv shows have the "previously on" part as 2.0 ac3...
_
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note... Visit The Land Of Dracula (Romania - EU)! Last edited by b66pak; 21st October 2011 at 19:10. |
21st October 2011, 20:38 | #4 | Link | ||
Registered User
Join Date: Jul 2011
Posts: 224
|
Quote:
When you use eac3to to go from one format to another like .wav does it do so without quality loss? ( IIRC eac3to to .wav outputs a stereo/2 channel wav file right? so you would lose the 5.1 audio) Quote:
running the command below shows all streams for a file: eac3to.exe E:\yyh\BDMV\STREAM\00039.m2ts For the tv shows that you are talking about, this would show if there was a 2.0 ac3 stream correct? Is there a method you use before trimming to check if there is a segment that uses 2.0 ac3? Also how do you go about making sure your trim avoids the 2.0 ac3? do you just listen to the quality to determine, or is there a more definitive test. Last edited by xekon; 22nd October 2011 at 05:56. |
||
21st October 2011, 20:54 | #5 | Link |
Registered User
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
|
you have to demux the .ac3 and check it with delaycut...or use ffmpeg for decoding:
Code:
ffmpeg -i tvshow.m2ts -vn -sn -drc_scale 0 -ac 6 -acodec pcm_s24le -f wav tvshow.wav -async 1
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note... Visit The Land Of Dracula (Romania - EU)! Last edited by b66pak; 21st October 2011 at 21:00. |
22nd October 2011, 00:16 | #6 | Link |
Registered User
Join Date: Jul 2011
Posts: 224
|
Thanks for the reply!
I changed the batch file so that it avoids the issue (I have never ran into the problem you describe, but I have not ripped and encoded many series yet.) I no longer decode/demux using eac3to, using ffmpeg now instead. the avs uses the ffmpeg decoded audio file, which gets piped into qaac/neroaac Last edited by xekon; 27th October 2011 at 07:10. |
22nd October 2011, 19:04 | #7 | Link | |
Registered User
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
|
it's ok...if the m2ts have multiple audio tracks you must add "-map int:int" to the ffmpeg line...
to determine the values run: Code:
ffmpeg -i tvshow.m2ts Quote:
Code:
ffmpeg -i %1 -vn -sn -drc_scale 0 -ac 6 -acodec pcm_s24le -f wav -map 0:2 -y job.wav -async 1
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note... Visit The Land Of Dracula (Romania - EU)! Last edited by b66pak; 22nd October 2011 at 19:19. |
|
22nd October 2011, 19:27 | #8 | Link |
Registered User
Join Date: Jul 2011
Posts: 224
|
Yes, I read about -map. if you don't use it then ffmpeg uses the first audio track. What do you think of the new .batch file?
it uses RaWavSource() like tebasuna51 suggested, and it uses ffmpeg like you suggested, instead of using eac3to, i also added the -y option so that it overrides any existing file, this is good because the batch file can be used to queue more than one job, this way I do not have to delete the intermediate file at the end of a file/episode, it can just be overwritten. Now using AlignedSplice(Trim(%3, %4), Trim(%5, %6)) should not be a problem even if one or more frames originally had ac 2.0. Last edited by xekon; 22nd October 2011 at 23:23. |
22nd October 2011, 19:47 | #9 | Link |
Registered User
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
|
you should mod it to work with:
Code:
CALL bd.bat E:\yyh\BDMV\STREAM\00039.m2ts 25 2 3 004 2832 16675 16872 31270 _
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note... Visit The Land Of Dracula (Romania - EU)! |
22nd October 2011, 19:55 | #11 | Link |
Registered User
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
|
don't forget the fps (this is for trimsrt)...
_
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note... Visit The Land Of Dracula (Romania - EU)! |
22nd October 2011, 23:00 | #12 | Link | |
Registered User
Join Date: Jul 2011
Posts: 224
|
Quote:
it says that nicaudio RaWavSource() uses 32bit float. If I am going to use nicaudio's RaWavSource() in my avs, for audio decoded using ffmpeg, would it be best to decode with ffmpeg to the same type? Code:
E:\AviSynth\ffmpeg\bin\ffmpeg -i 00037.m2ts -vn -sn -y -drc_scale 0 -ac 6 -async 1 -acodec pcm_s24le -f wav job2.wav so I am not sure that is the best way to do it. ffmpeg supports many flavors of 32bit: s32be, s32le, u32be, u32le, f32be, f32le assuming I want to keep it at 32 bit float so that it is the same as RaWavSource() that narrows it down to: f32be, f32le I am still unclear as to what would be the best -acodec to use if I am going to be using RaWavSource() in my avs. my best guess is: Code:
E:\AviSynth\ffmpeg\bin\ffmpeg -i E:\yyh\BDMV\STREAM\00037.m2ts -vn -sn -y -map 0:2 -drc_scale 0 -ac 6 -async 1 -acodec pcm_f32le -f wav job3.wav |
|
23rd October 2011, 00:24 | #13 | Link |
Moderator
Join Date: Feb 2005
Location: Spain
Posts: 6,890
|
I don't know how work now ffmpeg. Long time ago the decoded data was always at 16 bits only, of course the output can be upsize until float 32 but the precision was always 16 bits.
For audio quality of TV sources I think is enough 24 bits, but RaWavSource and NeroAacEnc support also 32 bit float (the mantissa is 24 bits, then the precision is the same than 24 bits int)
__________________
BeHappy, AviSynth audio transcoder. |
23rd October 2011, 08:05 | #14 | Link | |
typo lover
Join Date: May 2009
Posts: 595
|
Quote:
And generaly, you should avoid use of global variables if possible. Thus, avs2pipe(mod) is better choice than wavi if you want to use float audio.
__________________
my repositories Last edited by Chikuzen; 23rd October 2011 at 08:22. |
|
23rd October 2011, 10:01 | #17 | Link |
typo lover
Join Date: May 2009
Posts: 595
|
You are correct. it was my misapprehension.
__________________
my repositories |
27th October 2011, 18:02 | #19 | Link | |||
Registered User
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
|
this line is not OK:
Quote:
Quote:
Quote:
__________________
if you ask a question and somebody give you the correct answer don't forget to leave a "thank you" note... Visit The Land Of Dracula (Romania - EU)! |
|||
27th October 2011, 20:09 | #20 | Link | ||
Registered User
Join Date: Jul 2011
Posts: 224
|
I have tested the script with a couple of sources start to finish, mkvmerge did not have a problem with this line for me:
Code:
E:\AviSynth\ffmpeg\bin\ffmpeg -i %1 -an -sn -y -vcodec copy -f rawvideo job.h264 Quote:
What I will probably do is edit the batch file to detect if the input file ends in .mp4, and if it does then add "-vbsf h264_mp4toannexb" to the ffmpeg video demux line. HOWEVER, I moved away from eac3to, because for some odd reason when I used it, some of the episodes where just Blank/Black and Avisynth through an error. but If I use mkvmerge to pack it into mkv then I no longer have the blank/black video error. The reason I am not using: Code:
echo V = FFVideoSource("E:\AviSynth\%1")>>bd.avs http://ffmpegsource.googlecode.com/s...-avisynth.html Quote:
Last edited by xekon; 27th October 2011 at 21:05. |
||
Thread Tools | Search this Thread |
Display Modes | |
|
|