I am leveraging ffmpeg (specifically the python-ffmpeg lib) to take two mp4 inputs, partially overlay them using xstack and output the combined mp4. This is mostly working but I consistently am getting the undesired effect of the overlapping cross-section flickering back and forth between the two inputs.
I first thought this might be happening because the inputs have different bitrate values. I tried to force the bitrates of the individual inputs to be as close as possible using b:v, minrate, maxrate, and bufsize. I have been unable to get identical bitrates this way but got them very close but it did not affect my flickering symptoms.
Does anyone have any suggestions for preventing this flickering side-effect for overlapping inputs?
ffmpeg -f mp4 -rtbufsize 50M -thread_queue_size 512 -i /shared-storage/video/2/2.mp4 -f mp4 -rtbufsize 50M -thread_queue_size 512 -i /shared-storage/video/2/1.mp4 -filter_complex "[0][1]xstack=fill=#171f29:inputs=2:layout=628_172|26_26[s0];[s0]scale=1920:-2[s1];[s1]yadif[s2]" -map "[s2]" -b:v 1200k -bufsize 1200k -c:v libx264 -color_primaries 1 -color_trc iec61966_2_1 -colorspace 1 -maxrate 1200k -minrate 1200k -pix_fmt yuv420p -threads auto -x264opts "keyint_min=1:keyint=1" /shared-storage/video/2/Untitled.mp4 -report -y
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7686e80] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7686e80] After avformat_find_stream_info() pos: 136186 bytes read:169955 seeks:2 frames:1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/shared-storage/video/2/2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.16.100
Duration: 00:00:54.00, start: 0.000000, bitrate: 1084 kb/s
Stream #0:0[0x1](und), 1, 1/16384: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/iec61966-2-1, progressive), 864x788, 1084 kb/s, 1 fps, 1 tbr, 16384 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Successfully opened the file.
Parsing a group of options: input url /shared-storage/video/2/1.mp4.
Applying option f (force format) with argument mp4.
Applying option thread_queue_size (set the maximum number of queued packets from the demuxer) with argument 512.
Successfully parsed a group of options.
Opening an input file: /shared-storage/video/2/1.mp4.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] Opening '/shared-storage/video/2/1.mp4' for reading
[file @ 0x76ffc80] Setting default whitelist 'file,crypto,data'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] Processing st: 0, edit list 0 - media time: 0, duration: 884736
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] Before avformat_find_stream_info() pos: 7261674 bytes read:33817 seeks:1 nb_streams:1
[h264 @ 0x76af480] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x76af480] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x76af480] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x76af480] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x76af480] nal_unit_type: 6(SEI), nal_ref_idc: 0
[h264 @ 0x76af480] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x76af480] Format yuv420p chosen by get_format().
[h264 @ 0x76af480] Reinit context to 864x800, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7694940] After avformat_find_stream_info() pos: 134991 bytes read:168760 seeks:2 frames:1
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/shared-storage/video/2/1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.16.100
Duration: 00:00:54.00, start: 0.000000, bitrate: 1075 kb/s
Stream #1:0[0x1](und), 1, 1/16384: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/iec61966-2-1, progressive), 864x788, 1075 kb/s, 1 fps, 1 tbr, 16384 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Successfully opened the file.
[Parsed_xstack_0 @ 0x76fec40] Setting 'fill' to value '#171f29'
[Parsed_xstack_0 @ 0x76fec40] Setting 'inputs' to value '2'
[Parsed_xstack_0 @ 0x76fec40] Setting 'layout' to value '628_172|26_26'
[Parsed_scale_1 @ 0x76a3100] Setting 'w' to value '1920'
[Parsed_scale_1 @ 0x76a3100] Setting 'h' to value '-2'
[Parsed_scale_1 @ 0x76a3100] w:1920 h:-2 flags:'' interl:0
Parsing a group of options: output url /shared-storage/video/2/Untitled.mp4.
Applying option map (set input stream mapping) with argument [s2].
Applying option b:v (video bitrate (please use -b:v)) with argument 1200k.
Applying option c:v (codec name) with argument libx264.
Applying option pix_fmt (set pixel format) with argument yuv420p.
Successfully parsed a group of options.