Newest 'ffmpeg' Questions - Stack Overflow

Articles published on the website

  • how to add subtitles in video with ffmpeg filter?

    31 March, by Mr.Slow

    I am having hard time adding .srt subtitles to the newly creating video. I am using Python.



    I have checked they are correct.

    pieces of my code that does not work:

    audio = f'{PROJECT_PATH}/data/ppt-elements/audio_{file_id}.txt'
            images = f'{PROJECT_PATH}/data/ppt-elements/images_{file_id}.txt'
            image_input = ffmpeg.input(images, f='concat', safe=0, t=seconds).video
            audio_input = ffmpeg.input(audio, f='concat', safe=0, t=seconds).audio
    inputs = [image_input, audio_input]
    command = (
                ffmpeg.filter('subtitles', f"{PROJECT_PATH}/data/subtitles/final_subtitle_srt/")

    Am I using subtitles filter well?

  • Error: Unable to extract uploader id - Youtube,

    31 March, by nikita goncharov

    I have a very powerful bot in discord (, PYTHON) that can play music in voice channels. It gets the music from youtube (youtube_dl). It's used to work perfectly but now it is not working with any video. I tried updating youtube_dl but it is still not working. I searched everywhere but I still can't find an answer that might help me. This is the Error: Error: Unable to extract uploader id After and before the error log there is no more information.

    Can anyone help?

    I will leave some of the code that I use for my bot... The youtube settup settings:

    youtube_dl.utils.bug_reports_message = lambda: ''
    ytdl_format_options = {
        'format': 'bestaudio/best',
        'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
        'restrictfilenames': True,
        'noplaylist': True,
        'nocheckcertificate': True,
        'ignoreerrors': False,
        'logtostderr': False,
        'quiet': True,
        'no_warnings': True,
        'default_search': 'auto',
        'source_address': '',  # bind to ipv4 since ipv6 addresses cause issues sometimes
    ffmpeg_options = {
        'options': '-vn',
    ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
    class YTDLSource(discord.PCMVolumeTransformer):
        def __init__(self, source, *, data, volume=0.5):
            super().__init__(source, volume)
   = data
            self.title = data.get('title')
            self.url = data.get('url')
            self.duration = data.get('duration')
            self.image = data.get("thumbnails")[0]["url"]
        async def from_url(cls, url, *, loop=None, stream=False):
            loop = loop or asyncio.get_event_loop()
            data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
            if 'entries' in data:
                # take first item from a playlist
                data = data['entries'][0]
            filename = data['url'] if stream else ytdl.prepare_filename(data)
            return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)

    Aproximately the command to run the audio (from my bot):

    sessionChanel =
    await sessionChannel.connect()
    url =
    player = await YTDLSource.from_url(url, loop=client.loop, stream=True), after=lambda e: print(
                                           f'Player error: {e}') if e else None)
  • Ffmpeg gentle stop sending [closed]

    31 March, by Ли Шеньшунь

    Good day. I'm trying to do a simple video sending and receiving on two computers that are on the same network. Video simulates streaming (video conference for example). I want to use ffmpeg but have run into a number of difficulties. I start with two simple scripts: Sender machine

    ffmpeg -re -i input_file.mp4 -c copy -f mpegts udp://

    recipient machine:

    ffmpeg -i udp:// -c copy save_video.mp4

    I got 2 questions:

    1. Is there a way to correctly end video reception when the sender does not send anything else?

    The receive command works by waiting indefinitely. If the sender is still sending video and at this moment interrupt the receiver with ctrl+c, then the video is saved correctly. If the sender is finished, then after that, to stop, you need to use ctrl + c twice and the video is "broken", because. does not open apparently due to damage to the meta-data or codecs.

    I'm aware of options like using timeout, or saving to mkv format, they really work. But setting a specific number of seconds is problematic, and simply killing a process does not look very nice.

    1. Is the -re switch enough to simulate a "webcam" from a video file? I heard that ffmpeg buffers packets in case of loss and can send them later later. I need to send it as it is, if there are any problems, then we lose the package forever. The -flush_packets key, as I understand it, is for writing to a file, but not when sending over the network.
  • How to read realtime microphone audio volume in python and ffmpeg or similar

    31 March, by Ryan Martin

    I'm trying to read, in near-realtime, the volume coming from the audio of a USB microphone in Python.

    I have the pieces, but can't figure out how to put it together.

    If I already have a .wav file, I can pretty simply read it using wavefile:

    from wavefile import WaveReader
    with WaveReader("/Users/rmartin/audio.wav") as r:
        for data in r.read_iter(size=512):
            left_channel = data[0]
            volume = np.linalg.norm(left_channel)
            print volume

    This works great, but I want to process the audio from the microphone in real-time, not from a file.

    So my thought was to use something like ffmpeg to PIPE the real-time output into WaveReader, but my Byte knowledge is somewhat lacking.

    import subprocess
    import numpy as np
    command = ["/usr/local/bin/ffmpeg",
                '-f', 'avfoundation',
                '-i', ':2',
                '-t', '5',
                '-ar', '11025',
                '-ac', '1',
                '-acodec','aac', '-']
    pipe = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=10**8)
    stdout_data =
    audio_array = np.fromstring(stdout_data, dtype="int16")
    print audio_array

    That looks pretty, but it doesn't do much. It fails with a [NULL @ 0x7ff640016600] Unable to find a suitable output format for 'pipe:' error.

    I assume this is a fairly simple thing to do given that I only need to check the audio for volume levels.

    Anyone know how to accomplish this simply? FFMPEG isn't a requirement, but it does need to work on OSX & Linux.

  • React-Native - Path to local Files

    31 March, by iSaBo

    my question is about react-native 0.60+ and about local files.

    My App has the followed folder structure:

    • App.js
    • android
    • ios
    • node_modules
    • src
      • components
      • views
      • assets
      • images
        • myImage.png

    Now, i want to get the path from myImage.png. I want to add an Watermark to a Video. The Watermark to add, is the myImage.png. For that issue i use the ffmpeg-Library.

    But how can i access to these files? What is the Path of these files? i have tried it with React-Native-Filesystem (RNFS), but with no solutions.

    Every time a get: Directory or File not exists

    FFMPEG Cmd:

    const ffmpegWatermarkCommand = '-i ' + RNFS.ExternalStorageDirectoryPath+ '/videos/myVideo.mp4 ' + "-i [Path to Local Watermark]/myImage.jpg ' + '-filter_complex "overlay=10:10" ' + RNFS.ExternalStorageDirectoryPath + '/videos/outVideomp4';

    I hope someone has an solution for me. Thanks