【发布时间】:2019-11-12 02:49:09
【问题描述】:
我正在尝试学习使用 FFmpeg 的 libav 库。我正在为 Node.js 使用 beamcoder 包装器。我有一个程序可以解码 MP4 文件,然后尝试将其编码为 h264。编码步骤生成的数据包始终将其持续时间设置为零。任何想法为什么会这样?
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);
}
})();
【问题讨论】:
标签: ffmpeg