Newest 'ffmpeg' Questions - Stack Overflow

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

Articles published on the website

  • Create movie programatically

    14 November, by Martin Delille

    I would like to create a movie programatically.

    My first iteration is to create a picture sequence with QPainter rendering (see https://github.com/MartinDelille/videogenerator) and then assemble them with ffmpeg but I would be more happy to generate the video file directly.

    I choose QPainter, but I'm open to QML rendering mechanism which is more modern in my opinion.

    What would be the best approach for this?

  • How to add subtitles to the encoded video using ffmpeg?

    14 November, by geo-freak

    I am trying to add my srt file to the video using the options which were answered here before. My input file has captions in it by default. I tried in different ways to get the captions enabled in my encoded video. Below are the commands I used.

    ffmpeg  -i input.ts -i captions.srt -b:a 32000 -ar 48000  -force_key_frames 'expr:gte(t,n_forced*3)' -acodec libfaac -hls_flags single_file -hls_list_size 0 -hls_time 3 -vcodec libx264 -s 320x240 -b:v 512000 -maxrate 512000 -c:s mov_text outfile.ts
    

    But I couldn't see the captions after I see the mediainfo of the encoded file. You can see the log file of my command.

    [mpegts @ 0x56412e67b0c0] max_analyze_duration 5000000 reached at 5024000 microseconds st:1
    input.ts FPS 29.970030 1
    Input #0, mpegts, from 'input.ts':
      Duration: 00:03:00.07, start: 1.400000, bitrate: 2172 kb/s
      Program 1
        Metadata:
          service_name    : Service01
          service_provider: FFmpeg
        Stream #0:0[0x100]: Video: mpeg2video (Main), 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv), 704x480 [SAR 10:11 DAR 4:3], Closed Captions, max. 15000 kb/s, 
    29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
        Stream #0:1[0x101](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
    Input #1, srt, from 'captions.srt':
      Duration: N/A, bitrate: N/A
        Stream #1:0: Subtitle: subrip
    [graph 0 input from stream 0:0 @ 0x56412e678540] w:704 h:480 pixfmt:yuv420p tb:1/90000 fr:30000/1001 sar:10/11 sws_param:flags=2
    [scaler for output stream 0:0 @ 0x56412e9caac0] w:320 h:240 flags:'bicubic' interl:0
    [scaler for output stream 0:0 @ 0x56412e9caac0] w:704 h:480 fmt:yuv420p sar:10/11 -> w:320 h:240 fmt:yuv420p sar:1/1 flags:0x4
    [graph 1 input from stream 0:1 @ 0x56412e9f74e0] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3
    [audio format for output stream 0:1 @ 0x56412e9f7b40] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format 
    for output stream 0:1'                                                                                                                                               
    [auto-inserted resampler 0 @ 0x56412e9f9f20] ch:2 chl:stereo fmt:fltp r:48000Hz -> ch:2 chl:stereo fmt:s16 r:48000Hz
    [libx264 @ 0x56412e9bb8c0] VBV maxrate specified, but no bufsize, ignored
    [libx264 @ 0x56412e9bb8c0] using SAR=1/1
    [libx264 @ 0x56412e9bb8c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x56412e9bb8c0] profile High, level 2.0
    [mpegts @ 0x56412e9ba5a0] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
    Output #0, mpegts, to 'my_encoded_all-3.ts':
      Metadata:
        encoder         : Lavf57.25.100
        Stream #0:0: Video: h264 (libx264), -1 reference frame, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 512 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
        Metadata:
          encoder         : Lavc57.24.102 libx264
        Side data:
          unknown side data type 10 (24 bytes)
        Stream #0:1(eng): Audio: aac (libfaac), 48000 Hz, stereo, s16, 32 kb/s
        Metadata:
          encoder         : Lavc57.24.102 libfaac
        Stream #0:2(eng): Subtitle: subrip (srt), 320x240
            Metadata:
              encoder         : Lavc57.24.102 srt
        Stream mapping:
          Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
          Stream #0:1 -> #0:1 (ac3 (native) -> aac (libfaac))
          Stream #1:0 -> #0:2 (subrip (srt) -> subrip (srt))
    Press [q] to stop, [?] for help
    [scaler for output stream 0:0 @ 0x56412e9caac0] w:704 h:480 fmt:yuv420p sar:40/33 -> w:320 h:240 fmt:yuv420p sar:4/3 flags:0x4
    No more output streams to write to, finishing.e=00:02:58.85 bitrate= 658.4kbits/s speed=13.2x
    frame= 5377 fps=385 q=-1.0 Lsize=   16672kB time=00:59:16.18 bitrate=  38.4kbits/s speed= 255x
    video:11401kB audio:1410kB subtitle:446kB other streams:0kB global headers:0kB muxing overhead: 25.753614%
    Input file #0 (input.ts):
      Input stream #0:0 (video): 5380 packets read (40279443 bytes); 5377 frames decoded; 
      Input stream #0:1 (audio): 5625 packets read (4320000 bytes); 5625 frames decoded (8640000 samples); 
      Total: 11005 packets (44599443 bytes) demuxed
    Input file #1 (captions.srt):
      Input stream #1:0 (subtitle): 10972 packets read (447147 bytes); 10972 frames decoded; 
      Total: 10972 packets (447147 bytes) demuxed
    Output file #0 (output.ts):
      Output stream #0:0 (video): 5377 frames encoded; 5377 packets muxed (11675098 bytes); 
      Output stream #0:1 (audio): 8438 frames encoded (8640000 samples); 8439 packets muxed (1444109 bytes); 
      Output stream #0:2 (subtitle): 10972 frames encoded; 10972 packets muxed (456619 bytes); 
      Total: 24788 packets (13575826 bytes) muxed
    [libx264 @ 0x56412e9bb8c0] frame I:81    Avg QP:15.08  size: 16370
    [libx264 @ 0x56412e9bb8c0] frame P:2312  Avg QP:17.77  size:  3393
    [libx264 @ 0x56412e9bb8c0] frame B:2984  Avg QP:22.38  size:   839
    [libx264 @ 0x56412e9bb8c0] consecutive B-frames: 20.6% 13.2%  9.4% 56.8%
    [libx264 @ 0x56412e9bb8c0] mb I  I16..4: 11.6% 37.0% 51.4%
    [libx264 @ 0x56412e9bb8c0] mb P  I16..4:  1.2%  3.2%  2.4%  P16..4: 33.7% 18.0% 15.7%  0.0%  0.0%    skip:25.6%
    [libx264 @ 0x56412e9bb8c0] mb B  I16..4:  0.2%  0.3%  0.2%  B16..8: 30.7%  9.2%  3.2%  direct: 5.1%  skip:51.1%  L0:33.6% L1:44.5% BI:21.9%
    [libx264 @ 0x56412e9bb8c0] final ratefactor: 16.76
    [libx264 @ 0x56412e9bb8c0] 8x8 transform intra:43.0% inter:49.8%
    [libx264 @ 0x56412e9bb8c0] coded y,uvDC,uvAC intra: 77.9% 85.1% 68.8% inter: 22.9% 21.7% 6.0%
    [libx264 @ 0x56412e9bb8c0] i16 v,h,dc,p: 30% 38%  5% 26%
    [libx264 @ 0x56412e9bb8c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 23% 18%  4%  5%  7%  6%  7%  8%
    [libx264 @ 0x56412e9bb8c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 23% 11%  5%  6%  8%  6%  7%  6%
    [libx264 @ 0x56412e9bb8c0] i8c dc,h,v,p: 46% 24% 21%  8%
    [libx264 @ 0x56412e9bb8c0] Weighted P-Frames: Y:4.2% UV:2.6%
    [libx264 @ 0x56412e9bb8c0] ref P L0: 73.3% 10.9% 11.1%  4.5%  0.1%
    [libx264 @ 0x56412e9bb8c0] ref B L0: 92.1%  6.3%  1.6%
    [libx264 @ 0x56412e9bb8c0] ref B L1: 97.4%  2.6%
    

    I found no issues in encoding but I couldn't see the captions enabled in my output encoded video. I played it in my VLC player. No tracks for subtitles.

    Can't we add the subtitles to a video while encoding?

    Any help in achieving this would be appreciated.

  • Error while opening encoder for output stream #1:2 - maybe incorrect parameters such as bit_rate, rate, width or height

    14 November, by geo-freak

    I am encoding a video which has dvb_teletext inside. I got an error saying Error while opening encoder for output stream #1:2. I used the following command to encode my video.

    ffmpeg -threads 8 -i input.ts -s 400x222 -qscale:v 4 -vcodec libx264 -s 320x240 -b:v 512000 -maxrate 512000 -acodec libfaac -b:a 32000 -ar 48000 -force_key_frames expr:gte(t,n_forced*3) -hls_flags single_file -hls_list_size 0 -hls_time 3 -y output.m3u8
    

    You can see the log output of my command.

    Input #0, mpegts, from 'pipe:':
      Duration: N/A, start: 91105.257722, bitrate: N/A
      Program 1 
        Stream #0:0[0x4b1]: Video: h264 (High), 4 reference frames ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg), 704x576 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #0:1[0xc7d](swe): Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 256 kb/s
        Stream #0:2[0x1932](swe,nor,dan,fin,swe): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006), 492x250
    [Parsed_fps_0 @ 0x55975e31b7e0] fps=1/1
    [graph 0 input from stream 0:0 @ 0x55975e1fb9c0] w:704 h:576 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:16/11 sws_param:flags=2
    [scaler for output stream 0:0 @ 0x55975e1f8fe0] w:400 h:222 flags:'bicubic' interl:0
    [swscaler @ 0x55975e1a0c80] deprecated pixel format used, make sure you did set range correctly
    [scaler for output stream 0:0 @ 0x55975e1f8fe0] w:704 h:576 fmt:yuv420p sar:16/11 -> w:400 h:222 fmt:yuvj420p sar:74/75 flags:0x4
    [graph 1 input from stream 0:0 @ 0x55975e177120] w:704 h:576 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:16/11 sws_param:flags=2
    [scaler for output stream 1:0 @ 0x55975e1f1020] w:320 h:240 flags:'bicubic' interl:0
    [scaler for output stream 1:0 @ 0x55975e1f1020] w:704 h:576 fmt:yuv420p sar:16/11 -> w:320 h:240 fmt:yuv420p sar:4/3 flags:0x4
    [graph 2 input from stream 0:1 @ 0x55975e532f20] tb:1/48000 samplefmt:s16p samplerate:48000 chlayout:0x3
    [audio format for output stream 1:1 @ 0x55975e533540] auto-inserting filter 'auto-inserted resampler 0' between the filter 'Parsed_anull_0' and the filter 'audio format for output stream 1:1'
    [auto-inserted resampler 0 @ 0x55975e5358e0] ch:2 chl:stereo fmt:s16p r:48000Hz -> ch:2 chl:stereo fmt:s16 r:48000Hz
    [libx264 @ 0x55975e2349a0] VBV maxrate specified, but no bufsize, ignored
    [libx264 @ 0x55975e2349a0] using SAR=4/3
    [libx264 @ 0x55975e2349a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 0x55975e2349a0] profile High, level 2.0
    Output #0, hls, to 'output.m3u8':
        Stream #1:0: Video: h264 (libx264), -1 reference frame, yuv420p, 320x240 [SAR 4:3 DAR 16:9], q=-1--1, 512 kb/s, 25 fps, 25 tbn, 25 tbc
        Metadata:
          encoder         : Lavc57.24.102 libx264
        Side data:
          unknown side data type 10 (24 bytes)
        Stream #1:1(swe): Audio: aac (libfaac), 48000 Hz, stereo, s16, 32 kb/s
        Metadata:
          encoder         : Lavc57.24.102 libfaac
        Stream #1:2(swe,nor,dan,fin,swe): Subtitle: webvtt, 128 kb/s
        Metadata:
          encoder         : Lavc57.24.102 webvtt
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
      Stream #0:0 -> #1:0 (h264 (native) -> h264 (libx264))
      Stream #0:1 -> #1:1 (mp2 (native) -> aac (libfaac))
      Stream #0:2 -> #1:2 (dvb_teletext (libzvbi_teletextdec) -> webvtt (native))
    Error while opening encoder for output stream #1:2 - maybe incorrect parameters such as bit_rate, rate, width or height
    [Parsed_fps_0 @ 0x55975e31b7e0] 0 frames in, 0 frames out; 0 frames dropped, 0 frames duplicated.
    [libx264 @ 0x55975e2349a0] final ratefactor: 23.40
    (END)
    

    Do I need to use map options here? How to resolve this? Any help or suggestion?

  • How to speed up ffmpeg streaming on android using libvlc?

    14 November, by ALirezaSO

    I'm streaming live from my GoPro inside my android app. I use ffmpeg to receive the streaming data from the GoPro and vlc to play it in a surfaceview. I used the code which is provided by KonradIT here. The main command used for the ffmpeg is:

    -fflags nobuffer -f mpegts -i udp://:8554 -f mpegts udp://127.0.0.1:8555/gopro?pkt_size=64
    

    and the options for vlclib are:

    options.add("--aout=opensles");
    options.add("--audio-time-stretch");
    options.add("-vvv");
    

    The output is something worse. It's laggy and its speed is about 17 FPS. And one annoying thing is the streamed picture is very small and as far as I tried, there was no way to make it larger and stretched. I want to know if there is any command to speedup the streaming (in anyway, even by reducing the quality) ? Either on the side of ffmpeg or vlc.

  • Why my nodejs giving this problem while starting to run rtsp?

    14 November, by Rajaram

    While starting the server for the first time just after the code checkout , my react js project is throwing error "events.js:187 throw er; // Unhandled 'error' event" . I have node 13.1.0 and npm 6.12.1.

    [
      '-rtsp_transport',
      'tcp',
      '-i',
      'rtsp://user:user123@192.168.1.100:88/videoSub',
      '-f',
      'mpeg1video',
      '-b:v',
      '1000k',
      '-an',
      '-r',
      '24',
      '-'
    ]
    events.js:187
          throw er; // Unhandled 'error' event
          ^
    
    Error: spawn ffmpeg ENOENT
        at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
        at onErrorNT (internal/child_process.js:456:16)
        at processTicksAndRejections (internal/process/task_queues.js:80:21)
    Emitted 'error' event on ChildProcess instance at:
        at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
        at onErrorNT (internal/child_process.js:456:16)
        at processTicksAndRejections (internal/process/task_queues.js:80:21) {
      errno: -2,
      code: 'ENOENT',
      syscall: 'spawn ffmpeg',
      path: 'ffmpeg',
      spawnargs: [
        '-rtsp_transport',
        'tcp',
        '-i',
        'rtsp://user:user123@192.168.1.100:88/videoSub',
        '-f',
        'mpeg1video',
        '-b:v',
        '1000k',
        '-an',
        '-r',
        '24',
        '-'
      ]
    }