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.
42 lines
1.1 KiB
42 lines
1.1 KiB
3 years ago
|
import time
|
||
|
from datetime import datetime
|
||
|
|
||
|
import av
|
||
|
from PIL import Image
|
||
|
from av.frame import Fraction
|
||
|
from PIL import Image, ImageDraw, ImageFont
|
||
|
|
||
|
from StreamMerger import StreamMerger
|
||
|
from VideoFile import VideoFile
|
||
|
|
||
|
container = av.open('rtmp://localhost/live', mode='w', format='flv')
|
||
|
stream = container.add_stream('h264', framerate=60) # alibi frame rate
|
||
|
output_audio_stream = container.add_stream('aac', rate=44100)
|
||
|
|
||
|
stream.width = 1920
|
||
|
stream.height = 1080
|
||
|
stream.pix_fmt = 'yuv420p'
|
||
|
# stream.bit_rate = 128000
|
||
|
stream.time_base = Fraction(1, 60)
|
||
|
|
||
|
st = StreamMerger()
|
||
|
st.start()
|
||
|
my_pts = 0 # [seconds]
|
||
|
frame_i = 0
|
||
|
time_start = time.time()
|
||
|
while True:
|
||
|
if st.img is not None:
|
||
|
frame = av.VideoFrame.from_image(st.img)
|
||
|
framen = frame.reformat(format='yuv420p')
|
||
|
|
||
|
ntime = time.time() - time_start
|
||
|
|
||
|
frame.pts = ntime * 60
|
||
|
frame.time_base = Fraction(1, 60)
|
||
|
# frame.key_frame = frame_i
|
||
|
frame_i += 1
|
||
|
# print(dir(frame))
|
||
|
for packet in stream.encode(framen):
|
||
|
container.mux(packet)
|
||
|
time.sleep(1.0 / 60.0)
|