Last active
October 6, 2024 13:43
-
-
Save ndurner/636d37fd83aed4b875cdb66653017ae7 to your computer and use it in GitHub Desktop.
FFmpeg docker wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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