![]() ![]() Note: ffmpeg CLI should be in the execution path. Start FFmpeg sub-process with stdout as pipe: ffmpeg_process = ( Note: ffprobe CLI should be in the execution path. Getting the framerate may be a bit of a challenge. Using FFprobe for getting video frames resolution and framerate (without using OpenCV): p = ffmpeg.probe(stream_url, select_streams='v') Using ffmpeg-python is almost like using subprocess module, it used here mainly for simplifying the usage of FFprobe. In cases where cv2.VideoCapture is not working, we may use FFmpeg CLI as sub-process.įfmpeg-python module is Python binding for FFmpeg CLI. Using ffmpeg-python for reading the video, and OpenCV for recording the video: #url = '' # Need to login to first (using the browser). Testing the setup using FFplay and subprocess module: from streamlink import Streamlink ![]() Out.write(frame) # Write frame to output.mp4 Width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # Get frame size and rate of the input video Stream_url = stream_to_url(url, quality) # Get the video URLĬap = cv2.VideoCapture(stream_url, cv2.CAP_FFMPEG) # Open video stream for capturing Url = '' # Need to login to first (using the browser). Raise ValueError('Could not locate your stream.') If cv2.waitKey(1) = 27: # Press Esc for stop recording (cv2.waitKey is going to work only when cv2.imshow is used).Ĭomplete code sample: from streamlink import Streamlink if (frame_counter % 30 = 0):Ĭv2.imshow('frame', frame) # Show frame every 30 frames (for testing) One option to end the recording is when user press Esc key.Ĭv2.waitKey(1) is going to work only after executing cv2.imshow.Ī simple solution is executing cv2.imshow every 30 frames (for example). It is recommended to break the loop if ret is False: ret, frame = cap.read() Out = cv2.VideoWriter(video_file_name, cv2.VideoWriter_fourcc(*'mp4v'), fps, (width, height)) # Open video file for writing ![]() Height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) It is recommended to get frame size and rate of the input video, and set VideoWriter accordingly: width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) For getting a valid output file, we have to execute out.release() after the loop, but the loop may never end.The first argument of cv2.VideoWriter should be MP4 file name, and not stream.out = cv2.VideoWriter(stream, cv2.VideoWriter_fourcc(*'mp4v'), 30, (1920, 1080)) should be before the while True loop.cap = cv2.VideoCapture(stream) should be before the while True loop.The answer is going to be focused on the second part (also because I don't know GStreamer so well). The fist part uses GStreamer syntax, and OpenCV for Python is most likely not built with GStreamer. I get: OpenCV: FFMPEG: tag 0x7634706d/'mp4v' is not supported with codec id 12 and format 'hls / Apple HTTP Live Streaming' Out = cv2.VideoWriter(gst_out, cv2.VideoWriter_fourcc(*'mp4v'), 30, (1920, 1080))įor this code, I get this error msg: Error in the pull function.Īnd if I remove gst_out and feed stream instead as well as moving cap and out into the while loop like so: if streamlink.streams(url): Gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! nvvidconv ! omxh264enc ! h264parse ! qtmux ! filesink location=stream " Here's what I currently have: if streamlink.streams(url): which I believe those two are only dealing with (for recording). P.S.: Yes, I know there's other options like Streamlink and yt-dwl, but I want to operate solely in python, not using CLI. With this, I have no problem reading the stream and even writing a few images from it, but when it comes to writing it as a video, I get errors. I'm looking to record a Twitch Livestream by feeding it the direct livestream url using streamlink.streams(url) (which returns a.
0 Comments
Leave a Reply. |