Created
October 26, 2021 21:36
-
-
Save bmsan/62e96ec6b50e87ecb7eb18d8828c4448 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fractions | |
from aiortc.contrib.media import MediaRecorder | |
from aiortc.mediastreams import MediaStreamError | |
class MediaRecorderFixed30FPS(MediaRecorder): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.video_frame_ctr = {} | |
def addTrack(self, track): | |
super().addTrack(track) | |
if track.kind == "video": | |
self.video_frame_ctr[track.id] = 0 | |
async def __run_track(self, track, context): | |
while True: | |
try: | |
frame = await track.recv() | |
if track.kind == 'video': | |
frame.pts = self.video_frame_ctr[track.id] | |
frame.time_base = fractions.Fraction(1, 30) | |
self.frame_ctr[track.id] += 1 | |
except MediaStreamError: | |
return | |
for packet in context.stream.encode(frame): | |
self.__container.mux(packet) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment