Как извлечь кадры потока RTSP с помощью ffmpeg в Python ⇐ Python
Как извлечь кадры потока RTSP с помощью ffmpeg в Python
I want to extract the frames from an RTSP stream using a python script like
import subprocess import cv2 import numpy as np def extract_frames_and_display(rtsp_url): ffmpeg_cmd = [ "ffmpeg", "-i", rtsp_url, "-f", "image2pipe", "-pix_fmt", "bgr24", "-vcodec", "rawvideo", "-" ] ffmpeg_process = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: while True: raw_frame = ffmpeg_process.stdout.read(1920 * 1080 * 3) if not raw_frame: break frame = np.frombuffer(raw_frame, dtype=np.uint8).reshape((1080, 1920, 3)) frame = cv2.resize(frame, (800, 600)) cv2.imshow("RTSP Stream", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break finally: cv2.destroyAllWindows() ffmpeg_process.terminate() ffmpeg_process.wait() rtsp_url = "rtsp://localhost:8554/live.stream" extract_frames_and_display(rtsp_url) The problem in this code is that when showing the extracted frames using opencv they appear like multiple frames togather .. not each frame at a time like when we play a video.
Источник: https://stackoverflow.com/questions/780 ... -in-python
I want to extract the frames from an RTSP stream using a python script like
import subprocess import cv2 import numpy as np def extract_frames_and_display(rtsp_url): ffmpeg_cmd = [ "ffmpeg", "-i", rtsp_url, "-f", "image2pipe", "-pix_fmt", "bgr24", "-vcodec", "rawvideo", "-" ] ffmpeg_process = subprocess.Popen(ffmpeg_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: while True: raw_frame = ffmpeg_process.stdout.read(1920 * 1080 * 3) if not raw_frame: break frame = np.frombuffer(raw_frame, dtype=np.uint8).reshape((1080, 1920, 3)) frame = cv2.resize(frame, (800, 600)) cv2.imshow("RTSP Stream", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break finally: cv2.destroyAllWindows() ffmpeg_process.terminate() ffmpeg_process.wait() rtsp_url = "rtsp://localhost:8554/live.stream" extract_frames_and_display(rtsp_url) The problem in this code is that when showing the extracted frames using opencv they appear like multiple frames togather .. not each frame at a time like when we play a video.
Источник: https://stackoverflow.com/questions/780 ... -in-python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как передавать кадры один за другим и захватывать декодированные кадры с помощью LibAV?
Anonymous » » в форуме C# - 0 Ответы
- 27 Просмотры
-
Последнее сообщение Anonymous
-