Skip to content

Instantly share code, notes, and snippets.

@terminalcommand
Last active July 10, 2018 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terminalcommand/4b4ad78a67b30b787f0cda7b775784a4 to your computer and use it in GitHub Desktop.
Save terminalcommand/4b4ad78a67b30b787f0cda7b775784a4 to your computer and use it in GitHub Desktop.

What are these?

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 :)

Prerequisites

  • 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)

convertandstream.sh

#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment