Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to read an sdp file using python

    23 avril, par Mubashir

    I am runnig following command to forward webcam using ffmpeg to a remote IP over a cellular network

    ffmpeg -i /dev/video0 -c:v libx264 -crf 35 -preset ultrafast -vf "eq=gamma=0.8" -f rtp "rtp://10.78.253.19:51372"
    

    following command generate an sdp file which I can save in a txt file and its icon chane into vlc which I can run on remote desktop to play/see video

    here is my sdp file view_camera.sdp

    v=0
    o=- 0 0 IN IP4 127.0.0.1
    s=No Name
    c=IN IP4 10.78.253.19
    t=0 0
    a=tool:libavformat 58.29.100
    m=video 51372 RTP/AVP 96
    a=rtpmap:96 H264/90000
    a=fmtp:96 packetization-mode=1
    

    now I want to open and view view_camera.sdp in a python script to apply detection and different vision algorithm. How can I open do it

  • Thumbnail generation using golang+ffmpeg

    23 avril, par godvlpr

    I try to generate thumbnail from video mp4 using Golang+ffmpeg.

    Let me provide some steps:

    1. Tried to generate using terminal ffmpeg -i test.mp4 -ss 00:00:00 -vframes 1 thumbnail.jpg - all works successfully
    2. Tried to generate from golang and put result into stdout cmd := exec.Command("ffmpeg", "-i", "test.mp4", "-ss", "00:00:00", "-vframes", "1", "-f", "image2pipe", "-") - all works successfully
    3. Trying to open video using os.ReadFile and bytes.NewReader and after that - cmd := exec.Command("ffmpeg", "-i", "pipe:", "-ss", "00:00:00", "-vframes", "1", "-f", "image2pipe", "-") And in this step I have an error. Below provided all code and na error
        r, err := os.ReadFile("test.mp4")
        if err != nil {
            log.Fatalf("Failed to read video file: %v", err)
        }
        
        videoBuffer := bytes.NewReader(r)
    
        cmd := exec.Command("ffmpeg", "-i", "pipe:", "-ss", "00:00:00", "-vframes", "1", "-f", "image2pipe", "-")
    
        cmd.Stdin = videoBuffer
    
        // Capture output as bytes
        var out bytes.Buffer
        cmd.Stdout = &out
    
        var stderr bytes.Buffer
        cmd.Stderr = &stderr
    
        // Run the command
        err = cmd.Run()
        if err != nil {
            log.Fatalf("ffmpeg command failed: %v, stderr: %s", err, stderr.String())
        }
    
        // Convert bytes to image.Image
        img, _, err := image.Decode(&out)
        if err != nil {
            log.Fatalf("Failed to decode thumbnail: %v", err)
        }
    

    Error

    2024/04/23 13:25:51 ffmpeg command failed: exit status 183, stderr: ffmpeg version 7.0 Copyright (c) 2000-2024 the FFmpeg developers
      built with Apple clang version 15.0.0 (clang-1500.3.9.4)
      configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/7.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox --enable-neon
      libavutil      59.  8.100 / 59.  8.100
      libavcodec     61.  3.100 / 61.  3.100
      libavformat    61.  1.100 / 61.  1.100
      libavdevice    61.  1.100 / 61.  1.100
      libavfilter    10.  1.100 / 10.  1.100
      libswscale      8.  1.100 /  8.  1.100
      libswresample   5.  1.100 /  5.  1.100
      libpostproc    58.  1.100 / 58.  1.100
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x136504080] stream 0, offset 0x30: partial file
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x136504080] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1920x1080, 3496 kb/s): unspecified pixel format
    Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf58.26.100
      Duration: 00:00:02.01, start: 0.000000, bitrate: N/A
      Stream #0:0[0x1](und): Video: h264 (avc1 / 0x31637661), none, 1920x1080, 3496 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
          Metadata:
            handler_name    : VideoHandler
            vendor_id       : [0][0][0][0]
      Stream #0:1[0x2](und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
          Metadata:
            handler_name    : SoundHandler
            vendor_id       : [0][0][0][0]
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x136504080] stream 0, offset 0x30: partial file
    [in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x600001134000] Error during demuxing: Invalid data found when processing input
    Cannot determine format of input 0:0 after EOF
    [vf#0:0 @ 0x600001f2c000] Task finished with error code: -1094995529 (Invalid data found when processing input)
    [vf#0:0 @ 0x600001f2c000] Terminating thread with return code -1094995529 (Invalid data found when processing input)
    [vost#0:0/mjpeg @ 0x104a04650] Could not open encoder before EOF
    [vost#0:0/mjpeg @ 0x104a04650] Task finished with error code: -22 (Invalid argument)
    [vost#0:0/mjpeg @ 0x104a04650] Terminating thread with return code -22 (Invalid argument)
    [out#0/image2pipe @ 0x60000182c000] Nothing was written into output file, because at least one of its streams received no packets.
    frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A    
    Conversion failed!
    

    Also tried to do something like this cmd := exec.Command("ffmpeg", "-analyzeduration", "10000M", "-probesize", "10000M", "-i", "pipe:", "-ss", "00:00:00", "-vframes", "1", "-f", "image2pipe", "-") - and had the same error (almost the same).

    How to fix code or ffmpeg command - to bring this code workable?

  • Subtitle word scaling with ASS file causing line shifting

    23 avril, par Barrard

    I'm trying to make my subtitles scale one word at a time, but I'm running into an issue with the whole line shifting. Is there a way I can scale a word, and make the other words not move sue to the scale effect? Here is the ASS File

    [Script Info]
    ScriptType: v4.00+
    PlayResX: 384
    PlayResY: 288
    ScaledBorderAndShadow: yes
    [V4+ Styles]
    Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, 
    BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, 
    BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
    Style: Default,Arial,18,&H00FFFFFF,&H00FFFFFF,&H00000000,&HFF000000,-1,0,0,0,100,100,0,0,3,1,0.6,5,10,10,10,0
    [Events]
    Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
    Dialogue: 0,0:00:0.00,0:00:1.00,Default,,0,0,0,,{\an5\pos(192,144)\alpha&HFF&}And so my fellow Americans,
    Dialogue: 0,0:00:0.00,0:00:02.50,Default,,0,0,0,,{\an5\pos(192,144)\fscx90\fscy90\t(0,2500,\fscx120\fscy120)}And{\fscx100\fscy100} so my fellow Americans,
    Dialogue: 0,0:00:2.50,0:00:05.00,Default,,0,0,0,,{\an5\pos(192,144)\fscx120\fscy120\t(0,2500,\fscx100\fscy100)}And{\fscx100\fscy100} so my fellow Americans,
    

    this shows the video output. https://youtube.com/shorts/d4VaoWqTMtQ?feature=share

    Thanks in advanced.

  • How to run FFMPEG with —enable-libfontconfig on Amazon Linux 2

    22 avril, par Adrien Kaczmarek

    Problem

    I want to run FFmpeg on AWS Lambda (Amazon Linux 2) with the configuration --enable-libfontconfig enable.

    Situation

    I already have FFmpeg running on AWS Lambda without the configuration --enable-libfontconfig.

    Here is the step I took to run FFmpeg on AWS Lambda (see official guide):

    • Connect to Amazon EC2 running on AL2 (environment used by Lambda for Python 3.11)
    • Download and package FFmpeg from John Van Sickle
    • Create a Lambda Layer with FFmpeg

    Unfortunately, the version built by John Van Sickle doesn't have the configuration --enable-libfontconfig enabled.

    Unsuccessful Trials

    I tried to rebuilt it from scratch following the installation guide but without success (and the guide doesn't install font related dependencies)

    I tried to install it with brew but the command brew install ffmpeg didn't succeed on AL2.

    I tried to install ffmpeg from ffmpeg-master-latest-linux64-gpl.tar.xz. Unfortunately, this build of ffmpeg doesn't run on AL2:

    ffmpeg: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by ffmpeg)
    ffmpeg: /lib64/libpthread.so.0: version `GLIBC_2.28' not found (required by ffmpeg)
    ffmpeg: /lib64/libc.so.6: version `GLIBC_2.27' not found (required by ffmpeg)
    ffmpeg: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ffmpeg)
    

    Any help would be greatly appreciated,

    Please make sure your answer is up to date and tested. Too many answers out there are auto-generated, too generic, or simple redirect without context.

    Thank you

  • Using ffmpeg to convert all files to a subdir with same name [duplicate]

    22 avril, par Marc Mouton

    I cannot manage to make a working script for this under Linux. Basically i want a script that execute a ffmpeg command and output the files to a subdirectory with the same name as the source. Long story short it is to convert audio from several mkv files, but i want to keep the same name and as ffmpeg doesn't overwrite files, i need to output them to a subdirectory.

    There is this answer : https://superuser.com/questions/912730/ffmpeg-batch-convert-make-same-filename?newreg=4676efc538b54a178fcbcc17e1fd2127

    But the Linux solution:

    mkdir outdir
    for i in *.wav; do
      ffmpeg -i $i -acodec pcm_s16le -ac 1 -ar 22050 outdir/$i;
    done
    

    In my case it should be:

    mkdir outdir
    for i in *.mkv; do
      ffmpeg -i $i -c:v copy -c:a flac -compression_level 12 -map 0 -c:s copy outdir/$i;
    done
    

    But it doesn't work:

    [in#0 @ 0x5fd710398840] Error opening input: No such file or directory Error opening input file AAA. Error opening input files: No such file or directory