Cut into video image video image synthesizing + + Python

python programming, cut into a video image, the video image resynthesis

. A cut into the video image:

import cv2  
import os
vidcap = cv2.VideoCapture('./video/7.mp4')  
success,image = vidcap.read()  
count = 0  
success = True  
savedir='./f3/'

if  not os.path.exists(savedir):
    os.mkdir(savedir)
while success:  
  success,image = vidcap.read()  
  cv2.imwrite(savedir+"7frame%d.jpg" % count, image)     # save frame as JPEG file  
  if cv2.waitKey(10) == 27:                       
      break  
  count += 1  

num=len(os.listdir(savedir))-1
os.remove(savedir+"7frame%d.jpg" % num)

Note:

1, './video/7.mp4' into your video plus path name

2, the './f3/' images are stored into your path

3, "7frame% d.jpg" represents the name of each image frame. The first frame image, here named "7frame1.jpg", you can replace your favorite name

4, the following sentence, commented or keep, depending on whether the visual with your last image in my line of work, the last image of an open, direct use of the following sentence to the last image deleted

num = membrane (os.listdir (This means)) - 1 
os.remove (exactly constitutes + " 7frame% D.jpg " % num)

. B video image combining:

#!/usr/bin/env python
# -*-coding:utf-8-*-
import cv2
import os

fsp = 20
fourcc = cv2.VideoWriter_fourcc(*'avc1')
video_path = './hecheng.mp4' 
video_out = cv2.VideoWriter(video_path, fourcc, fsp, (1280,720)) 

img_path = "./f3/" 
for i in range(0,1200):
     if os.path.exists(img_path+"7frame"+str(i)+'.jpg'):
          frame = cv2.imread(img_path+"7frame"+str(i)+'.jpg')
          video_out.write(frame)
video_out.release()

Note:

1, fsp represents frame rate, ie the number of images to play one second.

     Come playback (fast-forward a similar effect), fsp big set point.

     Play slowly (similar slow-motion effect), fsp set up a small point.  

2, './hecheng.mp4' name into what you want.

3, (1280,720) indicates the size of each frame image. Specifically, as shown:

4, img_path = "./f3/" path to the image is stored. That you will be synthesized video image under "./f3/" path

5, (0,1200), the 1200 is a number equal to the number must be greater than "./f3/" image of the path. 0 fixed.

6, "7frame" + str (i) + '. Jpg' represents an image name. And FIG cutting time consistent naming images.

 

Guess you like

Origin www.cnblogs.com/wjjcjj/p/12340494.html