Monday, August 12, 2013

converting video for a media player (Roku, Panasonic, Android)

Media players are awesome, but only play certain types of videos.  Currently I work with a newish Panasonic TV (awesome), a Roku (very good), and a Bluray player with a USB port (pretty good).

All of these are rather particular about which videos and which codecs and which audio they'll play.  Sometimes everything will be great, but the sound will be out of sync!  Or everything will be in sync... until the end of the movie, where things will gradually get messed up.

It's helpful to have a workflow to iron out video conversion issues quickly.

What finally worked for me was:

1) install Handbrake (both handbrake-gtk and handbrake-cli)
2) convert 20-ish seconds several minutes into the program
3) copy video to USB stick
4) put in media player, try it
5) change conversion settings, repeat from step 2

Here is step #2 in a command line:
HandBrakeCLI -i input.avi --start-at duration:200 --stop-at duration:20 -o z.mp4


Lastly, it's easy to automate this.  This debugging script prints out input.mp4 for each input.avi file:
for input in *.avi ; do echo ${input%.avi}.mp4 ; done

Many video files have spaces, which Linux doesn't like too well.  Quote them:
for input in *.avi ; do echo "$input" "${input%.avi}.mp4" ; done

Putting it all together, we can convert all our videos to mediaplayer-friendly MP4 files with this one-liner.  In my case I found adding the "deblock" filter made my bad source files a little nicer to watch:
for input in *.avi ; do HandBrakeCLI -i "$input" --deblock -o "${input%.avi}.mp4" ; done

If you're insane like me, convert the movies in parallel, two at a time (P2):
for input in *.avi ; do echo "${input%.avi}" ; done | xargs -i -P2 HandBrakeCLI -i "{}".avi -o "{}".mp4 
The output will stutter, as Handbrake will write multiple status lines on top of each other, but them's the breaks.


A version of this on bashoneliners.com





1 comment:

  1. You may also try this method to solve can't play AVI on Roku at http://www.idealshare.net/video-converter/roku-avi.html

    ReplyDelete