Exemplo n.º 1
0
    def test_encoder_large(self):
        encoder = get_encoder(VP8_CODEC)
        self.assertTrue(isinstance(encoder, Vp8Encoder))

        # first keyframe
        frame = VideoFrame(width=2560, height=1920)
        frame.pts = 0
        frame.time_base = VIDEO_TIME_BASE
        payloads, timestamp = encoder.encode(frame)
        self.assertEqual(len(payloads), 7)
        self.assertEqual(len(payloads[0]), 1300)
        self.assertEqual(timestamp, 0)

        # delta frame
        frame = VideoFrame(width=2560, height=1920)
        frame.pts = 3000
        frame.time_base = VIDEO_TIME_BASE
        payloads, timestamp = encoder.encode(frame)
        self.assertEqual(len(payloads), 1)
        self.assertTrue(len(payloads[0]) < 1300)
        self.assertEqual(timestamp, 3000)

        # force keyframe
        frame = VideoFrame(width=2560, height=1920)
        frame.pts = 6000
        frame.time_base = VIDEO_TIME_BASE
        payloads, timestamp = encoder.encode(frame, force_keyframe=True)
        self.assertEqual(len(payloads), 7)
        self.assertEqual(len(payloads[0]), 1300)
        self.assertEqual(timestamp, 6000)
Exemplo n.º 2
0
    def test_frame_encoder(self):
        encoder = get_encoder(H264_CODEC)

        frame = VideoFrame(width=640, height=480)
        frame.pts = 0
        frame.time_base = VIDEO_TIME_BASE
        packages = list(encoder._encode_frame(frame, False))

        self.assertGreaterEqual(len(packages), 3)
        # first frame must have at least
        set(p[0] & 0x1f for p in packages).issuperset({
            8,  # PPS (picture parameter set)
            7,  # SPS (session parameter set)
            5,  # IDR (aka key frame)
        })

        frame = VideoFrame(width=640, height=480)
        frame.pts = 3000
        frame.time_base = VIDEO_TIME_BASE
        packages = list(encoder._encode_frame(frame, False))
        self.assertGreaterEqual(len(packages), 1)

        # change resolution
        frame = VideoFrame(width=320, height=240)
        frame.pts = 6000
        frame.time_base = VIDEO_TIME_BASE
        packages = list(encoder._encode_frame(frame, False))
        self.assertGreaterEqual(len(packages), 1)
Exemplo n.º 3
0
    def test_encoder(self):
        encoder = get_encoder(H264_CODEC)
        self.assertTrue(isinstance(encoder, H264Encoder))

        frame = VideoFrame(width=640, height=480)
        frame.pts = 0
        frame.time_base = VIDEO_TIME_BASE
        packages, timestamp = encoder.encode(frame)
        self.assertGreaterEqual(len(packages), 1)
Exemplo n.º 4
0
    def test_encoder(self):
        encoder = get_encoder(VP8_CODEC)
        self.assertTrue(isinstance(encoder, Vp8Encoder))

        frame = VideoFrame(width=640, height=480)
        frame.pts = 0
        frame.time_base = VIDEO_TIME_BASE
        payloads, timestamp = encoder.encode(frame)
        self.assertEqual(len(payloads), 1)
        self.assertTrue(len(payloads[0]) < 1300)
        self.assertEqual(timestamp, 0)

        # change resolution
        frame = VideoFrame(width=320, height=240)
        frame.pts = 3000
        frame.time_base = VIDEO_TIME_BASE
        payloads, timestamp = encoder.encode(frame)
        self.assertEqual(len(payloads), 1)
        self.assertTrue(len(payloads[0]) < 1300)
        self.assertEqual(timestamp, 3000)