Skip to content

Instantly share code, notes, and snippets.

@geekman
Created April 26, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekman/4f449829e8af96f18229e1b066d39660 to your computer and use it in GitHub Desktop.
Save geekman/4f449829e8af96f18229e1b066d39660 to your computer and use it in GitHub Desktop.
make MP4 files stream better by moving their "moov" atom to the front
#!/bin/sh
# script to make mp4 videos start fast
# (i.e. shifting their moov atoms to the front)
FNAME=$1
[ -f "$FNAME" ] || exit 1
TMPFNAME=`mktemp -u ${FNAME}.XXXXXX`
head -c128 "$FNAME" | grep -F moov -q
IS_FAST=$?
if [ $IS_FAST -eq 1 ]; then
ffmpeg -hide_banner -i "$FNAME" -c:v copy -c:a copy -movflags \+faststart -f mp4 "$TMPFNAME" && \
touch -r "$FNAME" "$TMPFNAME" && \
mv -f "$TMPFNAME" "$FNAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment