<?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>Behind the Scenes &#187; Scripting</title>
	<atom:link href="http://backstar.com/blog/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://backstar.com/blog</link>
	<description>of cutting edge art, media + technology</description>
	<lastBuildDate>Wed, 19 May 2010 18:49:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Append Videos With Mencoder</title>
		<link>http://backstar.com/blog/2009/11/10/append-videos-with-mencoder/</link>
		<comments>http://backstar.com/blog/2009/11/10/append-videos-with-mencoder/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 20:24:25 +0000</pubDate>
		<dc:creator>Ben Baker-Smith</dc:creator>
				<category><![CDATA[Media]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Encoding]]></category>
		<category><![CDATA[Mencoder]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://backstar.com/blog/?p=538</guid>
		<description><![CDATA[Mencoder, the free audio / video transcoding software packaged with MPlayer, offers a free command line (CLI) method for combining many video clips into one.
Why would you choose this over the multitude of free GUI transcoding programs out there?

Mencoder is super-fast
Allows the process to be scripted
Wide range of codecs
Cross-platform compatible

Once you get the feel for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mplayerhq.hu">Mencoder</a>, the free audio / video transcoding software packaged with MPlayer, offers a free command line (CLI) method for combining many video clips into one.<span id="more-538"></span></p>
<p>Why would you choose this over the multitude of free GUI transcoding programs out there?</p>
<ul>
<li>Mencoder is super-fast</li>
<li>Allows the process to be scripted</li>
<li>Wide range of codecs</li>
<li>Cross-platform compatible</li>
</ul>
<p>Once you get the feel for it, you can append videos much quicker with Mencoder than a more &#8220;user friendly&#8221; GUI program.  And, it works on Linux, Macintosh, and Windows machines, so you don&#8217;t have to learn 3 different programs if you work on multiple operating systems.</p>
<p>Here&#8217;s the basic format of a Mencoder append command:</p>
<pre>
mencoder -oac copy -ovc copy -o 'combined_clip.avi'
'clip1.avi' 'clip2.avi'
</pre>
<p>Simple as that.  The breakdown is as follows:</p>
<ul>
<li><strong>-oac</strong><br />
Tell Mencoder what audio codec to use.  For a complete list of options, check out the <a href="http://www.mplayerhq.hu/design7/info.html#docs">Mencoder documentation</a>.  In this case we have simply used &#8220;copy&#8221;, which will keep the current audio codec the same without transcoding (this option should only be used if the audio codecs are the same for all the clips).</li>
<li><strong>-ovc</strong><br />
Tell Mencoder what video codec to use.  Otherwise, same as above.</li>
<li><strong>-o</strong><br />
Define the paths to input and output files.  First list the output filename, then all the clips in the order which they will be appended.</li>
</ul>
<p>Knowing this, it is easy enough to script the process.  Say I have a whole directory of video files that I want to combine (ex: VID001.AVI, VID002.AVI, VID003.AVI, etc.).  I could use the following ruby script to string them all together in their numbered order:</p>
<pre>
vlist = String.new()
vpath = "/path/to/my/video/directory/"
vdir = Dir.new(vpath)
vdir.each do |v|
  if v.include?(".AVI") == true
    vlist << "\'#{vpath}#{v}\' "
  end
end

cmd = "mencoder -oac copy -ovc copy -o \'combined_clip.avi\'
#{vlist}"
system cmd
</pre>
<p>Save the script as VAppend.rb and run it like so:</p>
<pre>
ruby VAppend.rb
</pre>
<p>(you must be in the same directory as the script in order to run it with the above command)</p>
<p><strong>Final Notes</strong><br />
The command in the first code box is all one line, and the line in the second code box starting with "cmd =" is also all one line that continues onto a second for formatting purposes (in other words, #{vlist}" belongs at the end of the previous line).</p>
]]></content:encoded>
			<wfw:commentRss>http://backstar.com/blog/2009/11/10/append-videos-with-mencoder/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Avidemux Append Limit</title>
		<link>http://backstar.com/blog/2009/11/06/avidemux-maximum-clips/</link>
		<comments>http://backstar.com/blog/2009/11/06/avidemux-maximum-clips/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 15:32:10 +0000</pubDate>
		<dc:creator>Ben Baker-Smith</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Avidemux]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://backstar.com/blog/?p=533</guid>
		<description><![CDATA[I ran into an invisible barrier with my favorite free video editing software, Avidemux: a limit on the number of clips you can draw from for a single project.
Avidemux will only accept segments from up to 100 clips.
If you are appending each clip manually, there may or may not be an error message (this is [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an invisible barrier with my favorite free video editing software, <a href="http://fixounet.free.fr/avidemux/download.html">Avidemux</a>: a limit on the number of clips you can draw from for a single project.<span id="more-533"></span></p>
<p><strong>Avidemux will only accept segments from up to 100 clips.</strong></p>
<p>If you are appending each clip manually, there may or may not be an error message (this is not how I encountered the limit, so I&#8217;m not sure).  However, if you, like me, are using scripting to append a large number of files, there will be no error message; just a crash file.  This crash file will show one <em>app.load()</em> entry and 99 <em>app.append()</em> entries, and the comments will state something like <em>// 100 Videos</em>, regardless of how many more your script attempted to append.</p>
<p>My workaround was an obvious one: if I have 300 videos to splice together, I create three or more smaller videos first and then splice those together.</p>
<p>For example&#8230;</p>
<ul>
<li>Vid_A.avi = clips 1 &#8211; 100</li>
<li>Vid_B.avi = clips 101 &#8211; 200</li>
<li>Vid_C.avi = clips 201 &#8211; 300</li>
</ul>
<p>&#8230;and then&#8230;</p>
<ul>
<li>Vid_Final.avi = Vid_A.avi + Vid_B.avi + Vid_C.avi</li>
</ul>
<p>Of course, this takes a little longer, but when automated from the command line with another script, it&#8217;s not so bad.</p>
<p>If anyone else has a different tactic for dealing with this limit, please leave it in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://backstar.com/blog/2009/11/06/avidemux-maximum-clips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avidemux Basic Script Elements</title>
		<link>http://backstar.com/blog/2009/10/20/avidemux-basic-script-elements/</link>
		<comments>http://backstar.com/blog/2009/10/20/avidemux-basic-script-elements/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 22:01:57 +0000</pubDate>
		<dc:creator>Ben Baker-Smith</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Avidemux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://backstar.com/blog/?p=460</guid>
		<description><![CDATA[Avidemux is a free, cross-platform video editing program that is both very simple and immensely powerful.  Much of its power is thanks to its command line interface (CLI) and potential for scripting.
In this particular post I will be focusing on the latter aspect: scripting.
Specifically, I will be covering the elements and commands found in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://fixounet.free.fr/avidemux/download.html">Avidemux</a> is a free, cross-platform video editing program that is both very simple and immensely powerful.  Much of its power is thanks to its command line interface (CLI) and potential for scripting.</p>
<p>In this particular post I will be focusing on the latter aspect: scripting.<span id="more-460"></span></p>
<p>Specifically, I will be covering the elements and commands found in a basic Avidemux script.  I am currently using Avidemux 2.4.4 on a Mac, though I routinely use 2.5.1 on Linux, and even occasionally on Windows.  For those who have multiple platforms available, I recommend the Linux or Windows versions for their increased stability.</p>
<div style="height:22px"></div>
<hr />
<p><a></a><br />
<h2>Table of Contents</h2>
<ul>
<li><a href="#language">Scripting Language</a></li>
<li><a href="#script">The Basic Script</a></li>
<li><a href="#head">Header</a></li>
<li><a href="#video">Video</a></li>
<li><a href="#segments">Segments</a></li>
<li><a href="#postproc">Postproc</a></li>
<li><a href="#audio">Audio</a></li>
<li><a href="#running">Running Your Script</a></li>
<li><a href="#moreinfo">More Information</a></li>
</ul>
<div style="height:22px"></div>
<hr />
<p><a name="language"></a><br />
<h2>Scripting Language</h2>
<p>Avidemux reads and writes scripts in Javascript.  While basic script modifications can be made without any prior Javascript knowledge/experience, it is recommended that those of you interested in creating more advanced scripts learn the basics of the language before getting in too deep (you will only be frustrated).</p>
<p>Here are some Javascript concepts you might want to be familiar with.<br />
(this is in no way a comprehensive list)</p>
<ul>
<li>Declaring variables</li>
<li>If&#8230;Else statements</li>
<li>Arrays</li>
</ul>
<div style="height:22px"></div>
<hr />
<p><a name="script"></a><br />
<h2>The Basic Script</h2>
<p>Now, let&#8217;s get down to basics.  The easiest way to start learning about Avidemux scripts is to look at one.  Lucky for us (since the documentation online is pretty weak), Avidemux project files are actually just basic scripts.</p>
<p>So, if you want to know how to do something in a script, first try accomplishing it from the graphic user interface (GUI), then save your project, and open the project file in a text editor to see how the resulting script is put together.</p>
<p>For the following example, I did just that.  This script simply lays down a first video in its entirety, then appends a second video.</p>
<p><strong>Important:</strong> Avidemux scripts do not have an extension.  Even though they are written in Javascript, do not add a .js extension to the filename or they will not work.  If you can&#8217;t get Avidemux to recognize your scripts, be sure there isn&#8217;t a hidden extension (some text editors will add .txt or .rtf to the end of files that do not specify an alternate extension)</p>
<pre>
<div class="code">
//AD  <- Needed to identify//
//--automatically built--
//--Project: /Volumes/Media_G5/Ben/Tutorials/Test_Script

var app = new Avidemux();

//** Video **
// 02 videos source
app.load("/Volumes/MEDIA_G5/BEN/TUTORIALS/clip1.mov");
app.append("/Volumes/MEDIA_G5/BEN/TUTORIALS/clip2.mov");
//02 segments
app.clearSegments();
app.addSegment(0,0,3587);
app.addSegment(1,0,2707);
app.markerA=0;
app.markerB=6293;

//** Postproc **
app.video.setPostProc(3,3,0);

app.video.setFps1000(23907);

//** Filters **

//** Video Codec conf **
app.video.codec("Copy","CQ=4","0 ");

//** Audio **
app.audio.reset();
app.audio.codec("copy",128,0,"");
app.audio.normalizeMode=0;
app.audio.normalizeValue=0;
app.audio.delay=0;
app.audio.mixer("NONE");
app.setContainer("AVI");
setSuccess(1);
//app.Exit();

//End of script
</div>
</pre>
<p>Again, this script simply loads clip1.mov and then appends clip2.mov to that.  Nothing more, nothing less.</p>
<p>Now let&#8217;s examine the code.</p>
<div style="height:22px"></div>
<hr />
<p><a name="head"></a><br />
<h2>Header</h2>
<div class="code">
<pre>
//AD  <- Needed to identify//
//--automatically built--
//--Project: /Volumes/Media_G5/Ben/Tutorials/Test_Script
</pre>
</div>
<p>This is the header information.  The first line must always be included, as it identifies the file as an Avidemux script.  The second and third lines contain additional information that can be discarded or re-written.</p>
<div class="code">
<pre>
var app = new Avidemux();
</pre>
</div>
<p>This is the first line of actual code after the header (always).  It starts a new instance of Avidemux, so you need to include it (always).</p>
<div style="height:22px"></div>
<hr />
<p><a name="video"></a><br />
<h2>Video</h2>
<div class="code">
<pre>
//** Video **
// 02 videos source
app.load("/Volumes/Media_G5/Ben/Tutorials/clip1.mov");
app.append("/Volumes/Media_G5/Ben/Tutorials/clip2.mov");
</pre>
</div>
<p>This section loads the videos that will be used by the script.  You must always have one (no more, no less) app.load() command, after which you may list any number of additional clips using app.append().</p>
<p>Also, these scripts do not support relative paths.  You must include the full paths to the source videos.</p>
<div style="height:22px"></div>
<hr />
<p><a name="segments"></a><br />
<h2>Segments</h2>
<div class="code">
<pre>
//02 segments
app.clearSegments();
app.addSegment(0,0,3587);
app.addSegment(1,0,2707);
app.markerA=0;
app.markerB=6293;
</pre>
</div>
<p>Here's the meat of the script.  app.clearSegments() clears the timeline to ensure that you are starting with a clean slate.  As far as I know, there are no arguments for this command.</p>
<p>app.addSegment() adds the specified frames to the timeline in the order that the app.addSegments() commands appear.  They each require three arguments:</p>
<ul>
<li>Video clip number</li>
<li>Starting frame</li>
<li>Number of frames to add</li>
</ul>
<p>The Video clips are numbered in the order that they are added in the previous section.  The clip referenced by app.load() is always number 0.  In this case, clip2.mov is clip number 1.</p>
<p>The starting frame should be self-explanatory, as should the number of frames to add, though it should be noted that the final argument is NOT equivalent to the ending frame.  Also, because the starting frame is the first one added, the ending frame is not equal to (startingFrame + numberOfFrames) but rather (startingFrame + numberOfFrames - 1).</p>
<p>For example,  app.addSegment(1,15,60); would add frames 15 - 74 from clip2.mov.</p>
<p>app.markerA and app.markerB are optional.  They can be used to select a specific section of the timeline (by setting in and out points to specific frames), but if left out then the default is to simply count the whole timeline as selected.  This is very fortunate because it keeps us from having to calculate the total number of frames in every script.</p>
<div style="height:22px"></div>
<hr />
<p><a name="postproc"></a><br />
<h2>Postproc</h2>
<div class="code">
<pre>
//** Postproc **
app.video.setPostProc(3,3,0);

app.video.setFps1000(23907);

//** Filters **

//** Video Codec conf **
app.video.codec("Copy","CQ=4","0 ");
</pre>
</div>
<p>This section sets post-processing parameters.  I don't really know what function app.video.setPostProc() serves, but i know that it isn't necessary to include this line.  I leave it out of all my custom scripts and they still function just fine.</p>
<p>app.video.setFps1000() sets the framerate of the timeline:</p>
<ul>
<li>1000 = 1 Fps</li>
<li>23907 = 23.907 Fps</li>
<li>29970 = 29.97 Fps</li>
<li>30000 = 30 Fps</li>
</ul>
<p>You cannot set the framerate below 1 Fps (the value of app.video.setFps1000() cannot be less than 1000).</p>
<p>Filters would be listed under //** Filters ** but I haven't applied any to this timeline.</p>
<p>app.video.codec() specifies some codec settings.  I often leave this out of my scripts and simply set these parameters via the CLI or GUI when I run the script.</p>
<div style="height:22px"></div>
<hr />
<p><a name="audio"></a><br />
<h2>Audio</h2>
<div class="code">
<pre>
//** Audio **
app.audio.reset();
app.audio.codec("copy",128,0,"");
app.audio.normalizeMode=0;
app.audio.normalizeValue=0;
app.audio.delay=0;
app.audio.mixer("NONE");
</pre>
</div>
<p>I'm not going to get deep into audio in this post (you won't find anything about codec settings here), but I'll run through some basics.  </p>
<p>The normalizeMode and normalizeValue variables can be replaced with a single normalize on / off variable like so:</p>
<pre>app.audio.normalize=0;</pre>
<p>Where 0 is "off" and 1 is "on".  The same goes for the delay variable, which determines how much of an offset there is between the audio and the video (in milliseconds).</p>
<p>app.audio.mixer can take values of "NONE", "STEREO", or "MONO".</p>
<div class="code">
<pre>
app.setContainer("AVI");
setSuccess(1);
//app.Exit();

//End of script
</pre>
</div>
<p>app.setContainer() sets your container format (imagine that!).  This accepts the following arguments: PS, ES, TS, OGM, AVI, AVI_DUAL, AVI_UNP, MP4</p>
<p>It may actually accept more that are not documented, MP4 was one that I found through trial and error.</p>
<p>I am not entirely sure what setSuccess(1) does, but I leave it alone and it doesn't bother me.</p>
<p>If you uncomment app.Exit() it will quit Avidemux upon completing the script.  This, however, is not recommended unless you add a save command before it.  I have never been able to get the save commands to work reliably, so I just incorporate them into the CLI commands I use to run my scripts.  That said, app.save(filename_goes_here) is supposed to do the trick.</p>
<div style="height:22px"></div>
<hr />
<p><a name="running"></a><br />
<h2>Running Your Script</h2>
<p>You can run a script by opening up the GUI and selecting "Load/Run Project" or with the CLI, as below:</p>
<div class="code">
<pre>
avidemux2_cli
--run YOUR_SCRIPT_HERE --save YOUR_OUTPUT_FILE_HERE
--quit
</pre>
</div>
<div style="height:22px"></div>
<hr />
<p><a name="moreinfo"></a><br />
<h2>More Information</h2>
<p>More information on this topic can be found <a href="http://avidemux.org/admWiki/index.php?title=Scripting">here</a> and <a href="http://avidemux.org/admWiki/index.php?title=Scripting_tutorial">here</a> on the Avidemux wiki.</p>
<p>That wraps up today's lesson on the basic Avidemux script.  Soon I will be posting some more advanced tips and tricks, including elements and commands not found in a basic Avidemux project file.</p>
<p>If you found this post helpful, please leave feedback in the comments section below.  If there is anything that you need further clarified, or that you would like included in the next, more advanced post, do the same.</p>
<div style="height:22px"></div>
]]></content:encoded>
			<wfw:commentRss>http://backstar.com/blog/2009/10/20/avidemux-basic-script-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

