Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not get m3u8 and ts segments when outputting to buffer #1302

Open
mesozoic-technology opened this issue Oct 26, 2024 · 0 comments
Open

Comments

@mesozoic-technology
Copy link

mesozoic-technology commented Oct 26, 2024

Version information

  • fluent-ffmpeg version: 2.1.3
  • ffmpeg version: 7.1
  • OS: mac

Code to reproduce

My problem is that when I let fluent write the files to my filesystem on its own, it writes about 10 .ts files and a .m3u8 file that contains lines referencing those .ts files.

But when I try to save this into memory into two different buffers it seems I can get a bunch of .ts files in the buffer, but the m3u8 file does no t have the same amount of references to the segments that it does when I just save it to the filesystem.

I tried to put it into one command using two pipes (chatgpt told me so but it might be hallucinating).

This is what I wind up writing to the filesystem when I try to write what I got in memory for the m3u8. Notice there is only one pipe:10.ts. There should be about 10 of them, it seems.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.032000,
pipe:10.ts
#EXT-X-ENDLIST

The size of the buffer for the segments is about four times the size of the file I am trying to turn into an HLS format for playback, for what that's worth.

here is what gets the m3u8

    const readable = new Readable()
    readable.push(buffer)
    readable.push(null)

    const passthroughm3u8 = new PassThrough()
    const chunksm3u8 = []

    passthroughm3u8.on('data', chunk => chunksm3u8.push(chunk))
    passthroughm3u8.on('end', () => resolve(Buffer.concat(chunksm3u8)))
    passthroughm3u8.on('error', reject)

    ffmpeg()
      .input(readable)
      .inputFormat('mp4')
      .outputOptions([ 
        '-f hls', 
        '-hls_time 10', 
        '-hls_list_size 0',
      ])
      .on('error', reject)
      .pipe(passthroughm3u8)

here is what gets the segments

    const readable = new Readable()
    readable.push(buffer)
    readable.push(null)

    const passthrough = new PassThrough()
    const chunks = []

    passthrough.on('data', chunk => chunks.push(chunk))
    passthrough.on('end', () => {
      console.log("done")
      resolve(Buffer.concat(chunks))
    })
    passthrough.on('error', reject)

    ffmpeg()
      .input(readable)
      .inputFormat('mp4')
      .outputOptions([ 
        '-f mpegts',
        '-hls_time 10', 
        '-hls_list_size 0',
        '-hls_segment_type mpegts',
      ])
      .on('error', reject)
      .pipe(passthrough, { end: true })

Checklist

  • [-] I have read the FAQ
  • [ does not apply ] I tried the same with command line ffmpeg and it works correctly (hint: if the problem also happens this way, this is an ffmpeg problem and you're not reporting it to the right place)
  • [ does not apply ] I have included full stderr/stdout output from ffmpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant