<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>int64.org &#187; x264</title>
	<atom:link href="http://int64.org/tag/x264/feed" rel="self" type="application/rss+xml" />
	<link>http://int64.org</link>
	<description>When 4GiB just isn&#039;t enough</description>
	<lastBuildDate>Thu, 24 Jun 2010 11:50:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Re-encoding VFR Anime</title>
		<link>http://int64.org/2008/10/21/re-encoding-vfr-anime</link>
		<comments>http://int64.org/2008/10/21/re-encoding-vfr-anime#comments</comments>
		<pubDate>Tue, 21 Oct 2008 21:22:56 +0000</pubDate>
		<dc:creator>Cory</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[anime]]></category>
		<category><![CDATA[vfr]]></category>
		<category><![CDATA[x264]]></category>

		<guid isPermaLink="false">http://blog.int64.org/?p=43</guid>
		<description><![CDATA[So I preordered a Pandora, and for the past week have been re-encoding videos and music for playing on it.  All goes well, until I discovered my favorite anime uses VFR &#8212; Variable Frame Rate.  This is usually only seen in anime, which tends to use a low frame rate for slow scenes and a [...]]]></description>
			<content:encoded><![CDATA[<p>So I preordered a <a href="http://openpandora.org/">Pandora</a>, and for the past week have been re-encoding videos and music for playing on it.  All goes well, until I discovered my favorite anime uses VFR &#8212; Variable Frame Rate.  This is usually only seen in anime, which tends to use a low frame rate for slow scenes and a higher frame rate for action sequences and 3D renders.</p>
<p>For whatever reason, all the major video tools are completely dumb when it comes to VFR.  They expect a constant framerate and will completely screw up anything VFR.  This is such a problem that many raw and fansub groups tend to give up and decimate their encodes to a constant 24fps, noticably sacrificing quality.</p>
<p>But there is a light at the end of the tunnel.  After several days of searching and tinkering, I&#8217;ve found out how to do it.  Here are the steps I&#8217;m using &#8212; they are definitely still not optimal (though it <em>does</em> produce a perfect encode) so if you know of anything better, let me know.</p>
<ol>
<li>If your source is not MKV, you&#8217;ll need to convert it.  This can be done using mkvmerge from the <a href="http://www.bunkus.org/videotools/mkvtoolnix/">MKVToolnix</a> package.</li>
<li>Encode the source like normal.  I use <a href="http://sourceforge.net/projects/megui">meGUI</a>.</li>
<li>Use the mkv2vfr utility from the <a href="http://haali.cs.msu.ru/mkv/">Haali Media Splitter</a> package to extract a timecode file from the source MKV.  This is the important step &#8212; the timecode file describes the FPS that different segments of your video run at.  The mkvextract program from MKVToolnix has a timecode extraction option that looks cleaner, but seems to produce an incompatible or broken timecode file.</li>
<li>Mux the new video with the timecode file and the audio.  This is also done with mkvmerge.  Make sure you specify the timecode file for the video, not the audio.</li>
</ol>
<p>Here are the exact commands I used:</p>
<pre class="prettyprint"># 1. Convert MP4 to MKV
mkvmerge -o "source.mkv" -a 2 -d 1 -S "source.mp4" --track-order 0:1,0:2

# 2. Encode
x264 --crf 26 --ref 8 --mixed-refs --bframes 16 --b-pyramid
     --direct auto --filter 1:1 --subme 7 --trellis 2 --psy-rd 0.6:0
     --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --vbv-maxrate 25000
     --me umh --threads auto --thread-input --aq-mode 0
     --progress --no-psnr --no-ssim --output "output.mkv" "source.avs"

# 3. Extract timecodes
mkv2vfr "source.mkv" "dummy.avi" "timecodes.txt"

# 4. Mux output with timecodes and original audio.
mkvmerge -o "muxed.mkv" --timecodes "1:timecodes.txt"
         -d 1 -A -S "output.mkv" -a 2 -D -S "source.mkv"
         --track-order 0:1,1:2</pre>
<p>With source.avs looking like:</p>
<pre class="prettyprint">DirectShowSource("source.mkv", audio=false)

crop(2, 0, -4, -2)
Lanczos4Resize(800, 432)

vecs = last.MVAnalyseMulti(refframes=2, idx=1)
last.MVDegrainMulti(vecs, idx=1)</pre>
]]></content:encoded>
			<wfw:commentRss>http://int64.org/2008/10/21/re-encoding-vfr-anime/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
