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





3 comments:

  1. I use iDealshare VideoGo to convert various video formats like mkv, vob, flv, mpg, webm, h.265, etc for media player https://www.idealshare.net/video-converter/roku-avi.html

    ReplyDelete
  2. Avdshare Video Converter is also highly recommended to convert videos for meida player.

    ReplyDelete
  3. iDealshare VideoGo is just the right AVI to Roku Converter which has both Mac and Windows version! It helps to convert various AVI files whatever encoded with DivX, Xvid, etc to Roku more supported MP4 or MKV. https://www.idealshare.net/video-converter/roku-avi.html

    ReplyDelete