69 lines
2.6 KiB
Bash
69 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
# ==============================================================================
|
|
# FFmpeg Wrapper Script for Volume Detection
|
|
#
|
|
# This script acts as a wrapper for the real ffmpeg binary.
|
|
# It's designed to handle cases where 'ffmpeg -filter:a volumedetect'
|
|
# doesn't output 'mean_volume:' (e.g., for image files or videos without audio).
|
|
#
|
|
# If 'mean_volume:' is not found in the real ffmpeg's stderr output,
|
|
# it injects 'mean_volume: 0 dB' into the stderr stream.
|
|
#
|
|
# Setup:
|
|
# 1. Rename your original ffmpeg binary.
|
|
# Example: mv /usr/bin/ffmpeg /usr/bin/ffmpeg.bin
|
|
# 2. Place this script at the original ffmpeg's path.
|
|
# Example: cp this_script.sh /usr/bin/ffmpeg
|
|
# 3. Make this script executable.
|
|
# Example: chmod +x /usr/bin/ffmpeg
|
|
# 4. Ensure REAL_FFMPEG_BINARY points to your renamed ffmpeg binary.
|
|
# ==============================================================================
|
|
|
|
# --- Configuration ---
|
|
# Point this to the actual ffmpeg binary after you've renamed it.
|
|
# For example: /usr/bin/ffmpeg.bin or /usr/local/bin/ffmpeg.bin
|
|
REAL_FFMPEG_BINARY="/usr/bin/ffmpeg.bin"
|
|
# ---------------------
|
|
|
|
# Check if the real ffmpeg binary exists
|
|
if [ ! -f "$REAL_FFMPEG_BINARY" ]; then
|
|
echo "Error: Real ffmpeg binary not found at $REAL_FFMPEG_BINARY" >&2
|
|
echo "Please ensure you've renamed your original ffmpeg (e.g., to ffmpeg.bin)" >&2
|
|
echo "and updated the REAL_FFMPEG_BINARY path in this script." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Create a temporary file to capture stderr from the real ffmpeg command
|
|
TEMP_ERR_FILE=$(mktemp)
|
|
|
|
# Ensure the temporary file is deleted when the script exits
|
|
trap "rm -f $TEMP_ERR_FILE" EXIT
|
|
|
|
# Execute the real ffmpeg with all arguments passed to this script.
|
|
# Redirect its stdout to /dev/null as volumedetect output is on stderr.
|
|
# Redirect its stderr to our temporary file.
|
|
"$REAL_FFMPEG_BINARY" "$@" >/dev/null 2>"$TEMP_ERR_FILE"
|
|
|
|
# Capture the exit code of the real ffmpeg command
|
|
REAL_FFMPEG_EXIT_CODE=$?
|
|
|
|
# Read the content of the temporary stderr file
|
|
FFMPEG_STDERR_CONTENT=$(cat "$TEMP_ERR_FILE")
|
|
|
|
# Check if "mean_volume:" is present in the captured stderr content
|
|
if echo "$FFMPEG_STDERR_CONTENT" | grep -q "mean_volume:"; then
|
|
# If found, print the original stderr content to our stderr
|
|
echo "$FFMPEG_STDERR_CONTENT" >&2
|
|
else
|
|
# If not found, print the original stderr content
|
|
echo "$FFMPEG_STDERR_CONTENT" >&2
|
|
# Then inject the default mean_volume line
|
|
echo "[ffmpeg-wrapper] Injected: mean_volume: 0 dB (original output lacked volume info)" >&2 # For debugging
|
|
echo "mean_volume: 0 dB" >&2
|
|
fi
|
|
|
|
# Exit with the same exit code as the real ffmpeg command
|
|
exit $REAL_FFMPEG_EXIT_CODE
|
|
|