How to convert video to image?

I want to show the video that is predicted by the model. But I don’t know how to convert video to image ,when I get the image , these pictures will be predicted by model. finally those image will be converted a video.

I try

import panel as pn
pn.extension()
video = pn.pane.Video(’/output/video_sample.mp4’, width=640, height=360, loop=True)
pn.Row(video.controls(jslink=True), video)

But how to convert to image

Hi @David_legend

It might be a too complicated example to learn from. But you can find an advanced example here panel sharing/Videostream Interface.

You can try the app here VideoStream with transforms

You can just extend the example with more transforms. You can transform either PIL Images or numpy nd.arrays.

@Marc Thank you, and I have learned about the way to add model , but how to change the camera interface, and set video path

What do you mean by

  • change the camera interface?
  • change the video path?

@Marc
I found the videostream is based on camera. I want to input a video.mp4 and paly it on the screen. and the video can be divided into many images, predict them by model, and finally transfer them to a video.
so that I can show two videos on the screen ,one is original , the other is predicted.

1 Like

Ahh. That is a good question.

Would the source .mp4 be converted before the application is shown? Or would you like to convert the video on the fly?

@Marc
.mp4 file wouldn’t be converted, it keep showing there.
and I want to learn about whether rtsp stream can be accepted.

I’m no expert here. But I think you would be using opencv to read the .mp4 as an iterable of .jpg images. You can then transform the .jpg images and display the before and after image in some Panel PNG panes.

A starting point could be this non Panel code


vidcap = cv2.VideoCapture('big_buck_bunny_720p_5mb.mp4')
success,image = vidcap.read()
count = 0
while success:
  cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file      
  success,image = vidcap.read()
  print('Read a new frame: ', success)
  count += 1
1 Like