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