You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.6KB

  1. import subprocess as sp
  2. from PIL import Image
  3. import time
  4. import cv2
  5. import oss2
  6. import numpy as np
  7. # 推流
  8. if __name__== "__main__":
  9. cap = cv2.VideoCapture("/home/DATA/chenyukun/DJI_20211229100908_0001_S.mp4")
  10. # Get video information
  11. fps = int(cap.get(cv2.CAP_PROP_FPS))
  12. print(fps)
  13. width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
  14. print(width)
  15. height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
  16. print(height)
  17. # ffmpeg command
  18. command = ['/usr/bin/ffmpeg',
  19. '-y', # 不经过确认,输出时直接覆盖同名文件。
  20. '-f', 'rawvideo',
  21. '-vcodec', 'rawvideo',
  22. '-pix_fmt', 'bgr24',
  23. # '-s', "{}x{}".format(self.width * 2, self.height),
  24. '-s', "{}x{}".format(width, height),
  25. '-r', str(15),
  26. '-i', '-', # 指定输入文件
  27. '-g', '25',
  28. '-b:v', '3000k',
  29. '-c:v', 'libx264', # 指定视频编码器
  30. '-pix_fmt', 'yuv420p',
  31. '-preset', 'ultrafast', # 指定输出的视频质量,会影响文件的生成速度,有以下几个可用的值 ultrafast,
  32. # superfast, veryfast, faster, fast, medium, slow, slower, veryslow。
  33. '-f', 'flv',
  34. "rtmp://live.push.t-aaron.com/live/THSAe"]
  35. # 管道配置
  36. p = sp.Popen(command, stdin=sp.PIPE, shell=False)
  37. while(cap.isOpened()):
  38. ret, frame = cap.read()
  39. if not ret:
  40. print("Opening camera is failed")
  41. break
  42. time.sleep(0.03)
  43. p.stdin.write(frame.tostring())