So you say you want to use your ROKU TV as a media server. Fine, that isn’t something it does out of the box. You need to go and get RoksBox (http://roksbox.com/home/)
Well to make your Roksbox media server work you have to set up your directory structure in the way it wants with a parent directory named Media and three child directories named: Photos, Music and Videos.
OK then. If you are like me then the first two are already set up but the third is not. All those videos you took with your camera are in your photos directory and, well, you don’t want to have move them by hand and then convert them by hand.
Powershell to the rescue.
I wrote a neat little script that will go through the directory tree in your photos directory, find the video files, copy them to a new directory under Videos and convert them to the appropriate format.
First thing you need to do is to download Handbrake (http://handbrake.fr/) this will be to tool used to convert the files.
Follow these instructions to get the code needed to call Handbrake and convert from the script. - http://perfp.wordpress.com/2010/08/25/mass-converting-video-files-using-powershell-and-handbrake/
Essentially you are looking for the one line that looks like this:
"C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe" -i $file -t 1 -c 1 -o $destname -f mp4 --strict-anamorphic -e x264 -q 20 -a 1 -E faac -6 dpl2 -R 48 -B 160 -D 0.0 -x ref=2:bframes=2:subq=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0 -v 1
You’ll also need to make sure that your Powershell prompt is elevated. If your reading this, then I’m gonna assume you can run that down and figure it out on your own.
Here's the script.
$StartRunDateFrom = Get-Date "01/01/2012"
$rootpath = "E:\Photos\*"
$BaseNewDir = "E:\Videos\"
$FoundMovie = $false
$ExtensionArray=".3gp",".mov",".mpg",".mpeg",".wmv",".avi"
$NewFullName = ""
#loop through directories under root
foreach($folder in Get-Childitem $rootpath)
{
#Check to see if it is within the date range
if($folder.lastwritetime –gt $StartRunDateFrom)
{
foreach($file in Get-Childitem $folder)
{
foreach ($filetype in $ExtensionArray)
{
#find one match and then break
if ($file.fullname -like "*" + $filetype)
{
$FoundMovie = $true
break
}
}
}
#if we found a movie
if($FoundMovie)
{
#Get current child path from root
echo("booya: " + $folder.name)
$CopyToDir = $BaseNewDir + $folder.name
#Create new folder location in videos directory
new-item -path $CopyToDir -type directory -force | out-null
#copy files
foreach($file in Get-Childitem $folder)
{
foreach ($filetype in $ExtensionArray)
{
if ($file.fullname -like "*" + $filetype)
{
$FileNameNoExtension = [system.io.path]::GetFilenameWithoutExtension($file.name)
#The file name at the end of the process
$NewNewFullName = $CopyToDir + "\" + $FileNameNoExtension + ".mp4"
#if the file doesn't exist, copy and convert
if (!(test-path $NewNewFullName))
{
& "C:\Program Files\Handbrake\HandBrakeCLI.exe" -i $file.fullname -t 1 -c 1 –o
$NewNewFullName -f mp4 -4 --strict-anamorphic -e x264 -q 20 --vfr -a 1 -E faac
-B 160 -6 dpl2 -R Auto -D 0 --gain=0 --audio-copy-mask none --audio-fallback
ffac3 -x ref=1:weightp=1:subq=2:rc-lookahead=10:trellis=0:8x8dct=0 --verbose=1
}
}
}
}
}
#end if
#reset variables
$FoundMovie = $false
}
}
#end loop
Copy it and save it as FileMovieCopier.ps1. Set your root paths appropriately, set you date start variable correctly. Run it.