Skip to content

Instantly share code, notes, and snippets.

@aquaxp
Last active April 19, 2020 00:48
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 aquaxp/ba91cb7864e3fee53328b536a9dc7d29 to your computer and use it in GitHub Desktop.
Save aquaxp/ba91cb7864e3fee53328b536a9dc7d29 to your computer and use it in GitHub Desktop.
Naive script for creating a single MP4 file for an Instagram live stream. Using ffmpeg for handling operations with audio/video streams.
#!/bin/sh
# Cleanup
rm list.txt
rm output.mp4
# Rename files with spaces
find . -type f -name "* *.mp4" -exec bash -c 'mv "$0" "${0// /_}"' {} \;
# First we need to get an MP4 files with Video and Audio combiled
echo "Merging audio and video files to a single MP4 files"
# sort is required for streams with similar name and named via Chrome as "_(n)", where n > 0
for track in `ls *video_track*.mp4 | sort -V`;
do
ffmpeg -i ${track} -i $(echo ${track} | sed "s/video/audio/") -c:v copy -c:a copy $(echo ${track} | sed "s/video/merged/")
# Creating a list for concatenation
echo file \'$(echo ${track} | sed "s/video/merged/")\' >> list.txt
done;
# Concat multiple files into one
echo "Merging few MP4 files into single one"
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment