fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.97k stars 881 forks source link

No way to set input stream duration #1247

Open opheliagame opened 9 months ago

opheliagame commented 9 months ago

The ffmpeg command produced from using the given js code is not the expected result. Since changing the ffmpeg command produces the correct result, there is a need to introduce a way in the API to specify a duration for the input stream/file.

Version information

Code to reproduce

ffmpeg()
  .duration(10)
  .input('https://video16.pad.ma/BZX/240p1.mp4')
  .seekInput(0)
  .duration(10)
  .input('https://video16.pad.ma/BZX/240p1.mp4')
  .seekInput(100)
  .mergeToFile('output.mp4')
  .on('start', (commandline) => {
    console.log(`Spawned ffmpeg with command: ${commandline}`)
  })
  .on('stderr', function(stderrLine) {
    console.log('Stderr output: ' + stderrLine);
  })
  .on('error', function(err, stdout, stderr) {
    console.log('Cannot process video: ' + err.message);
  })

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

Expected an output file of 20 seconds, from 1-10 from the first input and 100-110 from the second input.

Observed results

Output of 10 seconds, just the first video.

ffmpeg output

Spawned ffmpeg with command: ffmpeg -ss 0 -i https://video16.pad.ma/BZX/240p1.mp4 -ss 100 -i https://video16.pad.ma/BZX/240p1.mp4 -y -filter_complex concat=n=2:v=1:a=1 -t 10 -t 10 output.mp4
Stderr output: ffmpeg version 6.0-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
Stderr output:   built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
Stderr output:   configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
Stderr output:   libavutil      58.  2.100 / 58.  2.100
Stderr output:   libavcodec     60.  3.100 / 60.  3.100
Stderr output:   libavformat    60.  3.100 / 60.  3.100
Stderr output:   libavdevice    60.  1.100 / 60.  1.100
Stderr output:   libavfilter     9.  3.100 /  9.  3.100
Stderr output:   libswscale      7.  1.100 /  7.  1.100
Stderr output:   libswresample   4. 10.100 /  4. 10.100
Stderr output:   libpostproc    57.  1.100 / 57.  1.100
Stderr output: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://video16.pad.ma/BZX/240p1.mp4':
Stderr output:   Metadata:
Stderr output:     major_brand     : isom
Stderr output:     minor_version   : 512
Stderr output:     compatible_brands: isomiso2avc1mp41
Stderr output:     encoder         : Lavf53.21.1
Stderr output:   Duration: 00:44:17.01, start: 0.000000, bitrate: 92 kb/s
Stderr output:   Stream #0:0[0x1](eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], 24 kb/s, 25 fps, 25 tbr, 25 tbn (default)        
Stderr output:     Metadata:
Stderr output:       handler_name    : VideoHandler
Stderr output:       vendor_id       : [0][0][0][0]
Stderr output:   Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
Stderr output:     Metadata:
Stderr output:       handler_name    : SoundHandler
Stderr output:       vendor_id       : [0][0][0][0]
Stderr output: Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'https://video16.pad.ma/BZX/240p1.mp4':
Stderr output:   Metadata:
Stderr output:     major_brand     : isom
Stderr output:     minor_version   : 512
Stderr output:     compatible_brands: isomiso2avc1mp41
Stderr output:     encoder         : Lavf53.21.1
Stderr output:   Duration: 00:44:17.01, start: 0.000000, bitrate: 92 kb/s
Stderr output:   Stream #1:0[0x1](eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], 24 kb/s, 25 fps, 25 tbr, 25 tbn (default)        
Stderr output:     Metadata:
Stderr output:       handler_name    : VideoHandler
Stderr output:       vendor_id       : [0][0][0][0]
Stderr output:   Stream #1:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
Stderr output:     Metadata:
Stderr output:       handler_name    : SoundHandler
Stderr output:       vendor_id       : [0][0][0][0]
Stderr output: Stream mapping:
Stderr output:   Stream #0:0 (h264) -> concat
Stderr output:   Stream #0:1 (aac) -> concat
Stderr output:   Stream #1:0 (h264) -> concat
Stderr output:   Stream #1:1 (aac) -> concat
Stderr output:   concat -> Stream #0:0 (libx264)
Stderr output:   concat -> Stream #0:1 (aac)
Stderr output: Press [q] to stop, [?] for help
Stderr output: [libx264 @ 00000272a2e675c0] using SAR=1/1
Stderr output: [libx264 @ 00000272a2e675c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
Stderr output: [libx264 @ 00000272a2e675c0] profile High, level 1.3, 4:2:0, 8-bit
Stderr output: [libx264 @ 00000272a2e675c0] 264 - core 164 r3106 eaa68fa - H.264/MPEG-4 AVC codec - Copyleft 2003-2023 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=7 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00      
Stderr output: Output #0, mp4, to 'output.mp4':
Stderr output:   Metadata:
Stderr output:     major_brand     : isom
Stderr output:     minor_version   : 512
Stderr output:     compatible_brands: isomiso2avc1mp41
Stderr output:     encoder         : Lavf60.3.100
Stderr output:   Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 12800 tbn
Stderr output:     Metadata:
Stderr output:       encoder         : Lavc60.3.100 libx264
Stderr output:     Side data:
Stderr output:       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stderr output:   Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s
Stderr output:     Metadata:
Stderr output:       encoder         : Lavc60.3.100 aac
Stderr output: frame=    0 fps=0.0 q=0.0 size=       0kB time=00:00:00.25 bitrate=   1.5kbits/s speed=0.21x
Stderr output: frame=  250 fps=148 q=-1.0 Lsize=      81kB time=00:00:09.98 bitrate=  66.7kbits/s speed=5.89x    
Stderr output: video:9kB audio:63kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 12.864926%
Stderr output: [libx264 @ 00000272a2e675c0] frame I:2     Avg QP:10.74  size:   212
Stderr output: [libx264 @ 00000272a2e675c0] frame P:101   Avg QP:13.87  size:    60
Stderr output: [libx264 @ 00000272a2e675c0] frame B:147   Avg QP:12.68  size:    16
Stderr output: [libx264 @ 00000272a2e675c0] consecutive B-frames: 20.0%  4.8%  0.0% 75.2%
Stderr output: [libx264 @ 00000272a2e675c0] mb I  I16..4: 71.0% 27.5%  1.5%
Stderr output: [libx264 @ 00000272a2e675c0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  1.0%  0.2%  0.1%  0.0%  0.0%    skip:98.6%
Stderr output: [libx264 @ 00000272a2e675c0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.2%  0.0%  0.0%  direct: 0.0%  skip:99.8%  L0:62.8% L1:37.2% BI: 0.0%
Stderr output: [libx264 @ 00000272a2e675c0] 8x8 transform intra:27.7% inter:28.5%
Stderr output: [libx264 @ 00000272a2e675c0] coded y,uvDC,uvAC intra: 2.7% 0.0% 0.0% inter: 0.2% 0.0% 0.0%
Stderr output: [libx264 @ 00000272a2e675c0] i16 v,h,dc,p: 90%  1% 10%  0%
Stderr output: [libx264 @ 00000272a2e675c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 54%  9% 37%  0%  0%  0%  0%  0%  0%
Stderr output: [libx264 @ 00000272a2e675c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 25% 36%  1%  3%  5%  3%  3%  1%
Stderr output: [libx264 @ 00000272a2e675c0] i8c dc,h,v,p: 100%  0%  0%  0%
Stderr output: [libx264 @ 00000272a2e675c0] Weighted P-Frames: Y:55.4% UV:0.0%
Stderr output: [libx264 @ 00000272a2e675c0] ref P L0: 94.8%  0.6%  3.9%  0.1%  0.6%
Stderr output: [libx264 @ 00000272a2e675c0] ref B L0: 72.9% 27.1%
Stderr output: [libx264 @ 00000272a2e675c0] ref B L1: 97.1%  2.9%
Stderr output: [libx264 @ 00000272a2e675c0] kb/s:7.02
Stderr output: [aac @ 00000272a309a140] Qavg: 64841.527
Stderr output: