Bad Movie Playback On Your Raspberry Pi? Time To Re-Encode Your Videos

Bad Movie Playback On Your Raspberry Pi? Time To Re-Encode Your Videos

While I regret purchasing a Raspberry Pi 2 for use as a media centre (more on that another time), it’s still more than serviceable if you want to use OpenELEC, OSMC or other home theatre distro. That is until you run up against videos encoded in H.265 / HEVC, which even the Pi 3 can struggle with.

H.264 is definitely the most popular video codec right now, but it won’t be long before the majority of online media is using the more efficient HEVC. If you’re planning to stick with your Raspberry Pi 2 or 3, you’ll want to convert these files to H.264, which the Pi’s GPU has hardware decoding support for.

Fortunately, conversion is straightforward with FFmpeg. Because the video stream has to be re-encoded, it’ll take more time than a simple container switch to get the job done.

Grab the latest Windows binaries for FFmpeg and install them to a directory accessible from the PATH environment settings. Then create a batch file in the directory containing the HEVC-encoded files and paste the following code into it.

mkdir output for %%i in (*.mkv) do ffmpeg -i "%%i" -c:a copy -sn -map 0:0 -map 0:1 -vcodec libx264 "output%%i"

Note you’ll need to change the *.mkv to match the extension of the video files you’re converting.

Basically, this command does the minimum work needed to transform the videos from H.265 to H.264. The audio is copied directly, so the only cost is the video re-encoding. If there are a lot of files to encode, you’ll be in for a wait.

FFmpeg can take advantage of multiple cores by default, so running extra instances to speed-up the conversion will have the opposite effect. Optionally, you can reduce the resolution — say, 1080p to 720p — to improve speeds.


  • For the given command line:
    for %%i in (*.mkv) do ffmpeg -i “%%i” -c:a copy -sn -map 0:0 -map 0:1 -vcodec libx264 “output\%%i”No video quality is specified here, so FFMPEG will use a default value of 23.0. This will probably be fine for most purposes, but if you’re a bit fussier, add an option before the output file name:

    -crf x

    where x specifies a relative quality. The number reflects the amount of compression, so a lower value gives higher quality video. Anything below 18 is unlikely to give noticeable benefits for the increased file size.

    -map 0:0 -map 0:1These two options duplicate the default stream mapping, so can be considered optional.

    -snNote that this will remove any subtitles that may have been present in the original file.

    Optionally, you can reduce the resolution — say, 1080p to 720p — to improve speeds.For this, add another option:

    -vf scale=720:-1

    This will scale the video to a width of 720 pixels; the -1 will attempt to retain the original aspect ratio but it may be necessary to specify an actual value if the scaled height doesn’t divide evenly by two.

  • Using hanbrake seems much easier. If you can’t work out HB then I doubt you’re the kind of person who’d have a Pi in the first place.

    • I think many who use the Pi have gained their content via torrents. But even then, I assume those who make torrented versions would be able to make the file play on TVs from the get go.

      The company is gone now so I can safely say this.

      When I saw TVs at Dick Smith, I used to look behind them and find a USB thumb drive working away. And sometimes, the aspect ratio of the movie was wrong.

      Doesn’t take much of an imagination to tell where the movie on the display unit came from.

  • You could use an odroid C1 or C2. Same price as a Pi but has HEVC hardware decoding.

    • While an option, a Plex solution is more involved; you need RasPlex on your Pi and a dedicated machine to run the media server.

      You also need to create an account on Plex (the vanilla one, not a Plex Pass) and then get a pin from the playback device (Pi) to attach to one’s account.

      So while the CLI is a bit fiddly, once done it’s a simple matter of copying to an external hard drive and letting OSMC etc do the work; making the FFMPEG route more accessible to less IT literate users.

      EDIT: Why am I being moderated? I haven’t posted anything on LifeHacker for ages so there is no way I could have done anything or late (or in the past for that matter) to warrant being moderated.

  • That is until you run up against videos encoded in H.265 / HEVC, which even the Pi 3 can struggle with.

    That’s primarily because the GPU on the Pi only has hardware acceleration for H.264 and lower decoding thus H.265 needs to be decoded for rendering on the CPU.

  • Regretting using a Pi as a media centre? Maybe our usage is different but I personally think it was one of the best choices I made. I used a RPi1 B+ for quite a while as my media centre. I bought two and had the other one acting as a network server (file sharing, network services, BitTorrent etc). I only just recently upgraded the Kodi RPi1 and it was replaced with an RPi3.

    I use a lot of existing stuff from my last media centre on the Pi, like my USB IR receiver. Only thing I bought extra to make everything work nicely was a HDMI audio extractor as my amp doesn’t handle HDMI audio and my last media PC used coax S/PDIF which was available for the input I wanted to use.

    Only thing that would make it even better would be to run Android TV or something on it. Having it work as a Chromecast equivalent and being able to access NetFlix plus any other streaming or CatchUp service with an Android App would be epic.

Show more comments

Comments are closed.

Log in to comment on this story!