Skip to content

Commit

Permalink
fix stdin/stdout issues with ffmpeg on mp4 (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Mar 2, 2025
1 parent ad1df6c commit 8195f8f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 29 deletions.
1 change: 1 addition & 0 deletions examples/ffmpeg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ RUN apk update && \
apk add --no-cache ffmpeg=="${FFMPEG_VERSION}"

COPY scyllaridae.yml /app/scyllaridae.yml
COPY cmd.sh /app/cmd.sh
61 changes: 61 additions & 0 deletions examples/ffmpeg/cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -eou pipefail

SOURCE_EXT="$1"
DESTINATION_EXT="$2"
ARGS=()
if [ "$#" -eq 3 ]; then
IFS=' ' read -r -a ARGS <<< "$3"
fi

TMP_DIR=$(mktemp -d)
INPUT_FILE="$TMP_DIR/input.$SOURCE_EXT"
OUTPUT_FILE="$TMP_DIR/output.$DESTINATION_EXT"

cleanup() {
rm -rf "$TMP_DIR"
}

trap cleanup EXIT
cat > "$INPUT_FILE"

if [ "$DESTINATION_EXT" = "mp4" ]; then
cmd=(
ffmpeg -loglevel error
-f "$SOURCE_EXT"
-i "$INPUT_FILE"
"${ARGS[@]}"
-vcodec libx264
-preset medium
-acodec aac
-strict -2
-ab 128k
-ac 2
-async 1
-movflags faststart
-y
-f "$DESTINATION_EXT"
"$OUTPUT_FILE"
)
echo "${cmd[@]}" >&2
"${cmd[@]}" > /dev/null
else
cmd=(
ffmpeg -loglevel error
-f "$SOURCE_EXT"
-i "$INPUT_FILE"
"${ARGS[@]}"
-y
-f "$DESTINATION_EXT"
"$OUTPUT_FILE"
)
echo "${cmd[@]}" >&2
"${cmd[@]}" > /dev/null
fi

if [ ! -f "$OUTPUT_FILE" ] || [ ! -s "$OUTPUT_FILE" ]; then
exit 1
fi

cat "$OUTPUT_FILE"
30 changes: 1 addition & 29 deletions examples/ffmpeg/scyllaridae.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,8 @@ cmdByMimeType:
- "-vcodec"
- "png"
- "-"
"video/mp4":
cmd: ffmpeg
args:
- "-f"
- "%source-mime-ext"
- "-i"
- "-"
- "%args"
- "-vcodec"
- "libx264"
- "-preset"
- "medium"
- "-acodec"
- "aac"
- "-strict"
- "-2"
- "-ab"
- "128k"
- "-ac"
- "2"
- "-async"
- "1"
- "-movflags"
- "faststart"
- "-y"
- "-f"
- "%destination-mime-ext"
- "-"
default:
cmd: ffmpeg
cmd: /app/cmd.sh "%source-mime-ext" "%destination-mime-ext" "%args"
args:
- "-f"
- "%source-mime-ext"
Expand Down

0 comments on commit 8195f8f

Please sign in to comment.