Reputation: 463
I'm trying to learn to use the libav libraries from FFmpeg. I'm using the beamcoder wrapper for Node. I have a program that decodes an MP4 file and then tries to encode it to h264. The resulting packets from the encode step always have their duration set to zero. Any ideas why that would be?
const beamcoder = require('beamcoder');
async function run() {
const dm = await beamcoder.demuxer('file:Video_001.mp4');
let videoStream = null;
for (const stream of dm.streams) {
const codecpar = stream.codecpar;
if (codecpar.codec_type === 'video') {
videoStream = stream;
}
}
const videoDecoder = beamcoder.decoder({
demuxer: dm,
stream_index: videoStream.index
});
const videoEncoder = beamcoder.encoder({
name: 'h264',
time_base: videoStream.time_base,
framerate: videoStream.r_frame_rate,
pix_fmt: videoStream.codecpar.format,
height: videoStream.codecpar.height,
width: videoStream.codecpar.width,
});
let packet = await dm.read();
while (packet !== null) {
if (packet.stream_index === videoStream.index) {
const decResult = await videoDecoder.decode(packet);
if (decResult.frames.length > 0) {
const encResult = await videoEncoder.encode(decResult.frames);
if (encResult.packets.length > 0) {
console.log(encResult.packets[0].duration); // Always prints 0
}
}
}
packet = await dm.read();
}
}
(async () => {
try {
await run();
} catch (err) {
console.log('FAILED', err);
}
})();
Upvotes: 3
Views: 902
Reputation: 31101
Not all file types encode packet duration, some only encode absolute frame timestamps. This is normal, and just something you must handle in your code.
Upvotes: 2