12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- # -*- coding: utf-8 -*-
- # @Author: wangkun
- # @Time: 2022/7/12
- import shutil
- import ffmpeg
- class Demo:
- # 获取已下载视频宽高、时长等信息
- @classmethod
- def get_video_info_from_local(cls, video_path):
- probe = ffmpeg.probe(video_path)
- # print('video_path: {}'.format(video_path))
- # format1 = probe['format']
- # bit_rate = int(format1['bit_rate']) / 1000
- # duration = format['duration']
- # size = int(format1['size']) / 1024 / 1024
- video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
- if video_stream is None:
- print('No video stream found!')
- return
- width = int(video_stream['width'])
- height = int(video_stream['height'])
- # num_frames = int(video_stream['nb_frames'])
- # fps = int(video_stream['r_frame_rate'].split('/')[0]) / int(video_stream['r_frame_rate'].split('/')[1])
- duration = float(video_stream['duration'])
- # print('width: {}'.format(width))
- # print('height: {}'.format(height))
- # print('num_frames: {}'.format(num_frames))
- # print('bit_rate: {}k'.format(bit_rate))
- # print('fps: {}'.format(fps))
- # print('size: {}MB'.format(size))
- # print('duration: {}'.format(duration))
- return width, height, duration
- # 判断视频时长是否大于 60s
- @classmethod
- def check_duration(cls):
- # 获取视频时长
- video_info = cls.get_video_info_from_local("../videos/11111/video.mp4")
- video_duration = video_info[2]
- if int(video_duration) < 60:
- shutil.rmtree("../videos/11111/")
- else:
- print(f"video_duration:{video_duration}")
- # 判断 title 长度
- @classmethod
- def check_title_len(cls):
- title = "🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看"[:30]
- # print(len(title))
- # if len(title) > 30:
- # title = title[:30]
- print(title)
- print(len(title))
- if __name__ == "__main__":
- demo = Demo()
- # demo.check_duration()
- demo.check_title_len()
|