why getting black screen here and not showing any transtion but playing next segment if we switch parameters ? our goal is to rencode transitions only due to our limited ressources :
    list_file_path = os.path.join(temp_dir, "concat_list.txt")
    valid_segments = []

    print(f"Preparing to concatenate {len(segments)} segments:")

    # Build the list file for FFmpeg concat-demuxer
    with open(list_file_path, "w", encoding="utf-8") as f:
        for i, seg_path_str in enumerate(segments):
            dur = get_media_duration(seg_path_str)
            if os.path.exists(seg_path_str) and dur is not None and dur >= 0.1:
                vinfo = get_video_codec_info(seg_path_str)
                if vinfo and vinfo.get("width", 0) > 0:
                    escaped = str(Path(seg_path_str).resolve()).replace("'", "'\\''")
                    f.write(f"file '{escaped}'\n")
                    valid_segments.append(seg_path_str)
                    print(f"✓ Segment {i}: {Path(seg_path_str).name} ({dur:.2f}s, codec={vinfo.get('codec')})")
                else:
                    print(f"⚠️ Segment {i}: invalid video – skipping")
            else:
                print(f"⚠️ Segment {i}: missing or too short – skipping")

    if not valid_segments:
        print("❌ No valid segments to concatenate.")
        return False

    print(f"Attempting FFmpeg stream-copy concat ({len(valid_segments)} segments)…")
    cmd_copy = [
        FFMPEG_BIN, "-y", "-f", "concat", "-safe", "0",
        "-i", list_file_path, "-c", "copy", "-movflags", "+faststart",
        output_path
    ]
    if run_ffmpeg_command(cmd_copy, f"FFmpeg concat with copy"):
        # verify
        odur = get_media_duration(output_path)
        if odur and odur > 0:
            print(f"✅ FFmpeg concat succeeded ({odur:.2f}s)")
            return True
        else:
            print("⚠️ FFmpeg concat output invalid, falling back to MP4Box")

    else:
        print("⚠️ FFmpeg concat failed, falling back to MP4Box")

    # --- MP4Box concat (always use -cat) ---
    mp4box_path = shutil.which("MP4Box")
    if mp4box_path:
        print(f"🔄 Using MP4Box at {mp4box_path}")
        cmd = [mp4box_path]
        for seg in valid_segments:
            cmd += ["-cat", seg]
        cmd += [output_path]

        print(f"Running MP4Box command: {' '.join(cmd)}")
        result = subprocess.run(cmd, capture_output=True, text=True)
        if result.returncode == 0 and os.path.exists(output_path) and get_media_duration(output_path):
            print("✅ MP4Box concat succeeded")
            return True
        else:
            print(f"❌ MP4Box concat error ({result.returncode}): {result.stderr.strip()}")
    else:
        print("⚠️ MP4Box not found on PATH")

    # --- Final fallback: segment-by-segment filter concat ---
    print("🔄 Falling back to FFmpeg filter_complex concat…")
    intermediate = valid_segments[0]
    for idx, seg in enumerate(valid_segments[1:], start=1):
        next_out = os.path.join(temp_dir, f"intermediate_{idx}.mp4")
        cmd_fc = [
            FFMPEG_BIN, "-y",
            "-i", intermediate,
            "-i", seg,
            "-filter_complex", "[0:v][1:v]concat=n=2:v=1:a=1[outv][outa]",
            "-map", "[outv]", "-map", "[outa]",
            "-c:v", "libx264", "-preset", "ultrafast", "-crf", "23",
            "-pix_fmt", "yuv420p",
            "-c:a", "aac", "-b:a", "128k",
            "-movflags", "+faststart",
            next_out
        ]
        if not run_ffmpeg_command(cmd_fc, f"Filter-complex concat part {idx}"):
            print(f"❌ Filter concat failed at segment {idx}")
            return False
        intermediate = next_out

    # move final intermediate to output
    shutil.copy2(intermediate, output_path)
    odur = get_media_duration(output_path)
    if odur:
        print(f"✅ Filter-complex concat succeeded ({odur:.2f}s)")
        return True

    print("❌ All concat methods failed")
    return False