1import{f as ee}from"./ctMediaConvertDownload-n0-64pPl.js";import{w as te,c as oe}from"./ctPendingDownload-B21SXRKd.js";import{b as H,s as ne,i as W,d as re,f as ae}from"./mediaInputFromFilename-AaKRjYpC.js";import{e as k,C as X,c as ie}from"./ctMediaProgressUi-wz6CtyvX.js";import{a as se,c as q,f as G}from"./fileDropzone-CA_uaFcV.js";import{c as ce}from"./videoToolFfmpegSession-vgvYnhrp.js";import{w as de}from"./ctMediaSourceOutputName-BkKiostT.js";import{b as le}from"./ffmpegVideoCompress-C_zYTcnz.js";import{s as me}from"./ctToast-C2BAo121.js";import{w as ge}from"./wireMediaToolPageOnce-DYtotjbx.js";import"./ctFullscreenAd-CL-AA_Ul.js";import"./app-gOHIPY12.js";import"./transientNotice-Ds_di7lD.js";import"./ffmpegWasmProbe-Dr2SB0y0.js";import"./videoEncodeHints-B5HbAqTP.js";const ue=500*1024*1024;function _(l){const o=document.getElementById("ctMergeVidToastBody"),t=document.getElementById("ctMergeVidToast");!o||!t||me(t,{bodyEl:o,message:l,delay:12e3})}const $=document.getElementById("ctMergeVidReadyLabel"),S=ie({barId:"ctMergeVidProgBar",labelId:"ctMergeVidProgLabel",percentId:"ctMergeVidProgPct"});function f(l,o=""){const t=Math.min(100,Math.max(0,l)),m=o&&o.toLowerCase().includes("done")?o:X;if($&&(t>=100?$.textContent=o||m:t<=0&&!o?$.textContent="Ready":$.textContent=`Working⦠${Math.round(t)}%`),t>=100){S.ui.setDone(o||m);return}if(t<=0&&!o){S.ui.hardReset("Ready");return}if(t<=0){S.ui.beginEncoding(o);return}S(t,o)}function fe(l,o,t){const m=l.slice(),[h]=m.splice(o,1);return m.splice(t,0,h),m}function pe(l){typeof bootstrap>"u"||!bootstrap.Tooltip||l.querySelectorAll('[data-bs-toggle="tooltip"]').forEach(o=>{bootstrap.Tooltip.getOrCreateInstance(o,{trigger:"hover focus",container:"body"})})}function he(l,o,t,m){t.forEach(w=>URL.revokeObjectURL(w)),t.length=0,l.innerHTML="";let h=null;o.forEach((w,C)=>{const x=URL.createObjectURL(w);t.push(x);const M=document.createElement("div");M.className="col-12 col-lg-6";const n=document.createElement("div");n.className="ct-merge-vid-item h-100 d-flex flex-column",n.dataset.index=String(C),n.setAttribute("role","listitem"),n.draggable=!0;const p=document.createElement("div");p.className="ct-merge-vid-item__head";const a=document.createElement("span");a.className="ct-merge-vid-item__grip flex-shrink-0",a.setAttribute("aria-hidden","true"),a.title="Drag to reorder",a.textContent="⠿";const d=document.createElement("button");d.type="button",d.className="btn btn-sm btn-outline-danger ct-merge-vid-item__del flex-shrink-0",d.setAttribute("aria-label","Remove this clip"),d.setAttribute("data-bs-toggle","tooltip"),d.setAttribute("data-bs-placement","top"),d.setAttribute("data-bs-title","Remove this clip from the merge list"),d.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16" aria-hidden="true"><path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/><path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h3.5a1 1 0 0 1 1-1h1a1 1 0 0 1 1 1H15a1 1 0 0 1 1 1v1zm-1 .5V2h-11v1h11zM5 4v9h6V4H5z"/></svg>',d.draggable=!1,d.addEventListener("mousedown",e=>e.stopPropagation());const v=C;d.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation();const i=m.getQueue();v<0||v>=i.length||(i.splice(v,1),m.setQueue(i))}),p.appendChild(a),p.appendChild(d);const s=document.createElement("div");s.className="ct-merge-vid-item__video-wrap flex-shrink-0";const b=document.createElement("video");b.className="ct-merge-vid-preview-video rounded border",b.draggable=!1,b.controls=!0,b.playsInline=!0,b.src=x,s.appendChild(b);const y=document.createElement("div");y.className="ct-merge-vid-item__meta flex-grow-1 min-w-0 mt-1";const T=document.createElement("p");T.className="small text-body-secondary mb-0 text-break fw-medium",T.textContent=w.name;const P=document.createElement("p");P.className="small text-body-tertiary mb-0",P.textContent=`Position ${C+1} of ${o.length}`,y.appendChild(T),y.appendChild(P),n.appendChild(p),n.appendChild(s),n.appendChild(y),n.addEventListener("dragstart",e=>{h=v,e.dataTransfer.setData("text/plain",String(v)),e.dataTransfer.effectAllowed="move",n.classList.add("opacity-50")}),n.addEventListener("dragend",()=>{h=null,n.classList.remove("opacity-50"),l.querySelectorAll(".ct-merge-vid-item--drag-over").forEach(e
1=>{e.classList.remove("ct-merge-vid-item--drag-over")})}),n.addEventListener("dragover",e=>{e.preventDefault(),e.dataTransfer.dropEffect="move",h!==null&&h!==v&&n.classList.add("ct-merge-vid-item--drag-over")}),n.addEventListener("dragleave",e=>{const i=e.relatedTarget;i instanceof Node&&n.contains(i)||n.classList.remove("ct-merge-vid-item--drag-over")}),n.addEventListener("drop",e=>{e.preventDefault(),e.stopPropagation(),n.classList.remove("ct-merge-vid-item--drag-over");const i=e.dataTransfer.getData("text/plain"),A=parseInt(i,10),g=h!==null?h:A,E=v;if(!Number.isFinite(g)||g===E)return;const u=m.getQueue();g<0||g>=u.length||E<0||E>=u.length||(h=null,m.setQueue(fe(u,g,E)))}),M.appendChild(n),l.appendChild(M)}),pe(l)}function Ne(){const l=document.getElementById("ct-merge-video-online-root");if(!ge(l,"ctMergeVidWired"))return;const o=(l.dataset.ctFormat||"mp4").toLowerCase(),t=document.getElementById("ctMergeVidFile"),m=document.getElementById("ctMergeVidDrop"),h=document.getElementById("ctMergeVidDropCaption"),w=document.getElementById("ctMergeVidPreviews"),C=document.getElementById("ctMergeVidBtn"),x=document.getElementById("ctMergeVidDownload"),M=oe();te(x,M);const n=document.getElementById("ctMergeVidClr"),p=document.getElementById("ctMergeVidName"),a=document.getElementById("ctMergeVidWasmStatus");if(!t||!w||!C||!n)return;t.setAttribute("accept",H());const d=[],v=ce(a);let s=null;const b=de({nameInput:p instanceof HTMLInputElement?p:null,defaultName:"merged_video",suffix:"_merged",getSourceFileName:()=>{var i;return((i=(s?s.getQueue():Array.from(t.files||[]))[0])==null?void 0:i.name)||null}}),y=()=>{var i;const e=s?s.getQueue().length:((i=t.files)==null?void 0:i.length)??0;C.disabled=e<2,n.disabled=e<1},T=()=>{if(!s){Array.from(t.files||[]).find(u=>!G(u,H()))&&(_("Only video files are allowed."),q(t));const E=Array.from(t.files||[]);d.forEach(u=>URL.revokeObjectURL(u)),d.length=0,w.innerHTML="",E.forEach(u=>{const D=URL.createObjectURL(u);d.push(D);const c=document.createElement("div");c.className="small text-body-secondary",c.textContent=u.name,w.appendChild(c)}),y();return}const e=s.getQueue();if(e.find(A=>
1!G(A,H()))){_("Only video files are allowed."),s.setQueue([]);return}he(w,e,d,s),y()},P=()=>{T(),(s?s.getQueue():Array.from(t.files||[])).length?b.onFileReady():b.onFileCleared()};m?s=se({input:t,drop:m,dragContainer:m.closest(".card-body"),captionEl:h,accumulate:!0,onChange:P}):t.addEventListener("change",P),f(0,""),n.addEventListener("click",()=>{M.clear(),M.syncDownloadButton(x),v.invalidate(),s?s.setQueue([]):q(t),p&&(p.value="merged_video"),b.onFileCleared(),f(0,""),a&&(a.textContent=""),y()}),C.addEventListener("click",async()=>{const e=s?s.getQueue():Array.from(t.files||[]);if(e.length<2){_("Select at least two videos.");return}for(const c of e)if(c.size>ue){_("Each file must be 500 MB or less.");return}C.disabled=!0,f(2,"Preparingâ¦"),ne(a);const i=[],A=async(c,V)=>{if(V)for(const F of c)try{await V.deleteFile(F)}catch{}};let g;try{g=await v.ensureFfmpeg(),f(20,"Preparingâ¦")}catch(c){W(c)||_(c instanceof Error?c.message:"Could not load the converter."),y(),f(0,"");return}a&&(a.textContent="Mergingâ¦");const E=e.length,u=12,D=60;try{for(let r=0;r<e.length;r++){const L=e[r],I=re(L.name,o),N=`in${r}.${I}`,U=`part${r}.mp4`;i.push(N,U);const O=u+r/E*(D-u),j=u+(r+1)/E*(D-u);await g.writeFile(N,await ae(L));const Z=r+1;await k(g,["-y","-i",N,"-c:v","libx264","-preset","veryfast","-crf","23","-pix_fmt","yuv420p","-c:a","aac","-b:a","128k",U],{phaseLo:O,phaseHi:j,labelForPercent:R=>`${Math.round(O+R/100*(j-O))}% â Step 1 (before merge): re-encoding clip ${Z} of ${E} to the same video/audio format (H.264 + AAC) so all parts can be joined â ${R}% of this clip`,onProgress:(R,z)=>f(R,z)})}let c="";for(let r=0;r<e.length;r++)c+=`file 'part${r}.mp4' 2`;const V="concat_list.txt",F="merged_concat.mp4";i.push(V,F),await g.writeFile(V,c),await k(g,["-y","-f","concat","-safe","0","-i",V,"-c","copy",F],{phaseLo:62,phaseHi:68,labelForPercent:r=>`${Math.round(62+r/100*6)}% â Step 2 (merge): stitching clips in order into one continuous video (fast join; not a full re-encode) â ${r}% of this step`,onProgress:(r,L)=>f(r,L)});let Q=F;if(o!=="mp4"){const r=`merged_final.${o}`;i.push(r);const L=le(o);await k(g,["-y","-i",F,...L,r],{phaseLo:70,phaseHi:94,labelForPercent:I=>`${Math.round(70+I/100*24)}% â Step 3 (export): encoding the merged video as .${o} for download â ${I}% of this encode`,onProgress:(I,N)=>f(I,N)}),Q=r}else f(85,"MP4 output: merged video is ready; preparing downloadâ¦");f(Math.min(98,o==="mp4"?92:96),"Almost done: reading merged file from memoryâ¦");const B=await g.readFile(Q),Y=B.buffer?B.buffer.slice(B.byteOffset,B.byteOffset+B.byteLength):B,J=new Blob([Y],{type:`video/${o}`}),K=((p==null?void 0:p.value)||"merged_video").replace(/[^\w\-]+/g,"_");await ee(M,x,{blob:J,filename:`${K}.${o}`,setProgress:f}),a&&(a.textContent="Done."),f(100,X)}catch(c){W(c)||(_(c instanceof Error?c.message:"Merge failed."),a&&(a.textContent="Merge failed.")),f(0,"")}finally{await A(i,g),y(),a&&a.textContent!=="Merge failed."&&setTimeout(()=>{a.textContent==="Done."&&(a.textContent="")},2e3)}})}export{Ne as initMergeVideoOnlinePage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.