I want resize a video from 1280*720 to 854*480 without changing fps or anything and also want to keep the original audio clip. I am using Jupyter Notebook in Windows 8.1.
Input Video file:
Name - test.mp4
Length - 7min, 41sec
Size - 13.5MB
FPS - 29.97
I used the following code:
import cv2
import numpy as np
cap = cv2.VideoCapture('test.mp4')
fourcc = cv2.VideoWriter_fourcc(*'H264')
out = cv2.VideoWriter('output.mp4',fourcc, 29.97, (854,480))
while True:
ret, frame = cap.read()
if ret == True:
b = cv2.resize(frame,(854,480),fx=0,fy=0, interpolation = cv2.INTER_CUBIC)
out.write(b)
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
But, I get output as 29fps and also there is no audio in output. Also the size of output is 673MB. Please tell some efficient way to do this.
I have tried:
import skvideo.io
videodata = skvideo.io.vread("test.mp4")
print(videodata.shape)
It gives error as:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-46-13276c4b2368> in <module>
----> 1 videodata = skvideo.io.vread("lol.mp4")
2 print(videodata.shape)
C:\Anaconda3\lib\site-packages\skvideo\io\io.py in vread(fname, height, width, num_frames, as_grey, inputdict, outputdict, backend, verbosity)
131 if backend == "ffmpeg":
132 # check if FFMPEG exists in the path
--> 133 assert _HAS_FFMPEG, "Cannot find installation of real FFmpeg (which comes with ffprobe)."
134
135 if ((height != 0) and (width != 0)):
AssertionError: Cannot find installation of real FFmpeg (which comes with ffprobe).
I have tried many ways to install ffmpeg but of no use, nothing works fine for me.
I then tried the following which gives invalid syntax error:
ffmpeg -i test.mp4 -vf scale=640:360 movie_360p.mp4
I also tried:
import subprocess
command = f"ffmpeg -i test.mp4 -vf scale=640:360 movie_360p.mp4"
subprocess.call(command, shell=True)
This gives the following output but does not generate any video
1