Compare commits
No commits in common. "fbfcc91c392bbb0274afe1609d4ac55fe69bcc57" and "f6ce5fce540e461eec7c9c52a9c07d94ba9ee0c5" have entirely different histories.
fbfcc91c39
...
f6ce5fce54
@ -2,19 +2,6 @@
|
|||||||
# Look into HW video encoding to vp9 instead of h264:
|
# Look into HW video encoding to vp9 instead of h264:
|
||||||
# https://www.reddit.com/r/VP9/comments/g9uzzv/hardware_encoding_vp9_on_intel/
|
# https://www.reddit.com/r/VP9/comments/g9uzzv/hardware_encoding_vp9_on_intel/
|
||||||
|
|
||||||
fail() {
|
|
||||||
echo "$*" >&2
|
|
||||||
exit -1
|
|
||||||
}
|
|
||||||
|
|
||||||
VIDEO=$(getent group video | sed -E 's,^video:[^:]*:([^:]*):.*$,\1,')
|
|
||||||
RENDER=$(getent group render | sed -E 's,^render:[^:]*:([^:]*):.*$,\1,')
|
|
||||||
|
|
||||||
[[ "${VIDEO}" != "" ]] || fail "No video group found."
|
|
||||||
|
|
||||||
ADD_GROUPS="--group-add ${VIDEO}"
|
|
||||||
[[ "${RENDER}" != "" ]] && ADD_GROUPS+=" --group-add ${RENDER}"
|
|
||||||
|
|
||||||
video_detect() {
|
video_detect() {
|
||||||
for file in "${*}"; do
|
for file in "${*}"; do
|
||||||
INFO=($(ffprobe -v error \
|
INFO=($(ffprobe -v error \
|
||||||
@ -52,8 +39,8 @@ function move {
|
|||||||
base="$(dirname "${IN}")"
|
base="$(dirname "${IN}")"
|
||||||
[ ! -d "${base}" ] && continue
|
[ ! -d "${base}" ] && continue
|
||||||
base=/remote/media/backup/"${base}"
|
base=/remote/media/backup/"${base}"
|
||||||
[ ! -d "${base}" ] && mkdir -p "${base}" || fail "Unable to mkdir '${base}'"
|
[ ! -d "${base}" ] && mkdir -p "${base}"
|
||||||
[ -e "${base}" ] && mv "${IN}" "${base}"/ || fail "Unable to move '$IN'"
|
[ -e "${base}" ] && mv "${IN}" "${base}"/
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert {
|
function convert {
|
||||||
@ -99,7 +86,7 @@ function convert {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "Counting frames in ${IN}: "
|
echo -n "Counting frames in ${IN}: "
|
||||||
FRAMES=$(ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 "${IN}") || fail "Unable to count frames"
|
FRAMES=$(ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 "${IN}")
|
||||||
echo "${FRAMES} frames."
|
echo "${FRAMES} frames."
|
||||||
|
|
||||||
# Use stdbuf to flush stdout/stderr every line
|
# Use stdbuf to flush stdout/stderr every line
|
||||||
@ -110,26 +97,16 @@ function convert {
|
|||||||
OUT=$(realpath "${OUT}")
|
OUT=$(realpath "${OUT}")
|
||||||
DIN=$(dirname "${IN}")
|
DIN=$(dirname "${IN}")
|
||||||
DOUT=$(dirname "${OUT}")
|
DOUT=$(dirname "${OUT}")
|
||||||
if false; then
|
NO_COLOR=1 \
|
||||||
quiet="
|
docker run --user=1000 --device=/dev/dri \
|
||||||
-v quiet
|
|
||||||
-loglevel fatal
|
|
||||||
"
|
|
||||||
else
|
|
||||||
quiet=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker run \
|
|
||||||
--device=/dev/dri \
|
|
||||||
--user=$(id -u) \
|
|
||||||
--rm \
|
--rm \
|
||||||
${ADD_GROUPS} \
|
|
||||||
-v "${DIN}:${DIN}" \
|
-v "${DIN}:${DIN}" \
|
||||||
-v "${DOUT}:${DOUT}" \
|
-v "${DOUT}:${DOUT}" \
|
||||||
intel-media-ffmpeg \
|
intel-media-ffmpeg \
|
||||||
ffmpeg \
|
ffmpeg \
|
||||||
${quiet} \
|
|
||||||
-nostdin \
|
-nostdin \
|
||||||
|
-v quiet \
|
||||||
|
-loglevel fatal \
|
||||||
${input_flags} \
|
${input_flags} \
|
||||||
-i "${IN}" \
|
-i "${IN}" \
|
||||||
-progress /dev/stdout \
|
-progress /dev/stdout \
|
||||||
@ -137,23 +114,12 @@ function convert {
|
|||||||
${output_flags} \
|
${output_flags} \
|
||||||
-movflags +faststart \
|
-movflags +faststart \
|
||||||
"${OUT}" \
|
"${OUT}" \
|
||||||
-y || fail "ffmpeg failed" 2>&1 |
|
-y | while read line; do
|
||||||
while read line; do
|
|
||||||
if [[ "${line}" == "ffmpeg failed" ]]; then
|
|
||||||
false
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
POS=$(echo $line | sed -n 's/^frame=*\(.*\)/\1/p')
|
POS=$(echo $line | sed -n 's/^frame=*\(.*\)/\1/p')
|
||||||
if [[ "${POS}" == "" ]]; then
|
if [[ "${POS}" != "" ]]; then
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
NOW=$(date +%s)
|
NOW=$(date +%s)
|
||||||
ELAPSEDTIME=$(( NOW - LASTTIME ))
|
ELAPSEDTIME=$(( NOW - LASTTIME ))
|
||||||
if (( ELAPSEDTIME <= 5 )); then
|
if (( ELAPSEDTIME > 5 )); then
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
ELAPSEDFRAMES=$(( POS - LASTPOS ))
|
ELAPSEDFRAMES=$(( POS - LASTPOS ))
|
||||||
REMAININGFRAMES=$(( FRAMES - POS ))
|
REMAININGFRAMES=$(( FRAMES - POS ))
|
||||||
REMAININGFRAMES=$(( REMAININGFRAMES * 1000 )) # convert to ms
|
REMAININGFRAMES=$(( REMAININGFRAMES * 1000 )) # convert to ms
|
||||||
@ -166,16 +132,20 @@ function convert {
|
|||||||
fi
|
fi
|
||||||
LASTTIME=${NOW}
|
LASTTIME=${NOW}
|
||||||
LASTPOS=${POS}
|
LASTPOS=${POS}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done && move && {
|
done && move && {
|
||||||
if [[ "${ORIG}" == "${IN}" ]]; then
|
if [[ "${ORIG}" == "${IN}" ]]; then
|
||||||
# If the original file was an '.mkv' then OUT was '.transcoded.mkv'
|
# If the original file was an '.mkv' then OUT was '.transcoded.mkv'
|
||||||
# during transcode. Now that the transcode is complete, set the
|
# during transcode. Now that the transcode is complete, set the
|
||||||
# file back to the original name.
|
# file back to the original name.
|
||||||
mv "${OUT}" "${IN}" || fail "Unable to mv '${OUT}' -> '${IN}'"
|
mv "${OUT}" "${IN}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
NOW=$(date +%s)
|
NOW=$(date +%s)
|
||||||
echo -e "\nCompleted in $(mstodate $(( NOW - STARTTIME ))000)"
|
echo -e "\nCompleted in $(mstodate $(( NOW - STARTTIME ))000)"
|
||||||
|
# -vcodec copy \
|
||||||
|
# -acodec aac \
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_and_convert {
|
function check_and_convert {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user