Skip to content

Instantly share code, notes, and snippets.

@liuyxpp
Created April 28, 2020 04:31
Show Gist options
  • Save liuyxpp/a5920e569341126f13dd30d9a952aa9f to your computer and use it in GitHub Desktop.
Save liuyxpp/a5920e569341126f13dd30d9a952aa9f to your computer and use it in GitHub Desktop.
Scripts based on `ffmpeg` to ease the make of course videos by iPad screen recording.

Scripts based on ffmpeg to ease the make of course videos by iPad screen recording.

Usage

  1. Screen recording on iPad results multiple mp4 files. These files have extension .MP4. Note the extension is capitalized.
  2. If needed, edit the video by iPad Photo App. Note that the edited file's extension is .mov.
  3. Airdrop these files to MacBook Pro.
  4. Rename all files to either ###.mp4 or ###.mov, where ### is $n$ digits where $n$ is determined by the number of files. ### should start with 001 and the numbering shall follow the order of the videos.
  5. Convert all mov files to mp4 files using script mov2mp4.
  6. Combine all mp4 files using script combinemp4.

Scripts

ffmpeg

The static binary of ffmpeg

mov2mp4

$ mov2mp4 1

Convert all mov files in the current folder to mp4 files. Run the command without any argument is a dry run.

combinemp4

$ combinemp4 1

Combine all mp4 files in the current folder to a single mp4 file. Run the command without any argument is a dry run.

#!/bin/bash
DRY=$1
if [ -z "$DRY" ]; then
DRY=true
else
DRY=false
fi
echo "Changing *.MP4 to *.mp4"
for mp4 in *.MP4; do
filename=$(basename "$mp4" .MP4)
if [ "$filename" = "*" ]; then
break
fi
if [ $DRY = false ]; then
mv "$mp4" "$filename".mp4
else
echo "mv $mp4 $filename.mp4"
fi
done
echo "Combining mp4 files"
command="ffmpeg"
filter=""
n=0
for mp4 in *.mp4; do
command="$command -i $mp4"
filter="$filter""[$n:v:0][$n:a:0]"
n=$((n+1))
done
filter="$filter""concat=n=$n:v=1:a=1[outv][outa]"
command="$command -filter_complex \"$filter\" -map \"[outv]\" -map \"[outa]\" out.mp4"
if [ $DRY = false ]; then
$($command)
else
echo "$command"
fi
if [ $DRY = true ]; then
echo "Please run command: combinemp4 1 to actually do the work."
fi
#!/bin/bash
DRY=$1
if [ -z "$DRY" ]; then
DRY=true
else
DRY=false
fi
for mov in *.mov; do
filename=$(basename "$mov" .mov)
if [ $DRY = false ]; then
ffmpeg -i "$mov" "$filename".mp4
else
echo "ffmpeg -i $mov $filename.mp4"
fi
done
for mov in *.MOV; do
filename=$(basename "$mov" .MOV)
if [ $DRY = false ]; then
ffmpeg -i "$mov" "$filename".mp4
else
echo "ffmpeg -i $mov $filename.mp4"
fi
done
if [ $DRY = true ]; then
echo "Please run command: mov2mp4 1 to actually do the work."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment