Page 1 of 1

Download and merge TS fragments from m3u8 index

Posted: Tue Feb 13, 2018 11:27 am
by admin
If you have the index and it's called index_1_av.m3u8

Download all fragments:

Code: Select all

wget -I index_1_av.m3u8


merge the fragments:

Code: Select all

#!/bin/bash
 
NUM_SEGMENTS=653
OUT_FILE=MyVideo.ts

rm $OUT_FILE

# Tested using bash version 4.1.5
#for ((i=1;i<=100;i++));
for ((i=1;i<=($NUM_SEGMENTS-1);i++));
do
   # your-unix-command-here
   FILENAME=segment"$i"_1_av.ts
   cat $FILENAME >> $OUT_FILE
done

Re: Download and merge TS fragments from m3u8 index

Posted: Thu Feb 22, 2018 10:07 am
by fabiodelorenzo
admin wrote:If you have the index and it's called index_1_av.m3u8

Download all fragments:

Code: Select all

wget -i index_1_av.m3u8


merge the fragments:

Code: Select all

#!/bin/bash
 
NUM_SEGMENTS=653
OUT_FILE=MyVideo.ts

rm $OUT_FILE

# Tested using bash version 4.1.5
#for ((i=1;i<=100;i++));
for ((i=1;i<=($NUM_SEGMENTS-1);i++));
do
   # your-unix-command-here
   FILENAME=segment"$i"_1_av.ts
   cat $FILENAME >> $OUT_FILE
done

Re: Download and merge TS fragments from m3u8 index

Posted: Thu Feb 22, 2018 10:41 am
by fabiodelorenzo
admin wrote:If you have the index and it's called index_1_av.m3u8

Download all fragments:

Code: Select all

wget -I index_1_av.m3u8


merge the fragments:

Code: Select all

#!/bin/bash
 
OUT_FILE=MyVideo.ts

NUM_SEGMENTS=`ls -l *.ts  | wc -l`

echo "NUM SEGMENTS: $NUM_SEGMENTS"

rm $OUT_FILE

# Tested using bash version 4.1.5
#for ((i=1;i<=100;i++));
for ((i=1;i<=($NUM_SEGMENTS);i++));
do
   # your-unix-command-here
   FILENAME=segment"$i"_1_av.ts
   cat $FILENAME >> $OUT_FILE
done