Using Handbrake to Encode Blu-Rays for the Roku

roku_logo_lThis post is a sibling of my earlier post Using Handbrake to Encode DVDs for the Roku and contains the settings I use for Blu-Ray movies.  The instructions apply to Handbrake 0.9.9.

Once again, start with the High Profile preset and then make the following changes:

  1. In Output Settings:
    1. Set Container = Mp4
    2. Ensure Large File Size is checked
    3. Ensure Web Optimized is checked
    4. Ensure iPod 5G Support is unchecked
  2. In Picture:
    1. Set Anamorphic = Strict (all Blu-Rays I’ve seen are 1920×1080)
    2. Set Cropping = Automatic.
  3. In Filters:
    1. Set Detelecine = Off
    2. Set Decomb = Fast
    3. Set Deinterlace = Off
    4. Set Denoise = Off
    5. Set Deblock = Off
    6. Ensure Grayscale is unchecked
  4. In Video:
    1. Set Video Codec = H.264 (x264)
    2. Set Framerate (FPS) = Same as source
    3. Set Constant Framerate
    4. Set Quality = Constant Quality of RF:20
    5. Set Optimise Video = Use Advanced Tab instead
  5. In Audio:
    1. Create two audio tracks.  The first audio track will have:
      1. Source = AC3 5.1 (which is what you should have ripped from your DVD)
      2. Codec = AAC (faac)
      3. Bitrate = 160
      4. Samplerate = Auto
      5. Mixdown = Stereo
      6. DRC = 1.5
      7. Gain = 0
    2. The second audio track will have:
      1. Source = AC3 5.1
      2. Codec = AC3 Passthru
  6. In Subtitles, keep everything empty.  I do not handle subtitles.
  7. In Chapters:
    1. Ensure Create chapter markers is checked
  8. In Advanced:
    1. In Encoding:
      1. Set Reference Frames = 3 (Default)
      2. Set Maximum B-Frames = 3 (Default)
      3. Ensure CABAC is checked
      4. Ensure 8×8 Transform is checked
      5. Ensure Weighted P-Frames is checked
      6. Set Pyramidal B-Frames = Normal (Default)

    2. In Analysis:
      1. Set Adaptive B-Frames = Optimal
      2. Set Adaptive Direct Mode = Automatic
      3. Set Motion Est Method = Hexagon (Default)
      4. Set Subpixel Motion Est = 7: RD in all frames
      5. Set Motion Est Range to 16
      6. Set Partition Type = Most (Default)
      7. Set Trellis = Encode Only (Default)

    3. In Psychovisual:
      1. Set Adaptive Quant Strength = Middle
      2. Set Rate Distortion = Middle
      3. Set Psychovisual Trellis = Leftmost Setting
      4. Ensure No DCT-Decimate is unchecked
      5. Set Deblocking = 0 (Default), 0 (Default)
    4. In x264 Encoder Options, set it to b-adapt=2:rc-lookahead=50:direct=auto

Using Handbrake to Encode DVDs for the Roku

Update 2014-04-27 10:00 PM: See also Using Handbrake to Encode Blu-Rays for the Roku

In a previous post, I noted that I use ffmpeg to convert DVDs to MP4s which will play on my Roku.  I recently encountered two problems with this approach.  First, the resulting MP4s only include a stereo audio track, so are highly sub-optimal for surround sound systems.  Second, for a yet-undetermined reason, Plex (my current preferred media client) will transcode the videos rather than play them directly.

To solve both problems, I have changed from ffmpeg to Handbrake and I am following the encoding guidance of Rokoding.  Specifically, since most of my source material is DVDs, I use the 480p Original settings.

Just in case the Rokoding site disappears, I have reproduced the 480p DVD Settings below in a slightly modified form.  These instructions apply to Handbrake 0.9.9.

In Handbrake, start with the High Profile preset and then make the following changes:

  1. In Output Settings:
    1. Set Container = Mp4
    2. Ensure Web Optimized is checked
    3. Ensure Large File Size and iPod 5G Support are unchecked
  2. In Picture:
    1. If the movie is widescreen or hard letterboxed, set Anamorphic = Strict.  If the movie is 4:3, set Anamorphic = None and ensure Keep Aspect Ratio is checked.
    2. Set Cropping = Automatic.
  3. In Filters:
    1. Set Detelecine = Off
    2. Set Decomb = Fast
    3. Set Deinterlace = Off
    4. Set Denoise = Off
    5. Set Deblock = Off
    6. Ensure Grayscale is unchecked
  4. In Video:
    1. Set Video Codec = H.264 (x264)
    2. Set Framerate (FPS) = Same as source
    3. Set Constant Framerate
    4. Set Quality = Constant Quality of RF:19
    5. Set Optimise Video = Use Advanced Tab instead
  5. In Audio:
    1. Create two audio tracks.  The first audio track will have:
      1. Source = AC3 5.1 (which is what you should have ripped from your DVD)
      2. Codec = AAC (faac)
      3. Bitrate = 160
      4. Samplerate = Auto
      5. Mixdown = Stereo
      6. DRC = 1.5
      7. Gain = 0
    2. The second audio track will have:
      1. Source = AC3 5.1
      2. Codec = AC3 Passthru
  6. In Subtitles, keep everything empty.  I do not handle subtitles.
  7. In Chapters:
    1. Ensure Create chapter markers is checked
  8. In Advanced:
    1. Set Adaptive B-Frames = Optimal
    2. Set Adaptive Direct Mode = Automatic
    3. In x264 Encoder Options, set it to b-adapt=2:rc-lookahead=50:direct=auto
    4. The rest are as default:
      1. Set Reference Frames = 3 (Default)
      2. Set Maximum B-Frames = 3 (Default)
      3. Ensure CABAC is checked
      4. Ensure 8×8 Transform is checked
      5. Ensure Weighted P-Frames is checked
      6. Set Pyramidal B-Frames = Normal (Default)
      7. Set Motion Est Method = Hexagon (Default)
      8. Set Subpixel Motion Est = 7: RD in all frames
      9. Set Motion Est Range to 16
      10. Set Partition Type = Most (Default)
      11. Set Trellis = Encode Only (Default)
      12. Set Adaptive Quant Strength = Middle
      13. Set Rate Distortion = Middle
      14. Set Psychovisual Trellis = Leftmost Setting
      15. Ensure No DCT-Decimate is unchecked
      16. Set Deblocking = 0 (Default), 0 (Default)

Ffmpeg encoding for the Roku

Update 2013-12-02: I no longer use this method. See this post for my new method.

Roku2_XD_Family_610x465I have three (someday to be four) Roku players at home.  I primarily use them to stream Netflix and Amazon Instant Video and to stream MP4s from a home server using Roksbox.

My typical workflow is to rip DVDs to VOBs using Dvdfab, copy the VOBs to my home server, and then convert them in bulk from VOB to MP4 using ffmpeg.

The Roku does not support all profiles of H.264, so here is the ffmpeg 1.0.6 command I use to create Roku-compatible MP4s:

ffmpeg -i src.vob -vcodec libx264 -threads 0 -f mp4 -y -acodec libfaac -ab 128k -ac 2 -preset slow -profile:v high -level 4 -crf 20 dest.mp4

Creating a Virtual Java RPM

javaSome RPMs (e.g. jpackage.org’s tomcat7-7.0.39-1.jpp6.noarch.rpm) express their dependency upon Java by requiring a RPM that provides capability java (as opposed to, for example, depending on the existence of a file /usr/bin/java). On CentOS, this capability is normally provided by the java-*-openjdk RPM. Therefore, if you execute # yum install tomcat7 on a clean install of CentOS, yum will install OpenJDK in addition to Tomcat 7.

Some people prefer to run the Oracle JRE/JDK instead of OpenJDK. Oracle provides RPMs named jre-version-linux-x64.rpm and jdk-version-linux-x64.rpm to make installing them easier. Unfortunately, these RPMs do not provide the capability java. This means that if you already have the Oracle JRE installed, and you install a RPM which requires the capability java, the OpenJDK will be unnecessarily installed (and might even become the default!).

I solved this dilemma by creating a ‘virtual’ RPM package which provides the capability java by depending on the Oracle JRE. I named this package virtual-java.

Creating this package is quite easy. First I created a Makefile to make building the RPM easier and deal with rpmbuild’s nonsense regarding _topdir:

VERSION=1.7
RELEASE=1
RPMNAME=virtual-java-$(VERSION)-$(RELEASE).noarch.rpm

.PHONY: all
all: dist/$(RPMNAME)

.PHONY: clean
clean:
	rm -rf work
	rm -rf dist

dist/$(RPMNAME): work/RPMS/noarch/$(RPMNAME) dist
	cp work/RPMS/noarch/$(RPMNAME) dist/$(RPMNAME)

work/RPMS/noarch/$(RPMNAME): work/BUILD work/RPMS/noarch work/SPECS/virtual-java.spec
	rpmbuild -bb --define="_topdir ${PWD}/work" work/SPECS/virtual-java.spec

work/SPECS/virtual-java.spec: work/SPECS virtual-java.spec
	cat virtual-java.spec | sed -e s/%VERSION%/$(VERSION)/g | sed -e s/%RELEASE%/$(RELEASE)/g > work/SPECS/virtual-java.spec

dist:
	if [ ! -d dist ]; then mkdir -p dist; fi
	touch dist
work/BUILD:
	if [ ! -d work/BUILD ]; then mkdir -p work/BUILD; fi
	touch work/BUILD
work/RPMS/noarch:
	if [ ! -d work/RPMS/noarch ]; then mkdir -p work/RPMS/noarch; fi
	touch work/RPMS/noarch
work/SPECS:
	if [ ! -d work/SPECS ]; then mkdir -p work/SPECS; fi
	touch work/SPECS

Note how the Makefile defines VERSION and RELEASE, and provides them to the .spec file. This is done because the Makefile needs to know the name of the generated RPM file, which depends on VERSION and RELEASE.

Here is virtual-java.spec:

Name: virtual-java
Version: %VERSION%
Release: %RELEASE%
Group: ENTER GROUP HERE
Summary: Virtual package which provides java but uses the Sun/Oracle JRE
License: None
BuildArch: noarch
Provides: java
Requires: jre > %VERSION%

%description
Virtual package which provides java but uses the Sun/Oracle JRE

%prep

%build

%pre

%post

%install

%files

%changelog