Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vo
Last active May 24, 2019 14:29
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 vo/0de97fbd88ee1c7c5d51c6b807c81b00 to your computer and use it in GitHub Desktop.
Save vo/0de97fbd88ee1c7c5d51c6b807c81b00 to your computer and use it in GitHub Desktop.
Makefile to fix broken mp4 files
# This makefile finds all .mp4 files and attempts to repair their indexes without re-encoding.
# It's a makefile so you can use "make -jN" to take advantage of N cores on your computer finish many quickly
MP4:=$(wildcard *.mp4)
OUTDIR:=out
FAST:=$(patsubst %.mp4,${OUTDIR}/%.fast.mp4,${MP4})
REKEYED:=$(patsubst %.mp4,${OUTDIR}/%.rekeyed.mp4,${MP4})
all:
@echo "Use 'make fast' to do a fast file index rebuild"
@echo "Use 'make rekeyed' to fix broken or missing frames"
fast: ${FAST}
rekeyed: ${REKEYED}
# create output directory
outdir:
mkdir -p ${OUTDIR}
# how to create fixed files
${OUTDIR}/%.fast.mp4: %.mp4 outdir
ffmpeg -i $< -c copy $@
# how to create rekeyed files
${OUTDIR}/%.rekeyed.mp4: %.mp4 outdir
ffmpeg -i $< -force_key_frames "expr:gte(t,n_forced*3)" $@
clean:
rm -rf ${FAST} ${REKEYED}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment