gpt4 book ai didi

node.js - Node js 将 mp4 转换为 m3u8 后,第一个 m3u8 ts 段不起作用

转载 作者:行者123 更新时间:2023-12-04 23:11:46 25 4
gpt4 key购买 nike

index.js

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpeg = require('fluent-ffmpeg');
const process = require('process');


const args = process.argv.slice(2);
if (args.length !== 4) {
console.error('Incorrect number of arguments');
process.exit(1);
}
const startTime = args[0];
const timeDuration = args[1];
const inputFile = args[2];
const outputFile=args[3];

ffmpeg.setFfmpegPath(ffmpegPath);

ffmpeg(inputFile)
.setStartTime(startTime)
.setDuration(timeDuration)
.output(outputFile)
.outputOptions('-hls_list_size 0')
.on('end', function(err) {
if(!err) { console.log('conversion Done') }
})
.on('error', function(err){
console.log('error: ', err)
}).run();

Here is the index.js and I'm running it by hitting the command on the terminal

node index.js 5 40 ./input.mp4 ./output.m3u8

Here 5 is for starting time and 40 is the time duration in seconds. The process creates m3u8 with ts files but the first ts file isn't getting created properly. It's been created in kb format while all the other files in mb format.enter image description here


the output_test0 isn't getting generated properly and so that's why while playing the m3u8 file, the first few seconds is just static picture. This issue has been happening with the first ts output only. Any trick on how to fix it?

最佳答案

在您评论它似乎是由使用输入搜索而不是输出搜索引起的:
使用seek()seekOutput()而不是 setStartTime() . The documentation描述差异:

seek(time): seek output


Aliases: seekOutput().

Seeks streams before encoding them into the output. This is different from calling seekInput() in that the offset will only apply to one output. This is also slower, as skipped frames will still be decoded (but dropped).

The time argument may be a number (in seconds) or a timestamp string (with format [[hh:]mm:]ss[.xxx]).

ffmpeg('/path/to/file.avi')
.seekInput('1:00')

.output('from-1m30s.avi')
.seek(30)

.output('from-1m40s.avi')
.seek('0:40');
setStartTime()seekInput() 的别名.来自 the same documentation :

seekInput(time): set input start time


Alias: setStartTime().

Seeks an input and only start decoding at given time offset.


请注意 seek()seekOutput()应该应用于输出而不是作为 seekInput() 的输入,即在 output() 之后.

关于node.js - Node js 将 mp4 转换为 m3u8 后,第一个 m3u8 ts 段不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65709194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com