0

I'm trying to set up a node.js app that allows me to download files from a web interface. I'm using yt-dl to get the video and audio stream and ffmpeg to pipe those streams into an mp4. This works and returns a mp4 file.

Now the only issue I have is that when I play the file through most video players, the video player is unable to seek, or skip through the song. I found somewhere deep down on a forum that means that that means the mp4 headers are not working but that is all I could find. Here is my code, almost unchanged from this response on another thread.

Can anyone provide a solution for this issue.

ytdl.getInfo(link, options).then(info => {
        audioStream = ytdl.downloadFromInfo(info, { ...options, quality: 'highestaudio' });
        videoStream = ytdl.downloadFromInfo(info, { ...options, quality: 'highestvideo' });
        // create the ffmpeg process for muxing
        ffmpegProcess = cp.spawn(ffmpegPath, [
            // supress non-crucial messages
            '-loglevel', '8', '-hide_banner',
            // input audio and video by pipe
            '-i', 'pipe:3', '-i', 'pipe:4',
            // map audio and video correspondingly
            '-map', '0:a', '-map', '1:v',
            // no need to change the codec
            '-c', 'copy',
            // output mp4 and pipe
            '-f', 'matroska', 'pipe:5'
        ], {
            // no popup window for Windows users
            windowsHide: true,
            stdio: [
                // silence stdin/out, forward stderr,
                'inherit', 'inherit', 'inherit',
                // and pipe audio, video, output
                'pipe', 'pipe', 'pipe'
            ]
        });
        audioStream.pipe(ffmpegProcess.stdio[3]);
        videoStream.pipe(ffmpegProcess.stdio[4]);
        ffmpegProcess.stdio[5].pipe(result);
    });
Lars
  • 1
  • 1
  • You're generating a matroska file, not mp4. And if you pipe the output, there won't be cues written in the matroska file, which are used for seeking. – Gyan Sep 08 '22 at 04:42
  • Thanks a lot for your anwser! I will try to fix that as soon as I have access to the code. – Lars Sep 08 '22 at 07:18

0 Answers0