Skip to content

Instantly share code, notes, and snippets.

@arijusg
Last active May 6, 2024 01:45
Show Gist options
  • Save arijusg/25d1f8b438f2fdc47960ab19bc3b1bc3 to your computer and use it in GitHub Desktop.
Save arijusg/25d1f8b438f2fdc47960ab19bc3b1bc3 to your computer and use it in GitHub Desktop.

Revisions

  1. arijusg revised this gist Sep 4, 2020. 1 changed file with 19 additions and 3 deletions.
    22 changes: 19 additions & 3 deletions download-video.md
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,33 @@
    # Download stream video
    ## Simple and recommended way (https://superuser.com/questions/692990/use-ffmpeg-copy-codec-to-combine-ts-files-into-a-single-mp4)
    ```
    The correct way to concat multiple video files from m3u8 playlist is

    ffmpeg -i "index.m3u8" -codec copy output.mp4
    The correct way to concat multiple video files from m3u8 playlist is

    ```
    ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "index.m3u8" -codec copy output.mp4
    ```
    the m3u8 playlist can be on web or locally in directory
    it contains list of file paths relative to the playlist
    -codec copy to avoid encoding
    container type matters:
    *.mp4 is fine but it seems little slow to mux when playlist is fetched from web
    *.mkv or *.ts worked best for me

    if your m3u file looks like
    ```
    #EXTM3U
    #EXT-X-PLAYLIST-TYPE:VOD
    #EXT-X-TARGETDURATION:2
    #EXT-X-VERSION:3
    #EXT-X-MEDIA-SEQUENCE:0
    #EXTINF:2
    segments/1_vs0_00000.ts
    #EXTINF:2
    segments/1_vs0_00001.ts
    ```
    you need to add url before segments


    ## Long winded way
    ```
  2. arijusg created this gist Mar 6, 2020.
    74 changes: 74 additions & 0 deletions download-video.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    # Download stream video
    ## Simple and recommended way (https://superuser.com/questions/692990/use-ffmpeg-copy-codec-to-combine-ts-files-into-a-single-mp4)
    ```
    The correct way to concat multiple video files from m3u8 playlist is
    ffmpeg -i "index.m3u8" -codec copy output.mp4
    the m3u8 playlist can be on web or locally in directory
    it contains list of file paths relative to the playlist
    -codec copy to avoid encoding
    container type matters:
    *.mp4 is fine but it seems little slow to mux when playlist is fetched from web
    *.mkv or *.ts worked best for me
    ```

    ## Long winded way
    ```
    #!/bin/bash
    # insert here urls
    LINK=(
    'https://stream.crowdcast.io/5e613e2755a3df005aa399a5/segments/1_vs0' # replace this with your url
    )
    rm -rf my-videos
    mkdir -p my-videos
    cd my-videos
    CNT=0
    for URL in ${LINK[@]}
    do
    # create folder for streaming media
    CNT=$((CNT + 1))
    mkdir $CNT
    cd $CNT
    (
    DIR="${URL##*/}"
    curl "${URL}_[00001-05000].ts" \
    -H 'authority: stream.crowdcast.io' \
    -H 'pragma: no-cache' \
    -H 'cache-control: no-cache' \
    -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36' \
    -H 'sec-fetch-dest: empty' \
    -H 'accept: */*' \
    -H 'origin: https://www.crowdcast.io' \
    -H 'sec-fetch-site: same-site' \
    -H 'sec-fetch-mode: cors' \
    -H 'referer: https://www.crowdcast.io/e/how-to-write-better-proposals' \
    -H 'accept-language: en-US,en;q=0.9,en-GB;q=0.8,lt;q=0.7' \
    -o "${DIR}_#1.ts"
    echo $(printf "${DIR}_%05d.ts\n" {1..5000}) | tr " " "\n" > tslist
    while read line; do cat $line >> $CNT.mp4; done < tslist
    rm -rf media* tslist
    ) &
    cd ..
    done
    cd my-videos/1
    for i in `ls *.ts | sort -V`; do echo "file $i"; done >> mylist.txt
    ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
    wait
    ```