<?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>Diego's Rants &#187; ffmpeg</title>
	<atom:link href="http://blog.massanti.com/tag/ffmpeg/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.massanti.com</link>
	<description>Confessions from a Geek</description>
	<lastBuildDate>Wed, 27 Oct 2010 11:22:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Serverside video resizing script for ffmpeg or Mencoder</title>
		<link>http://blog.massanti.com/2007/10/01/serverside-video-resizing-script/</link>
		<comments>http://blog.massanti.com/2007/10/01/serverside-video-resizing-script/#comments</comments>
		<pubDate>Mon, 01 Oct 2007 23:00:35 +0000</pubDate>
		<dc:creator>Diego Massanti</dc:creator>
				<category><![CDATA[Computers & Tech]]></category>
		<category><![CDATA[Web & Design]]></category>
		<category><![CDATA[aspect]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[keep]]></category>
		<category><![CDATA[midentify]]></category>
		<category><![CDATA[movies]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ratio]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[scale]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://massanti.com/2007/10/01/serverside-video-resizing-script/</guid>
		<description><![CDATA[Some days ago, while working on a project that involves the re-encoding of a lot of videos coming from several sources, aspect ratios, resolutions, etc, i found myself in the situation where i needed to &#8220;standarize&#8221; somehow all the videos to a prefixed size in order to place them on a fixed space in a [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago, while working on a project that involves the re-encoding of a lot of videos coming from several sources, aspect ratios, resolutions, etc, i found myself in the situation where i needed to &#8220;standarize&#8221; somehow all the videos to a prefixed size in order to place them on a fixed space in a web page.<br />
While most linux tools like ffmpeg or mencoder include native functions to scale or resize the video, they don&#8217;t care about the aspect ratios or about the fact that most video encoders expect mod16 values for the height and width values.<br />
So my situation was like this:</p>
<p>I needed to make all the videos 480 pixels high, and scale the width proportionally.</p>
<p>That being said, i came up with this PHP script that i call from inside a bash script:</p>
<pre class="brush: php; title: ;">#!/usr/bin/php
&lt;?php
$cmdWidth = 'midentify '.$argv[1];
$finalHeight = $argv[2];
exec($cmdWidth, $output);

foreach ($output as $value) {
    if (strstr($value, &quot;ID_VIDEO_WIDTH&quot;)) {

		$width = parseResult($value);
    }
    if (strstr($value, &quot;ID_VIDEO_HEIGHT&quot;)) {
    	$height = parseResult($value);
    }
}
$frameSize = $width / $height;
$finalWidth = $finalHeight * $frameSize;
echo getMod16(round($finalWidth)) . &quot;x&quot; . getMod16(round($finalHeight)) . &quot;\n&quot;;
function parseResult($line) {
	$v1 = explode(&quot;=&quot;,$line);
	$v20 = $v1[1];

	//var_dump($v2);
	return $v20;
}
function getMod16($number){
	while (fmod($number, 16) != 0) {
		$number ++;
	}
	return $number;
}
?&gt;</pre>
<p>This script assumes that you have the &#8220;midentify&#8221; utility (wich comes with mplayer) installed in your path, and expects 2 arguments, being argument 1 the movie you want to resize and argument 2 the actual height you want to reach.<br />
That being said, suppose you have a movie that is 848 pixels width and 480 pixels high and you want to re-scale it so it fits inside a 400 pixels high space, you would call the script like this:</p>
<p><code>./resizer mymovie.avi 400</code></p>
<p>The script will output this:</p>
<p><code>720x400</code></p>
<p>You can use later this value as an input parameter for ffmpeg for example.</p>
<p>Before somebody asks, the reason because i used PHP instead of BASH, is simply because bash does not supports floats.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.massanti.com/2007/10/01/serverside-video-resizing-script/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

