I will try to show you how I encode my files with avisynth, x264 and some other programs. Avisynth does have a steep learning curve. I am not going to touch on the actual setup of avisynth here, but can answer questions if you have them.
In its simplest form, taking a 1080i show and converting it to a 1080p24 file using avisynth would use a script like this:
#DGSource("videofilename.dgi") - this is a different filter for decoding a source file
This would load the video file and look for telecined frames, match them and remove the duplicate frames to leave the original 24p video. This script would need to be run through x264 to actually transcode the video and then the stream would need to be mux'd with audio into a container.
Here is the batch file that I use to do that:
FOR %%A IN (*.mpg) DO (
IF NOT EXIST "%%~nA.avs" ((
ECHO lanczosresize(1280, height^)
ECHO lanczosresize(width, 720^)
) > "%%~nA.avs"
@if %1X==X goto END
set mp4box="C:\Program Files (x86)\GPAC\mp4box.exe"
set cc="C:\Program Files (x86)\CCExtractor\ccextractorwin.exe"
FOR %%A IN (*.mpg) DO (
%dgindex% -i %%A -o %%~nA.dgi -h -e
%cc% %%A -o %%~nA.srt
copy c:\encode\style.txt %%~nA.srt.style
%ffmpeg% -i %%A -acodec libfaac -ab 128k -ac 2 "I:\temp\%%~nA.aac"
%x264% --crf 21 --tune film --keyint 48 --sar 1:1 -o I:\temp\%%~nA.264 %%~nA.avs 2>%%~nA.log
%mp4box% -add "I:\temp\%%~nA.264":fps=23.976:par=1:1 -add "I:\temp\%%~nA.aac" "I:\temp\%%~nA.mp4"
move %%A F:\Originals\
You can see I do a bit more to my videos. Here is what my avisynth scripts do to my 1080i video:
- setmtmode(5,0) - the 5 basically turns off multi-threading for the source filter and the ,0 tells it the number of threads = the # of processor cores when actual using multi-threading
- DGSource() - this is a source filter that can be used to load AVC, MPEG2, and VC1 files
- setmtmode(2) - this turns on multi-threading for everything below this line
- lanczosresize(1280,height) - this resizes the width of the video from 1920 to 1280. I am going to convert my 1080i video to 720p24 but I can only do width at this time because there are still telecined frames present
- TFM() - this is a telecine frame matching/flagging filter
- Tdecimate() - this deletes the frames that were matched and flagged from TFM
- lanczosresize(width, 720) - this completes the resizing to 720p24. Since I have already done telecine frame elimination above, I can now safely resize the height
- Removegrain(1) - is a VERY light denoise that does minmax clipping and results in no noticeable picture quality change but drops the final output bitrate by ~10%
- setmtmode(5) - turns off multithread for everything below: textsub cannot be threaded
- Textsub() - this filter will hardcode a subtitle file into the video stream
The top part of the batch file creates the above described avisynth script for every .mpg file in the directory where I run that batch file.
Underneath that is the portion of the batch file that actually processes the video and creates the file H.264/AAC MP4 file for each .mpg file in the source directory.
- The dgindex line takes the mpg file and processes it with dgindexnv to create an index file. This file is used by the DGSource filter to correctly decode the mpg file
- The CC line uses CCextractor to extract the captions from the mpg file into a srt file
- The copy style.txt line is just a line to set the subtitles styles to what I like.
- The ffmpeg line reads the source .mpg and outputs the audio as aac audio rather than AC3 audio which is present in most Tivo files. I have to use a special version of ffmpeg that has libfaac enabled for this
- The x264 line is the actual transcoding of the MPEG2 video to H.264
- The mp4 box line is the muxing of the H.264 elementary stream and the AAC elementary stream into a single MP4 file
- The rest of the script is just clean-up
This script will only work for 1080i video that was originally 24p material that was simply telecined to 29.97fps and encoded as interlaced.