2026-01-20 00:25:55 +03:00
#!/usr/bin/env node
2026-01-22 16:34:26 +03:00
import { createRequire as rF } from "node:module" ; var nF = Object . create ; var { getPrototypeOf : sF , defineProperty : Uu , getOwnPropertyNames : aF } = Object ; var iF = Object . prototype . hasOwnProperty ; var UD = ( D , u , F ) => { F = D != null ? nF ( sF ( D ) ) : { } ; let E = u || ! D || ! D . _ _esModule ? Uu ( F , "default" , { value : D , enumerable : ! 0 } ) : F ; for ( let C of aF ( D ) ) if ( ! iF . call ( E , C ) ) Uu ( E , C , { get : ( ) => D [ C ] , enumerable : ! 0 } ) ; return E } ; var H = ( D , u ) => ( ) => ( u || D ( ( u = { exports : { } } ) . exports , u ) , u . exports ) ; var a = rF ( import . meta . url ) ; var bu = H ( ( B2 , Su ) => { class yu { constructor ( D , u , F ) { this . etaBufferLength = D || 100 , this . valueBuffer = [ F ] , this . timeBuffer = [ u ] , this . eta = "0" } update ( D , u , F ) { this . valueBuffer . push ( u ) , this . timeBuffer . push ( D ) , this . calculate ( F - u ) } getTime ( ) { return this . eta } calculate ( D ) { let u = this . valueBuffer . length , F = Math . min ( this . etaBufferLength , u ) , E = this . valueBuffer [ u - 1 ] - this . valueBuffer [ u - F ] , C = this . timeBuffer [ u - 1 ] - this . timeBuffer [ u - F ] , B = E / C ; this . valueBuffer = this . valueBuffer . slice ( - this . etaBufferLength ) , this . timeBuffer = this . timeBuffer . slice ( - this . etaBufferLength ) ; let A = Math . ceil ( D / B / 1000 ) ; if ( isNaN ( A ) ) this . eta = "NULL" ; else if ( ! isFinite ( A ) ) this . eta = "INF" ; else if ( A > 1e7 ) this . eta = "INF" ; else if ( A < 0 ) this . eta = 0 ; else this . eta = A } } Su . exports = yu } ) ; var cD = H ( ( A2 , Pu ) => { var n = a ( "readline" ) ; class vu { constructor ( D ) { this . stream = D , this . linewrap = ! 0 , this . dy = 0 } cursorSave ( ) { if ( ! this . stream . isTTY ) return ; this . stream . write ( "\x1B7" ) } cursorRestore ( ) { if ( ! this . stream . isTTY ) return ; this . stream . write ( "\x1B8" ) } cursor ( D ) { if ( ! this . stream . isTTY ) return ; if ( D ) this . stream . write ( "\x1B[?25h" ) ; else this . stream . write ( "\x1B[?25l" ) } cursorTo ( D = null , u = null ) { if ( ! this . stream . isTTY ) return ; n . cursorTo ( this . stream , D , u ) } cursorRelative ( D = null , u = null ) { if ( ! this . stream . isTTY ) return ; this . dy = this . dy + u , n . moveCursor ( this . stream , D , u ) } cursorRelativeReset ( ) { if ( ! this . stream . isTTY ) return ; n . moveCursor ( this . stream , 0 , - this . dy ) , n . cursorTo ( this . stream , 0 , null ) , this . dy = 0 } clearRight ( ) { if ( ! this . stream . isTTY ) return ; n . clearLine ( this . stream , 1 ) } clearLine ( ) { if ( ! this . stream . isTTY ) return ; n . clearLine ( this . stream , 0 ) } clearBottom ( ) { if ( ! this . stream . isTTY ) return ; n . clearScreenDown ( this . stream ) } newline ( ) { this . stream . write ( `
` ),this.dy++}write(D,u=!1){if(this.linewrap===!0&&u===!1)this.stream.write(D.substr(0,this.getWidth()));else this.stream.write(D)}lineWrapping(D){if(!this.stream.isTTY)return;if(this.linewrap=D,D)this.stream.write(" \x 1B[?7h");else this.stream.write(" \x 1B[?7l")}isTTY(){return this.stream.isTTY===!0}getWidth(){return this.stream.columns||(this.stream.isTTY?80:200)}}Pu.exports=vu});var fu=H((Z2,hu)=>{hu.exports=({onlyFirst:D=!1}={})=>{let u=["[ \\ u001B \\ u009B][[ \\ ]()#;?]*(?:(?:(?:(?:;[-a-zA-Z \\ d \\ /#&.:=?%@~_]+)*|[a-zA-Z \\ d]+(?:;[-a-zA-Z \\ d \\ /#&.:=?%@~_]*)*)? \\ u0007)","(?:(?: \\ d{1,4}(?:; \\ d{0,4})*)?[ \\ dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(u,D?void 0:"g")}});var mu=H(( $ 2,gu)=>{var N8=fu();gu.exports=(D)=>typeof D==="string"?D.replace(N8(),""):D});var lu=H((J2,lD)=>{var cu=(D)=>{if(Number.isNaN(D))return!1;if(D>=4352&&(D<=4447||D===9001||D===9002||11904<=D&&D<=12871&&D!==12351||12880<=D&&D<=19903||19968<=D&&D<=42182||43360<=D&&D<=43388||44032<=D&&D<=55203||63744<=D&&D<=64255||65040<=D&&D<=65049||65072<=D&&D<=65131||65281<=D&&D<=65376||65504<=D&&D<=65510||110592<=D&&D<=110593||127488<=D&&D<=127569||131072<=D&&D<=262141))return!0;return!1};lD.exports=cu;lD.exports.default=cu});var du=H((K2,pu)=>{pu.exports=function(){return/ \u D83C \u DFF4 \u DB40 \u DC67 \u DB40 \u DC62(?: \u DB40 \u DC65 \u DB40 \u DC6E \u DB40 \u DC67| \u DB40 \u DC73 \u DB40 \u DC63 \u DB40 \u DC74| \u DB40 \u DC77 \u DB40 \u DC6C \u DB40 \u DC73) \u DB40 \u DC7F| \u D83D \u DC68(?: \u D83C \u DFFC \u 200D(?: \u D83E \u DD1D \u 200D \u D83D \u DC68 \u D83C \u DFFB| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])| \u D83C \u DFFF \u 200D(?: \u D83E \u DD1D \u 200D \u D83D \u DC68(?: \u D83C[ \u DFFB- \u DFFE])| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])| \u D83C \u DFFE \u 200D(?: \u D83E \u DD1D \u 200D \u D83D \u DC68(?: \u D83C[ \u DFFB- \u DFFD])| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])| \u D83C \u DFFD \u 200D(?: \u D83E \u DD1D \u 200D \u D83D \u DC68(?: \u D83C[ \u DFFB \u DFFC])| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])| \u 200D(?: \u 2764 \u FE0F \u 200D(?: \u D83D \u DC8B \u 200D)? \u D83D \u DC68|(?: \u D83D[ \u DC68 \u DC69]) \u 200D(?: \u D83D \u DC66 \u 200D \u D83D \u DC66| \u D83D \u DC67 \u 200D(?: \u D83D[ \u DC66 \u DC67]))| \u D83D \u DC66 \u 200D \u D83D \u DC66| \u D83D \u DC67 \u 200D(?: \u D83D[ \u DC66 \u DC67])|(?: \u D83D[ \u DC68 \u DC69]) \u 200D(?: \u D83D[ \u DC66 \u DC67])|[ \u 2695 \u 2696 \u 2708] \u FE0F| \u D83D[ \u DC66 \u DC67]| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])|(?: \u D83C \u DFFB \u 200D[ \u 2695 \u 2696 \u 2708]| \u D83C \u DFFF \u 200D[ \u 2695 \u 2696 \u 2708]| \u D83C \u DFFE \u 200D[ \u 2695 \u 2696 \u 2708]| \u D83C \u DFFD \u 200D[ \u 2695 \u 2696 \u 2708]| \u D83C \u DFFC \u 200D[ \u 2695 \u 2696 \u 2708]) \u FE0F| \u D83C \u DFFB \u 200D(?: \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])| \u D83C[ \u DFFB- \u DFFF])|(?: \u D83E \u DDD1 \u D83C \u DFFB \u 200D \u D83E \u DD1D \u 200D \u D83E \u DDD1| \u D83D \u DC69 \u D83C \u DFFC \u 200D \u D83E \u DD1D \u 200D \u D83D \u DC69) \u D83C \u DFFB| \u D83E \u DDD1(?: \u D83C \u DFFF \u 200D \u D83E \u DD1D \u 200D \u D83E \u DDD1(?: \u D83C[ \u DFFB- \u DFFF])| \u 200D \u D83E \u DD1D \u 200D \u D83E \u DDD1)|(?: \u D83E \u DDD1 \u D83C \u DFFE \u 200D \u D83E \u DD1D \u 200D \u D83E \u DDD1| \u D83D \u DC69 \u D83C \u DFFF \u 200D \u D83E \u DD1D \u 200D(?: \u D83D[ \u DC68 \u DC69]))(?: \u D83C[ \u DFFB- \u DFFE])|(?: \u D83E \u DDD1 \u D83C \u DFFC \u 200D \u D83E \u DD1D \u 200D \u D83E \u DDD1| \u D83D \u DC69 \u D83C \u DFFD \u 200D \u D83E \u DD1D \u 200D \u D83D \u DC69)(?: \u D83C[ \u DFFB \u DFFC])| \u D83D \u DC69(?: \u D83C \u DFFE \u 200D(?: \u D83E \u DD1D \u 200D \u D83D \u DC68(?: \u D83C[ \u DFFB- \u DFFD \u DFFF])| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D83E[ \u DDAF- \u DDB3 \u DDBC \u DDBD])| \u D83C \u DFFC \u 200D(?: \u D83E \u DD1D \u 200D \u D83D \u DC68(?: \u D83C[ \u DFFB \u DFFD- \u DFFF])| \u D83C[ \u DF3E \u DF73 \u DF93 \u DFA4 \u DFA8 \u DFEB \u DFED]| \u D83D[ \u DCBB \u DCBC \u DD27 \u DD2C \u DE80 \u DE92]| \u D
` ).map((C)=>C.trim()).filter(Boolean),F=[],E={cuda:"nvenc",qsv:"qsv",vaapi:"vaapi",videotoolbox:"videotoolbox",v4l2m2m:"v4l2",dxva2:"amf"};for(let C of u){let B=E[C];if(B)F.push({accelerator:B})}return F}async function WD(D){let u=["-v","error","-f","lavfi","-i","testsrc=size=320x240:rate=1","-frames:v","1","-an","-c:v",D,"-f","null","-"];return new Promise((F)=>{let E=g("ffmpeg",u);E.on("error",()=>F(!1)),E.on("close",(C)=>F(C===0))})}async function kD(D,u){let F=["-v","error"];if(D==="nvenc")F.push("-hwaccel","cuda","-hwaccel_output_format","cuda");else if(D==="qsv")F.push("-hwaccel","qsv");else if(D==="vaapi")F.push("-hwaccel","vaapi","-vaapi_device","/dev/dri/renderD128");else if(D==="videotoolbox")F.push("-hwaccel","videotoolbox");else if(D==="v4l2")F.push("-hwaccel","v4l2m2m");else if(D==="amf")return!1;return F.push("-i",u,"-frames:v","1","-f","null","-"),new Promise((E)=>{let C=g("ffmpeg",F);C.on("error",()=>E(!1)),C.on("close",(B)=>E(B===0))})}async function p(D,u,F){let C= `
2026-01-20 00:25:55 +03:00
=== FFmpeg Command [ $ { new Date ( ) . toISOString ( ) } ] ===
2026-01-20 14:24:51 +03:00
ffmpeg $ { D . join ( " " ) }
2026-01-22 16:34:26 +03:00
` ;return await f(C),new Promise((B,A)=>{let $ =g("ffmpeg",D),J=""; $ .stderr.on("data",(X)=>{let G=X.toString();if(J+=G,u&&F){let Y=G.match(/time=( \d {2}):( \d {2}):( \d {2} \. \d {2})/);if(Y){let Z=parseInt(Y[1]),Q=parseInt(Y[2]),N=parseFloat(Y[3]),K=Z*3600+Q*60+N,k=Math.min(100,K/F*100);u(k)}}}), $ .on("error",(X)=>{f( ` ERROR : $ { X . message }
` ),A(Error( ` FFmpeg error : $ { X . message } ` ))}), $ .on("close",(X)=>{if(X===0){let Y=J.split( `
2026-01-20 14:24:51 +03:00
` ).filter((Z)=>Z.trim()).slice(-10).join( `
2026-01-22 09:50:51 +03:00
` );f( ` SUCCESS : Exit code $ { X }
2026-01-20 00:25:55 +03:00
-- - Last 10 lines of output -- -
$ { Y }
2026-01-22 16:34:26 +03:00
` ),B()}else f( ` FAILED : Exit code $ { X }
2026-01-20 00:25:55 +03:00
-- - Full error output -- -
2026-01-22 16:34:26 +03:00
$ { J }
` ),A(Error( ` FFmpeg failed with exit code $ { X }
$ { J } ` ))})})}async function bD(D){let F= `
2026-01-20 00:25:55 +03:00
=== MP4Box Command [ $ { new Date ( ) . toISOString ( ) } ] ===
2026-01-20 14:24:51 +03:00
MP4Box $ { D . join ( " " ) }
2026-01-22 16:34:26 +03:00
` ;return await f(F),new Promise((E,C)=>{let B=g("MP4Box",D),A="", $ ="";B.stdout.on("data",(J)=>{A+=J.toString()}),B.stderr.on("data",(J)=>{ $ +=J.toString()}),B.on("error",(J)=>{f( ` ERROR : $ { J . message }
` ),C(Error( ` MP4Box error : $ { J . message } ` ))}),B.on("close",(J)=>{if(J===0){let Y=(A|| $ ).split( `
2026-01-20 14:24:51 +03:00
` ).filter((Z)=>Z.trim()).slice(-10).join( `
2026-01-22 16:34:26 +03:00
` );f( ` SUCCESS : Exit code $ { J }
2026-01-20 00:25:55 +03:00
-- - Last 10 lines of output -- -
$ { Y }
2026-01-22 16:34:26 +03:00
` ),E()}else{let X= $ ||A;f( ` FAILED : Exit code $ { J }
2026-01-20 00:25:55 +03:00
-- - Full error output -- -
2026-01-20 14:24:51 +03:00
$ { X }
2026-01-22 16:34:26 +03:00
` ),C(Error( ` MP4Box failed with exit code $ { J }
$ { X } ` ))}})})}import{spawn as tF}from"node:child_process";async function e(D){return new Promise((u,F)=>{let E=tF("ffprobe",["-v","error","-show_entries","stream=width,height,duration,r_frame_rate,codec_name,codec_type,bit_rate","-show_entries","format=duration","-of","json",D]),C="";E.stdout.on("data",(B)=>{C+=B.toString()}),E.on("error",(B)=>{F(Error( ` ffprobe error : $ { B . message } ` ))}),E.on("close",(B)=>{if(B!==0){F(Error( ` ffprobe failed with exit code $ { B } ` ));return}try{let A=JSON.parse(C), $ =A.streams.find((K)=>K.codec_type==="video"),J=A.streams.find((K)=>K.codec_type==="audio"),X=A.format;if(! $ ){F(Error("No video stream found in input file"));return}let G=30;if( $ .r_frame_rate){let[K,k]= $ .r_frame_rate.split("/").map(Number);if(K&&k&&k!==0)G=K/k}let Y=parseFloat( $ .duration||X.duration||"0"),Z=A.streams.find((K)=>K.codec_type==="audio"&&K.bit_rate),Q=Z?.bit_rate?Math.round(parseInt(Z.bit_rate)/1000):void 0,N= $ .bit_rate?Math.round(parseInt( $ .bit_rate)/1000):void 0;u({width: $ .width,height: $ .height,duration:Y,fps:G,codec: $ .codec_name,hasAudio:Boolean(J),audioBitrate:Q,videoBitrate:N})}catch(A){F(Error( ` Failed to parse ffprobe output : $ { A } ` ))}})})}function QD(D,u=256){if(!D)return ` $ { u } k ` ;let E=Math.max(D,64),C=Math.min(E,u);if(C<=64)return"64k";if(C<=96)return"96k";if(C<=128)return"128k";if(C<=192)return"192k";return"256k"}function _D(D){let u=Math.floor(D/3600),F=Math.floor(D%3600/60),E=D%60;return ` $ { String ( u ) . padStart ( 2 , "0" ) } : $ { String ( F ) . padStart ( 2 , "0" ) } : $ { E . toFixed ( 3 ) . padStart ( 6 , "0" ) } ` }import{mkdir as eF,access as D8,constants as u8}from"node:fs/promises";async function d(D){try{await D8(D,u8.F_OK)}catch{await eF(D,{recursive:!0})}}function C8(D,u){let F=D*u;if(F<=230400)return 0.08;if(F<=409920)return 0.075;if(F<=921600)return 0.07;if(F<=2073600)return 0.065;if(F<=3686400)return 0.06;return 0.055}function b(D,u,F=30,E){let C=C8(D,u),B=Math.round(D*u*F*C/1000);if(E&&B>E)B=E;return ` $ { B } k ` }var vD=[{name:"360p",width:640,height:360,videoBitrate:b(640,360,30),audioBitrate:"192k"},{name:"480p",width:854,height:480,videoBitrate:b(854,480,30),audioBitrate:"192k"},{name:"720p",width:1280,height:720,videoBitrate:b(1280,720,30),audioBitrate:"192k"},{name:"1080p",width:1920,height:1080,videoBitrate:b(1920,1080,30),audioBitrate:"256k"},{name:"1440p",width:2560,height:1440,videoBitrate:b(2560,1440,30),audioBitrate:"256k"},{name:"2160p",width:3840,height:2160,videoBitrate:b(3840,2160,30),audioBitrate:"256k"}];function KD(D,u,F=30,E){let C=[],B=D/u,A=(G,Y,Z=0.01)=>Math.abs(G-Y)<Z, $ =A(B,1.7777777777777777),J=A(B,1.3333333333333333),X=vD.filter((G)=>{return G.height<=u});for(let G of X){let{height:Y,width:Z}=G;if(! $ &&!J){if(Z=Math.round(Y*B),Z%2!==0)Z-=1;if(Z<2)Z=2}C.push({...G,width:Z,height:Y,videoBitrate:b(Z,Y,30,E),fps:30})}return C}function B8(D,u,F){return{...D,name: ` $ { D . name } - $ { u } ` ,videoBitrate:b(D.width,D.height,u,F),fps:u}}function Wu(D){let F=D.trim().match(/^( \d +)p?(?:[@-]( \d +))? $ /i);if(!F)return null;let E=F[1]+"p",C=F[2]?parseInt(F[2]):30;return{resolution:E,fps:C}}function ku(D,u=30,F){let E=vD.find((C)=>C.name===D);if(!E)return null;if(u===30)return{...E,videoBitrate:b(E.width,E.height,30,F),fps:30};return B8(E,u,F)}function A8(D,u,F,E){let C=Wu(D);if(!C)return{error: ` Invalid profile format : $ { D } . Use format like : 360 , 720 @ 60 , 1080 - 60 ` };let B=ku(C.resolution,C.fps);if(!B)return{error: ` Unknown resolution : $ { C . resolution } . Available : 360 , 480 , 720 , 1080 , 1440 , 2160 ` };if(B.height>F)return{error: ` Source height ( $ { F } px ) is lower than requested $ { D } height ( $ { B . height } px ) ` };let A=120, $ =C.fps,J;if(C.fps>E) $ =Math.min(E,A),J= ` Requested $ { C . fps } FPS in $ { D } , but source is $ { E } FPS . Using $ { $ } FPS instead ` ;else if(C.fps>A) $ =A,J= ` Requested $ { C . fps } FPS in $ { D } exceeds maximum $ { A } FPS . Using $ { $ } FPS instead ` ;return J?{warning:J,adjustedFps: $ }:{}}function ND(D,u,F,E,C){let B=[],A=[], $ =[];for(let J of D){let X=A8(J,u,F,E);if(X.error){A.push(X.error);continue}if(X.warning) $ .push(X.warning);let G=Wu(J);if(!G)continue;let Y=X.adjustedFps!==void 0?X.adjustedFps:G.fps,Z=ku(G.resolution,Y,C);if(Z)B.push(Z)}return{profiles:B,errors:A,warnings:
2026-01-20 00:25:55 +03:00
2026-01-22 16:34:26 +03:00
` ;for(let $ =0; $ <D; $ ++){let J= $ *u,X=( $ +1)*u,G=Math.floor( $ /C),Z= $ %C*F,Q=G*E;A+= ` $ { _D ( J ) } -- > $ { _D ( X ) }
` ,A+= ` $ { B } # xywh = $ { Z } , $ { Q } , $ { F } , $ { E }
2026-01-20 00:25:55 +03:00
2026-01-22 16:34:26 +03:00
` }return A}import{join as K8}from"node:path";function X8(D,u,F){if(F)if(u==="h264")return 32;else return 42;else if(u==="h264"){if(D<=360)return 25;if(D<=480)return 24;if(D<=720)return 23;if(D<=1080)return 22;if(D<=1440)return 21;return 20}else{if(D<=360)return 40;if(D<=480)return 38;if(D<=720)return 35;if(D<=1080)return 32;if(D<=1440)return 30;return 28}}async function qu(D,u,F,E,C,B,A, $ ,J,X,G,Y=!1,Z,Q){let N=K8(u, ` video _$ { J } _$ { F . name } . mp4 ` ),K=["-y"];if(Z){if(Z==="nvenc")K.push("-hwaccel","cuda","-hwaccel_output_format","cuda");else if(Z==="qsv")K.push("-hwaccel","qsv");else if(Z==="vaapi")K.push("-hwaccel","vaapi");else if(Z==="videotoolbox")K.push("-hwaccel","videotoolbox");else if(Z==="v4l2")K.push("-hwaccel","v4l2")}K.push("-i",D,"-c:v",E);let k=E.includes("nvenc")||E.includes("qsv")||E.includes("amf")||E.includes("vaapi")||E.includes("videotoolbox")||E.includes("v4l2"),U;if(k&&X?.cq!==void 0)U=X.cq;else if(!k&&X?.crf!==void 0)U=X.crf;else U=X8(F.height,J,k);if(E==="h264_nvenc")K.push("-rc:v","vbr"),K.push("-cq",String(U)),K.push("-preset",C),K.push("-2pass","0");else if(E==="av1_nvenc")K.push("-rc:v","vbr"),K.push("-cq",String(U)),K.push("-preset",C),K.push("-2pass","0");else if(E==="av1_qsv")K.push("-preset",C),K.push("-global_quality",String(U));else if(E==="h264_qsv")K.push("-preset",C),K.push("-global_quality",String(U));else if(E==="av1_amf")K.push("-quality","balanced"),K.push("-rc","cqp"),K.push("-qp_i",String(U)),K.push("-qp_p",String(U));else if(E==="h264_amf")K.push("-quality","balanced"),K.push("-rc","cqp"),K.push("-qp_i",String(U)),K.push("-qp_p",String(U));else if(E==="libsvtav1")K.push("-crf",String(U)),K.push("-preset",C),K.push("-svtav1-params","tune=0:enable-overlays=1");else if(E==="libx264")K.push("-crf",String(U)),K.push("-preset",C);else K.push("-preset",C);let W=J==="av1"?0.6:1,z=Math.round(parseInt(F.videoBitrate)*W*1.5);K.push("-maxrate", ` $ { z } k ` ),K.push("-bufsize", ` $ { z * 2 } k ` );let j=F.fps||30,O=Math.round(j*A);K.push("-g",String(O),"-keyint_min",String(O),"-sc_threshold","0");let x=[],v=F.width,BD=F.height,l=Z==="nvenc";if(l)x.push( ` scale _cuda = $ { F . width } : $ { F . height } ` );else x.push( ` scale = $ { F . width } : $ { F . height } ` );if(G){if(G.deinterlace)x.push("yadif");if(G.denoise)x.push("hqdn3d");if(G.customFilters)x.push(...G.customFilters)}if(l)x.push("hwdownload","format=nv12");if(x.push( ` pad = $ { v } : $ { BD } : ( ow - iw ) / 2 : ( oh - ih ) / 2 ` ,"setsar=1"),K.push("-vf",x.join(",")),!Y){let OD=parseInt(F.audioBitrate)||256,LD=QD( $ ,OD);K.push("-c:a","aac","-b:a",LD);let AD=B.toFixed(3),ZD=["aresample=async=1:min_hard_comp=0.1:first_pts=0", ` apad = whole _dur = $ { AD } ` , ` atrim = 0 : $ { AD } ` ];if(G?.audioNormalize)ZD.push("loudnorm");K.push("-af",ZD.join(","))}else K.push("-an");return K.push("-f","mp4",N),await p(K,Q,B),N}async function Iu(D,u,F,E,C,B,A, $ ,J,X,G,Y,Z,Q=!1,N,K){let k=new Map;if(J&&F.length>1)for(let U=0;U<F.length;U+=X){let W=F.slice(U,U+X),z=W.map((O)=>qu(D,u,O,E,C,B,A, $ ,G,Y,Z,Q,N,(x)=>{if(K)K(O.name,x)}));(await Promise.all(z)).forEach((O,x)=>{let v=W[x];k.set(v.name,O)})}else for(let U of F){let W=await qu(D,u,U,E,C,B,A, $ ,G,Y,Z,Q,N,(z)=>{if(K)K(U.name,z)});k.set(U.name,W)}return k}import{join as L}from"node:path";import{readdir as Ou,rename as c3,mkdir as l3,writeFile as gD}from"node:fs/promises";import{readFile as PD,writeFile as hD}from"node:fs/promises";async function Vu(D){let u=await PD(D,"utf-8");u=u.replace(/ \/ \/ >/g,"/>"),u=u.replace(/ \/ \s + \/ >/g,"/>"),u=u.replace(/(<Representation[^>]+) \s + \/ >/g," $ 1/>"),u=u.replace(/<Representation \s +([^>]+) \/ > \s *< \/ Representation>/g,"<Representation $ 1/>"),u=u.replace(/<Representation \s +([^>]+) \/ > \s *(<AudioChannelConfiguration[^>]* \/ >)/g, ` < Representation $1 >
2026-01-20 00:25:55 +03:00
$2
2026-01-20 14:24:51 +03:00
< /Representation>`),u=u.replace(/ < Representation \ s + ( [ ^ > ] + ) > \ s * ( ? = < ( ? : Representation | \ / AdaptationSet ) ) / g , ` <Representation $ 1/>
2026-01-22 16:34:26 +03:00
` ),await hD(D,u,"utf-8")}async function Hu(D){let u=await PD(D,"utf-8");u=u.replace(/media=" \$ RepresentationID \$ _ \$ Number \$ \. m4s"/g,'media=" $ RepresentationID $ / $ RepresentationID $ _ $ Number $ .m4s"'),u=u.replace(/initialization=" \$ RepresentationID \$ _ \. mp4"/g,'initialization=" $ RepresentationID $ / $ RepresentationID $ _.mp4"'),await hD(D,u,"utf-8")}async function xu(D){let F=(await PD(D,"utf-8")).split( `
` ),E=[],C=0;while(C<F.length){let B=F[C];if(B.includes("<AdaptationSet")&&B.includes("maxWidth")){let A=C, $ =[B],J=[],X=[],G=[],Y=!1;C++;while(C<F.length&&!F[C].includes("</AdaptationSet>")){let Z=F[C];if(Z.includes("<SegmentTemplate"))Y=!0;if(Y){if(J.push(Z),Z.includes("</SegmentTemplate>"))Y=!1}else if(Z.includes("<Representation")&&Z.includes("-h264"))X.push(Z);else if(Z.includes("<Representation")&&Z.includes("-av1"))G.push(Z);C++}if(X.length>0&&G.length>0)E.push(B),J.forEach((Z)=>E.push(Z)),X.forEach((Z)=>E.push(Z)),E.push(" </AdaptationSet>"),E.push(B),J.forEach((Z)=>E.push(Z)),G.forEach((Z)=>E.push(Z)),E.push(" </AdaptationSet>");else{E.push(B);for(let Z=A+1;Z<C;Z++)E.push(F[Z]);E.push(F[C])}C++}else E.push(B),C++}await hD(D,E.join( `
` ),"utf-8")}function fD(D,u,F){let E= ` # EXTM3U
` ;E+= ` # EXT - X - VERSION : 6
` ,E+= ` # EXT - X - TARGETDURATION : $ { Math . ceil ( F ) }
` ,E+= ` # EXT - X - MEDIA - SEQUENCE : 1
` ,E+= ` # EXT - X - INDEPENDENT - SEGMENTS
` ,E+= ` # EXT - X - MAP : URI = "${u}"
` ;for(let C of D)E+= ` # EXTINF : $ { F } ,
` ,E+= ` $ { C }
` ;return E+= ` # EXT - X - ENDLIST
` ,E}function Mu(D,u){let F= ` # EXTM3U
` ;if(F+= ` # EXT - X - VERSION : 6
2026-01-20 14:24:51 +03:00
` ,F+= ` # EXT - X - INDEPENDENT - SEGMENTS
2026-01-20 00:25:55 +03:00
2026-01-22 16:34:26 +03:00
` ,u)F+= ` # EXT - X - MEDIA : TYPE = AUDIO , GROUP - ID = "audio" , NAME = "audio" , AUTOSELECT = YES , URI = "audio/playlist.m3u8" , CHANNELS = "2"
2026-01-20 00:25:55 +03:00
2026-01-22 16:34:26 +03:00
` ;for(let E of D){let C=u?"avc1.4D4020,mp4a.40.2":"avc1.4D4020";if(F+= ` # EXT - X - STREAM - INF : BANDWIDTH = $ { E . bandwidth } , CODECS = "${C}" , RESOLUTION = $ { E . resolution } , FRAME - RATE = $ { E . fps } ` ,u)F+=',AUDIO="audio"';F+= `
` ,F+= ` $ { E . path }
2026-01-20 00:25:55 +03:00
2026-01-22 16:34:26 +03:00
` }return F}async function Y8(D,u,F,E,C,B){let A=L(u,"manifest.mpd"), $ =C.length>1,J=["-dash",String(E*1000),"-frag",String(E*1000),"-rap","-segment-timeline","-segment-name"," $ RepresentationID $ _ $ Number $ ","-out",A],X=!0;for(let[G,Y]of D.entries())for(let Z of F){let Q=Y.get(Z.name);if(!Q)throw Error( ` MP4 file not found for profile : $ { Z . name } , codec : $ { G } ` );let N= $ ? ` $ { Z . name } - $ { G } ` :Z.name;if(J.push( ` $ { Q } # video : id = $ { N } ` ),X&&B)J.push( ` $ { Q } # audio : id = audio ` ),X=!1}if(await bD(J),await G8(u,F,C,B),await Hu(A), $ )await xu(A);return await Vu(A),A}async function G8(D,u,F,E){let{readdir:C,rename:B,mkdir:A}=await import("node:fs/promises"), $ =F.length>1,J=[];for(let Y of F)for(let Z of u){let Q= $ ? ` $ { Z . name } - $ { Y } ` :Z.name;J.push(Q);let N=L(D,Q);await A(N,{recursive:!0})}let X=L(D,"audio");if(E)await A(X,{recursive:!0});let G=await C(D);for(let Y of G){if(Y==="manifest.mpd")continue;if(E&&(Y.startsWith("audio_")||Y==="audio_init.m4s")){let Z=L(D,Y),Q=L(X,Y);await B(Z,Q);continue}for(let Z of J)if(Y.startsWith( ` $ { Z } _ ` )){let Q=L(D,Y),N=L(D,Z,Y);await B(Q,N);break}}}async function Lu(D,u,F,E,C,B,A){let $ ,J,X=B.length>0,G=B.includes("dash"),Y=B.includes("hls");if(X){if( $ =await Y8(D,u,F,E,C,A),!G) $ =void 0}if(Y)J=await U8(u,F,E,C.length>1,A);return{manifestPath: $ ,hlsManifestPath:J}}async function U8(D,u,F,E,C){let B=L(D,"master.m3u8"),A=[];for(let G of u){let Y=E? ` $ { G . name } - h264 ` :G.name,Z=L(D,Y),Q=await Ou(Z),N=Q.filter((z)=>z.endsWith(".m4s")).sort((z,j)=>{let O=parseInt(z.match(/_( \d +) \. m4s $ /)?.[1]||"0"),x=parseInt(j.match(/_( \d +) \. m4s $ /)?.[1]||"0");return O-x}),K=Q.find((z)=>z.endsWith("_.mp4"));if(!K||N.length===0)continue;let k=fD(N,K,F),U=L(Z,"playlist.m3u8");await gD(U,k,"utf-8");let W=parseInt(G.videoBitrate)*1000;A.push({path: ` $ { Y } / playlist . m3u8 ` ,bandwidth:W,resolution: ` $ { G . width } x$ { G . height } ` ,fps:G.fps||30})}let $ ,J=[];if(C){let G=L(D,"audio"),Y=[];try{Y=await Ou(G)}catch{Y=[]}if(J=Y.filter((Z)=>Z.endsWith(".m4s")).sort((Z,Q)=>{let N=parseInt(Z.match(/_( \d +) \. m4s $ /)?.[1]||"0"),K=parseInt(Q.match(/_( \d +) \. m4s $ /)?.[1]||"0");return N-K}), $ =Y.find((Z)=>Z.endsWith("_.mp4")), $ &&J.length>0){let Z=fD(J, $ ,F);await gD(L(G,"playlist.m3u8"),Z,"utf-8")}}let X=Mu(A,C&& $ !==void 0&&J.length>0);return await gD(B,X,"utf-8"),B}async function mD(D){let{input:u,outputDir:F,segmentDuration:E=2,profiles:C,customProfiles:B,codec:A=["h264"],formats: $ =["dash","hls"],hardwareDecoder:J,hardwareAccelerator:X,quality:G,generateThumbnails:Y=!0,thumbnailConfig:Z={},generatePoster:Q=!0,posterTimecode:N="00:00:00",parallel:K=!0,muted:k=!1,onProgress:U}=D,W=zD("/tmp", ` dash - converter - $ { W8 ( ) } ` );await d(W);let z=ju(u,Tu(u)),j=zD(F,z);await d(j);let O=zD(j,"conversion.log");SD(O);let{writeFile:x}=await import("node:fs/promises"),v= ` === === === === === === === === === === === === === === =
2026-01-20 00:25:55 +03:00
DASH Conversion Log
Started : $ { new Date ( ) . toISOString ( ) }
2026-01-20 14:24:51 +03:00
Input : $ { u }
2026-01-22 09:50:51 +03:00
Output : $ { j }
2026-01-22 16:34:26 +03:00
Codec : $ { Array . isArray ( A ) ? A . join ( "," ) : A }
2026-01-20 14:52:59 +03:00
Formats : $ { $ ? . join ( "," ) || "dash,hls" }
2026-01-20 00:25:55 +03:00
=== === === === === === === === === === === === === === =
2026-01-22 16:34:26 +03:00
` ;await x(O,v,"utf-8");try{return await k8(u,F,W,E,C,B,A, $ ,X,J,G,Y,Z,Q,N,K,k,U)}finally{let{appendFile:BD}=await import("node:fs/promises");try{await BD(O, `
2026-01-20 00:25:55 +03:00
Completed : $ { new Date ( ) . toISOString ( ) }
2026-01-22 16:34:26 +03:00
` ,"utf-8")}catch(l){}try{await wu(W,{recursive:!0,force:!0})}catch(l){console.warn( ` Warning : Failed to cleanup temp directory : $ { W } ` )}}}async function k8(D,u,F,E,C,B,A, $ ,J,X,G,Y,Z,Q,N,K,k,U){if(!await i())throw Error("FFmpeg is not installed or not in PATH");if(!await r())throw Error("MP4Box is not installed or not in PATH. Install gpac package.");let W=(q,V,TD,wD)=>{if(U)U({stage:q,percent:V,message:TD,currentProfile:wD})};W("analyzing",0,"Analyzing input video...");let z=await e(D),j=!k&&z.hasAudio,O=z.duration,x=Math.max(1,Math.ceil(O/E)),v=O/x,BD=J&&J!=="auto"?J:"auto",l=await o(),OD=await t(),LD=l.some((q)=>q.av1Encoder),AD=Array.isArray(A)?A:[A],ZD=AD.includes("h264"),RD=AD.includes("av1"),{selected:YD,h264Encoder:SF,av1Encoder:bF,warnings:Cu}=Q8(l,BD,ZD,RD);if(Cu.length>0)for(let q of Cu)console.warn( ` ⚠ ️ $ { q } ` );let{selected:GD}=_8(OD,X||"auto");if(RD&&!LD)console.warn("⚠️ AV1 hardware encoder not detected. AV1 will use CPU encoder (slow).");let P=[];if(ZD)P.push("h264");if(RD)P.push("av1");if(P.length===0)P.push("h264");let Bu= $ && $ .length>0?Array.from(new Set( $ )):["dash","hls"],R;if(B&&B.length>0){let q=ND(B,z.width,z.height,z.fps,z.videoBitrate);if(q.errors.length>0){console.warn( `
2026-01-22 09:50:51 +03:00
❌ Profile errors : ` );for(let V of q.errors)console.warn( ` - $ { V } ` );console.warn("")}if(q.warnings.length>0){console.warn( `
2026-01-22 16:34:26 +03:00
⚠ ️ Profile warnings : ` );for(let V of q.warnings)console.warn( ` - $ { V } ` );console.warn("")}if(R=q.profiles,R.length===0)throw Error("No valid profiles found in custom list. Check errors above.")}else if(C)R=C;else R=KD(z.width,z.height,z.fps,z.videoBitrate);if(R.length===0)throw Error("No suitable profiles found for input video resolution");let vF=ju(D,Tu(D)), $ D=zD(u,vF);try{await wu( $ D,{recursive:!0,force:!0})}catch(q){}await d( $ D);let h=[];if(P.includes("h264")){let q=SF||"libx264",V=Ru(q,"h264");h.push({type:"h264",codec:q,preset:V})}if(P.includes("av1")){let q=bF||"libsvtav1",V=Ru(q,"av1");h.push({type:"av1",codec:q,preset:V})}let PF=h.map((q)=>q.type.toUpperCase()).join(" + "),hF=YD==="cpu"?"CPU":YD.toUpperCase();W("analyzing",20, ` Using $ { PF } encoding ( $ { hF } , decoder $ { GD . toUpperCase ( ) } ) ` ,void 0);let fF=YD==="cpu"?2:3,jD=new Map;for(let q=0;q<h.length;q++){let{type:V,codec:TD,preset:wD}=h[q],Ku=q/h.length,cF=1/h.length;W("encoding",25+Ku*40, ` Stage 1 : Encoding $ { V . toUpperCase ( ) } ( $ { R . length } profiles ) ... ` );let lF=V==="h264"?G?.h264:G?.av1,pF=await Iu(D,F,R,TD,wD,z.duration,v,z.audioBitrate,K,fF,V,lF,void 0,k,GD==="cpu"?void 0:GD,(JD,Xu)=>{let U3=R.findIndex((dF)=>dF.name===JD),Yu=25+Ku*40,Gu=Xu/100*(40*cF/R.length);if(W("encoding",Yu+Gu, ` Encoding $ { V . toUpperCase ( ) } $ { JD } ... ` , ` $ { V } - $ { JD } ` ),U)U({stage:"encoding",percent:Yu+Gu,currentProfile: ` $ { V } - $ { JD } ` ,profilePercent:Xu,message: ` Encoding $ { V . toUpperCase ( ) } $ { JD } ... ` })});jD.set(V,pF)}W("encoding",65,"Stage 1 complete: All codecs and profiles encoded"),W("encoding",70,"Stage 2: Creating segments and manifests...");let{manifestPath:gF,hlsManifestPath:mF}=await Lu(jD, $ D,R,v,P,Bu,j),Au=[];for(let q of jD.values())Au.push(...Array.from(q.values()));W("encoding",80,"Stage 2 complete: All formats packaged");let Zu, $ u;if(Y){W("thumbnails",80,"Generating thumbnail sprites...");let q={width:Z.width||160,height:Z.height||90,interval:Z.interval||1,columns:Z.columns||10},V=await zu(D, $ D,z.duration,q);Zu=V.spritePath, $ u=V.vttPath,W("thumbnails",90,"Thumbnails generated")}let Ju;if(Q)W("thumbnails",92,"Generating poster image..."),Ju=await Nu(D, $ D,N),W("thumbnails",95,"Poster generated");return W("manifest",95,"Finalizing..."),W("complete",100,"Conversion complete!"),{manifestPath:gF,hlsManifestPath:mF,videoPaths:Au,thumbnailSpritePath:Zu,thumbnailVttPath: $ u,posterPath:Ju,duration:z.duration,profiles:R,usedNvenc:h.some((q)=>q.codec.includes("nvenc")),selectedAccelerator:YD,selectedDecoder:GD,codecs:P,formats:Bu}}var DD={nvenc:100,qsv:90,amf:80,vaapi:70,videotoolbox:65,v4l2:60,cpu:1};function Q8(D,u,F,E){let C=[],B=new Set(["nvenc","qsv","amf","vaapi","videotoolbox","v4l2"]),A=D.filter((k)=>F&&k.h264Encoder||E&&k.av1Encoder), $ =A.filter((k)=>B.has(k.accelerator)),J=(k)=>A.find((U)=>U.accelerator===k);if(u==="cpu")return{selected:"cpu",h264Encoder:void 0,av1Encoder:void 0,warnings:C};let X;if(u!=="auto"){if(!B.has(u))C.push( ` Ускоритель "${u}" пока не поддерживается , использую CPU ` );else if(X=J(u),!X)throw Error( ` Аппаратный ускоритель "${u}" недоступен в системе ` )}else if(X=( $ .length>0? $ :[]).sort((U,W)=>(DD[W.accelerator]||0)-(DD[U.accelerator]||0))[0],!X&&A.length>0)C.push("Доступен аппаратный ускоритель, но он пока не поддерживается пайплайном, использую CPU");let Y=( $ .length>0? $ :[]).sort((k,U)=>(DD[U.accelerator]||0)-(DD[k.accelerator]||0)),Z=(k)=>{let U=k==="h264"?X?.h264Encoder:X?.av1Encoder;if(U)return{encoder:U,accel:X?.accelerator};let W=Y.find((z)=>k==="h264"?z.h264Encoder:z.av1Encoder);if(W){if(u!=="auto"&&X)C.push( ` Выбранный ускоритель "${X.accelerator}" не поддерживает $ { k . toUpperCase ( ) } , использую $ { W . accelerator } ` );return{encoder:k==="h264"?W.h264Encoder:W.av1Encoder,accel:W.accelerator}}if(u!=="auto")C.push( ` Ускоритель "${u}" не поддерживает $ { k . toUpperCase ( ) } , использую CPU ` );return{encoder:void 0,accel:"cpu"}},Q=F?Z("h264"):{encoder:void 0,accel:X
2026-01-22 09:50:51 +03:00
Options : ` ),console.error(" -r, --resolutions Video resolutions (e.g., 360,480,720 or 720@60,1080@60)"),console.error(" -c, --codec Video codec: av1 or h264 (default: auto = h264 + AV1 if HW)"),console.error(" -f, --format Streaming format: dash or hls (default: auto = dash + hls)"),console.error(" -p, --poster Poster timecode (e.g., 00:00:05 or 10)"),console.error(" -e, --encoder <type> Hardware encoder: auto|nvenc|qsv|amf|vaapi|videotoolbox|v4l2|cpu (default: auto)"),console.error(" -d, --decoder <type> Hardware decoder: auto|nvenc|qsv|amf|vaapi|videotoolbox|v4l2|cpu (default: auto)"),console.error(" -m, --muted Disable audio track (no audio in output)"),console.error( `
2026-01-20 00:25:55 +03:00
Quality Options ( override defaults ) : ` ),console.error(" --h264-cq <value> H.264 GPU CQ value (0-51, lower = better, default: auto)"),console.error(" --h264-crf <value> H.264 CPU CRF value (0-51, lower = better, default: auto)"),console.error(" --av1-cq <value> AV1 GPU CQ value (0-51, lower = better, default: auto)"),console.error(" --av1-crf <value> AV1 CPU CRF value (0-63, lower = better, default: auto)"),console.error( `
2026-01-20 14:24:51 +03:00
Examples : ` ),console.error(" create-vod video.mp4"),console.error(" create-vod video.mp4 ./output"),console.error(" create-vod video.mp4 -r 360,480,720"),console.error(" create-vod video.mp4 -c av1 --av1-cq 40"),console.error(" create-vod video.mp4 -c h264 --h264-cq 30"),console.error(" create-vod video.mp4 -f hls"),console.error(" create-vod video.mp4 -r 720@60,1080@60,2160@60 -c av1 -f dash"),console.error(" create-vod video.mp4 -p 00:00:05"),console.error(" create-vod video.mp4 ./output -r 720,1080 -p 10 --h264-cq 28"),process.exit(1);console.log( ` \uD83D\uDD0D Checking system ...
2026-01-22 16:34:26 +03:00
` );var xF=await i(),MF=await r(),OF=await o(),a8=await t(),i8=OF.some((D)=>D.av1Encoder),HD={nvenc:100,qsv:90,amf:80,vaapi:70,videotoolbox:65,v4l2:60,cpu:1},r8={nvenc:"h264_nvenc",qsv:"h264_qsv",amf:"h264_amf",vaapi:"h264_vaapi",videotoolbox:"h264_videotoolbox",v4l2:"h264_v4l2m2m",cpu:"libx264"},o8=Array.from(new Set([...OF.map((D)=>D.accelerator),"cpu"])),t8=Array.from(new Set([...a8.map((D)=>D.accelerator),"cpu"]));async function e8(){let D=[];for(let u of o8){if(u==="amf")continue;let F=r8[u]||"libx264";if(await WD(F))D.push(u)}return D}async function D3(){let D=[];for(let u of t8){if(u==="cpu"){D.push("cpu");continue}if(await kD(u,s))D.push(u)}return D}var LF=await e8(),RF=await D3(),ED=LF.slice().sort((D,u)=>(HD[u]||0)-(HD[D]||0))[0],CD=RF.slice().sort((D,u)=>(HD[u]||0)-(HD[D]||0))[0];console.log( ` FFmpeg : $ { xF ? "✅" : "❌" } ` );console.log( ` MP4Box : $ { MF ? "✅" : "❌" } ` );var _F=Array.from(new Set(LF.map((D)=>D.toUpperCase()))),NF=Array.from(new Set(RF.map((D)=>D.toUpperCase()))),zF=uD?uD.toUpperCase():ED&&ED.toUpperCase()||"CPU",jF=_F.length>0?_F:["CPU"],qF=FD?FD.toUpperCase():CD&&CD.toUpperCase()||"CPU",TF=NF.length>0?NF:["CPU"];console.log( ` Encoder : $ { zF === "AUTO" ? ED && ED . toUpperCase ( ) || "CPU" : zF } ( $ { jF . join ( ", " ) } ) ` );console.log( ` Decoder : $ { qF === "AUTO" ? CD && CD . toUpperCase ( ) || "CPU" : qF } ( $ { TF . join ( ", " ) } ) ` );console.log("");if(!xF)console.error("❌ FFmpeg not found. Please install FFmpeg first."),process.exit(1);if(!MF)console.error("❌ MP4Box not found. Please install: sudo pacman -S gpac"),process.exit(1);var Eu=VD&&VD.length>0?VD:["h264"],xD=Eu.includes("h264"),MD=Eu.includes("av1");if(!xD)console.warn("⚠️ H.264 is mandatory for compatibility. Adding H.264."),xD=!0;if(MD&&!i8)console.error("⚠️ AV1 requested but no hardware AV1 encoder found."),console.error(" CPU-based AV1 encoding (libsvtav1) will be VERY slow."),console.error( ` Consider using -- codec h264 for faster encoding .
2026-01-22 09:50:51 +03:00
` );var u3=!0,F3=!0;console.log( ` \uD83D\uDCCA Analyzing video ...
2026-01-22 16:34:26 +03:00
` );var M=await e(s),E3=s8(s),C3=(E3.size/1048576).toFixed(2);console.log(" \u D83D \u DCF9 Video Information:");console.log( ` File : $ { s } ` );console.log( ` Size : $ { C3 } MB ` );console.log( ` Resolution : $ { M . width } x$ { M . height } ` );console.log( ` FPS : $ { M . fps . toFixed ( 2 ) } ` );console.log( ` Duration : $ { M . duration . toFixed ( 2 ) } s ` );console.log( ` Codec : $ { M . codec } ` );if(M.videoBitrate)console.log( ` Video Bitrate : $ { ( M . videoBitrate / 1000 ) . toFixed ( 2 ) } Mbps ` );if(M.audioBitrate)console.log( ` Audio Bitrate : $ { M . audioBitrate } kbps ` );var eD=[];if(XD&&XD.length>0){let D=ND(XD,M.width,M.height,M.fps,M.videoBitrate);if(D.errors.length>0)console.error( `
2026-01-20 14:24:51 +03:00
❌ Profile errors : ` ),D.errors.forEach((u)=>console.error( ` - $ { u } ` )),process.exit(1);if(D.warnings.length>0)console.warn( `
2026-01-22 16:34:26 +03:00
⚠ ️ Profile warnings : ` ),D.warnings.forEach((u)=>console.warn( ` - $ { u } ` ));eD=D.profiles.map((u)=>u.fps? ` $ { u . name } @ $ { u . fps } ` :u.name)}else eD=KD(M.width,M.height,M.fps,M.videoBitrate).map((u)=>u.fps? ` $ { u . name } @ $ { u . fps } ` :u.name);var B3=[u3?"DASH (manifest.mpd)":null,F3?"HLS (master.m3u8)":null].filter(Boolean).join(", "),A3=!0,Z3=Du||"00:00:00", $ 3=[xD?"h264":null,MD?"av1":null].filter(Boolean).join(", "),J3=!MD&&Eu.includes("av1")?" (AV1 disabled: no HW)":"",wF=ED&&ED.toUpperCase()||"CPU",yF=CD&&CD.toUpperCase()||"CPU",IF=uD?uD.toUpperCase():wF,VF=FD?FD.toUpperCase():yF,K3=IF==="AUTO"?wF:IF,X3=VF==="AUTO"?yF:VF,Y3=jF.join(", "),G3=TF.join(", ");console.log( `
\uD83D\uDCE6 Parameters : ` );console.log( ` Input : $ { s } ` );console.log( ` Output : $ { HF } ` );console.log( ` Codec : $ { $3 } $ { J3 } ` );console.log( ` Profiles : $ { eD . join ( ", " ) } ` );console.log( ` Manifests : $ { B3 } ` );console.log( ` Poster : $ { Z3 } ( will be generated ) ` );console.log( ` Thumbnails : $ { A3 ? "yes (with VTT)" : "no" } ` );console.log( ` Encoder : $ { K3 } ( available : $ { Y3 } ) ` );console.log( ` Decoder : $ { X3 } ( available : $ { G3 } ) ` );console.log( ` Audio : $ { Fu ? "disabled (muted)" : "enabled" } ` );var c;if(T!==void 0||w!==void 0||y!==void 0||S!==void 0){if(c={},T!==void 0||w!==void 0){if(c.h264={},T!==void 0)c.h264.cq=T;if(w!==void 0)c.h264.crf=w;console.log( ` \uD83C\uDF9A ️ H . 264 Quality : $ { T !== void 0 ? ` CQ ${ T } ` : "" } $ { w !== void 0 ? ` CRF ${ w } ` : "" } ` )}if(y!==void 0||S!==void 0){if(c.av1={},y!==void 0)c.av1.cq=y;if(S!==void 0)c.av1.crf=S;console.log( ` \uD83C\uDF9A ️ AV1 Quality : $ { y !== void 0 ? ` CQ ${ y } ` : "" } $ { S !== void 0 ? ` CRF ${ S } ` : "" } ` )}}console.log( `
2026-01-20 00:25:55 +03:00
\uD83D\uDE80 Starting conversion ...
2026-01-22 16:34:26 +03:00
` );var ID=new tD.default.MultiBar({format:"{stage} | {bar} | {percentage}% | {name}",barCompleteChar:"█",barIncompleteChar:"░",hideCursor:!0,clearOnComplete:!1,stopOnComplete:!0},tD.default.Presets.shades_classic),rD={},oD=null;try{let D=Date.now(),u=await mD({input:s,outputDir:HF,customProfiles:XD,posterTimecode:Du,codec:[...xD?["h264"]:[],...MD?["av1"]:[]],segmentDuration:2,hardwareAccelerator:uD,hardwareDecoder:FD,quality:c,generateThumbnails:!0,generatePoster:!0,muted:Fu,parallel:!0,onProgress:(C)=>{let B=C.stage==="encoding"?"Encoding":C.stage==="thumbnails"?"Thumbnails":C.stage==="manifest"?"Manifest":C.stage==="analyzing"?"Analyzing":"Complete";if(C.stage==="encoding"&&C.currentProfile){if(!rD[C.currentProfile])rD[C.currentProfile]=ID.create(100,0,{stage:"Encode",name:C.currentProfile});let A=C.profilePercent??C.percent;rD[C.currentProfile].update(A,{stage:"Encode",name:C.currentProfile})}if(!oD)oD=ID.create(100,0,{stage:B,name:"Overall"});oD.update(C.percent,{stage:B,name:C.message||"Overall"})}});ID.stop();let E=((Date.now()-D)/1000).toFixed(2);console.log( `
✅ Conversion completed successfully ! ( $ { E } s )
2026-01-22 10:44:39 +03:00
` )}catch(D){ID.stop(),console.error( `
2026-01-20 00:25:55 +03:00
2026-01-20 14:24:51 +03:00
❌ Error during conversion : ` ),console.error(D),process.exit(1)}