Opened 4 months ago

Closed 3 months ago

#10826 closed defect (fixed)

Short trim inside filter_complex leads to empty output

Reported by: Gyan Owned by:
Priority: critical Component: ffmpeg
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: 7.0 Reproduced by developer: no
Analyzed by developer: no

Description

Carrying out a short trim like in the command below leads to an empty output.

ffmpeg -i src.mp4 -filter_complex "[0:v]trim=start=0.5:end=0.9[v]; [0:a]atrim=start=0.5:end=0.9[a]" -map [v] -map [a] out.mp4

Source can be generated using

ffmpeg -f lavfi -i testsrc -f lavfi -i sine -t 1 src.mp4

Proximate source of error in log below is d119ae2fd82a494d9430ff4d4fc262961a68c598

[vost#0:0/libx264 @ 0000017973984cc0] Could not open encoder before EOF
[aost#0:1/aac @ 0000017973985ac0] Could not open encoder before EOF
[vost#0:0/libx264 @ 0000017973984cc0] Task finished with error code: -22 (Invalid argument)
[aost#0:1/aac @ 0000017973985ac0] Task finished with error code: -22 (Invalid argument)
[vost#0:0/libx264 @ 0000017973984cc0] Terminating thread with return code -22 (Invalid argument)
[aost#0:1/aac @ 0000017973985ac0] Terminating thread with return code -22 (Invalid argument)
[out#0/mp4 @ 0000017973a752c0] 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=       0kB time=N/A bitrate=N/A speed=N/A   

However, the empty output first occurs with d35c05cb9ee39e1d90fab326a6aaec6c6c9433e1

[out#0/mp4 @ 0000015db613bfc0] sq: 0 EOF
[out#0/mp4 @ 0000015db613bfc0] sq: finish queue
[out#0/mp4 @ 0000015db613bfc0] sq: 1 EOF
[out#0/mp4 @ 0000015db613bfc0] sq: finish queue
[out#0/mp4 @ 0000015db613bfc0] sq: 1 EOF
[out#0/mp4 @ 0000015db613bfc0] sq: finish queue
[out#0/mp4 @ 0000015db613bfc0] sq: receive 1 ts 0.9 queue head -1 ts N/A
[aac @ 0000015db5db1340] Trying to remove 792 more samples than there are in the queue
[out#0/mp4 @ 0000015db613bfc0] sq: 1 EOF
[out#0/mp4 @ 0000015db613bfc0] sq: finish queue
[out#0/mp4 @ 0000015db613bfc0] 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=       0kB time=00:00:00.89 bitrate=   0.0kbits/s speed=46.9x 


Change History (2)

comment:1 by Niklas Haas, 3 months ago

I can't reproduce this on current git master (a3ca4beeaa4). In particular, every commit since d119ae2fd82a4 fixes the output for me:

$ git checkout d119ae2fd82a4 && make
$ ./ffmpeg -y -i src.mp4 -filter_complex "[0:v]trim=start=0.5:end=0.9[v]; [0:a]atrim=start=0.5:end=0.9[a]" -map [v] -map [a] out.mp4
ffmpeg version N-112959-gd119ae2fd82 Copyright (c) 2000-2023 the FFmpeg developers

built with gcc 13 (SUSE Linux)
configuration: --prefix=/home/nand/dev/prefix/ --disable-optimizations --assert-level=2 --enable-libfreetype --enable-libharfbuzz --enable-libx264 --enable-libzimg --enable-lcms2 --enable-gpl --enable-libdrm --enable-libdav1d --enable-libplacebo --samples=/home/nand/cms/fate-suite
libavutil 58. 32.100 / 58. 32.100
libavcodec 60. 35.100 / 60. 35.100
libavformat 60. 18.100 / 60. 18.100
libavdevice 60. 4.100 / 60. 4.100
libavfilter 9. 14.100 / 9. 14.100
libswscale 7. 6.100 / 7. 6.100
libswresample 4. 13.100 / 4. 13.100
libpostproc 57. 4.100 / 57. 4.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'src.mp4':

Metadata:

major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.21.101

Duration: 00:00:01.00, start: 0.000000, bitrate: 150 kb/s
Stream #0:0[0x1](und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p(progressive), 320x240 [SAR 1:1 DAR 4:3], 61 kb/s, 25 fps, 25 tbr, 12800 tbn (default)

Metadata:

handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.40.100 libx264

Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 70 kb/s (default)

Metadata:

handler_name : SoundHandler
vendor_id : [0][0][0][0]

Stream mapping:

Stream #0:0 (h264) -> trim:default
Stream #0:1 (aac) -> atrim:default
trim:default -> Stream #0:0 (libx264)
atrim:default -> Stream #0:1 (aac)

Press [q] to stop, ? for help
[libx264 @ 0x4e82fc0] using SAR=1/1
[libx264 @ 0x4e82fc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x4e82fc0] profile High 4:4:4 Predictive, level 1.3, 4:4:4, 8-bit
[libx264 @ 0x4e82fc0] 264 - core 164 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - 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=4 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
Output #0, mp4, to 'out.mp4':

Metadata:

major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.18.100

Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 25 fps, 12800 tbn

Metadata:

encoder : Lavc60.35.100 libx264

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A

Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s

Metadata:

encoder : Lavc60.35.100 aac

[out#0/mp4 @ 0x4e81dc0] video:5kB audio:4kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 21.040626%
frame= 23 fps=0.0 q=-1.0 Lsize= 11kB time=N/A bitrate=N/A dup=13 drop=0 speed=N/A
[libx264 @ 0x4e82fc0] frame I:1 Avg QP:18.26 size: 3164
[libx264 @ 0x4e82fc0] frame P:6 Avg QP:15.53 size: 183
[libx264 @ 0x4e82fc0] frame B:16 Avg QP:13.16 size: 31
[libx264 @ 0x4e82fc0] consecutive B-frames: 4.3% 0.0% 26.1% 69.6%
[libx264 @ 0x4e82fc0] mb I I16..4: 43.7% 29.7% 26.7%
[libx264 @ 0x4e82fc0] mb P I16..4: 0.2% 0.2% 0.0% P16..4: 6.4% 2.2% 0.8% 0.0% 0.0% skip:90.2%
[libx264 @ 0x4e82fc0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 2.8% 0.0% 0.0% direct: 0.0% skip:97.2% L0:69.6% L1:25.6% BI: 4.8%
[libx264 @ 0x4e82fc0] 8x8 transform intra:29.9% inter:81.0%
[libx264 @ 0x4e82fc0] coded y,u,v intra: 15.7% 14.0% 14.3% inter: 0.3% 0.4% 0.4%
[libx264 @ 0x4e82fc0] i16 v,h,dc,p: 79% 12% 3% 6%
[libx264 @ 0x4e82fc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 71% 5% 23% 1% 0% 0% 0% 0% 0%
[libx264 @ 0x4e82fc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 51% 21% 18% 2% 2% 2% 0% 3% 0%
[libx264 @ 0x4e82fc0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x4e82fc0] ref P L0: 69.3% 9.7% 16.5% 4.6%
[libx264 @ 0x4e82fc0] ref B L0: 77.1% 20.4% 2.5%
[libx264 @ 0x4e82fc0] kb/s:41.34
[aac @ 0x4e84c40] Qavg: 3547.460
$ ./ffmpeg -v quiet -i out.mp4 -f framecrc -
#software: Lavf60.18.100
#tb 0: 1/25
#media_type 0: video
#codec_id 0: rawvideo
#dimensions 0: 320x240
#sar 0: 1/1
#tb 1: 1/44100
#media_type 1: audio
#codec_id 1: pcm_s16le
#sample_rate 1: 44100
#channel_layout_name 1: mono
0, 0, 0, 1, 230400, 0x2d184ac0
0, 1, 1, 1, 230400, 0x1a5050cd
0, 2, 2, 1, 230400, 0x1fc950bc
0, 3, 3, 1, 230400, 0x2c64516d
0, 4, 4, 1, 230400, 0xab864ea8
0, 5, 5, 1, 230400, 0x92064f96
0, 6, 6, 1, 230400, 0xc2f84f67
0, 7, 7, 1, 230400, 0x94b04fc5
0, 8, 8, 1, 230400, 0x13184f01
0, 9, 9, 1, 230400, 0x21664f02
0, 10, 10, 1, 230400, 0xe4f54ed4
0, 11, 11, 1, 230400, 0x21664f02
1, 20992, 20992, 1024, 2048, 0xc8b0ed65
0, 12, 12, 1, 230400, 0x13184f01
1, 22016, 22016, 1024, 2048, 0xf752f25f
0, 13, 13, 1, 230400, 0xc9d752f8
1, 23040, 23040, 1024, 2048, 0x23c2eeb3
1, 24064, 24064, 1024, 2048, 0x361eedf5
0, 14, 14, 1, 230400, 0xd2bd727f
1, 25088, 25088, 1024, 2048, 0xc8f102f9
1, 26112, 26112, 1024, 2048, 0xf6fff59f
0, 15, 15, 1, 230400, 0xe3e78eb2
1, 27136, 27136, 1024, 2048, 0x30eaecde
1, 28160, 28160, 1024, 2048, 0x01ccfe82
0, 16, 16, 1, 230400, 0x4fd765f1
1, 29184, 29184, 1024, 2048, 0x844e1796
0, 17, 17, 1, 230400, 0xaaea76d5
1, 30208, 30208, 1024, 2048, 0xf3f90700
1, 31232, 31232, 1024, 2048, 0x0ae9f75e
0, 18, 18, 1, 230400, 0xee33aa91
1, 32256, 32256, 1024, 2048, 0xf933ec91
1, 33280, 33280, 1024, 2048, 0x2c990129
0, 19, 19, 1, 230400, 0x509a8536
1, 34304, 34304, 1024, 2048, 0xc43f0997
0, 20, 20, 1, 230400, 0xedcf9310
1, 35328, 35328, 1024, 2048, 0xa458f5b0
1, 36352, 36352, 1024, 2048, 0xf140f703
0, 21, 21, 1, 230400, 0xa07fc062
1, 37376, 37376, 1024, 2048, 0x3683ed6b
1, 38400, 38400, 1024, 2048, 0x77630880
0, 22, 22, 1, 230400, 0x97ac9629
1, 39424, 39424, 1024, 2048, 0x9828037c

comment:2 by Gyan, 3 months ago

Resolution: fixed
Status: newclosed

Confirmed that current master is ok.

Upon bisecting, the fix is 1ea2e757f7cba714eefd27efb2f9285078bba4a3

Note: See TracTickets for help on using tickets.