What the device supports
According to the Xperia U White Paper this device can decode H.264 video, High profile, level 3.2 in MP4 container with AAC audio.
Example ffmpeg
command
ffmpeg -i input -codec:v libx264 -crf 23 -preset medium -profile high -level 3.2 \ -pix_fmt yuv420p -movflags +faststart -codec:a aac -strict experimental out.mp4
What these options do
-codec:v libx264
– Choose video encoderlibx264
to encode H.264 video.-crf 23
– Output video quality level.23
is the default and a lower value is a higher quality.-preset medium
– Encoding speed vs compression efficiency tradeoff. Default ismedium
.-profile high
– Sets H.264 video profile to High.-level 3.2
– Sets H.264 video level to 3.2.-pix_fmt yuv420p
–ffmpeg
attempts to minimize or avoid chroma subsampling (depending on input, encoder,ffmpeg
version, etc). This is technically a good thing, but can result in an output that non-FFmpeg based players can't handle. This ensures a compatible chroma subsampling scheme.-movflags +faststart
– Relocates the "moov atom" to the beginning of the file so playback may begin before the file is completely downloaded in the case of progressive download (such as watching via a browser).-codec:a aac -strict experimental
– Encode AAC audio using the experimental native FFmpeg AAC encoder. It's not the worst AAC encoder, but if it sounds shitty use a higher bitrate with-b:a
(default is 128k).
Additional notes
Use a recent version of
ffmpeg
. Old versions do not enforce the correct number of reference frames when using-level
(fixed bug #3307), but since you're using Arch Linux you don't need to worry about that.The ffmpeg package from the Arch Linux Extra repository only supports the native FFmpeg AAC encoder. Recompile from ABS with
--enable-libfdk-aac --enable-nonfree
(with libfdk-aac package as a depends) or use the ffmpeg-git package in AUR to gain support for encoding with libfdk_aac which is the best AAC encoder supported by FFmpeg. Using the ABS package is recommended over the AUR package if you want to try this.If the input video and/or audio is already compatible then you can simply stream copy it instead of re-encoding, such as with
-codec:a copy
.The mobile device may have additional restrictions that I am unaware of, so you will have to experiment. I'm also unsure if the device will work with a plain link to the video, but that would be easy to test.
See the FFmpeg H.264 Encoding Guide and FFmpeg AAC Encoding Guide for additional info.