一个视频文件的时长有很多种:
- 容器时长
- 流时长
- 文件时长
def get_video_seconds(video_file_path: Path) -> int:
import av
with av.open(str(video_file_path), metadata_encoding='utf-8', metadata_errors='ignore') as container:
stream = container.streams.video[0]
return int(stream.frames/stream.average_rate)