<?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>Ashevile Web Design and Computer Networking :: Applied Solutions Group &#187; ffmpeg</title>
	<atom:link href="http://www.appliedtns.com/blog/tag/ffmpeg/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.appliedtns.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 28 Apr 2010 02:39:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FFMpeg and Converting Entire Folders of Files &#8211; Added Bonus Renaming All the Files you Converted</title>
		<link>http://www.appliedtns.com/blog/2009/02/ffmpeg-and-converting-entire-folders-of-files-added-bonus-renaming-all-the-files-you-converted/</link>
		<comments>http://www.appliedtns.com/blog/2009/02/ffmpeg-and-converting-entire-folders-of-files-added-bonus-renaming-all-the-files-you-converted/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 14:58:33 +0000</pubDate>
		<dc:creator>Tom</dc:creator>
				<category><![CDATA[Productivity Tools]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[batch convert]]></category>
		<category><![CDATA[converting files]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://ashevillewebblog.com/tom/2009/02/ffmpeg-and-converting-entire-folders-of-files-added-bonus-renaming-all-the-files-you-converted/</guid>
		<description><![CDATA[Using FFMPEG to convert a whole folder of videos is actually a lot easier than you would think. Lets take a look at a really basic bash script to do so.

	#!/bin/bash
&#160;
	DIR=/Users/tom/Desktop/Video
&#160;
	for i in `find $DIR -type f`; do
	  ffmpeg  -i $i $i.mpg
	done

Thats it, just make sure to change the DIR variable to where [...]]]></description>
			<content:encoded><![CDATA[<p>Using FFMPEG to convert a whole folder of videos is actually a lot easier than you would think. Lets take a look at a really basic bash script to do so.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">	<span style="">#!/bin/bash</span>
&nbsp;
	<span style="color:#6666ff; font-weight:bold;">DIR</span>=<span style="color:#006600; font-weight:bold;">/</span>Users<span style="color:#006600; font-weight:bold;">/</span>tom<span style="color:#006600; font-weight:bold;">/</span>Desktop<span style="color:#006600; font-weight:bold;">/</span>Video
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">`</span><span style="color:#0000FF; font-weight:bold;">find</span> <span style="color:#0066ff; font-weight:bold;">$DIR</span> <span style="">-type</span> f<span style="color:#006600; font-weight:bold;">`</span>; <span style="color:#9966CC; font-weight:bold;">do</span>
	  <span style="color:#0000FF; font-weight:bold;">ffmpeg</span>  <span style="">-i</span> <span style="color:#0066ff; font-weight:bold;">$i</span> <span style="color:#0066ff; font-weight:bold;">$i</span>.mpg
	<span style="color:#9966CC; font-weight:bold;">done</span></pre></div></div>

<p>Thats it, just make sure to change the DIR variable to where you are working at, this could be made to take user input easily also or to just work in the current directory but that is up to you as to how you use it and change it. Here is a small change you can make that will make this script infinitely more useful.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">	<span style="">#!/bin/bash</span>
&nbsp;
	<span style="color:#6666ff; font-weight:bold;">DIR</span>=<span style="color:#006600; font-weight:bold;">/</span>Users<span style="color:#006600; font-weight:bold;">/</span>tom<span style="color:#006600; font-weight:bold;">/</span>Desktop<span style="color:#006600; font-weight:bold;">/</span>Video
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">`</span><span style="color:#0000FF; font-weight:bold;">find</span> <span style="color:#0066ff; font-weight:bold;">$DIR</span> <span style="">-type</span> f<span style="color:#006600; font-weight:bold;">`</span>; <span style="color:#9966CC; font-weight:bold;">do</span>
	  <span style="color:#0000FF; font-weight:bold;">ffmpeg</span>  <span style="">-i</span> <span style="color:#0066ff; font-weight:bold;">$i</span> <span style="color:#0066ff; font-weight:bold;">$i</span>.mpg
	  <span style="color:#0000FF; font-weight:bold;">ffmpeg</span>  <span style="">-itsoffset</span> <span style="">-4</span>  <span style="">-i</span> <span style="color:#0066ff; font-weight:bold;">$i</span> <span style="">-vcodec</span> mjpeg <span style="">-vframes</span> <span style="color:#006666;">1</span> <span style="">-an</span> <span style="">-f</span> rawvideo <span style="">-s</span> 200x200 <span style="color:#0066ff; font-weight:bold;">$i</span>.jpg
	<span style="color:#9966CC; font-weight:bold;">done</span></pre></div></div>

<p>Adding the next <code>ffmpeg</code> line makes you a nice thumbnail for your video that is 200&#215;200, again you can modify to your needs easily.</p>
<p>Well now we have our files converted but since we didn&#8217;t work any magic in the bash script to convert them we have some ugly file names. For instance you may have before had the file <code>video.avi</code> and you converted it to an <code>mpg</code> so now we have <code>video.avi.mpg</code>. That won&#8217;t do so lets look at a really simple ruby script to parse the directory and rename our files how we want.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">	<span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> get_input
	  <span style="color:#CC0066; font-weight:bold;">system</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'clear'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;What directory will I be working in? ( <span style="color:#000099;">\e</span>[32mMust be absolute path<span style="color:#000099;">\e</span>[0m )&quot;</span>
	  directory = <span style="color:#CC0066; font-weight:bold;">gets</span>
	  directory.<span style="color:#CC0066; font-weight:bold;">chomp!</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> parse_directory<span style="color:#006600; font-weight:bold;">&#40;</span>directory<span style="color:#006600; font-weight:bold;">&#41;</span>
	  basedir = directory
	  file_stack = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
	  <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>basedir<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |file|
	    <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">directory</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span>
	      file_stack.<span style="color:#9900CC;">push</span> file
	    <span style="color:#9966CC; font-weight:bold;">end</span>
	  <span style="color:#9966CC; font-weight:bold;">end</span>
	  <span style="color:#0000FF; font-weight:bold;">return</span> file_stack
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	<span style="color:#9966CC; font-weight:bold;">def</span> bulk_rename<span style="color:#006600; font-weight:bold;">&#40;</span>file_stack<span style="color:#006600; font-weight:bold;">&#41;</span>
	  file_stack.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |file|
	    command = <span style="color:#996600;">&quot;mv #{file} &quot;</span>
	    file.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.avi.mpg'</span>,<span style="color:#996600;">'.mpg'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	    command <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">&amp;</span>lt; file
	    <span style="color:#CC0066; font-weight:bold;">system</span> command
	    <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">'.'</span>
	  <span style="color:#9966CC; font-weight:bold;">end</span>
	  <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
	file_stack = parse_directory<span style="color:#006600; font-weight:bold;">&#40;</span>get_input<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
	<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;I found <span style="color:#000099;">\e</span>[34m#{file_stack.nitems}<span style="color:#000099;">\e</span>[0m files&quot;</span>
&nbsp;
	bulk_rename<span style="color:#006600; font-weight:bold;">&#40;</span>file_stack<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
	<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Looks like I am done please type <span style="color:#000099;">\e</span>[31mls -l<span style="color:#000099;">\e</span>[0m to make sure I didn't mess up!<span style="color:#000099;">\n</span>&quot;</span></pre></div></div>

<p>This script is actually much shorter than it looks but it handles some basic user input so you can run this and let it know what directory to work in. I use this same script alot to rename a directory of files to other extentions or what ever. The line that has <code>file.gsub!('.avi.mpg','.mpg')</code> can be changes to any <code>'Pattern', 'Replacement'</code> that you need. This script is not perfect by any means so use that at your own risk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.appliedtns.com/blog/2009/02/ffmpeg-and-converting-entire-folders-of-files-added-bonus-renaming-all-the-files-you-converted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
