CREATE TABLE IF NOT EXISTS video_formats (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    postfix VARCHAR(50) NOT NULL,
    width INT UNSIGNED NOT NULL DEFAULT 0,
    height INT UNSIGNED NOT NULL DEFAULT 0,
    keep_aspect TINYINT(1) NOT NULL DEFAULT 1,
    ffmpeg_options TEXT NOT NULL,
    is_active TINYINT(1) NOT NULL DEFAULT 1,
    is_source TINYINT(1) NOT NULL DEFAULT 0,
    sort_order INT UNSIGNED NOT NULL DEFAULT 0,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_active (is_active, sort_order)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT IGNORE INTO video_formats (id, name, postfix, width, height, ffmpeg_options, is_active, is_source, sort_order) VALUES
(1, 'MP4 720p', '_720p.mp4', 1280, 720, '-vcodec libx264 -movflags +faststart -crf 23 -preset medium -acodec aac -ar 44100 -ab 128k -f mp4', 1, 0, 1),
(2, 'MP4 480p', '_480p.mp4', 854, 480, '-vcodec libx264 -movflags +faststart -crf 25 -preset medium -acodec aac -ar 44100 -ab 96k -f mp4', 1, 0, 2),
(3, 'MP4 360p', '_360p.mp4', 640, 360, '-vcodec libx264 -movflags +faststart -crf 28 -preset fast -acodec aac -ar 44100 -ab 64k -f mp4', 0, 0, 3);
