Skip to content

Instantly share code, notes, and snippets.

@yacn
Last active October 31, 2021 05:13
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 yacn/5d437d63639f27b64c05d7ba0ccc9b69 to your computer and use it in GitHub Desktop.
Save yacn/5d437d63639f27b64c05d7ba0ccc9b69 to your computer and use it in GitHub Desktop.
merging two files from an iphone.

Merging two videos from an iPhone 7

Step 1. Make sure videos are completely the same spec-wise (same resolution/aspect ratio/time base/etc)

Example 1

  • Two videos: a.mov, b.mov
    • a.mov: 838x838
    • b.mov: 724x724

Need to resize a.mov to match b.mov

Step 2. Convert from HEVC to x264

Probably not necessary, but I had trouble getting valid videos without doing this.

Example 1

Convert a.mov from HEVC to x264 and resize to match 724x724:

$ ffmpeg -i a.mov -map 0:0 -map 0:1 -c:v libx264 -crf 18 -vf "format=yuv420p, scale=724:-1" -c:a copy a-x264.mkv

Convert b.mov from HEVC to x264:

$ ffmpeg -i b.mov -map 0:0 -map 0:1 -c:v libx264 -crf 18 -vf format=yuv420p -c:a copy b-x264.mkv

Step 3: Concatenate newly created files into a single mp4

$ cat << EOF > ./combine.txt
file ./a-x264.mkv
file ./b-x264.mkv
EOF
$ ffmpeg -safe 0 -f concat -i combine.txt -c:v copy -c:a copy merged.mp4

Tada!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment