Skip to content

Commit

Permalink
⤴️⬆️ Merge pull request #10 from amaya382/vaapi
Browse files Browse the repository at this point in the history
#9 Support VA-API
  • Loading branch information
amaya382 committed Apr 10, 2017
2 parents 2de5c7d + c8c9d90 commit 8581b9c
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 131 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Raw size
> mirakurun 82.6MB -> 68.7MB
> chinachu 641MB -> 468MB
> chinachu 641MB -> 469MB

## Contents
Expand All @@ -23,6 +23,7 @@ Raw size


## Test Environment
* CPU: i3-2100T
* OS: Ubuntu 16.04.2
* Tuner: PT3
* Card Reader: SCR3310-NTTCom
Expand Down Expand Up @@ -52,6 +53,7 @@ sudo $SHELL ./dkms.install
sudo systemctl stop pcscd.socket
sudo systemctl disable pcscd.socket
```
* [OPT] VA-API Driver


## Usage
Expand All @@ -67,16 +69,20 @@ docker-compose down

#### 1. コンテナ設定
`runtime/docker-compose.yml` を調整する
* Tunerデバイス
`mirakurun > devices`
* CardReaderデバイス (`lsusb` 等で特定する. **物理ポートを変更するとここの設定も変わるので注意**)
`mirakurun > devices`
* 録画ファイルの保存先
`chinachu > volumes > recorded`
* chinachu WebUIのポートバインド
`chinachu > ports`
* デーモン化
`* > restart`
* Tunerデバイス
* `mirakurun > devices`
* CardReaderデバイス (`lsusb` 等で特定する. **物理ポートを変更するとここの設定も変わるので注意**)
* `mirakurun > devices`
* 録画ファイルの保存先
* `chinachu > volumes > recorded`
* Chinachu WebUIのポートバインド
* `chinachu > ports`
* [OPT] Chinachu VA-API
* `chinachu > devices`
* `chinachu > environment > VAAPI_ENABLED`
* `chinachu > environment > VAAPI_DEVICE`
* デーモン化
* `* > restart`

#### 2. チューナ設定
```shell
Expand Down Expand Up @@ -131,7 +137,7 @@ docker exec -it mirakurun mirakurun config channels
* WUI (w/ Basic認証), ユーザ名/パスワード (デフォルトは認証なし)
* 録画ファイル名フォーマット
ここではTSファイルのフォーマットを指定する. 拡張子は `*.m2ts` から **変更しない** こと. デフォルトでは自動エンコード後に `*.mp4` に置き換えられる.
* `mirakurunPath`, `recordedDir`, `storageLowSpaceCommand`, `recordedCommand`**変更しない** こと. `recordedDir``runtime/docker-compose.yml` 内の `/usr/local/chinachu/recorded` に対応するホスト側マウントパスで, `storageLowSpaceCommand``runtime/chinachu/storage_low_space_command` を, `recordedCommand``runtime/chinachu/recorded_command` を編集する.
* `uid`, `gid`, `mirakurunPath`, `recordedDir`, `vaapiEnabled`, `vaapiDevice`, `storageLowSpaceCommand`, `recordedCommand`**変更しない** こと. VA-API関係は `runtime/docker-compose.yml` 内のデバイスと環境変数の項目で, `recordedDir` `/usr/local/chinachu/recorded` に対応するホスト側マウントパスで, `storageLowSpaceCommand``runtime/chinachu/storage_low_space_command` を, `recordedCommand``runtime/chinachu/recorded_command` を編集する.
* etc.

#### 5. エンコード設定
Expand Down
137 changes: 94 additions & 43 deletions chinachu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ FROM alpine:3.5
LABEL maintainer='amaya <mail@sapphire.in.net>'

ARG REPOSITORY='https://github.com/Chinachu/Chinachu.git'
ARG COMMIT='c313f3daa3824bcff65083db1b7540b9a4492a30'
ARG COMMIT='f1a825439f29341da805cbe7a1f01fd81777fad1'
ARG FFMPEG_VERSION='3.2.4'

ENV CHINACHU_UID=1000
ENV CHINACHU_HOME='/usr/local/chinachu'
ENV SCRIPT_DIR='/usr/local/bin'
ENV RECORDED_DIR="$CHINACHU_HOME/recorded"
Expand All @@ -15,48 +17,97 @@ WORKDIR $CHINACHU_HOME
COPY chinachu-mp4.patch $SCRIPT_DIR
COPY service $SCRIPT_DIR

RUN set -eux \
&& apk add --no-cache \
bash \
curl \
nodejs \
coreutils \
procps \
ca-certificates \
jq \
\
&& apk add --no-cache --virtual .build-deps \
git \
make \
gcc \
g++ \
autoconf \
automake \
wget \
tar \
xz \
libc-dev \
musl-dev \
eudev-dev \
libevent-dev \
&& git clone $REPOSITORY $CHINACHU_HOME \
&& git checkout $COMMIT \
&& cd $CHINACHU_HOME \
&& echo 1 | ./chinachu installer \
&& patch -p1 < $SCRIPT_DIR/chinachu-mp4.patch \
&& rm $SCRIPT_DIR/chinachu-mp4.patch \
&& mkdir turnout \
&& cat config.sample.json | \
jq ".mirakurunPath = \"http://mirakurun:40772/\" | .recordedDir = \"$RECORDED_DIR/\" | .storageLowSpaceAction = \"none\" | .storageLowSpaceCommand = \"$SCRIPT_DIR/storage_low_space_command\" | .recordedCommand = \"$SCRIPT_DIR/recorded_command\"" \
> turnout/config.json \
&& echo [] > turnout/rules.json \
&& rm *.sample.json \
&& ./chinachu service operator initscript > /etc/init.d/chinachu-operator \
&& ./chinachu service wui initscript > /etc/init.d/chinachu-wui \
&& chmod +x /etc/init.d/* \
\
&& apk del --purge .build-deps \
&& rm -rf .git ~/.npm
RUN set -eux && \
apk add --no-cache \
bash \
curl \
nodejs \
coreutils \
procps \
ca-certificates \
jq \
\
libva \
libva-intel-driver \
zlib-dev \
yasm-dev \
lame-dev \
libva-dev \
libogg-dev \
libvpx-dev \
libvorbis-dev \
x264-dev \
x265-dev \
freetype-dev \
libass-dev \
libwebp-dev \
rtmpdump-dev \
libtheora-dev \
opus-dev && \
apk add --no-cache --virtual .build-deps \
build-base \
git \
autoconf \
automake \
xz \
musl-dev \
eudev-dev \
libevent-dev \
nasm \
bzip2 && \
adduser -D -u $CHINACHU_UID -h $CHINACHU_HOME chinachu && \
git clone $REPOSITORY $CHINACHU_HOME && \
git checkout $COMMIT && \
cd $CHINACHU_HOME && \
patch -p1 < $SCRIPT_DIR/chinachu-mp4.patch && \
echo 1 | ./chinachu installer && \
mkdir turnout && \
cat config.sample.json | \
jq ".uid = $CHINACHU_UID \
| .mirakurunPath = \"http://mirakurun:40772/\" \
| .recordedDir = \"$RECORDED_DIR/\" \
| .storageLowSpaceAction = \"none\" \
| .storageLowSpaceCommand = \"$SCRIPT_DIR/storage_low_space_command\" \
| .recordedCommand = \"$SCRIPT_DIR/recorded_command\"" \
> turnout/config.json && \
echo [] > turnout/rules.json && \
rm $SCRIPT_DIR/chinachu-mp4.patch *.sample.json && \
chown chinachu. -R $CHINACHU_HOME && \
./chinachu service operator initscript | sed -e "s/^USER=.*$/USER=$CHINACHU_UID/" > /etc/init.d/chinachu-operator && \
./chinachu service wui initscript | sed -e "s/^USER=.*$/USER=$CHINACHU_UID/" > /etc/init.d/chinachu-wui && \
chmod +x /etc/init.d/* && \
\
rm -rf usr/bin/* usr/src/* && \
wget http://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.gz -O - \
| tar xz && \
cd ffmpeg-$FFMPEG_VERSION && \
./configure \
--enable-version3 \
--enable-gpl \
--enable-nonfree \
--enable-small \
--enable-libmp3lame \
--enable-libx264 \
--enable-libx265 \
--enable-libvpx \
--enable-libtheora \
--enable-libvorbis \
--enable-libopus \
--enable-libass \
--enable-libwebp \
--enable-librtmp \
--enable-postproc \
--enable-avresample \
--enable-libfreetype \
--disable-debug \
--disable-doc && \
make && \
make install && \
make distclean && \
cd .. && \
\
apk del --purge .build-deps && \
rm -rf ffmpeg-$FFMPEG_VERSION .git ~/.npm

EXPOSE 20772

Expand Down
12 changes: 6 additions & 6 deletions chinachu/chinachu-mp4.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ index b6a8200..59856dd 100644
)
,
diff --git a/api/script-recorded-program-watch.vm.js b/api/script-recorded-program-watch.vm.js
index d69aae4..9fa78db 100644
index 5bc2156..5090418 100644
--- a/api/script-recorded-program-watch.vm.js
+++ b/api/script-recorded-program-watch.vm.js
@@ -183,7 +183,7 @@ function main(avinfo) {

if (!request.query.debug) args.push('-v', '0');
@@ -190,7 +190,7 @@ function main(avinfo) {
args.push("-hwaccel_output_format", "yuv420p");
}

- args.push('-i', 'pipe:0');
+ args.push('-i', program.recorded);

if (d.t) { args.push('-t', d.t); }

@@ -224,13 +224,11 @@ function main(avinfo) {
@@ -262,13 +262,11 @@ function main(avinfo) {

args.push('-y', '-f', d.f, 'pipe:1');

Expand All @@ -42,7 +42,7 @@ index d69aae4..9fa78db 100644
readStream.pipe(response);
} else {
var ffmpeg = child_process.spawn('ffmpeg', args);
@@ -239,8 +237,6 @@ function main(avinfo) {
@@ -277,8 +275,6 @@ function main(avinfo) {

ffmpeg.stdout.pipe(response);

Expand Down
33 changes: 24 additions & 9 deletions chinachu/service
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

[ -s config.json ] || cat turnout/config.json > config.json
[ -s rules.json ] || cat turnout/rules.json > rules.json
chown $CHINACHU_UID *.json data/*.json || :

find $RECORDED_DIR -name "*.tmp.mp4" -print | xargs -i sh -c 'tmp={} && raw=${tmp%.tmp.mp4}.m2ts && recorded_command $raw'
VIDEO_GID=`ls -n $VAAPI_DEVICE | cut -d' ' -f4 || :`
: ${VAAPI_ENABLED:=false}

$VAAPI_ENABLED && [ "$VIDEO_GID" = "" ] \
&& echo 'ERROR: VA-API is enabled, but VA-API device was not found' && exit 1

cat config.json \
| jq ".gid = ${VIDEO_GID:-$CHINACHU_UID} \
| .vaapiEnabled = $VAAPI_ENABLED \
| .vaapiDevice = \"$VAAPI_DEVICE\"" > config.json_
cat config.json_ > config.json
rm config.json_

find $RECORDED_DIR -name "*.tmp.mp4" -print \
| xargs -i sh -c 'tmp={} && raw=${tmp%.tmp.mp4}.m2ts && recorded_command $raw'

rm -f /var/run/chinachu-operator.pid
rm -f /var/run/chinachu-wui.pid
Expand All @@ -12,15 +27,15 @@ retry_limit=300
n_retries=0
while [ $n_retries -le $retry_limit ]
do
http_status=`curl -s mirakurun:40772/api/status -o /dev/null -w '%{http_code}'; :`
if [ "$http_status" = "200" ]; then
n_retries=0
echo "succeeded in connecting with mirakurun"
break
fi
http_status=`curl -s mirakurun:40772/api/status -o /dev/null -w '%{http_code}'; :`
if [ "$http_status" = "200" ]; then
n_retries=0
echo "succeeded in connecting with mirakurun"
break
fi
n_retries=$(($n_retries + 1))
echo "waiting for mirakurun...(${n_retries}sec)"
sleep 1
echo "waiting for mirakurun...(${n_retries}sec)"
sleep 1
done

[ $n_retries -ge $retry_limit ] && echo "mirakurun timed out"
Expand Down
Loading

0 comments on commit 8581b9c

Please sign in to comment.