Streampunk / beamcoder

Node.js native bindings to FFmpeg.
GNU General Public License v3.0
397 stars 76 forks source link

How to close an SDP/RTP demuxers early #54

Closed jbaudanza closed 3 years ago

jbaudanza commented 3 years ago

I'm using beamcoder to save an RTP-OPUS stream into an OGG-OPUS file.

I have an SDP/RTP demuxer that is feeding into an OGG-OPUS muxer. It's using a very simple demuxer.read / muxer.writeFrame loop. It's all working fine, but I'm running into problems shutting it down when I'm done saving.

My first approach was to call demuxer.forceClose to try and unblock the unresolved demuxer.read promise. This, however, is generating a segmentation fault. I suspect it is related to this issue: https://github.com/Streampunk/beamcoder/issues/53 If you'd like, I can provide more debugging information, but it's probably redundant.

My next idea is to try and set the interrupt_callback in the AVFormatContext struct. See https://github.com/FFmpeg/FFmpeg/blob/3da35b7cc7e2f80ca4af89e55fef9a7bcb19c128/libavformat/avformat.h#L1503

This would require patching beamcoder. I think it would probably go before avformat_open_input is called. Maybe around here: https://github.com/Streampunk/beamcoder/blob/ab226a7aefa0dd1e09de9bc81bff964ee818fb6f/src/demux.cc#L55

Could you let me know if I'm on the right path? Is there a better way to close an RTP demuxer early?

Thanks for your help! beamcoder has been a lifesaver!