16 November 2012

Bleh!  I’ve been so busy with the new position I started in April I’ve fallen off posting on this blog.  I have a lot of Powershell stuff I want to post—creating progress/activity bars, hashing, and perhaps a series on creating a simple text console.  I’ve also not been paying attention to replies, sorry!  I get so much spam from this blog that Gmail started dumping all my email alerts to comments in my spam box, which I never check.  I did respond to a couple, though… and realized I REALLY need to build-out the styling of the reply section and add the functionality to reply to comments!

Anyway, I just wanted to drop this quick and easy one here that I had to figure out last night.  I tried googling a solution for batch conversion last night when I needed to convert about 40 flv’s to mp4.  The web yielded nothing too great.  One site had a Powershell script but it didn’t work.  So, I just took from it what parameters I had to pass to the VLC application and wrote my own script.

This script has to be run from the directory where the videos are and it outputs them to the same directory.  I’m using Powershell 2.0 on Windows 7 Ultimate with VLC 2.0.4

$fileItems = Get-childitem -filter *.flv

ForEach ($file in $fileItems) {
$destination = “$($file.fullname).mp4”
start-process “C:\Program Files (x86)\VideoLAN\VLC\vlc.exe” “-I dummy -vvv “”$($file.fullname)”” `
–sout=#transcode{vcodec=h264,vb=1024,acodec=mpga,ab=192,channels=2,deinterlace}:standard{access=file,mux=ts,dst=””$destination””} vlc://quit” -wait
}

The parts:

  • $fileItems = Get-childitem -filter *.flv
    • get’s all of the items in the folder that end in .flv (this is why you have to run it in the same folder, I was too lazy that late at night to put in an Open Dialog box 😉 )
  • ForEach ($file in $fileItems) {
    • begins our For loop that basically says “For each file you found in your enumeration results, do the following”
  • $destination =”$($file.fullname).mp4″
    • creates the full-path file name we are SAVING the file as.  I found it necessary to put the full path and set it in a variable because VLC didn’t like it otherwise.  I suspect because the VLC executable is in another directory than the files.  .fullname is a property of the object that is returned that is the fully-qualified path of the file.  If you want to modify anything and just want to use the filename (including extension) then it’s just .name
  • start-process “C:\Program Files (x86)\VideoLAN\VLC\vlc.exe” “-I dummy -vvv “”$($file.fullname)”” ` –sout=#transcode{vcodec=h264,vb=1024,acodec=mpga,ab=192,channels=2,deinterlace}:standard{access=file,mux=ts,dst=””$destination””} vlc://quit” -wait
    • Is technically one line.  The backtick (`) tells Powershell the command continues on the next line.
    • To be honest I don’t know what all the parameters do that are being passed to VLC but I do know the important ones:  vcodec is the name of the video codec you want to use to encode, vb is the video bitrate you want to encode at, acodec is the audio codec you want to encode with, and ab is the audio bitrate you want to encode at.   Channels is the number of audio channels.  dst is the destination file you want to save to.
    • Notice I have $destination surrounded in double quotes.  This is so when powershell actually passes that string to VLC it will put quotes around the destination file string.  This is necessary in the event you have spaces in your path and/or filename itself.  The vlc://quit tells VLC to exit when it’s done transcoding that file.  The -wait tells powershell to not go on to the next one until that current one is complete (lest you crash VLC…

Hope this saves someone some time 🙂


3 Responses to “Using Powershell to Batch Convert with VLC”

  • Marius
    January 6th, 2013 at 9:24 am     

    Had to modify for use in Windows 8 Enterprise on my machine anyway the above did not work, but only minor updates though, thanks for making this available, hopefully this will help others and save precious hours 🙂

    PS C:\Users\mariusr\Videos\Series\Nashville> $fileItems = Get-childitem -filter *.flv
    ForEach ($file in $fileItems) {
    $destination = “$($file.fullname).mp4”
    start-process “C:\Software\vlc\vlc-2.0.4-win64\vlc-2.0.4\vlc.exe” “-I dummy -vvv “”$file”” `
    –sout=transcode{vcodec=h264,vb=1024,acodec=mpga,ab=192,channels=2,deinterlace}:standard{access=file,mux=ts,dst=””$destination””} vlc://quit” -wait
    }

  • thegeek
    January 6th, 2013 at 8:24 pm     

    Awesome, thanks for sharing! I haven’t made the jump to 8 yet, how do you like it?

  • Marius
    January 12th, 2013 at 10:41 pm     

    Once you get use to the start bar not being there like before and you actually start using the new gestures it actually makes sense and no touch screen yet, but acquired a touch mouse which has been very useful. Been using it since RC and no blue screens after Beta and using all my apps with some updates to utilize the new interface.

You must be logged in to post a comment.

Links

RSS 2.0 Feed

Support

Brave Rewards
This site supports Brave Rewards. Please consider tipping or adding it to your monthly contributions if you find anything helpful!

For other ways: Support

Support this blog! If you have found it helpfu you can send me crypto. Any amount is appreciated!
ETH: 0xBEaF72807Cb5f4a8CCE23A5E7949041f62e8F8f0 | BTC: 3HTK5VJWr3vnftxbrcWAszLkRTrx9s5KzZ | SHIB: 0xdb209f96dD1BdcC12f03FdDfFAD0602276fb29BE
Brave Users you can send me BAT using the browser.