Reputation: 417
I'm new with python and I want to do is receive UDP stream (streaming from VLC, H264) and make any modifications to the video and display it (Python 2.7).
I used openCV (openCV 2.4.9) and I can receive video frames and also modify it. Now I need to do is create a video file using these frames and display it and I don't need to save both frames and the video.
I tried FFMPEG,FFPLAY and it works on saved video frames.
I appreciate that if you can point out the steps or any other alternatives.
First of all sorry about my explanation early. Here is what I've tried:
Receive UDP video stream.
Modify the video stream: I used openCV and get video frames from stream and modified them it working.
cap = cv2.VideoCapture("udp://224.1.1.1:1234")
while(cap.isOpened()):
success, image = cap.read()
...
cv2.imwrite("./frames/frame%d.jpeg" %count, image)
count += 1
Create video and display: I tried FFMPEG and FFPLAY
command1 = 'ffmpeg -i ./frames/frame%d.jpeg -c:v libx264 -vf fps=23.97 -pix_fmt yuv420p -f rawvideo -'
command2 = 'ffplay -'
pipe1 = sp.Popen(command1,stdout=sp.PIPE)
pipe2 = sp.Popen(command2,stdin=pipe1.stdout)
These steps working but I cannot save frames or video file physically. I need to do is after step 2 direcly pass video frames to FFMPEG, FFPLAY to play without saving them in frames folder.
Upvotes: 0
Views: 1835
Reputation: 21
you can use cv2.imshow() to show your processed frames directly rather than passing them to ffplay or ffmpeg,for example instead of writing the frames in your code
import cv2
cap = cv2.VideoCapture("udp://224.1.1.1:1234")
while(cap.isOpened()):
success,image = cap.read()
......
......
cv2.imshow("Video", image)
Upvotes: 0
Reputation: 417
command1 = 'ffmpeg -y -f image2pipe -vcodec mjpeg -r 23.97 -i - -vcodec mpeg4 -pix_fmt yuv420p -c:v libx264 -r 23.97 -f avi - '
command2 = 'ffplay -'
pipe1 = sp.Popen(command1,stdin=sp.PIPE,stdout=sp.PIPE)
pipe2 = sp.Popen(command2,stdin=pipe1.stdout)
While(cap.isOpened()):
success,raw_image = cap.read()
pil_im = Image.fromarray(raw_image)
pil_im.save(pipe1.stdin ,'JPEG')
This works for me but some colour problems.
Upvotes: 1