-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoImage.py
44 lines (39 loc) · 1.01 KB
/
VideoImage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from msilib.schema import IniFile
from pydub import AudioSegment
from moviepy.editor import VideoFileClip
import cv2
import sys
import subprocess
import os
def audio(video_file):
# Open the mp4 file
clip = VideoFileClip(video_file)
# Extract the audio from the file
audio = clip.audio
# Save the audio to a new file
audio.write_audiofile("audio.mp3")
def convert(infile):
print(infile)
audio(infile)
out = ".\images"
vidcap = cv2.VideoCapture(infile)
#success,image = vidcap.read()
count = 0
success = True
while success:
success,image = vidcap.read()
try:
cv2.imwrite(out + "\\" + "%d.jpg" % count, image) # save frame as JPEG file
print(f"Saved Image {count}")
except:
print("IMAGE EMPTY")
if cv2.waitKey(10) == 27: # exit if Escape is hit
break
count += 1
def videofps(infile):
vidcap = cv2.VideoCapture(infile)
fps = vidcap.get(cv2.CAP_PROP_FPS)
vidcap.release()
return fps
if __name__ == "__main__":
convert("test.mp4")