"""
Video composition examples using FMUS-VID.
"""

import fmusvid
from pathlib import Path

def create_picture_in_picture():
    """Create picture-in-picture effect."""
    # Memuat video utama dan overlay
    main = fmusvid.load("main.mp4")
    overlay = fmusvid.load("overlay.mp4")

    # Menyiapkan overlay
    overlay = (overlay
        .resize(width=480)            # Ukuran untuk PiP
        .volume(0.3)                  # Volume overlay 30%
    )

    # Membuat komposisi
    result = (main
        .overlay(
            overlay,
            position=(50, 50),        # Posisi dari kiri atas
            start=5.0,                # Mulai pada detik ke-5
            duration=10.0,            # Durasi overlay 10 detik
            fade_in=1.0,              # Fade in 1 detik
            fade_out=1.0              # Fade out 1 detik
        )
    )

    result.save("pip_output.mp4")

def create_video_grid():
    """Create video grid layout."""
    # Memuat video
    videos = [
        fmusvid.load(f"clip{i}.mp4")
        for i in range(1, 5)
    ]

    # Menyeragamkan ukuran
    videos = [
        video.resize(width=640, height=360)
        for video in videos
    ]

    # Membuat grid 2x2
    grid = fmusvid.grid(
        videos,
        rows=2,
        cols=2,
        padding=10,                   # Padding antar video
        background_color=(0, 0, 0)    # Background hitam
    )

    grid.save("grid_output.mp4")

def create_transitions():
    """Create video transitions."""
    clips = [
        fmusvid.load(f"clip{i}.mp4")
        for i in range(1, 4)
    ]

    # Membuat transisi
    transitions = []
    for i in range(len(clips) - 1):
        transitions.append(clips[i])
        transitions.append(
            fmusvid.transition.fade(
                clips[i],
                clips[i + 1],
                duration=1.0          # Durasi transisi 1 detik
            )
        )
    transitions.append(clips[-1])

    # Menggabungkan semua
    result = fmusvid.concat(transitions)
    result.save("transitions_output.mp4")

def create_split_screen():
    """Create split screen effect."""
    left = fmusvid.load("left.mp4")
    right = fmusvid.load("right.mp4")

    # Menyiapkan kedua video
    left = left.resize(width=960)     # Setengah 1920
    right = right.resize(width=960)

    # Membuat split screen
    result = fmusvid.compose(
        [
            (left, (0, 0)),           # Posisi kiri
            (right, (960, 0))         # Posisi kanan
        ],
        width=1920,
        height=1080
    )

    result.save("split_screen.mp4")
