Skip to content

Commit

Permalink
chore: details log
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed Dec 20, 2024
1 parent 6a92cbf commit c0c3d27
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 22 deletions.
50 changes: 35 additions & 15 deletions packages/av-cliper/src/clips/mp4-clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,9 @@ class VideoFrameFinder {
this.#videoFrames.push(rsVf);
},
error: (err) => {
Log.error(
`VideoFinder VideoDecoder err: ${err.message}`,
', config:',
encoderConf,
);
const errMsg = `VideoFinder VideoDecoder err: ${err.message}, config: ${JSON.stringify(encoderConf)}, state: ${JSON.stringify(this.#getState())}`;
Log.error(errMsg);
throw Error(errMsg);
},
});
this.#dec.configure(encoderConf);
Expand Down Expand Up @@ -970,7 +968,7 @@ function createAudioChunksDecoder(
opts: { resampleRate: number; volume: number },
outputCb: (pcm: Float32Array[]) => void,
) {
let intputCnt = 0;
let inputCnt = 0;
let outputCnt = 0;
const outputHandler = (pcmArr: Float32Array[]) => {
outputCnt += 1;
Expand Down Expand Up @@ -1005,21 +1003,38 @@ function createAudioChunksDecoder(
ad.close();
},
error: (err) => {
Log.error(`MP4Clip AudioDecoder err: ${err.message}`);
handleDecodeError('MP4Clip AudioDecoder err', err as Error);
},
});
adec.configure(decoderConf);

function handleDecodeError(prefixStr: string, err: Error) {
const errMsg = `${prefixStr}: ${(err as Error).message}, state: ${JSON.stringify(
{
qSize: adec.decodeQueueSize,
state: adec.state,
inputCnt,
outputCnt,
},
)}`;
Log.error(errMsg);
throw Error(errMsg);
}

return {
decode(chunks: EncodedAudioChunk[]) {
intputCnt += chunks.length;
for (const chunk of chunks) adec.decode(chunk);
inputCnt += chunks.length;
try {
for (const chunk of chunks) adec.decode(chunk);
} catch (err) {
handleDecodeError('decode audio chunk error', err as Error);
}
},
close() {
if (adec.state !== 'closed') adec.close();
},
get decoding() {
return intputCnt > outputCnt;
return inputCnt > outputCnt;
},
get state() {
return adec.state;
Expand Down Expand Up @@ -1329,11 +1344,16 @@ async function thumbnailByKeyFrame(
}
},
error: (err) => {
Log.error(
`thumbnails decoder error: ${err.message}`,
', config:',
encoderConf,
);
const errMsg = `thumbnails decoder error: ${err.message}, config: ${JSON.stringify(encoderConf)}, state: ${JSON.stringify(
{
qSize: dec.decodeQueueSize,
state: dec.state,
outputCnt,
inputCnt: chunks.length,
},
)}`;
Log.error(errMsg);
throw Error(errMsg);
},
});
abortSingl.addEventListener('abort', () => {
Expand Down
52 changes: 45 additions & 7 deletions packages/internal-utils/src/recodemux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,19 @@ export function recodemux(opts: IRecodeMuxOpts): {
},
encodeAudio: (ad) => {
if (aEncoder == null) return;
aEncoder.encode(ad);
ad.close();
try {
aEncoder.encode(ad);
ad.close();
} catch (err) {
const errMsg = `encode audio chunk error: ${(err as Error).message}, state: ${JSON.stringify(
{
qSize: aEncoder.encodeQueueSize,
state: aEncoder.state,
},
)}`;
Log.error(errMsg);
throw Error(errMsg);
}
},
getEncodeQueueSize: () =>
vEncoder?.encodeQueueSize ?? aEncoder?.encodeQueueSize ?? 0,
Expand Down Expand Up @@ -267,9 +278,22 @@ function encodeVideoTrack(
return encoder0.encodeQueueSize + encoder1.encodeQueueSize;
},
encode: (vf: VideoFrame, opts: VideoEncoderEncodeOptions) => {
if (opts.keyFrame) gopId += 1;
const encoder = gopId % 2 === 0 ? encoder0 : encoder1;
encoder.encode(vf, opts);
try {
if (opts.keyFrame) gopId += 1;
const encoder = gopId % 2 === 0 ? encoder0 : encoder1;
encoder.encode(vf, opts);
} catch (err) {
const errMsg = `encode video frame error: ${(err as Error).message}, state: ${JSON.stringify(
{
ts: vf.timestamp,
keyFrame: opts.keyFrame,
duration: vf.duration,
gopId,
},
)}`;
Log.error(errMsg);
throw Error(errMsg);
}
},
flush: async () => {
await Promise.all([
Expand Down Expand Up @@ -318,7 +342,14 @@ function createVideoEncoder(
} as const;
const encoder = new VideoEncoder({
error: (err) => {
Log.error('VideoEncoder error:', err, ', config:', encoderConf);
const errMsg = `VideoEncoder error: ${err.message}, config: ${JSON.stringify(encoderConf)}, state: ${JSON.stringify(
{
qSize: encoder.encodeQueueSize,
state: encoder.state,
},
)}`;
Log.error(errMsg);
throw Error(errMsg);
},
output: outHandler,
});
Expand Down Expand Up @@ -362,7 +393,14 @@ function encodeAudioTrack(

const encoder = new AudioEncoder({
error: (err) => {
Log.error('AudioEncoder error:', err, ', config:', encoderConf);
const errMsg = `AudioEncoder error: ${err.message}, config: ${JSON.stringify(
encoderConf,
)}, state: ${JSON.stringify({
qSize: encoder.encodeQueueSize,
state: encoder.state,
})}`;
Log.error(errMsg);
throw Error(errMsg);
},
output: (chunk, meta) => {
if (trackId === -1) {
Expand Down

0 comments on commit c0c3d27

Please sign in to comment.