@uploadista/flow-videos-av-node 0.0.18-beta.17 → 0.0.18-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,21 @@
1
-
2
- 
3
- > @uploadista/flow-videos-av-node@0.0.18-beta.16 build /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/videos/av-node
4
- > tsdown
5
-
6
- ℹ tsdown v0.16.8 powered by rolldown v1.0.0-beta.52
7
- ℹ Using tsdown config: /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/videos/av-node/tsdown.config.ts
8
- ℹ entry: src/index.ts
9
- ℹ tsconfig: tsconfig.json
10
- ℹ Build start
11
- ℹ Cleaning 7 files
12
- ℹ [CJS] dist/index.cjs 8.09 kB │ gzip: 2.39 kB
13
- ℹ [CJS] 1 files, total: 8.09 kB
14
- ℹ [ESM] dist/index.mjs  7.81 kB │ gzip: 2.50 kB
15
- ℹ [ESM] dist/index.mjs.map 34.42 kB │ gzip: 6.80 kB
16
- ℹ [ESM] dist/index.d.mts.map  0.88 kB │ gzip: 0.47 kB
17
- ℹ [ESM] dist/index.d.mts  3.39 kB │ gzip: 1.04 kB
18
- ℹ [ESM] 4 files, total: 46.51 kB
19
- ℹ [CJS] dist/index.d.cts.map 0.88 kB │ gzip: 0.47 kB
20
- ℹ [CJS] dist/index.d.cts 3.39 kB │ gzip: 1.04 kB
21
- ℹ [CJS] 2 files, total: 4.28 kB
22
- ✔ Build complete in 4724ms
1
+
2
+ > @uploadista/flow-videos-av-node@0.0.18-beta.1 build /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/videos/av-node
3
+ > tsdown
4
+
5
+ ℹ tsdown v0.16.6 powered by rolldown v1.0.0-beta.51
6
+ ℹ Using tsdown config: /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/flow/videos/av-node/tsdown.config.ts
7
+ ℹ entry: src/index.ts
8
+ ℹ tsconfig: tsconfig.json
9
+ ℹ Build start
10
+ ℹ Cleaning 7 files
11
+ ℹ [CJS] dist/index.cjs 7.28 kB │ gzip: 2.22 kB
12
+ ℹ [CJS] 1 files, total: 7.28 kB
13
+ ℹ [ESM] dist/index.mjs  7.09 kB │ gzip: 2.32 kB
14
+ ℹ [ESM] dist/index.mjs.map 32.57 kB │ gzip: 6.47 kB
15
+ ℹ [ESM] dist/index.d.mts.map  0.88 kB │ gzip: 0.47 kB
16
+ ℹ [ESM] dist/index.d.mts  3.39 kB │ gzip: 1.04 kB
17
+ ℹ [ESM] 4 files, total: 43.94 kB
18
+ ℹ [CJS] dist/index.d.cts.map 0.88 kB │ gzip: 0.47 kB
19
+ ℹ [CJS] dist/index.d.cts 3.39 kB │ gzip: 1.04 kB
20
+ ℹ [CJS] 2 files, total: 4.28 kB
21
+ ✔ Build complete in 4629ms
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- let e=require(`node-av/constants`),t=require(`@uploadista/core/errors`),n=require(`@uploadista/observability`),r=require(`effect`),i=require(`node-av/api`),a=require(`@uploadista/core/flow`);async function o(){try{return await import(`node-av`),{available:!0,version:`4.x`}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}}const s={mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,avi:`video/x-msvideo`},c={mp4:`mp4`,webm:`webm`,mov:`mov`,avi:`avi`},l={h264:e.FF_ENCODER_LIBX264,h265:e.FF_ENCODER_LIBX265,vp9:e.FF_ENCODER_LIBVPX_VP9,av1:e.FF_ENCODER_LIBAOM_AV1},u={aac:e.FF_ENCODER_AAC,mp3:e.FF_ENCODER_LIBMP3LAME,opus:e.FF_ENCODER_LIBOPUS,vorbis:e.FF_ENCODER_LIBVORBIS},d={jpeg:e.FF_ENCODER_MJPEG,mjpeg:e.FF_ENCODER_MJPEG,png:e.FF_ENCODER_PNG};function f(){let e=[],t=0n;return{callbacks:{write:n=>(e.push(n),t+=BigInt(n.length),n.length),seek:(e,n)=>{switch(n){case 0:t=e;break;case 1:t+=e;break;case 2:t=e;break}return t}},getOutput:()=>{let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}}}function p(){return{describe:e=>r.Effect.tryPromise({try:async()=>{let t=Buffer.from(e);await using n=await i.Demuxer.open(t);let r=n.video(),a=n.audio();if(!r)throw Error(`No video stream found`);let o=r.codecpar,s=0;if(r.rFrameRate){let{num:e,den:t}=r.rFrameRate;s=t?e/t:e}let c=`unknown`;if(r.sampleAspectRatio){let{num:e,den:t}=r.sampleAspectRatio;c=`${e}:${t}`}return{duration:n.duration||0,width:o.width||0,height:o.height||0,codec:String(o.codecId)||`unknown`,format:n.formatName||`unknown`,bitrate:n.bitRate||0,frameRate:s,aspectRatio:c,hasAudio:!!a,audioCodec:a?.codecpar.codecId?String(a.codecpar.codecId):void 0,audioBitrate:a?.codecpar.bitRate?Number(a.codecpar.bitRate):void 0,size:e.byteLength}},catch:e=>t.UploadistaError.fromCode(`VIDEO_METADATA_EXTRACTION_FAILED`,{body:`Failed to extract video metadata: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe((0,n.withOperationSpan)(`video`,`describe`,{"video.input_size":e.byteLength})),transcode:(e,a)=>r.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),{callbacks:n,getOutput:r}=f();await using o=await i.Demuxer.open(t),s=await i.Muxer.open(n,{format:a.format});let c=o.video();if(!c)throw Error(`No video stream found`);using d=await i.Decoder.create(c);let p=a.codec?l[a.codec]:l.h264;using m=await i.Encoder.create(p,{...a.videoBitrate&&{bitrate:a.videoBitrate}});let h=s.addStream(m);for await(using e of d.frames(o.packets(c.index))){if(!e)continue;await m.encode(e);let t=await m.receive();for(;t;)await s.writePacket(t,h),t.free(),t=await m.receive()}await m.flush();let g=await m.receive();for(;g;)await s.writePacket(g,h),g.free(),g=await m.receive();let _=o.audio();if(_){using e=await i.Decoder.create(_);let t=a.audioCodec?u[a.audioCodec]:u.aac;using n=await i.Encoder.create(t,{...a.audioBitrate&&{bitrate:a.audioBitrate}});let r=s.addStream(n);for await(using t of e.frames(o.packets(_.index))){if(!t)continue;await n.encode(t);let e=await n.receive();for(;e;)await s.writePacket(e,r),e.free(),e=await n.receive()}await n.flush();let c=await n.receive();for(;c;)await s.writePacket(c,r),c.free(),c=await n.receive()}return r()},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Transcode failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe((0,n.withOperationSpan)(`video`,`transcode`,{"video.format":a.format,"video.codec":a.codec,"video.video_bitrate":a.videoBitrate,"video.audio_codec":a.audioCodec,"video.audio_bitrate":a.audioBitrate,"video.input_size":e.byteLength})),resize:(e,a)=>r.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),{callbacks:n,getOutput:r}=f();await using o=await i.Demuxer.open(t),s=await i.Muxer.open(n,{format:`mp4`});let c=o.video();if(!c)throw Error(`No video stream found`);using d=await i.Decoder.create(c);if(!a.width&&!a.height)throw Error(`Either width or height must be specified`);using p=await i.Encoder.create(l.h264);let m=s.addStream(p);for await(using e of d.frames(o.packets(c.index))){if(!e)continue;await p.encode(e);let t=await p.receive();for(;t;)await s.writePacket(t,m),t.free(),t=await p.receive()}await p.flush();let h=await p.receive();for(;h;)await s.writePacket(h,m),h.free(),h=await p.receive();let g=o.audio();if(g){using e=await i.Decoder.create(g),t=await i.Encoder.create(u.aac);let n=s.addStream(t);for await(using r of e.frames(o.packets(g.index))){if(!r)continue;await t.encode(r);let e=await t.receive();for(;e;)await s.writePacket(e,n),e.free(),e=await t.receive()}await t.flush();let r=await t.receive();for(;r;)await s.writePacket(r,n),r.free(),r=await t.receive()}return r()},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Resize failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe((0,n.withOperationSpan)(`video`,`resize`,{"video.width":a.width,"video.height":a.height,"video.input_size":e.byteLength})),trim:(e,a)=>r.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),{callbacks:n,getOutput:r}=f();await using o=await i.Demuxer.open(t),s=await i.Muxer.open(n,{format:`mp4`});let c=o.video();if(!c)throw Error(`No video stream found`);let d;d=a.duration===void 0?a.endTime===void 0?o.duration||1/0:a.endTime:a.startTime+a.duration;using p=await i.Decoder.create(c),m=await i.Encoder.create(l.h264);let h=s.addStream(m);for await(using e of p.frames(o.packets(c.index))){if(!e)continue;let t=e.pts||0n,n=c.timeBase?c.timeBase.num/c.timeBase.den:1,r=Number(t)*n;if(r>=a.startTime&&r<d){await m.encode(e);let t=await m.receive();for(;t;)await s.writePacket(t,h),t.free(),t=await m.receive()}if(r>=d)break}await m.flush();let g=await m.receive();for(;g;)await s.writePacket(g,h),g.free(),g=await m.receive();let _=o.audio();if(_){using e=await i.Decoder.create(_),t=await i.Encoder.create(u.aac);let n=s.addStream(t);for await(using r of e.frames(o.packets(_.index))){if(!r)continue;let e=r.pts||0n,i=_.timeBase?_.timeBase.num/_.timeBase.den:1,o=Number(e)*i;if(o>=a.startTime&&o<d){await t.encode(r);let e=await t.receive();for(;e;)await s.writePacket(e,n),e.free(),e=await t.receive()}if(o>=d)break}await t.flush();let r=await t.receive();for(;r;)await s.writePacket(r,n),r.free(),r=await t.receive()}return r()},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Trim failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe((0,n.withOperationSpan)(`video`,`trim`,{"video.start_time":a.startTime,"video.end_time":a.endTime,"video.duration":a.duration,"video.input_size":e.byteLength})),extractFrame:(e,a)=>r.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),n=a.format||`jpeg`;await using r=await i.Demuxer.open(t);let o=r.video();if(!o)throw Error(`No video stream found`);using s=await i.Decoder.create(o);let c=null,l=a.timestamp;for await(using e of s.frames(r.packets(o.index))){if(!e)continue;let t=e.pts||0n,r=o.timeBase?o.timeBase.num/o.timeBase.den:1;if(Number(t)*r>=l){let t=d[n]||d.jpeg;using r=await i.Encoder.create(t);await r.encode(e);let a=await r.receive();if(a?.data){c=new Uint8Array(a.data),a.free();break}}}if(!c)throw Error(`No frame found at timestamp ${l}`);return c},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Frame extraction failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe((0,n.withOperationSpan)(`video`,`extract-frame`,{"video.timestamp":a.timestamp,"video.format":a.format??`jpeg`,"video.input_size":e.byteLength}))}}const m=r.Layer.succeed(a.VideoPlugin,p()),h=r.Layer.effectDiscard(r.Effect.gen(function*(){let e=yield*r.Effect.promise(()=>o());e.available?console.log(`✓ node-av ${e.version} detected`):console.warn(`⚠️ node-av is not installed or not available.`,`
1
+ let e=require(`node-av/constants`),t=require(`@uploadista/core/errors`),n=require(`effect`),r=require(`node-av/api`),i=require(`@uploadista/core/flow`);async function a(){try{return await import(`node-av`),{available:!0,version:`4.x`}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}}const o={mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,avi:`video/x-msvideo`},s={mp4:`mp4`,webm:`webm`,mov:`mov`,avi:`avi`},c={h264:e.FF_ENCODER_LIBX264,h265:e.FF_ENCODER_LIBX265,vp9:e.FF_ENCODER_LIBVPX_VP9,av1:e.FF_ENCODER_LIBAOM_AV1},l={aac:e.FF_ENCODER_AAC,mp3:e.FF_ENCODER_LIBMP3LAME,opus:e.FF_ENCODER_LIBOPUS,vorbis:e.FF_ENCODER_LIBVORBIS},u={jpeg:e.FF_ENCODER_MJPEG,mjpeg:e.FF_ENCODER_MJPEG,png:e.FF_ENCODER_PNG};function d(){let e=[],t=0n;return{callbacks:{write:n=>(e.push(n),t+=BigInt(n.length),n.length),seek:(e,n)=>{switch(n){case 0:t=e;break;case 1:t+=e;break;case 2:t=e;break}return t}},getOutput:()=>{let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}}}function f(){return{describe:e=>n.Effect.tryPromise({try:async()=>{let t=Buffer.from(e);await using n=await r.Demuxer.open(t);let i=n.video(),a=n.audio();if(!i)throw Error(`No video stream found`);let o=i.codecpar,s=0;if(i.rFrameRate){let{num:e,den:t}=i.rFrameRate;s=t?e/t:e}let c=`unknown`;if(i.sampleAspectRatio){let{num:e,den:t}=i.sampleAspectRatio;c=`${e}:${t}`}return{duration:n.duration||0,width:o.width||0,height:o.height||0,codec:String(o.codecId)||`unknown`,format:n.formatName||`unknown`,bitrate:n.bitRate||0,frameRate:s,aspectRatio:c,hasAudio:!!a,audioCodec:a?.codecpar.codecId?String(a.codecpar.codecId):void 0,audioBitrate:a?.codecpar.bitRate?Number(a.codecpar.bitRate):void 0,size:e.byteLength}},catch:e=>t.UploadistaError.fromCode(`VIDEO_METADATA_EXTRACTION_FAILED`,{body:`Failed to extract video metadata: ${e instanceof Error?e.message:String(e)}`,cause:e})}),transcode:(e,i)=>n.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),{callbacks:n,getOutput:a}=d();await using o=await r.Demuxer.open(t),s=await r.Muxer.open(n,{format:i.format});let u=o.video();if(!u)throw Error(`No video stream found`);using f=await r.Decoder.create(u);let p=i.codec?c[i.codec]:c.h264;using m=await r.Encoder.create(p,{...i.videoBitrate&&{bitrate:i.videoBitrate}});let h=s.addStream(m);for await(using e of f.frames(o.packets(u.index))){if(!e)continue;await m.encode(e);let t=await m.receive();for(;t;)await s.writePacket(t,h),t.free(),t=await m.receive()}await m.flush();let g=await m.receive();for(;g;)await s.writePacket(g,h),g.free(),g=await m.receive();let _=o.audio();if(_){using e=await r.Decoder.create(_);let t=i.audioCodec?l[i.audioCodec]:l.aac;using n=await r.Encoder.create(t,{...i.audioBitrate&&{bitrate:i.audioBitrate}});let a=s.addStream(n);for await(using t of e.frames(o.packets(_.index))){if(!t)continue;await n.encode(t);let e=await n.receive();for(;e;)await s.writePacket(e,a),e.free(),e=await n.receive()}await n.flush();let c=await n.receive();for(;c;)await s.writePacket(c,a),c.free(),c=await n.receive()}return a()},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Transcode failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}),resize:(e,i)=>n.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),{callbacks:n,getOutput:a}=d();await using o=await r.Demuxer.open(t),s=await r.Muxer.open(n,{format:`mp4`});let u=o.video();if(!u)throw Error(`No video stream found`);using f=await r.Decoder.create(u);if(!i.width&&!i.height)throw Error(`Either width or height must be specified`);using p=await r.Encoder.create(c.h264);let m=s.addStream(p);for await(using e of f.frames(o.packets(u.index))){if(!e)continue;await p.encode(e);let t=await p.receive();for(;t;)await s.writePacket(t,m),t.free(),t=await p.receive()}await p.flush();let h=await p.receive();for(;h;)await s.writePacket(h,m),h.free(),h=await p.receive();let g=o.audio();if(g){using e=await r.Decoder.create(g),t=await r.Encoder.create(l.aac);let n=s.addStream(t);for await(using r of e.frames(o.packets(g.index))){if(!r)continue;await t.encode(r);let e=await t.receive();for(;e;)await s.writePacket(e,n),e.free(),e=await t.receive()}await t.flush();let i=await t.receive();for(;i;)await s.writePacket(i,n),i.free(),i=await t.receive()}return a()},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Resize failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}),trim:(e,i)=>n.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),{callbacks:n,getOutput:a}=d();await using o=await r.Demuxer.open(t),s=await r.Muxer.open(n,{format:`mp4`});let u=o.video();if(!u)throw Error(`No video stream found`);let f;f=i.duration===void 0?i.endTime===void 0?o.duration||1/0:i.endTime:i.startTime+i.duration;using p=await r.Decoder.create(u),m=await r.Encoder.create(c.h264);let h=s.addStream(m);for await(using e of p.frames(o.packets(u.index))){if(!e)continue;let t=e.pts||0n,n=u.timeBase?u.timeBase.num/u.timeBase.den:1,r=Number(t)*n;if(r>=i.startTime&&r<f){await m.encode(e);let t=await m.receive();for(;t;)await s.writePacket(t,h),t.free(),t=await m.receive()}if(r>=f)break}await m.flush();let g=await m.receive();for(;g;)await s.writePacket(g,h),g.free(),g=await m.receive();let _=o.audio();if(_){using e=await r.Decoder.create(_),t=await r.Encoder.create(l.aac);let n=s.addStream(t);for await(using r of e.frames(o.packets(_.index))){if(!r)continue;let e=r.pts||0n,a=_.timeBase?_.timeBase.num/_.timeBase.den:1,o=Number(e)*a;if(o>=i.startTime&&o<f){await t.encode(r);let e=await t.receive();for(;e;)await s.writePacket(e,n),e.free(),e=await t.receive()}if(o>=f)break}await t.flush();let a=await t.receive();for(;a;)await s.writePacket(a,n),a.free(),a=await t.receive()}return a()},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Trim failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}),extractFrame:(e,i)=>n.Effect.tryPromise({try:async()=>{let t=Buffer.from(e),n=i.format||`jpeg`;await using a=await r.Demuxer.open(t);let o=a.video();if(!o)throw Error(`No video stream found`);using s=await r.Decoder.create(o);let c=null,l=i.timestamp;for await(using e of s.frames(a.packets(o.index))){if(!e)continue;let t=e.pts||0n,i=o.timeBase?o.timeBase.num/o.timeBase.den:1;if(Number(t)*i>=l){let t=u[n]||u.jpeg;using i=await r.Encoder.create(t);await i.encode(e);let a=await i.receive();if(a?.data){c=new Uint8Array(a.data),a.free();break}}}if(!c)throw Error(`No frame found at timestamp ${l}`);return c},catch:e=>t.UploadistaError.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Frame extraction failed: ${e instanceof Error?e.message:String(e)}`,cause:e})})}}const p=n.Layer.succeed(i.VideoPlugin,f()),m=n.Layer.effectDiscard(n.Effect.gen(function*(){let e=yield*n.Effect.promise(()=>a());e.available?console.log(`✓ node-av ${e.version} detected`):console.warn(`⚠️ node-av is not installed or not available.`,`
2
2
  Video processing operations will fail.`,`
3
- Install node-av: npm install node-av`)})).pipe(r.Layer.provideMerge(m));exports.AVNodeVideoPlugin=m,exports.AVNodeVideoPluginWithCheck=h,exports.audioCodecToAVName=u,exports.checkAVAvailable=o,exports.codecToAVName=l,exports.createAVNodeVideoPlugin=p,exports.formatToExtension=c,exports.formatToMimeType=s,exports.imageFormatToEncoder=d;
3
+ Install node-av: npm install node-av`)})).pipe(n.Layer.provideMerge(p));exports.AVNodeVideoPlugin=p,exports.AVNodeVideoPluginWithCheck=m,exports.audioCodecToAVName=l,exports.checkAVAvailable=a,exports.codecToAVName=c,exports.createAVNodeVideoPlugin=f,exports.formatToExtension=s,exports.formatToMimeType=o,exports.imageFormatToEncoder=u;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/utils/av-check.ts","../src/utils/format-mappings.ts","../src/video-plugin.ts","../src/video-plugin-layer.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAGY,aAAA;;EAAA,OAAA,CAAA,EAAA,MAAa;EAUH,KAAA,CAAA,EAAA,MAAA;;;;ACKtB;AAWA;AAWa,iBD3BS,gBAAA,CAAA,CCmCrB,EDnCyC,OCmCzC,CDnCiD,aCmCjD,CAAA;;;;;;AD7CW,cCeC,gBDfY,ECeM,MDfN,CCea,oBDfb,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA;AAUzB;;;cCgBa,mBAAmB,OAAO;AAXvC;AAWA;AAWA;AACc,cADD,aACC,EADc,MACd,CAAZ,WAAY,CAAA,oBAAA,CAAA,OAAA,CAAA,CAAA,EACZ,cADY,CAAA;;;;AADoB,cAarB,kBAbqB,EAaD,MAbC,CAchC,WAdgC,CAcpB,oBAdoB,CAAA,YAAA,CAAA,CAAA,EAehC,cAfgC,CAAA;AAalC;;;AAEE,cAWW,oBAXX,EAWiC,MAXjC,CAAA,MAAA,EAWgD,cAXhD,CAAA;;;;;;iBCrCc,uBAAA,CAAA,GAA2B;;;;;;AFf3C;AAUA;;;;ACKA;AAWA;AAWA;;;;;;AAaA;;;;;;AAaA;cEtCa,mBAAiB,KAAA,CAAA,MAAA;;;ADV9B;;;;ACUA;AA4BA;;;;;;;;;;;;;;;;cAAa,4BAA0B,KAAA,CAAA,MAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/utils/av-check.ts","../src/utils/format-mappings.ts","../src/video-plugin.ts","../src/video-plugin-layer.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAGY,aAAA;;EAAA,OAAA,CAAA,EAAA,MAAa;EAUH,KAAA,CAAA,EAAA,MAAA;;;;ACKtB;AAWA;AAWa,iBD3BS,gBAAA,CAAA,CCmCrB,EDnCyC,OCmCzC,CDnCiD,aCmCjD,CAAA;;;;;;AD7CW,cCeC,gBDfY,ECeM,MDfN,CCea,oBDfb,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA;AAUzB;;;cCgBa,mBAAmB,OAAO;AAXvC;AAWA;AAWA;AACc,cADD,aACC,EADc,MACd,CAAZ,WAAY,CAAA,oBAAA,CAAA,OAAA,CAAA,CAAA,EACZ,cADY,CAAA;;;;AADoB,cAarB,kBAbqB,EAaD,MAbC,CAchC,WAdgC,CAcpB,oBAdoB,CAAA,YAAA,CAAA,CAAA,EAehC,cAfgC,CAAA;AAalC;;;AAEE,cAWW,oBAXX,EAWiC,MAXjC,CAAA,MAAA,EAWgD,cAXhD,CAAA;;;;;;iBCtCc,uBAAA,CAAA,GAA2B;;;;;;AFd3C;AAUA;;;;ACKA;AAWA;AAWA;;;;;;AAaA;;;;;;AAaA;cEtCa,mBAAiB,KAAA,CAAA,MAAA;;;ADX9B;;;;ACWA;AA4BA;;;;;;;;;;;;;;;;cAAa,4BAA0B,KAAA,CAAA,MAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/av-check.ts","../src/utils/format-mappings.ts","../src/video-plugin.ts","../src/video-plugin-layer.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAGY,aAAA;;EAAA,OAAA,CAAA,EAAA,MAAa;EAUH,KAAA,CAAA,EAAA,MAAA;;;;ACKtB;AAWA;AAWa,iBD3BS,gBAAA,CAAA,CCmCrB,EDnCyC,OCmCzC,CDnCiD,aCmCjD,CAAA;;;;;;AD7CW,cCeC,gBDfY,ECeM,MDfN,CCea,oBDfb,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA;AAUzB;;;cCgBa,mBAAmB,OAAO;AAXvC;AAWA;AAWA;AACc,cADD,aACC,EADc,MACd,CAAZ,WAAY,CAAA,oBAAA,CAAA,OAAA,CAAA,CAAA,EACZ,cADY,CAAA;;;;AADoB,cAarB,kBAbqB,EAaD,MAbC,CAchC,WAdgC,CAcpB,oBAdoB,CAAA,YAAA,CAAA,CAAA,EAehC,cAfgC,CAAA;AAalC;;;AAEE,cAWW,oBAXX,EAWiC,MAXjC,CAAA,MAAA,EAWgD,cAXhD,CAAA;;;;;;iBCrCc,uBAAA,CAAA,GAA2B;;;;;;AFf3C;AAUA;;;;ACKA;AAWA;AAWA;;;;;;AAaA;;;;;;AAaA;cEtCa,mBAAiB,KAAA,CAAA,MAAA;;;ADV9B;;;;ACUA;AA4BA;;;;;;;;;;;;;;;;cAAa,4BAA0B,KAAA,CAAA,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/utils/av-check.ts","../src/utils/format-mappings.ts","../src/video-plugin.ts","../src/video-plugin-layer.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAGY,aAAA;;EAAA,OAAA,CAAA,EAAA,MAAa;EAUH,KAAA,CAAA,EAAA,MAAA;;;;ACKtB;AAWA;AAWa,iBD3BS,gBAAA,CAAA,CCmCrB,EDnCyC,OCmCzC,CDnCiD,aCmCjD,CAAA;;;;;;AD7CW,cCeC,gBDfY,ECeM,MDfN,CCea,oBDfb,CAAA,QAAA,CAAA,EAAA,MAAA,CAAA;AAUzB;;;cCgBa,mBAAmB,OAAO;AAXvC;AAWA;AAWA;AACc,cADD,aACC,EADc,MACd,CAAZ,WAAY,CAAA,oBAAA,CAAA,OAAA,CAAA,CAAA,EACZ,cADY,CAAA;;;;AADoB,cAarB,kBAbqB,EAaD,MAbC,CAchC,WAdgC,CAcpB,oBAdoB,CAAA,YAAA,CAAA,CAAA,EAehC,cAfgC,CAAA;AAalC;;;AAEE,cAWW,oBAXX,EAWiC,MAXjC,CAAA,MAAA,EAWgD,cAXhD,CAAA;;;;;;iBCtCc,uBAAA,CAAA,GAA2B;;;;;;AFd3C;AAUA;;;;ACKA;AAWA;AAWA;;;;;;AAaA;;;;;;AAaA;cEtCa,mBAAiB,KAAA,CAAA,MAAA;;;ADX9B;;;;ACWA;AA4BA;;;;;;;;;;;;;;;;cAAa,4BAA0B,KAAA,CAAA,MAAA"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{FF_ENCODER_AAC as e,FF_ENCODER_LIBAOM_AV1 as t,FF_ENCODER_LIBMP3LAME as n,FF_ENCODER_LIBOPUS as r,FF_ENCODER_LIBVORBIS as i,FF_ENCODER_LIBVPX_VP9 as a,FF_ENCODER_LIBX264 as o,FF_ENCODER_LIBX265 as s,FF_ENCODER_MJPEG as c,FF_ENCODER_PNG as l}from"node-av/constants";import{UploadistaError as u}from"@uploadista/core/errors";import{withOperationSpan as d}from"@uploadista/observability";import{Effect as f,Layer as p}from"effect";import{Decoder as m,Demuxer as h,Encoder as g,Muxer as _}from"node-av/api";import{VideoPlugin as v}from"@uploadista/core/flow";async function y(){try{return await import(`node-av`),{available:!0,version:`4.x`}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}}const b={mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,avi:`video/x-msvideo`},x={mp4:`mp4`,webm:`webm`,mov:`mov`,avi:`avi`},S={h264:o,h265:s,vp9:a,av1:t},C={aac:e,mp3:n,opus:r,vorbis:i},w={jpeg:c,mjpeg:c,png:l};function T(){let e=[],t=0n;return{callbacks:{write:n=>(e.push(n),t+=BigInt(n.length),n.length),seek:(e,n)=>{switch(n){case 0:t=e;break;case 1:t+=e;break;case 2:t=e;break}return t}},getOutput:()=>{let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}}}function E(){return{describe:e=>f.tryPromise({try:async()=>{let t=Buffer.from(e);await using n=await h.open(t);let r=n.video(),i=n.audio();if(!r)throw Error(`No video stream found`);let a=r.codecpar,o=0;if(r.rFrameRate){let{num:e,den:t}=r.rFrameRate;o=t?e/t:e}let s=`unknown`;if(r.sampleAspectRatio){let{num:e,den:t}=r.sampleAspectRatio;s=`${e}:${t}`}return{duration:n.duration||0,width:a.width||0,height:a.height||0,codec:String(a.codecId)||`unknown`,format:n.formatName||`unknown`,bitrate:n.bitRate||0,frameRate:o,aspectRatio:s,hasAudio:!!i,audioCodec:i?.codecpar.codecId?String(i.codecpar.codecId):void 0,audioBitrate:i?.codecpar.bitRate?Number(i.codecpar.bitRate):void 0,size:e.byteLength}},catch:e=>u.fromCode(`VIDEO_METADATA_EXTRACTION_FAILED`,{body:`Failed to extract video metadata: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe(d(`video`,`describe`,{"video.input_size":e.byteLength})),transcode:(e,t)=>f.tryPromise({try:async()=>{let n=Buffer.from(e),{callbacks:r,getOutput:i}=T();await using a=await h.open(n),o=await _.open(r,{format:t.format});let s=a.video();if(!s)throw Error(`No video stream found`);using c=await m.create(s);let l=t.codec?S[t.codec]:S.h264;using u=await g.create(l,{...t.videoBitrate&&{bitrate:t.videoBitrate}});let d=o.addStream(u);for await(using e of c.frames(a.packets(s.index))){if(!e)continue;await u.encode(e);let t=await u.receive();for(;t;)await o.writePacket(t,d),t.free(),t=await u.receive()}await u.flush();let f=await u.receive();for(;f;)await o.writePacket(f,d),f.free(),f=await u.receive();let p=a.audio();if(p){using e=await m.create(p);let n=t.audioCodec?C[t.audioCodec]:C.aac;using r=await g.create(n,{...t.audioBitrate&&{bitrate:t.audioBitrate}});let i=o.addStream(r);for await(using t of e.frames(a.packets(p.index))){if(!t)continue;await r.encode(t);let e=await r.receive();for(;e;)await o.writePacket(e,i),e.free(),e=await r.receive()}await r.flush();let s=await r.receive();for(;s;)await o.writePacket(s,i),s.free(),s=await r.receive()}return i()},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Transcode failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe(d(`video`,`transcode`,{"video.format":t.format,"video.codec":t.codec,"video.video_bitrate":t.videoBitrate,"video.audio_codec":t.audioCodec,"video.audio_bitrate":t.audioBitrate,"video.input_size":e.byteLength})),resize:(e,t)=>f.tryPromise({try:async()=>{let n=Buffer.from(e),{callbacks:r,getOutput:i}=T();await using a=await h.open(n),o=await _.open(r,{format:`mp4`});let s=a.video();if(!s)throw Error(`No video stream found`);using c=await m.create(s);if(!t.width&&!t.height)throw Error(`Either width or height must be specified`);using l=await g.create(S.h264);let u=o.addStream(l);for await(using e of c.frames(a.packets(s.index))){if(!e)continue;await l.encode(e);let t=await l.receive();for(;t;)await o.writePacket(t,u),t.free(),t=await l.receive()}await l.flush();let d=await l.receive();for(;d;)await o.writePacket(d,u),d.free(),d=await l.receive();let f=a.audio();if(f){using e=await m.create(f),t=await g.create(C.aac);let n=o.addStream(t);for await(using r of e.frames(a.packets(f.index))){if(!r)continue;await t.encode(r);let e=await t.receive();for(;e;)await o.writePacket(e,n),e.free(),e=await t.receive()}await t.flush();let r=await t.receive();for(;r;)await o.writePacket(r,n),r.free(),r=await t.receive()}return i()},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Resize failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe(d(`video`,`resize`,{"video.width":t.width,"video.height":t.height,"video.input_size":e.byteLength})),trim:(e,t)=>f.tryPromise({try:async()=>{let n=Buffer.from(e),{callbacks:r,getOutput:i}=T();await using a=await h.open(n),o=await _.open(r,{format:`mp4`});let s=a.video();if(!s)throw Error(`No video stream found`);let c;c=t.duration===void 0?t.endTime===void 0?a.duration||1/0:t.endTime:t.startTime+t.duration;using l=await m.create(s),u=await g.create(S.h264);let d=o.addStream(u);for await(using e of l.frames(a.packets(s.index))){if(!e)continue;let n=e.pts||0n,r=s.timeBase?s.timeBase.num/s.timeBase.den:1,i=Number(n)*r;if(i>=t.startTime&&i<c){await u.encode(e);let t=await u.receive();for(;t;)await o.writePacket(t,d),t.free(),t=await u.receive()}if(i>=c)break}await u.flush();let f=await u.receive();for(;f;)await o.writePacket(f,d),f.free(),f=await u.receive();let p=a.audio();if(p){using e=await m.create(p),n=await g.create(C.aac);let r=o.addStream(n);for await(using i of e.frames(a.packets(p.index))){if(!i)continue;let e=i.pts||0n,a=p.timeBase?p.timeBase.num/p.timeBase.den:1,s=Number(e)*a;if(s>=t.startTime&&s<c){await n.encode(i);let e=await n.receive();for(;e;)await o.writePacket(e,r),e.free(),e=await n.receive()}if(s>=c)break}await n.flush();let i=await n.receive();for(;i;)await o.writePacket(i,r),i.free(),i=await n.receive()}return i()},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Trim failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe(d(`video`,`trim`,{"video.start_time":t.startTime,"video.end_time":t.endTime,"video.duration":t.duration,"video.input_size":e.byteLength})),extractFrame:(e,t)=>f.tryPromise({try:async()=>{let n=Buffer.from(e),r=t.format||`jpeg`;await using i=await h.open(n);let a=i.video();if(!a)throw Error(`No video stream found`);using o=await m.create(a);let s=null,c=t.timestamp;for await(using e of o.frames(i.packets(a.index))){if(!e)continue;let t=e.pts||0n,n=a.timeBase?a.timeBase.num/a.timeBase.den:1;if(Number(t)*n>=c){let t=w[r]||w.jpeg;using n=await g.create(t);await n.encode(e);let i=await n.receive();if(i?.data){s=new Uint8Array(i.data),i.free();break}}}if(!s)throw Error(`No frame found at timestamp ${c}`);return s},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Frame extraction failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}).pipe(d(`video`,`extract-frame`,{"video.timestamp":t.timestamp,"video.format":t.format??`jpeg`,"video.input_size":e.byteLength}))}}const D=p.succeed(v,E()),O=p.effectDiscard(f.gen(function*(){let e=yield*f.promise(()=>y());e.available?console.log(`✓ node-av ${e.version} detected`):console.warn(`⚠️ node-av is not installed or not available.`,`
1
+ import{FF_ENCODER_AAC as e,FF_ENCODER_LIBAOM_AV1 as t,FF_ENCODER_LIBMP3LAME as n,FF_ENCODER_LIBOPUS as r,FF_ENCODER_LIBVORBIS as i,FF_ENCODER_LIBVPX_VP9 as a,FF_ENCODER_LIBX264 as o,FF_ENCODER_LIBX265 as s,FF_ENCODER_MJPEG as c,FF_ENCODER_PNG as l}from"node-av/constants";import{UploadistaError as u}from"@uploadista/core/errors";import{Effect as d,Layer as f}from"effect";import{Decoder as p,Demuxer as m,Encoder as h,Muxer as g}from"node-av/api";import{VideoPlugin as _}from"@uploadista/core/flow";async function v(){try{return await import(`node-av`),{available:!0,version:`4.x`}}catch(e){return{available:!1,error:e instanceof Error?e.message:String(e)}}}const y={mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,avi:`video/x-msvideo`},b={mp4:`mp4`,webm:`webm`,mov:`mov`,avi:`avi`},x={h264:o,h265:s,vp9:a,av1:t},S={aac:e,mp3:n,opus:r,vorbis:i},C={jpeg:c,mjpeg:c,png:l};function w(){let e=[],t=0n;return{callbacks:{write:n=>(e.push(n),t+=BigInt(n.length),n.length),seek:(e,n)=>{switch(n){case 0:t=e;break;case 1:t+=e;break;case 2:t=e;break}return t}},getOutput:()=>{let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}}}function T(){return{describe:e=>d.tryPromise({try:async()=>{let t=Buffer.from(e);await using n=await m.open(t);let r=n.video(),i=n.audio();if(!r)throw Error(`No video stream found`);let a=r.codecpar,o=0;if(r.rFrameRate){let{num:e,den:t}=r.rFrameRate;o=t?e/t:e}let s=`unknown`;if(r.sampleAspectRatio){let{num:e,den:t}=r.sampleAspectRatio;s=`${e}:${t}`}return{duration:n.duration||0,width:a.width||0,height:a.height||0,codec:String(a.codecId)||`unknown`,format:n.formatName||`unknown`,bitrate:n.bitRate||0,frameRate:o,aspectRatio:s,hasAudio:!!i,audioCodec:i?.codecpar.codecId?String(i.codecpar.codecId):void 0,audioBitrate:i?.codecpar.bitRate?Number(i.codecpar.bitRate):void 0,size:e.byteLength}},catch:e=>u.fromCode(`VIDEO_METADATA_EXTRACTION_FAILED`,{body:`Failed to extract video metadata: ${e instanceof Error?e.message:String(e)}`,cause:e})}),transcode:(e,t)=>d.tryPromise({try:async()=>{let n=Buffer.from(e),{callbacks:r,getOutput:i}=w();await using a=await m.open(n),o=await g.open(r,{format:t.format});let s=a.video();if(!s)throw Error(`No video stream found`);using c=await p.create(s);let l=t.codec?x[t.codec]:x.h264;using u=await h.create(l,{...t.videoBitrate&&{bitrate:t.videoBitrate}});let d=o.addStream(u);for await(using e of c.frames(a.packets(s.index))){if(!e)continue;await u.encode(e);let t=await u.receive();for(;t;)await o.writePacket(t,d),t.free(),t=await u.receive()}await u.flush();let f=await u.receive();for(;f;)await o.writePacket(f,d),f.free(),f=await u.receive();let _=a.audio();if(_){using e=await p.create(_);let n=t.audioCodec?S[t.audioCodec]:S.aac;using r=await h.create(n,{...t.audioBitrate&&{bitrate:t.audioBitrate}});let i=o.addStream(r);for await(using t of e.frames(a.packets(_.index))){if(!t)continue;await r.encode(t);let e=await r.receive();for(;e;)await o.writePacket(e,i),e.free(),e=await r.receive()}await r.flush();let s=await r.receive();for(;s;)await o.writePacket(s,i),s.free(),s=await r.receive()}return i()},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Transcode failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}),resize:(e,t)=>d.tryPromise({try:async()=>{let n=Buffer.from(e),{callbacks:r,getOutput:i}=w();await using a=await m.open(n),o=await g.open(r,{format:`mp4`});let s=a.video();if(!s)throw Error(`No video stream found`);using c=await p.create(s);if(!t.width&&!t.height)throw Error(`Either width or height must be specified`);using l=await h.create(x.h264);let u=o.addStream(l);for await(using e of c.frames(a.packets(s.index))){if(!e)continue;await l.encode(e);let t=await l.receive();for(;t;)await o.writePacket(t,u),t.free(),t=await l.receive()}await l.flush();let d=await l.receive();for(;d;)await o.writePacket(d,u),d.free(),d=await l.receive();let f=a.audio();if(f){using e=await p.create(f),t=await h.create(S.aac);let n=o.addStream(t);for await(using r of e.frames(a.packets(f.index))){if(!r)continue;await t.encode(r);let e=await t.receive();for(;e;)await o.writePacket(e,n),e.free(),e=await t.receive()}await t.flush();let r=await t.receive();for(;r;)await o.writePacket(r,n),r.free(),r=await t.receive()}return i()},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Resize failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}),trim:(e,t)=>d.tryPromise({try:async()=>{let n=Buffer.from(e),{callbacks:r,getOutput:i}=w();await using a=await m.open(n),o=await g.open(r,{format:`mp4`});let s=a.video();if(!s)throw Error(`No video stream found`);let c;c=t.duration===void 0?t.endTime===void 0?a.duration||1/0:t.endTime:t.startTime+t.duration;using l=await p.create(s),u=await h.create(x.h264);let d=o.addStream(u);for await(using e of l.frames(a.packets(s.index))){if(!e)continue;let n=e.pts||0n,r=s.timeBase?s.timeBase.num/s.timeBase.den:1,i=Number(n)*r;if(i>=t.startTime&&i<c){await u.encode(e);let t=await u.receive();for(;t;)await o.writePacket(t,d),t.free(),t=await u.receive()}if(i>=c)break}await u.flush();let f=await u.receive();for(;f;)await o.writePacket(f,d),f.free(),f=await u.receive();let _=a.audio();if(_){using e=await p.create(_),n=await h.create(S.aac);let r=o.addStream(n);for await(using i of e.frames(a.packets(_.index))){if(!i)continue;let e=i.pts||0n,a=_.timeBase?_.timeBase.num/_.timeBase.den:1,s=Number(e)*a;if(s>=t.startTime&&s<c){await n.encode(i);let e=await n.receive();for(;e;)await o.writePacket(e,r),e.free(),e=await n.receive()}if(s>=c)break}await n.flush();let i=await n.receive();for(;i;)await o.writePacket(i,r),i.free(),i=await n.receive()}return i()},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Trim failed: ${e instanceof Error?e.message:String(e)}`,cause:e})}),extractFrame:(e,t)=>d.tryPromise({try:async()=>{let n=Buffer.from(e),r=t.format||`jpeg`;await using i=await m.open(n);let a=i.video();if(!a)throw Error(`No video stream found`);using o=await p.create(a);let s=null,c=t.timestamp;for await(using e of o.frames(i.packets(a.index))){if(!e)continue;let t=e.pts||0n,n=a.timeBase?a.timeBase.num/a.timeBase.den:1;if(Number(t)*n>=c){let t=C[r]||C.jpeg;using n=await h.create(t);await n.encode(e);let i=await n.receive();if(i?.data){s=new Uint8Array(i.data),i.free();break}}}if(!s)throw Error(`No frame found at timestamp ${c}`);return s},catch:e=>u.fromCode(`VIDEO_PROCESSING_FAILED`,{body:`Frame extraction failed: ${e instanceof Error?e.message:String(e)}`,cause:e})})}}const E=f.succeed(_,T()),D=f.effectDiscard(d.gen(function*(){let e=yield*d.promise(()=>v());e.available?console.log(`✓ node-av ${e.version} detected`):console.warn(`⚠️ node-av is not installed or not available.`,`
2
2
  Video processing operations will fail.`,`
3
- Install node-av: npm install node-av`)})).pipe(p.provideMerge(D));export{D as AVNodeVideoPlugin,O as AVNodeVideoPluginWithCheck,C as audioCodecToAVName,y as checkAVAvailable,S as codecToAVName,E as createAVNodeVideoPlugin,x as formatToExtension,b as formatToMimeType,w as imageFormatToEncoder};
3
+ Install node-av: npm install node-av`)})).pipe(f.provideMerge(E));export{E as AVNodeVideoPlugin,D as AVNodeVideoPluginWithCheck,S as audioCodecToAVName,v as checkAVAvailable,x as codecToAVName,T as createAVNodeVideoPlugin,b as formatToExtension,y as formatToMimeType,C as imageFormatToEncoder};
4
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["formatToMimeType: Record<TranscodeVideoParams[\"format\"], string>","formatToExtension: Record<TranscodeVideoParams[\"format\"], string>","codecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"codec\"]>,\n FFEncoderCodec\n>","audioCodecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"audioCodec\"]>,\n FFEncoderCodec\n>","imageFormatToEncoder: Record<string, FFEncoderCodec>","chunks: Buffer[]","callbacks: IOOutputCallbacks","endTime: number","frameData: Uint8Array | null"],"sources":["../src/utils/av-check.ts","../src/utils/format-mappings.ts","../src/utils/memory-io.ts","../src/video-plugin.ts","../src/video-plugin-layer.ts"],"sourcesContent":["/**\n * Result of node-av availability check\n */\nexport type AVCheckResult = {\n available: boolean;\n version?: string;\n error?: string;\n};\n\n/**\n * Checks if node-av is available and can access FFmpeg binaries\n * @returns Promise with availability status and version info\n */\nexport async function checkAVAvailable(): Promise<AVCheckResult> {\n try {\n // Try to import node-av to verify it's available\n await import(\"node-av\");\n\n // node-av includes FFmpeg binaries, so if import succeeds, it's available\n return {\n available: true,\n version: \"4.x\", // node-av version is in package.json\n };\n } catch (error) {\n return {\n available: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n","import type { TranscodeVideoParams } from \"@uploadista/core/flow\";\nimport type { FFEncoderCodec } from \"node-av/constants\";\nimport {\n FF_ENCODER_AAC,\n FF_ENCODER_LIBAOM_AV1,\n FF_ENCODER_LIBMP3LAME,\n FF_ENCODER_LIBOPUS,\n FF_ENCODER_LIBVORBIS,\n FF_ENCODER_LIBVPX_VP9,\n FF_ENCODER_LIBX264,\n FF_ENCODER_LIBX265,\n FF_ENCODER_MJPEG,\n FF_ENCODER_PNG,\n} from \"node-av/constants\";\n\n/**\n * Maps video format to MIME type\n */\nexport const formatToMimeType: Record<TranscodeVideoParams[\"format\"], string> =\n {\n mp4: \"video/mp4\",\n webm: \"video/webm\",\n mov: \"video/quicktime\",\n avi: \"video/x-msvideo\",\n };\n\n/**\n * Maps video format to file extension\n */\nexport const formatToExtension: Record<TranscodeVideoParams[\"format\"], string> =\n {\n mp4: \"mp4\",\n webm: \"webm\",\n mov: \"mov\",\n avi: \"avi\",\n };\n\n/**\n * Maps codec parameter to node-av codec constant\n */\nexport const codecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"codec\"]>,\n FFEncoderCodec\n> = {\n h264: FF_ENCODER_LIBX264,\n h265: FF_ENCODER_LIBX265,\n vp9: FF_ENCODER_LIBVPX_VP9,\n av1: FF_ENCODER_LIBAOM_AV1,\n};\n\n/**\n * Maps audio codec parameter to node-av audio codec constant\n */\nexport const audioCodecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"audioCodec\"]>,\n FFEncoderCodec\n> = {\n aac: FF_ENCODER_AAC,\n mp3: FF_ENCODER_LIBMP3LAME,\n opus: FF_ENCODER_LIBOPUS,\n vorbis: FF_ENCODER_LIBVORBIS,\n};\n\n/**\n * Maps image format to encoder constant\n */\nexport const imageFormatToEncoder: Record<string, FFEncoderCodec> = {\n jpeg: FF_ENCODER_MJPEG,\n mjpeg: FF_ENCODER_MJPEG,\n png: FF_ENCODER_PNG,\n};\n","import type { IOOutputCallbacks } from \"node-av/api\";\n\n/**\n * Creates an in-memory output buffer that implements IOOutputCallbacks\n * @param _format - The output format (e.g., 'mp4', 'webm', 'jpeg') - not used but kept for API clarity\n * @returns IOOutputCallbacks and a function to get the accumulated data\n */\nexport function createMemoryOutput(): {\n callbacks: IOOutputCallbacks;\n getOutput: () => Uint8Array;\n} {\n const chunks: Buffer[] = [];\n let position = 0n;\n\n const callbacks: IOOutputCallbacks = {\n write: (buffer: Buffer): number => {\n chunks.push(buffer);\n position += BigInt(buffer.length);\n return buffer.length;\n },\n seek: (offset: bigint, whence: number): bigint => {\n // For most formats, seeking is optional during muxing\n // We'll implement a basic version that tracks position\n // AVSEEK_SET = 0, AVSEEK_CUR = 1, AVSEEK_END = 2\n switch (whence) {\n case 0: // AVSEEK_SET\n position = offset;\n break;\n case 1: // AVSEEK_CUR\n position += offset;\n break;\n case 2: // AVSEEK_END\n // For end seeking, we'd need to know total size\n // Most streaming formats don't require this\n position = offset;\n break;\n }\n return position;\n },\n };\n\n const getOutput = (): Uint8Array => {\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n return result;\n };\n\n return { callbacks, getOutput };\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport type {\n DescribeVideoMetadata,\n VideoPluginShape,\n} from \"@uploadista/core/flow\";\nimport { withOperationSpan } from \"@uploadista/observability\";\nimport { Effect } from \"effect\";\nimport { Decoder, Demuxer, Encoder, Muxer } from \"node-av/api\";\nimport {\n audioCodecToAVName,\n codecToAVName,\n imageFormatToEncoder,\n} from \"./utils/format-mappings\";\nimport { createMemoryOutput } from \"./utils/memory-io\";\n\n/**\n * Creates a node-av based video processing plugin\n */\nexport function createAVNodeVideoPlugin(): VideoPluginShape {\n return {\n describe: (input) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for node-av\n const buffer = Buffer.from(input);\n await using mediaInput = await Demuxer.open(buffer);\n\n const videoStream = mediaInput.video();\n const audioStream = mediaInput.audio();\n\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n const videoCodecParams = videoStream.codecpar;\n\n // Calculate frame rate from rational number\n let frameRate = 0;\n if (videoStream.rFrameRate) {\n const { num, den } = videoStream.rFrameRate;\n frameRate = den ? num / den : num;\n }\n\n // Get aspect ratio\n let aspectRatio = \"unknown\";\n if (videoStream.sampleAspectRatio) {\n const { num, den } = videoStream.sampleAspectRatio;\n aspectRatio = `${num}:${den}`;\n }\n\n const metadata: DescribeVideoMetadata = {\n duration: mediaInput.duration || 0,\n width: videoCodecParams.width || 0,\n height: videoCodecParams.height || 0,\n codec: String(videoCodecParams.codecId) || \"unknown\",\n format: mediaInput.formatName || \"unknown\",\n bitrate: mediaInput.bitRate || 0,\n frameRate,\n aspectRatio,\n hasAudio: !!audioStream,\n audioCodec: audioStream?.codecpar.codecId\n ? String(audioStream.codecpar.codecId)\n : undefined,\n audioBitrate: audioStream?.codecpar.bitRate\n ? Number(audioStream.codecpar.bitRate)\n : undefined,\n size: input.byteLength,\n };\n\n return metadata;\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_METADATA_EXTRACTION_FAILED\", {\n body: `Failed to extract video metadata: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }).pipe(\n withOperationSpan(\"video\", \"describe\", {\n \"video.input_size\": input.byteLength,\n }),\n ),\n\n transcode: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n\n // Create in-memory output\n const { callbacks, getOutput } = createMemoryOutput();\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n await using mediaOutput = await Muxer.open(callbacks, {\n format: options.format,\n });\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n using videoDecoder = await Decoder.create(videoStream);\n\n // Determine encoder codec\n const encoderCodec = options.codec\n ? codecToAVName[options.codec]\n : codecToAVName.h264;\n\n using videoEncoder = await Encoder.create(encoderCodec, {\n ...(options.videoBitrate && { bitrate: options.videoBitrate }),\n });\n\n const videoOutputIndex = mediaOutput.addStream(videoEncoder);\n\n // Process video frames\n for await (using frame of videoDecoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n await videoEncoder.encode(frame);\n let packet = await videoEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, videoOutputIndex);\n packet.free();\n packet = await videoEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await videoEncoder.flush();\n let transcodeVPacket = await videoEncoder.receive();\n while (transcodeVPacket) {\n await mediaOutput.writePacket(transcodeVPacket, videoOutputIndex);\n transcodeVPacket.free();\n transcodeVPacket = await videoEncoder.receive();\n }\n\n // Handle audio stream if present\n const audioStream = mediaInput.audio();\n if (audioStream) {\n using audioDecoder = await Decoder.create(audioStream);\n\n const audioEncoderCodec = options.audioCodec\n ? audioCodecToAVName[options.audioCodec]\n : audioCodecToAVName.aac;\n\n using audioEncoder = await Encoder.create(audioEncoderCodec, {\n ...(options.audioBitrate && { bitrate: options.audioBitrate }),\n });\n\n const audioOutputIndex = mediaOutput.addStream(audioEncoder);\n\n // Process audio frames\n for await (using frame of audioDecoder.frames(\n mediaInput.packets(audioStream.index),\n )) {\n if (!frame) continue;\n await audioEncoder.encode(frame);\n let packet = await audioEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, audioOutputIndex);\n packet.free();\n packet = await audioEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await audioEncoder.flush();\n let transcodeAPacket = await audioEncoder.receive();\n while (transcodeAPacket) {\n await mediaOutput.writePacket(transcodeAPacket, audioOutputIndex);\n transcodeAPacket.free();\n transcodeAPacket = await audioEncoder.receive();\n }\n }\n\n // Return accumulated output\n return getOutput();\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Transcode failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }).pipe(\n withOperationSpan(\"video\", \"transcode\", {\n \"video.format\": options.format,\n \"video.codec\": options.codec,\n \"video.video_bitrate\": options.videoBitrate,\n \"video.audio_codec\": options.audioCodec,\n \"video.audio_bitrate\": options.audioBitrate,\n \"video.input_size\": input.byteLength,\n }),\n ),\n\n resize: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n\n // Create in-memory output\n const { callbacks, getOutput } = createMemoryOutput();\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n await using mediaOutput = await Muxer.open(callbacks, {\n format: \"mp4\",\n });\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n using videoDecoder = await Decoder.create(videoStream);\n\n // TODO: Implement proper resizing with FilterAPI\n // Currently, resize functionality is limited because node-av's Encoder\n // auto-initializes from the first frame it receives. To implement proper\n // resizing, we would need to:\n // 1. Use FilterAPI.create('scale', { width, height }) to create a scale filter\n // 2. Pass decoded frames through the filter before encoding\n // For now, this function will pass through frames without resizing.\n\n // Validate that resize parameters are provided\n if (!options.width && !options.height) {\n throw new Error(\"Either width or height must be specified\");\n }\n\n using videoEncoder = await Encoder.create(codecToAVName.h264);\n\n const videoOutputIndex = mediaOutput.addStream(videoEncoder);\n\n // Process video frames with resizing\n // Note: For production use, consider using FilterAPI for better quality scaling\n for await (using frame of videoDecoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n // TODO: Apply scale filter here for better quality\n // For now, encoder will handle basic resizing\n await videoEncoder.encode(frame);\n let packet = await videoEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, videoOutputIndex);\n packet.free();\n packet = await videoEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await videoEncoder.flush();\n let vPacket = await videoEncoder.receive();\n while (vPacket) {\n await mediaOutput.writePacket(vPacket, videoOutputIndex);\n vPacket.free();\n vPacket = await videoEncoder.receive();\n }\n\n // Copy audio stream if present\n const audioStream = mediaInput.audio();\n if (audioStream) {\n using audioDecoder = await Decoder.create(audioStream);\n using audioEncoder = await Encoder.create(audioCodecToAVName.aac);\n\n const audioOutputIndex = mediaOutput.addStream(audioEncoder);\n\n for await (using frame of audioDecoder.frames(\n mediaInput.packets(audioStream.index),\n )) {\n if (!frame) continue;\n await audioEncoder.encode(frame);\n let packet = await audioEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, audioOutputIndex);\n packet.free();\n packet = await audioEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await audioEncoder.flush();\n let resizeAPacket = await audioEncoder.receive();\n while (resizeAPacket) {\n await mediaOutput.writePacket(resizeAPacket, audioOutputIndex);\n resizeAPacket.free();\n resizeAPacket = await audioEncoder.receive();\n }\n }\n\n // Return accumulated output\n return getOutput();\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Resize failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }).pipe(\n withOperationSpan(\"video\", \"resize\", {\n \"video.width\": options.width,\n \"video.height\": options.height,\n \"video.input_size\": input.byteLength,\n }),\n ),\n\n trim: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n\n // Create in-memory output\n const { callbacks, getOutput } = createMemoryOutput();\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n await using mediaOutput = await Muxer.open(callbacks, {\n format: \"mp4\",\n });\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n // Calculate end time\n let endTime: number;\n if (options.duration !== undefined) {\n endTime = options.startTime + options.duration;\n } else if (options.endTime !== undefined) {\n endTime = options.endTime;\n } else {\n endTime = mediaInput.duration || Number.POSITIVE_INFINITY;\n }\n\n using videoDecoder = await Decoder.create(videoStream);\n using videoEncoder = await Encoder.create(codecToAVName.h264);\n\n const videoOutputIndex = mediaOutput.addStream(videoEncoder);\n\n // Process video frames within time range\n for await (using frame of videoDecoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n // Calculate frame timestamp\n const pts = frame.pts || 0n;\n const timeBase = videoStream.timeBase\n ? videoStream.timeBase.num / videoStream.timeBase.den\n : 1;\n const timestamp = Number(pts) * timeBase;\n\n if (timestamp >= options.startTime && timestamp < endTime) {\n await videoEncoder.encode(frame);\n let packet = await videoEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, videoOutputIndex);\n packet.free();\n packet = await videoEncoder.receive();\n }\n }\n\n if (timestamp >= endTime) break;\n }\n\n // Flush remaining packets\n await videoEncoder.flush();\n let trimVPacket = await videoEncoder.receive();\n while (trimVPacket) {\n await mediaOutput.writePacket(trimVPacket, videoOutputIndex);\n trimVPacket.free();\n trimVPacket = await videoEncoder.receive();\n }\n\n // Handle audio stream if present\n const audioStream = mediaInput.audio();\n if (audioStream) {\n using audioDecoder = await Decoder.create(audioStream);\n using audioEncoder = await Encoder.create(audioCodecToAVName.aac);\n\n const audioOutputIndex = mediaOutput.addStream(audioEncoder);\n\n for await (using frame of audioDecoder.frames(\n mediaInput.packets(audioStream.index),\n )) {\n if (!frame) continue;\n const pts = frame.pts || 0n;\n const timeBase = audioStream.timeBase\n ? audioStream.timeBase.num / audioStream.timeBase.den\n : 1;\n const timestamp = Number(pts) * timeBase;\n\n if (timestamp >= options.startTime && timestamp < endTime) {\n await audioEncoder.encode(frame);\n let packet = await audioEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, audioOutputIndex);\n packet.free();\n packet = await audioEncoder.receive();\n }\n }\n\n if (timestamp >= endTime) break;\n }\n\n // Flush remaining packets\n await audioEncoder.flush();\n let trimAPacket = await audioEncoder.receive();\n while (trimAPacket) {\n await mediaOutput.writePacket(trimAPacket, audioOutputIndex);\n trimAPacket.free();\n trimAPacket = await audioEncoder.receive();\n }\n }\n\n // Return accumulated output\n return getOutput();\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Trim failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }).pipe(\n withOperationSpan(\"video\", \"trim\", {\n \"video.start_time\": options.startTime,\n \"video.end_time\": options.endTime,\n \"video.duration\": options.duration,\n \"video.input_size\": input.byteLength,\n }),\n ),\n\n extractFrame: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n const format = options.format || \"jpeg\";\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n using decoder = await Decoder.create(videoStream);\n\n let frameData: Uint8Array | null = null;\n const targetTimestamp = options.timestamp;\n\n for await (using frame of decoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n // Calculate frame timestamp\n const pts = frame.pts || 0n;\n const timeBase = videoStream.timeBase\n ? videoStream.timeBase.num / videoStream.timeBase.den\n : 1;\n const timestamp = Number(pts) * timeBase;\n\n // Look for frame at or after target timestamp\n if (timestamp >= targetTimestamp) {\n // Use an image encoder to save the frame\n const encoderCodec =\n imageFormatToEncoder[format] || imageFormatToEncoder.jpeg;\n using imageEncoder = await Encoder.create(encoderCodec);\n\n // Encode the frame as image\n // The encoder will initialize from the first frame's properties\n await imageEncoder.encode(frame);\n const packet = await imageEncoder.receive();\n if (packet?.data) {\n // Convert Buffer to Uint8Array\n frameData = new Uint8Array(packet.data);\n packet.free();\n break;\n }\n }\n }\n\n if (!frameData) {\n throw new Error(`No frame found at timestamp ${targetTimestamp}`);\n }\n\n return frameData;\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Frame extraction failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }).pipe(\n withOperationSpan(\"video\", \"extract-frame\", {\n \"video.timestamp\": options.timestamp,\n \"video.format\": options.format ?? \"jpeg\",\n \"video.input_size\": input.byteLength,\n }),\n ),\n };\n}\n","import { VideoPlugin } from \"@uploadista/core/flow\";\nimport { Effect, Layer } from \"effect\";\nimport { checkAVAvailable } from \"./utils/av-check\";\nimport { createAVNodeVideoPlugin } from \"./video-plugin\";\n\n/**\n * Effect Layer for the node-av video plugin\n *\n * This layer provides video processing capabilities using node-av (FFmpeg bindings).\n * Note: node-av includes prebuilt FFmpeg binaries, so no system installation is required.\n *\n * @example\n * ```typescript\n * import { AVNodeVideoPlugin } from \"@uploadista/flow-videos-av-node\";\n * import { Effect } from \"effect\";\n *\n * const program = Effect.gen(function* () {\n * const videoPlugin = yield* VideoPlugin;\n * const metadata = yield* videoPlugin.describe(videoBytes);\n * return metadata;\n * });\n *\n * // Run with node-av plugin layer\n * const result = await Effect.runPromise(\n * program.pipe(Effect.provide(AVNodeVideoPluginLive))\n * );\n * ```\n */\nexport const AVNodeVideoPlugin = Layer.succeed(\n VideoPlugin,\n createAVNodeVideoPlugin(),\n);\n\n/**\n * Effect Layer for the node-av video plugin with availability check\n *\n * This layer checks if node-av is properly installed and logs status information.\n * The plugin will still be created, but operations will fail if node-av is not available.\n *\n * @example\n * ```typescript\n * import { AVNodeVideoPluginWithCheck } from \"@uploadista/flow-videos-av-node\";\n * import { Effect } from \"effect\";\n *\n * const program = Effect.gen(function* () {\n * const videoPlugin = yield* VideoPlugin;\n * const metadata = yield* videoPlugin.describe(videoBytes);\n * return metadata;\n * });\n *\n * // Run with node-av plugin layer (with check)\n * const result = await Effect.runPromise(\n * program.pipe(Effect.provide(AVNodeVideoPluginWithCheck))\n * );\n * ```\n */\nexport const AVNodeVideoPluginWithCheck = Layer.effectDiscard(\n Effect.gen(function* () {\n const result = yield* Effect.promise(() => checkAVAvailable());\n\n if (!result.available) {\n console.warn(\n \"⚠️ node-av is not installed or not available.\",\n \"\\nVideo processing operations will fail.\",\n \"\\nInstall node-av: npm install node-av\",\n );\n } else {\n console.log(`✓ node-av ${result.version} detected`);\n }\n }),\n).pipe(Layer.provideMerge(AVNodeVideoPlugin));\n"],"mappings":"kjBAaA,eAAsB,GAA2C,CAC/D,GAAI,CAKF,OAHA,MAAM,OAAO,WAGN,CACL,UAAW,GACX,QAAS,MACV,OACM,EAAO,CACd,MAAO,CACL,UAAW,GACX,MAAO,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAC9D,ECTL,MAAaA,EACX,CACE,IAAK,YACL,KAAM,aACN,IAAK,kBACL,IAAK,kBACN,CAKUC,EACX,CACE,IAAK,MACL,KAAM,OACN,IAAK,MACL,IAAK,MACN,CAKUC,EAGT,CACF,KAAM,EACN,KAAM,EACN,IAAK,EACL,IAAK,EACN,CAKYC,EAGT,CACF,IAAK,EACL,IAAK,EACL,KAAM,EACN,OAAQ,EACT,CAKYC,EAAuD,CAClE,KAAM,EACN,MAAO,EAC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MAAQ,EAAM,QAAU,OAAO,EAAM,GACxF,MAAO,EACR,CAAC,CACL,CAAC,CAAC,KACD,EAAkB,QAAS,gBAAiB,CAC1C,kBAAmB,EAAQ,UAC3B,eAAgB,EAAQ,QAAU,OAClC,mBAAoB,EAAM,WAC3B,CAAC,CACH,CACJ,CCxdH,MAAa,EAAoB,EAAM,QACrC,EACA,GAAyB,CAC1B,CAyBY,EAA6B,EAAM,cAC9C,EAAO,IAAI,WAAa,CACtB,IAAM,EAAS,MAAO,EAAO,YAAc,GAAkB,CAAC,CAEzD,EAAO,UAOV,QAAQ,IAAI,aAAa,EAAO,QAAQ,WAAW,CANnD,QAAQ,KACN,iDACA;wCACA;sCACD,EAIH,CACH,CAAC,KAAK,EAAM,aAAa,EAAkB,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":["formatToMimeType: Record<TranscodeVideoParams[\"format\"], string>","formatToExtension: Record<TranscodeVideoParams[\"format\"], string>","codecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"codec\"]>,\n FFEncoderCodec\n>","audioCodecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"audioCodec\"]>,\n FFEncoderCodec\n>","imageFormatToEncoder: Record<string, FFEncoderCodec>","chunks: Buffer[]","callbacks: IOOutputCallbacks","endTime: number","frameData: Uint8Array | null"],"sources":["../src/utils/av-check.ts","../src/utils/format-mappings.ts","../src/utils/memory-io.ts","../src/video-plugin.ts","../src/video-plugin-layer.ts"],"sourcesContent":["/**\n * Result of node-av availability check\n */\nexport type AVCheckResult = {\n available: boolean;\n version?: string;\n error?: string;\n};\n\n/**\n * Checks if node-av is available and can access FFmpeg binaries\n * @returns Promise with availability status and version info\n */\nexport async function checkAVAvailable(): Promise<AVCheckResult> {\n try {\n // Try to import node-av to verify it's available\n await import(\"node-av\");\n\n // node-av includes FFmpeg binaries, so if import succeeds, it's available\n return {\n available: true,\n version: \"4.x\", // node-av version is in package.json\n };\n } catch (error) {\n return {\n available: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n","import type { TranscodeVideoParams } from \"@uploadista/core/flow\";\nimport type { FFEncoderCodec } from \"node-av/constants\";\nimport {\n FF_ENCODER_AAC,\n FF_ENCODER_LIBAOM_AV1,\n FF_ENCODER_LIBMP3LAME,\n FF_ENCODER_LIBOPUS,\n FF_ENCODER_LIBVORBIS,\n FF_ENCODER_LIBVPX_VP9,\n FF_ENCODER_LIBX264,\n FF_ENCODER_LIBX265,\n FF_ENCODER_MJPEG,\n FF_ENCODER_PNG,\n} from \"node-av/constants\";\n\n/**\n * Maps video format to MIME type\n */\nexport const formatToMimeType: Record<TranscodeVideoParams[\"format\"], string> =\n {\n mp4: \"video/mp4\",\n webm: \"video/webm\",\n mov: \"video/quicktime\",\n avi: \"video/x-msvideo\",\n };\n\n/**\n * Maps video format to file extension\n */\nexport const formatToExtension: Record<TranscodeVideoParams[\"format\"], string> =\n {\n mp4: \"mp4\",\n webm: \"webm\",\n mov: \"mov\",\n avi: \"avi\",\n };\n\n/**\n * Maps codec parameter to node-av codec constant\n */\nexport const codecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"codec\"]>,\n FFEncoderCodec\n> = {\n h264: FF_ENCODER_LIBX264,\n h265: FF_ENCODER_LIBX265,\n vp9: FF_ENCODER_LIBVPX_VP9,\n av1: FF_ENCODER_LIBAOM_AV1,\n};\n\n/**\n * Maps audio codec parameter to node-av audio codec constant\n */\nexport const audioCodecToAVName: Record<\n NonNullable<TranscodeVideoParams[\"audioCodec\"]>,\n FFEncoderCodec\n> = {\n aac: FF_ENCODER_AAC,\n mp3: FF_ENCODER_LIBMP3LAME,\n opus: FF_ENCODER_LIBOPUS,\n vorbis: FF_ENCODER_LIBVORBIS,\n};\n\n/**\n * Maps image format to encoder constant\n */\nexport const imageFormatToEncoder: Record<string, FFEncoderCodec> = {\n jpeg: FF_ENCODER_MJPEG,\n mjpeg: FF_ENCODER_MJPEG,\n png: FF_ENCODER_PNG,\n};\n","import type { IOOutputCallbacks } from \"node-av/api\";\n\n/**\n * Creates an in-memory output buffer that implements IOOutputCallbacks\n * @param _format - The output format (e.g., 'mp4', 'webm', 'jpeg') - not used but kept for API clarity\n * @returns IOOutputCallbacks and a function to get the accumulated data\n */\nexport function createMemoryOutput(): {\n callbacks: IOOutputCallbacks;\n getOutput: () => Uint8Array;\n} {\n const chunks: Buffer[] = [];\n let position = 0n;\n\n const callbacks: IOOutputCallbacks = {\n write: (buffer: Buffer): number => {\n chunks.push(buffer);\n position += BigInt(buffer.length);\n return buffer.length;\n },\n seek: (offset: bigint, whence: number): bigint => {\n // For most formats, seeking is optional during muxing\n // We'll implement a basic version that tracks position\n // AVSEEK_SET = 0, AVSEEK_CUR = 1, AVSEEK_END = 2\n switch (whence) {\n case 0: // AVSEEK_SET\n position = offset;\n break;\n case 1: // AVSEEK_CUR\n position += offset;\n break;\n case 2: // AVSEEK_END\n // For end seeking, we'd need to know total size\n // Most streaming formats don't require this\n position = offset;\n break;\n }\n return position;\n },\n };\n\n const getOutput = (): Uint8Array => {\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n result.set(chunk, offset);\n offset += chunk.length;\n }\n return result;\n };\n\n return { callbacks, getOutput };\n}\n","import { UploadistaError } from \"@uploadista/core/errors\";\nimport type {\n DescribeVideoMetadata,\n VideoPluginShape,\n} from \"@uploadista/core/flow\";\nimport { Effect } from \"effect\";\nimport { Decoder, Demuxer, Encoder, Muxer } from \"node-av/api\";\nimport {\n audioCodecToAVName,\n codecToAVName,\n imageFormatToEncoder,\n} from \"./utils/format-mappings\";\nimport { createMemoryOutput } from \"./utils/memory-io\";\n\n/**\n * Creates a node-av based video processing plugin\n */\nexport function createAVNodeVideoPlugin(): VideoPluginShape {\n return {\n describe: (input) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for node-av\n const buffer = Buffer.from(input);\n await using mediaInput = await Demuxer.open(buffer);\n\n const videoStream = mediaInput.video();\n const audioStream = mediaInput.audio();\n\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n const videoCodecParams = videoStream.codecpar;\n\n // Calculate frame rate from rational number\n let frameRate = 0;\n if (videoStream.rFrameRate) {\n const { num, den } = videoStream.rFrameRate;\n frameRate = den ? num / den : num;\n }\n\n // Get aspect ratio\n let aspectRatio = \"unknown\";\n if (videoStream.sampleAspectRatio) {\n const { num, den } = videoStream.sampleAspectRatio;\n aspectRatio = `${num}:${den}`;\n }\n\n const metadata: DescribeVideoMetadata = {\n duration: mediaInput.duration || 0,\n width: videoCodecParams.width || 0,\n height: videoCodecParams.height || 0,\n codec: String(videoCodecParams.codecId) || \"unknown\",\n format: mediaInput.formatName || \"unknown\",\n bitrate: mediaInput.bitRate || 0,\n frameRate,\n aspectRatio,\n hasAudio: !!audioStream,\n audioCodec: audioStream?.codecpar.codecId\n ? String(audioStream.codecpar.codecId)\n : undefined,\n audioBitrate: audioStream?.codecpar.bitRate\n ? Number(audioStream.codecpar.bitRate)\n : undefined,\n size: input.byteLength,\n };\n\n return metadata;\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_METADATA_EXTRACTION_FAILED\", {\n body: `Failed to extract video metadata: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }),\n\n transcode: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n\n // Create in-memory output\n const { callbacks, getOutput } = createMemoryOutput();\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n await using mediaOutput = await Muxer.open(callbacks, {\n format: options.format,\n });\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n using videoDecoder = await Decoder.create(videoStream);\n\n // Determine encoder codec\n const encoderCodec = options.codec\n ? codecToAVName[options.codec]\n : codecToAVName.h264;\n\n using videoEncoder = await Encoder.create(encoderCodec, {\n ...(options.videoBitrate && { bitrate: options.videoBitrate }),\n });\n\n const videoOutputIndex = mediaOutput.addStream(videoEncoder);\n\n // Process video frames\n for await (using frame of videoDecoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n await videoEncoder.encode(frame);\n let packet = await videoEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, videoOutputIndex);\n packet.free();\n packet = await videoEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await videoEncoder.flush();\n let transcodeVPacket = await videoEncoder.receive();\n while (transcodeVPacket) {\n await mediaOutput.writePacket(transcodeVPacket, videoOutputIndex);\n transcodeVPacket.free();\n transcodeVPacket = await videoEncoder.receive();\n }\n\n // Handle audio stream if present\n const audioStream = mediaInput.audio();\n if (audioStream) {\n using audioDecoder = await Decoder.create(audioStream);\n\n const audioEncoderCodec = options.audioCodec\n ? audioCodecToAVName[options.audioCodec]\n : audioCodecToAVName.aac;\n\n using audioEncoder = await Encoder.create(audioEncoderCodec, {\n ...(options.audioBitrate && { bitrate: options.audioBitrate }),\n });\n\n const audioOutputIndex = mediaOutput.addStream(audioEncoder);\n\n // Process audio frames\n for await (using frame of audioDecoder.frames(\n mediaInput.packets(audioStream.index),\n )) {\n if (!frame) continue;\n await audioEncoder.encode(frame);\n let packet = await audioEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, audioOutputIndex);\n packet.free();\n packet = await audioEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await audioEncoder.flush();\n let transcodeAPacket = await audioEncoder.receive();\n while (transcodeAPacket) {\n await mediaOutput.writePacket(transcodeAPacket, audioOutputIndex);\n transcodeAPacket.free();\n transcodeAPacket = await audioEncoder.receive();\n }\n }\n\n // Return accumulated output\n return getOutput();\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Transcode failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }),\n\n resize: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n\n // Create in-memory output\n const { callbacks, getOutput } = createMemoryOutput();\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n await using mediaOutput = await Muxer.open(callbacks, {\n format: \"mp4\",\n });\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n using videoDecoder = await Decoder.create(videoStream);\n\n // TODO: Implement proper resizing with FilterAPI\n // Currently, resize functionality is limited because node-av's Encoder\n // auto-initializes from the first frame it receives. To implement proper\n // resizing, we would need to:\n // 1. Use FilterAPI.create('scale', { width, height }) to create a scale filter\n // 2. Pass decoded frames through the filter before encoding\n // For now, this function will pass through frames without resizing.\n\n // Validate that resize parameters are provided\n if (!options.width && !options.height) {\n throw new Error(\"Either width or height must be specified\");\n }\n\n using videoEncoder = await Encoder.create(codecToAVName.h264);\n\n const videoOutputIndex = mediaOutput.addStream(videoEncoder);\n\n // Process video frames with resizing\n // Note: For production use, consider using FilterAPI for better quality scaling\n for await (using frame of videoDecoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n // TODO: Apply scale filter here for better quality\n // For now, encoder will handle basic resizing\n await videoEncoder.encode(frame);\n let packet = await videoEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, videoOutputIndex);\n packet.free();\n packet = await videoEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await videoEncoder.flush();\n let vPacket = await videoEncoder.receive();\n while (vPacket) {\n await mediaOutput.writePacket(vPacket, videoOutputIndex);\n vPacket.free();\n vPacket = await videoEncoder.receive();\n }\n\n // Copy audio stream if present\n const audioStream = mediaInput.audio();\n if (audioStream) {\n using audioDecoder = await Decoder.create(audioStream);\n using audioEncoder = await Encoder.create(audioCodecToAVName.aac);\n\n const audioOutputIndex = mediaOutput.addStream(audioEncoder);\n\n for await (using frame of audioDecoder.frames(\n mediaInput.packets(audioStream.index),\n )) {\n if (!frame) continue;\n await audioEncoder.encode(frame);\n let packet = await audioEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, audioOutputIndex);\n packet.free();\n packet = await audioEncoder.receive();\n }\n }\n\n // Flush remaining packets\n await audioEncoder.flush();\n let resizeAPacket = await audioEncoder.receive();\n while (resizeAPacket) {\n await mediaOutput.writePacket(resizeAPacket, audioOutputIndex);\n resizeAPacket.free();\n resizeAPacket = await audioEncoder.receive();\n }\n }\n\n // Return accumulated output\n return getOutput();\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Resize failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }),\n\n trim: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n\n // Create in-memory output\n const { callbacks, getOutput } = createMemoryOutput();\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n await using mediaOutput = await Muxer.open(callbacks, {\n format: \"mp4\",\n });\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n // Calculate end time\n let endTime: number;\n if (options.duration !== undefined) {\n endTime = options.startTime + options.duration;\n } else if (options.endTime !== undefined) {\n endTime = options.endTime;\n } else {\n endTime = mediaInput.duration || Number.POSITIVE_INFINITY;\n }\n\n using videoDecoder = await Decoder.create(videoStream);\n using videoEncoder = await Encoder.create(codecToAVName.h264);\n\n const videoOutputIndex = mediaOutput.addStream(videoEncoder);\n\n // Process video frames within time range\n for await (using frame of videoDecoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n // Calculate frame timestamp\n const pts = frame.pts || 0n;\n const timeBase = videoStream.timeBase\n ? videoStream.timeBase.num / videoStream.timeBase.den\n : 1;\n const timestamp = Number(pts) * timeBase;\n\n if (timestamp >= options.startTime && timestamp < endTime) {\n await videoEncoder.encode(frame);\n let packet = await videoEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, videoOutputIndex);\n packet.free();\n packet = await videoEncoder.receive();\n }\n }\n\n if (timestamp >= endTime) break;\n }\n\n // Flush remaining packets\n await videoEncoder.flush();\n let trimVPacket = await videoEncoder.receive();\n while (trimVPacket) {\n await mediaOutput.writePacket(trimVPacket, videoOutputIndex);\n trimVPacket.free();\n trimVPacket = await videoEncoder.receive();\n }\n\n // Handle audio stream if present\n const audioStream = mediaInput.audio();\n if (audioStream) {\n using audioDecoder = await Decoder.create(audioStream);\n using audioEncoder = await Encoder.create(audioCodecToAVName.aac);\n\n const audioOutputIndex = mediaOutput.addStream(audioEncoder);\n\n for await (using frame of audioDecoder.frames(\n mediaInput.packets(audioStream.index),\n )) {\n if (!frame) continue;\n const pts = frame.pts || 0n;\n const timeBase = audioStream.timeBase\n ? audioStream.timeBase.num / audioStream.timeBase.den\n : 1;\n const timestamp = Number(pts) * timeBase;\n\n if (timestamp >= options.startTime && timestamp < endTime) {\n await audioEncoder.encode(frame);\n let packet = await audioEncoder.receive();\n while (packet) {\n await mediaOutput.writePacket(packet, audioOutputIndex);\n packet.free();\n packet = await audioEncoder.receive();\n }\n }\n\n if (timestamp >= endTime) break;\n }\n\n // Flush remaining packets\n await audioEncoder.flush();\n let trimAPacket = await audioEncoder.receive();\n while (trimAPacket) {\n await mediaOutput.writePacket(trimAPacket, audioOutputIndex);\n trimAPacket.free();\n trimAPacket = await audioEncoder.receive();\n }\n }\n\n // Return accumulated output\n return getOutput();\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Trim failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }),\n\n extractFrame: (input, options) =>\n Effect.tryPromise({\n try: async () => {\n // Convert Uint8Array to Buffer for input\n const inputBuffer = Buffer.from(input);\n const format = options.format || \"jpeg\";\n\n await using mediaInput = await Demuxer.open(inputBuffer);\n\n const videoStream = mediaInput.video();\n if (!videoStream) {\n throw new Error(\"No video stream found\");\n }\n\n using decoder = await Decoder.create(videoStream);\n\n let frameData: Uint8Array | null = null;\n const targetTimestamp = options.timestamp;\n\n for await (using frame of decoder.frames(\n mediaInput.packets(videoStream.index),\n )) {\n if (!frame) continue;\n // Calculate frame timestamp\n const pts = frame.pts || 0n;\n const timeBase = videoStream.timeBase\n ? videoStream.timeBase.num / videoStream.timeBase.den\n : 1;\n const timestamp = Number(pts) * timeBase;\n\n // Look for frame at or after target timestamp\n if (timestamp >= targetTimestamp) {\n // Use an image encoder to save the frame\n const encoderCodec =\n imageFormatToEncoder[format] || imageFormatToEncoder.jpeg;\n using imageEncoder = await Encoder.create(encoderCodec);\n\n // Encode the frame as image\n // The encoder will initialize from the first frame's properties\n await imageEncoder.encode(frame);\n const packet = await imageEncoder.receive();\n if (packet?.data) {\n // Convert Buffer to Uint8Array\n frameData = new Uint8Array(packet.data);\n packet.free();\n break;\n }\n }\n }\n\n if (!frameData) {\n throw new Error(`No frame found at timestamp ${targetTimestamp}`);\n }\n\n return frameData;\n },\n catch: (error) =>\n UploadistaError.fromCode(\"VIDEO_PROCESSING_FAILED\", {\n body: `Frame extraction failed: ${error instanceof Error ? error.message : String(error)}`,\n cause: error,\n }),\n }),\n };\n}\n","import { VideoPlugin } from \"@uploadista/core/flow\";\nimport { Effect, Layer } from \"effect\";\nimport { checkAVAvailable } from \"./utils/av-check\";\nimport { createAVNodeVideoPlugin } from \"./video-plugin\";\n\n/**\n * Effect Layer for the node-av video plugin\n *\n * This layer provides video processing capabilities using node-av (FFmpeg bindings).\n * Note: node-av includes prebuilt FFmpeg binaries, so no system installation is required.\n *\n * @example\n * ```typescript\n * import { AVNodeVideoPlugin } from \"@uploadista/flow-videos-av-node\";\n * import { Effect } from \"effect\";\n *\n * const program = Effect.gen(function* () {\n * const videoPlugin = yield* VideoPlugin;\n * const metadata = yield* videoPlugin.describe(videoBytes);\n * return metadata;\n * });\n *\n * // Run with node-av plugin layer\n * const result = await Effect.runPromise(\n * program.pipe(Effect.provide(AVNodeVideoPluginLive))\n * );\n * ```\n */\nexport const AVNodeVideoPlugin = Layer.succeed(\n VideoPlugin,\n createAVNodeVideoPlugin(),\n);\n\n/**\n * Effect Layer for the node-av video plugin with availability check\n *\n * This layer checks if node-av is properly installed and logs status information.\n * The plugin will still be created, but operations will fail if node-av is not available.\n *\n * @example\n * ```typescript\n * import { AVNodeVideoPluginWithCheck } from \"@uploadista/flow-videos-av-node\";\n * import { Effect } from \"effect\";\n *\n * const program = Effect.gen(function* () {\n * const videoPlugin = yield* VideoPlugin;\n * const metadata = yield* videoPlugin.describe(videoBytes);\n * return metadata;\n * });\n *\n * // Run with node-av plugin layer (with check)\n * const result = await Effect.runPromise(\n * program.pipe(Effect.provide(AVNodeVideoPluginWithCheck))\n * );\n * ```\n */\nexport const AVNodeVideoPluginWithCheck = Layer.effectDiscard(\n Effect.gen(function* () {\n const result = yield* Effect.promise(() => checkAVAvailable());\n\n if (!result.available) {\n console.warn(\n \"⚠️ node-av is not installed or not available.\",\n \"\\nVideo processing operations will fail.\",\n \"\\nInstall node-av: npm install node-av\",\n );\n } else {\n console.log(`✓ node-av ${result.version} detected`);\n }\n }),\n).pipe(Layer.provideMerge(AVNodeVideoPlugin));\n"],"mappings":"ofAaA,eAAsB,GAA2C,CAC/D,GAAI,CAKF,OAHA,MAAM,OAAO,WAGN,CACL,UAAW,GACX,QAAS,MACV,OACM,EAAO,CACd,MAAO,CACL,UAAW,GACX,MAAO,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAC9D,ECTL,MAAaA,EACX,CACE,IAAK,YACL,KAAM,aACN,IAAK,kBACL,IAAK,kBACN,CAKUC,EACX,CACE,IAAK,MACL,KAAM,OACN,IAAK,MACL,IAAK,MACN,CAKUC,EAGT,CACF,KAAM,EACN,KAAM,EACN,IAAK,EACL,IAAK,EACN,CAKYC,EAGT,CACF,IAAK,EACL,IAAK,EACL,KAAM,EACN,OAAQ,EACT,CAKYC,EAAuD,CAClE,KAAM,EACN,MAAO,EACP,IAAK,EACN,CC/DD,SAAgB,GAGd,CACA,IAAMC,EAAmB,EAA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AG1C,MAAM,EAAU,MAAM,EAAQ,OAAO,EAAY,CAEjD,IAAIC,EAA+B,KAC7B,EAAkB,EAAQ,UAEhC,UAAW,MAAM,KAAS,EAAQ,OAChC,EAAW,QAAQ,EAAY,MAAM,CACtC,CAAE,CACD,GAAI,CAAC,EAAO,SAEZ,IAAM,EAAM,EAAM,KAAO,GACnB,EAAW,EAAY,SACzB,EAAY,SAAS,IAAM,EAAY,SAAS,IAChD,EAIJ,GAHkB,OAAO,EAAI,CAAG,GAGf,EAAiB,CAEhC,IAAM,EACJ,EAAqB,IAAW,EAAqB,KACvD,MAAM,EAAe,MAAM,EAAQ,OAAO,EAAa,CAIvD,MAAM,EAAa,OAAO,EAAM,CAChC,IAAM,EAAS,MAAM,EAAa,SAAS,CAC3C,GAAI,GAAQ,KAAM,CAEhB,EAAY,IAAI,WAAW,EAAO,KAAK,CACvC,EAAO,MAAM,CACb,QAKN,GAAI,CAAC,EACH,MAAU,MAAM,+BAA+B,IAAkB,CAGnE,OAAO,GAET,MAAQ,GACN,EAAgB,SAAS,0BAA2B,CAClD,KAAM,4BAA4B,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,GACxF,MAAO,EACR,CAAC,CACL,CAAC,CACL,CCvbH,MAAa,EAAoB,EAAM,QACrC,EACA,GAAyB,CAC1B,CAyBY,EAA6B,EAAM,cAC9C,EAAO,IAAI,WAAa,CACtB,IAAM,EAAS,MAAO,EAAO,YAAc,GAAkB,CAAC,CAEzD,EAAO,UAOV,QAAQ,IAAI,aAAa,EAAO,QAAQ,WAAW,CANnD,QAAQ,KACN,iDACA;wCACA;sCACD,EAIH,CACH,CAAC,KAAK,EAAM,aAAa,EAAkB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/flow-videos-av-node",
3
3
  "type": "module",
4
- "version": "0.0.18-beta.17",
4
+ "version": "0.0.18-beta.2",
5
5
  "description": "FFmpeg video processing plugin for Uploadista Flow with av-node",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -14,9 +14,8 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "node-av": "5.0.2",
18
- "@uploadista/core": "0.0.18-beta.17",
19
- "@uploadista/observability": "0.0.18-beta.17"
17
+ "node-av": "5.0.1",
18
+ "@uploadista/core": "0.0.18-beta.2"
20
19
  },
21
20
  "peerDependencies": {
22
21
  "effect": "^3.0.0",
@@ -25,11 +24,11 @@
25
24
  "devDependencies": {
26
25
  "@effect/vitest": "0.27.0",
27
26
  "@types/node": "24.10.1",
28
- "effect": "3.19.8",
29
- "tsdown": "0.16.8",
30
- "vitest": "4.0.15",
27
+ "effect": "3.19.6",
28
+ "tsdown": "0.16.6",
29
+ "vitest": "4.0.13",
31
30
  "zod": "4.1.13",
32
- "@uploadista/typescript-config": "0.0.18-beta.17"
31
+ "@uploadista/typescript-config": "0.0.18-beta.2"
33
32
  },
34
33
  "scripts": {
35
34
  "build": "tsdown",
@@ -3,7 +3,6 @@ import type {
3
3
  DescribeVideoMetadata,
4
4
  VideoPluginShape,
5
5
  } from "@uploadista/core/flow";
6
- import { withOperationSpan } from "@uploadista/observability";
7
6
  import { Effect } from "effect";
8
7
  import { Decoder, Demuxer, Encoder, Muxer } from "node-av/api";
9
8
  import {
@@ -74,11 +73,7 @@ export function createAVNodeVideoPlugin(): VideoPluginShape {
74
73
  body: `Failed to extract video metadata: ${error instanceof Error ? error.message : String(error)}`,
75
74
  cause: error,
76
75
  }),
77
- }).pipe(
78
- withOperationSpan("video", "describe", {
79
- "video.input_size": input.byteLength,
80
- }),
81
- ),
76
+ }),
82
77
 
83
78
  transcode: (input, options) =>
84
79
  Effect.tryPromise({
@@ -182,16 +177,7 @@ export function createAVNodeVideoPlugin(): VideoPluginShape {
182
177
  body: `Transcode failed: ${error instanceof Error ? error.message : String(error)}`,
183
178
  cause: error,
184
179
  }),
185
- }).pipe(
186
- withOperationSpan("video", "transcode", {
187
- "video.format": options.format,
188
- "video.codec": options.codec,
189
- "video.video_bitrate": options.videoBitrate,
190
- "video.audio_codec": options.audioCodec,
191
- "video.audio_bitrate": options.audioBitrate,
192
- "video.input_size": input.byteLength,
193
- }),
194
- ),
180
+ }),
195
181
 
196
182
  resize: (input, options) =>
197
183
  Effect.tryPromise({
@@ -296,13 +282,7 @@ export function createAVNodeVideoPlugin(): VideoPluginShape {
296
282
  body: `Resize failed: ${error instanceof Error ? error.message : String(error)}`,
297
283
  cause: error,
298
284
  }),
299
- }).pipe(
300
- withOperationSpan("video", "resize", {
301
- "video.width": options.width,
302
- "video.height": options.height,
303
- "video.input_size": input.byteLength,
304
- }),
305
- ),
285
+ }),
306
286
 
307
287
  trim: (input, options) =>
308
288
  Effect.tryPromise({
@@ -421,14 +401,7 @@ export function createAVNodeVideoPlugin(): VideoPluginShape {
421
401
  body: `Trim failed: ${error instanceof Error ? error.message : String(error)}`,
422
402
  cause: error,
423
403
  }),
424
- }).pipe(
425
- withOperationSpan("video", "trim", {
426
- "video.start_time": options.startTime,
427
- "video.end_time": options.endTime,
428
- "video.duration": options.duration,
429
- "video.input_size": input.byteLength,
430
- }),
431
- ),
404
+ }),
432
405
 
433
406
  extractFrame: (input, options) =>
434
407
  Effect.tryPromise({
@@ -491,12 +464,6 @@ export function createAVNodeVideoPlugin(): VideoPluginShape {
491
464
  body: `Frame extraction failed: ${error instanceof Error ? error.message : String(error)}`,
492
465
  cause: error,
493
466
  }),
494
- }).pipe(
495
- withOperationSpan("video", "extract-frame", {
496
- "video.timestamp": options.timestamp,
497
- "video.format": options.format ?? "jpeg",
498
- "video.input_size": input.byteLength,
499
- }),
500
- ),
467
+ }),
501
468
  };
502
469
  }