1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Best Avisynth Scripts For XL-4 & HD Content?

Discussion in 'TiVo Home Media Features & TiVoToGo' started by thebib62, Feb 3, 2013.

  1. thebib62

    thebib62 New Member

    Feb 3, 2013
    I currently have the TiVo XL 4, I use that to record my HD content, and transfer it to PC for later editing. I've been using Handbrake, but I know that's not the "proper" and "scene" way to encode any type of video. I know avisynth is the only tool to use for proper encoding. I've heard others say it's not a good idea to use cookie cutter templates from other sources, or shows, but avisynth is so over my head, I don't think I'd ever learn how to code for my own RAW files. That is why I was wondering if anyone has an avisynth script that works with .TIVO files created from the XL4 in mind?

    If it helps, here's the video codec info from my RAW files:
     File:                                     Name : J:\TiVO Recordings (RAW)\My Little Pony Friendship Is Magic - ''A Canterlot Wedding - Part 1'' (Recorded Feb 3, 2013, HUBHD).TiVo
                                               Size : 2.764 GB
                                           Duration : 00:32:01.01
                                           Mux type : TiVo TS
                                        TS mux rate : 18.211 Mbps
     Video:                                Encoding : MPEG2
                                      VideoStreamID : x1B4F
                                         Frame rate : 29.97 fps
                                      Encoding size : 1920 x 1080
                                       Aspect ratio : 16:9
                                    Header bit rate : 14.664 Mbps
                                         VBV buffer : 976 KBytes
                                            Profile : Main@High
                                        Progressive : Prog or Int
                                             Chroma : 4:2:0
                                           Bit rate : 10.683 Mbps
     Audio Stream: 1 (Primary)                Codec : AC3
                                             Format : AC3 stream
                                           Channels : 5.1
                                                PID : x1B50
                                      PES Stream Id : xBD
                                           Bit rate : 384 Kbps
                                      Sampling rate : 48000
                                        Sample size : 16 bits
    I'm capping both live action, and animation, so I know I'd need at least two scripts.
    Also, the biggest thing for me is being able to deinterlace/decomb properly. I've used Handbrake to try and deinterlace/decomb my files, but after using the DECOMB filter, I can still see some interlacing lines every so often, and it's quite annoying. A script that would properly handle that would be great.

    As for file size anywhere between 700-850MB for a 30min.(22min. without commercials) episode is fine.

    Thanks to anyone that can help me out! Perhaps finally I can get my stuff to "scene" standards. :D
  2. txporter

    txporter One sec, almost done

    Sep 17, 2006
    Austin, TX
    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 setmtmode(5,0^)
      ECHO DGSource("%%~nA.dgi"^)
      ECHO setmtmode(2^)
      ECHO lanczosresize(1280, height^)
      ECHO TFM(^)
      ECHO TDecimate(^)
      ECHO lanczosresize(width, 720^)
      ECHO RemoveGrain(1^)
      ECHO setmtmode(5^)
      ECHO TextSub("%%~nA.srt"^)
    ) > "%%~nA.avs"
    ) )
    @if %1X==X goto END
    @goto LOOP
    set mp4box="C:\Program Files (x86)\GPAC\mp4box.exe"
    set dgindex="c:\encode\dgdecnv2042\dgindexnv.exe"
    set cc="C:\Program Files (x86)\CCExtractor\ccextractorwin.exe"
    set x264="c:\encode\x264.exe"
    set ffmpeg="c:\encode\ffmpeg.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"
    del *.txt
    del %%~nA.avs
    del %%~nA.dgi
    del I:\temp\%%~nA.aac
    del I:\temp\%%~nA.264
    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:
    1. 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
    2. DGSource() - this is a source filter that can be used to load AVC, MPEG2, and VC1 files
    3. setmtmode(2) - this turns on multi-threading for everything below this line
    4. 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
    5. TFM() - this is a telecine frame matching/flagging filter
    6. Tdecimate() - this deletes the frames that were matched and flagged from TFM
    7. 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
    8. 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%
    9. setmtmode(5) - turns off multithread for everything below: textsub cannot be threaded
    10. 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.

    1. 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
    2. The CC line uses CCextractor to extract the captions from the mpg file into a srt file
    3. The copy style.txt line is just a line to set the subtitles styles to what I like.
    4. 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
    5. The x264 line is the actual transcoding of the MPEG2 video to H.264
    6. The mp4 box line is the muxing of the H.264 elementary stream and the AAC elementary stream into a single MP4 file
    7. 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.

Share This Page