Search code examples
pythoncmdffmpegyoutube-dl

FFmpeg Minimize memory usage or add timeout to youtube-dl


So I am using FFmpeg to download an m3u8 stream. For optimization, I tried running the FFmpeg directly instead of using youtube-dl with it. But for some reason, the ffmpeg.exe uses 140 MB of memory while ffmpeg.exe via youtube-dl uses only 14 MB of memory.

So I have two questions:

  • Is there a way to minimize the direction FFmpeg memory usage
  • Add a timer (custom command) to FFmpeg via youtube-dl. FFmpeg has a build-in command -t (seconds). Is there a way to use it via youtube-dl?

FFmpeg directly (140MB in memory):

import os
os.system('cmd /k "ffmpeg -i https://36-d4.divas.cloud/CHAN-3792/CHAN-3792_1.stream/playlist.m3u8 -t 100 output.mp4"')

FFmpeg using youtube-dl (14MB in memory):

import youtube_dl

ydl_opts = {
    'nopart': True,
    'outtmpl': 'output.mp4',
    'nocheckcertificate': True
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://36-d4.divas.cloud/CHAN-3792/CHAN-3792_1.stream/playlist.m3u8'])

Edit: I double checked and both the exe FFmpeg for the direct and youtube-dl are both the same version.


Solution

  • youtube-dl on linux with the link you provided seems to launch ffmpeg with theses arguments:

    ffmpeg -y -loglevel verbose -headers 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.67 Safari/537.36\
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\
    Accept-Encoding: gzip, deflate\
    Accept-Language: en-us,en;q=0.5' \
     -i https://36-d4.divas.cloud/CHAN-3792/CHAN-3792_1.stream/chunklist_w70914220.m3u8 -c copy -f mp4 file:playlist-playlist.mp4.part
    

    I guess if you just re-use them and add yours (-t 100) you should be able to get the same kind of memory usage.

    You may also try with only -c copy and -f mp4, which I guess are the most relevant for the memory usage of ffmpeg.