Skip to content

Commit c0c3d27

Browse files
committed
chore: details log
1 parent 6a92cbf commit c0c3d27

File tree

2 files changed

+80
-22
lines changed

2 files changed

+80
-22
lines changed

packages/av-cliper/src/clips/mp4-clip.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,9 @@ class VideoFrameFinder {
763763
this.#videoFrames.push(rsVf);
764764
},
765765
error: (err) => {
766-
Log.error(
767-
`VideoFinder VideoDecoder err: ${err.message}`,
768-
', config:',
769-
encoderConf,
770-
);
766+
const errMsg = `VideoFinder VideoDecoder err: ${err.message}, config: ${JSON.stringify(encoderConf)}, state: ${JSON.stringify(this.#getState())}`;
767+
Log.error(errMsg);
768+
throw Error(errMsg);
771769
},
772770
});
773771
this.#dec.configure(encoderConf);
@@ -970,7 +968,7 @@ function createAudioChunksDecoder(
970968
opts: { resampleRate: number; volume: number },
971969
outputCb: (pcm: Float32Array[]) => void,
972970
) {
973-
let intputCnt = 0;
971+
let inputCnt = 0;
974972
let outputCnt = 0;
975973
const outputHandler = (pcmArr: Float32Array[]) => {
976974
outputCnt += 1;
@@ -1005,21 +1003,38 @@ function createAudioChunksDecoder(
10051003
ad.close();
10061004
},
10071005
error: (err) => {
1008-
Log.error(`MP4Clip AudioDecoder err: ${err.message}`);
1006+
handleDecodeError('MP4Clip AudioDecoder err', err as Error);
10091007
},
10101008
});
10111009
adec.configure(decoderConf);
10121010

1011+
function handleDecodeError(prefixStr: string, err: Error) {
1012+
const errMsg = `${prefixStr}: ${(err as Error).message}, state: ${JSON.stringify(
1013+
{
1014+
qSize: adec.decodeQueueSize,
1015+
state: adec.state,
1016+
inputCnt,
1017+
outputCnt,
1018+
},
1019+
)}`;
1020+
Log.error(errMsg);
1021+
throw Error(errMsg);
1022+
}
1023+
10131024
return {
10141025
decode(chunks: EncodedAudioChunk[]) {
1015-
intputCnt += chunks.length;
1016-
for (const chunk of chunks) adec.decode(chunk);
1026+
inputCnt += chunks.length;
1027+
try {
1028+
for (const chunk of chunks) adec.decode(chunk);
1029+
} catch (err) {
1030+
handleDecodeError('decode audio chunk error', err as Error);
1031+
}
10171032
},
10181033
close() {
10191034
if (adec.state !== 'closed') adec.close();
10201035
},
10211036
get decoding() {
1022-
return intputCnt > outputCnt;
1037+
return inputCnt > outputCnt;
10231038
},
10241039
get state() {
10251040
return adec.state;
@@ -1329,11 +1344,16 @@ async function thumbnailByKeyFrame(
13291344
}
13301345
},
13311346
error: (err) => {
1332-
Log.error(
1333-
`thumbnails decoder error: ${err.message}`,
1334-
', config:',
1335-
encoderConf,
1336-
);
1347+
const errMsg = `thumbnails decoder error: ${err.message}, config: ${JSON.stringify(encoderConf)}, state: ${JSON.stringify(
1348+
{
1349+
qSize: dec.decodeQueueSize,
1350+
state: dec.state,
1351+
outputCnt,
1352+
inputCnt: chunks.length,
1353+
},
1354+
)}`;
1355+
Log.error(errMsg);
1356+
throw Error(errMsg);
13371357
},
13381358
});
13391359
abortSingl.addEventListener('abort', () => {

packages/internal-utils/src/recodemux.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,19 @@ export function recodemux(opts: IRecodeMuxOpts): {
123123
},
124124
encodeAudio: (ad) => {
125125
if (aEncoder == null) return;
126-
aEncoder.encode(ad);
127-
ad.close();
126+
try {
127+
aEncoder.encode(ad);
128+
ad.close();
129+
} catch (err) {
130+
const errMsg = `encode audio chunk error: ${(err as Error).message}, state: ${JSON.stringify(
131+
{
132+
qSize: aEncoder.encodeQueueSize,
133+
state: aEncoder.state,
134+
},
135+
)}`;
136+
Log.error(errMsg);
137+
throw Error(errMsg);
138+
}
128139
},
129140
getEncodeQueueSize: () =>
130141
vEncoder?.encodeQueueSize ?? aEncoder?.encodeQueueSize ?? 0,
@@ -267,9 +278,22 @@ function encodeVideoTrack(
267278
return encoder0.encodeQueueSize + encoder1.encodeQueueSize;
268279
},
269280
encode: (vf: VideoFrame, opts: VideoEncoderEncodeOptions) => {
270-
if (opts.keyFrame) gopId += 1;
271-
const encoder = gopId % 2 === 0 ? encoder0 : encoder1;
272-
encoder.encode(vf, opts);
281+
try {
282+
if (opts.keyFrame) gopId += 1;
283+
const encoder = gopId % 2 === 0 ? encoder0 : encoder1;
284+
encoder.encode(vf, opts);
285+
} catch (err) {
286+
const errMsg = `encode video frame error: ${(err as Error).message}, state: ${JSON.stringify(
287+
{
288+
ts: vf.timestamp,
289+
keyFrame: opts.keyFrame,
290+
duration: vf.duration,
291+
gopId,
292+
},
293+
)}`;
294+
Log.error(errMsg);
295+
throw Error(errMsg);
296+
}
273297
},
274298
flush: async () => {
275299
await Promise.all([
@@ -318,7 +342,14 @@ function createVideoEncoder(
318342
} as const;
319343
const encoder = new VideoEncoder({
320344
error: (err) => {
321-
Log.error('VideoEncoder error:', err, ', config:', encoderConf);
345+
const errMsg = `VideoEncoder error: ${err.message}, config: ${JSON.stringify(encoderConf)}, state: ${JSON.stringify(
346+
{
347+
qSize: encoder.encodeQueueSize,
348+
state: encoder.state,
349+
},
350+
)}`;
351+
Log.error(errMsg);
352+
throw Error(errMsg);
322353
},
323354
output: outHandler,
324355
});
@@ -362,7 +393,14 @@ function encodeAudioTrack(
362393

363394
const encoder = new AudioEncoder({
364395
error: (err) => {
365-
Log.error('AudioEncoder error:', err, ', config:', encoderConf);
396+
const errMsg = `AudioEncoder error: ${err.message}, config: ${JSON.stringify(
397+
encoderConf,
398+
)}, state: ${JSON.stringify({
399+
qSize: encoder.encodeQueueSize,
400+
state: encoder.state,
401+
})}`;
402+
Log.error(errMsg);
403+
throw Error(errMsg);
366404
},
367405
output: (chunk, meta) => {
368406
if (trackId === -1) {

0 commit comments

Comments
 (0)