ffmpeg conversion for Chromecast

From Wikistix

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

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 supports mov_text subtitle encoding, but it's not supported by Chromecast.
  • mkv container supports webvtt 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 that libx264 uses for video compression.

See also