@@ -508,7 +508,8 @@ export const properties = {
508508 "ast" ,
509509 "au" ,
510510 "aud" ,
511- "av1" ,
511+ "av1.mkv" ,
512+ "av1.mp4" ,
512513 "avi" ,
513514 "avif" ,
514515 "avs" ,
@@ -546,9 +547,11 @@ export const properties = {
546547 "gxf" ,
547548 "h261" ,
548549 "h263" ,
549- "h264" ,
550- "h265" ,
551- "h266" ,
550+ "h264.mkv" ,
551+ "h264.mp4" ,
552+ "h265.mkv" ,
553+ "h265.mp4" ,
554+ "h266.mkv" ,
552555 "hdr" ,
553556 "hevc" ,
554557 "ico" ,
@@ -696,36 +699,58 @@ export async function convert(
696699
697700 if ( convertTo === "ico" ) {
698701 // make sure image is 256x256 or smaller
699- extraArgs = [ '-filter:v' , "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease" ] ;
702+ extraArgs = [
703+ "-filter:v" ,
704+ "scale='min(256,iw)':min'(256,ih)':force_original_aspect_ratio=decrease" ,
705+ ] ;
700706 message = "Done: resized to 256x256" ;
701707 }
702708
709+ if ( convertTo . split ( "." ) . length > 1 ) {
710+ // support av1.mkv and av1.mp4 and h265.mp4 etc.
711+ const split = convertTo . split ( "." ) ;
712+ const codec_short = split [ 0 ] ;
713+
714+ switch ( codec_short ) {
715+ case "av1" :
716+ extraArgs . push ( "-c:v" , "libaom-av1" ) ;
717+ break ;
718+ case "h264" :
719+ extraArgs . push ( "-c:v" , "libx264" ) ;
720+ break ;
721+ case "h265" :
722+ extraArgs . push ( "-c:v" , "libx265" ) ;
723+ break ;
724+ case "h266" :
725+ extraArgs . push ( "-c:v" , "libx266" ) ;
726+ break ;
727+ }
728+ }
729+
703730 // Parse FFMPEG_ARGS environment variable into array
704- const ffmpegArgs = process . env . FFMPEG_ARGS ? process . env . FFMPEG_ARGS . split ( / \s + / ) : [ ] ;
705-
706- // Build arguments array
707- const args = [
708- ...ffmpegArgs ,
709- "-i" , filePath ,
710- ...extraArgs ,
711- targetPath
712- ] ;
731+ const ffmpegArgs = process . env . FFMPEG_ARGS
732+ ? process . env . FFMPEG_ARGS . split ( / \s + / )
733+ : [ ] ;
713734
714735 return new Promise ( ( resolve , reject ) => {
715- execFile ( "ffmpeg" , args , ( error , stdout , stderr ) => {
716- if ( error ) {
717- reject ( `error: ${ error } ` ) ;
718- }
736+ execFile (
737+ "ffmpeg" ,
738+ [ ...ffmpegArgs , "-i" , filePath , ...extraArgs , targetPath ] ,
739+ ( error , stdout , stderr ) => {
740+ if ( error ) {
741+ reject ( `error: ${ error } ` ) ;
742+ }
719743
720- if ( stdout ) {
721- console . log ( `stdout: ${ stdout } ` ) ;
722- }
744+ if ( stdout ) {
745+ console . log ( `stdout: ${ stdout } ` ) ;
746+ }
723747
724- if ( stderr ) {
725- console . error ( `stderr: ${ stderr } ` ) ;
726- }
748+ if ( stderr ) {
749+ console . error ( `stderr: ${ stderr } ` ) ;
750+ }
727751
728- resolve ( message ) ;
729- } ) ;
752+ resolve ( message ) ;
753+ } ,
754+ ) ;
730755 } ) ;
731756}
0 commit comments