Skip to content

Instantly share code, notes, and snippets.

@wildart
Forked from maxwellito/m3u8-concat.sh
Created August 16, 2018 00: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 wildart/b3dbf53e6f363ad241f2c6eb3c7ff5c6 to your computer and use it in GitHub Desktop.
Save wildart/b3dbf53e6f363ad241f2c6eb3c7ff5c6 to your computer and use it in GitHub Desktop.
Concat / join .ts segment files into an mp4 file
#!/bin/sh
# This script must be executed in the repo where
# the *.ts files are.
# It will concatenate the segments into one temp
# file which ffmpeg will reencode the audio track.
# By default the ouptup filename is output.mp4
# but can be changed by providing the name as parameter.
#
# ffmpeg is required
#
# Example:
# $ ./m3u8-concat.sh trololo.mp4
# Get the output file name
output=$1
if [ -z "$output" ]; then
output="output.mp4"
fi
# Get length of segment in the current repo
seglen=`ls -la segment-*.ts | wc -l`
if [ -z "$seglen" ]; then
echo "Not segment file found"
exit 1
fi
# Clean temp files
bin=`rm -f all.ts`
# Concat segments into one
a=1
while [ "$a" -le $seglen ]
do
bin=`cat segment-$a.ts >> all.ts`
a=`expr $a + 1`
done
# Run ffmpeg to reencode the audio
bin=`ffmpeg -i all.ts -bsf:a aac_adtstoasc -vcodec copy $output`
echo $bin
# Delete temp files
bin=`rm -f all.ts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment