admin管理员组

文章数量:1393064

this is the code that i used. this code create a minifest.mpd file, with the same resolution AdaptationSet set

const createCourse = async (req: Request, res: Response, next: NextFunction) => {
    try {
        const VIDEO_STORAGE_PATH = path.join(__dirname, "../../public/uploads").replace(/\\/g, "/");
        const videoId = req.body.videoId;
        const inputPath = path.join(VIDEO_STORAGE_PATH, "original", `${videoId}.mp4`).replace(/\\/g, "/");
        const outputDir = path.join(VIDEO_STORAGE_PATH, "dash", videoId).replace(/\\/g, "/");

        if (!fs.existsSync(outputDir)) {
            fs.mkdirSync(outputDir, { recursive: true });
        }

        if (!ffmpegStatic) {
            return next(new Error("❌ ffmpegStatic path is null"));
        }

        ffmpeg.setFfmpegPath(ffmpegStatic);

        const qualities = [
            { resolution: "1280x720", bitrate: "1800k" },
            { resolution: "854x480", bitrate: "1200k" },
            { resolution: "640x360", bitrate: "800k" },
            { resolution: "426x240", bitrate: "400k" }
        ];

        const outputMpd = path.join(outputDir, "manifest.mpd").replace(/\\/g, "/");

        // Create FFmpeg command
        let command = ffmpeg(inputPath)
            .output(outputMpd)
            .outputOptions([
                '-f dash', // Output format
                '-seg_duration 4', // Segment duration in seconds
                '-window_size 10', // Number of segments in the manifest
                '-init_seg_name init-stream$RepresentationID$.webm', // Name for initialization segments
                '-media_seg_name chunk-stream$RepresentationID$-$Number%05d$.webm', // Name for media segments
            ]);

        // Add multiple resolutions
        qualities.forEach(({ resolution, bitrate }) => {
            console.log('esolution, bitrate :>> ', resolution, bitrate);
            command
                .outputOptions([
                    `-map 0:v`, // Map the video stream
                    `-s ${resolution}`, // Set resolution
                    `-b:v ${bitrate}`, // Set bitrate
                    `-c:v libvpx-vp9`, // Use VP9 codec
                    `-c:a libopus`, // Use Opus codec
                ]);
        });

        command
            .on("end", () => {
                console.log(`

本文标签: expresswhy mpd file contain same resolution AdaptationSetStack Overflow