demo.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/7/12
  4. import shutil
  5. import ffmpeg
  6. class Demo:
  7. # 获取已下载视频宽高、时长等信息
  8. @classmethod
  9. def get_video_info_from_local(cls, video_path):
  10. probe = ffmpeg.probe(video_path)
  11. # print('video_path: {}'.format(video_path))
  12. # format1 = probe['format']
  13. # bit_rate = int(format1['bit_rate']) / 1000
  14. # duration = format['duration']
  15. # size = int(format1['size']) / 1024 / 1024
  16. video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
  17. if video_stream is None:
  18. print('No video stream found!')
  19. return
  20. width = int(video_stream['width'])
  21. height = int(video_stream['height'])
  22. # num_frames = int(video_stream['nb_frames'])
  23. # fps = int(video_stream['r_frame_rate'].split('/')[0]) / int(video_stream['r_frame_rate'].split('/')[1])
  24. duration = float(video_stream['duration'])
  25. # print('width: {}'.format(width))
  26. # print('height: {}'.format(height))
  27. # print('num_frames: {}'.format(num_frames))
  28. # print('bit_rate: {}k'.format(bit_rate))
  29. # print('fps: {}'.format(fps))
  30. # print('size: {}MB'.format(size))
  31. # print('duration: {}'.format(duration))
  32. return width, height, duration
  33. # 判断视频时长是否大于 60s
  34. @classmethod
  35. def check_duration(cls):
  36. # 获取视频时长
  37. video_info = cls.get_video_info_from_local("../videos/11111/video.mp4")
  38. video_duration = video_info[2]
  39. if int(video_duration) < 60:
  40. shutil.rmtree("../videos/11111/")
  41. else:
  42. print(f"video_duration:{video_duration}")
  43. # 判断 title 长度
  44. @classmethod
  45. def check_title_len(cls):
  46. title = "🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看🌸这首《老公赚钱给老婆花》🌸被唱的太肉麻了🌸好听好看"[:30]
  47. # print(len(title))
  48. # if len(title) > 30:
  49. # title = title[:30]
  50. print(title)
  51. print(len(title))
  52. if __name__ == "__main__":
  53. demo = Demo()
  54. # demo.check_duration()
  55. demo.check_title_len()