Here are some scripts I've written to make chromecast streaming easier on linux.
I plan to update these over time. I have a couple more scripts but I intend to test them before I release :)
- For streaming I use the wonderful catt package.
- For converting I use ffmpeg, it would be beneficial if you could activate hardware encoding/decoding, if not you can change the ffmpeg command in the script easily.
- It could be better if you mounted /tmp on ram (second comment if you use systemd)
#!/bin/bash
function getvideocodec {
ffmpeg -i "$1" 2>&1 | grep Video: | awk '{print $4}'
}
function getaudiocodec {
ffmpeg -i "$1" 2>&1 | grep Audio: | awk '{print $4}'
}
ACODEC="$(getaudiocodec "$1")"
VCODEC="$(getvideocodec "$1")"
APARAM="-c:a copy"
VPARAM="-c:v copy"
if [ "$ACODEC" != "aac" ] && [ "$ACODEC" != "mp3" ]
then
echo "Audio codec is neither aac nor mp3, converting ${ACODEC} to aac"
APARAM="-c:a aac"
fi
if [ "$VCODEC" != "h264" ] && [ "$VCODEC" != "vp8" ]
then
echo "Video codec is neither h264 nor vp8, converting ${VCODEC} to h264"
VPARAM="-c:v h264_vaapi"
fi
echo "$VPARAM" "$APARAM"
(ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128 -i "$1" $VPARAM $APARAM -vf 'format=nv12|vaapi,hwupload' /tmp/out.mkv)
catt cast /tmp/out.mkv