norge5oslo_169Jodo-Milano.2008-09_035Saaristoleiri-Uto-2008_180Osaka, Japan 2010-04-29South.Africa.Roadtrip.2007-08_353Kuortti.2010-06-26italia2005-04_219Vesa-Rauttu-60v_1899South.Africa.Roadtrip.2007-08_216Nanbudo_Norge2007-12_038Nanbudo_Norge2007-12_211Somero2002_02Saaristoleiri 2009-08 34Helsinki2005-10-15_16_042Kuortti.2010-06-26Kobe, Japan 2010-04-28Inujima, Japan 2010-04-30Slovenia2009-04_658Kuortti.2010-06-26Zoo2006-10-07_043Oslo.Norway.2002.summer.034Helsinki2005-10-15_16_019
釵際柄頭のパ

Japanese character for "pa" as in paazio (パージオ) or Paasonen (パーソネン), or even in Paazmaya (パーズマヤ). The angle of the second vertical line might make this look the character used for "eight".

FFmpeg patch encoding with Avanti

Avanti is a graphic user interface to FFmpeg and Avisynth.

This article is based on the study to encode ~0.5 TB of video files produced while recording VHS tapes to digital format. The codec selected for video is H.264 and for audio AAC.

Material is mainly consisting of the following properties:

  • Frame size 720 x 576 pixels
  • Frame rate 25 fps
  • Extremely high bit rate

For selecting the suitable profile and level, the targeted decoding environment needs to be defined. The resulting media files should be playable in Apple iPod/iPhone and Nokia N900, thus the profile and level are limited according to the device limitations. In case the files should be playable in Sony PSP, the limitations would be even more strict.

The frame size and frame rate allows level 3 at the lowest standard. Baseline profile is the "best" profile which both of the devices can play without fail. The resizing is skipped as the main focus will be in getting the items played in N900. iPod would require slightly smaller frame size (640 x 480). In case you would need the iPod playability, add resizing to your Avisynth template.

In order to achieve such requirements, few FFmpeg presets are used. Best references for their options used are by Robert Swain and Dark_Shikari. The related line in the template attached is:

v_userOpt=-@pass1 -vpre "libx264-fastfirstpass.ffpreset" -vpre "libx264-main.ffpreset" -@pass2 -vpre "libx264-hq.ffpreset" -vpre "libx264-main.ffpreset"

The template in question is used in Avanti Job Manager for patch processing which in turn uses the given presets when initiating FFmpeg via command line.

Avisynth is used for deinterlacing and colour correction, as shown below. These commands are included in the template attached:

V=DirectShowSource("@source1_path")
V=ConvertToYV12(V)
V=Levels(V, 16, 1, 235, 0, 255, coring=false)
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\TomsMoComp.dll")
V=TomsMoComp(V,-1,5,1)

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\UnDot.dll")
V=UnDot(V)

V=TemporalSoften(V,4,4,8,15,2)
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\Convolution3DYV12.dll")
V=Convolution3D(V, "vhsBQ")

V=Tweak(V, sat=0.95)

Return V

Additionally, depending of the content quality, some scripts for Avisynth could be added, such as DeVCR. A plugin made by Moscow State University for field shift fixing is worth checking out.

One thing missing in the Job Manager is the ability to save the given files in their originating directories, versus the current way of defining just one unified destination for all the resulting files. Even better would be a directory scanner for files matching a given regular expression and save the resulting files in the same directory with the original.

Output from the Mediainfo for the resulting file is somewhat as such:

General
Format                           : MPEG-4
Format profile                   : Base Media
Codec ID                         : isom
Overall bit rate                 : 1 119 Kbps
Writing application              : Lavf52.52.0

Video
ID                               : 1
Format                           : AVC
Format/Info                      : Advanced Video Codec
Format profile                   : Baseline@L3.0
Format settings, CABAC           : No
Format settings, ReFrames        : 4 frames
Codec ID                         : avc1
Codec ID/Info                    : Advanced Video Coding
Bit rate mode                    : Variable
Bit rate                         : 1 000 Kbps
Width                            : 720 pixels
Height                           : 576 pixels
Display aspect ratio             : 5:4
Frame rate mode                  : Constant
Frame rate                       : 25.000 fps
Standard                         : PAL
Resolution                       : 8 bits
Colorimetry                      : 4:2:0
Scan type                        : Progressive
Bits/(Pixel*Frame)               : 0.096
Writing library                  : x264 core 83 r1400 20fa784
Encoding settings                : cabac=0 / ref=4 / deblock=1:0:0 / analyse=0x1:0x111 / me=umh / subme=8 / psy=1 / psy_rd=1.0:0.0 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=1 / sliced_threads=0 / nr=0 / decimate=1 / mbaff=0 / constrained_intra=0 / bframes=0 / wpredp=0 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=2pass / mbtree=1 / bitrate=1000 / ratetol=4.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.41 / aq=1:1.00

Audio
ID                               : 2
Format                           : AAC
Format/Info                      : Advanced Audio Codec
Format version                   : Version 4
Format profile                   : LC
Format settings, SBR             : No
Codec ID                         : 40
Bit rate mode                    : Variable
Bit rate                         : 111 Kbps
Channel(s)                       : 2 channels
Channel positions                : L R
Sampling rate                    : 48.0 KHz

Hopefully someday there will be a solution which would do all the work but would still let the user decide on details. This is where most all-in-one tools fail. Those who succeed in giving user the control are then in another hand too complex to process thousands of files at one go.

Several video codecs exists. Ten years ago most of videos were encoded with Divx 3 and soon followed by Xvid. Recently H.264 has become increasingly popular, but the support for its different profiles is still rather incomplete, keeping the Baseline as the most reasonable choice.

Next step might be the Snow codec from FFmpeg...

Quick links for the tools needed in this set:

AVANTI_PAAZIO_H264_MP4_HQ_B3.tpl

Time: 20/02/2010 22:52

QR code for paazio.nanbudo.fi