From 773600fb034ead03c6ca5bd01b0259c4627baa61 Mon Sep 17 00:00:00 2001 From: "James P. Ketrenos" Date: Wed, 18 Sep 2019 17:02:56 -0700 Subject: [PATCH] mv cmd_encode => cmd_decode and added cmd_encode helper Signed-off-by: James P. Ketrenos --- Dockerfile | 12 +++++ Dockerfile.solution | 7 +++ assets/cmd_decode | 114 +++++++++++++++++++++++++++++++++++++++++ assets/cmd_encode | 121 ++++++++++++++++++++++++++++++++++++++++++++ assets/entry | 95 ++++++++++++++++++++++++++++++++++ templates/ending.in | 5 ++ 6 files changed, 354 insertions(+) create mode 100755 assets/cmd_decode create mode 100755 assets/cmd_encode create mode 100755 assets/entry diff --git a/Dockerfile b/Dockerfile index 623b65c..6a6e23f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -144,6 +144,13 @@ RUN ./configure --arch=x86_64 --disable-yasm --enable-vaapi --enable-libmfx \ && make \ && make install +# ffmpeg is installed; the build and source trees are no longer needed +# RUN rm -rf /home/agama/ffmpeg + +COPY assets/* /assets/ + +ENTRYPOINT [ "/assets/entry" ] + # # Standard ending begins here (from templates/ending.in) # @@ -152,6 +159,11 @@ RUN ./configure --arch=x86_64 --disable-yasm --enable-vaapi --enable-libmfx \ # changes,) causing all subsequent layers to be # regenerated. +# Clean up APT content that might still be around +#RUN apt-get clean autoclean \ +# && apt-get autoremove -y \ +# && rm -rf /var/lib/${apt,dpkg,cache,log} + # Ensure that each Docker container self-documents the # versions included in it diff --git a/Dockerfile.solution b/Dockerfile.solution index fde7f4e..77d936d 100644 --- a/Dockerfile.solution +++ b/Dockerfile.solution @@ -36,3 +36,10 @@ WORKDIR /home/agama/ffmpeg RUN ./configure --arch=x86_64 --disable-yasm --enable-vaapi --enable-libmfx \ && make \ && make install + +# ffmpeg is installed; the build and source trees are no longer needed +# RUN rm -rf /home/agama/ffmpeg + +COPY assets/* /assets/ + +ENTRYPOINT [ "/assets/entry" ] diff --git a/assets/cmd_decode b/assets/cmd_decode new file mode 100755 index 0000000..74a4354 --- /dev/null +++ b/assets/cmd_decode @@ -0,0 +1,114 @@ +#!/bin/bash + +PARAM=$0 +PARAM=${PARAM/.\/cmd_} + +short() { + echo "Decode H264 video and save as raw file" +} + +help() { +cat << EOF +$(short) + +$(info) + +INFILE Input stream must be H264 video +OUTFILE Will be decoded and saved as YUV420P + +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 \ + -hwaccel qsv \ + -qsv_device ${QSV_DEVICE} \ + -c:v h264_qsv \ + -i /media/INFILE \ + -vf hwdownload,format=nv12 \ + -pix_fmt yuv420p \ + /media/OUTFILE + +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_DEVCIE}' not found. + +Did you pass /dev/dri to Docker? + + docker ... --device=/dev/dri ... + +or similar? + +EOF + exit 2 +} + +ffmpeg -hwaccel qsv -qsv_device ${QSV_DEVICE} \ + -c:v h264_qsv -i /media/"${arguments[0]}" \ + -vf hwdownload,format=nv12 -pix_fmt yuv420p \ + /media/"${arguments[1]}" + diff --git a/assets/cmd_encode b/assets/cmd_encode new file mode 100755 index 0000000..45b75cd --- /dev/null +++ b/assets/cmd_encode @@ -0,0 +1,121 @@ +#!/bin/bash + +PARAM=$0 +PARAM=${PARAM/.\/cmd_} + +short() { + echo "Encode 10 frames from YUV420 raw input as H264 with 5Mbps using VBR mode" +} + +help() { +cat << EOF +$(short) + +$(info) + +INFILE Must 720p raw +OUTFILE Will be encoded as H264 w/ 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 qsv=hw \ + -filter_hw_device hw \ + -f rawvideo -pix_fmt yuv420p \ + -s:v 176x144 \ + -i /media/INFILE \ + -vf hwupload=extra_hw_frames=64,format=qsv \ + -c:v h264_qsv \ + -b:v 5M \ + -frames:v 10 \ + -y /media/OUTFILE + +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_DEVCIE}' not found. + +Did you pass /dev/dri to Docker? + + docker ... --device=/dev/dri ... + +or similar? + +EOF + exit 2 +} + +INFILE="${arguments[0]}" +OUTFILE="${arguments[1]}" + +ffmpeg -loglevel debug -init_hw_device qsv=hw \ + -filter_hw_device hw -f rawvideo -pix_fmt \ + yuv420p -s:v 176x144 -i /media/"${INFILE}" -vf \ + hwupload=extra_hw_frames=64,format=qsv \ + -c:v h264_qsv -b:v 5M -frames:v 10 \ + -y /media/"${OUTFILE}" diff --git a/assets/entry b/assets/entry new file mode 100755 index 0000000..8cb7826 --- /dev/null +++ b/assets/entry @@ -0,0 +1,95 @@ +#!/bin/bash +request=$1 +shift + +commands=(info help version ffmpeg) +commands+=(cmd_*) + +cd /assets + +. SOLUTION +. MANIFEST + +name() { + cat << EOF +Intel Accelerated Graphics and Media Access container +Copyright (C) 2019 Intel Corporation +----- +EOF +} + +info() { + [ "$1" == "--short" ] && { + echo "Information about running container environment" + } || { + cat << EOF +$(name) + +Detected base OS: Ubuntu 19.04 +Detected hardware: None +Detected Agama version: ${AGAMA_VERSION} + +EOF + } +} + +version() { + [ "$1" == "--short" ] && { + echo "Show container version information" + } || { + cat << EOF +$CONTAINER built using Agama $AGAMA_VERSION. + +EOF + } +} + +ffmpeg() { + [ "$1" == "--short" ] && { + echo "Run ffmpeg commands." + } || { + /usr/local/bin/ffmpeg $* + } +} + +help() { + [ "$1" == "--short" ] && { + echo "This help information" + } || { + cat << EOF +$(name) + +Commands: +EOF + # Change cmd_foo to ./cmd_foo in expansion below + for cmd in ${commands[@]}; do + printf " %-15s %s\n" ${cmd/cmd_} "$(${cmd/cmd_/./cmd_} --short)" + done + } +} + +case $request in +info) + info $* + ;; + +ffmpeg) + ffmpeg $* + ;; + +version) + version $* + ;; + +help|"") + help $* + ;; + +*) + [ ! -f ./cmd_$request ] && { + echo "'${request}' is not a recognized command." + } || { + ./cmd_$request $* + } + ;; +esac diff --git a/templates/ending.in b/templates/ending.in index 79447e3..da40d70 100644 --- a/templates/ending.in +++ b/templates/ending.in @@ -3,6 +3,11 @@ # changes,) causing all subsequent layers to be # regenerated. +# Clean up APT content that might still be around +#RUN apt-get clean autoclean \ +# && apt-get autoremove -y \ +# && rm -rf /var/lib/${apt,dpkg,cache,log} + # Ensure that each Docker container self-documents the # versions included in it