2

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.

Yesterdec
  • 37
  • 1
  • 6
  • Please provide a few lines of the file and say if you use **homebrew** to manage packages on your Mac https://brew.sh – Mark Setchell Feb 20 '20 at 00:48
  • Sorry, it's hard to read code in comments because they are unformatted. Could you click `edit` under your question and paste it in there please. Thanks. – Mark Setchell Feb 20 '20 at 07:44
  • Sorry, I don't use `m3u8` myself, so I am not too familiar with it, but bear with me, pls. Do you have another text file with names of m3u8 files in it? If so, can you show a few lines of that please? – Mark Setchell Feb 20 '20 at 08:28
  • Thanks Mark. Do you mean another sample of the m3u8 files I'm using to download? All the m3u8 files are identical, the only difference being the number of segments within the file (corresponding to the length of the particular video) and the URL where the m3u8 file is located. – Yesterdec Feb 20 '20 at 09:15
  • You want to run lots of `ffmpeg` processes at once. So you go to the first Terminal and run `ffmpeg -i http://somewhere.m3u8 ...` and then you go to a second Terminal and run `ffmpeg -i http://somewhereelse.m3u8 ...` , correct? So where is the list of `http://somewhere.m3u8` and `http://somewhereelse.m3u8` and what does it look like? – Mark Setchell Feb 20 '20 at 09:22
  • Updated my original post with info – Yesterdec Feb 20 '20 at 09:56

1 Answers1

0

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Something strange going on. Initially, using the above answer, I ran it and the while an initial output file was created, the process in the Terminal seemed to stall after producing a large output. It asked me to enter some sort of 'command'. I wiped everything and started again, in case I'd made a mistake, but this time, when I run `bash grabAll` nothing happens at all. Pressing enter just returns a new line in the Terminal, remaining in my home folder with no output whatsoever. – Yesterdec Feb 20 '20 at 13:47
  • Create a 3-line `hold list.txt` to test with rather than using a file with hundreds of lines in it. Check your `grabAll` script still looks correct, or re-copy and re-save my code from above. – Mark Setchell Feb 20 '20 at 13:51
  • The output was enormous, and went past the post limite. Assuming I can't add an attachment(?), the output is temporarily available here: https://a.uguu.se/cYZK4u4QiB67.txt – Yesterdec Feb 20 '20 at 14:36
  • The output should not be any different from what you normally get when you run a single `ffmpeg` command in your Terminal, surely? If you make your text file contain just one line it must surely run just the same as when you run it by hand? – Mark Setchell Feb 20 '20 at 14:52
  • Just to be clear, the grabAll code goes into TextEdit, and I save it in plain text without a .txt extension? – Yesterdec Feb 20 '20 at 16:07
  • Yes, Type `ls g*` in Terminal to see all files beginning with `g` – Mark Setchell Feb 20 '20 at 16:11
  • Try as I might, couldn't get it to work. Thanks for your efforts though. Have opted for a more cumbersome workaround in the form of an Excel spreadhseet to concatenate the arguments, and then sticking them in a single Terminal folder separated with `;` – Yesterdec Feb 20 '20 at 18:55
  • Ok, sorry I couldn't get you there. Good luck! – Mark Setchell Feb 20 '20 at 19:10