Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Real time HLS editing with FFmpeg filter_complex without re-encoding full stream

    28 mai, par Devdeep Ghosh

    I'm new to FFmpeg and working on a lightweight video editor for HLS streams that allows cutting and trimming without re-encoding the entire video. I'm using FFmpeg to only process the segments that intersect with "exclusion" ranges (timestamps to remove), while copying unmodified segments directly. The goal is speed and accuracy.

    The logic identifies which .ts segments overlap with exclusion windows, applies filter_complex to trim just those segments, and then programatically reassemble everything into a new .m3u8 playlist. However, the final output sometimes freezes or desynchronizes—audio gets out of sync or playback freezes where segments were excluded.

    Here's the FFmpeg logic I'm using to trim segments:

    const videoFilter = `[0:v]select='not(between(t,${start},${end}))'[vout]`;
    const audioFilter = `[0:a]aselect='not(between(t,${start},${end}))'[aout]`;
    
    
    const ffmpegArgs = [
      "-i", inputPath,
      "-filter_complex", `${videoFilter};${audioFilter};[vout]setpts='PTS-STARTPTS'[v];[aout]asetpts='PTS-STARTPTS'[a]`,
      "-map", "[v]",
      "-map", "[a]",
      "-c:v", "libx264",
      "-c:a", "aac",
      "-preset", "ultrafast",
      "-hls_flags", "independent_segments",
      "-avoid_negative_ts", "make_zero",
      "-y", outputPath,
    ];
    

    Is this approach actually viable for cutting .ts segments from an HLS stream without full re-encoding?

    Am I misunderstanding how FFmpeg handles timestamps when trimming?

    Is there a better or more reliable way to do this (e.g. concat, -ss/-to, GOP alignment, etc.)?

  • mp4 - Mooving moov atom in web js [closed]

    27 mai, par Ben Carp

    In a web app, recording is done with MeidaRecorder, which places the moov atom at the end. We want to generate a progressive video with moov at the start.

    Most of examples that I found use ffmpeg wasm which we can't use in our project. Is there an option to extract the video parts from the Blob/video chunks and to repack them in mp4 that will generate a new progressive mp4?

  • Python yt-dlp and ffmpeg error "merging of multiple formats but ffmpeg is not installed"

    27 mai, par T Tea Tie

    I am using the latest version of yt-dlp with Python 3.9.

    I am trying to download a youtube video in mp4 format with outputname as the youtubeid.mp4 and with best resolution not more than 4K.

    This is my Python code:

    ytid = '4cDqaLxrt6Q'
    url = 'https://www.youtube.com/watch?v='+ytid
    output_filename = ytid+".mp4"
        
    with YoutubeDL({'format': 'bestvideo[height<=?4K]+bestaudio/best', 'output': output_filename}) as ydl:
        ydl.download(url)`#TODO debug FFmpeg and check if outputname is ok
    

    I expected to have an .mp4 file in my current working directory.

    Then I installed the latest version of FFmpeg from ffmpeg-master-latest-win64-gpl.zip and put ffmpeg.exe, ffplay.exe and ffprobe.exe in Scripts python folder (where yt-dlp.exe is). I also installed ffmpeg using pip install.

    The Traceback is:

    [youtube] Extracting URL: https://www.youtube.com/watch?v=4cDqaLxrt6Q [youtube] 4cDqaLxrt6Q: Downloading webpage [youtube] 4cDqaLxrt6Q: Downloading android player API JSON [youtube] 4cDqaLxrt6Q: Downloading MPD manifest [youtube] 4cDqaLxrt6Q: Downloading MPD manifest [info] 4cDqaLxrt6Q: Downloading 1 format(s): 243+251 ERROR: You have requested merging of multiple formats but ffmpeg is not installed. Aborting due to --abort-on-error Traceback (most recent call last):

    File "C:\Users\t\OneDrive\Documents\Python Scripts\project\main.py", line 88, in ydl.download(url)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 3353, in download self.__download_wrapper(self.extract_info)(

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 3328, in wrapper res = func(*args, **kwargs)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 1486, in extract_info return self.__extract_info(url, self.get_info_extractor(key), download, extra_info, process)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 1497, in wrapper return func(self, *args, **kwargs)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 1594, in __extract_info return self.process_ie_result(ie_result, download, extra_info)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 1653, in process_ie_result ie_result = self.process_video_result(ie_result, download=download)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 2767, in process_video_result self.process_info(new_info)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 3189, in process_info self.report_error(f'{msg}. Aborting due to --abort-on-error')

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 1007, in report_error self.trouble(f'{self._format_err("ERROR:", self.Styles.ERROR)} {message}', *args, **kwargs)

    File "C:\Users\t\anaconda3\lib\site-packages\yt_dlp\YoutubeDL.py", line 947, in trouble raise DownloadError(message, exc_info)

    DownloadError: ERROR: You have requested merging of multiple formats but ffmpeg is not installed. Aborting due to --abort-on-error

  • FFmpeg trim : -to as input option vs -to as output option

    27 mai, par jackmiller

    Command 1:

    > ffmpeg -ss 01:00 -to 02:00 -i "input.mp4" "output.mp4"
    

    Cuts from 01:00 to 02:00.

    Command 2:

    > ffmpeg -ss 01:00 -i "input.mp4" -to 02:00 "output.mp4"
    

    Cuts from 01:00 to 03:00.

    I know, the parameter -ss as an input option, first seeks to the given position and then resets the input timestamps to 00:00. Hence, the second command cuts from 01:00 to 03:00 (in the new timestamps 00:00 to 02:00 is 01:00 to 03:00 in the original timestamps).

    But it's not the same in the first command. Why is that? Is it because in the first command, the reset happens after the -to operation?

  • FFmpeg + RTSP + JSMpeg : Stream randomly rotates in browser

    27 mai, par Lais Lemos

    I'm streaming an RTSP camera to a web page using FFmpeg as the encoder and JSMpeg as the web player. The stream generally works fine, but sometimes — completely at random — the video rotates (usually 45 or 225 degrees) without any change in the code, camera settings, or stream configuration.

    This issue usually occurs after the server has been running for a while (one or two weeks). Currently, the only way to solve it is by restarting the Docker container that runs the server.

    Setup

    • Source: IP camera via RTSP
    • Streaming: FFmpeg reads the RTSP stream and sends it to a WebSocket server
    • Player: JSMpeg in the browser receives the WebSocket stream and plays the video in a canvas.

    FFmpeg options used

    ffmpegOptions: {  
              '-loglevel': 'error',  
              '-r': 30,  
              '-b:v': '5000k',  
              '-s': '1920x1080',  
              '-maxrate': '8000k',  
              '-max_delay': '500000',  
              '-bufsize': '16000k',  
              '-sc_threshold': 0,  
              '-metadata:s:v:0': 'rotate=0',  
              '-vf': 'rotate=0'  
            }
    

    What I've Checked

    • Verified that the camera itself does not send incorrect rotation metadata — seems fine.
    • It doesn't appear that JSMpeg is causing the issue either.
    • The problem appears to be on FFmpeg's side.

    Screenshots of the issue

    The blue edges shows the stream orientation during the bug and the red ones, how it was supposed to be.

    enter image description here

    Questions

    • Has anyone experienced this behavior?
    • Any suggestions on how to debug or fix this?

    enter image description here

    Any help or guidance would be greatly appreciated!