.

High quality encodes from Premiere Pro for AppleTV, DVD or BRD

videoediting-encodingThis document describes a solution to transcode video from Adobe Premiere Pro to Apple TV, DVD or Blu-ray Disk.  It assumes that video was rendered to a Lagarith Lossless encoded AVI file (see the last section of Using the Canon Vixia HF10 with Adobe Premiere Pro CS3.
While Premiere Pro’s Media Encoder can be used to export to both AppleTV and DVD format, its quality does not come close to that of the open source x264 encoder.  By exporting to Lagarith Lossless, Premiere is used for what it is good at: render video and the transcoding is left to free quality tools.
Some notes before we start
The script that I use can be found here.  Feel free to use it, but expect it to require some massaging as it is tweaked to my needs.
About subtitles
Subtitle Workshop is a popular tool for subtitling.  However be careful not to import MPEG-2 files in Subtitle Workshop because the timestamps will be incorrect.  This is due to the non-sequential frame order in MPEG-2.  Instead export to DV AVI from Premiere Pro and use that in Subtitle Workshop.
About audio delays
“Somehow”, x264 causes the video to lag behind the audio.  While the above script will appear in sync in VirtualDub, the resulting .mp4 file may not be.  To determine the required audio delay, one can create a wrapper .avs file with DirectShowSource(“file.mp4”), and loading this script in VirtualDub.  Use View > Audio Display to visualize the audio track, and step to a loud sound.  Then experiment with adding DelayAudio to this wrapper script.  When the correct value is found, move it to the above script and encode the audio and video.
To AppleTV with hard coded subtitles
AppleTV Take2 supports a maximum resolution of 1280x720p24.  We choose to compress the video as H.264 Progressive Main Profile (CAVLC) level 3.1 at 4500 kbps.  The audio will be encoded as 160 kbps AAC-LC.  The following tools will be used
Create an AviSynth file to resize, de-interlace and add hard coded subtitles

# import Lagarith Lossless compressed AVI file
AviSource(“clip.avi”)
# deinterlace, only needed if source is interlaced
#LoadPlugin(“SmoothDeinterlacer.dll”)
#ConvertToRGB32()
#SmoothDeinterlace(doublerate=false)
# resize, only needed if source > 720 pixels high, or > 1280 wide
LanczosResize(1280,720)
# synchronize audio with video if needed, only needed if audio and video are out of sync
#DelayAudio(+0.000)
# add subtitles, if desired
LoadPlugin(“vsfilter.dll”)
TextSub(“clip.srt”)
# convert color space
ConvertToYV12()
While it should be possible to extract the audio from the AVI file using VirtualDub, I have not been very successful doing so.  Instead, I load the AVI in Adobe Soundbooth, and save it as WAV.
Use Nero’s AAC encoder to compress the audio to AAC-LC

NeroAacEnc_Sse -lc -br 160000 -if “clip.wav” -of “clip.aac”

Compress video to 1280×720 video compressed using H.264 at an average bit rate of 4500 kbps, with peaks up to 12000 kbps.  At 1280x720p24, the average bit rate (ABR) is documented by Apple as 5 MBps.  The same documentation claims Main Profile 3.1 compliance.  Based on this table that allows a peak bit rate of 14000 kbps.
Note that x264 parameter ‘–sar’ specifies the Pixel Aspect Ratio (PAR and not the Sample Aspect Ratio (SAR).  The PAR can be calculated as in PARX = DARX * SARY; PARY = DARY * SARX; PAR = PARX:PARY
set /a PARX=16*720
set /a PARY=9*1280
set PAR=%PARX%:%PARY%
set VIDEO_ABR=4500
set VIDEO_PBR=12000
x264.exe –pass 1 –bitrate %VIDEO_ABR% –stats “clip.stats” ^
–level 3.1 –bframes 3 –b-adapt 2 –weightb ^
–direct none –no-cabac –subme 2 –partitions none –qpmin 16 ^
–vbv-bufsize VIDEO_PBR –vbv-maxrate VIDEO_PBR ^
–me dia –merange 12 –threads auto –thread-input ^
–sar %PAR% –progress –no-psnr –no-ssim ^
–output NUL “clip.avs”
x264.exe –pass 2 –bitrate %VIDEO_ABR% –stats  “clip.stats” ^
–level 3.1 –bframes 3  –b-adapt 2 –weightb ^
–direct none –no-cabac –subme 7 –partitions p8x8,b8x8,i4x4 –qpmin 16 ^
–vbv-bufsize %VIDEO_PBR% –vbv-maxrate %VIDEO_PBR% ^
–me umh –merange 12 –threads auto –thread-input ^
–sar %PAR% –progress –no-psnr –no-ssim ^
–output “clip.264” “clip.avs”
Merge the audio, video and subtitle tracks

MP4Box-0.4.5-dev\MP4Box.exe -new ^

-add “clip.264:lang=dut:fps=23.976023976:name=clip” ^
-add “clip.aac” ^
-add “clip.srt:lang=dut” “clip.mp4”
Tag the .mp4 file for use in iTunes
atomicparsley “clip.mp4” –overWrite –genre “TV Shows” –stik “TV Show” ^
–TVNetwork “Your name” –TVShowName “Your show name” ^
–TVSeasonNum 1 –TVEpisodeNum 1 –title “Your title”
Import to iTunes by drag’n’drop “clip.mp4” on iTunes
To Blu-Ray Disc (BRD)
Blue ray disk (BRD) supports 1920x1080p24 directly.  We choose to compress the video as H.264 Progressive Main Profile (CAVLC) level 3.1 at 4500 kbps.  The audio will be encoded as 160 kbps AAC-LC.  The following tools will be used
Create an AviSynth file to resize, deinterlace and add hardcoded subtitles

# import Lagarith Lossless compressed AVI file
AviSource(“clip.avi”)
# deinterlace, only needed if source is interlaced
#LoadPlugin(“SmoothDeinterlacer.dll”)
#ConvertToRGB32()
#SmoothDeinterlace(doublerate=false)
# resize, only needed if source > 1080 pixels high, or > 1920 wide
#LanczosResize(1920,1080)
# synchronize audio with video if needed, only needed if audio and video are out of sync
#DelayAudio(+0.000)
# convert color space
ConvertToYV12()
Use Nero’s AAC encoder to compress the audio to AAC-LC

NeroAacEnc_Sse -lc -br 160000 -if “clip.wav” -of “clip.aac”

Compress video to 1920×1080 video compressed using H.264 at an average bit rate of 17000 kbps, with peaks up to 40000 kbps.
Note that x264 parameter ‘–sar’ specifies the Pixel Aspect Ratio (PAR and not the Sample Aspect Ratio (SAR).  The PAR can be calculated as in PARX = DARX * SARY; PARY = DARY * SARX; PAR = PARX:PARY
set /a PARX=16*720
set /a PARY=9*1280
set PAR=%PARX%:%PARY%
set ABR=17000
set PBR=40000
x264.exe –pass 1 –bitrate  %ABR% –stats  “clip.stats” ^
–level 4.1 –keyint 24 –min-keyint 2 –bframes 3 –b-adapt 2 –weightb ^
–direct auto –deblock -1:-1 –subme 2 ^
–partitions none –ipratio 1.1 –pbratio 1.1 ^
–vbv-bufsize %PBR% –vbv-maxrate %PBR% –qcomp 0.5 –me dia ^
–threads auto –thread-input ^
–sar %PAR% –progress –no-psnr –no-ssim ^
–output NUL  “clip.avs” ^
–mvrange 511 –aud –nal-hrd –sar %PAR%
x264.exe –pass 2 –bitrate %ABR% –stats “clip.stats” ^
–level 4.1 –keyint 24 –min-keyint 2 –ref 3 –mixed-refs –bframes 3 –b-adapt 2 –weightb ^
–direct auto –deblock -1:-1 –subme 7 –trellis 2 ^
–partitions p8x8,b8x8,i4x4,i8x8 –8x8dct –ipratio 1.1 –pbratio 1.1 ^
–vbv-bufsize %PBR% –vbv-maxrate %PBR% –qcomp 0.5 –me umh ^
–threads auto –thread-input ^
–sar %PAR% –progress –no-psnr –no-ssim ^
–output “clip.264” “clip.avs” ^
–mvrange 511 –aud –nal-hrd –sar %PAR%
Merge the audio, video and subtitle tracks
set DAR=16/9
mkvmerge.exe –output “clip.mkv” ^
–noaudio –nosubs –track-name “0:Your Track Name” –language 0:English –aspect-ratio 0:%DAR% “clip.264” ^
–novideo –nosubs –track-name “1:English/Nederlands” –language 1:English “clip.aac” ^

–stracks 0 –novideo –noaudio –language 0:Dutch –track-name “0:Nederlands” “clip.srt”  ^

–no-clusters-in-meta-seek
To DVD (as used by Adobe Encore)
We choose to compress the video as MPEG-2 at a constant bitrate of 6000 kbps.  The audio will be encoded as 192 kbps Layer-II.  The following tools will be used
  • scripted video editor AviSynth 2.57 to manipulate the video.  Plug-ins vsfilter.dll and SmoothDeinterlacer.dll.
  • ffmpeg media encoder suite (executable copied from MeGUI tools directory)
Create an AviSynth file to resize, de-interlace and add hardcoded subtitles

# import Lagarith Lossless compressed AVI file
AviSource(“clip.avi”)
# if input is interlaced, then de-interlace before resizing
# Yadif(order=0,mode=1)
# resize to DVD resolution
LanczosResize(720,480)
# apply 3:2 pulldown
AssumeFrameBased()
SeparateFields()
SelectEvery(8, 0,1, 2,3,2, 5,4, 7,6,7)
Weave()
# synchronize audio with video if needed, only needed if audio and video are out of sync
DelayAudio(+0.000)
# convert color space
ConvertToYV12()
Compress audio and video, and merge
set DAR=16:9
set VIDEO_BR=6000
set AUDIO_BR=192
ffmpeg.exe -y -i “clip.avs” -target ntsc-dvd -shortest ^
-b %VIDEO_BR%k -aspect %OUT_DAR% -vtag “MPG2” ^
-ab %AUDIO_BR%k -acodec mp2 “clip.vob”

Import as time line in Encore.  You probably have to enter *.vob to be able to select the file.

Coert Vonk

Coert Vonk

Independent Firmware Engineer at Los Altos, CA
Welcome to the things that I couldn’t find.This blog shares some of the notes that I took while deep diving into various fields.Many such endeavors were triggered by curious inquiries from students. Even though the notes often cover a broader area, the key goal is to help the them adopt, flourish and inspire them to invent new technology.
Coert Vonk

Latest posts by Coert Vonk (see all)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Protected with IP Blacklist CloudIP Blacklist Cloud