Chopping video

From EChase
Jump to: navigation, search

Something else we (well, OK, I) told ORF was that they didn't need to bother cutting video footage into clips because we could do that so long as they gave us the clip timings. So how can we do it, and more importantly how can we do it without having to sit there with some GUI tool and manually chop the video?

The obvious way is to use a format such as SMIL or ASX that allows us to do 'soft' chops by simply jumping through the bits we want to cut. It would be really good if we could do this on-the-fly when the user wishes to view a clip, but that will probably take a fair bit of work. However, we can still use it to do the chopping, although I have to admit to not having got as far as writing a script/program to do it just yet. Instead, I'll just point out the important bits of the SMIL and ASX formats so that you don't waste time trying to understand the rest of these (fairly complex) playlist formats.

Using SMIL[edit]

SMIL, or Synchronized Multimedia Integration Language, is a powerful beast, able to do far more than we need it to. Unfortunately it's also been set upon by the various vendors that 'support' it, who have each added their own extensions that do roughly the same thing but using a different syntax. For the time being we only need to bother with Apple's implementation, as we're not using the Real player. Apple are among the worst offenders when it comes to abuse of the SMIL specification; I guess they must have been having a bit of a 'Microsoft' moment...

Here's the contents of a typical .smil file that will play in the Quicktime player:

SMILtext
<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns:qt="http://www.apple.com/quicktime/resources/smilextensions" 
	qt:time-slider="true" qt:chapter-mode="clip" qt:autoplay="true"
	qt:immediate-instantiation="true">
<head>
	<meta name="author" content="www.orf.at"/>
	<meta name="title" content="Eastern Europe in times of cold war"/>
	<meta name="copyright" content="(c) 2005 ORF"/>
	
	<layout>
		<root-layout id="main" height="100%" width="100%" fit="fill"/>
	</layout>
</head>

<body>
	<par>
		<seq>
			<!-- tape 1 -->
			<video src="rtsp://localhost/EasternEurope1.mp4" region="main"
				qt:chapter="1. Havel Prozess in Prag 1989"
				clipBegin="npt=00:00:50" clipEnd="npt=00:06:29"
				clip-begin="npt=00:00:50" clip-end="npt=00:06:29"/>
			<video src="rtsp://localhost/EasternEurope1.mp4" region="main"
				qt:chapter="2. Arbeitermiliz in Ungarn 1988"
				clipBegin="npt=00:06:49" clipEnd="npt=00:13:02"
				clip-begin="npt=00:06:49" clip-end="npt=00:13:02"
			/>
			<video src="rtsp://localhost/EasternEurope1.mp4" region="main"
				qt:chapter="3. Bulgarien - in zerstorten turkischen Dorf"
				clipBegin="npt=00:13:22" clipEnd="npt=00:34:41"
				clip-begin="npt=00:13:22" clip-end="npt=00:34:41"/>
			<video src="rtsp://localhost/EasternEurope1.mp4" region="main"
				qt:chapter="4. Gedachtnisstatte in KP-Umerziehungslager Lovec"
				clipBegin="npt=00:35:01" clipEnd="npt=00:57:38"
				clip-begin="npt=00:35:01" clip-end="npt=00:57:38"/>

...

		</seq>
	</par>
</body>

</smil>

First thing to notice is the "SMILtext" before the XML declaration - nice, huh? Second thing you won't have noticed because it's not clear from the above code is that all the end-of-line characters have to be Mac-encoded, not Windows or Unix. That means \r instead of \r\n or \n. Also, unless you're up-to-speed with your SMIL specifications, you won't have noticed that Quicktime requires a hybrid of SMIL 1.0 and SMIL 2.0: you have to specify the hyphenated attributes (e.g. 'clip-begin') as well as the 'camel case' attributes (e.g. 'clipBegin').

The rest should be fairly obvious, and it should be pretty clear how the information given to us by ORF can be easily transformed into this format. Unfortunately mplayer doesn't support .smil files (at least, not the Quicktime varient) so command-line usage is hard to do, but Quicktime has no problems with it so using .smil files is a nice way to chop a big video into a smaller one.

Using ASX[edit]

It probably goes without saying that Windows Media Player can't use the same files as Quicktime does. Although WMP supports SMIL, it's not very good at it, so the preferred format for Windows Media player is Microsoft's own ASX format, which is similar to, although not as powerful as, SMIL. Here's the equivalent of the above SMIL file as ASX:

<asx version = "3.0">

	<!-- Playlist properties -->
	<title>Eastern Europe in times of cold war</title>
  	<author>www.orf.at</author>
	<copyright>2005 ORF-Öffentlichkeitsarbeit und Kommunikation</copyright>
	<base href="mms://192.9.206.124/eCHASE/"/>
	
	<!-- clips -->  
	<entry>
  	  	<ref href = "EasternEurope1.wmv"/>
  		<title>1. Havel Prozess in Prag 1989</title>
 	  	<starttime value="00:00:00"/>
		<duration value="00:06:29"/>
	</entry>
	<entry>
  	  	<ref href = "EasternEurope1.wmv"/>
  		<title>2. Arbeitermiliz in Ungarn 1988</title>
 		<starttime value="00:06:49"/>
		<duration value="00:06:13"/>
	</entry>
	<entry>
  	  	<ref href = "EasternEurope1.wmv"/>
  		<title>3. Bulgarien - in zerstorten turkischen Dorf</title>
 		<starttime value="00:13:22"/>
		<duration value="00:21:19"/>
	</entry>	

...

</asx>

As you can see, the ASX file is far simpler than the SMIL one, and doesn't suffer from the inconstencies and duplication of data.

A note about Unicode[edit]

Despite the "UTF-8" in the above SMIL file, I couldn't get Unicode characters (well, I only tried German ones such as 'ü') to display properly in the Quicktime player, so I replaced any accented characters with their unaccented equivalents. ASX appears to support Unicode to some extent, but I haven't tested it fully.


Back to video tips and tricks