Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg is making my audio and video frozen and I don't know why

    17 avril, par Sdpro

    I'm using bunjs runtime to execute ffmpeg as terminal code but I don't know if my code is typescript code is wrong or ffmpeg is wrong and I'm using json file to get the clips correctly

        let videos = 0;
        let stepsTrim = "";
        let concatInputs = "";
    
        for (let i = 0; i < 40; i++) {
            if (unwantedWords[i].keepORdelete === true) {
                stepsTrim += `[0:v]trim=0:${
                    unwantedWords[i].start
                },setpts=PTS[v${i}];[0:a]atrim=0:${
                    unwantedWords[i].start
                },asetpts=PTS-STARTPTS[a${i}];[0:v]trim=${unwantedWords[i].start}:${
                    unwantedWords[i].end
                },setpts=PTS[v${unwantedWords.length + i + 1}];[0:a]atrim=${
                    unwantedWords[i].start
                }:${unwantedWords[i].end},asetpts=PTS-STARTPTS[a${
                    unwantedWords.length + i + 1
                }];`;
    
                concatInputs += `[v${i}][a${i}][v${unwantedWords.length + i + 1}][a${
                    unwantedWords.length + i + 1
                }]`;
                videos += 2; 
            }
        }
    
        stepsTrim = stepsTrim.slice(0, -1);
    
        await $`ffmpeg -hide_banner -i ${videoRequirements.output} -filter_complex "${stepsTrim},${concatInputs} concat=n=${videos}:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -c:v libopenh264 -preset slow -c:a mp3 -vsync 1 -y ${removedUnwantedWords}/fastAf.mp4`;
    

    at the end after everything was done:

    warning
    [vost#0:0/libopenh264 @ 0x558f80ea1dc0] More than 1000 frames duplicated.9kbits/s dup=110 drop=1 speed=0.831x    
    [out_0_0 @ 0x558f8100a880] 100 buffers queued in out_0_0, something may be wrong. dup=1064 drop=1 speed=1.43x    
    [out_0_1 @ 0x558f8100af80] 100 buffers queued in out_0_1, something may be wrong.
    [out_0_1 @ 0x558f8100af80] 1000 buffers queued in out_0_1, something may be wrong.
    I can't figure out why ffmpeg is sometimes making the audio + video work and sometimes not
    [enter image description here](https://i.stack.imgur.com/PicaA.png)
    
    [
      {
        "word": "Hello",
        "id": 0,
        "keepORdelete": false,
        "start": 0,
        "end": 9.06
      },
      {
        "word": "guys,",
        "id": 1,
        "keepORdelete": false,
        "start": 9.06,
        "end": 10.2
      },
      {
        "word": "there",
        "id": 2,
        "keepORdelete": false,
        "start": 11.76,
        "end": 12.06
      },
    ...
    

    I have tried commands from many types of ffmpeg commands changing the code and I can't seem to get the audio and video right

  • Python OpenCV VideoCapture Color Differs from ffmpeg and Other Media Players

    17 avril, par cliffsu

    I’m working on video processing in Python and have noticed a slight color difference when using cv2.VideoCapture to read videos compared to other media players.

    enter image description here

    I then attempted to read the video frames directly using ffmpeg, and despite using the ffmpeg backend in OpenCV, there are still differences between OpenCV’s and ffmpeg’s output. The frames read by ffmpeg match those from other media players.

    enter image description here

    Below are the videos I’m using for testing:

    test3.webm

    test.avi

    Here is my code:

    import cv2
    import numpy as np
    import subprocess
    
    def read_frames(path, res):
        """Read numpy arrays of video frames. Path is the file path
           and res is the resolution as a tuple."""
        args = [
            "ffmpeg",
            "-i",
            path,
            "-f",
            "image2pipe",
            "-pix_fmt",
            "rgb24",
            "-vcodec",
            "rawvideo",
            "-",
        ]
    
        pipe = subprocess.Popen(
            args,
            stdout=subprocess.PIPE,
            stderr=subprocess.DEVNULL,
            bufsize=res[0] * res[1] * 3,
        )
    
        while pipe.poll() is None:
            frame = pipe.stdout.read(res[0] * res[1] * 3)
            if len(frame) > 0:
                array = np.frombuffer(frame, dtype="uint8")
                break
    
        pipe.stdout.close()
        pipe.wait()
        array = array.reshape((res[1], res[0], 3))
        array = cv2.cvtColor(array, cv2.COLOR_RGB2BGR)
        return array
    
    ORIGINAL_VIDEO = 'test3.webm'
    
    array = read_frames(ORIGINAL_VIDEO, (1280, 720))
    
    cap = cv2.VideoCapture(ORIGINAL_VIDEO, cv2.CAP_FFMPEG)
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        print(frame.shape)
        cv2.imshow("Opencv Read", frame)
        cv2.imshow("FFmpeg Direct Read", array)
        cv2.waitKeyEx()
        cv2.waitKeyEx()
        break
    cap.release()
    

    I’ve attempted to use different media players to compare cv2.VideoCapture and ffmpeg’s frame reading, to confirm that the issue lies with opencv. I’m looking to determine whether it’s a bug in OpenCV or if there are issues in my code.

    EDIT:

    Just use the following code to check the difference between opencv read and ffmpeg read.

    cv2.imshow('test', cv2.absdiff(array, frame)*10)
    cv2.waitKey(0)
    

    Here is the result: enter image description here

  • Segmentation Fault when calling FFMPEG on Lambda - but not locally

    17 avril, par thiagogps

    I am trying to extract the next 30 seconds of audio from a live video stream on YouTube using AWS Lambda. However, I'm facing an issue where Lambda does not wait for an FFmpeg subprocess to complete, unlike when running the same script locally. Below is a simplified Python script illustrating the problem:

    import subprocess
    from datetime import datetime
    
    def lambda_handler(event, context, streaming_url):
        ffmpeg_command = [
            "ffmpeg", 
            "-loglevel", "error", 
            "-i", streaming_url, 
            "-t", "30", 
            "-acodec", "pcm_s16le", 
            "-ar", "44100", 
            "-ac", "2", 
            "/tmp/output.wav"
        ]
    
        print("Starting subprocess...")
        print(f"Start time: {datetime.now()}")
        subprocess.run(ffmpeg_command, capture_output=True)
        print(f"End time: {datetime.now()}")
    

    In this script, I am using FFmpeg to capture audio from the specified streaming_url, converting it to a .wav format, and saving it as output.wav. When executed locally, this script waits until the subprocess finishes, evidenced by the significant time difference between the start and end print statements. However, when run on AWS Lambda, it proceeds almost immediately without waiting for the subprocess to complete, resulting in incomplete audio files.

    Question: How can I ensure that AWS Lambda waits for the FFmpeg subprocess to fully execute before the function exits? I assume I'm not understanding correctly how Lambda handles subprocesses. I even tried adding a time.sleep(30) after the subprocess.run, but that didn't help. Is there a specific configuration or method to handle subprocesses in Lambda correctly?

    EDIT: With the help of the comments, I understood that in fact it's returning quickly in Lambda because of a segmentation fault, since it gives me a returncode of -11, so I edited the question and its title accordingly. Locally, there is no such error. I found out this is a similar situation to Using FFmpeg with URL input causes SIGSEGV in AWS Lambda (Python runtime), but I'm still unable to solve it.

  • AWS Lambda Does Not Wait Until FFmpeg Subprocess Completes

    17 avril, par thiagogps

    I am trying to extract the next 30 seconds of audio from a live video stream on YouTube using AWS Lambda. However, I'm facing an issue where Lambda does not wait for an FFmpeg subprocess to complete, unlike when running the same script locally. Below is a simplified Python script illustrating the problem:

    import subprocess
    from datetime import datetime
    
    def lambda_handler(event, context, streaming_url):
        ffmpeg_command = [
            "ffmpeg", 
            "-loglevel", "error", 
            "-i", streaming_url, 
            "-t", "30", 
            "-acodec", "pcm_s16le", 
            "-ar", "44100", 
            "-ac", "2", 
            "output.wav"
        ]
    
        print("Starting subprocess...")
        print(f"Start time: {datetime.now()}")
        subprocess.run(ffmpeg_command, capture_output=True)
        print(f"End time: {datetime.now()}")
    

    In this script, I am using FFmpeg to capture audio from the specified streaming_url, converting it to a .wav format, and saving it as output.wav. When executed locally, this script waits until the subprocess finishes, evidenced by the significant time difference between the start and end print statements. However, when run on AWS Lambda, it proceeds almost immediately without waiting for the subprocess to complete, resulting in incomplete audio files.

    Question: How can I ensure that AWS Lambda waits for the FFmpeg subprocess to fully execute before the function exits? I assume I'm not understanding correctly how Lambda handles subprocesses. I even tried adding a time.sleep(30) after the subprocess.run, but that didn't help. Is there a specific configuration or method to handle subprocesses in Lambda correctly?

    EDIT: With the help of the comments, I understood that in fact it's returning quickly in Lambda because of a segmentation fault, since it gives me a returncode of -11. Locally, there is no such error. I found out this is a similar situation to Using FFmpeg with URL input causes SIGSEGV in AWS Lambda (Python runtime), but I'm still unable to solve it.

  • How to record video and audio from webcam using ffmpeg on Windows ?

    17 avril, par Babu

    I want to record video as well as audio from webcam using ffmpeg,

    I have used the following codes to know what devices are available:

    ffmpeg -list_devices true -f dshow -i dummy
    

    And got the result:

    ffmpeg version N-54082-g96b33dd Copyright (c) 2000-2013 the FFmpeg developers
    built on Jun 17 2013 02:05:16 with gcc 4.7.3 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
    ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
    ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
    amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
    enable-libxvid --enable-zlib
    libavutil      52. 37.101 / 52. 37.101
    libavcodec     55. 16.100 / 55. 16.100
    libavformat    55.  8.103 / 55.  8.103
    libavdevice    55.  2.100 / 55.  2.100
    libavfilter     3. 77.101 /  3. 77.101
    libswscale      2.  3.100 /  2.  3.100
    libswresample   0. 17.102 /  0. 17.102
    libpostproc    52.  3.100 / 52.  3.100
    [dshow @ 024eb460] DirectShow video devices
    [dshow @ 024eb460]  "Sirius USB2.0 Camera"
    [dshow @ 024eb460]  "Vimicro USB Camera (Altair)"
    [dshow @ 024eb460] DirectShow audio devices
    [dshow @ 024eb460]  "Microphone (Realtek High Defini"
    dummy: Immediate exit requested
    

    I am using the following codes to get more details about the device:

    ffmpeg -f dshow -list_options true -i video="Vimicro USB Camera (Altair)"
    

    And i am getting the following results:

    ffmpeg version N-54082-g96b33dd Copyright (c) 2000-2013 the FFmpeg developers
    built on Jun 17 2013 02:05:16 with gcc 4.7.3 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
    ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
    ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
    amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
    enable-libxvid --enable-zlib
    libavutil      52. 37.101 / 52. 37.101
    libavcodec     55. 16.100 / 55. 16.100
    libavformat    55.  8.103 / 55.  8.103
    libavdevice    55.  2.100 / 55.  2.100
    libavfilter     3. 77.101 /  3. 77.101
    libswscale      2.  3.100 /  2.  3.100
    libswresample   0. 17.102 /  0. 17.102
    libpostproc    52.  3.100 / 52.  3.100
    [dshow @ 0249b3e0] DirectShow video device options
    [dshow @ 0249b3e0]  Pin "Capture"
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=640x480 fps=30 max   s=640x480 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=640x480 fps=30 max s=640x480 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=352x288 fps=30 max s=352x288 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=352x288 fps=30 max s=352x288 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=320x240 fps=30 max s=320x240 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=320x240 fps=30 max s=320x240 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=176x144 fps=30 max s=176x144 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=176x144 fps=30 max s=176x144 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=160x120 fps=30 max s=160x120 fp
    s=30
    [dshow @ 0249b3e0]   pixel_format=yuyv422  min s=160x120 fps=30 max s=160x120 fp
    s=30
    video=Vimicro USB Camera (Altair): Immediate exit requested
    

    When i am trying following codes to get video and audio stream:

    ffmpeg -f dshow -s 320x240 -r 30 -vcodec mjpeg -i video="Vimicro USB Camera (Altair)" e:\output.mp4
    

    I am getting an error message as "Could not set video options video=Vimicro USB Camera (Altair): Input/output error"

    Following are the error details:

    ffmpeg version N-54082-g96b33dd Copyright (c) 2000-2013 the FFmpeg developers
    built on Jun 17 2013 02:05:16 with gcc 4.7.3 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
    ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
    ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
    amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
    enable-libxvid --enable-zlib
    libavutil      52. 37.101 / 52. 37.101
    libavcodec     55. 16.100 / 55. 16.100
    libavformat    55.  8.103 / 55.  8.103
    libavdevice    55.  2.100 / 55.  2.100
    libavfilter     3. 77.101 /  3. 77.101
    libswscale      2.  3.100 /  2.  3.100
    libswresample   0. 17.102 /  0. 17.102
    libpostproc    52.  3.100 / 52.  3.100
    [dshow @ 002f78e0] Could not set video options
    video=Vimicro USB Camera (Altair): Input/output error
    

    And i am unable to find where i am doing wrong.

    So if anybody can find where i am doing wrong or how to record video as well as audio from webcam using ffmpeg please help me to solve this problem.