Last active
May 7, 2021 09:55
-
-
Save ashish1405/c06374d55d863f6f400205fd814b9964 to your computer and use it in GitHub Desktop.
Shell script for generating m3u8 file from a list of encrypted ts files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
keyfilepath=$(dirname "${1}") | |
#read keyinfo file | |
IFS=$'\n' read -d '' -r -a keyfilelines < $1 | |
KEYFILE="$keyfilepath/${keyfilelines[1]}" | |
IV=${keyfilelines[2]} | |
KEY=$(xxd -p $KEYFILE) | |
#read m3u8 file | |
IFS=$'\n' read -d '' -r -a m3u8filelines < $2 | |
#write header | |
for f in ${m3u8filelines[*]}; | |
do | |
if [[ $f == *"#EXTINF"* ]]; then | |
break | |
fi | |
echo $f >> $4 | |
done | |
#read ts file list | |
IFS=$'\n' read -d '' -r -a tsfilelines < $3 | |
for f in ${tsfilelines[*]}; | |
do | |
duration=`ffprobe -key $KEY -iv $IV -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 crypto:$f` | |
#write duration for x file | |
echo "#EXTINF:$duration">>$4 | |
#write name of x file | |
echo "$f">>$4 | |
done | |
echo "#EXT-X-ENDLIST">>$4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i $1 -hide_banner -loglevel panic -codec: copy -start_number 0 -hls_time 6 -hls_key_info_file enc.keyinfo -hls_list_size 2 -f hls filename.m3u8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The encrypted ts files are generated using ffmpeg command (record.sh).
The main script takes 4 parameters