abhiTronix / deffcode

A cross-platform High-performance FFmpeg based Real-time Video Frames Decoder in Pure Python 🎞️⚡
https://abhitronix.github.io/deffcode
Apache License 2.0
182 stars 4 forks source link

[Question]: while input stream have stop , deffcode will not stop but just hold on #41

Closed wuqingzhou828 closed 3 months ago

wuqingzhou828 commented 1 year ago

Issue guidelines

Issue Checklist

Describe your Question

source: 'rtmp://xxxx/live/xxx' is a online stream while the online stream haved close, my code will not stop but just hold on

Terminal log output(Optional)

No response

Python Code(Optional)

def test():
    ffparams = {
        "-vcodec": "h264_cuvid",
        "-debug": 1,
        "-ffprefixes": [
            "-vsync", "0",
            "-hwaccel_device", "0",
            "-hwaccel", "cuda",
        ],
        "-custom_resolution": "null",
        "-framerate": "null",
    }
    source = 'rtmp://xxxx/live/xxx'
    videoDecoder = VideoDecode(source=source, ffparams=ffparams)
    decoder = videoDecoder.decode(verbose=True)
    while True:
        try:
            frame = next(decoder.generateFrame(), None)
            if frame is None:
                break
        except Exception as e:
            print(e)

if __name__ == '__main__':
    test()

DeFFcode Version

0.2.5

Python version

3.8

Operating System version

nvcr.io/nvidia/tensorrt:22.04-py3 and ffmpeg gpu

Any other Relevant Information?

No response

wuqingzhou828 commented 1 year ago

i have to stop by KeyboardInterrupt rtmp @ 0x555986dfd140] Sending bytes read report0:00:11.16 bitrate=1244160.0kbits/s speed= 1.8x
^CTraceback (most recent call last):1150kB time=00:00:20.88 bitrate=1244160.0kbits/s speed=1.34x
File "test_infer.py", line 120, in test() File "test_infer.py", line 110, in test frame = next(decoder.generateFrame(), None) File "/usr/local/lib/python3.8/dist-packages/deffcode/ffdecoder.py", line 711, in generateFrame frame = self.fetchNextFrame() File "/usr/local/lib/python3.8/dist-packages/deffcode/ffdecoder.py", line 673, in fetchNextFrame frame = self.fetchNextfromPipeline() File "/usr/local/lib/python3.8/dist-packages/deffcode/ffdecoder.py", line 655, in fetchNextfromPipeline self.__process.stdout.read( KeyboardInterrupt

abhiTronix commented 1 year ago

@wuqingzhou828 That is because you're processing frames in GPU memory which is separated from main thread and will continue to process until you manually kill the process or send SIGINT signal to terminate process. However I can add a flag to kill process immediately, I'll look into that,

abhiTronix commented 3 months ago

@wuqingzhou828 Successfully resolved and merged in commit: https://github.com/abhiTronix/deffcode/commit/f4682f3a317d77481bc146ad020104b01c2fdb96