javascript – FFmpeg video has an excessively long duration
When using ytdl-core and ffmpeg-static to download high quality youtube videos, the output video is supposedly thousands of hours long, which makes it not let me advance the video in a media player. The error only occurs in windows 10 players. In VLC or Discord it does not happen.
res.header("Content-Disposition", `attachment; filename=video.mp4`)
let video = ytdl(link, {
filter: 'videoonly'
})
let audio = ytdl(link, {
filter: 'audioonly',
highWaterMark: 1 << 25
});
const ffmpegProcess = cp.spawn(ffmpeg, [
'-i', `pipe:3`,
'-i', `pipe:4`,
'-map', '1:0',
'-map', '0:0',
'-vcodec', 'libx264',
'-c:v', 'libx264',
'-c:a', 'aac',
'-crf', '27',
'-preset', 'veryslow',
'-b:v', '1500k',
'-b:a', '128k',
'-movflags', 'frag_keyframe+empty_moov',
'-f', 'mp4',
'-loglevel', 'error',
'-',
], {
stdio: [
'pipe', 'pipe', 'pipe', 'pipe', 'pipe',
],
});
video.pipe(ffmpegProcess.stdio[3]);
audio.pipe(ffmpegProcess.stdio[4]);
ffmpegProcess.stdio[1].pipe(res);
let ffmpegLogs=""
ffmpegProcess.stdio[2].on(
'data',
(chunk) => {
ffmpegLogs += chunk.toString()
}
)
ffmpegProcess.on(
'exit',
(exitCode) => {
if (exitCode === 1) {
console.error(ffmpegLogs)
}
}
)
I’ve tried changing the codecs options. But I’m not sure what I’m doing
Read more here: Source link