@@ -599,61 +599,3 @@ export async function ffmpegConcatVideos(videos: string[]): Promise<string> {
599599 } ) ;
600600 return output ;
601601}
602-
603- export const ffmpegVideoNormal = async ( input : string , option : {
604- widthMax ?: number ;
605- heightMax ?: number ;
606- fps ?: number ;
607- durationMax ?: number ;
608- } ) : Promise < string > => {
609- option = Object . assign ( {
610- widthMax : 1920 ,
611- heightMax : 1920 ,
612- fps : 25 ,
613- durationMax : - 1 ,
614- } ) ;
615- const ext = await $mapi . file . ext ( input ) ;
616- const output = await $mapi . file . temp ( ext ) ;
617- const { width, height, duration, fps} = await ffprobeVideoInfo ( input ) ;
618- let scaleFilter = "" ;
619- let targetWidth = width ;
620- let targetHeight = height ;
621- let targetFps = fps ;
622- if ( option . widthMax && width > option . widthMax ) {
623- targetWidth = option . widthMax ;
624- targetHeight = Math . round ( ( option . widthMax / width ) * height ) ;
625- }
626- if ( option . heightMax && targetHeight > option . heightMax ) {
627- targetHeight = option . heightMax ;
628- targetWidth = Math . round ( ( option . heightMax / height ) * targetWidth ) ;
629- }
630- if ( targetWidth !== width || targetHeight !== height ) {
631- scaleFilter = `scale=${ targetWidth } :${ targetHeight } ` ;
632- }
633- if ( option . fps && fps > option . fps ) {
634- targetFps = option . fps ;
635- scaleFilter += ( scaleFilter ? "," : "" ) + `fps=${ targetFps } ` ;
636- }
637- if ( option . durationMax && option . durationMax > 0 && duration > option . durationMax ) {
638- scaleFilter += ( scaleFilter ? "," : "" ) + `trim=duration=${ option . durationMax } ,setpts=PTS-STARTPTS` ;
639- }
640- const args = [
641- "-i" ,
642- input ,
643- "-vf" ,
644- scaleFilter || "null" ,
645- "-r" ,
646- targetFps . toString ( ) ,
647- "-preset" ,
648- "fast" ,
649- "-y" ,
650- output ,
651- ] ;
652- // console.log("FFmpeg videoNormal args:", args.join(" "));
653- await $mapi . app . spawnBinary ( "ffmpeg" , args ) ;
654- if ( ! ( await $mapi . file . exists ( output ) ) ) {
655- throw "视频处理失败,请检查视频文件是否存在或ffmpeg是否正常工作" ;
656- }
657- return output ;
658- }
659-
0 commit comments