|
13 | 13 |
|
14 | 14 | try: |
15 | 15 | import av |
16 | | - import cv2 |
17 | 16 | except ImportError: |
18 | 17 | raise RuntimeError( |
19 | | - "av and opencv-python is required to run this example, install with `pip install av opencv-python`" |
| 18 | + "av is required to run this example, install with `pip install av`" |
20 | 19 | ) |
21 | 20 |
|
22 | 21 | # ensure LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET are set |
@@ -52,32 +51,18 @@ def __init__(self, media_file: Union[str, Path]) -> None: |
52 | 51 | audio_sample_rate=audio_stream.sample_rate, |
53 | 52 | audio_channels=audio_stream.channels, |
54 | 53 | ) |
55 | | - print(self._info) |
56 | 54 |
|
57 | 55 | @property |
58 | 56 | def info(self) -> MediaInfo: |
59 | 57 | return self._info |
60 | 58 |
|
61 | | - async def stream_video( |
62 | | - self, av_sync: rtc.AVSynchronizer |
63 | | - ) -> AsyncIterable[tuple[rtc.VideoFrame, float]]: |
| 59 | + async def stream_video(self) -> AsyncIterable[tuple[rtc.VideoFrame, float]]: |
64 | 60 | """Streams video frames from the media file in an endless loop.""" |
65 | 61 | for i, av_frame in enumerate(self._video_container.decode(video=0)): |
66 | 62 | # Convert video frame to RGBA |
67 | 63 | frame = av_frame.to_rgb().to_ndarray() |
68 | 64 | frame_rgba = np.ones((frame.shape[0], frame.shape[1], 4), dtype=np.uint8) |
69 | 65 | frame_rgba[:, :, :3] = frame |
70 | | - |
71 | | - # put fps and timestamps in the frame |
72 | | - frame_rgba = cv2.putText( |
73 | | - frame_rgba, f"{av_sync.actual_fps:.2f}fps", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2 |
74 | | - ) |
75 | | - |
76 | | - if i % 10 == 0: |
77 | | - print( |
78 | | - f"decoded frame {i} ({av_frame.time:.3f}s), {av_sync.actual_fps:.2f}fps, " |
79 | | - f"last video time: {av_sync.last_video_time:.3f}s, last audio time: {av_sync.last_audio_time:.3f}s" |
80 | | - ) |
81 | 66 | yield ( |
82 | 67 | rtc.VideoFrame( |
83 | 68 | width=frame.shape[1], |
@@ -190,7 +175,7 @@ async def _push_frames( |
190 | 175 | while True: |
191 | 176 | streamer.reset() |
192 | 177 | video_task = asyncio.create_task( |
193 | | - _push_frames(streamer.stream_video(av_sync), av_sync) |
| 178 | + _push_frames(streamer.stream_video(), av_sync) |
194 | 179 | ) |
195 | 180 | audio_task = asyncio.create_task( |
196 | 181 | _push_frames(streamer.stream_audio(), av_sync) |
|
0 commit comments