ffmpeg conversion for Chromecast
On an old Google Chromecast 1, I've found the following to produce playable content:
ffmpeg4 -i input.mp4 -preset fast -c:a aac -b:a 192k -ac 2 -c:v libx264 -b:v 1024k -profile:v high -level 4.1 -crf -1 -pix_fmt yuv420p output.mp4
More complex transcoding is possible. Eg. With an input where the video is fine, but the audio stream is aac 5.1 and refuses to play, we can copy the video stream, and map the audio stream twice, keeping the aac 5.1 stream and adding a second 192kb/s aac stereo stream. Eg.
ffmpeg4 -i input.mp4 -map 0:v:0 -c:v copy -map 0:a:0 -map 0:a:0 -c:a:0 aac -ac:a:0 2 -b:a:0 192k -c:a:1 copy output.mp4
From DVD files
Using the 4th and 3rd audio tracks (numbered from zero) downsampled to stereo, video compressed with constrained-quality (max bitrate is specified together with crf), and the 13th subtitle (bitmap) stream:
ffmpeg6 -probesize 200000000 -analyzeduration 600000000 \
-i "concat:$(perl -e 'print join("|", @ARGV);' VTS_01_[1-9].VOB)" \
-map 0:v:0 -preset fast \
-c:v libx264 -threads 4 -b:v 1024k -profile:v high -level 4.1 -crf -1 -pix_fmt yuv420p \
-map 0:a:3 -map 0:a:2 -c:a aac -b:a 192k -ac:a 2 \
-map 0:s:12 -c:s dvb_subtitle output.mkv
Stuttering playback and resolution scaling
A reader has informed me that odd horizontal resolutions may be a cause of stuttering playback, which was seen with 1248x520
. Adding a scaling filter to change the horizontal resolution to a standard 1280 or 1920 may improve this - to maintain aspect ratio and an even vertical line count, a scaling filter can be added via e.g. -vf scale=1280:-2
.
There is also a known Chromecast bug effecting Chromecast gen 1 that results in stuttering playback with 1080p 60fps YouTube video, especially videos that have static images or computer rendered video with large solid blocks of colour (e.g. minecraft). This likely effects any video playback, and not just YouTube. Disabling 60fps playback is one possible workaround. See Redit thread or Google Nest community thread for more information.
Notes
- aac 5.1 audio doesn't seem to work.
- use
-t <duration_secs>
to test settings on a small portion of the file. -crf -1
normally specifies constant quality mode, but together with a video bitrate, it specifies constrained-quality mode, but is roughly equivalent to-crf 30
. For higher quality, try, eg.-crf 25
, together with increasing the bitrate.- use eg.
-s 1920x1080
to scale. - the
mp4
container supportsmov_text
subtitle encoding, but it's not supported by Chromecast. mkv
container supportswebvtt
subtitle encoding, which is supported by Chromecast.VOB
files do not have a global index, so ffmpeg scans the start of the file to find available streams. For streams that start late, ffmpeg must be told to scan more of the file.-probesize 200000000 -analyzeduration 600000000
specifies to scan 200 MiB and/or 600 seconds.-threads 4
specifies the parallelism thatlibx264
uses for video compression.
See also
- Supported Media for Google Cast.
- FFmpeg FAQ.
- Scaling ffmpeg wiki page.