Skip to content

Commit

Permalink
Added auto video converter progress in gui.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlesage committed Apr 25, 2019
1 parent bfed41d commit 59395a8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ RUN \
# For optical drive listing:
lsscsi \
# For watchfolder
yad \
findutils \
expect

Expand Down
1 change: 1 addition & 0 deletions Dockerfile.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ RUN \
# For optical drive listing:
lsscsi \
# For watchfolder
yad \
findutils \
expect

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ of this parameter has the format `<VARIABLE_NAME>=<VALUE>`.
|`AUTOMATED_CONVERSION_CHECK_INTERVAL`| Interval (in seconds) at which the automatic video converter checks for new files. | `5` |
|`AUTOMATED_CONVERSION_MAX_WATCH_FOLDERS`| Maximum number of watch folders handled by the automatic video converter. | `5` |
|`HANDBRAKE_DEBUG`| Setting this to `1` enables HandBrake debug logging for both the GUI and the automatic video converter. For the latter, the increased verbosity is reflected in `/config/log/hb/conversion.log` (container path). For the GUI, log messages are sent to `/config/log/hb/handbrake.debug.log` (container path). **NOTE**: When enabled, a lot of information is generated and the log file will grow quickly. Make sure to enable this temporarily and only when needed. | (unset) |
|`AUTOMATED_CONVERSION_NO_GUI_PROGRESS`| When set to `1`, progress of videos converted by the automatic video converter is not shown in the HandBrake GUI. | `0` |

### Data Volumes

Expand Down Expand Up @@ -635,7 +636,6 @@ subdirectory. The application can then be configured to monitor this
subdirectory. For example, if `AUTOMATED_CONVERSION_OUTPUT_SUBDIR` is set to
`TV Shows` and `/output` is mapped to `$HOME/appvolumes/HandBrake` on the host,
`$HOME/appvolumes/HandBrake/TV Shows` should be monitored by the application.
application.

## Intel Quick Sync Video

Expand Down
13 changes: 12 additions & 1 deletion appdefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ subdirectory. The application can then be configured to monitor this
subdirectory. For example, if `AUTOMATED_CONVERSION_OUTPUT_SUBDIR` is set to
`TV Shows` and `/output` is mapped to `$HOME/appvolumes/HandBrake` on the host,
`$HOME/appvolumes/HandBrake/TV Shows` should be monitored by the application.
application.
</content>
</section>
<section>
Expand Down Expand Up @@ -886,6 +885,18 @@ On systems running unRAID, the `--ulimit core=-1` parameter can be added to the
<description>Setting this to `1` enables HandBrake debug logging for both the GUI and the automatic video converter. For the latter, the increased verbosity is reflected in `/config/log/hb/conversion.log` (container path). For the GUI, log messages are sent to `/config/log/hb/handbrake.debug.log` (container path). **NOTE**: When enabled, a lot of information is generated and the log file will grow quickly. Make sure to enable this temporarily and only when needed.</description>
<default/>
</environment_variable>
<environment_variable>
<name>AUTOMATED_CONVERSION_NO_GUI_PROGRESS</name>
<description>When set to `1`, progress of videos converted by the automatic video converter is not shown in the HandBrake GUI.</description>
<default>0</default>
<unraid_template>
<title>Automatic Video Converter: Disable Progress in GUI</title>
<description>Set to 1 to disable display of the video conversion progress in HandBrake GUI.</description>
<display>advanced</display>
<required>false</required>
<mask>false</mask>
</unraid_template>
</environment_variable>
</environment_variables>
<!-- Volumes -->
<volumes>
Expand Down
55 changes: 53 additions & 2 deletions rootfs/etc/services.d/autovideoconverter/run
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,19 @@ log() {
}

log_hb_encode_progress() {
YAD_FD="${1:-UNSET}"
LINE_COUNT=0
while read OUTPUT; do
L="$(echo "$OUTPUT" | cut -d',' -f2- | sed 's/^ *//')"
if [ "$(expr $LINE_COUNT % 6)" = "0" ]; then
log "Encoding:$(echo "$OUTPUT" | cut -d',' -f2-)"
log "Encoding: $L"
fi
LINE_COUNT="$(expr $LINE_COUNT + 1)"

if [ "$YAD_FD" != "UNSET" ]; then
echo "$L" | cut -d ' ' -f1 >&$YAD_FD
echo "# $L" >&$YAD_FD
fi
done
}

Expand Down Expand Up @@ -242,6 +249,41 @@ process_video() {
# Set the temporary output filename.
OUTPUT_FILE_TMP="$OUTPUT_DIR_TMP/$basename.$AC_FORMAT"

# Create a named pipe for the progress window.
if [ "${AUTOMATED_CONVERSION_NO_GUI_PROGRESS:-0}" -eq 0 ]; then
YAD_NP="$(mktemp)"
YAD_NP_FD=6
rm "$YAD_NP" && mkfifo "$YAD_NP"
if [ "$?" -ne 0 ]; then
log "WARNING: Failed to create named pipe for UI progress."
rm "$YAD_NP"
YAD_NP="UNSET"
else
# Open a read/write file descriptor so we can write to the named
# pipe without blocking.
exec $YAD_NP_FD<> "$YAD_NP"
fi
else
YAD_NP="UNSET"
YAD_NP_FD="UNSET"
fi

# Open the progress window in background.
if [ "$YAD_NP" != "UNSET" ]; then
yad --fixed \
--width=384 \
--posx=$(expr $DISPLAY_WIDTH / 2 - 384 / 2) \
--posy=5 \
--title "Automatic Video Converter" \
--window-icon /opt/novnc/images/icons/master_icon.png \
--borders 10 \
--text "Encoding $video..." \
--no-buttons \
--auto-close \
--progress \
< "$YAD_NP" &
fi

# Invoke HandBrake.
echo "------- CONVERSION OUTPUT $(date) -------" >> \
/config/log/hb/conversion.log
Expand All @@ -251,9 +293,18 @@ process_video() {
--preset "$AC_PRESET" 2>> \
/config/log/hb/conversion.log \| \
/usr/bin/unbuffer -p grep "^Encoding" \| \
log_hb_encode_progress
log_hb_encode_progress "$YAD_NP_FD"
hb_rc=$pipestatus_1

if [ "$YAD_NP" != "UNSET" ]; then
# Make sure to close the progress window.
echo 100 >&$YAD_NP_FD

# Close the file descriptor and remove the named pipe.
exec $YAD_NP_FD<&-
rm "$YAD_NP"
fi

# Move the file to its final location if conversion terminated
# successfully.
if [ $hb_rc -eq 0 ]; then
Expand Down

0 comments on commit 59395a8

Please sign in to comment.