コード例 #1
0
    def roundtrip_video(self, codec, width, height):
        """
        Round-trip a VideoFrame through encoder then decoder.
        """
        encoder = get_encoder(codec)
        decoder = get_decoder(codec)

        for timestamp in range(0, 90000, 3000):
            # encode
            frame = VideoFrame(width=width, height=height)
            frame.pts = timestamp
            frame.time_base = VIDEO_TIME_BASE
            packages, timestamp = encoder.encode(frame)

            # depacketize
            data = b''
            for package in packages:
                data += depayload(codec, package)

            # decode
            frames = decoder.decode(JitterFrame(data=data, timestamp=timestamp))
            self.assertEqual(len(frames), 1)
            self.assertEqual(frames[0].width, width)
            self.assertEqual(frames[0].height, height)
            self.assertEqual(frames[0].pts, timestamp)
            self.assertEqual(frames[0].time_base, VIDEO_TIME_BASE)
コード例 #2
0
 def create_video_frames(self,
                         width,
                         height,
                         count,
                         time_base=VIDEO_TIME_BASE):
     frames = []
     for i in range(count):
         frame = VideoFrame(width=width, height=height)
         frame.pts = int(i / time_base / 30)
         frame.time_base = time_base
         frames.append(frame)
     return frames
コード例 #3
0
    def roundtrip_video(self, codec, width, height):
        """
        Round-trip a VideoFrame through encoder then decoder.
        """
        encoder = get_encoder(codec)
        decoder = get_decoder(codec)

        # encode
        frame = VideoFrame(width=width, height=height)
        packages = encoder.encode(frame)

        # depacketize
        data = b''
        for package in packages:
            data += depayload(codec, package)

        # decode
        frames = decoder.decode(data)
        self.assertEqual(len(frames), 1)
        self.assertEqual(frames[0].width, width)
        self.assertEqual(frames[0].height, height)
コード例 #4
0
ファイル: server.py プロジェクト: shrinivdeshmukh/aiortc
    async def recv(self):
        frame = await self.received.get()

        self.counter += 1
        if (self.counter % 100) > 50:
            # apply image processing to frame
            if self.transform == 'edges':
                img = frame_to_bgr(frame)
                edges = cv2.Canny(img, 100, 200)
                return frame_from_gray(edges)
            elif self.transform == 'rotate':
                img = frame_to_bgr(frame)
                rows, cols, _ = img.shape
                M = cv2.getRotationMatrix2D((cols / 2, rows / 2), self.counter * 7.2, 1)
                rotated = cv2.warpAffine(img, M, (cols, rows))
                return frame_from_bgr(rotated)
            elif self.transform == 'green':
                return VideoFrame(width=frame.width, height=frame.height)
            else:
                return frame
        else:
            # return raw frame
            return frame
コード例 #5
0
 def test_frame_to_bgr(self):
     frame = VideoFrame(width=640, height=480)
     image = frame_to_bgr(frame)
     self.assertEqual(image.shape, (480, 640, 3))
コード例 #6
0
 def test_video_no_time_base(self):
     frame = VideoFrame(width=640, height=480)
     frame.pts = 9000
     self.assertEqual(frame.time, None)
コード例 #7
0
 def test_video_no_pts(self):
     frame = VideoFrame(width=640, height=480)
     frame.time_base = fractions.Fraction(1, 90000)
     self.assertEqual(frame.time, None)
コード例 #8
0
 def test_video(self):
     frame = VideoFrame(width=640, height=480)
     frame.pts = 9000
     frame.time_base = fractions.Fraction(1, 90000)
     self.assertEqual(frame.time, 0.1)
コード例 #9
0
 def test_video_frame_to_bgr(self):
     frame = VideoFrame(width=640, height=480, timestamp=123)
     image = video_frame_to_bgr(frame)
     self.assertEqual(image.shape, (480, 640, 3))