diff --git a/bin/cli.js b/bin/cli.js index 548fc00..44b017a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,42 +1,43 @@ #!/usr/bin/env node -import{createRequire as IF}from"node:module";var NF=Object.create;var{getPrototypeOf:zF,defineProperty:tD,getOwnPropertyNames:HF}=Object;var qF=Object.prototype.hasOwnProperty;var ED=(u,D,E)=>{E=u!=null?NF(zF(u)):{};let F=D||!u||!u.__esModule?tD(E,"default",{value:u,enumerable:!0}):E;for(let C of HF(u))if(!qF.call(F,C))tD(F,C,{get:()=>u[C],enumerable:!0});return F};var x=(u,D)=>()=>(D||u((D={exports:{}}).exports,D),D.exports);var p=IF(import.meta.url);var Nu=x((z3,Qu)=>{class _u{constructor(u,D,E){this.etaBufferLength=u||100,this.valueBuffer=[E],this.timeBuffer=[D],this.eta="0"}update(u,D,E){this.valueBuffer.push(D),this.timeBuffer.push(u),this.calculate(E-D)}getTime(){return this.eta}calculate(u){let D=this.valueBuffer.length,E=Math.min(this.etaBufferLength,D),F=this.valueBuffer[D-1]-this.valueBuffer[D-E],C=this.timeBuffer[D-1]-this.timeBuffer[D-E],B=F/C;this.valueBuffer=this.valueBuffer.slice(-this.etaBufferLength),this.timeBuffer=this.timeBuffer.slice(-this.etaBufferLength);let A=Math.ceil(u/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}}Qu.exports=_u});var MD=x((H3,Hu)=>{var d=p("readline");class zu{constructor(u){this.stream=u,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(u){if(!this.stream.isTTY)return;if(u)this.stream.write("\x1B[?25h");else this.stream.write("\x1B[?25l")}cursorTo(u=null,D=null){if(!this.stream.isTTY)return;d.cursorTo(this.stream,u,D)}cursorRelative(u=null,D=null){if(!this.stream.isTTY)return;this.dy=this.dy+D,d.moveCursor(this.stream,u,D)}cursorRelativeReset(){if(!this.stream.isTTY)return;d.moveCursor(this.stream,0,-this.dy),d.cursorTo(this.stream,0,null),this.dy=0}clearRight(){if(!this.stream.isTTY)return;d.clearLine(this.stream,1)}clearLine(){if(!this.stream.isTTY)return;d.clearLine(this.stream,0)}clearBottom(){if(!this.stream.isTTY)return;d.clearScreenDown(this.stream)}newline(){this.stream.write(` -`),this.dy++}write(u,D=!1){if(this.linewrap===!0&&D===!1)this.stream.write(u.substr(0,this.getWidth()));else this.stream.write(u)}lineWrapping(u){if(!this.stream.isTTY)return;if(this.linewrap=u,u)this.stream.write("\x1B[?7h");else this.stream.write("\x1B[?7l")}isTTY(){return this.stream.isTTY===!0}getWidth(){return this.stream.columns||(this.stream.isTTY?80:200)}}Hu.exports=zu});var Iu=x((q3,qu)=>{qu.exports=({onlyFirst:u=!1}={})=>{let D=["[\\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(D,u?void 0:"g")}});var Vu=x((I3,xu)=>{var pF=Iu();xu.exports=(u)=>typeof u==="string"?u.replace(pF(),""):u});var Mu=x((x3,OD)=>{var Lu=(u)=>{if(Number.isNaN(u))return!1;if(u>=4352&&(u<=4447||u===9001||u===9002||11904<=u&&u<=12871&&u!==12351||12880<=u&&u<=19903||19968<=u&&u<=42182||43360<=u&&u<=43388||44032<=u&&u<=55203||63744<=u&&u<=64255||65040<=u&&u<=65049||65072<=u&&u<=65131||65281<=u&&u<=65376||65504<=u&&u<=65510||110592<=u&&u<=110593||127488<=u&&u<=127569||131072<=u&&u<=262141))return!0;return!1};OD.exports=Lu;OD.exports.default=Lu});var Ru=x((V3,Ou)=>{Ou.exports=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g}});var wu=x((L3,RD)=>{var nF=Vu(),sF=Mu(),aF=Ru(),ju=(u)=>{if(typeof u!=="string"||u.length===0)return 0;if(u=nF(u),u.length===0)return 0;u=u.replace(aF()," ");let D=0;for(let E=0;E=127&&F<=159)continue;if(F>=768&&F<=879)continue;if(F>65535)E++;D+=sF(F)?2:1}return D};RD.exports=ju;RD.exports.default=ju});var jD=x((M3,Su)=>{Su.exports=function(D,E,F){if(E.autopadding!==!0)return D;function C(B,A){return(E.autopaddingChar+B).slice(-A)}switch(F){case"percentage":return C(D,3);default:return D}}});var wD=x((O3,Tu)=>{Tu.exports=function(D,E){let F=Math.round(D*E.barsize),C=E.barsize-F;return E.barCompleteString.substr(0,F)+E.barGlue+E.barIncompleteString.substr(0,C)}});var SD=x((R3,bu)=>{bu.exports=function(D,E,F){function C(A){if(F)return F*Math.round(A/F);else return A}function B(A){return(E.autopaddingChar+A).slice(-2)}if(D>3600)return B(Math.floor(D/3600))+"h"+B(C(D%3600/60))+"m";else if(D>60)return B(Math.floor(D/60))+"m"+B(C(D%60))+"s";else if(D>10)return B(C(D))+"s";else return B(D)+"s"}});var TD=x((j3,yu)=>{var rF=wu(),iF=jD(),oF=wD(),tF=SD();yu.exports=function(D,E,F){let C=D.format,B=D.formatTime||tF,A=D.formatValue||iF,$=D.formatBar||oF,J=Math.floor(E.progress*100)+"",G=E.stopTime||Date.now(),X=Math.round((G-E.startTime)/1000),Y=Object.assign({},F,{bar:$(E.progress,D),percentage:A(J,D,"percentage"),total:A(E.total,D,"total"),value:A(E.value,D,"value"),eta:A(E.eta,D,"eta"),eta_formatted:B(E.eta,D,5),duration:A(X,D,"duration"),duration_formatted:B(X,D,1)});C=C.replace(/\{(\w+)\}/g,function(_,U){if(typeof Y[U]<"u")return Y[U];return _});let Z=Math.max(0,E.maxWidth-rF(C)-2),K=Math.floor(Z/2);switch(D.align){case"right":C=Z>0?" ".repeat(Z)+C:C;break;case"center":C=K>0?" ".repeat(K)+C:C;break;case"left":default:break}return C}});var JD=x((w3,vu)=>{function H(u,D){if(typeof u>"u"||u===null)return D;else return u}vu.exports={parse:function(D,E){let F={},C=Object.assign({},E,D);return F.throttleTime=1000/H(C.fps,10),F.stream=H(C.stream,process.stderr),F.terminal=H(C.terminal,null),F.clearOnComplete=H(C.clearOnComplete,!1),F.stopOnComplete=H(C.stopOnComplete,!1),F.barsize=H(C.barsize,40),F.align=H(C.align,"left"),F.hideCursor=H(C.hideCursor,!1),F.linewrap=H(C.linewrap,!1),F.barGlue=H(C.barGlue,""),F.barCompleteChar=H(C.barCompleteChar,"="),F.barIncompleteChar=H(C.barIncompleteChar,"-"),F.format=H(C.format,"progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}"),F.formatTime=H(C.formatTime,null),F.formatValue=H(C.formatValue,null),F.formatBar=H(C.formatBar,null),F.etaBufferLength=H(C.etaBuffer,10),F.etaAsynchronousUpdate=H(C.etaAsynchronousUpdate,!1),F.progressCalculationRelative=H(C.progressCalculationRelative,!1),F.synchronousUpdate=H(C.synchronousUpdate,!0),F.noTTYOutput=H(C.noTTYOutput,!1),F.notTTYSchedule=H(C.notTTYSchedule,2000),F.emptyOnZero=H(C.emptyOnZero,!1),F.forceRedraw=H(C.forceRedraw,!1),F.autopadding=H(C.autopadding,!1),F.gracefulExit=H(C.gracefulExit,!1),F},assignDerivedOptions:function(D){return D.barCompleteString=D.barCompleteChar.repeat(D.barsize+1),D.barIncompleteString=D.barIncompleteChar.repeat(D.barsize+1),D.autopaddingChar=D.autopadding?H(D.autopaddingChar," "):"",D}}});var bD=x((S3,hu)=>{var Pu=Nu(),eF=MD(),D8=TD(),u8=JD(),F8=p("events");hu.exports=class extends F8{constructor(D){super();this.options=u8.assignDerivedOptions(D),this.terminal=this.options.terminal?this.options.terminal:new eF(this.options.stream),this.value=0,this.startValue=0,this.total=100,this.lastDrawnString=null,this.startTime=null,this.stopTime=null,this.lastRedraw=Date.now(),this.eta=new Pu(this.options.etaBufferLength,0,0),this.payload={},this.isActive=!1,this.formatter=typeof this.options.format==="function"?this.options.format:D8}render(D=!1){let E={progress:this.getProgress(),eta:this.eta.getTime(),startTime:this.startTime,stopTime:this.stopTime,total:this.total,value:this.value,maxWidth:this.terminal.getWidth()};if(this.options.etaAsynchronousUpdate)this.updateETA();let F=this.formatter(this.options,E,this.payload);if(D||this.options.forceRedraw||this.options.noTTYOutput&&!this.terminal.isTTY()||this.lastDrawnString!=F)this.emit("redraw-pre"),this.terminal.cursorTo(0,null),this.terminal.write(F),this.terminal.clearRight(),this.lastDrawnString=F,this.lastRedraw=Date.now(),this.emit("redraw-post")}start(D,E,F){this.value=E||0,this.total=typeof D<"u"&&D>=0?D:100,this.startValue=E||0,this.payload=F||{},this.startTime=Date.now(),this.stopTime=null,this.lastDrawnString="",this.eta=new Pu(this.options.etaBufferLength,this.startTime,this.value),this.isActive=!0,this.emit("start",D,E)}stop(){this.isActive=!1,this.stopTime=Date.now(),this.emit("stop",this.total,this.value)}update(D,E={}){if(typeof D==="number")this.value=D,this.eta.update(Date.now(),D,this.total);let F=(typeof D==="object"?D:E)||{};this.emit("update",this.total,this.value);for(let C in F)this.payload[C]=F[C];if(this.value>=this.getTotal()&&this.options.stopOnComplete)this.stop()}getProgress(){let D=this.value/this.total;if(this.options.progressCalculationRelative)D=(this.value-this.startValue)/(this.total-this.startValue);if(isNaN(D))D=this.options&&this.options.emptyOnZero?0:1;return D=Math.min(Math.max(D,0),1),D}increment(D=1,E={}){if(typeof D==="object")this.update(this.value+1,D);else this.update(this.value+D,E)}getTotal(){return this.total}setTotal(D){if(typeof D<"u"&&D>=0)this.total=D}updateETA(){this.eta.update(Date.now(),this.value,this.total)}}});var gu=x((T3,fu)=>{var E8=bD(),C8=JD();fu.exports=class extends E8{constructor(D,E){super(C8.parse(D,E));if(this.timer=null,this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.options.synchronousUpdate=!1;this.schedulingRate=this.terminal.isTTY()?this.options.throttleTime:this.options.notTTYSchedule,this.sigintCallback=null}render(){if(this.timer)clearTimeout(this.timer),this.timer=null;if(super.render(),this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.terminal.newline();this.timer=setTimeout(this.render.bind(this),this.schedulingRate)}update(D,E){if(!this.timer)return;if(super.update(D,E),this.options.synchronousUpdate&&this.lastRedraw+this.options.throttleTime*2{var B8=MD(),A8=bD(),Z8=JD(),$8=p("events");mu.exports=class extends $8{constructor(D,E){super();this.bars=[],this.options=Z8.parse(D,E),this.options.synchronousUpdate=!1,this.terminal=this.options.terminal?this.options.terminal:new B8(this.options.stream),this.timer=null,this.isActive=!1,this.schedulingRate=this.terminal.isTTY()?this.options.throttleTime:this.options.notTTYSchedule,this.loggingBuffer=[],this.sigintCallback=null}create(D,E,F,C={}){let B=new A8(Object.assign({},this.options,{terminal:this.terminal},C));if(this.bars.push(B),this.options.noTTYOutput===!1&&this.terminal.isTTY()===!1)return B;if(this.sigintCallback===null&&this.options.gracefulExit)this.sigintCallback=this.stop.bind(this),process.once("SIGINT",this.sigintCallback),process.once("SIGTERM",this.sigintCallback);if(!this.isActive){if(this.options.hideCursor===!0)this.terminal.cursor(!1);if(this.options.linewrap===!1)this.terminal.lineWrapping(!1);this.timer=setTimeout(this.update.bind(this),this.schedulingRate)}return this.isActive=!0,B.start(D,E,F),this.emit("start"),B}remove(D){let E=this.bars.indexOf(D);if(E<0)return!1;return this.bars.splice(E,1),this.update(),this.terminal.newline(),this.terminal.clearBottom(),!0}update(){if(this.timer)clearTimeout(this.timer),this.timer=null;if(this.emit("update-pre"),this.terminal.cursorRelativeReset(),this.emit("redraw-pre"),this.loggingBuffer.length>0){this.terminal.clearLine();while(this.loggingBuffer.length>0)this.terminal.write(this.loggingBuffer.shift(),!0)}for(let D=0;D0)this.terminal.newline();this.bars[D].render()}if(this.emit("redraw-post"),this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.terminal.newline(),this.terminal.newline();if(this.timer=setTimeout(this.update.bind(this),this.schedulingRate),this.emit("update-post"),this.options.stopOnComplete&&!this.bars.find((D)=>D.isActive))this.stop()}stop(){if(clearTimeout(this.timer),this.timer=null,this.sigintCallback)process.removeListener("SIGINT",this.sigintCallback),process.removeListener("SIGTERM",this.sigintCallback),this.sigintCallback=null;if(this.isActive=!1,this.options.hideCursor===!0)this.terminal.cursor(!0);if(this.options.linewrap===!1)this.terminal.lineWrapping(!0);if(this.terminal.cursorRelativeReset(),this.emit("stop-pre-clear"),this.options.clearOnComplete)this.terminal.clearBottom();else{for(let D=0;D0)this.terminal.newline();this.bars[D].render(),this.bars[D].stop()}this.terminal.newline()}this.emit("stop")}log(D){this.loggingBuffer.push(D)}}});var du=x((y3,lu)=>{lu.exports={format:"progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"=",barIncompleteChar:"-"}});var nu=x((v3,pu)=>{pu.exports={format:" {bar} {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"█",barIncompleteChar:"░"}});var au=x((P3,su)=>{su.exports={format:" \x1B[90m{bar}\x1B[0m {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"█",barIncompleteChar:"░"}});var iu=x((h3,ru)=>{ru.exports={format:" {bar}■ {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"■",barIncompleteChar:" "}});var tu=x((f3,ou)=>{var J8=du(),K8=nu(),X8=au(),Y8=iu();ou.exports={legacy:J8,shades_classic:K8,shades_grey:X8,rect:Y8}});var uF=x((g3,DF)=>{var eu=gu(),G8=cu(),U8=tu(),k8=TD(),W8=jD(),_8=wD(),Q8=SD();DF.exports={Bar:eu,SingleBar:eu,MultiBar:G8,Presets:U8,Format:{Formatter:k8,BarFormat:_8,ValueFormat:W8,TimeFormat:Q8}}});import{join as $D,basename as Uu,extname as ku}from"node:path";import{randomUUID as cF}from"node:crypto";import{rm as Wu}from"node:fs/promises";import{spawn as DD}from"node:child_process";import{appendFile as xF}from"node:fs/promises";var QD=null;function ND(u){QD=u}async function h(u){if(QD)try{await xF(QD,u,"utf-8")}catch(D){}}async function n(){return new Promise((u)=>{let D=DD("ffmpeg",["-version"]);D.on("error",()=>u(!1)),D.on("close",(E)=>u(E===0))})}async function s(){return new Promise((u)=>{let D=DD("MP4Box",["-version"]);D.on("error",()=>u(!1)),D.on("close",(E)=>u(E===0))})}async function a(){let u=await new Promise((C)=>{let B=DD("ffmpeg",["-hide_banner","-encoders"]),A="";B.stdout.on("data",($)=>{A+=$.toString()}),B.on("error",()=>C("")),B.on("close",()=>C(A))}),D=(C)=>u.includes(C),E=[],F=[{acc:"nvenc",h264:D("h264_nvenc")?"h264_nvenc":void 0,av1:D("av1_nvenc")?"av1_nvenc":void 0},{acc:"qsv",h264:D("h264_qsv")?"h264_qsv":void 0,av1:D("av1_qsv")?"av1_qsv":void 0},{acc:"amf",h264:D("h264_amf")?"h264_amf":void 0,av1:D("av1_amf")?"av1_amf":void 0},{acc:"vaapi",h264:D("h264_vaapi")?"h264_vaapi":void 0,av1:D("av1_vaapi")?"av1_vaapi":void 0},{acc:"videotoolbox",h264:D("h264_videotoolbox")?"h264_videotoolbox":void 0,av1:D("av1_videotoolbox")?"av1_videotoolbox":void 0},{acc:"v4l2",h264:D("h264_v4l2m2m")?"h264_v4l2m2m":void 0,av1:D("av1_v4l2m2m")?"av1_v4l2m2m":void 0}];for(let C of F)if(C.h264||C.av1)E.push({accelerator:C.acc,h264Encoder:C.h264,av1Encoder:C.av1});return E}async function c(u,D,E){let C=` +import{createRequire as jF}from"node:module";var MF=Object.create;var{getPrototypeOf:LF,defineProperty:uu,getOwnPropertyNames:OF}=Object;var RF=Object.prototype.hasOwnProperty;var $D=(u,D,E)=>{E=u!=null?MF(LF(u)):{};let F=D||!u||!u.__esModule?uu(E,"default",{value:u,enumerable:!0}):E;for(let C of OF(u))if(!RF.call(F,C))uu(F,C,{get:()=>u[C],enumerable:!0});return F};var I=(u,D)=>()=>(D||u((D={exports:{}}).exports,D),D.exports);var n=jF(import.meta.url);var qu=I((j3,Hu)=>{class zu{constructor(u,D,E){this.etaBufferLength=u||100,this.valueBuffer=[E],this.timeBuffer=[D],this.eta="0"}update(u,D,E){this.valueBuffer.push(D),this.timeBuffer.push(u),this.calculate(E-D)}getTime(){return this.eta}calculate(u){let D=this.valueBuffer.length,E=Math.min(this.etaBufferLength,D),F=this.valueBuffer[D-1]-this.valueBuffer[D-E],C=this.timeBuffer[D-1]-this.timeBuffer[D-E],B=F/C;this.valueBuffer=this.valueBuffer.slice(-this.etaBufferLength),this.timeBuffer=this.timeBuffer.slice(-this.etaBufferLength);let A=Math.ceil(u/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}}Hu.exports=zu});var wD=I((w3,Iu)=>{var p=n("readline");class xu{constructor(u){this.stream=u,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(u){if(!this.stream.isTTY)return;if(u)this.stream.write("\x1B[?25h");else this.stream.write("\x1B[?25l")}cursorTo(u=null,D=null){if(!this.stream.isTTY)return;p.cursorTo(this.stream,u,D)}cursorRelative(u=null,D=null){if(!this.stream.isTTY)return;this.dy=this.dy+D,p.moveCursor(this.stream,u,D)}cursorRelativeReset(){if(!this.stream.isTTY)return;p.moveCursor(this.stream,0,-this.dy),p.cursorTo(this.stream,0,null),this.dy=0}clearRight(){if(!this.stream.isTTY)return;p.clearLine(this.stream,1)}clearLine(){if(!this.stream.isTTY)return;p.clearLine(this.stream,0)}clearBottom(){if(!this.stream.isTTY)return;p.clearScreenDown(this.stream)}newline(){this.stream.write(` +`),this.dy++}write(u,D=!1){if(this.linewrap===!0&&D===!1)this.stream.write(u.substr(0,this.getWidth()));else this.stream.write(u)}lineWrapping(u){if(!this.stream.isTTY)return;if(this.linewrap=u,u)this.stream.write("\x1B[?7h");else this.stream.write("\x1B[?7l")}isTTY(){return this.stream.isTTY===!0}getWidth(){return this.stream.columns||(this.stream.isTTY?80:200)}}Iu.exports=xu});var Mu=I((S3,Vu)=>{Vu.exports=({onlyFirst:u=!1}={})=>{let D=["[\\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(D,u?void 0:"g")}});var Ou=I((T3,Lu)=>{var eF=Mu();Lu.exports=(u)=>typeof u==="string"?u.replace(eF(),""):u});var ju=I((b3,SD)=>{var Ru=(u)=>{if(Number.isNaN(u))return!1;if(u>=4352&&(u<=4447||u===9001||u===9002||11904<=u&&u<=12871&&u!==12351||12880<=u&&u<=19903||19968<=u&&u<=42182||43360<=u&&u<=43388||44032<=u&&u<=55203||63744<=u&&u<=64255||65040<=u&&u<=65049||65072<=u&&u<=65131||65281<=u&&u<=65376||65504<=u&&u<=65510||110592<=u&&u<=110593||127488<=u&&u<=127569||131072<=u&&u<=262141))return!0;return!1};SD.exports=Ru;SD.exports.default=Ru});var Su=I((y3,wu)=>{wu.exports=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g}});var bu=I((v3,TD)=>{var D8=Ou(),u8=ju(),F8=Su(),Tu=(u)=>{if(typeof u!=="string"||u.length===0)return 0;if(u=D8(u),u.length===0)return 0;u=u.replace(F8()," ");let D=0;for(let E=0;E=127&&F<=159)continue;if(F>=768&&F<=879)continue;if(F>65535)E++;D+=u8(F)?2:1}return D};TD.exports=Tu;TD.exports.default=Tu});var bD=I((P3,yu)=>{yu.exports=function(D,E,F){if(E.autopadding!==!0)return D;function C(B,A){return(E.autopaddingChar+B).slice(-A)}switch(F){case"percentage":return C(D,3);default:return D}}});var yD=I((h3,vu)=>{vu.exports=function(D,E){let F=Math.round(D*E.barsize),C=E.barsize-F;return E.barCompleteString.substr(0,F)+E.barGlue+E.barIncompleteString.substr(0,C)}});var vD=I((f3,Pu)=>{Pu.exports=function(D,E,F){function C(A){if(F)return F*Math.round(A/F);else return A}function B(A){return(E.autopaddingChar+A).slice(-2)}if(D>3600)return B(Math.floor(D/3600))+"h"+B(C(D%3600/60))+"m";else if(D>60)return B(Math.floor(D/60))+"m"+B(C(D%60))+"s";else if(D>10)return B(C(D))+"s";else return B(D)+"s"}});var PD=I((g3,hu)=>{var E8=bu(),C8=bD(),B8=yD(),A8=vD();hu.exports=function(D,E,F){let C=D.format,B=D.formatTime||A8,A=D.formatValue||C8,Z=D.formatBar||B8,J=Math.floor(E.progress*100)+"",G=E.stopTime||Date.now(),X=Math.round((G-E.startTime)/1000),Y=Object.assign({},F,{bar:Z(E.progress,D),percentage:A(J,D,"percentage"),total:A(E.total,D,"total"),value:A(E.value,D,"value"),eta:A(E.eta,D,"eta"),eta_formatted:B(E.eta,D,5),duration:A(X,D,"duration"),duration_formatted:B(X,D,1)});C=C.replace(/\{(\w+)\}/g,function(K,_){if(typeof Y[_]<"u")return Y[_];return K});let $=Math.max(0,E.maxWidth-E8(C)-2),N=Math.floor($/2);switch(D.align){case"right":C=$>0?" ".repeat($)+C:C;break;case"center":C=N>0?" ".repeat(N)+C:C;break;case"left":default:break}return C}});var GD=I((m3,fu)=>{function H(u,D){if(typeof u>"u"||u===null)return D;else return u}fu.exports={parse:function(D,E){let F={},C=Object.assign({},E,D);return F.throttleTime=1000/H(C.fps,10),F.stream=H(C.stream,process.stderr),F.terminal=H(C.terminal,null),F.clearOnComplete=H(C.clearOnComplete,!1),F.stopOnComplete=H(C.stopOnComplete,!1),F.barsize=H(C.barsize,40),F.align=H(C.align,"left"),F.hideCursor=H(C.hideCursor,!1),F.linewrap=H(C.linewrap,!1),F.barGlue=H(C.barGlue,""),F.barCompleteChar=H(C.barCompleteChar,"="),F.barIncompleteChar=H(C.barIncompleteChar,"-"),F.format=H(C.format,"progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}"),F.formatTime=H(C.formatTime,null),F.formatValue=H(C.formatValue,null),F.formatBar=H(C.formatBar,null),F.etaBufferLength=H(C.etaBuffer,10),F.etaAsynchronousUpdate=H(C.etaAsynchronousUpdate,!1),F.progressCalculationRelative=H(C.progressCalculationRelative,!1),F.synchronousUpdate=H(C.synchronousUpdate,!0),F.noTTYOutput=H(C.noTTYOutput,!1),F.notTTYSchedule=H(C.notTTYSchedule,2000),F.emptyOnZero=H(C.emptyOnZero,!1),F.forceRedraw=H(C.forceRedraw,!1),F.autopadding=H(C.autopadding,!1),F.gracefulExit=H(C.gracefulExit,!1),F},assignDerivedOptions:function(D){return D.barCompleteString=D.barCompleteChar.repeat(D.barsize+1),D.barIncompleteString=D.barIncompleteChar.repeat(D.barsize+1),D.autopaddingChar=D.autopadding?H(D.autopaddingChar," "):"",D}}});var hD=I((c3,mu)=>{var gu=qu(),Z8=wD(),$8=PD(),J8=GD(),K8=n("events");mu.exports=class extends K8{constructor(D){super();this.options=J8.assignDerivedOptions(D),this.terminal=this.options.terminal?this.options.terminal:new Z8(this.options.stream),this.value=0,this.startValue=0,this.total=100,this.lastDrawnString=null,this.startTime=null,this.stopTime=null,this.lastRedraw=Date.now(),this.eta=new gu(this.options.etaBufferLength,0,0),this.payload={},this.isActive=!1,this.formatter=typeof this.options.format==="function"?this.options.format:$8}render(D=!1){let E={progress:this.getProgress(),eta:this.eta.getTime(),startTime:this.startTime,stopTime:this.stopTime,total:this.total,value:this.value,maxWidth:this.terminal.getWidth()};if(this.options.etaAsynchronousUpdate)this.updateETA();let F=this.formatter(this.options,E,this.payload);if(D||this.options.forceRedraw||this.options.noTTYOutput&&!this.terminal.isTTY()||this.lastDrawnString!=F)this.emit("redraw-pre"),this.terminal.cursorTo(0,null),this.terminal.write(F),this.terminal.clearRight(),this.lastDrawnString=F,this.lastRedraw=Date.now(),this.emit("redraw-post")}start(D,E,F){this.value=E||0,this.total=typeof D<"u"&&D>=0?D:100,this.startValue=E||0,this.payload=F||{},this.startTime=Date.now(),this.stopTime=null,this.lastDrawnString="",this.eta=new gu(this.options.etaBufferLength,this.startTime,this.value),this.isActive=!0,this.emit("start",D,E)}stop(){this.isActive=!1,this.stopTime=Date.now(),this.emit("stop",this.total,this.value)}update(D,E={}){if(typeof D==="number")this.value=D,this.eta.update(Date.now(),D,this.total);let F=(typeof D==="object"?D:E)||{};this.emit("update",this.total,this.value);for(let C in F)this.payload[C]=F[C];if(this.value>=this.getTotal()&&this.options.stopOnComplete)this.stop()}getProgress(){let D=this.value/this.total;if(this.options.progressCalculationRelative)D=(this.value-this.startValue)/(this.total-this.startValue);if(isNaN(D))D=this.options&&this.options.emptyOnZero?0:1;return D=Math.min(Math.max(D,0),1),D}increment(D=1,E={}){if(typeof D==="object")this.update(this.value+1,D);else this.update(this.value+D,E)}getTotal(){return this.total}setTotal(D){if(typeof D<"u"&&D>=0)this.total=D}updateETA(){this.eta.update(Date.now(),this.value,this.total)}}});var lu=I((l3,cu)=>{var X8=hD(),Y8=GD();cu.exports=class extends X8{constructor(D,E){super(Y8.parse(D,E));if(this.timer=null,this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.options.synchronousUpdate=!1;this.schedulingRate=this.terminal.isTTY()?this.options.throttleTime:this.options.notTTYSchedule,this.sigintCallback=null}render(){if(this.timer)clearTimeout(this.timer),this.timer=null;if(super.render(),this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.terminal.newline();this.timer=setTimeout(this.render.bind(this),this.schedulingRate)}update(D,E){if(!this.timer)return;if(super.update(D,E),this.options.synchronousUpdate&&this.lastRedraw+this.options.throttleTime*2{var G8=wD(),U8=hD(),W8=GD(),k8=n("events");du.exports=class extends k8{constructor(D,E){super();this.bars=[],this.options=W8.parse(D,E),this.options.synchronousUpdate=!1,this.terminal=this.options.terminal?this.options.terminal:new G8(this.options.stream),this.timer=null,this.isActive=!1,this.schedulingRate=this.terminal.isTTY()?this.options.throttleTime:this.options.notTTYSchedule,this.loggingBuffer=[],this.sigintCallback=null}create(D,E,F,C={}){let B=new U8(Object.assign({},this.options,{terminal:this.terminal},C));if(this.bars.push(B),this.options.noTTYOutput===!1&&this.terminal.isTTY()===!1)return B;if(this.sigintCallback===null&&this.options.gracefulExit)this.sigintCallback=this.stop.bind(this),process.once("SIGINT",this.sigintCallback),process.once("SIGTERM",this.sigintCallback);if(!this.isActive){if(this.options.hideCursor===!0)this.terminal.cursor(!1);if(this.options.linewrap===!1)this.terminal.lineWrapping(!1);this.timer=setTimeout(this.update.bind(this),this.schedulingRate)}return this.isActive=!0,B.start(D,E,F),this.emit("start"),B}remove(D){let E=this.bars.indexOf(D);if(E<0)return!1;return this.bars.splice(E,1),this.update(),this.terminal.newline(),this.terminal.clearBottom(),!0}update(){if(this.timer)clearTimeout(this.timer),this.timer=null;if(this.emit("update-pre"),this.terminal.cursorRelativeReset(),this.emit("redraw-pre"),this.loggingBuffer.length>0){this.terminal.clearLine();while(this.loggingBuffer.length>0)this.terminal.write(this.loggingBuffer.shift(),!0)}for(let D=0;D0)this.terminal.newline();this.bars[D].render()}if(this.emit("redraw-post"),this.options.noTTYOutput&&this.terminal.isTTY()===!1)this.terminal.newline(),this.terminal.newline();if(this.timer=setTimeout(this.update.bind(this),this.schedulingRate),this.emit("update-post"),this.options.stopOnComplete&&!this.bars.find((D)=>D.isActive))this.stop()}stop(){if(clearTimeout(this.timer),this.timer=null,this.sigintCallback)process.removeListener("SIGINT",this.sigintCallback),process.removeListener("SIGTERM",this.sigintCallback),this.sigintCallback=null;if(this.isActive=!1,this.options.hideCursor===!0)this.terminal.cursor(!0);if(this.options.linewrap===!1)this.terminal.lineWrapping(!0);if(this.terminal.cursorRelativeReset(),this.emit("stop-pre-clear"),this.options.clearOnComplete)this.terminal.clearBottom();else{for(let D=0;D0)this.terminal.newline();this.bars[D].render(),this.bars[D].stop()}this.terminal.newline()}this.emit("stop")}log(D){this.loggingBuffer.push(D)}}});var su=I((p3,nu)=>{nu.exports={format:"progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"=",barIncompleteChar:"-"}});var iu=I((n3,au)=>{au.exports={format:" {bar} {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"█",barIncompleteChar:"░"}});var ou=I((s3,ru)=>{ru.exports={format:" \x1B[90m{bar}\x1B[0m {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"█",barIncompleteChar:"░"}});var eu=I((a3,tu)=>{tu.exports={format:" {bar}■ {percentage}% | ETA: {eta}s | {value}/{total}",barCompleteChar:"■",barIncompleteChar:" "}});var uF=I((i3,DF)=>{var N8=su(),Q8=iu(),_8=ou(),z8=eu();DF.exports={legacy:N8,shades_classic:Q8,shades_grey:_8,rect:z8}});var CF=I((r3,EF)=>{var FF=lu(),H8=pu(),q8=uF(),x8=PD(),I8=bD(),V8=yD(),M8=vD();EF.exports={Bar:FF,SingleBar:FF,MultiBar:H8,Presets:q8,Format:{Formatter:x8,BarFormat:V8,ValueFormat:I8,TimeFormat:M8}}});import{join as YD,basename as Nu,extname as Qu}from"node:path";import{randomUUID as iF}from"node:crypto";import{rm as _u}from"node:fs/promises";import{spawn as s}from"node:child_process";import{appendFile as wF}from"node:fs/promises";var qD=null;function xD(u){qD=u}async function f(u){if(qD)try{await wF(qD,u,"utf-8")}catch(D){}}async function a(){return new Promise((u)=>{let D=s("ffmpeg",["-version"]);D.on("error",()=>u(!1)),D.on("close",(E)=>u(E===0))})}async function i(){return new Promise((u)=>{let D=s("MP4Box",["-version"]);D.on("error",()=>u(!1)),D.on("close",(E)=>u(E===0))})}async function r(){let u=await new Promise((C)=>{let B=s("ffmpeg",["-hide_banner","-encoders"]),A="";B.stdout.on("data",(Z)=>{A+=Z.toString()}),B.on("error",()=>C("")),B.on("close",()=>C(A))}),D=(C)=>u.includes(C),E=[],F=[{acc:"nvenc",h264:D("h264_nvenc")?"h264_nvenc":void 0,av1:D("av1_nvenc")?"av1_nvenc":void 0},{acc:"qsv",h264:D("h264_qsv")?"h264_qsv":void 0,av1:D("av1_qsv")?"av1_qsv":void 0},{acc:"amf",h264:D("h264_amf")?"h264_amf":void 0,av1:D("av1_amf")?"av1_amf":void 0},{acc:"vaapi",h264:D("h264_vaapi")?"h264_vaapi":void 0,av1:D("av1_vaapi")?"av1_vaapi":void 0},{acc:"videotoolbox",h264:D("h264_videotoolbox")?"h264_videotoolbox":void 0,av1:D("av1_videotoolbox")?"av1_videotoolbox":void 0},{acc:"v4l2",h264:D("h264_v4l2m2m")?"h264_v4l2m2m":void 0,av1:D("av1_v4l2m2m")?"av1_v4l2m2m":void 0}];for(let C of F)if(C.h264||C.av1)E.push({accelerator:C.acc,h264Encoder:C.h264,av1Encoder:C.av1});return E}async function o(){let D=(await new Promise((C)=>{let B=s("ffmpeg",["-hide_banner","-hwaccels"]),A="";B.stdout.on("data",(Z)=>A+=Z.toString()),B.on("error",()=>C("")),B.on("close",()=>C(A))})).split(` +`).map((C)=>C.trim()).filter(Boolean),E=[],F={cuda:"nvenc",qsv:"qsv",vaapi:"vaapi",videotoolbox:"videotoolbox",v4l2m2m:"v4l2",dxva2:"amf"};for(let C of D){let B=F[C];if(B)E.push({accelerator:B})}return E}async function l(u,D,E){let C=` === FFmpeg Command [${new Date().toISOString()}] === ffmpeg ${u.join(" ")} -`;return await h(C),new Promise((B,A)=>{let $=DD("ffmpeg",u),J="";$.stderr.on("data",(G)=>{let X=G.toString();if(J+=X,D&&E){let Y=X.match(/time=(\d{2}):(\d{2}):(\d{2}\.\d{2})/);if(Y){let Z=parseInt(Y[1]),K=parseInt(Y[2]),_=parseFloat(Y[3]),U=Z*3600+K*60+_,q=Math.min(100,U/E*100);D(q)}}}),$.on("error",(G)=>{h(`ERROR: ${G.message} -`),A(Error(`FFmpeg error: ${G.message}`))}),$.on("close",(G)=>{if(G===0){let Y=J.split(` -`).filter((Z)=>Z.trim()).slice(-10).join(` -`);h(`SUCCESS: Exit code ${G} +`;return await f(C),new Promise((B,A)=>{let Z=s("ffmpeg",u),J="";Z.stderr.on("data",(G)=>{let X=G.toString();if(J+=X,D&&E){let Y=X.match(/time=(\d{2}):(\d{2}):(\d{2}\.\d{2})/);if(Y){let $=parseInt(Y[1]),N=parseInt(Y[2]),K=parseFloat(Y[3]),_=$*3600+N*60+K,W=Math.min(100,_/E*100);D(W)}}}),Z.on("error",(G)=>{f(`ERROR: ${G.message} +`),A(Error(`FFmpeg error: ${G.message}`))}),Z.on("close",(G)=>{if(G===0){let Y=J.split(` +`).filter(($)=>$.trim()).slice(-10).join(` +`);f(`SUCCESS: Exit code ${G} --- Last 10 lines of output --- ${Y} -`),B()}else h(`FAILED: Exit code ${G} +`),B()}else f(`FAILED: Exit code ${G} --- Full error output --- ${J} `),A(Error(`FFmpeg failed with exit code ${G} -${J}`))})})}async function zD(u){let E=` +${J}`))})})}async function ID(u){let E=` === MP4Box Command [${new Date().toISOString()}] === MP4Box ${u.join(" ")} -`;return await h(E),new Promise((F,C)=>{let B=DD("MP4Box",u),A="",$="";B.stdout.on("data",(J)=>{A+=J.toString()}),B.stderr.on("data",(J)=>{$+=J.toString()}),B.on("error",(J)=>{h(`ERROR: ${J.message} -`),C(Error(`MP4Box error: ${J.message}`))}),B.on("close",(J)=>{if(J===0){let Y=(A||$).split(` -`).filter((Z)=>Z.trim()).slice(-10).join(` -`);h(`SUCCESS: Exit code ${J} +`;return await f(E),new Promise((F,C)=>{let B=s("MP4Box",u),A="",Z="";B.stdout.on("data",(J)=>{A+=J.toString()}),B.stderr.on("data",(J)=>{Z+=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||Z).split(` +`).filter(($)=>$.trim()).slice(-10).join(` +`);f(`SUCCESS: Exit code ${J} --- Last 10 lines of output --- ${Y} -`),F()}else{let G=$||A;h(`FAILED: Exit code ${J} +`),F()}else{let G=Z||A;f(`FAILED: Exit code ${J} --- Full error output --- ${G} `),C(Error(`MP4Box failed with exit code ${J} -${G}`))}})})}import{spawn as VF}from"node:child_process";async function r(u){return new Promise((D,E)=>{let F=VF("ffprobe",["-v","error","-show_entries","stream=width,height,duration,r_frame_rate,codec_name,codec_type,bit_rate","-show_entries","format=duration","-of","json",u]),C="";F.stdout.on("data",(B)=>{C+=B.toString()}),F.on("error",(B)=>{E(Error(`ffprobe error: ${B.message}`))}),F.on("close",(B)=>{if(B!==0){E(Error(`ffprobe failed with exit code ${B}`));return}try{let A=JSON.parse(C),$=A.streams.find((U)=>U.codec_type==="video"),J=A.streams.find((U)=>U.codec_type==="audio"),G=A.format;if(!$){E(Error("No video stream found in input file"));return}let X=30;if($.r_frame_rate){let[U,q]=$.r_frame_rate.split("/").map(Number);if(U&&q&&q!==0)X=U/q}let Y=parseFloat($.duration||G.duration||"0"),Z=A.streams.find((U)=>U.codec_type==="audio"&&U.bit_rate),K=Z?.bit_rate?Math.round(parseInt(Z.bit_rate)/1000):void 0,_=$.bit_rate?Math.round(parseInt($.bit_rate)/1000):void 0;D({width:$.width,height:$.height,duration:Y,fps:X,codec:$.codec_name,hasAudio:Boolean(J),audioBitrate:K,videoBitrate:_})}catch(A){E(Error(`Failed to parse ffprobe output: ${A}`))}})})}function CD(u,D=256){if(!u)return`${D}k`;let E=Math.min(u,D);if(E<=64)return"64k";if(E<=96)return"96k";if(E<=128)return"128k";if(E<=192)return"192k";return"256k"}function BD(u){let D=Math.floor(u/3600),E=Math.floor(u%3600/60),F=u%60;return`${String(D).padStart(2,"0")}:${String(E).padStart(2,"0")}:${F.toFixed(3).padStart(6,"0")}`}import{mkdir as LF,access as MF,constants as OF}from"node:fs/promises";async function l(u){try{await MF(u,OF.F_OK)}catch{await LF(u,{recursive:!0})}}function wF(u,D){let E=u*D;if(E<=230400)return 0.08;if(E<=409920)return 0.075;if(E<=921600)return 0.07;if(E<=2073600)return 0.065;if(E<=3686400)return 0.06;return 0.055}function v(u,D,E=30,F){let C=wF(u,D),B=Math.round(u*D*E*C/1000);if(F&&B>F)B=F;return`${B}k`}var HD=[{name:"360p",width:640,height:360,videoBitrate:v(640,360,30),audioBitrate:"192k"},{name:"480p",width:854,height:480,videoBitrate:v(854,480,30),audioBitrate:"192k"},{name:"720p",width:1280,height:720,videoBitrate:v(1280,720,30),audioBitrate:"192k"},{name:"1080p",width:1920,height:1080,videoBitrate:v(1920,1080,30),audioBitrate:"256k"},{name:"1440p",width:2560,height:1440,videoBitrate:v(2560,1440,30),audioBitrate:"256k"},{name:"2160p",width:3840,height:2160,videoBitrate:v(3840,2160,30),audioBitrate:"256k"}];function uD(u,D,E=30,F){let C=[],B=HD.filter((A)=>{return A.width<=u&&A.height<=D});for(let A of B)C.push({...A,videoBitrate:v(A.width,A.height,30,F),fps:30});return C}function SF(u,D,E){return{...u,name:`${u.name}-${D}`,videoBitrate:v(u.width,u.height,D,E),fps:D}}function eD(u){let E=u.trim().match(/^(\d+)p?(?:[@-](\d+))?$/i);if(!E)return null;let F=E[1]+"p",C=E[2]?parseInt(E[2]):30;return{resolution:F,fps:C}}function Du(u,D=30,E){let F=HD.find((C)=>C.name===u);if(!F)return null;if(D===30)return{...F,videoBitrate:v(F.width,F.height,30,E),fps:30};return SF(F,D,E)}function TF(u,D,E,F){let C=eD(u);if(!C)return{error:`Invalid profile format: ${u}. Use format like: 360, 720@60, 1080-60`};let B=Du(C.resolution,C.fps);if(!B)return{error:`Unknown resolution: ${C.resolution}. Available: 360, 480, 720, 1080, 1440, 2160`};if(B.width>D||B.height>E)return{error:`Source resolution (${D}x${E}) is lower than ${u} (${B.width}x${B.height})`};let A=120,$=C.fps,J;if(C.fps>F)$=Math.min(F,A),J=`Requested ${C.fps} FPS in ${u}, but source is ${F} FPS. Using ${$} FPS instead`;else if(C.fps>A)$=A,J=`Requested ${C.fps} FPS in ${u} exceeds maximum ${A} FPS. Using ${$} FPS instead`;return J?{warning:J,adjustedFps:$}:{}}function AD(u,D,E,F,C){let B=[],A=[],$=[];for(let J of u){let G=TF(J,D,E,F);if(G.error){A.push(G.error);continue}if(G.warning)$.push(G.warning);let X=eD(J);if(!X)continue;let Y=G.adjustedFps!==void 0?G.adjustedFps:X.fps,Z=Du(X.resolution,Y,C);if(Z)B.push(Z)}return{profiles:B,errors:A,warnings:$}}import{join as f}from"node:path";import{readdir as bF,unlink as uu,rmdir as yF,writeFile as Fu}from"node:fs/promises";async function Eu(u,D,E="00:00:00"){let F=f(D,"poster.jpg"),C=/^\d+(\.\d+)?$/.test(E)?E:E;return await c(["-ss",C,"-i",u,"-vframes","1","-q:v","2","-y",F]),F}async function Cu(u,D,E,F){let{width:C,height:B,interval:A,columns:$}=F,J=f(D,".thumbnails_temp");await l(J),await Fu(f(J,".keep"),"");let G=f(J,"thumb_%04d.jpg");await c(["-i",u,"-vf",`fps=1/${A},scale=${C}:${B}`,"-q:v","5",G]);let Y=(await bF(J)).filter((W)=>W.startsWith("thumb_")&&W.endsWith(".jpg")).sort();if(Y.length===0)throw Error("No thumbnails generated");let Z=Y.length,K=Math.ceil(Z/$),_=f(D,"thumbnails.jpg"),U=`tile=${$}x${K}`;await c(["-i",G,"-filter_complex",U,"-q:v","5",_]);let q=f(D,"thumbnails.vtt"),k=vF(Z,A,C,B,$,"thumbnails.jpg");await Fu(q,k);for(let W of Y)await uu(f(J,W));return await uu(f(J,".keep")),await yF(J),{spritePath:_,vttPath:q}}function vF(u,D,E,F,C,B){let A=`WEBVTT +${G}`))}})})}import{spawn as SF}from"node:child_process";async function t(u){return new Promise((D,E)=>{let F=SF("ffprobe",["-v","error","-show_entries","stream=width,height,duration,r_frame_rate,codec_name,codec_type,bit_rate","-show_entries","format=duration","-of","json",u]),C="";F.stdout.on("data",(B)=>{C+=B.toString()}),F.on("error",(B)=>{E(Error(`ffprobe error: ${B.message}`))}),F.on("close",(B)=>{if(B!==0){E(Error(`ffprobe failed with exit code ${B}`));return}try{let A=JSON.parse(C),Z=A.streams.find((_)=>_.codec_type==="video"),J=A.streams.find((_)=>_.codec_type==="audio"),G=A.format;if(!Z){E(Error("No video stream found in input file"));return}let X=30;if(Z.r_frame_rate){let[_,W]=Z.r_frame_rate.split("/").map(Number);if(_&&W&&W!==0)X=_/W}let Y=parseFloat(Z.duration||G.duration||"0"),$=A.streams.find((_)=>_.codec_type==="audio"&&_.bit_rate),N=$?.bit_rate?Math.round(parseInt($.bit_rate)/1000):void 0,K=Z.bit_rate?Math.round(parseInt(Z.bit_rate)/1000):void 0;D({width:Z.width,height:Z.height,duration:Y,fps:X,codec:Z.codec_name,hasAudio:Boolean(J),audioBitrate:N,videoBitrate:K})}catch(A){E(Error(`Failed to parse ffprobe output: ${A}`))}})})}function JD(u,D=256){if(!u)return`${D}k`;let E=Math.min(u,D);if(E<=64)return"64k";if(E<=96)return"96k";if(E<=128)return"128k";if(E<=192)return"192k";return"256k"}function KD(u){let D=Math.floor(u/3600),E=Math.floor(u%3600/60),F=u%60;return`${String(D).padStart(2,"0")}:${String(E).padStart(2,"0")}:${F.toFixed(3).padStart(6,"0")}`}import{mkdir as TF,access as bF,constants as yF}from"node:fs/promises";async function d(u){try{await bF(u,yF.F_OK)}catch{await TF(u,{recursive:!0})}}function hF(u,D){let E=u*D;if(E<=230400)return 0.08;if(E<=409920)return 0.075;if(E<=921600)return 0.07;if(E<=2073600)return 0.065;if(E<=3686400)return 0.06;return 0.055}function v(u,D,E=30,F){let C=hF(u,D),B=Math.round(u*D*E*C/1000);if(F&&B>F)B=F;return`${B}k`}var VD=[{name:"360p",width:640,height:360,videoBitrate:v(640,360,30),audioBitrate:"192k"},{name:"480p",width:854,height:480,videoBitrate:v(854,480,30),audioBitrate:"192k"},{name:"720p",width:1280,height:720,videoBitrate:v(1280,720,30),audioBitrate:"192k"},{name:"1080p",width:1920,height:1080,videoBitrate:v(1920,1080,30),audioBitrate:"256k"},{name:"1440p",width:2560,height:1440,videoBitrate:v(2560,1440,30),audioBitrate:"256k"},{name:"2160p",width:3840,height:2160,videoBitrate:v(3840,2160,30),audioBitrate:"256k"}];function CD(u,D,E=30,F){let C=[],B=VD.filter((A)=>{return A.width<=u&&A.height<=D});for(let A of B)C.push({...A,videoBitrate:v(A.width,A.height,30,F),fps:30});return C}function fF(u,D,E){return{...u,name:`${u.name}-${D}`,videoBitrate:v(u.width,u.height,D,E),fps:D}}function Fu(u){let E=u.trim().match(/^(\d+)p?(?:[@-](\d+))?$/i);if(!E)return null;let F=E[1]+"p",C=E[2]?parseInt(E[2]):30;return{resolution:F,fps:C}}function Eu(u,D=30,E){let F=VD.find((C)=>C.name===u);if(!F)return null;if(D===30)return{...F,videoBitrate:v(F.width,F.height,30,E),fps:30};return fF(F,D,E)}function gF(u,D,E,F){let C=Fu(u);if(!C)return{error:`Invalid profile format: ${u}. Use format like: 360, 720@60, 1080-60`};let B=Eu(C.resolution,C.fps);if(!B)return{error:`Unknown resolution: ${C.resolution}. Available: 360, 480, 720, 1080, 1440, 2160`};if(B.width>D||B.height>E)return{error:`Source resolution (${D}x${E}) is lower than ${u} (${B.width}x${B.height})`};let A=120,Z=C.fps,J;if(C.fps>F)Z=Math.min(F,A),J=`Requested ${C.fps} FPS in ${u}, but source is ${F} FPS. Using ${Z} FPS instead`;else if(C.fps>A)Z=A,J=`Requested ${C.fps} FPS in ${u} exceeds maximum ${A} FPS. Using ${Z} FPS instead`;return J?{warning:J,adjustedFps:Z}:{}}function XD(u,D,E,F,C){let B=[],A=[],Z=[];for(let J of u){let G=gF(J,D,E,F);if(G.error){A.push(G.error);continue}if(G.warning)Z.push(G.warning);let X=Fu(J);if(!X)continue;let Y=G.adjustedFps!==void 0?G.adjustedFps:X.fps,$=Eu(X.resolution,Y,C);if($)B.push($)}return{profiles:B,errors:A,warnings:Z}}import{join as g}from"node:path";import{readdir as mF,unlink as Cu,rmdir as cF,writeFile as Bu}from"node:fs/promises";async function Au(u,D,E="00:00:00"){let F=g(D,"poster.jpg"),C=/^\d+(\.\d+)?$/.test(E)?E:E;return await l(["-ss",C,"-i",u,"-vframes","1","-q:v","2","-y",F]),F}async function Zu(u,D,E,F){let{width:C,height:B,interval:A,columns:Z}=F,J=g(D,".thumbnails_temp");await d(J),await Bu(g(J,".keep"),"");let G=g(J,"thumb_%04d.jpg");await l(["-i",u,"-vf",`fps=1/${A},scale=${C}:${B}`,"-q:v","5",G]);let Y=(await mF(J)).filter((k)=>k.startsWith("thumb_")&&k.endsWith(".jpg")).sort();if(Y.length===0)throw Error("No thumbnails generated");let $=Y.length,N=Math.ceil($/Z),K=g(D,"thumbnails.jpg"),_=`tile=${Z}x${N}`;await l(["-i",G,"-filter_complex",_,"-q:v","5",K]);let W=g(D,"thumbnails.vtt"),U=lF($,A,C,B,Z,"thumbnails.jpg");await Bu(W,U);for(let k of Y)await Cu(g(J,k));return await Cu(g(J,".keep")),await cF(J),{spritePath:K,vttPath:W}}function lF(u,D,E,F,C,B){let A=`WEBVTT -`;for(let $=0;$ ${BD(G)} -`,A+=`${B}#xywh=${Z},${K},${E},${F} +`;for(let Z=0;Z ${KD(G)} +`,A+=`${B}#xywh=${$},${N},${E},${F} -`}return A}import{join as PF}from"node:path";function hF(u,D,E){if(E)if(D==="h264")return 32;else return 42;else if(D==="h264"){if(u<=360)return 25;if(u<=480)return 24;if(u<=720)return 23;if(u<=1080)return 22;if(u<=1440)return 21;return 20}else{if(u<=360)return 40;if(u<=480)return 38;if(u<=720)return 35;if(u<=1080)return 32;if(u<=1440)return 30;return 28}}async function Bu(u,D,E,F,C,B,A,$,J,G,X,Y){let Z=PF(D,`video_${J}_${E.name}.mp4`),K=["-y","-i",u,"-c:v",F],_=F.includes("nvenc")||F.includes("qsv")||F.includes("amf")||F.includes("vaapi")||F.includes("videotoolbox")||F.includes("v4l2"),U;if(_&&G?.cq!==void 0)U=G.cq;else if(!_&&G?.crf!==void 0)U=G.crf;else U=hF(E.height,J,_);if(F==="h264_nvenc")K.push("-rc:v","vbr"),K.push("-cq",String(U)),K.push("-preset",C),K.push("-2pass","0");else if(F==="av1_nvenc")K.push("-rc:v","vbr"),K.push("-cq",String(U)),K.push("-preset",C),K.push("-2pass","0");else if(F==="av1_qsv")K.push("-preset",C),K.push("-global_quality",String(U));else if(F==="h264_qsv")K.push("-preset",C),K.push("-global_quality",String(U));else if(F==="av1_amf")K.push("-quality","balanced"),K.push("-rc","cqp"),K.push("-qp_i",String(U)),K.push("-qp_p",String(U));else if(F==="h264_amf")K.push("-quality","balanced"),K.push("-rc","cqp"),K.push("-qp_i",String(U)),K.push("-qp_p",String(U));else if(F==="libsvtav1")K.push("-crf",String(U)),K.push("-preset",C),K.push("-svtav1-params","tune=0:enable-overlays=1");else if(F==="libx264")K.push("-crf",String(U)),K.push("-preset",C);else K.push("-preset",C);let q=J==="av1"?0.6:1,k=Math.round(parseInt(E.videoBitrate)*q*1.5);K.push("-maxrate",`${k}k`),K.push("-bufsize",`${k*2}k`);let W=E.fps||30,z=Math.round(W*A);K.push("-g",String(z),"-keyint_min",String(z),"-sc_threshold","0");let V=[`scale=${E.width}:${E.height}`];if(X){if(X.deinterlace)V.push("yadif");if(X.denoise)V.push("hqdn3d");if(X.customFilters)V.push(...X.customFilters)}K.push("-vf",V.join(","));let j=parseInt(E.audioBitrate)||256,w=CD($,j);if(K.push("-c:a","aac","-b:a",w),X?.audioNormalize)K.push("-af","loudnorm");return K.push("-f","mp4",Z),await c(K,Y,B),Z}async function Au(u,D,E,F,C,B,A,$,J,G,X,Y,Z,K){let _=new Map;if(J&&E.length>1)for(let U=0;UBu(u,D,z,F,C,B,A,$,X,Y,Z,(V)=>{if(K)K(z.name,V)}));(await Promise.all(k)).forEach((z,V)=>{let j=q[V];_.set(j.name,z)})}else for(let U of E){let q=await Bu(u,D,U,F,C,B,A,$,X,Y,Z,(k)=>{if(K)K(U.name,k)});_.set(U.name,q)}return _}import{join as M}from"node:path";import{readdir as Xu,rename as E3,mkdir as C3,writeFile as VD}from"node:fs/promises";import{readFile as qD,writeFile as ID}from"node:fs/promises";async function Zu(u){let D=await qD(u,"utf-8");D=D.replace(/\/\/>/g,"/>"),D=D.replace(/\/\s+\/>/g,"/>"),D=D.replace(/(]+)\s+\/>/g,"$1/>"),D=D.replace(/]+)\/>\s*<\/Representation>/g,""),D=D.replace(/]+)\/>\s*(]*\/>)/g,` +`}return A}import{join as dF}from"node:path";function pF(u,D,E){if(E)if(D==="h264")return 32;else return 42;else if(D==="h264"){if(u<=360)return 25;if(u<=480)return 24;if(u<=720)return 23;if(u<=1080)return 22;if(u<=1440)return 21;return 20}else{if(u<=360)return 40;if(u<=480)return 38;if(u<=720)return 35;if(u<=1080)return 32;if(u<=1440)return 30;return 28}}async function $u(u,D,E,F,C,B,A,Z,J,G,X,Y,$){let N=dF(D,`video_${J}_${E.name}.mp4`),K=["-y"];if(Y){if(Y==="nvenc")K.push("-hwaccel","cuda","-hwaccel_output_format","cuda");else if(Y==="qsv")K.push("-hwaccel","qsv");else if(Y==="vaapi")K.push("-hwaccel","vaapi");else if(Y==="videotoolbox")K.push("-hwaccel","videotoolbox");else if(Y==="v4l2")K.push("-hwaccel","v4l2")}K.push("-i",u,"-c:v",F);let _=F.includes("nvenc")||F.includes("qsv")||F.includes("amf")||F.includes("vaapi")||F.includes("videotoolbox")||F.includes("v4l2"),W;if(_&&G?.cq!==void 0)W=G.cq;else if(!_&&G?.crf!==void 0)W=G.crf;else W=pF(E.height,J,_);if(F==="h264_nvenc")K.push("-rc:v","vbr"),K.push("-cq",String(W)),K.push("-preset",C),K.push("-2pass","0");else if(F==="av1_nvenc")K.push("-rc:v","vbr"),K.push("-cq",String(W)),K.push("-preset",C),K.push("-2pass","0");else if(F==="av1_qsv")K.push("-preset",C),K.push("-global_quality",String(W));else if(F==="h264_qsv")K.push("-preset",C),K.push("-global_quality",String(W));else if(F==="av1_amf")K.push("-quality","balanced"),K.push("-rc","cqp"),K.push("-qp_i",String(W)),K.push("-qp_p",String(W));else if(F==="h264_amf")K.push("-quality","balanced"),K.push("-rc","cqp"),K.push("-qp_i",String(W)),K.push("-qp_p",String(W));else if(F==="libsvtav1")K.push("-crf",String(W)),K.push("-preset",C),K.push("-svtav1-params","tune=0:enable-overlays=1");else if(F==="libx264")K.push("-crf",String(W)),K.push("-preset",C);else K.push("-preset",C);let U=J==="av1"?0.6:1,k=Math.round(parseInt(E.videoBitrate)*U*1.5);K.push("-maxrate",`${k}k`),K.push("-bufsize",`${k*2}k`);let q=E.fps||30,V=Math.round(q*A);K.push("-g",String(V),"-keyint_min",String(V),"-sc_threshold","0");let L=[`scale=${E.width}:${E.height}`];if(X){if(X.deinterlace)L.push("yadif");if(X.denoise)L.push("hqdn3d");if(X.customFilters)L.push(...X.customFilters)}K.push("-vf",L.join(","));let y=parseInt(E.audioBitrate)||256,P=JD(Z,y);if(K.push("-c:a","aac","-b:a",P),X?.audioNormalize)K.push("-af","loudnorm");return K.push("-f","mp4",N),await l(K,$,B),N}async function Ju(u,D,E,F,C,B,A,Z,J,G,X,Y,$,N,K){let _=new Map;if(J&&E.length>1)for(let W=0;W$u(u,D,V,F,C,B,A,Z,X,Y,$,N,(L)=>{if(K)K(V.name,L)}));(await Promise.all(k)).forEach((V,L)=>{let y=U[L];_.set(y.name,V)})}else for(let W of E){let U=await $u(u,D,W,F,C,B,A,Z,X,Y,$,N,(k)=>{if(K)K(W.name,k)});_.set(W.name,U)}return _}import{join as O}from"node:path";import{readdir as Uu,rename as G3,mkdir as U3,writeFile as RD}from"node:fs/promises";import{readFile as MD,writeFile as LD}from"node:fs/promises";async function Ku(u){let D=await MD(u,"utf-8");D=D.replace(/\/\/>/g,"/>"),D=D.replace(/\/\s+\/>/g,"/>"),D=D.replace(/(]+)\s+\/>/g,"$1/>"),D=D.replace(/]+)\/>\s*<\/Representation>/g,""),D=D.replace(/]+)\/>\s*(]*\/>)/g,` $2 `),D=D.replace(/]+)>\s*(?=<(?:Representation|\/AdaptationSet))/g,` -`),await ID(u,D,"utf-8")}async function $u(u,D,E){let F=await qD(u,"utf-8");F=F.replace(/media="\$RepresentationID\$_\$Number\$\.m4s"/g,'media="$RepresentationID$/$RepresentationID$_$Number$.m4s"'),F=F.replace(/initialization="\$RepresentationID\$_\.mp4"/g,'initialization="$RepresentationID$/$RepresentationID$_.mp4"'),await ID(u,F,"utf-8")}async function Ju(u){let E=(await qD(u,"utf-8")).split(` -`),F=[],C=0;while(C")){let Z=E[C];if(Z.includes(""))Y=!1}else if(Z.includes("0&&X.length>0)F.push(B),J.forEach((Z)=>F.push(Z)),G.forEach((Z)=>F.push(Z)),F.push(" "),F.push(B),J.forEach((Z)=>F.push(Z)),X.forEach((Z)=>F.push(Z)),F.push(" ");else{F.push(B);for(let Z=A+1;Z")){let $=E[C];if($.includes(""))Y=!1}else if($.includes("0&&X.length>0)F.push(B),J.forEach(($)=>F.push($)),G.forEach(($)=>F.push($)),F.push(" "),F.push(B),J.forEach(($)=>F.push($)),X.forEach(($)=>F.push($)),F.push(" ");else{F.push(B);for(let $=A+1;$z.endsWith(".m4s")).sort((z,V)=>{let j=parseInt(z.match(/_(\d+)\.m4s$/)?.[1]||"0"),w=parseInt(V.match(/_(\d+)\.m4s$/)?.[1]||"0");return j-w}),U=K.find((z)=>z.endsWith("_.mp4"));if(!U||_.length===0)continue;let q=xD(_,U,E),k=M(Z,"playlist.m3u8");await VD(k,q,"utf-8");let W=parseInt(X.videoBitrate)*1000;A.push({path:`${Y}/playlist.m3u8`,bandwidth:W,resolution:`${X.width}x${X.height}`,fps:X.fps||30})}let $,J=[];if(C){let X=M(u,"audio"),Y=[];try{Y=await Xu(X)}catch{Y=[]}if(J=Y.filter((Z)=>Z.endsWith(".m4s")).sort((Z,K)=>{let _=parseInt(Z.match(/_(\d+)\.m4s$/)?.[1]||"0"),U=parseInt(K.match(/_(\d+)\.m4s$/)?.[1]||"0");return _-U}),$=Y.find((Z)=>Z.endsWith("_.mp4")),$&&J.length>0){let Z=xD(J,$,E);await VD(M(X,"playlist.m3u8"),Z,"utf-8")}}let G=Ku(A,C&&$!==void 0&&J.length>0);return await VD(B,G,"utf-8"),B}async function LD(u){let{input:D,outputDir:E,segmentDuration:F=2,profiles:C,customProfiles:B,codec:A="dual",format:$="both",useNvenc:J,hardwareAccelerator:G,quality:X,generateThumbnails:Y=!0,thumbnailConfig:Z={},generatePoster:K=!0,posterTimecode:_="00:00:00",parallel:U=!0,onProgress:q}=u,k=$D("/tmp",`dash-converter-${cF()}`);await l(k);let W=Uu(D,ku(D)),z=$D(E,W);await l(z);let V=$D(z,"conversion.log");ND(V);let{writeFile:j}=await import("node:fs/promises"),w=`=========================================== +`}return E}async function nF(u,D,E,F,C,B){let A=O(D,"manifest.mpd"),Z=["-dash",String(F*1000),"-frag",String(F*1000),"-rap","-segment-timeline","-segment-name","$RepresentationID$_$Number$","-out",A],J=!0;for(let[G,X]of u.entries())for(let Y of E){let $=X.get(Y.name);if(!$)throw Error(`MP4 file not found for profile: ${Y.name}, codec: ${G}`);let N=C==="dual"?`${Y.name}-${G}`:Y.name;if(Z.push(`${$}#video:id=${N}`),J&&B)Z.push(`${$}#audio:id=audio`),J=!1}if(await ID(Z),await sF(D,E,C,B),await Xu(A,E,C),C==="dual")await Yu(A);return await Ku(A),A}async function sF(u,D,E,F){let{readdir:C,rename:B,mkdir:A}=await import("node:fs/promises"),Z=[];if(E==="h264"||E==="dual")Z.push("h264");if(E==="av1"||E==="dual")Z.push("av1");let J=[];for(let Y of Z)for(let $ of D){let N=E==="dual"?`${$.name}-${Y}`:$.name;J.push(N);let K=O(u,N);await A(K,{recursive:!0})}let G=O(u,"audio");if(F)await A(G,{recursive:!0});let X=await C(u);for(let Y of X){if(Y==="manifest.mpd")continue;if(F&&(Y.startsWith("audio_")||Y==="audio_init.m4s")){let $=O(u,Y),N=O(G,Y);await B($,N);continue}for(let $ of J)if(Y.startsWith(`${$}_`)){let N=O(u,Y),K=O(u,$,Y);await B(N,K);break}}}async function Wu(u,D,E,F,C,B,A){let Z,J;if(B==="dash"||B==="both")Z=await nF(u,D,E,F,C,A);if(B==="hls"||B==="both")J=await aF(D,E,F,C,A);return{manifestPath:Z,hlsManifestPath:J}}async function aF(u,D,E,F,C){let B=O(u,"master.m3u8"),A=[];for(let X of D){let Y=F==="dual"?`${X.name}-h264`:X.name,$=O(u,Y),N=await Uu($),K=N.filter((q)=>q.endsWith(".m4s")).sort((q,V)=>{let L=parseInt(q.match(/_(\d+)\.m4s$/)?.[1]||"0"),y=parseInt(V.match(/_(\d+)\.m4s$/)?.[1]||"0");return L-y}),_=N.find((q)=>q.endsWith("_.mp4"));if(!_||K.length===0)continue;let W=OD(K,_,E),U=O($,"playlist.m3u8");await RD(U,W,"utf-8");let k=parseInt(X.videoBitrate)*1000;A.push({path:`${Y}/playlist.m3u8`,bandwidth:k,resolution:`${X.width}x${X.height}`,fps:X.fps||30})}let Z,J=[];if(C){let X=O(u,"audio"),Y=[];try{Y=await Uu(X)}catch{Y=[]}if(J=Y.filter(($)=>$.endsWith(".m4s")).sort(($,N)=>{let K=parseInt($.match(/_(\d+)\.m4s$/)?.[1]||"0"),_=parseInt(N.match(/_(\d+)\.m4s$/)?.[1]||"0");return K-_}),Z=Y.find(($)=>$.endsWith("_.mp4")),Z&&J.length>0){let $=OD(J,Z,E);await RD(O(X,"playlist.m3u8"),$,"utf-8")}}let G=Gu(A,C&&Z!==void 0&&J.length>0);return await RD(B,G,"utf-8"),B}async function jD(u){let{input:D,outputDir:E,segmentDuration:F=2,profiles:C,customProfiles:B,codec:A="dual",format:Z="both",hardwareDecoder:J,hardwareAccelerator:G,quality:X,generateThumbnails:Y=!0,thumbnailConfig:$={},generatePoster:N=!0,posterTimecode:K="00:00:00",parallel:_=!0,onProgress:W}=u,U=YD("/tmp",`dash-converter-${iF()}`);await d(U);let k=Nu(D,Qu(D)),q=YD(E,k);await d(q);let V=YD(q,"conversion.log");xD(V);let{writeFile:L}=await import("node:fs/promises"),y=`=========================================== DASH Conversion Log Started: ${new Date().toISOString()} Input: ${D} -Output: ${z} +Output: ${q} Codec: ${A} -Format: ${$} +Format: ${Z} =========================================== -`;await j(V,w,"utf-8");try{return await lF(D,E,k,F,C,B,A,$,J,G,X,Y,Z,K,_,U,q)}finally{let{appendFile:GD}=await import("node:fs/promises");try{await GD(V,` +`;await L(V,y,"utf-8");try{return await rF(D,E,U,F,C,B,A,Z,G,J,X,Y,$,N,K,_,W)}finally{let{appendFile:P}=await import("node:fs/promises");try{await P(V,` Completed: ${new Date().toISOString()} -`,"utf-8")}catch(UD){}try{await Wu(k,{recursive:!0,force:!0})}catch(UD){console.warn(`Warning: Failed to cleanup temp directory: ${k}`)}}}async function lF(u,D,E,F,C,B,A,$,J,G,X,Y,Z,K,_,U,q){if(!await n())throw Error("FFmpeg is not installed or not in PATH");if(!await s())throw Error("MP4Box is not installed or not in PATH. Install gpac package.");let k=(N,I,WD,_D)=>{if(q)q({stage:N,percent:I,message:WD,currentProfile:_D})};k("analyzing",0,"Analyzing input video...");let W=await r(u),z=W.hasAudio,V=G&&G!=="auto"?G:J===!0?"nvenc":J===!1?"cpu":"auto",j=await a(),{selected:w,h264Encoder:GD,av1Encoder:UD,warnings:lD}=dF(j,V,A);if(lD.length>0)for(let N of lD)console.warn(`⚠️ ${N}`);let $F=j.some((N)=>N.av1Encoder),m=A;if(A==="dual"&&!$F)console.warn("⚠️ AV1 hardware encoder not detected. Switching to H.264 only."),m="h264";let O;if(B&&B.length>0){let N=AD(B,W.width,W.height,W.fps,W.videoBitrate);if(N.errors.length>0){console.warn(` -❌ Profile errors:`);for(let I of N.errors)console.warn(` - ${I}`);console.warn("")}if(N.warnings.length>0){console.warn(` -⚠️ Profile warnings:`);for(let I of N.warnings)console.warn(` - ${I}`);console.warn("")}if(O=N.profiles,O.length===0)throw Error("No valid profiles found in custom list. Check errors above.")}else if(C)O=C;else O=uD(W.width,W.height,W.fps,W.videoBitrate);if(O.length===0)throw Error("No suitable profiles found for input video resolution");let JF=Uu(u,ku(u)),t=$D(D,JF);try{await Wu(t,{recursive:!0,force:!0})}catch(N){}await l(t);let P=[];if(m==="h264"||m==="dual"){let N=GD||"libx264",I=Gu(N,"h264");P.push({type:"h264",codec:N,preset:I})}if(m==="av1"||m==="dual"){let N=UD||"libsvtav1",I=Gu(N,"av1");P.push({type:"av1",codec:N,preset:I})}let KF=P.map((N)=>N.type.toUpperCase()).join(" + "),XF=w==="cpu"?"CPU":w.toUpperCase();k("analyzing",20,`Using ${KF} encoding (${XF})`,void 0);let YF=w==="cpu"?2:3,kD=new Map;for(let N=0;N{let R8=O.findIndex((QF)=>QF.name===e),iD=25+aD*40,oD=rD/100*(40*kF/O.length);if(k("encoding",iD+oD,`Encoding ${I.toUpperCase()} ${e}...`,`${I}-${e}`),q)q({stage:"encoding",percent:iD+oD,currentProfile:`${I}-${e}`,profilePercent:rD,message:`Encoding ${I.toUpperCase()} ${e}...`})});kD.set(I,_F)}k("encoding",65,"Stage 1 complete: All codecs and profiles encoded"),k("encoding",70,"Stage 2: Creating segments and manifests...");let{manifestPath:GF,hlsManifestPath:UF}=await Yu(kD,t,O,F,m,$,z),dD=[];for(let N of kD.values())dD.push(...Array.from(N.values()));k("encoding",80,"Stage 2 complete: All formats packaged");let pD,nD;if(Y){k("thumbnails",80,"Generating thumbnail sprites...");let N={width:Z.width||160,height:Z.height||90,interval:Z.interval||1,columns:Z.columns||10},I=await Cu(u,t,W.duration,N);pD=I.spritePath,nD=I.vttPath,k("thumbnails",90,"Thumbnails generated")}let sD;if(K)k("thumbnails",92,"Generating poster image..."),sD=await Eu(u,t,_),k("thumbnails",95,"Poster generated");return k("manifest",95,"Finalizing..."),k("complete",100,"Conversion complete!"),{manifestPath:GF,hlsManifestPath:UF,videoPaths:dD,thumbnailSpritePath:pD,thumbnailVttPath:nD,posterPath:sD,duration:W.duration,profiles:O,usedNvenc:P.some((N)=>N.codec.includes("nvenc")),selectedAccelerator:w,codecType:m,format:$}}var ZD={nvenc:100,qsv:90,amf:80,vaapi:70,videotoolbox:65,v4l2:60,cpu:1};function dF(u,D,E){let F=E==="h264"||E==="dual",C=E==="av1"||E==="dual",B=[],A=new Set(["nvenc","qsv","amf"]),$=u.filter((k)=>F&&k.h264Encoder||C&&k.av1Encoder),J=$.filter((k)=>A.has(k.accelerator)),G=(k)=>$.find((W)=>W.accelerator===k),X;if(D!=="auto"){if(D==="cpu")X=void 0;else if(!A.has(D))B.push(`Ускоритель "${D}" пока не поддерживается, использую CPU`);else if(X=G(D),!X)throw Error(`Аппаратный ускоритель "${D}" недоступен в системе`)}else if(X=(J.length>0?J:[]).sort((W,z)=>(ZD[z.accelerator]||0)-(ZD[W.accelerator]||0))[0],!X&&$.length>0)B.push("Доступен аппаратный ускоритель, но он пока не поддерживается пайплайном, использую CPU");let Z=(J.length>0?J:[]).sort((k,W)=>(ZD[W.accelerator]||0)-(ZD[k.accelerator]||0)),K=(k)=>{let W=k==="h264"?X?.h264Encoder:X?.av1Encoder;if(W)return{encoder:W,accel:X?.accelerator};let z=Z.find((V)=>k==="h264"?V.h264Encoder:V.av1Encoder);if(z){if(D!=="auto"&&X)B.push(`Выбранный ускоритель "${X.accelerator}" не поддерживает ${k.toUpperCase()}, использую ${z.accelerator}`);return{encoder:k==="h264"?z.h264Encoder:z.av1Encoder,accel:z.accelerator}}if(D!=="auto"&&D!=="cpu")B.push(`Ускоритель "${D}" не поддерживает ${k.toUpperCase()}, использую CPU`);return{encoder:void 0,accel:"cpu"}},_=F?K("h264"):{encoder:void 0,accel:X?.accelerator},U=C?K("av1"):{encoder:void 0,accel:X?.accelerator};return{selected:X?.accelerator||_.accel||U.accel||"cpu",h264Encoder:_.encoder,av1Encoder:U.encoder,warnings:B}}function Gu(u,D){if(u.includes("nvenc"))return"p4";if(u.includes("qsv"))return"medium";if(u.includes("amf"))return"balanced";if(u.includes("vaapi"))return"5";if(u.includes("videotoolbox"))return"medium";if(u.includes("v4l2"))return"medium";if(u==="libsvtav1")return"8";if(u==="libx264")return"medium";return D==="av1"?"8":"medium"}var PD=ED(uF(),1);import{statSync as N8}from"node:fs";var Q=process.argv.slice(2),FD,gD,R="dual",i="both",mD=[],S,T,b,y,EF;for(let u=0;uF.trim()).filter((F)=>F.length>0)}else if(Q[u]==="-p"||Q[u]==="--poster")gD=Q[u+1],u++;else if(Q[u]==="-c"||Q[u]==="--codec"){let D=Q[u+1];if(D==="av1"||D==="h264"||D==="dual")R=D;else console.error(`❌ Invalid codec: ${D}. Valid options: av1, h264, dual`),process.exit(1);u++}else if(Q[u]==="-f"||Q[u]==="--format"){let D=Q[u+1];if(D==="dash"||D==="hls"||D==="both")i=D;else console.error(`❌ Invalid format: ${D}. Valid options: dash, hls, both`),process.exit(1);u++}else if(Q[u]==="--h264-cq"){if(S=parseInt(Q[u+1]),isNaN(S)||S<0||S>51)console.error(`❌ Invalid H.264 CQ value: ${Q[u+1]}. Must be 0-51`),process.exit(1);u++}else if(Q[u]==="--h264-crf"){if(T=parseInt(Q[u+1]),isNaN(T)||T<0||T>51)console.error(`❌ Invalid H.264 CRF value: ${Q[u+1]}. Must be 0-51`),process.exit(1);u++}else if(Q[u]==="--av1-cq"){if(b=parseInt(Q[u+1]),isNaN(b)||b<0||b>51)console.error(`❌ Invalid AV1 CQ value: ${Q[u+1]}. Must be 0-51`),process.exit(1);u++}else if(Q[u]==="--av1-crf"){if(y=parseInt(Q[u+1]),isNaN(y)||y<0||y>63)console.error(`❌ Invalid AV1 CRF value: ${Q[u+1]}. Must be 0-63`),process.exit(1);u++}else if(Q[u]==="--accel"||Q[u]==="--hardware"){let D=Q[u+1];if(!["auto","nvenc","qsv","amf","cpu"].includes(D))console.error(`❌ Invalid accelerator: ${D}. Valid: auto, nvenc, qsv, amf, cpu`),process.exit(1);EF=D,u++}else if(!Q[u].startsWith("-"))mD.push(Q[u]);var o=mD[0],CF=mD[1]||".";if(!o)console.error("❌ Usage: create-vod [output-dir] [options]"),console.error(` -Options:`),console.error(" -r, --resolutions Video resolutions (e.g., 360,480,720 or 720@60,1080@60)"),console.error(" -c, --codec Video codec: av1, h264, or dual (default: dual)"),console.error(" -f, --format Streaming format: dash, hls, or both (default: both)"),console.error(" -p, --poster Poster timecode (e.g., 00:00:05 or 10)"),console.error(" --accel Hardware accelerator: auto|nvenc|qsv|amf|cpu (default: auto)"),console.error(` +`,"utf-8")}catch(QD){}try{await _u(U,{recursive:!0,force:!0})}catch(QD){console.warn(`Warning: Failed to cleanup temp directory: ${U}`)}}}async function rF(u,D,E,F,C,B,A,Z,J,G,X,Y,$,N,K,_,W){if(!await a())throw Error("FFmpeg is not installed or not in PATH");if(!await i())throw Error("MP4Box is not installed or not in PATH. Install gpac package.");let U=(z,x,zD,HD)=>{if(W)W({stage:z,percent:x,message:zD,currentProfile:HD})};U("analyzing",0,"Analyzing input video...");let k=await t(u),q=k.hasAudio,V=J&&J!=="auto"?J:"auto",L=await r(),y=await o(),{selected:P,h264Encoder:QD,av1Encoder:UF,warnings:nD}=oF(L,V,A);if(nD.length>0)for(let z of nD)console.warn(`⚠️ ${z}`);let{selected:ZD}=tF(y,G||"auto"),WF=L.some((z)=>z.av1Encoder),c=A;if(A==="dual"&&!WF)console.warn("⚠️ AV1 hardware encoder not detected. Switching to H.264 only."),c="h264";let R;if(B&&B.length>0){let z=XD(B,k.width,k.height,k.fps,k.videoBitrate);if(z.errors.length>0){console.warn(` +❌ Profile errors:`);for(let x of z.errors)console.warn(` - ${x}`);console.warn("")}if(z.warnings.length>0){console.warn(` +⚠️ Profile warnings:`);for(let x of z.warnings)console.warn(` - ${x}`);console.warn("")}if(R=z.profiles,R.length===0)throw Error("No valid profiles found in custom list. Check errors above.")}else if(C)R=C;else R=CD(k.width,k.height,k.fps,k.videoBitrate);if(R.length===0)throw Error("No suitable profiles found for input video resolution");let kF=Nu(u,Qu(u)),FD=YD(D,kF);try{await _u(FD,{recursive:!0,force:!0})}catch(z){}await d(FD);let h=[];if(c==="h264"||c==="dual"){let z=QD||"libx264",x=ku(z,"h264");h.push({type:"h264",codec:z,preset:x})}if(c==="av1"||c==="dual"){let z=UF||"libsvtav1",x=ku(z,"av1");h.push({type:"av1",codec:z,preset:x})}let NF=h.map((z)=>z.type.toUpperCase()).join(" + "),QF=P==="cpu"?"CPU":P.toUpperCase();U("analyzing",20,`Using ${NF} encoding (${QF}, decoder ${ZD.toUpperCase()})`,void 0);let _F=P==="cpu"?2:3,_D=new Map;for(let z=0;z{let f8=R.findIndex((VF)=>VF.name===ED),eD=25+oD*40,Du=tD/100*(40*qF/R.length);if(U("encoding",eD+Du,`Encoding ${x.toUpperCase()} ${ED}...`,`${x}-${ED}`),W)W({stage:"encoding",percent:eD+Du,currentProfile:`${x}-${ED}`,profilePercent:tD,message:`Encoding ${x.toUpperCase()} ${ED}...`})});_D.set(x,IF)}U("encoding",65,"Stage 1 complete: All codecs and profiles encoded"),U("encoding",70,"Stage 2: Creating segments and manifests...");let{manifestPath:zF,hlsManifestPath:HF}=await Wu(_D,FD,R,F,c,Z,q),sD=[];for(let z of _D.values())sD.push(...Array.from(z.values()));U("encoding",80,"Stage 2 complete: All formats packaged");let aD,iD;if(Y){U("thumbnails",80,"Generating thumbnail sprites...");let z={width:$.width||160,height:$.height||90,interval:$.interval||1,columns:$.columns||10},x=await Zu(u,FD,k.duration,z);aD=x.spritePath,iD=x.vttPath,U("thumbnails",90,"Thumbnails generated")}let rD;if(N)U("thumbnails",92,"Generating poster image..."),rD=await Au(u,FD,K),U("thumbnails",95,"Poster generated");return U("manifest",95,"Finalizing..."),U("complete",100,"Conversion complete!"),{manifestPath:zF,hlsManifestPath:HF,videoPaths:sD,thumbnailSpritePath:aD,thumbnailVttPath:iD,posterPath:rD,duration:k.duration,profiles:R,usedNvenc:h.some((z)=>z.codec.includes("nvenc")),selectedAccelerator:P,selectedDecoder:ZD,codecType:c,format:Z}}var e={nvenc:100,qsv:90,amf:80,vaapi:70,videotoolbox:65,v4l2:60,cpu:1};function oF(u,D,E){let F=E==="h264"||E==="dual",C=E==="av1"||E==="dual",B=[],A=new Set(["nvenc","qsv","amf"]),Z=u.filter((U)=>F&&U.h264Encoder||C&&U.av1Encoder),J=Z.filter((U)=>A.has(U.accelerator)),G=(U)=>Z.find((k)=>k.accelerator===U),X;if(D!=="auto"){if(D==="cpu")X=void 0;else if(!A.has(D))B.push(`Ускоритель "${D}" пока не поддерживается, использую CPU`);else if(X=G(D),!X)throw Error(`Аппаратный ускоритель "${D}" недоступен в системе`)}else if(X=(J.length>0?J:[]).sort((k,q)=>(e[q.accelerator]||0)-(e[k.accelerator]||0))[0],!X&&Z.length>0)B.push("Доступен аппаратный ускоритель, но он пока не поддерживается пайплайном, использую CPU");let $=(J.length>0?J:[]).sort((U,k)=>(e[k.accelerator]||0)-(e[U.accelerator]||0)),N=(U)=>{let k=U==="h264"?X?.h264Encoder:X?.av1Encoder;if(k)return{encoder:k,accel:X?.accelerator};let q=$.find((V)=>U==="h264"?V.h264Encoder:V.av1Encoder);if(q){if(D!=="auto"&&X)B.push(`Выбранный ускоритель "${X.accelerator}" не поддерживает ${U.toUpperCase()}, использую ${q.accelerator}`);return{encoder:U==="h264"?q.h264Encoder:q.av1Encoder,accel:q.accelerator}}if(D!=="auto"&&D!=="cpu")B.push(`Ускоритель "${D}" не поддерживает ${U.toUpperCase()}, использую CPU`);return{encoder:void 0,accel:"cpu"}},K=F?N("h264"):{encoder:void 0,accel:X?.accelerator},_=C?N("av1"):{encoder:void 0,accel:X?.accelerator};return{selected:X?.accelerator||K.accel||_.accel||"cpu",h264Encoder:K.encoder,av1Encoder:_.encoder,warnings:B}}function tF(u,D){let E=new Set(["nvenc","qsv","vaapi","videotoolbox","v4l2"]),F=(A)=>u.find((Z)=>Z.accelerator===A);if(D!=="auto"){if(D==="cpu")return{selected:"cpu"};let A=F(D);return{selected:A?A.accelerator:"cpu"}}let C=u.filter((A)=>E.has(A.accelerator));if(C.length===0)return{selected:"cpu"};return{selected:C.sort((A,Z)=>(e[Z.accelerator]||0)-(e[A.accelerator]||0))[0].accelerator}}function ku(u,D){if(u.includes("nvenc"))return"p4";if(u.includes("qsv"))return"medium";if(u.includes("amf"))return"balanced";if(u.includes("vaapi"))return"5";if(u.includes("videotoolbox"))return"medium";if(u.includes("v4l2"))return"medium";if(u==="libsvtav1")return"8";if(u==="libx264")return"medium";return D==="av1"?"8":"medium"}var mD=$D(CF(),1);import{statSync as L8}from"node:fs";var Q=process.argv.slice(2),BD,lD,j="dual",DD="both",dD=[],w,S,T,b,WD,kD;for(let u=0;uF.trim()).filter((F)=>F.length>0)}else if(Q[u]==="-p"||Q[u]==="--poster")lD=Q[u+1],u++;else if(Q[u]==="-c"||Q[u]==="--codec"){let D=Q[u+1];if(D==="av1"||D==="h264"||D==="dual")j=D;else console.error(`❌ Invalid codec: ${D}. Valid options: av1, h264, dual`),process.exit(1);u++}else if(Q[u]==="-f"||Q[u]==="--format"){let D=Q[u+1];if(D==="dash"||D==="hls"||D==="both")DD=D;else console.error(`❌ Invalid format: ${D}. Valid options: dash, hls, both`),process.exit(1);u++}else if(Q[u]==="--h264-cq"){if(w=parseInt(Q[u+1]),isNaN(w)||w<0||w>51)console.error(`❌ Invalid H.264 CQ value: ${Q[u+1]}. Must be 0-51`),process.exit(1);u++}else if(Q[u]==="--h264-crf"){if(S=parseInt(Q[u+1]),isNaN(S)||S<0||S>51)console.error(`❌ Invalid H.264 CRF value: ${Q[u+1]}. Must be 0-51`),process.exit(1);u++}else if(Q[u]==="--av1-cq"){if(T=parseInt(Q[u+1]),isNaN(T)||T<0||T>51)console.error(`❌ Invalid AV1 CQ value: ${Q[u+1]}. Must be 0-51`),process.exit(1);u++}else if(Q[u]==="--av1-crf"){if(b=parseInt(Q[u+1]),isNaN(b)||b<0||b>63)console.error(`❌ Invalid AV1 CRF value: ${Q[u+1]}. Must be 0-63`),process.exit(1);u++}else if(Q[u]==="--accel"||Q[u]==="--hardware"||Q[u]==="-e"||Q[u]==="--encoder"){let D=Q[u+1];if(!["auto","nvenc","qsv","amf","cpu","vaapi","videotoolbox","v4l2"].includes(D))console.error(`❌ Invalid accelerator: ${D}. Valid: auto, nvenc, qsv, amf, vaapi, videotoolbox, v4l2, cpu`),process.exit(1);WD=D,u++}else if(Q[u]==="-d"||Q[u]==="--decoder"){let D=Q[u+1];if(!["auto","nvenc","qsv","amf","vaapi","videotoolbox","v4l2","cpu"].includes(D))console.error(`❌ Invalid decoder: ${D}. Valid: auto, nvenc, qsv, amf, vaapi, videotoolbox, v4l2, cpu`),process.exit(1);kD=D,u++}else if(!Q[u].startsWith("-"))dD.push(Q[u]);var uD=dD[0],KF=dD[1]||".";if(!uD)console.error("❌ Usage: create-vod [output-dir] [options]"),console.error(` +Options:`),console.error(" -r, --resolutions Video resolutions (e.g., 360,480,720 or 720@60,1080@60)"),console.error(" -c, --codec Video codec: av1, h264, or dual (default: dual)"),console.error(" -f, --format Streaming format: dash, hls, or both (default: both)"),console.error(" -p, --poster Poster timecode (e.g., 00:00:05 or 10)"),console.error(" -e, --encoder Hardware encoder: auto|nvenc|qsv|amf|vaapi|videotoolbox|v4l2|cpu (default: auto)"),console.error(" -d, --decoder Hardware decoder: auto|nvenc|qsv|amf|vaapi|videotoolbox|v4l2|cpu (default: auto)"),console.error(` Quality Options (override defaults):`),console.error(" --h264-cq H.264 GPU CQ value (0-51, lower = better, default: auto)"),console.error(" --h264-crf H.264 CPU CRF value (0-51, lower = better, default: auto)"),console.error(" --av1-cq AV1 GPU CQ value (0-51, lower = better, default: auto)"),console.error(" --av1-crf AV1 CPU CRF value (0-63, lower = better, default: auto)"),console.error(` 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 dual --h264-cq 30 --av1-cq 39"),console.error(" create-vod video.mp4 -f hls"),console.error(" create-vod video.mp4 -c dual -f both"),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 -c dual -f both -p 10 --h264-cq 28 --av1-cq 37"),process.exit(1);console.log(`\uD83D\uDD0D Checking system... -`);var BF=await n(),AF=await s(),cD=await a(),ZF=cD.some((u)=>u.av1Encoder),FF={nvenc:100,qsv:90,amf:80,vaapi:70,videotoolbox:65,v4l2:60},XD=cD.slice().sort((u,D)=>(FF[D.accelerator]||0)-(FF[u.accelerator]||0))[0];console.log(`FFmpeg: ${BF?"✅":"❌"}`);console.log(`MP4Box: ${AF?"✅":"❌"}`);var z8=Array.from(new Set(cD.map((u)=>u.accelerator.toUpperCase()))),hD=XD?XD.accelerator.toUpperCase():void 0,YD=z8.filter((u)=>u!==hD),H8=hD?`✅ ${hD}${YD.length>0?` (${YD.join(", ")})`:""}`:"❌";console.log(`Hardware: ${H8}`);console.log("");if(!BF)console.error("❌ FFmpeg not found. Please install FFmpeg first."),process.exit(1);if(!AF)console.error("❌ MP4Box not found. Please install: sudo pacman -S gpac"),process.exit(1);if((R==="av1"||R==="dual")&&!ZF){if(R==="av1")console.error("⚠️ Warning: AV1 encoding 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. -`);else if(R==="dual")console.warn("⚠️ AV1 hardware encoder not detected. Using H.264 only (disable AV1)."),R="h264"}if((i==="hls"||i==="both")&&R==="av1")console.error("❌ Error: HLS format requires H.264 codec for Safari/iOS compatibility."),console.error(` Please use --codec h264 or --codec dual with --format hls +`);var XF=await a(),YF=await i(),pD=await r(),GF=pD.some((u)=>u.av1Encoder),ND=await o(),BF={nvenc:100,qsv:90,amf:80,vaapi:70,videotoolbox:65,v4l2:60},AF=pD.slice().sort((u,D)=>(BF[D.accelerator]||0)-(BF[u.accelerator]||0))[0];console.log(`FFmpeg: ${XF?"✅":"❌"}`);console.log(`MP4Box: ${YF?"✅":"❌"}`);var O8=Array.from(new Set(pD.map((u)=>u.accelerator.toUpperCase()))),AD=AF?AF.accelerator.toUpperCase():void 0,ZF=O8.filter((u)=>u!==AD),R8=AD?`✅ ${AD}${ZF.length>0?` (${ZF.join(", ")})`:""}`:"❌";console.log(`Hardware: ${R8}`);if(ND.length>0){let u=Array.from(new Set(ND.map((D)=>D.accelerator.toUpperCase())));console.log(`Decoders: ${u.join(", ")}`)}console.log("");if(!XF)console.error("❌ FFmpeg not found. Please install FFmpeg first."),process.exit(1);if(!YF)console.error("❌ MP4Box not found. Please install: sudo pacman -S gpac"),process.exit(1);if((j==="av1"||j==="dual")&&!GF){if(j==="av1")console.error("⚠️ Warning: AV1 encoding 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. +`);else if(j==="dual")console.warn("⚠️ AV1 hardware encoder not detected. Using H.264 only (disable AV1)."),j="h264"}if((DD==="hls"||DD==="both")&&j==="av1")console.error("❌ Error: HLS format requires H.264 codec for Safari/iOS compatibility."),console.error(` Please use --codec h264 or --codec dual with --format hls `),process.exit(1);console.log(`\uD83D\uDCCA Analyzing video... -`);var L=await r(o),q8=N8(o),I8=(q8.size/1048576).toFixed(2);console.log("\uD83D\uDCF9 Video Information:");console.log(` File: ${o}`);console.log(` Size: ${I8} MB`);console.log(` Resolution: ${L.width}x${L.height}`);console.log(` FPS: ${L.fps.toFixed(2)}`);console.log(` Duration: ${Math.floor(L.duration/60)}m ${Math.floor(L.duration%60)}s`);console.log(` Codec: ${L.codec}`);if(L.videoBitrate)console.log(` Video Bitrate: ${(L.videoBitrate/1000).toFixed(2)} Mbps`);if(L.audioBitrate)console.log(` Audio Bitrate: ${L.audioBitrate} kbps`);var fD=[];if(FD&&FD.length>0){let u=AD(FD,L.width,L.height,L.fps,L.videoBitrate);if(u.errors.length>0)console.error(` +`);var M=await t(uD),j8=L8(uD),w8=(j8.size/1048576).toFixed(2);console.log("\uD83D\uDCF9 Video Information:");console.log(` File: ${uD}`);console.log(` Size: ${w8} MB`);console.log(` Resolution: ${M.width}x${M.height}`);console.log(` FPS: ${M.fps.toFixed(2)}`);console.log(` Duration: ${Math.floor(M.duration/60)}m ${Math.floor(M.duration%60)}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 cD=[];if(BD&&BD.length>0){let u=XD(BD,M.width,M.height,M.fps,M.videoBitrate);if(u.errors.length>0)console.error(` ❌ Profile errors:`),u.errors.forEach((D)=>console.error(` - ${D}`)),process.exit(1);if(u.warnings.length>0)console.warn(` -⚠️ Profile warnings:`),u.warnings.forEach((D)=>console.warn(` - ${D}`));fD=u.profiles.map((D)=>D.name)}else fD=uD(L.width,L.height,L.fps,L.videoBitrate).map((D)=>D.name);var x8=i==="both"?"DASH (manifest.mpd), HLS (master.m3u8)":i==="dash"?"DASH (manifest.mpd)":"HLS (master.m3u8)",V8=!0,L8=gD||"00:00:00",M8=R==="dual"?"dual (AV1 + H.264)":R,O8=R==="h264"&&YD&&YD.length>=0&&!ZF?" (AV1 disabled: no HW)":"";console.log(` -\uD83D\uDCE6 Parameters:`);console.log(` Input: ${o}`);console.log(` Output: ${CF}`);console.log(` Codec: ${M8}${O8}`);console.log(` Profiles: ${fD.join(", ")}`);console.log(` Manifests: ${x8}`);console.log(` Poster: ${L8} (will be generated)`);console.log(` Thumbnails: ${V8?"yes (with VTT)":"no"}`);console.log(` Accelerator: ${XD?XD.accelerator.toUpperCase():"CPU"}`);var g;if(S!==void 0||T!==void 0||b!==void 0||y!==void 0){if(g={},S!==void 0||T!==void 0){if(g.h264={},S!==void 0)g.h264.cq=S;if(T!==void 0)g.h264.crf=T;console.log(`\uD83C\uDF9A️ H.264 Quality: ${S!==void 0?`CQ ${S}`:""}${T!==void 0?` CRF ${T}`:""}`)}if(b!==void 0||y!==void 0){if(g.av1={},b!==void 0)g.av1.cq=b;if(y!==void 0)g.av1.crf=y;console.log(`\uD83C\uDF9A️ AV1 Quality: ${b!==void 0?`CQ ${b}`:""}${y!==void 0?` CRF ${y}`:""}`)}}console.log(` +⚠️ Profile warnings:`),u.warnings.forEach((D)=>console.warn(` - ${D}`));cD=u.profiles.map((D)=>D.name)}else cD=CD(M.width,M.height,M.fps,M.videoBitrate).map((D)=>D.name);var S8=DD==="both"?"DASH (manifest.mpd), HLS (master.m3u8)":DD==="dash"?"DASH (manifest.mpd)":"HLS (master.m3u8)",T8=!0,b8=lD||"00:00:00",y8=j==="dual"?"dual (AV1 + H.264)":j,v8=j==="h264"&&!GF?" (AV1 disabled: no HW)":"",$F=WD?WD.toUpperCase():AD||"CPU",JF=kD?kD.toUpperCase():ND[0]?.accelerator.toUpperCase()||"CPU",P8=$F==="AUTO"?AD||"CPU":$F,h8=JF==="AUTO"?ND[0]?.accelerator.toUpperCase()||"CPU":JF;console.log(` +\uD83D\uDCE6 Parameters:`);console.log(` Input: ${uD}`);console.log(` Output: ${KF}`);console.log(` Codec: ${y8}${v8}`);console.log(` Profiles: ${cD.join(", ")}`);console.log(` Manifests: ${S8}`);console.log(` Poster: ${b8} (will be generated)`);console.log(` Thumbnails: ${T8?"yes (with VTT)":"no"}`);console.log(` Accelerator: ${P8}`);console.log(` Decoder: ${h8}`);var m;if(w!==void 0||S!==void 0||T!==void 0||b!==void 0){if(m={},w!==void 0||S!==void 0){if(m.h264={},w!==void 0)m.h264.cq=w;if(S!==void 0)m.h264.crf=S;console.log(`\uD83C\uDF9A️ H.264 Quality: ${w!==void 0?`CQ ${w}`:""}${S!==void 0?` CRF ${S}`:""}`)}if(T!==void 0||b!==void 0){if(m.av1={},T!==void 0)m.av1.cq=T;if(b!==void 0)m.av1.crf=b;console.log(`\uD83C\uDF9A️ AV1 Quality: ${T!==void 0?`CQ ${T}`:""}${b!==void 0?` CRF ${b}`:""}`)}}console.log(` \uD83D\uDE80 Starting conversion... -`);var KD=new PD.default.MultiBar({format:"{stage} | {bar} | {percentage}% | {name}",barCompleteChar:"█",barIncompleteChar:"░",hideCursor:!0,clearOnComplete:!1,stopOnComplete:!0},PD.default.Presets.shades_classic),yD={},vD=null;try{let u=await LD({input:o,outputDir:CF,customProfiles:FD,posterTimecode:gD,codec:R,format:i,segmentDuration:2,hardwareAccelerator:EF,quality:g,generateThumbnails:!0,generatePoster:!0,parallel:!0,onProgress:(D)=>{let E=D.stage==="encoding"?"Encoding":D.stage==="thumbnails"?"Thumbnails":D.stage==="manifest"?"Manifest":D.stage==="analyzing"?"Analyzing":"Complete";if(D.stage==="encoding"&&D.currentProfile){if(!yD[D.currentProfile])yD[D.currentProfile]=KD.create(100,0,{stage:"Encode",name:D.currentProfile});let F=D.profilePercent??D.percent;yD[D.currentProfile].update(F,{stage:"Encode",name:D.currentProfile})}if(!vD)vD=KD.create(100,0,{stage:E,name:"Overall"});vD.update(D.percent,{stage:E,name:D.message||"Overall"})}});KD.stop(),console.log(` -✅ Conversion completed successfully! -`)}catch(u){KD.stop(),console.error(` +`);var UD=new mD.default.MultiBar({format:"{stage} | {bar} | {percentage}% | {name}",barCompleteChar:"█",barIncompleteChar:"░",hideCursor:!0,clearOnComplete:!1,stopOnComplete:!0},mD.default.Presets.shades_classic),fD={},gD=null;try{let u=Date.now(),D=await jD({input:uD,outputDir:KF,customProfiles:BD,posterTimecode:lD,codec:j,format:DD,segmentDuration:2,hardwareAccelerator:WD,hardwareDecoder:kD,quality:m,generateThumbnails:!0,generatePoster:!0,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(!fD[C.currentProfile])fD[C.currentProfile]=UD.create(100,0,{stage:"Encode",name:C.currentProfile});let A=C.profilePercent??C.percent;fD[C.currentProfile].update(A,{stage:"Encode",name:C.currentProfile})}if(!gD)gD=UD.create(100,0,{stage:B,name:"Overall"});gD.update(C.percent,{stage:B,name:C.message||"Overall"})}});UD.stop();let F=((Date.now()-u)/1000).toFixed(2);console.log(` +✅ Conversion completed successfully! (${F}s) +`)}catch(u){UD.stop(),console.error(` ❌ Error during conversion:`),console.error(u),process.exit(1)} diff --git a/src/cli.ts b/src/cli.ts index 50305b0..20d471c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -10,7 +10,7 @@ * create-vod ./video.mp4 ./output -r 720,1080 */ -import { convertToDash, checkFFmpeg, checkMP4Box, getVideoMetadata, detectHardwareEncoders } from './index'; +import { convertToDash, checkFFmpeg, checkMP4Box, getVideoMetadata, detectHardwareEncoders, detectHardwareDecoders } from './index'; import cliProgress from 'cli-progress'; import { statSync } from 'node:fs'; import { basename, extname } from 'node:path'; @@ -31,6 +31,7 @@ let h264CRF: number | undefined; let av1CQ: number | undefined; let av1CRF: number | undefined; let accelerator: HardwareAccelerationOption | undefined; +let decoder: HardwareAccelerationOption | undefined; // First pass: extract flags and their values for (let i = 0; i < args.length; i++) { @@ -101,15 +102,24 @@ for (let i = 0; i < args.length; i++) { process.exit(1); } i++; // Skip next arg - } else if (args[i] === '--accel' || args[i] === '--hardware') { + } else if (args[i] === '--accel' || args[i] === '--hardware' || args[i] === '-e' || args[i] === '--encoder') { const acc = args[i + 1]; - const allowed: HardwareAccelerationOption[] = ['auto', 'nvenc', 'qsv', 'amf', 'cpu']; + const allowed: HardwareAccelerationOption[] = ['auto', 'nvenc', 'qsv', 'amf', 'cpu', 'vaapi', 'videotoolbox', 'v4l2']; if (!allowed.includes(acc as HardwareAccelerationOption)) { - console.error(`❌ Invalid accelerator: ${acc}. Valid: auto, nvenc, qsv, amf, cpu`); + console.error(`❌ Invalid accelerator: ${acc}. Valid: auto, nvenc, qsv, amf, vaapi, videotoolbox, v4l2, cpu`); process.exit(1); } accelerator = acc as HardwareAccelerationOption; i++; + } else if (args[i] === '-d' || args[i] === '--decoder') { + const acc = args[i + 1]; + const allowed: HardwareAccelerationOption[] = ['auto', 'nvenc', 'qsv', 'amf', 'vaapi', 'videotoolbox', 'v4l2', 'cpu']; + if (!allowed.includes(acc as HardwareAccelerationOption)) { + console.error(`❌ Invalid decoder: ${acc}. Valid: auto, nvenc, qsv, amf, vaapi, videotoolbox, v4l2, cpu`); + process.exit(1); + } + decoder = acc as HardwareAccelerationOption; + i++; } else if (!args[i].startsWith('-')) { // Positional argument positionalArgs.push(args[i]); @@ -127,7 +137,8 @@ if (!input) { console.error(' -c, --codec Video codec: av1, h264, or dual (default: dual)'); console.error(' -f, --format Streaming format: dash, hls, or both (default: both)'); console.error(' -p, --poster Poster timecode (e.g., 00:00:05 or 10)'); - console.error(' --accel Hardware accelerator: auto|nvenc|qsv|amf|cpu (default: auto)'); + console.error(' -e, --encoder Hardware encoder: auto|nvenc|qsv|amf|vaapi|videotoolbox|v4l2|cpu (default: auto)'); + console.error(' -d, --decoder Hardware decoder: auto|nvenc|qsv|amf|vaapi|videotoolbox|v4l2|cpu (default: auto)'); console.error('\nQuality Options (override defaults):'); console.error(' --h264-cq H.264 GPU CQ value (0-51, lower = better, default: auto)'); console.error(' --h264-crf H.264 CPU CRF value (0-51, lower = better, default: auto)'); @@ -153,6 +164,7 @@ const hasFFmpeg = await checkFFmpeg(); const hasMP4Box = await checkMP4Box(); const hwEncoders = await detectHardwareEncoders(); const hasAv1Hardware = hwEncoders.some(item => item.av1Encoder); +const hwDecoders = await detectHardwareDecoders(); const accelPriority: Record = { nvenc: 100, @@ -176,6 +188,10 @@ const accelLabel = bestAccelName ? `✅ ${bestAccelName}${accelRest.length > 0 ? ` (${accelRest.join(', ')})` : ''}` : '❌'; console.log(`Hardware: ${accelLabel}`); +if (hwDecoders.length > 0) { + const decList = Array.from(new Set(hwDecoders.map((d) => d.accelerator.toUpperCase()))); + console.log(`Decoders: ${decList.join(', ')}`); +} console.log(''); if (!hasFFmpeg) { @@ -267,7 +283,13 @@ const manifestDesc = const thumbnailsPlanned = true; const posterPlanned = posterTimecode || '00:00:00'; const codecDisplay = codecType === 'dual' ? 'dual (AV1 + H.264)' : codecType; -const codecNote = codecType === 'h264' && accelRest && accelRest.length >= 0 && !hasAv1Hardware ? ' (AV1 disabled: no HW)' : ''; +const codecNote = codecType === 'h264' && !hasAv1Hardware ? ' (AV1 disabled: no HW)' : ''; +const plannedAccel = accelerator ? accelerator.toUpperCase() : (bestAccelName || 'CPU'); +const plannedDecoder = decoder ? decoder.toUpperCase() : (hwDecoders[0]?.accelerator.toUpperCase() || 'CPU'); +const acceleratorDisplay = plannedAccel === 'AUTO' ? (bestAccelName || 'CPU') : plannedAccel; +const decoderDisplay = plannedDecoder === 'AUTO' + ? (hwDecoders[0]?.accelerator.toUpperCase() || 'CPU') + : plannedDecoder; console.log('\n📦 Parameters:'); console.log(` Input: ${input}`); @@ -277,7 +299,8 @@ console.log(` Profiles: ${displayProfiles.join(', ')}`); console.log(` Manifests: ${manifestDesc}`); console.log(` Poster: ${posterPlanned} (will be generated)`); console.log(` Thumbnails: ${thumbnailsPlanned ? 'yes (with VTT)' : 'no'}`); -console.log(` Accelerator: ${bestAccel ? bestAccel.accelerator.toUpperCase() : 'CPU'}`); +console.log(` Accelerator: ${acceleratorDisplay}`); +console.log(` Decoder: ${decoderDisplay}`); // Build quality settings if any are specified let quality: QualitySettings | undefined; @@ -316,6 +339,7 @@ const bars: Record = {}; let overallBar: any = null; try { + const startedAt = Date.now(); const result = await convertToDash({ input, outputDir, @@ -325,6 +349,7 @@ try { format: formatType, segmentDuration: 2, hardwareAccelerator: accelerator, + hardwareDecoder: decoder, quality, generateThumbnails: true, generatePoster: true, @@ -368,7 +393,9 @@ try { multibar.stop(); - console.log('\n✅ Conversion completed successfully!\n'); + const elapsedMs = Date.now() - startedAt; + const elapsedSec = (elapsedMs / 1000).toFixed(2); + console.log(`\n✅ Conversion completed successfully! (${elapsedSec}s)\n`); } catch (error) { multibar.stop(); diff --git a/src/core/converter.ts b/src/core/converter.ts index 09d3e96..2a8f917 100644 --- a/src/core/converter.ts +++ b/src/core/converter.ts @@ -11,7 +11,8 @@ import type { StreamingFormat, HardwareAccelerationOption, HardwareAccelerator, - HardwareEncoderInfo + HardwareEncoderInfo, + HardwareDecoderInfo } from '../types'; import { checkFFmpeg, @@ -19,7 +20,8 @@ import { getVideoMetadata, ensureDir, setLogFile, - detectHardwareEncoders + detectHardwareEncoders, + detectHardwareDecoders } from '../utils'; import { selectProfiles, createProfilesFromStrings } from '../config/profiles'; import { generateThumbnailSprite, generatePoster } from './thumbnails'; @@ -41,7 +43,7 @@ export async function convertToDash( customProfiles, codec = 'dual', format = 'both', - useNvenc, + hardwareDecoder, hardwareAccelerator, quality, generateThumbnails = true, @@ -87,8 +89,8 @@ Format: ${format} customProfiles, codec, format, - useNvenc, hardwareAccelerator, + hardwareDecoder, quality, generateThumbnails, thumbnailConfig, @@ -127,8 +129,8 @@ async function convertToDashInternal( customProfiles: string[] | undefined, codec: CodecType, format: StreamingFormat, - useNvenc: boolean | undefined, hardwareAccelerator: HardwareAccelerationOption | undefined, + hardwareDecoder: HardwareAccelerationOption | undefined, quality: DashConvertOptions['quality'], generateThumbnails: boolean, thumbnailConfig: ThumbnailConfig, @@ -164,13 +166,10 @@ async function convertToDashInternal( const preferredAccelerator: HardwareAccelerationOption = hardwareAccelerator && hardwareAccelerator !== 'auto' ? hardwareAccelerator - : useNvenc === true - ? 'nvenc' - : useNvenc === false - ? 'cpu' - : 'auto'; + : 'auto'; const hardwareEncoders = await detectHardwareEncoders(); + const hardwareDecoders = await detectHardwareDecoders(); const { selected, h264Encoder, av1Encoder, warnings: accelWarnings } = selectHardwareEncoders( hardwareEncoders, @@ -184,6 +183,11 @@ async function convertToDashInternal( } } + const { selected: selectedDecoder } = selectHardwareDecoders( + hardwareDecoders, + hardwareDecoder || 'auto' + ); + const av1HardwareAvailable = hardwareEncoders.some(info => info.av1Encoder); let effectiveCodec: CodecType = codec; @@ -275,7 +279,7 @@ async function convertToDashInternal( const codecNames = codecs.map(c => c.type.toUpperCase()).join(' + '); const accelLabel = selected === 'cpu' ? 'CPU' : selected.toUpperCase(); - reportProgress('analyzing', 20, `Using ${codecNames} encoding (${accelLabel})`, undefined); + reportProgress('analyzing', 20, `Using ${codecNames} encoding (${accelLabel}, decoder ${selectedDecoder.toUpperCase()})`, undefined); const maxConcurrent = selected === 'cpu' ? 2 : 3; @@ -306,6 +310,7 @@ async function convertToDashInternal( type, // Pass codec type to differentiate output files codecQuality, // Pass quality settings (CQ/CRF) undefined, // optimizations - for future use + selectedDecoder === 'cpu' ? undefined : selectedDecoder, (profileName, percent) => { const profileIndex = profiles.findIndex(p => p.name === profileName); const baseProgress = 25 + codecProgress * 40; @@ -412,6 +417,7 @@ async function convertToDashInternal( profiles, usedNvenc: codecs.some(c => c.codec.includes('nvenc')), selectedAccelerator: selected, + selectedDecoder, codecType: effectiveCodec, format }; @@ -518,6 +524,36 @@ function selectHardwareEncoders( }; } +function selectHardwareDecoders( + available: HardwareDecoderInfo[], + preferred: HardwareAccelerationOption +): { + selected: HardwareAccelerator; +} { + const supportedForAuto = new Set(['nvenc', 'qsv', 'vaapi', 'videotoolbox', 'v4l2']); + + const pick = (acc: HardwareAccelerator) => available.find(info => info.accelerator === acc); + + if (preferred !== 'auto') { + if (preferred === 'cpu') { + return { selected: 'cpu' }; + } + const item = pick(preferred); + return { selected: item ? item.accelerator : 'cpu' }; + } + + const pool = available.filter(info => supportedForAuto.has(info.accelerator)); + if (pool.length === 0) { + return { selected: 'cpu' }; + } + + const best = pool.sort( + (a, b) => (ACCEL_PRIORITY[b.accelerator] || 0) - (ACCEL_PRIORITY[a.accelerator] || 0) + )[0]; + + return { selected: best.accelerator }; +} + function resolvePresetForEncoder(encoder: string, codecType: 'h264' | 'av1'): string { if (encoder.includes('nvenc')) return 'p4'; if (encoder.includes('qsv')) return 'medium'; diff --git a/src/core/encoding.ts b/src/core/encoding.ts index 2106bf9..0d9144e 100644 --- a/src/core/encoding.ts +++ b/src/core/encoding.ts @@ -1,6 +1,6 @@ import { join } from 'node:path'; import { execFFmpeg, selectAudioBitrate } from '../utils'; -import type { VideoProfile, VideoOptimizations, CodecQualitySettings } from '../types'; +import type { VideoProfile, VideoOptimizations, CodecQualitySettings, HardwareAccelerator } from '../types'; /** * Get default CQ/CRF value based on resolution and codec @@ -53,15 +53,29 @@ export async function encodeProfileToMP4( codecType: 'h264' | 'av1', qualitySettings?: CodecQualitySettings, optimizations?: VideoOptimizations, + decoderAccel?: HardwareAccelerator, onProgress?: (percent: number) => void ): Promise { const outputPath = join(tempDir, `video_${codecType}_${profile.name}.mp4`); - const args = [ - '-y', - '-i', input, - '-c:v', videoCodec - ]; + const args = ['-y']; + + // Hardware decode (optional) + if (decoderAccel) { + if (decoderAccel === 'nvenc') { + args.push('-hwaccel', 'cuda', '-hwaccel_output_format', 'cuda'); + } else if (decoderAccel === 'qsv') { + args.push('-hwaccel', 'qsv'); + } else if (decoderAccel === 'vaapi') { + args.push('-hwaccel', 'vaapi'); + } else if (decoderAccel === 'videotoolbox') { + args.push('-hwaccel', 'videotoolbox'); + } else if (decoderAccel === 'v4l2') { + args.push('-hwaccel', 'v4l2'); + } + } + + args.push('-i', input, '-c:v', videoCodec); // Determine if using GPU or CPU encoder const isGPU = videoCodec.includes('nvenc') || videoCodec.includes('qsv') || videoCodec.includes('amf') || videoCodec.includes('vaapi') || videoCodec.includes('videotoolbox') || videoCodec.includes('v4l2'); @@ -196,6 +210,7 @@ export async function encodeProfilesToMP4( codecType: 'h264' | 'av1', qualitySettings?: CodecQualitySettings, optimizations?: VideoOptimizations, + decoderAccel?: HardwareAccelerator, onProgress?: (profileName: string, percent: number) => void ): Promise> { const mp4Files = new Map(); @@ -217,6 +232,7 @@ export async function encodeProfilesToMP4( codecType, qualitySettings, optimizations, + decoderAccel, (percent) => { if (onProgress) { onProgress(profile.name, percent); @@ -246,6 +262,7 @@ export async function encodeProfilesToMP4( codecType, qualitySettings, optimizations, + decoderAccel, (percent) => { if (onProgress) { onProgress(profile.name, percent); diff --git a/src/index.ts b/src/index.ts index f5eac21..45aa5d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,8 @@ export type { CodecType, HardwareAccelerator, HardwareAccelerationOption, - HardwareEncoderInfo + HardwareEncoderInfo, + HardwareDecoderInfo } from './types'; // Utility exports @@ -24,7 +25,8 @@ export { checkAV1Support, getVideoMetadata, selectAudioBitrate, - detectHardwareEncoders + detectHardwareEncoders, + detectHardwareDecoders } from './utils'; // Profile exports diff --git a/src/types/index.ts b/src/types/index.ts index 8aaaf5e..1c95dfb 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -27,6 +27,13 @@ export interface HardwareEncoderInfo { av1Encoder?: string; } +/** + * Набор доступных декодеров/accel + */ +export interface HardwareDecoderInfo { + accelerator: HardwareAccelerator; +} + /** * Quality settings for a codec */ @@ -73,12 +80,11 @@ export interface DashConvertOptions { /** Streaming format to generate: 'dash', 'hls', or 'both' (default: 'both') */ format?: StreamingFormat; - - /** Enable NVENC hardware acceleration (auto-detect if undefined) — устарело, используйте hardwareAccelerator */ - useNvenc?: boolean; /** Предпочитаемый аппаратный ускоритель (auto по умолчанию) */ hardwareAccelerator?: HardwareAccelerationOption; + /** Предпочитаемый аппаратный ускоритель для декодера (auto по умолчанию) */ + hardwareDecoder?: HardwareAccelerationOption; /** Quality settings for video encoding (CQ/CRF values) */ quality?: QualitySettings; @@ -195,6 +201,8 @@ export interface DashConvertResult { /** Выбранный аппаратный ускоритель */ selectedAccelerator: HardwareAccelerator; + /** Выбранный аппаратный декодер */ + selectedDecoder: HardwareAccelerator; /** Codec type used for encoding */ codecType: CodecType; diff --git a/src/utils/index.ts b/src/utils/index.ts index a210270..c1698ea 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,6 +5,7 @@ export { checkNvenc, checkAV1Support, detectHardwareEncoders, + detectHardwareDecoders, execFFmpeg, execMP4Box, setLogFile diff --git a/src/utils/system.ts b/src/utils/system.ts index 6ca1f39..ae244ba 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -1,6 +1,6 @@ import { spawn } from 'node:child_process'; import { appendFile } from 'node:fs/promises'; -import type { HardwareAccelerator, HardwareEncoderInfo } from '../types'; +import type { HardwareAccelerator, HardwareDecoderInfo, HardwareEncoderInfo } from '../types'; // Global variable for log file path let currentLogFile: string | null = null; @@ -159,6 +159,40 @@ export async function detectHardwareEncoders(): Promise { return detected; } +/** + * Получить список доступных аппаратных декодеров (по выводу ffmpeg -hwaccels) + */ +export async function detectHardwareDecoders(): Promise { + const output: string = await new Promise((resolve) => { + const proc = spawn('ffmpeg', ['-hide_banner', '-hwaccels']); + let data = ''; + proc.stdout.on('data', (chunk) => data += chunk.toString()); + proc.on('error', () => resolve('')); + proc.on('close', () => resolve(data)); + }); + + const lines = output.split('\n').map(l => l.trim()).filter(Boolean); + const decoders: HardwareDecoderInfo[] = []; + + const map: Record = { + cuda: 'nvenc', + qsv: 'qsv', + vaapi: 'vaapi', + videotoolbox: 'videotoolbox', + v4l2m2m: 'v4l2', + dxva2: 'amf' + }; + + for (const line of lines) { + const acc = map[line]; + if (acc) { + decoders.push({ accelerator: acc }); + } + } + + return decoders; +} + /** * Execute FFmpeg command with progress tracking */