Server:Server Status

Bash Script to Clip Ripped Home Movies

Bash script I wrote to assist in clipping home movies. Still some more to do, but here's a summary.

Particularly useful was the code I used to find the difference under bash between start and end points using date...and keeping the result in a format ffmpeg could understand.

#!/bin/bash<br /> #&nbsp;<br /> #&nbsp;Title:&nbsp;HomeMoviesClipper.sh<br /> #&nbsp;Description:&nbsp;Use&nbsp;ffmpeg&nbsp;to&nbsp;split&nbsp;raw&nbsp;home&nbsp;movie&nbsp;captures&nbsp;into&nbsp;clips<br /> #&nbsp;Original&nbsp;Author:&nbsp;Joseph&nbsp;Gullo&nbsp;(surfrock66)&nbsp;(surfrock66@surfrock66.com)<br /> #<br /> #&nbsp;This&nbsp;script&nbsp;works&nbsp;with&nbsp;a&nbsp;very&nbsp;specific&nbsp;set&nbsp;of&nbsp;constraints&nbsp;and&nbsp;formats&nbsp;to&nbsp;<br /> #&nbsp;&nbsp;take&nbsp;raw&nbsp;video&nbsp;captures&nbsp;and&nbsp;split&nbsp;them&nbsp;into&nbsp;clips&nbsp;of&nbsp;events.&nbsp;&nbsp;Each&nbsp;of&nbsp;<br /> #&nbsp;&nbsp;these&nbsp;movies&nbsp;was&nbsp;captured,&nbsp;using&nbsp;a&nbsp;Dazzle&nbsp;USB&nbsp;video&nbsp;capture&nbsp;device,&nbsp;<br /> #&nbsp;&nbsp;into&nbsp;h264&nbsp;video&nbsp;and&nbsp;mp3&nbsp;audio,&nbsp;using&nbsp;VLC.&nbsp;&nbsp;These&nbsp;original&nbsp;tapes&nbsp;were&nbsp;<br /> #&nbsp;&nbsp;typically&nbsp;close&nbsp;to&nbsp;2&nbsp;hours&nbsp;long,&nbsp;however&nbsp;capture&nbsp;was&nbsp;often&nbsp;left&nbsp;to&nbsp;run,&nbsp;<br /> #&nbsp;&nbsp;creating&nbsp;videos&nbsp;that&nbsp;were&nbsp;8+&nbsp;hours&nbsp;long.&nbsp;&nbsp;The&nbsp;capture&nbsp;device&nbsp;produced&nbsp;<br /> #&nbsp;&nbsp;video&nbsp;that&nbsp;was&nbsp;480x480&nbsp;and&nbsp;audio&nbsp;that&nbsp;only&nbsp;contains&nbsp;1&nbsp;channel&nbsp;(recorded&nbsp;<br /> #&nbsp;&nbsp;through&nbsp;stereo),&nbsp;and&nbsp;the&nbsp;output&nbsp;video&nbsp;will&nbsp;retain&nbsp;this.&nbsp;&nbsp;The&nbsp;desired&nbsp;<br /> #&nbsp;&nbsp;format&nbsp;is&nbsp;high-bitrate&nbsp;h264&nbsp;and&nbsp;aac&nbsp;audio,&nbsp;encapsulated&nbsp;in&nbsp;.mp4&nbsp;files.&nbsp;<br /> #&nbsp;&nbsp;This&nbsp;script&nbsp;also&nbsp;works&nbsp;within&nbsp;a&nbsp;predictable&nbsp;directory&nbsp;environment&nbsp;<br /> #&nbsp;&nbsp;because&nbsp;of&nbsp;how&nbsp;specific&nbsp;the&nbsp;task&nbsp;is,&nbsp;and&nbsp;because&nbsp;I'm&nbsp;a&nbsp;lazy&nbsp;bastard&nbsp;<br /> #&nbsp;&nbsp;that&nbsp;doesn't&nbsp;want&nbsp;to&nbsp;code&nbsp;bunch&nbsp;of&nbsp;directory&nbsp;logic.&nbsp;&nbsp;The&nbsp;script&nbsp;first&nbsp;<br /> #&nbsp;&nbsp;queries&nbsp;the&nbsp;input&nbsp;file,&nbsp;then&nbsp;works&nbsp;on&nbsp;this&nbsp;file&nbsp;recursing&nbsp;the&nbsp;steps&nbsp;<br /> #&nbsp;&nbsp;for&nbsp;each&nbsp;clip.&nbsp;&nbsp;Each&nbsp;clip&nbsp;requires&nbsp;an&nbsp;output&nbsp;name,&nbsp;a&nbsp;start&nbsp;timecode&nbsp;<br /> #&nbsp;&nbsp;(formatted&nbsp;hh:mm:ss.nnn)&nbsp;and&nbsp;an&nbsp;ending&nbsp;timecode.&nbsp;&nbsp;This&nbsp;is&nbsp;part&nbsp;of&nbsp;<br /> #&nbsp;&nbsp;some&nbsp;of&nbsp;the&nbsp;headache,&nbsp;as&nbsp;ffmpeg&nbsp;processes&nbsp;clips&nbsp;with&nbsp;a&nbsp;start&nbsp;time&nbsp;<br /> #&nbsp;&nbsp;and&nbsp;a&nbsp;duration,&nbsp;meaning&nbsp;you&nbsp;have&nbsp;to&nbsp;do&nbsp;the&nbsp;difference&nbsp;math&nbsp;yourself.&nbsp;&nbsp;<br /> #&nbsp;&nbsp;I&nbsp;take&nbsp;care&nbsp;of&nbsp;this&nbsp;in&nbsp;there.&nbsp;&nbsp;After&nbsp;producing&nbsp;a&nbsp;clip,&nbsp;the&nbsp;script&nbsp;<br /> #&nbsp;&nbsp;will&nbsp;ask&nbsp;the&nbsp;user&nbsp;if&nbsp;they&nbsp;want&nbsp;to&nbsp;create&nbsp;another&nbsp;clip&nbsp;from&nbsp;the&nbsp;same&nbsp;<br /> #&nbsp;&nbsp;source&nbsp;file,&nbsp;at&nbsp;which&nbsp;it&nbsp;recurses&nbsp;through&nbsp;a&nbsp;prompting&nbsp;loop.&nbsp;&nbsp;The&nbsp;<br /> #&nbsp;&nbsp;script&nbsp;also&nbsp;can&nbsp;be&nbsp;run&nbsp;from&nbsp;the&nbsp;command&nbsp;line...however&nbsp;in&nbsp;CLI&nbsp;mode,&nbsp;<br /> #&nbsp;&nbsp;the&nbsp;intent&nbsp;is&nbsp;to&nbsp;NOT&nbsp;allow&nbsp;the&nbsp;script&nbsp;to&nbsp;re-prompt&nbsp;for&nbsp;additional&nbsp;cips&nbsp;<br /> #&nbsp;&nbsp;from&nbsp;the&nbsp;same&nbsp;source&nbsp;video.<br /> #&nbsp;<br /> #&nbsp;The&nbsp;script&nbsp;can&nbsp;optionally&nbsp;take&nbsp;4&nbsp;command&nbsp;line&nbsp;arguments:<br /> #&nbsp;&nbsp;1)&nbsp;The&nbsp;filename&nbsp;for&nbsp;the&nbsp;source&nbsp;video,&nbsp;without&nbsp;extension<br /> #&nbsp;&nbsp;2)&nbsp;The&nbsp;desired&nbsp;resulting&nbsp;clip&nbsp;name,&nbsp;without&nbsp;extension<br /> #&nbsp;&nbsp;3)&nbsp;The&nbsp;start&nbsp;timecode&nbsp;for&nbsp;the&nbsp;clip,&nbsp;format&nbsp;hh:mm:ss.nnn<br /> #&nbsp;&nbsp;4)&nbsp;The&nbsp;end&nbsp;timecode&nbsp;for&nbsp;the&nbsp;clip,&nbsp;format&nbsp;hh:mm:ss.nnn<br /> #<br /> #&nbsp;Variables:<br /> #&nbsp;&nbsp;INPUTFILE&nbsp;-&nbsp;Input&nbsp;video&nbsp;filename,&nbsp;without&nbsp;extension<br /> #&nbsp;&nbsp;OUTPUTFILE&nbsp;-&nbsp;Clip&nbsp;output&nbsp;filename,&nbsp;without&nbsp;extension<br /> #&nbsp;&nbsp;STARTTIME&nbsp;-&nbsp;Clip&nbsp;starting&nbsp;timecode,&nbsp;format&nbsp;hh:mm:ss.nnn<br /> #&nbsp;&nbsp;ENDTIME&nbsp;-&nbsp;Clip&nbsp;ending&nbsp;timecode,&nbsp;format&nbsp;hh:mm:ss.nnn<br /> #&nbsp;&nbsp;NANODIFF&nbsp;-&nbsp;Difference&nbsp;between&nbsp;start&nbsp;and&nbsp;end&nbsp;timecode,&nbsp;in&nbsp;milliseconds<br /> #&nbsp;&nbsp;NUMSECS&nbsp;-&nbsp;Timecoe&nbsp;difference&nbsp;in&nbsp;whole&nbsp;seconds<br /> #&nbsp;&nbsp;NUMNANO&nbsp;-&nbsp;Timecode&nbsp;difference&nbsp;remainder&nbsp;in&nbsp;milliseconds<br /> #&nbsp;&nbsp;REPLY&nbsp;-&nbsp;Flag&nbsp;for&nbsp;checking&nbsp;if&nbsp;the&nbsp;script&nbsp;should&nbsp;create&nbsp;another&nbsp;clip<br /> #&nbsp;&nbsp;CLIFLAG&nbsp;-&nbsp;Flag&nbsp;set&nbsp;if&nbsp;command&nbsp;line&nbsp;mode&nbsp;is&nbsp;detected,&nbsp;to&nbsp;prevent&nbsp;prompting<br /> #<br /> <br /> #&nbsp;Prompt&nbsp;the&nbsp;user&nbsp;for&nbsp;all&nbsp;parameters,&nbsp;by&nbsp;asking&nbsp;for&nbsp;the&nbsp;source&nbsp;clip&nbsp;name,&nbsp;then&nbsp;calling<br /> #&nbsp;&nbsp;the&nbsp;function&nbsp;which&nbsp;prompts&nbsp;for&nbsp;the&nbsp;clip&nbsp;info.&nbsp;&nbsp;This&nbsp;can&nbsp;safely&nbsp;call&nbsp;the&nbsp;clip-info&nbsp;<br /> #&nbsp;&nbsp;prompting&nbsp;function,&nbsp;as&nbsp;this&nbsp;should&nbsp;only&nbsp;be&nbsp;used&nbsp;once&nbsp;per&nbsp;execution,&nbsp;if&nbsp;at&nbsp;all.<br /> PROMPTFULL()&nbsp;{<br /> &nbsp;&nbsp;echo&nbsp;"---What&nbsp;is&nbsp;the&nbsp;source&nbsp;video&nbsp;name?&nbsp;(No&nbsp;Extension)&nbsp;(Inside&nbsp;/home/surfrock66/Videos/HomeMoviesRaw/):"<br /> &nbsp;&nbsp;#&nbsp;First&nbsp;point&nbsp;of&nbsp;possible&nbsp;declaration&nbsp;for&nbsp;INPUTFILE<br /> &nbsp;&nbsp;read&nbsp;INPUTFILE<br /> &nbsp;&nbsp;#&nbsp;Execute&nbsp;the&nbsp;PROMPCLIP&nbsp;function<br /> &nbsp;&nbsp;PROMPTCLIP<br /> }<br /> <br /> #&nbsp;Prompt&nbsp;the&nbsp;user&nbsp;for&nbsp;the&nbsp;clip&nbsp;name,&nbsp;start&nbsp;time,&nbsp;and&nbsp;end&nbsp;time.&nbsp;&nbsp;<br /> PROMPTCLIP()&nbsp;{<br /> &nbsp;&nbsp;echo&nbsp;"---What&nbsp;is&nbsp;the&nbsp;output&nbsp;filename&nbsp;for&nbsp;this&nbsp;clip?&nbsp;(No&nbsp;Extension):"<br /> &nbsp;&nbsp;#&nbsp;First&nbsp;point&nbsp;of&nbsp;possible&nbsp;declaration&nbsp;for&nbsp;OUTPUTFILE<br /> &nbsp;&nbsp;read&nbsp;OUTPUTFILE<br /> &nbsp;&nbsp;echo&nbsp;"---What&nbsp;is&nbsp;the&nbsp;timecode&nbsp;for&nbsp;the&nbsp;start&nbsp;of&nbsp;this&nbsp;clip?&nbsp;(##:##:##.###):"<br /> &nbsp;&nbsp;#&nbsp;First&nbsp;point&nbsp;of&nbsp;possible&nbsp;declaration&nbsp;for&nbsp;STARTTIME<br /> &nbsp;&nbsp;read&nbsp;STARTTIME<br /> &nbsp;&nbsp;echo&nbsp;"---What&nbsp;is&nbsp;the&nbsp;timecode&nbsp;for&nbsp;the&nbsp;end&nbsp;of&nbsp;this&nbsp;clip?&nbsp;(##:##:##.###):"<br /> &nbsp;&nbsp;#&nbsp;First&nbsp;point&nbsp;of&nbsp;possible&nbsp;declaration&nbsp;for&nbsp;ENDTIME<br /> &nbsp;&nbsp;read&nbsp;ENDTIME<br /> }<br /> <br /> #&nbsp;This&nbsp;function&nbsp;handles&nbsp;the&nbsp;timecode&nbsp;calculations&nbsp;to&nbsp;find&nbsp;the&nbsp;clip&nbsp;duration,&nbsp;<br /> #&nbsp;&nbsp;then&nbsp;executes&nbsp;the&nbsp;actial&nbsp;ffmpeg&nbsp;command.<br /> PROCESSVID()&nbsp;{<br /> &nbsp;&nbsp;#&nbsp;Calculate&nbsp;the&nbsp;actuall&nbsp;difference,&nbsp;in&nbsp;milliseconds&nbsp;(but&nbsp;we'll&nbsp;call&nbsp;them&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;nanoseconds,&nbsp;because&nbsp;that's&nbsp;how&nbsp;the&nbsp;date&nbsp;command&nbsp;works)&nbsp;between&nbsp;the&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;start&nbsp;time&nbsp;and&nbsp;end&nbsp;time.&nbsp;&nbsp;This&nbsp;relies&nbsp;heavily&nbsp;on&nbsp;the&nbsp;"date"&nbsp;command.&nbsp;&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;It&nbsp;can&nbsp;convert&nbsp;formatted&nbsp;timecodes&nbsp;between&nbsp;different&nbsp;format&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;conventions,&nbsp;but&nbsp;to&nbsp;go&nbsp;from&nbsp;something&nbsp;resembling&nbsp;a&nbsp;standard&nbsp;video&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;editing&nbsp;timecode&nbsp;to&nbsp;a&nbsp;raw&nbsp;nanosecond&nbsp;count&nbsp;is&nbsp;a&nbsp;PAIN&nbsp;IN&nbsp;THE&nbsp;ASS.&nbsp;&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;This&nbsp;strips&nbsp;out&nbsp;the&nbsp;amount&nbsp;of&nbsp;hours&nbsp;in&nbsp;milliseconds,&nbsp;then&nbsp;the&nbsp;number&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;of&nbsp;minutes&nbsp;in&nbsp;milliseconds,&nbsp;then&nbsp;the&nbsp;number&nbsp;of&nbsp;seconds&nbsp;in&nbsp;milliseconds,&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;then&nbsp;the&nbsp;number&nbsp;of&nbsp;nanoseconds&nbsp;in&nbsp;milliseconds.&nbsp;&nbsp;It&nbsp;then&nbsp;adds&nbsp;them&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;together,&nbsp;creates&nbsp;a&nbsp;full&nbsp;millisecond&nbsp;count&nbsp;for&nbsp;the&nbsp;start&nbsp;an&nbsp;end&nbsp;time,&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;and&nbsp;then&nbsp;finds&nbsp;the&nbsp;difference,&nbsp;in&nbsp;milliseconds.<br /> &nbsp;&nbsp;NANODIFF=$(($(($(($(date&nbsp;-d&nbsp;$ENDTIME&nbsp;+%-H)&nbsp;<em>&nbsp;3600000))&nbsp;+&nbsp;$(($(date&nbsp;-d&nbsp;$ENDTIME&nbsp;+%-M)&nbsp;</em>&nbsp;60000))&nbsp;+&nbsp;$(($(date&nbsp;-d&nbsp;$ENDTIME&nbsp;+%-S)&nbsp;<em>&nbsp;1000))&nbsp;+&nbsp;$(($(date&nbsp;-d&nbsp;$ENDTIME&nbsp;+%-N)&nbsp;/&nbsp;1000000))))&nbsp;-&nbsp;$(($(($(date&nbsp;-d&nbsp;$STARTTIME&nbsp;+%-H)&nbsp;</em>&nbsp;3600000))&nbsp;+&nbsp;$(($(date&nbsp;-d&nbsp;$STARTTIME&nbsp;+%-M)&nbsp;<em>&nbsp;60000))&nbsp;+&nbsp;$(($(date&nbsp;-d&nbsp;$STARTTIME&nbsp;+%-S)&nbsp;</em>&nbsp;1000))&nbsp;+&nbsp;$(($(date&nbsp;-d&nbsp;$STARTTIME&nbsp;+%-N)&nbsp;/&nbsp;1000000))))))<br /> &nbsp;&nbsp;#&nbsp;Convert&nbsp;the&nbsp;resulting&nbsp;difference,&nbsp;in&nbsp;millisecodns,&nbsp;into&nbsp;seconds<br /> &nbsp;&nbsp;NUMSECS=$(($NANODIFF&nbsp;/&nbsp;1000))<br /> &nbsp;&nbsp;#&nbsp;Convert&nbsp;the&nbsp;reaminder&nbsp;of&nbsp;the&nbsp;resulting&nbsp;difference,&nbsp;in&nbsp;milliseconds,<br /> &nbsp;&nbsp;#&nbsp;&nbsp;to&nbsp;milliseconds<br /> &nbsp;&nbsp;NUMNANO=$(($NANODIFF&nbsp;%&nbsp;1000))<br /> &nbsp;&nbsp;#&nbsp;Print&nbsp;out&nbsp;the&nbsp;ffmpeg&nbsp;command&nbsp;that&nbsp;is&nbsp;generated,&nbsp;mostly&nbsp;for&nbsp;debugging<br /> &nbsp;&nbsp;echo&nbsp;"\nCommand:&nbsp;ffmpeg&nbsp;-i&nbsp;\"/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE.mp4\"&nbsp;-ss&nbsp;$STARTTIME&nbsp;-t&nbsp;$NUMSECS.$NUMNANO&nbsp;-vcodec&nbsp;libx264&nbsp;-b&nbsp;1500k&nbsp;-s&nbsp;480x480&nbsp;-acodec&nbsp;libfaac&nbsp;-ab&nbsp;192k&nbsp;-ac&nbsp;1&nbsp;-threads&nbsp;8&nbsp;\"/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE/$OUTPUTFILE.mp4\"\n"<br /> &nbsp;&nbsp;#&nbsp;Execute&nbsp;the&nbsp;ffmpeg&nbsp;command,&nbsp;this&nbsp;is&nbsp;the&nbsp;big&nbsp;kahuna.<br /> &nbsp;&nbsp;ffmpeg&nbsp;-i&nbsp;"/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE.mp4"&nbsp;-ss&nbsp;$STARTTIME&nbsp;-t&nbsp;$NUMSECS.$NUMNANO&nbsp;-vcodec&nbsp;libx264&nbsp;-b&nbsp;1500k&nbsp;-s&nbsp;480x480&nbsp;-acodec&nbsp;libfaac&nbsp;-ab&nbsp;192k&nbsp;-ac&nbsp;1&nbsp;-threads&nbsp;8&nbsp;"/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE/$OUTPUTFILE.mp4"<br /> }<br /> <br /> #&nbsp;Start&nbsp;of&nbsp;the&nbsp;main&nbsp;script.&nbsp;&nbsp;Section&nbsp;1:&nbsp;Input&nbsp;validation<br /> #&nbsp;&nbsp;Check&nbsp;that&nbsp;there&nbsp;is&nbsp;a&nbsp;first&nbsp;parameter.&nbsp;&nbsp;If&nbsp;not,&nbsp;Prompt&nbsp;the&nbsp;user&nbsp;for&nbsp;the<br /> #&nbsp;&nbsp;&nbsp;parameters.&nbsp;&nbsp;If&nbsp;there&nbsp;is&nbsp;one,&nbsp;validate&nbsp;the&nbsp;rest&nbsp;of&nbsp;the&nbsp;params,&nbsp;then&nbsp;<br /> #&nbsp;&nbsp;&nbsp;either&nbsp;prompt&nbsp;the&nbsp;user,&nbsp;or&nbsp;use&nbsp;the&nbsp;passed&nbsp;params.<br /> if&nbsp;[&nbsp;-z&nbsp;"$1"&nbsp;]<br /> then<br /> &nbsp;&nbsp;#&nbsp;Call&nbsp;the&nbsp;prompt&nbsp;function,&nbsp;including&nbsp;asking&nbsp;for&nbsp;the&nbsp;source&nbsp;video<br /> &nbsp;&nbsp;PROMPTFULL<br /> else<br /> &nbsp;&nbsp;#&nbsp;Assuming&nbsp;the&nbsp;first&nbsp;parameter&nbsp;exists,&nbsp;check&nbsp;for&nbsp;parameters&nbsp;2,3,&nbsp;and<br /> &nbsp;&nbsp;#&nbsp;&nbsp;4.&nbsp;&nbsp;I'm&nbsp;not&nbsp;validating&nbsp;these&nbsp;strings,&nbsp;mostly&nbsp;because&nbsp;ffmpeg&nbsp;will&nbsp;<br /> &nbsp;&nbsp;#&nbsp;&nbsp;flip&nbsp;out&nbsp;if&nbsp;there's&nbsp;something&nbsp;wrong&nbsp;with&nbsp;them...as&nbsp;you&nbsp;know,&nbsp;it's<br /> &nbsp;&nbsp;#&nbsp;&nbsp;quite&nbsp;verbose.<br /> &nbsp;&nbsp;if&nbsp;[&nbsp;-z&nbsp;"$2"&nbsp;-o&nbsp;-z&nbsp;"$3"&nbsp;-o&nbsp;-z&nbsp;"$4"&nbsp;]<br /> &nbsp;&nbsp;then<br /> &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;If&nbsp;any&nbsp;parameters&nbsp;are&nbsp;invalid,&nbsp;prompt&nbsp;for&nbsp;them&nbsp;all.&nbsp;Even&nbsp;if&nbsp;param&nbsp;1<br /> &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;is&nbsp;successfully&nbsp;detected,&nbsp;re-ask&nbsp;for&nbsp;it.&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"--Parameters&nbsp;are&nbsp;incomplete,&nbsp;switching&nbsp;to&nbsp;prompt&nbsp;mode."<br /> &nbsp;&nbsp;&nbsp;&nbsp;PROMPTFULL&nbsp;<br /> &nbsp;&nbsp;else<br /> &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Pass&nbsp;all&nbsp;the&nbsp;command&nbsp;line&nbsp;parameters&nbsp;to&nbsp;the&nbsp;variables<br /> &nbsp;&nbsp;&nbsp;&nbsp;INPUTFILE="$1"<br /> &nbsp;&nbsp;&nbsp;&nbsp;OUTPUTFILE="$2"<br /> &nbsp;&nbsp;&nbsp;&nbsp;STARTTIME="$3"<br /> &nbsp;&nbsp;&nbsp;&nbsp;ENDTIME="$4"<br /> &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Change&nbsp;the&nbsp;flag&nbsp;to&nbsp;indicate&nbsp;later&nbsp;that&nbsp;this&nbsp;initiated&nbsp;by&nbsp;CLI<br /> &nbsp;&nbsp;&nbsp;&nbsp;CLIFLAG="yes"<br /> &nbsp;&nbsp;fi<br /> fi<br /> <br /> #&nbsp;Create&nbsp;the&nbsp;default&nbsp;output&nbsp;directory,&nbsp;if&nbsp;it's&nbsp;not&nbsp;already&nbsp;created<br /> if&nbsp;[&nbsp;!&nbsp;-d&nbsp;/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE&nbsp;];&nbsp;then<br /> &nbsp;&nbsp;mkdir&nbsp;/home/surfrock66/Videos/HomeMoviesRaw/$INPUTFILE<br /> fi<br /> <br /> #&nbsp;Now...initiate&nbsp;the&nbsp;final&nbsp;video&nbsp;processing<br /> #&nbsp;&nbsp;Declare&nbsp;and&nbsp;initiate&nbsp;the&nbsp;REPLY&nbsp;flag...can&nbsp;be&nbsp;set&nbsp;to&nbsp;anything&nbsp;byt&nbsp;n/N<br /> REPLY="y"<br /> #&nbsp;As&nbsp;long&nbsp;as&nbsp;the&nbsp;REPLY&nbsp;flag&nbsp;isn't&nbsp;n&nbsp;or&nbsp;N,&nbsp;repeat&nbsp;the&nbsp;loop<br /> while&nbsp;[&nbsp;"$REPLY"&nbsp;!=&nbsp;"n"&nbsp;]&nbsp;&&&nbsp;[&nbsp;"$REPLY"&nbsp;!=&nbsp;"N"&nbsp;]<br /> do<br /> &nbsp;&nbsp;#&nbsp;Call&nbsp;the&nbsp;function&nbsp;PROCESSVID<br /> &nbsp;&nbsp;PROCESSVID<br /> &nbsp;&nbsp;#&nbsp;Check&nbsp;to&nbsp;see&nbsp;if&nbsp;the&nbsp;script&nbsp;was&nbsp;run&nbsp;with&nbsp;command&nbsp;line&nbsp;parameters,<br /> &nbsp;&nbsp;#&nbsp;&nbsp;If&nbsp;not,&nbsp;issue&nbsp;a&nbsp;bunch&nbsp;of&nbsp;logic&nbsp;to&nbsp;see&nbsp;if&nbsp;we&nbsp;want&nbsp;to&nbsp;re-run&nbsp;the<br /> &nbsp;&nbsp;#&nbsp;&nbsp;code&nbsp;for&nbsp;new&nbsp;clips<br /> &nbsp;&nbsp;if&nbsp;[&nbsp;-z&nbsp;"$CLIFLAG"&nbsp;]<br /> &nbsp;&nbsp;then<br /> &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Now&nbsp;that&nbsp;we&nbsp;know&nbsp;the&nbsp;script&nbsp;was&nbsp;run&nbsp;in&nbsp;prompt&nbsp;mode,&nbsp;ask&nbsp;the&nbsp;user<br /> &nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;if&nbsp;they&nbsp;want&nbsp;to&nbsp;make&nbsp;another&nbsp;clip,&nbsp;repeating&nbsp;this&nbsp;loop<br /> &nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"---Would&nbsp;you&nbsp;like&nbsp;to&nbsp;create&nbsp;another&nbsp;clip&nbsp;from&nbsp;this&nbsp;input&nbsp;video?&nbsp;{Y/n}"<br /> &nbsp;&nbsp;&nbsp;&nbsp;read&nbsp;REPLY<br /> &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;[&nbsp;"$REPLY"&nbsp;!=&nbsp;"n"&nbsp;]&nbsp;&&&nbsp;[&nbsp;"$REPLY"&nbsp;!=&nbsp;"N"&nbsp;]<br /> &nbsp;&nbsp;&nbsp;&nbsp;then<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROMPTCLIP<br /> &nbsp;&nbsp;&nbsp;&nbsp;fi<br /> &nbsp;&nbsp;#&nbsp;If&nbsp;it&nbsp;was&nbsp;run&nbsp;by&nbsp;command&nbsp;line,&nbsp;essentially&nbsp;abort&nbsp;the&nbsp;loop,<br /> &nbsp;&nbsp;#&nbsp;&nbsp;and&nbsp;the&nbsp;script.<br /> &nbsp;&nbsp;else<br /> &nbsp;&nbsp;&nbsp;&nbsp;REPLY="n"<br /> &nbsp;&nbsp;fi<br /> done<br />

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Raspberry Pi Shadowbox Case

Come on, no one reads this. However I need a place to show off my Raspberry Pi case, so I will make it go here.

OBJECTIVES:

  • Functional case for the Raspberry Pi as a media player
  • Attractive enough to pass the wife-approval test
  • Can end up near the TV without any furniture around it

So I got this idea...let's mount the thing in a shadow box. It can hang on the wall next to the tv, will have some air in the case to dissipate heat, can have all cables routed out one side, and can have a matte to hide internal wires.

Here's the results!

pi1

This is the mount, before any cabling is done.

pi2

Here it is up on the wall, with some of the cable management. The HDMI cable isn't done yet, so it's just hanging out the bottom.

Pi3

On the wall, with cables in and power on, basically the finished product.

pi4

The finished thing, with raspBMC powered up and running.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Redoing Bathrooms

Thought I'd show some updates to the work Jenn and I are doing to redo our bathrooms in the new house. All three full bathrooms had awful green 70's tile which we're removing and replacing. One bathroom (the master) has a green tub as well...we'll be getting that resurfaced.

The steps have been as follows:

  1. Remove old tile, being very careful to preserve it to donate to habitat
  2. Remove existing rotted drywall
  3. Clean all surfaces
  4. Put up concrete backer board
  5. Cut tile, apply mortar, put tile up (usually 4-5 stages per room)
  6. Grout tile
  7. Seal tile
  8. Apply Caulk
  9. Replace Fixtures
Read more »

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Dynamic Menus in WordPress as a CMS

I've been developing a site where I'm using wordpress as a CMS more than a blog, for many reasons. I'm very familiar with it, I like the automated SEO, I think it's simple to use, etc. But one big challenge is the menu navigation and how to set it up. I want this to be automated and I don't want to have to edit the menu every time there's a new page.

To clarify the terms, there's a menu with "solutions" then "products" with 3 sub categories "indoor" "outdoor" and "media players." Plus there's a "guides" area and a "blog" area.

The menu system is handled by the category management. If a page is made that goes into the menu, you simply tag it with the category where it should go. You can click the main header of the menu to go to a page with all the posts in the category. Then you hover over the header of the menu, and I want a dropdown menu with a list of posts in there. I want to limit this to a certain number of posts, then have a button for "more" at the bottom. You can see an example here.

Let's take a look at the code at the start of my menu. This basically encapsulates the markup for the menu, and for the first dropdown. I have this in a separate "nav_menu.php" file but it could go in your header as well.

   

So, take a look at the php code there. First of all, important to note, this disrupts the wordpress loop so we'll need to fix it a little bit later. First, it does a post query limiting the list to one category (you can search by "category_name" but I'm a fan of the Id's) and then setting a limit to how many to pull; I chose 5 by default. Then, there's a while loop that pulls some data from each post and formats it into a listed menu entry. After the while loop closes, I throw out the "more" button which queries the whole category for posts.

If you do just that, every time you try to list posts you'll pull a list of every post you've got and it will supremely annoy you. You need to reset your post query to be able to limit it to the page at hand. At the bottom of my theme's "header.php" file, right before the posts would get displayed by "index.php," I added the following php line:



This will pull the post list based on the categories selected or the specific post listed; all of my links and navigation are handled through those 2 "GET" variables so it will limit the posts queried to anything selected. Make sure to put the @ before $_GET to suppress any errors the get command gets, for example, if there's nothing passed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Rooting to the Palm Pre in Ubuntu

I found a lot of disjointed instructions for rooting to the palm pre in linux, so I thought I'd document the process I used to make it work. These instructions were written using Ubuntu 9.04 Jaunty Jackalope and WebOS version 1.1.0.

  1. Add the repository for virtualbox to your sources list. For Ubuntu 9.04, add deb http://download.virtualbox.org/virtualbox/debian jaunty non-free A list of repos for other distros can be found here: http://www.virtualbox.org/wiki/Linux_Downloads, or if you want to download the .deb and install it that way, go here and choose version 2.2: http://www.virtualbox.org/wiki/Download_Old_Builds I know V-Box is past 3 now, but I had the most success with 2.2. The source for the GPG key can be found here: http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc. Virtualbox is a virtual machine platform that acts as a development platform for the pre, so you may not use it much, but you should do it anyway.
  2. Install virtualbox using the following command: sudo apt-get install virtualbox-2.2
  3. Install the Java JRE using the following terminal command: sudo apt-get install sun-java6-jre
  4. Download the Palm Mojo SDK at the following website: http://developer.palm.com/index.php?option=com_ajaxregister&view=register&sdkdownload. You will be asked to register as a developer, at which point you will be able to choose to Download the sdk, and you should choose the Linux SDK, which will say it is designed for Ubuntu 8.04.
  5. The SDK is a .deb file. You should double-click this file, which will prompt you to install. Install the package.
  6. Download the Novacom Driver from the following link: https://cdn.downloads.palm.com/sdkdownloads/1.1/sdkBinaries/palm-novacom_0.3-svn177284-hud9_i386.deb Install it exactly as you did the SDK
  7. Open your palm pre and load the launcher. Type the following text EXACTLY: upupdowndownleftrightleftrightbastart
  8. This will launch a dialogue asking you to put the phone into dev mode. Slide the switch to activate dev mode, and agree when it asks you to reboot the phone. This same procedure is used to remove the phone from developer mode, and you will be asked to do that later.
  9. Once the phone comes back on, plug it into the computer using the USB cable, and choose "Just Charge" on the phone's screen.
  10. You now have terminal access to your phone. Open a terminal and type: cd /opt/Palm/novacom If this doesn't work, some people report the files for novaterm are located in /opt/nova/bin
  11. Type novaterm and you should be brought to a command prompt that displays:"root@castle:/#
  12. Before taking this step, make sure you either have a data signal, or make sure you have wifi access; you need the internet here. Type the following command in EXACTLY to enable Optiware . In fact, it's probably wise to copy and paste them into your terminal: cd /tmp
    wget http://gitorious.org/webos-internals/bootstrap/blobs/raw/master/optware-bootstrap.sh
    sh optware-bootstrap.sh
    Follow the on-screen instructions to complete the setup.
  13. This step istalls the "Quilt" patch manager (pun intended.) Type the following code in exactly: cd /tmp
    wget http://gitorious.org/webos-internals/bootstrap/blobs/raw/master/quilt-bootstrap.sh
    sh quilt-bootstrap.sh
  14. The Pre already has a package management app, called FileCoaster, meaning you can install apps from the pre, without rooting in through a terminal, over the web. To install the package manager though, I recommend using the terminal. At the Pre terminal prompt, type this exactly: sudo ipkg -o /var install http://www.precentral.net/sites/precentral.net/files/webos-homebrew-apps/feeds/com.palm_.net_.precoder.fcoaster_1.1.1_all.ipk Check here for updated links to .ipk files for versions of FileCoaster past 1.1.1.
  15. It's annoying to have to type the whole code to turn the developer mode on and off, but fortunately there's a patch to put a button in your launcher. This uses the procedure for applying patches using quilt, and there's an instruction sheet for this process here. Basically, you're going to enter the following code exactly:sudo mount -o remount,rw /
    cd /
    sudo quilt import /opt/src/modifications/luna/enable-dev-mode-icon.patch
    sudo quilt push
    sudo mount -o remount,ro /
    For a complete list of patches you can apply using this procedure, look here: http://www.webos-internals.org/wiki/Portal:Patches_to_webOS
  16. To log out of your pre and close terminal access, type: exit
  17. Turn off your pre, then turn it back on.
  18. While this is not necessarily a step, you can now ssh to your pre even if you don't have a USB cable attached. I'll check my home router's config to find the IP of the pre (or just use www.checkmyip.com) and ssh in on port 222 with the following command:ssh <IP Address> -p 222 -l <username>

That should set you up to do most of what you could ever want to do with homebrew on the pre. Check out this thread for a list of homebrew apps, and the links to the .ipk files which you can use to install via FileCoaster: http://forums.precentral.net/homebrew-apps/194104-links-all-homebrew-apps-updated-7-31-a.html.

I credit this article to the following sources:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -