Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Burn subtitles in a stop motion video, with hardware acceleration

    9 février 2020, par Belinde

    I'm trying to make a year long stop motion video with the images taken from a webcam. I've created a input.txt file with this format inside:

    ffconcat version 1.0
    
    file 'amianthe201909031230.jpg'
    duration 0.093034825870647
    
    file 'amianthe201909031330.jpg'
    duration 0.093034825870647
    

    The command I've crafted (mostly taken from the example in the official ffmpeg documentation) is:

    ffmpeg \
        -y \
        -hwaccel vaapi \
        -hwaccel_device /dev/dri/renderD128 \
        -hwaccel_output_format vaapi \
        -f concat \
        -i input.txt \
        -vf 'hwmap=mode=read+write+direct,format=nv12,ass=subtitles.ass,hwmap' \
        -c:v h264_vaapi \
        ~/amianthe.mp4
    

    But it badly fails with this output:

    ffmpeg version 4.1.4-1build2 Copyright (c) 2000-2019 the FFmpeg developers
      built with gcc 9 (Ubuntu 9.2.1-4ubuntu1)
      configuration: --prefix=/usr --extra-version=1build2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
      libavutil      56. 22.100 / 56. 22.100
      libavcodec     58. 35.100 / 58. 35.100
      libavformat    58. 20.100 / 58. 20.100
      libavdevice    58.  5.100 / 58.  5.100
      libavfilter     7. 40.101 /  7. 40.101
      libavresample   4.  0.  0 /  4.  0.  0
      libswscale      5.  3.100 /  5.  3.100
      libswresample   3.  3.100 /  3.  3.100
      libpostproc    55.  3.100 / 55.  3.100
    Input #0, concat, from 'input.txt':
      Duration: 00:00:18.70, start: 0.000000, bitrate: 5 kb/s
        Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080 [SAR 1:1 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (h264_vaapi))
    Press [q] to stop, [?] for help
    [Parsed_ass_2 @ 0x5557f4ec4ac0] Shaper: FriBidi 0.19.7 (SIMPLE) HarfBuzz-ng 2.6.1 (COMPLEX)
    [Parsed_ass_2 @ 0x5557f4ec4ac0] Using font provider fontconfig
    [Parsed_ass_2 @ 0x5557f4ec4ac0] Added subtitle file: 'subtitles.ass' (4 styles, 2 events)
    [Parsed_hwmap_3 @ 0x5557f5381ec0] Unsupported formats for hwmap: from nv12 (vaapi_vld) to vaapi_vld.
    [Parsed_hwmap_3 @ 0x5557f5381ec0] Failed to configure output pad on Parsed_hwmap_3
    Error reinitializing filters!
    Failed to inject frame into filter network: Invalid argument
    Error while processing the decoded data for stream #0:0
    Conversion failed!
    

    I'm honestly lost: from my understanding, all the elaboration should be done directly in the video card memory, so I don't understand why it's converting the surface format. Is there some other parameter I must put in format? What am I missing?

  • disable post processing in YOUTUBE-DL

    9 février 2020, par user3515562

    I want to disbale post process in youtube-dl(2020.01.24). My batch file contains

    set /p ytlink=Enter the link of Youtube Video:-    
    youtube-dl -x -o D:\%%(title)s.%%(ext)s %ytlink%  
    pause  
    

    The youtube-dl first downloads webm file or any other file than use post process ffmpeg.exe to convert it. I want to disable post process.Their must be no post process happening after youtube-dl download.
    -x is the option to only download audio file of the YouTube video in webm format .There is no post processing involved.But youtube-dl by default tries to convert the webm file to some other format, which is post processing.Post processing of audio file by default is one that i want to disable
    OS=Windows 10

  • How to convert byte[] or String to Frame(H264) with javacv ?

    9 février 2020, par oleotiger

    I have received a video from port 11111 with UDP; The video frame is split by 1460Byte as its size exceeds the size of UPD packet.

    while(true){
                data=new byte[2048];//创建字节数组,指定接收数据报的大小
                packet=new DatagramPacket(data,data.length);
                try {
                    socket.receive(packet);//此方法接收到数据报之前会一直阻塞
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String info=new String(packet.getData(),0,packet.getLength());
                frameStr+=info;
                //End of the frame
                if(info.length()!=1460){
                    decode(frameStr);
                }
            }
    

    How to decode the frame with javacv? The video is decoded by H264. The raw frame is String or byte[].

  • ffmpeg merging two sources with optional audio

    9 février 2020, par Sven Nolting

    I want to merge two video files together by using ffmpeg. I already found this command:

    ffmpeg -i INPUT1 -i INPUT2 -filter_complex \"[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]\" -map \"[v]\" -map \"[a]\" OUTPUT
    

    The Problem is, that INPUT2 not alway has Audio, so ffmpeg throws an invalid Input Stream. I'm very inexperienced with ffmpeg and I'm not getting smart out of the documentation. Is there a possible way that is decently understandable, possibly in one command?

    Summed up: I want to concat two Video Files including Audio, but the second file may or may not has an audio layer.

  • HTML5 H264 video sometimes not displaying

    8 février 2020, par Daniel

    Given this stream from an RTSP camera which produce H264 stream:

    Input #0, rtsp, from 'rtsp://admin:admin@192.168.0.15:554':
      Metadata:
        title           : LIVE555 Streaming Media v2017.10.28
        comment         : LIVE555 Streaming Media v2017.10.28
      Duration: N/A, start: 0.881956, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1600x900, 25 fps, 25 tbr, 90k tbn, 50 tbc
    

    I want to run ffmpeg and pipe its output to a HTML5 video component with MSE.

    Everything is fine and smooth as long I run this ffmpeg command (piping is removed!):

    $ ffmpeg -i 'rtsp://admin:admin@192.168.0.15:554' -c:v copy -an -movflags frag_keyframe+empty_moov -f mp4
    

    However it takes a bit time at the beginning.

    I realized that the function avformat_find_stream_info makes about 15-20 seconds of delay on my system. Here is the docs.

    Now I have also realized that if I add -probesize 32, avformat_find_stream_info will return almost immediately, but it cause some warnings:

    $ ffmpeg -probesize 32 -i 'rtsp://admin:admin@192.168.0.15:554' -c:v copy -an -movflags frag_keyframe+empty_moov -f mp4
    
    [rtsp @ 0x1b2b300] Stream #0: not enough frames to estimate rate; consider increasing probesize
    [rtsp @ 0x1b2b300] decoding for stream 0 failed
    Input #0, rtsp, from 'rtsp://admin:admin@192.168.0.15:554':
      Metadata:
        title           : LIVE555 Streaming Media v2017.10.28
        comment         : LIVE555 Streaming Media v2017.10.28
      Duration: N/A, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1600x900, 25 tbr, 90k tbn, 50 tbc
    

    If I dump out this stream (into a file, test.mp4), all mediaplayers can play it perfectly.

    However if I pipe this output into the HTML5 video with MSE, the stream sometimes displayed correctly, sometimes it just doesn't. No warnings or error messages are printed on the console in the browser.

    From the second output I can see the fps is missing. I tried to set it up manually, but was not succeed (it seemed I could not change it manually).

    How can I avoid avformat_find_stream_info and have the HTML5 MSE playback if I know everything of the stream beforehand?

    Update

    According to @szatmary's comments and answers I have search for a h264 bitstream parser.

    This is what I found. I did also save the mp4 file which is not playable by HTML5 video, but by VLC it does, and I dropped into this analyser.

    Here is a screenshot of my analysis: enter image description here

    Some facts here:

    • until #66 there is no type7 (SPS) unit in the stream.
    • 62 is the last PPS before the first SPS arrived.
    • there are a lot of PPS even before 62.
    • bitstream ends at #103.
    • playing in VLC the stream is 20 seconds long.

    I have several things to clear:

    1. the #62 and #66 sps/pps units (or whatever) are holding metadata only for the next coming frames, or they can even refer to previous frames?
    2. VLC plays 20 seconds, is it possible that it scans the whole file before, then play the frames from #1 based on #62 and #66 infos? - if VLC would get the file as stream, in this case it might play only a few seconds (#66 - #103).
    3. most important: what shall I do with the bitstream parser to make HTML5 video playing this data? Shall I drop all the units before #62? Or before #66?

    Now I'm really lost in this topic. I have created a video, with FFMPEG but this time I allowed it to finish its avformat_find_stream_info function.

    Saved the video with the same methods as previously. VLC now plays 18 seconds (this is okay, I have a 1000 frame limitation in ffmpeg command).

    However let's see now the bitstream information:

    enter image description here

    Now PPS and SPS are 130 and 133 respectively. This resulted a stream which is 2 sec shorter than before. (I guess)

    Now I have learned that in a correct parsed h264 there can still be a lot of units before the first SPS(/PPS).

    SO I would finetune my question above: what shall I do with the bitstream parser to make HTML5 video playing this data?

    Also the bitstream parser I have found is not good, because it uses a binary wrapper => it can not be run purely on the client side.

    I'm looking at mp4box now.