Sunteți pe pagina 1din 3

16/8/2019 ffmpeg - Cómo descargar .

m3u8 en una sola vez

Cómo descargar .m3u8 de una vez


Preguntó Hace 1 año y 9 meses Activo hace 6 meses Visto 9k veces

I have a .m3u8 file on remote host, with contain fixed numbers of chunk .ts file name, and not stream:

3 #EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:9.736,
media_0.ts
#EXTINF:9.96,
44
media_1.ts
#EXTINF:10.0,
media_2.ts
#EXTINF:10.0,
media_3.ts
#EXTINF:10.0,
media_4.ts
#EXTINF:10.2,
media_5.ts
#EXTINF:10.0,

When I use this command:

# ffmpeg -i "http://example.com/chunklist.m3u8" file.mp4

frame= 582 fps=9.4 q=28.0 size= 1536kB time=00:00:23.21 bitrate= 542.1kbits/s dup=2
drop=4 speed=0.375x

It works. But It get frame by frame video and very long time needed. (It takes time almost to playback the video.)

But since the path of all the .ts files are known. (http://example.com/media_0.ts, http://example.com/media_1.ts, ...) There must be a way to
get and merge them all at the same time.

But How in ffmpeg directly?!

EDIT (try a solution):

For one solution, I know how can concatenation files with ffmpeg.

ffmpeg -i "concat:0.ts|1.ts|2.ts|3.ts|4.ts|5.ts" -c copy output.mp4

This ffmpeg command was great, and works in less 1 sec time!

So try to download all .ts files with CURL with this command:

curl \
http://example.com/media_0.ts -o 0.ts \
http://example.com/media_1.ts -o 1.ts \
http://example.com/media_2.ts -o 2.ts \
http://example.com/media_3.ts -o 3.ts \
http://example.com/media_4.ts -o 4.ts \
http://example.com/media_5.ts -o 5.ts

But you can see result:

% Total % Received % Xferd Average Speed Time Time Time Current


Dload Upload Total Spent Left Speed
100 687k 100 687k 0 0 75108 0 0:00:09 0:00:09 --:--:-- 74111
100 652k 100 652k 0 0 59404 0 0:00:11 0:00:11 --:--:-- 53400
100 673k 100 673k 0 0 48675 0 0:00:14 0:00:14 --:--:-- 55781
100 657k 100 657k 0 0 63573 0 0:00:10 0:00:10 --:--:-- 62494
100 671k 100 671k 0 0 39019 0 0:00:17 0:00:17 --:--:-- 40863
100 692k 100 692k 0 0 63480 0 0:00:11 0:00:11 --:--:-- 80049

¡Mira, el tiempo total de descarga fue de 72 segundos, mientras que la duración total de todas las partes es de 59 segundos! que esta vez es
muy largo!

Lo siento, descargue todas las partes y luego concat, eso no fue una buena solución.

EDITAR 2

Intento con otro .m3u8 archivo en otro servidor con URL de diferencia:

Descargar y concat juntos:

ffmpeg -i "concat:\
http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_0.ts|\
http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_1.ts|\
http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_2.ts|\
http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_3.ts|\
http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_4.ts|\
http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_5.ts\
" -c copy -y output.ts

Al utilizar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de cookies , nuestra Política de privacidad y nuestros
Otro comando con el input.txt archivo de URL.
Términos de servicio .

https://stackoverflow.com/questions/47233304/how-to-download-m3u8-in-once-time 1/3
16/8/2019 ffmpeg - Cómo descargar .m3u8 en una sola vez

ffmpeg -f "concat" -i "input.txt" -c copy -y output.ts

archivo input.txt:

file 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_0.ts'
file 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_1.ts'
file 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_2.ts'
file 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_3.ts'
file 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_4.ts'
file 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/media_w442897525_b560000_5.ts'

O este comando en algún momento si es necesario:

ffmpeg -f "concat" -safe "0" -protocol_whitelist "file,http,https,tcp,tls" -i


"input.txt" -c copy -y output.ts

Finalmente, para que la velocidad de descarga fuera buena, QUIZÁS mi objetivo de servidor tiene un ancho de banda limitado. :-(

ffmpeg concatenación m3u8

editado el 11 de noviembre de 17 a laspreguntó


4:30 el 11 de noviembre de 17 a la
Nabi KAZ
3,487 1 30 43

Si controlas el lado del servidor, ¿qué tal si utilizas un archivo zip allí y luego lo descomprimes después de la descarga? - Dave S 11 de noviembre de 17 a
las 4:14

@DaveS Este es un mal acto. - Nabi KAZ 11 de noviembre de 17 a 4:32

3 ffmpeg -i http://reading/documentation/is/magic/just/try/it/really.m3u8 -c copy file.mp4 - aergistal 11 de noviembre de 17 a las 10:59

3 respuestas

La forma correcta de capturar múltiples archivos de video de la lista de reproducción m3u8 es

ffmpeg -i "http://example.com/chunklist.m3u8" -codec copy file.mp4


3

la lista de reproducción m3u8 puede estar en la web o localmente en el directorio


contiene una lista de rutas de archivos relativas a la lista de reproducción
-codec copy para evitar la codificación (que lleva tiempo)
el tipo de contenedor importa:
*.mp4 está bien, pero parece poco lento para mux cuando la lista de reproducción se obtiene de la web
*.mkv o *.ts funcionó mejor para mí

respondió Nov 14 '18 a las 20:16


Vlastimil Ovčáčík
1,311 16 25

puedes probar.

command:
00 ffmpeg -y \
-v warning \
-loglevel debug \
-i "m3u8 url" \
-vcodec copy \
-c copy -f mpegts out.ts

convertir ts a mp4:

ffmpeg -i out.ts -acodec copy -vcodec copy out.mp4

Respondido Dec 20 '17 a las 10:37


Gatspy
772 2 8 13

Aquí hay un código de Python que lo hace, solo necesita proporcionar la url del primer segmento y el número de segmentos (del archivo
.m3u8):
Al utilizar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de cookies , nuestra Política de privacidad y nuestros
00
Términos de servicio .

https://stackoverflow.com/questions/47233304/how-to-download-m3u8-in-once-time 2/3
16/8/2019 ffmpeg - Cómo descargar .m3u8 en una sola vez

def dumpSegs(initUrl, n, path, append=False):


""" downlaod and combine the .ts files
given the first seg's url, the number of segments and
the destination download path """
with open(path, 'ab' if append else 'wb') as f:
for i in range(1, n + 1):
segurl = initUrl.replace('seg-1-', 'seg-{:d}-'.format(i))
success = False
while not success:
try:
seg = requests.get(segurl, headers=HEADERS)
success = True
except:
print('retrying...')
f.write(seg.content)

Aquí está el mismo código con algunas campanas y silbatos más

edited Jan 19 '18 at 9:19 answered Jan 19 '18 at 0:28


sam46
1,068 7 11

1 This is the second link-only post advertising the same package. This borders on excessive self promotion. You may want to read about (how not to be a
spammer)[stackoverflow.com/help/promotion]. You have contributed several other good answers to the SO community, so I am not going to flag this as spam,
but it is definitely a link-only answer. To improve your answer and avoid deletion, I recommend you include some of the relevant code in this post. Your answer
should stand on its own without the link. The link should just be supplemental. – Tom Aranda Jan 19 '18 at 2:51

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can
become invalid if the linked page changes. - From Review – Tom Aranda Jan 19 '18 at 2:51

1 fair enough, edited – sam46 Jan 19 '18 at 9:19

1 Nice edit. Just make sure you disclose that the link is to your repo. – Tom Aranda Jan 19 '18 at 14:44

Al utilizar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de cookies , nuestra Política de privacidad y nuestros
Términos de servicio .

https://stackoverflow.com/questions/47233304/how-to-download-m3u8-in-once-time 3/3

S-ar putea să vă placă și