Created
April 26, 2019 15:36
-
-
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
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/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