目录
moviepy 和opencv
import cv2
from moviepy.editor import VideoFileClip
video_path=r"E:\project\jijia\mp4_zhuanchang\bvItEnpaNcs.mp4"
# 加载视频文件
video = VideoFileClip(video_path)
# 获取视频长度(以秒为单位)
video_length = video.duration
video = cv2.VideoCapture(video_path)
count = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
v_fps=video.get(cv2.CAP_PROP_FPS)
print(f"v_fps: {v_fps} fps")
print(f"视频长度: {video_length*v_fps} fps",count)
opencv
from decord import VideoReader
sys.path.insert(0, '/home/model-server/dev/data_platform/processors')
from aesthetic import get_aesthetic_model, get_aesthetic_score_batch_queue
from mytools.utils import print_with_timestamp as print
from mytools.utils import sleep_for_test
def get_video_length(video_path):
cap = cv2.VideoCapture(video_path)
frame_count=0
if cap.isOpened():
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
cap.release()
vreader = VideoReader(video_path)
video_length = len(vreader)
return min(video_length, frame_count)