Skip to content

Instantly share code, notes, and snippets.

@ndurner
Last active October 6, 2024 13:43
Show Gist options
  • Save ndurner/636d37fd83aed4b875cdb66653017ae7 to your computer and use it in GitHub Desktop.
Save ndurner/636d37fd83aed4b875cdb66653017ae7 to your computer and use it in GitHub Desktop.
FFmpeg docker wrapper
#!/bin/zsh
# Create a temporary directory
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
# Function to process file path
process_file_path() {
local file_path="$1"
local temp_file="$temp_dir/$(basename "$file_path")"
if [[ -f "$file_path" ]]; then
cp "$file_path" "$temp_file"
fi
echo "/workdir/$(basename "$temp_file")"
}
# Prepare arguments for Docker
docker_args=()
output_to_stdout=false
for arg in "$@"; do
if [[ "$arg" == "-" ]]; then
output_to_stdout=true
docker_args+=("$arg")
elif [[ -e "$arg" ]] || [[ "$arg" == */* ]]; then
# If argument is a file/directory or looks like a path
docker_args+=("$(process_file_path "$arg")")
else
docker_args+=("$arg")
fi
done
# Run FFmpeg in Docker
if $output_to_stdout; then
echo "docker run --rm -i -v \"$temp_dir:/workdir\" -w /workdir jrottenberg/ffmpeg ${docker_args[@]}" >&2
docker run --rm -i -v "$temp_dir:/workdir" -w /workdir jrottenberg/ffmpeg "${docker_args[@]}"
else
echo "docker run --rm -v \"$temp_dir:/workdir\" -w /workdir jrottenberg/ffmpeg ${docker_args[@]}" >&2
docker run --rm -v "$temp_dir:/workdir" -w /workdir jrottenberg/ffmpeg "${docker_args[@]}"
# Copy output files back to the current directory
cp "$temp_dir"/* ./
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment