#!/bin/bash PARAM=$0 # Strip path from command name PARAM=${PARAM##*/} short() { echo "Encode frames from YUV420 raw input as H264 with 5Mbps using VBR mode" } help() { cat << EOF $(short) $(info) IN_FILE YUV 420p raw stream OUT_FILE Encoded to AVC (H.264) with 5Mbps using VBR NOTE: Above paths are read from the container volume /media. EOF } details() { cat << EOF $(short) This script provides a quick reference example using the following ffmpeg command: ffmpeg \ -loglevel debug \ -init_hw_device vaapi=va:\${QSV_DEVICE:-/dev/dri/renderD128} \ -init_hw_device qsv=hw@va \ -filter_hw_device hw \ -f rawvideo \ -pix_fmt yuv420p \ -s:v 176x144 \ -i /media/\${IN_FILE} \ -vf hwupload=extra_hw_frames=64,format=qsv \ -c:v h264_qsv \ -b:v 5M \ -y \ /media/\${OUT_FILE} EOF } arguments=() for arg in $*; do [[ $arg =~ ^-- ]] && { command=${arg/--} case $command in short) short exit 0 ;; help) help exit 0 ;; details) details exit 0 ;; *) echo "Unrecognized command." exit 1 ;; esac } || { arguments+=("$arg") } done info() { cat << EOF usage: $PARAM INPUT-FILE OUTPUT-FILE EOF } QSV_DEVICE=${QSV_DEVICE:-/dev/dri/renderD128} [ "${arguments[0]}" == "" ] || [ "${arguments[1]}" == "" ] && { info exit 1 } [ ! -e /media/"${arguments[0]}" ] && { cat << EOF Error: '${arguments[0]}' not found. Was the volume /media mounted when launching the container? docker ... --volume \$(pwd)/media:/media ... or similar? EOF exit 1 } [ ! -e ${QSV_DEVICE} ] && { cat << EOF Error: '${QSV_DEVICE}' not found. Did you pass /dev/dri to Docker? docker ... --device=/dev/dri ... or similar? EOF exit 2 } IN_FILE="${arguments[0]}" OUT_FILE="${arguments[1]}" ffmpeg \ -loglevel debug \ -init_hw_device vaapi=va:${QSV_DEVICE:-/dev/dri/renderD128} \ -init_hw_device qsv=hw@va \ -filter_hw_device hw \ -f rawvideo \ -pix_fmt yuv420p \ -s:v 176x144 \ -i /media/${IN_FILE} \ -vf hwupload=extra_hw_frames=64,format=qsv \ -c:v h264_qsv \ -b:v 5M \ -y \ /media/${OUT_FILE}