<?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>The Accidental Developer &#187; Video</title>
	<atom:link href="http://osric.com/chris/accidental-developer/category/video/feed/" rel="self" type="application/rss+xml" />
	<link>http://osric.com/chris/accidental-developer</link>
	<description>What if Gregor Samsa awoke a computer programmer?</description>
	<lastBuildDate>Mon, 30 Apr 2012 21:16:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using FFmpeg to programmatically slice and splice video</title>
		<link>http://osric.com/chris/accidental-developer/2012/04/using-ffmpeg-to-programmatically-slice-and-splice-video/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/04/using-ffmpeg-to-programmatically-slice-and-splice-video/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 22:43:27 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Video]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dependency hell]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[H.264]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[mp4]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=690</guid>
		<description><![CDATA[My wife has a research project in which she needs to analyze brief (8-second) segments of hundreds of much longer videos. My goal was to take the videos (~30 minutes each) and cut out only the relevant sections and splice them together, including a static marker between each segment. This should allow her and her [...]]]></description>
			<content:encoded><![CDATA[<p>My wife has a research project in which she needs to analyze brief (8-second) segments of hundreds of much longer videos. My goal was to take the videos (~30 minutes each) and cut out only the relevant sections and splice them together, including a static marker between each segment. This should allow her and her colleagues to analyze the videos quickly and using precise time-points (instead of using a slider in a video player to locate and estimate time-points). I&#8217;ve posted my notes from this process below for my own reference, and in case it should prove useful to anyone else.</p>
<p>To my knowledge, the best tool for the job is <a href="http://ffmpeg.org/">FFmpeg</a>, an open source video tool. <span id="more-690"></span> FFmpeg provides much of the underlying processing functionality for other popular video tools, such as <a href="http://handbrake.fr/">Handbrake</a>, <a href="http://www.mirovideoconverter.com/">Miro</a>, and <a href="http://www.mplayerhq.hu">MPlayer</a>. Since you compile FFmpeg from source code, it should run on any system with a C compiler, including my OS X box. Unfortunately, it&#8217;s not the most user-friendly software package in the world.</p>
<p>The developers recommend using the latest version from <a href="http://git-scm.com/">Git</a> (which finally forced me to install Git, something I&#8217;d been meaning to do anyway). One <a href="http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html">how-to for FFmpeg on OS X</a> docs suggest that I&#8217;d also need <a href="http://lame.sourceforge.net/">LAME</a> in order to process audio. (The audio is irrelevant for my use case, so I didn&#8217;t bother with LAME.) But I couldn&#8217;t compile FFmpeg because, apparently, OS X doesn&#8217;t include GCC. To get GCC on OS X, the official Apple way, I needed XCODE from the <a href="https://developer.apple.com/technologies/tools/">Apple Developer Tools</a>. To get those you have to sign up for an Apple Developer account. Welcome to Dependency Hell, now featuring bureaucracy!</p>
<p>Hours later, I&#8217;ve compiled FFmpeg. However, the videos I&#8217;m dealing with are raw H.264 video files from a <a href="http://www.nightowlsp.com/Products/Complete-Kits/K-44500-C">Night Owl K-44500-C</a> surveillance system. Also, I want to save them as H.264-encoded MP4 files. That means I needed additional H.264 support&#8211;or, at least, I thought I did&#8211;from the <a href="http://www.videolan.org/developers/x264.html">x264</a> project. And you need <a href="http://yasm.tortall.net/">YASM</a> to compile x264.</p>
<p>I was actually unable to compile YASM from the Git repository, although I was able to compile it following the instructions in this <a href="https://trac.handbrake.fr/wiki/CompileGuide">Handbrake for Mac OS X guide</a>.</p>
<p>I recompiled FFmpeg with the &#8211;enable-libx264 and &#8211;enable-gpl switches:<br />
<code>./configure --enable-libx264 --enable-gpl<br />
make<br />
sudo make install</code></p>
<p>To select just the relevant portions of the video, I used the -ss (start/seek position) and -t (time/duration) flags, e.g.:<br />
<code>ffmpeg -f h264 -i input-video-file.264 -ss 180 -t 8 output-video-file.mp4</code></p>
<p>The above example takes 8 seconds of the input video starting at the 3-minute (180-second) mark.</p>
<p>However, when I played back the output, it played much too fast. The source videos included a timestamp, and about 4 seconds ticked by every for every second of video! It turned out that the source videos were recorded at 7 fps (frames per second). I added a flag to specify the framerate:<br />
<code>ffmpeg -f h264 -r:v 7 -i input-video-file.264 -ss 180 -t 8 output-video-file.mp4</code></p>
<p>After running this a few times for different 8 second segments, I needed to put the segments back together again. This is such a relatively common use-case that FFmpeg has instructions in their FAQ, <a href="http://ffmpeg.org/faq.html#How-can-I-join-video-files_003f">How can I join video files?</a>. The first method&#8211;concatenating MPEG-2 files&#8211;seemed like the easiest option. However, MPEG-2 doesn&#8217;t support the framerate (7 fps).</p>
<p>I tried the other suggested method of concatenating videos, using named pipes. This worked, although the BASH script was convoluted and very particular.</p>
<p>Another thing I wanted to add to the video was a separator&#8211;some static frames to divide each 8-second clip&#8211;and a title card. At first I created a JPEG and turned it into a 1-frame video, concatenated it with itself to create a 2-frame video, and then 4, 8, 16, etc. However, I discovered a much easier method of creating a video from a single image using the loop flag:<br />
<code>ffmpeg -f image2 -loop 1 -r:v 7 -i image.jpeg -pix_fmt yuv420p -an -t 2 image-movie.mpeg</code></p>
<p>(The pix_fmt flag was to set the correct color space, and the an flag ignores the audio channel.)</p>
<p>Now I had title cards, clip separators, and 8-second video clips that I could combine into a single video. But I needed to do this hundreds of times! I wrote a Python script to generate the appropriate BASH script based on the input filename. The BASH script would create the title cards and clip separators using <a href="http://www.imagemagick.org">ImageMagick</a>, and then call the appropriate FFmpeg commands to create and concatenate the video.</p>
<p>The ImageMagick commands look like this:<br />
<code>convert -size 704x480 -background SteelBlue1 -fill black -font Helvetica -pointsize 72 -gravity center label:[Video Title] titlecard.jpg</code></p>
<p>Then I used the find command to run the Python script on all the video files:<br />
<code>find *.264 -maxdepth 1 -exec ./process.sh '{}' \; -print</code></p>
<p>Eureka! It worked. Almost perfectly.</p>
<p><em>Almost.</em></p>
<p>Some (but not all) of the output videos would produce solid gray frames after a certain time point. Reviewing the FFmpeg output for those files, there was an error:<br />
<code>[h264 @ 0x9460340] FMO not supported</code></p>
<p>FMO stands for Flexible Macroblock Ordering, and based on the response to a <a href="http://roundup.libav.org/issue1440">libavcodec issue from 2009</a>, the FFmpeg developers don&#8217;t plan to support it (although one of the developers suggested that, if someone would like to create a software patch to enable FMO support, the community would welcome it).</p>
<p>I wrote to technical support for the camera system and asked if they had any suggestions. They replied that, although conversion to MPEG formats was not supported, they do provide a conversion utility to convert to AVI. I was able to successfully convert the AVIs to MP4s. An annoying extra step, but one that is only necessary in a subset of cases.</p>
<p>This solution took me several weeks to figure out, although it should save quite a bit of time in the long run.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/04/using-ffmpeg-to-programmatically-slice-and-splice-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedded FLV video players: Flowplayer and JW Player</title>
		<link>http://osric.com/chris/accidental-developer/2009/03/embedded-flv-video-players-flowplayer-and-jw-player/</link>
		<comments>http://osric.com/chris/accidental-developer/2009/03/embedded-flv-video-players-flowplayer-and-jw-player/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 18:37:39 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Video]]></category>
		<category><![CDATA[embedded video]]></category>
		<category><![CDATA[flowplayer]]></category>
		<category><![CDATA[flv players]]></category>
		<category><![CDATA[jwplayer]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=157</guid>
		<description><![CDATA[Over the past several months, I have worked with both Flowplayer and JW Player as embedded FLV video players. Why wouldn&#8217;t you just upload your videos to YouTube and use their embedded player? That&#8217;s a pretty fair question, as I think YouTube provides: An excellent player that your users are already familiar with A variety [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past several months, I have worked with both <a href="http://flowplayer.org/">Flowplayer</a> and <a href="http://www.longtailvideo.com/">JW Player</a> as embedded FLV video players.</p>
<p>Why wouldn&#8217;t you just upload your videos to YouTube and use their embedded player? That&#8217;s a pretty fair question, as I think YouTube provides:</p>
<ul>
<li>An excellent player that your users are already familiar with</li>
<li>A variety of options to control the appearance (e.g. you can disable related videos)</li>
<li>High-availability bandwidth</li>
</ul>
<p>Of course there are several drawbacks:</p>
<ul>
<li>Limits on length and file size</li>
<li>Critical infrastructure is no longer in your control</li>
<li>Their logo appears on your site</li>
<li>Progressive download only (no streaming)</li>
</ul>
<p>Let&#8217;s take a look at both Flowplayer and JW Player:<br />
<span id="more-157"></span><br />
Both players offer simple configuration options as well as numerous additional options for users who are able and willing to change a few config options or write a few lines of Javascript. Both include cross-browser Flash embedding scripts. Both support progressive download of FLVs and MP3s and a variety of streaming servers (I&#8217;ve been working with <a href="http://www.wowzamedia.com/">Wowza</a>).</p>
<p>Flowplayer is pretty slick right from the start. The default skin is very attractive, and the Javascript is very easy to work with. However, I have run into few issues using Flowplayer:</p>
<ul>
<li>Breakneck <a href="http://flowplayer.org/documentation/version-history.html">release schedule</a> (8 releases in the past 5 months&ndash;2.24-3.0.7&ndash;and 3.1 will be out soon)</li>
<li>Unresolved errors with &#8220;filmstrips&#8221; (audio with still images)</li>
<li>Inconsistent documentation and support</li>
<li>No streaming for MP3s</li>
</ul>
<p>You might think that a lot of new releases is a good thing, because new features are constantly being added. But a lot of the releases fix bugs that probably should never have made it to a release version, and even releases that only include new features require a lot of testing on my part to make sure that our old customizations still work and that everything is cross-platform and cross-browser compatible. Flowplayer&#8217;s frequent releases lead to serious upgrade fatigue.</p>
<p>The &#8220;filmstrip&#8221; issue probably doesn&#8217;t affect many users, most of whom are probably using strictly MP3s and FLVs. But I have occasionally had use to post a series of MP3s, each with its own accompanying JPEG. Although Flowplayer supports this by adding a JPEG followed by an MP3 in a playlist, if you use &#8220;rewind&#8221; to the previous clip it goes back to the MP3&#8211;but not the accompanying image.</p>
<p>Although the documentation has improved dramatically since I first started using it&ndash;config parameters now include lists of valid options or formats&ndash;their examples are occasionally buggy. I have a feeling this is in part due to their release schedule, which would require substantial testing of their various examples across browsers. Their forums seem to get a fair amount of use, and the developers are present to answer questions&ndash;but occasionally an important question goes completely unanswered. They do offer paid support, which presumably guarantees a response.</p>
<p>Also, one of the developers has a <a href="http://flowplayer.org/forum/users/1421">photo of a man without a shirt</a> (presumably himself) for his forum icon. Mind you, there are several bare-chested photos of me online, but none that I use for professional purposes. He&#8217;s Finnish, so possibly they have a more relaxed sense of decorum!</p>
<p>MP3s automatically use progressive download instead of streaming (unless I didn&#8217;t set it up properly, which is always a possibility).</p>
<p>JW Player, on the other hand seems to be a more mature product. Their <a href="http://developer.longtailvideo.com/trac/roadmap?show=all">release schedule</a> follows a (somewhat) more reasonable pace, and includes substantial detail about new features and bug fixes. I have had fewer errors and issues configuring JW Player than I had with Flowplayer. However, JW PLayer has a few drawbacks as well:</p>
<ul>
<li>Documentation information hard to locate</li>
<li>Javascript not as slick</li>
<li>Overall look not as polished</li>
</ul>
<p>The JW Player site is sprawling and a bit unorganized. You&#8217;d expect to find a link somewhere labeled &#8220;documentation,&#8221; but if you wanted to find a list of supported config parameters you&#8217;ll need to go to <em>Support&#8211;Developers&#8217; Wiki</em>. Their forums are organized into categories, but you can&#8217;t restrict a search to a specific category. (Both JW Player and Flowplayer could benefit from improved site searches, in my opinion.) Although the software behind the Flowplayer forums is superior, I&#8217;ve never had an unanswered question on the JW Player forums. (I don&#8217;t know if the responses have come from developers or other users, but it&#8217;s something to consider.)</p>
<p>While Flowplayer&#8217;s Javascript looks very much like jQuery (and works with jQuery), JW Player&#8217;s Javascript looks a little clumsy by comparison. I wrote wrapper functions for both to supply my most frequently used config parameters, so I never use their code directly. But it&#8217;s something to consider.</p>
<p>The JW Player controls do not look as good as Flowplayer&#8217;s. JW Player does offer a variety of different skins, as well as tutorials on customizing existing skin files or creating your own, but none of the existing skins look as good, to me, as the default Flowplayer controls (you can supply a custom Flowplayer controlbar as well). JW Player skins offer built-in playlist functionality, toggled on or off with a config parameter (which is convenient&ndash;Flowplayer requires a Javascript plugin), but it does not look as good as the Flowplayer playlist, nor is the look as easily modified.</p>
<p>Both are clearly good players, but at this point in time I am recommending JW Player over Flowplayer. Although Flowplayer&#8217;s look is more polished, JW Player seems the more reliable and mature product. Your experience with either of these players, or other Flash-based video players, is welcome. </p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2009/03/embedded-flv-video-players-flowplayer-and-jw-player/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

