Как включить ffmpeg python внутри докера?Python

Программы на Python
Anonymous
Как включить ffmpeg python внутри докера?

Сообщение Anonymous »


I have a problem with enabling ffmpeg streaming inside my Docker container, and specifically, inside a Python service running inside the Docker. I need to stream my screen view, and I'm using the 'x11grab' source, and the destination is an RTSP server (AWS IVS). This is my code for the stream:

bit_rate = f"{self.config_service.thermal_stream_bit_rate}k" # 150k vsync_param = self.config_service.stream_vsync_param # 'cfr' frame_rate = self.config_service.stream_frame_rate # 5 stream_command = ffmpeg.input( os.getenv('DISPLAY'), # env var passed into the container s=f"{self.config_service.display_width}x{self.config_service.display_height}", f="x11grab", r=frame_rate, fflags="nobuffer+discardcorrupt+shortest", loglevel="level+debug", )..output( self.dest_path, # My rstp url vcodec='nvenc_h264', preset='hp', pix_fmt=pix_format_param, tune="zerolatency", b=bit_rate, g=keyframe_interval_seconds, r=frame_rate, format="flv", ) streaming_process = await stream_command.run_asyncio(pipe_stderr=True) When I run the code, I receive this error: x11grab: No such file or directory.

When I enter the Docker container, and run Python, and then the script:

import ffmpeg >>> x11_display = ':0' >>> format = "x11grab" >>> screen_width = f"1920x1080" >>> bit_rate = "150k" >>> pix_format_param = "yuv420p" >>> keyframe_interval_seconds = 2 >>> frame_rate = 5 >>> dest_path = 'rtmps://XXXX.global-contribute.live-video.net:443/app/YYYY' >>> command = ffmpeg.input(x11_display, s=screen_width, f="x11grab", r=frame_rate, fflags="nobuffer+discardcorrupt+shortest", loglevel="level+debug",).output(dest_path, vcodec='nvenc_h264', preset='hp', pix_fmt=pix_format_param, tune="zerolatency", b=bit_rate, g=keyframe_interval_seconds, r=frame_rate, format="flv",) >>> command.run() The stream is starting. I took the exact command by printing inside my service script (print the ffmpeg.input, and the ffmpeg.output). Also, when I tried async running the command (as in my script) inside the Python console, it also succeeded, so it's not related to that. Basically there are no functional differences between the commands. I've tried comparing the Python version, the ffmpeg version, the file system permissions - they are the same in the script run and in the python console. I don't understand what configuration am I missing. Thank you in advance.


Источник: https://stackoverflow.com/questions/780 ... e-a-docker

Вернуться в «Python»