<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Encoding media files in Ruby using ffmpeg/mencoder with progress tracking</title>
	<atom:link href="http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/feed/" rel="self" type="application/rss+xml" />
	<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/</link>
	<description>In my blog I'll try to describe about interesting technologies, my discovery in IT and some useful things about programming.</description>
	<pubDate>Sun, 12 Oct 2008 15:05:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Lele</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-215752</link>
		<dc:creator>Lele</dc:creator>
		<pubDate>Sat, 30 Nov 2002 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-215752</guid>
		<description>Hi,
I'm trying to do something similar to what you did.
One thing I'm trying to add now is a timeout, what I would like to do is to check if I get some output from mencoder, if I don't get any output on the stdour or error for more that 30 sec I want to quit the process.
Is that possible?
thanks very much in advance</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I&#8217;m trying to do something similar to what you did.<br />
One thing I&#8217;m trying to add now is a timeout, what I would like to do is to check if I get some output from mencoder, if I don&#8217;t get any output on the stdour or error for more that 30 sec I want to quit the process.<br />
Is that possible?<br />
thanks very much in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-215571</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Wed, 30 Nov 2005 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-215571</guid>
		<description>The ffmpeg progress counter will never update with Ruby 1.8.6 because duration is defined out of scope (the first if clause) when processing each line from ffmpeg's output (the second if clause) -- to fix it, change the line: "progress = nil" to "duration = progress = nil" and it will work fine.</description>
		<content:encoded><![CDATA[<p>The ffmpeg progress counter will never update with Ruby 1.8.6 because duration is defined out of scope (the first if clause) when processing each line from ffmpeg&#8217;s output (the second if clause) &#8212; to fix it, change the line: &#8220;progress = nil&#8221; to &#8220;duration = progress = nil&#8221; and it will work fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: benok</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-153066</link>
		<dc:creator>benok</dc:creator>
		<pubDate>Fri, 30 Nov 2001 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-153066</guid>
		<description>Hi, do you know this library?
It's very handy.
http://0xcc.net/ruby-progressbar/index.html.en</description>
		<content:encoded><![CDATA[<p>Hi, do you know this library?<br />
It&#8217;s very handy.<br />
<a href="http://0xcc.net/ruby-progressbar/index.html.en" rel="nofollow">http://0xcc.net/ruby-progressbar/index.html.en</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-142496</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Wed, 30 Nov 2011 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-142496</guid>
		<description>Hi , Thanks for this tutorial. 
I am on leopard FFmpeg version SVN-r9102, ruby 1.8.6.
The above code works fine for me but the progress wont update sequentially as expected. 

Any idea what this could be?? Is it something to do with pipe.each("\r") ??</description>
		<content:encoded><![CDATA[<p>Hi , Thanks for this tutorial.<br />
I am on leopard FFmpeg version SVN-r9102, ruby 1.8.6.<br />
The above code works fine for me but the progress wont update sequentially as expected. </p>
<p>Any idea what this could be?? Is it something to do with pipe.each(&#8221;\r&#8221;) ??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Руслан Разбежкин</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-130540</link>
		<dc:creator>Руслан Разбежкин</dc:creator>
		<pubDate>Tue, 30 Nov 2010 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-130540</guid>
		<description>Помогите решить вот такую проблему:
конвертирую flv в mov
на входе 8 Мб
на выходе 51 Мб, т.е. в 6 раз больше.

команда такая:
ffmpeg -i sqlintro1.flv -sameq 01sql.mov

Подскажите, если не затруднит, какими ключами можно уменьшить размер выходного файла, чтобы он был примерно таким же как и входной.</description>
		<content:encoded><![CDATA[<p>Помогите решить вот такую проблему:<br />
конвертирую flv в mov<br />
на входе 8 Мб<br />
на выходе 51 Мб, т.е. в 6 раз больше.</p>
<p>команда такая:<br />
ffmpeg -i sqlintro1.flv -sameq 01sql.mov</p>
<p>Подскажите, если не затруднит, какими ключами можно уменьшить размер выходного файла, чтобы он был примерно таким же как и входной.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links, ideas and geek stuff &#187; Blog Archive &#187; links for 2007-10-19</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-110892</link>
		<dc:creator>links, ideas and geek stuff &#187; Blog Archive &#187; links for 2007-10-19</dc:creator>
		<pubDate>Sat, 30 Nov 2002 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-110892</guid>
		<description>[...] Encoding media files in Ruby using ffmpeg/mencoder with progress tracking [...]</description>
		<content:encoded><![CDATA[<p>[...] Encoding media files in Ruby using ffmpeg/mencoder with progress tracking [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Converting movies to flv format. &#171; nuby on rails</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-88316</link>
		<dc:creator>Converting movies to flv format. &#171; nuby on rails</dc:creator>
		<pubDate>Tue, 30 Nov 2010 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-88316</guid>
		<description>[...] going with a different guide [...]</description>
		<content:encoded><![CDATA[<p>[...] going with a different guide [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baerz</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-63129</link>
		<dc:creator>Baerz</dc:creator>
		<pubDate>Wed, 30 Nov 2011 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-63129</guid>
		<description>Hey, works :) Thanks...</description>
		<content:encoded><![CDATA[<p>Hey, works <img src='http://kpumuk.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Thanks&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmytro Shteflyuk</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-63125</link>
		<dc:creator>Dmytro Shteflyuk</dc:creator>
		<pubDate>Wed, 30 Nov 2011 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-63125</guid>
		<description>Baerz, you should define methods &lt;tt&gt;execute_mencoder&lt;/tt&gt; and &lt;tt&gt;execute_ffmpeg&lt;/tt&gt; &lt;strong&gt;before&lt;/strong&gt; executing them, for example, right after definition of the class &lt;tt&gt;MediaFormatException&lt;/tt&gt;.</description>
		<content:encoded><![CDATA[<p>Baerz, you should define methods <tt>execute_mencoder</tt> and <tt>execute_ffmpeg</tt> <strong>before</strong> executing them, for example, right after definition of the class <tt>MediaFormatException</tt>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Baerz</title>
		<link>http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-63120</link>
		<dc:creator>Baerz</dc:creator>
		<pubDate>Wed, 30 Nov 2011 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://kpumuk.info/ruby-on-rails/encoding-media-files-in-ruby-using-ffmpeg-mencoder-with-progress-tracking/#comment-63120</guid>
		<description>Hi, i tried to implement your Script, but it will not work for me. I get an Error: undefined method `execute_mencoder' for main:Object (NoMethodError)

Why? :)

&lt;code lang="ruby"&gt;
class MediaFormatException &lt; StandardError
end


command_mencoder = "/usr/bin/mencoder /home/download/medien_trailer.mov -o /home/robin/download/output.avi -oac lavc -ovc lavc -lavcopts vcodec=xvid:acodec=mp3"
command_ffmpeg = "/usr/bin/ffmpeg -y -i /home/download/medien_trailer.mov -vcodec xvid -acodec mp3 -ab 96 /home/robin/download/output.avi 2&gt;&#038;1"

begin
  execute_mencoder(command_mencoder)
  execute_ffmpeg(command_ffmpeg)
rescue
  print "ERROR\n"
  exit 1
end

def execute_mencoder(command)
  progress = nil
  Open3.popen3(command) do &#124;pipe&#124;
    pipe.each("\r") do &#124;line&#124;
      if line =~ /Pos:[^(]*(\s*(\d+)%)/
        p = $1.to_i
        p = 100 if p &gt; 100
        if progress != p
          progress = p
          print "PROGRESS: #{progress}\n"
          $defout.flush
        end
      end
    end
  end
  raise MediaFormatException if $?.exitstatus != 0
end

def execute_ffmpeg(command)
  progress = nil
  Open3.popen3(command) do &#124;pipe&#124;
    pipe.each("\r") do &#124;line&#124;
      if line =~ /Duration: (\d{2}):(\d{2}):(\d{2}).(\d{1})/
        duration = (($1.to_i * 60 + $2.to_i) * 60 + $3.to_i) * 10 + $4.to_i
      end
      if line =~ /time=(\d+).(\d+)/
        if not duration.nil? and duration != 0
          p = ($1.to_i * 10 + $2.to_i) * 100 / duration
        else
          p = 0
        end
        p = 100 if p &gt; 100
        if progress != p
          progress = p
          print "PROGRESS: #{progress}\n"
          $defout.flush
        end
      end
    end
  end
  raise MediaFormatException if $?.exitstatus != 0
end
&lt;/code&gt;

</description>
		<content:encoded><![CDATA[<p>Hi, i tried to implement your Script, but it will not work for me. I get an Error: undefined method `execute_mencoder&#8217; for main:Object (NoMethodError)</p>
<p>Why? <img src='http://kpumuk.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="codecolorer-container ruby" style="height:280px;"><div class="codecolorer" style="font-family: monospace;"><span class="kw1">class</span> MediaFormatException &lt; <span class="kw4">StandardError</span><br />
<span class="kw1">end</span><br />
<br />
<br />
command_mencoder = <span class="st0">&quot;/usr/bin/mencoder /home/download/medien_trailer.mov -o /home/robin/download/output.avi -oac lavc -ovc lavc -lavcopts vcodec=xvid:acodec=mp3&quot;</span><br />
command_ffmpeg = <span class="st0">&quot;/usr/bin/ffmpeg -y -i /home/download/medien_trailer.mov -vcodec xvid -acodec mp3 -ab 96 /home/robin/download/output.avi 2&gt;&amp;1&quot;</span><br />
<br />
<span class="kw1">begin</span><br />
&nbsp; execute_mencoder<span class="br0">&#40;</span>command_mencoder<span class="br0">&#41;</span><br />
&nbsp; execute_ffmpeg<span class="br0">&#40;</span>command_ffmpeg<span class="br0">&#41;</span><br />
<span class="kw1">rescue</span><br />
&nbsp; <span class="kw3">print</span> <span class="st0">&quot;ERROR<span class="es0">\n</span>&quot;</span><br />
&nbsp; <span class="kw3">exit</span> <span class="nu0">1</span><br />
<span class="kw1">end</span><br />
<br />
<span class="kw1">def</span> execute_mencoder<span class="br0">&#40;</span>command<span class="br0">&#41;</span><br />
&nbsp; progress = <span class="kw2">nil</span><br />
&nbsp; Open3.<span class="me1">popen3</span><span class="br0">&#40;</span>command<span class="br0">&#41;</span> <span class="kw1">do</span> |pipe|<br />
&nbsp; &nbsp; pipe.<span class="me1">each</span><span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\r</span>&quot;</span><span class="br0">&#41;</span> <span class="kw1">do</span> |line|<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> line =~ /Pos:<span class="br0">&#91;</span>^<span class="br0">&#40;</span><span class="br0">&#93;</span>*<span class="br0">&#40;</span>\s*<span class="br0">&#40;</span>\d+<span class="br0">&#41;</span>%<span class="br0">&#41;</span>/<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">p</span> = $<span class="nu0">1</span>.<span class="me1">to_i</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">p</span> = <span class="nu0">100</span> <span class="kw1">if</span> <span class="kw3">p</span> &gt; <span class="nu0">100</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> progress != <span class="kw3">p</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progress = <span class="kw3">p</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">print</span> <span class="st0">&quot;PROGRESS: #{progress}<span class="es0">\n</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$defout</span>.<span class="me1">flush</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw3">raise</span> MediaFormatException <span class="kw1">if</span> $?.<span class="me1">exitstatus</span> != <span class="nu0">0</span><br />
<span class="kw1">end</span><br />
<br />
<span class="kw1">def</span> execute_ffmpeg<span class="br0">&#40;</span>command<span class="br0">&#41;</span><br />
&nbsp; progress = <span class="kw2">nil</span><br />
&nbsp; Open3.<span class="me1">popen3</span><span class="br0">&#40;</span>command<span class="br0">&#41;</span> <span class="kw1">do</span> |pipe|<br />
&nbsp; &nbsp; pipe.<span class="me1">each</span><span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\r</span>&quot;</span><span class="br0">&#41;</span> <span class="kw1">do</span> |line|<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> line =~ /Duration: <span class="br0">&#40;</span>\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span><span class="br0">&#41;</span>:<span class="br0">&#40;</span>\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span><span class="br0">&#41;</span>:<span class="br0">&#40;</span>\d<span class="br0">&#123;</span><span class="nu0">2</span><span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1"><span class="br0">&#40;</span></span>\d<span class="br0">&#123;</span><span class="nu0">1</span><span class="br0">&#125;</span><span class="br0">&#41;</span>/<br />
&nbsp; &nbsp; &nbsp; &nbsp; duration = <span class="br0">&#40;</span><span class="br0">&#40;</span>$<span class="nu0">1</span>.<span class="me1">to_i</span> * <span class="nu0">60</span> + $<span class="nu0">2</span>.<span class="me1">to_i</span><span class="br0">&#41;</span> * <span class="nu0">60</span> + $<span class="nu0">3</span>.<span class="me1">to_i</span><span class="br0">&#41;</span> * <span class="nu0">10</span> + $<span class="nu0">4</span>.<span class="me1">to_i</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> line =~ /time=<span class="br0">&#40;</span>\d+<span class="br0">&#41;</span>.<span class="me1"><span class="br0">&#40;</span></span>\d+<span class="br0">&#41;</span>/<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="kw1">not</span> duration.<span class="kw2">nil</span>? <span class="kw1">and</span> duration != <span class="nu0">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">p</span> = <span class="br0">&#40;</span>$<span class="nu0">1</span>.<span class="me1">to_i</span> * <span class="nu0">10</span> + $<span class="nu0">2</span>.<span class="me1">to_i</span><span class="br0">&#41;</span> * <span class="nu0">100</span> / duration<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">p</span> = <span class="nu0">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">p</span> = <span class="nu0">100</span> <span class="kw1">if</span> <span class="kw3">p</span> &gt; <span class="nu0">100</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> progress != <span class="kw3">p</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progress = <span class="kw3">p</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">print</span> <span class="st0">&quot;PROGRESS: #{progress}<span class="es0">\n</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$defout</span>.<span class="me1">flush</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; &nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw1">end</span><br />
&nbsp; <span class="kw3">raise</span> MediaFormatException <span class="kw1">if</span> $?.<span class="me1">exitstatus</span> != <span class="nu0">0</span><br />
<span class="kw1">end</span></div></div>
]]></content:encoded>
	</item>
</channel>
</rss>
