(inputFile: File)
| 583 | }; |
| 584 | |
| 585 | const convertVideoFormat = async (inputFile: File): Promise<void> => { |
| 586 | try { |
| 587 | const parser = await import("@remotion/media-parser"); |
| 588 | const webcodecs = await import("@remotion/webcodecs"); |
| 589 | |
| 590 | const onProgress = ({ |
| 591 | overallProgress, |
| 592 | }: { |
| 593 | overallProgress: number | null; |
| 594 | }) => { |
| 595 | if (overallProgress !== null) { |
| 596 | setProgress(Math.min(Math.round(overallProgress * 100), 99)); |
| 597 | } |
| 598 | }; |
| 599 | |
| 600 | const controller = parser.mediaParserController |
| 601 | ? parser.mediaParserController() |
| 602 | : null; |
| 603 | parserControllerRef.current = controller; |
| 604 | |
| 605 | console.log(`Starting conversion with Remotion: ${conversionPath}`); |
| 606 | console.log( |
| 607 | `Input file: ${inputFile.name}, size: ${inputFile.size} bytes`, |
| 608 | ); |
| 609 | |
| 610 | const canUseWebCodecs = |
| 611 | typeof VideoDecoder !== "undefined" && |
| 612 | typeof AudioDecoder !== "undefined" && |
| 613 | typeof ArrayBuffer.prototype.resize === "function"; |
| 614 | |
| 615 | if (!canUseWebCodecs) { |
| 616 | throw new Error( |
| 617 | "Your browser doesn't support WebCodecs. Try using Chrome or Edge.", |
| 618 | ); |
| 619 | } |
| 620 | |
| 621 | const metadata = await parser.parseMedia({ |
| 622 | src: inputFile, |
| 623 | fields: { |
| 624 | durationInSeconds: true, |
| 625 | dimensions: true, |
| 626 | videoCodec: true, |
| 627 | }, |
| 628 | }); |
| 629 | |
| 630 | console.log("Video metadata:", metadata); |
| 631 | |
| 632 | const outputContainer = currentTargetFormat === "webm" ? "webm" : "mp4"; |
| 633 | |
| 634 | let videoCodec; |
| 635 | if (outputContainer === "webm") { |
| 636 | videoCodec = "vp8"; |
| 637 | } else { |
| 638 | videoCodec = "h264"; |
| 639 | } |
| 640 | |
| 641 | const result = await webcodecs.convertMedia({ |
| 642 | src: inputFile, |
no test coverage detected