#8843 closed defect (fixed)

concat Segmentation fault filter_complex

Reported by: Dirk Vanbeveren Owned by: Dirk Vanbeveren
Priority: important Component: avfilter
Version: git-master Keywords: crash concat amix
Cc: vanbeverendirk@hotmail.com Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
I get a segmentation fault when I combine 3 generated sequences created with 2 files.

Basically sequence 0 contains vid1.mp4 overlayed on a color background 500x500.
Sequence 1 contains a trim of vid1 and vid2 on top of eachother.
Sequence 2 is a part of vid2.

When I concat the 3 sequences in one complex filter I get a segmentation fault.
Although if I concat seq0 and seq1 only I get no error. When I encode seq0 and seq1 to a file and concat that file with seq2 it also poses no problem.

Encoding 3 sequences seperately, then concat the 3 files there is also no error.

How to reproduce:
(code): basically the 3 blocks that start with 'color' represent the 3 sequences with outputs [Seq{sequence#}_out_{v/a}].
Then combined with concat.

ffmpeg -i "vid1.mp4" -i "vid2.mp4" -filter_complex "\

color=s=500x500[Seq0_bg];\
[0:v]trim=0:5,setpts=PTS-STARTPTS[Seq0_0];\
[Seq0_0]scale=w='if(gt(iw/ih,500/(500)),500,-2)':h='if(gt(iw/ih,500/(500)),-2,500)':eval=init[Seq0_0_v];\
[Seq0_bg][Seq0_0_v]overlay=x='(W-w)/2':y='(H-h)/2':eval=init:shortest=1[Seq0_out_v];\
[0:a]atrim=0:5,asetpts=PTS-STARTPTS[Seq0_out_a];\

color=s=500x500[Seq1_bg];\
[0:v]trim=5:10.022,setpts=PTS-STARTPTS[Seq1_0];\
[Seq1_0]scale=w='if(gt(iw/ih,500/(250)),500,-2)':h='if(gt(iw/ih,500/(250)),-2,250)':eval=init[Seq1_0_v];\
[1:v]trim=0:5.022,setpts=PTS-STARTPTS[Seq1_1];\
[Seq1_1]scale=w='if(gt(iw/ih,500/(250)),500,-2)':h='if(gt(iw/ih,500/(250)),-2,250)':eval=init[Seq1_1_v];\
[Seq1_bg][Seq1_0_v]overlay=x='(500-w)/2+0':y='(250-h)/2+0':eval=init:shortest=1[Seq1_overlay_0];\
[Seq1_overlay_0][Seq1_1_v]overlay=x='(500-w)/2+0':y='(250-h)/2+250':eval=init[Seq1_out_v];\
[0:a]atrim=5:10.022,asetpts=PTS-STARTPTS[Seq1_0_a];\
[1:a]atrim=0:5.022,asetpts=PTS-STARTPTS[Seq1_1_a];\
[Seq1_0_a][Seq1_1_a]amix=inputs=2[Seq1_out_a];\

color=s=500x500[Seq2_bg];\
[1:v]trim=5.022:10.024,setpts=PTS-STARTPTS[Seq2_1];\
[Seq2_1]scale=w='if(gt(iw/ih,500/(500)),500,-2)':h='if(gt(iw/ih,500/(500)),-2,500)':eval=init[Seq2_1_v];\
[Seq2_bg][Seq2_1_v]overlay=x='(W-w)/2':y='(H-h)/2':eval=init:shortest=1[Seq2_out_v];\
[1:a]atrim=5.022:10.024,asetpts=PTS-STARTPTS[Seq2_out_a];\

[Seq0_out_v][Seq0_out_a][Seq1_out_v][Seq1_out_a][Seq2_out_v][Seq2_out_a]concat=n=3:v=1:a=1[vid][aud]" \
-map [vid] -map [aud] -y "out.mp4";

ffmpeg version

ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
configuration: --prefix=/usr --extra-version=1ubuntu0.1 --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-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

I attached the logs and the video files. Length of videos are 10s.

Attachments (5)

output.txt (675.4 KB ) - added by Dirk Vanbeveren 15 months ago.
output logs of command run
vid1.mp4 (2.0 MB ) - added by Dirk Vanbeveren 15 months ago.
first video
vid2.mp4 (2.5 MB ) - added by Dirk Vanbeveren 15 months ago.
second video
ffmpeg-20200809-031443.log (635.0 KB ) - added by Dirk Vanbeveren 15 months ago.
ffmpeg output log file
output.19388 (532.9 KB ) - added by Dirk Vanbeveren 15 months ago.
gcore register dump

Change History (22)

by Dirk Vanbeveren, 15 months ago

Attachment: output.txt added

output logs of command run

by Dirk Vanbeveren, 15 months ago

Attachment: vid1.mp4 added

first video

by Dirk Vanbeveren, 15 months ago

Attachment: vid2.mp4 added

second video

comment:1 by Dirk Vanbeveren, 15 months ago

Owner: set to Dirk Vanbeveren
Status: newopen

comment:2 by Dirk Vanbeveren, 15 months ago

Cc: vanbeverendirk@hotmail.com added

..

Last edited 15 months ago by Dirk Vanbeveren (previous) (diff)

comment:3 by Dirk Vanbeveren, 15 months ago

Cc: vanbeverendirk@hotmail.com removed

comment:4 by Dirk Vanbeveren, 15 months ago

Cc: vanbeverendirk@hotmail.com added

comment:5 by Carl Eugen Hoyos, 15 months ago

Component: ffmpegundetermined
Keywords: crash added; segmentation fault removed
Reproduced by developer: unset
Version: 4.2unspecified

Please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output, backtrace, disassembly and register dump to make this a valid ticket.

comment:6 by Dirk Vanbeveren, 15 months ago

Summary: concat Segmentation fault filter_complexconcat Segmentation fault of 3 sources

in reply to:  5 comment:7 by Dirk Vanbeveren, 15 months ago

Replying to cehoyos:

Please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output, backtrace, disassembly and register dump to make this a valid ticket.

So basically, install from git head, then run code with '-report' and '-loglevel 99' and put those outputs in a file.
then using "gcore -o filename PID" for the register dump.
Is this right?
And what should I do for the disassembly?

Last edited 15 months ago by Dirk Vanbeveren (previous) (diff)

comment:8 by Dirk Vanbeveren, 15 months ago

Summary: concat Segmentation fault of 3 sourcesconcat Segmentation fault filter_complex

by Dirk Vanbeveren, 15 months ago

Attachment: ffmpeg-20200809-031443.log added

ffmpeg output log file

by Dirk Vanbeveren, 15 months ago

Attachment: output.19388 added

gcore register dump

in reply to:  5 comment:9 by Dirk Vanbeveren, 15 months ago

Replying to cehoyos:

Please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output, backtrace, disassembly and register dump to make this a valid ticket.

I installed latest ffmpeg from git.
Ran the ffmpeg command with '-loglevel 99 -report' and put the output report as attachment.
ran "gcore -o output [PID]" on process creation and put the output file as attachment.

comment:10 by Dirk Vanbeveren, 15 months ago

Version: unspecifiedgit-master

comment:11 by Nicolas George, 15 months ago

Simplified command-line:

./ffmpeg_g -loglevel verbose -i /tmp/vid1.mp4 -filter_complex "
testsrc2=s=16x16:r=25:d=0.062 [v1] ;
testsrc2=s=16x16:r=24:d=0.040 [v2] ;
anullsrc , atrim=0:0.062 [a2] ;
anullsrc , atrim=0:0.040 [a3] ;
[0:a]atrim=9.960:10.022 , asetpts=PTS-STARTPTS[a1] ;
[a1][a2]amix=inputs=2[Seq1_out_a] ;
[v1][Seq1_out_a][v2][a3]concat=n=2:v=1:a=1[vid][aud]" -map "[vid]" -map "[aud]
" -f null -

Removing input from the file or amix make the bug disappear.

in reply to:  11 comment:12 by Dirk Vanbeveren, 15 months ago

Replying to Cigaes:

Simplified command-line:

./ffmpeg_g -loglevel verbose -i /tmp/vid1.mp4 -filter_complex "
testsrc2=s=16x16:r=25:d=0.062 [v1] ;
testsrc2=s=16x16:r=24:d=0.040 [v2] ;
anullsrc , atrim=0:0.062 [a2] ;
anullsrc , atrim=0:0.040 [a3] ;
[0:a]atrim=9.960:10.022 , asetpts=PTS-STARTPTS[a1] ;
[a1][a2]amix=inputs=2[Seq1_out_a] ;
[v1][Seq1_out_a][v2][a3]concat=n=2:v=1:a=1[vid][aud]" -map "[vid]" -map "[aud]
" -f null -

Removing input from the file or amix make the bug disappear.

Just combining 2 of the streams poses no problem. But combining the 3 does.
This command works flawlessly:

ffmpeg -i vid1.mp4 -i vid2.mp4 -filter_complex "\

color=s=500x500[Seq0_bg];\
[0:v]trim=0:5,setpts=PTS-STARTPTS, scale=w=500:h=500:eval=init[Seq0_0_v];\
[Seq0_bg][Seq0_0_v]overlay=x=0:y=0:eval=init:shortest=1[Seq0_out_v];\
[0:a]atrim=0:5,asetpts=PTS-STARTPTS[Seq0_out_a];\

color=s=500x500[Seq1_bg];\
[0:v]trim=5:10.022,setpts=PTS-STARTPTS,scale=w=500:h=250:eval=init[Seq1_0_v];\
[1:v]trim=0:5.022,setpts=PTS-STARTPTS,scale=w=500:h=250:eval=init[Seq1_1_v];\
[Seq1_bg][Seq1_0_v]overlay=x=0:y=0:eval=init:shortest=1[Seq1_overlay_0];\
[Seq1_overlay_0][Seq1_1_v]overlay=x=0:y=250[Seq1_out_v];\
[0:a]atrim=5:10.022,asetpts=PTS-STARTPTS[Seq1_0_a];\
[1:a]atrim=0:5.022,asetpts=PTS-STARTPTS[Seq1_1_a];\
[Seq1_0_a][Seq1_1_a]amix=inputs=2[Seq1_out_a];\

[Seq0_out_v][Seq0_out_a][Seq1_out_v][Seq1_out_a]concat=n=2:v=1:a=1[vid][aud]" \
-map [vid] -map [aud] -y out.mp4

comment:13 by Nicolas George, 15 months ago

Component: undeterminedavfilter
Keywords: amix added; concat removed

I very much confirm the command-line I gave reproduces the problem with only two segments.

The problem seems to be in the amix filter: it sends the last frame without a timestamp. The following patch protects concat from it and prevents the segfault, resulting in an error with a message instead.

https://ffmpeg.org/pipermail/ffmpeg-devel/2020-August/267563.html

For a proper fix, amix needs to be investigated.

I suggest trying to use amerge and pan instead.

in reply to:  13 comment:14 by Dirk Vanbeveren, 15 months ago

Replying to Cigaes:

I very much confirm the command-line I gave reproduces the problem with only two segments.

The problem seems to be in the amix filter: it sends the last frame without a timestamp. The following patch protects concat from it and prevents the segfault, resulting in an error with a message instead.

https://ffmpeg.org/pipermail/ffmpeg-devel/2020-August/267563.html

For a proper fix, amix needs to be investigated.

I suggest trying to use amerge and pan instead.

Sorry, I thought you said your code did work. Indeed your code also caused the segmentation fault as I ran it.

Thank you for the suggestion. I'm going to try to implement amix with amerge and pan like you said; for now at least. Hopefully it works. :)

comment:15 by Carl Eugen Hoyos, 15 months ago

Keywords: concat added
Priority: normalimportant

The posted patch seems to indicate that there is a crash in the concat filter...

in reply to:  15 comment:16 by Dirk Vanbeveren, 15 months ago

Replying to cehoyos:

The posted patch seems to indicate that there is a crash in the concat filter...

Yes indeed. In the end concat should be able to handle the the exception and amix should fix its output.

comment:17 by Elon Musk, 13 months ago

Resolution: fixed
Status: openclosed

Fixed in 17b44f759e8cbb6952c0ae2 and 05c8d0bce64888c531282

Note: See TracTickets for help on using tickets.