#------------------------------------------------------------------------------ #This Python + OpenCV code adjusts the frame rate per second (FPS) of a video. #You can use it to create a video for slow-motion or fast-motion display. Some- #times the FPS of videos need to be equalize to play to side-by-side. The audio #is not preserved and you need to add the audio --- though the audio shall also #should be adjusted to be in synch with the video frames. Output from this code #is same as FFmpeg command: ffmpeg -i in.mp4 -filter:v fps=10 -y out.mp4 #------------------------------------------------------------------------------ import cv2 #Read the input videos and specify name of the output video Vid = "v1.mp4" Out = "newFPS.mp4" newFPS = 10 cap = cv2.VideoCapture(Vid) if (cap.isOpened() == False): print("Error opening the video file, exiting!") exit() h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) size = (int(w), int(h)) fourcc = cv2.VideoWriter_fourcc('m','p','4','v') videowriter = cv2.VideoWriter(Out,fourcc,newFPS,size) while (True): cap.set(cv2.CAP_PROP_FPS, newFPS) ret,frame = cap.read() if ret == True: videowriter.write(frame) else: break cap.release() cv2.destroyAllWindows()