How can I batch/sequentially download m3u8 files using ffmpeg?

元气小坏坏 提交于 2020-12-06 19:18:44

问题


I'm currently downloading m38u playlists individually using the following on Mac:

ffmpeg -i <"URL with m3u8"> -codec copy output.ts

If I want to do multiple files, I currently do it from separate Terminal windows.

What I would like to do is, in a single instance, tell ffmpeg to e.g. take URLs from a .txt file and download them in sequence, with a sequential output name for each (fine for them to all go in same output folder).

Sample code from m3u8 file:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:9
#EXTINF:8.333333,
segment00000.ts
#EXTINF:8.333333,
segment00001.ts
#EXTINF:8.333333,
segment00002.ts
#EXTINF:5.000000,
segment00003.ts
#EXTINF:8.333333,
segment00004.ts
#EXTINF:8.333333,
segment00005.ts

I certainly have homebrew installed - I'm a novice, so unsure whether that means I'm actively 'using' it to manage packages

The file with the list of of m3u8 addresses is currently located at /Users/username/Downloads/m38u hold list.txt and looks like this:

https://streaming.imvbox.com/media/2825/1280x800/1280x800.m3u8
https://streaming.imvbox.com/media/2298/1280x800/1280x800.m3u8
https://streaming.imvbox.com/media/2822/1280x800/1280x800.m3u8
https://streaming.imvbox.com/media/2821/1280x800/1280x800.m3u8
https://streaming.imvbox.com/media/2820/1280x800/1280x800.m3u8
https://streaming.imvbox.com/media/2088/1280x800/1280x800.m3u8

But so far this file is simply a place to store the links - I haven't used it anything other than to copy the links from.


回答1:


So, I would save the following in your HOME directory as grabAll:

#!/bin/bash

HoldList="/Users/username/Downloads/m38u hold list.txt"

index=0
while read line ; do
    echo ffmpeg -i $line -codec copy output-${index}.ts
    ((index=index+1))
done < "$HoldList"

Note: If you use TextEdit, make sure to click menu option Format->Make Plain Text

Then you can start Terminal and run:

bash grabAll

and see if it is generating the type of commands you want. It doesn't currently do anything, it just says on the screen what it would do. If it looks good, you just need to remove the word echo from the 3rd to last line and run it again.

Sample Output

ffmpeg -i https://streaming.imvbox.com/media/2825/1280x800/1280x800.m3u8 -codec copy output-0.ts
ffmpeg -i https://streaming.imvbox.com/media/2298/1280x800/1280x800.m3u8 -codec copy output-1.ts
ffmpeg -i https://streaming.imvbox.com/media/2822/1280x800/1280x800.m3u8 -codec copy output-2.ts
ffmpeg -i https://streaming.imvbox.com/media/2821/1280x800/1280x800.m3u8 -codec copy output-3.ts
ffmpeg -i https://streaming.imvbox.com/media/2820/1280x800/1280x800.m3u8 -codec copy output-4.ts
ffmpeg -i https://streaming.imvbox.com/media/2088/1280x800/1280x800.m3u8 -codec copy output-5.ts


来源:https://stackoverflow.com/questions/60311360/how-can-i-batch-sequentially-download-m3u8-files-using-ffmpeg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!