Skip to content

Instantly share code, notes, and snippets.

@geekman geekman/faststart
Created Apr 26, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.