There seems to be a lot of misunderstanding around what H.264 (with a dot) actually is. So, quoting from Wikipedia:
H.264/MPEG-4 Part 10 or AVC (Advanced Video Coding) is a standard for
video compression, and is currently one of the most commonly used
formats [...]
The important part to stretch here is that it's only a standard. That means, videos are not actually encoded with H.264, but with a codec that meets the H.264 standard. One of the most common ones is x264 (lower-case x, no dot):
x264 is a free software library for encoding video streams into the H.264/MPEG-4
AVC format.
[...]
x264 implements a large number of features compared to other H.264 encoders.
So, H.264 is kind of an Interface and x264 is an Implementation (with the actual functionality) of that interface.
So, the Pi will play x264 encoded files just fine.
Then why do some x264 encoded files not play smoothly but stop every 4-6 seconds (depending on the amount of GPU-Ram)?
Most of the time, it's the sound. Since x264 is an encoder for HD video files, most of those files come with a digital high-quality sound-track, which uses the DTS-codec.
The Pi is (at the moment) not able to hardware-decode the DTS-track and it's CPU is not powerful enough. There is a discussion about this on the official Forums which is worth looking into.
To find out if this is the case for you, you can use the mediainfo
-tool (must be installed, package-names depend on your distro):
[tv@raspberry]$ mediainfo some_random_movie.mkv
# Shortened output!
Audio #2
ID : 3
Format : DTS
Format/Info : Digital Theater Systems
Codec ID : A_DTS
You now have two options:
- Buy a DTS-capable receiver (maybe your TV can do it, too?) and enable "pass-through" (last point) in Xbmc (or whatever player you're using).
- Convert the DTS-Tracks to AC3, which can be passed through (faster) or CPU decoded.
To find out what your receiver (the thing you plugged your HDMI-cable in) is capable of, use the tvservice
-tool (which is not in the PATH, so you'll need the full path):
[tv@raspberry ~]$ /opt/vc/bin/tvservice -a
PCM supported: Max channels: 2, Max samplerate: 48kHz, Max samplesize 24 bits.
AC3 supported: Max channels: 6, Max samplerate: 48kHz, Max rate 640 kb/s.
As you can see, my current receiver is capable of decoding PCM and AC3 (not DTS).
My solution to this problem is to convert the Audio-Tracks which are DTS to AC3. Here is a small one-liner that converts all audio-streams in infile.mkv
to AC3 and doesn't touch the video:
ffmpeg:
ffmpeg -i infile.mkv -map 0 -codec:v copy -codec:s copy -codec:a ac3 outfile.mkv
avconv:
avconv -i infile.mkv -map 0 -vcodec copy -acodec ac3 -ab 256k outfile.mkv
Note: The above command also sets the bit-rate for the resulting AC3 encoded audio-stream (which is necessary, it seems). While 256kbps is
reasonably good (most DVD's use 192kbps), you might want to
in/decrease it.
Luckily, this takes only around 5 minutes (depending on your hardware, of course). As a little bonus, your file becomes smaller and if you're not an Audiophile, you won't hear a difference.
Still, 1080p FullHD Movies are stuttering, the screen goes black for a few seconds with no sound but the video-playback seems to continue. The Movie is H.264 encoded in an MKV container with AC3 tracks. What is the problem?
Most likely, there is nothing wrong with the movie-file, but with your Xbmc settings. In my case, the problem was the "refresh rate" of Xbmc. This is set to 60Hz by default. For 720p and any other small video files, this seems to not be a problem for the Pi, but 1080p files result in the above problem.
Lower the refresh-rate to something less than 60Hz (at least 24Hz are sufficient for Movies). There are two options here:
- Global Xbmc (including Xbmc itself):
System -> Settings -> System -> Video output -> Refresh rate
- Movies only (determined by video-file):
System -> Settings -> Video -> Playback -> Adjust display refresh rate to match video
After lowering the refresh rate, 1080p movies should also play just fine.