Exemplo n.º 1
0
    def test_audio_buffer_volume_filter(self):
        graph = Graph()
        self.link_nodes(
            graph.add_abuffer(
                format="fltp",
                sample_rate=48000,
                layout="stereo",
                time_base=Fraction(1, 48000),
            ),
            graph.add("volume", volume="0.5"),
            graph.add("abuffersink"),
        )
        graph.configure()

        input_frame = generate_audio_frame(0,
                                           input_format="fltp",
                                           layout="stereo",
                                           sample_rate=48000)
        graph.push(input_frame)

        out_frame = graph.pull()
        self.assertEqual(out_frame.format.name, "fltp")
        self.assertEqual(out_frame.layout.name, "stereo")
        self.assertEqual(out_frame.sample_rate, 48000)

        input_data = input_frame.to_ndarray()
        output_data = out_frame.to_ndarray()

        self.assertTrue(np.allclose(input_data * 0.5, output_data),
                        "Check that volume is reduced")
Exemplo n.º 2
0
    def test_audio_buffer_resample(self):
        graph = Graph()
        self.link_nodes(
            graph.add_abuffer(
                format="fltp",
                sample_rate=48000,
                layout="stereo",
                time_base=Fraction(1, 48000),
            ),
            graph.add(
                "aformat",
                "sample_fmts=s16:sample_rates=44100:channel_layouts=stereo"),
            graph.add("abuffersink"),
        )
        graph.configure()

        graph.push(
            generate_audio_frame(0,
                                 input_format="fltp",
                                 layout="stereo",
                                 sample_rate=48000))
        out_frame = graph.pull()
        self.assertEqual(out_frame.format.name, "s16")
        self.assertEqual(out_frame.layout.name, "stereo")
        self.assertEqual(out_frame.sample_rate, 44100)
Exemplo n.º 3
0
    def test_delegate_sink(self):

        graph = Graph()
        src = graph.add('testsrc')
        src.link_to(graph.add('buffersink'))
        graph.configure()

        print(src.outputs)
        
        frame = src.pull()
        frame.to_image().save('sandbox/mandelbrot4.png')
Exemplo n.º 4
0
    def test_delegate_sink(self):

        graph = Graph()
        src = graph.add('testsrc')
        src.link_to(graph.add('buffersink'))
        graph.configure()

        frame = src.pull()

        if Image:
            frame.to_image().save(self.sandboxed('mandelbrot4.png'))
Exemplo n.º 5
0
    def test_haldclut_graph(self):

        raise SkipTest()

        graph = Graph()

        img = Image.open(fate_suite("png1/lena-rgb24.png"))
        frame = VideoFrame.from_image(img)
        img_source = graph.add_buffer(frame)

        hald_img = Image.open("hald_7.png")
        hald_frame = VideoFrame.from_image(hald_img)
        hald_source = graph.add_buffer(hald_frame)

        hald_filter = graph.add("haldclut")

        sink = graph.add("buffersink")

        img_source.link(0, hald_filter, 0)
        hald_source.link(0, hald_filter, 1)
        hald_filter.link(0, sink, 0)
        graph.config()

        self.assertIs(img_source.outputs[0].linked_to, hald_filter.inputs[0])
        self.assertIs(hald_source.outputs[0].linked_to, hald_filter.inputs[1])
        self.assertIs(hald_filter.outputs[0].linked_to, sink.inputs[0])

        hald_source.push(hald_frame)

        img_source.push(frame)

        frame = sink.pull()
        self.assertIsInstance(frame, VideoFrame)
        frame.to_image().save(self.sandboxed("filtered.png"))
Exemplo n.º 6
0
 def test_generator_graph(self):
     
     graph = Graph()
     src = graph.add('testsrc')
     lutrgb = graph.add('lutrgb', "r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val", name='invert')
     sink = graph.add('buffersink')
     src.link_to(lutrgb)
     lutrgb.link_to(sink)
     
     # pads and links
     self.assertIs(src.outputs[0].link.output, lutrgb.inputs[0])
     self.assertIs(lutrgb.inputs[0].link.input, src.outputs[0])
     
     frame = sink.pull()
     self.assertIsInstance(frame, VideoFrame)
     frame.to_image().save('sandbox/mandelbrot2.png')
Exemplo n.º 7
0
 def test_generator_graph(self):
     
     graph = Graph()
     src = graph.add('testsrc')
     lutrgb = graph.add('lutrgb', "r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val", name='invert')
     sink = graph.add('buffersink')
     src.link_to(lutrgb)
     lutrgb.link_to(sink)
     
     # pads and links
     self.assertIs(src.outputs[0].link.output, lutrgb.inputs[0])
     self.assertIs(lutrgb.inputs[0].link.input, src.outputs[0])
     
     frame = sink.pull()
     self.assertIsInstance(frame, VideoFrame)
     frame.to_image().save('sandbox/mandelbrot2.png')
Exemplo n.º 8
0
    def test_auto_find_sink(self):

        graph = Graph()
        src = graph.add('testsrc')
        src.link_to(graph.add('buffersink'))
        graph.configure()

        frame = graph.pull()
        frame.to_image().save('sandbox/mandelbrot3.png')
Exemplo n.º 9
0
    def test_auto_find_sink(self):

        graph = Graph()
        src = graph.add("testsrc")
        src.link_to(graph.add("buffersink"))
        graph.configure()

        frame = graph.pull()

        if Image:
            frame.to_image().save(self.sandboxed("mandelbrot3.png"))
Exemplo n.º 10
0
    def test_generator_graph(self):

        graph = Graph()
        src = graph.add("testsrc")
        lutrgb = graph.add(
            "lutrgb",
            "r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val",
            name="invert",
        )
        sink = graph.add("buffersink")
        src.link_to(lutrgb)
        lutrgb.link_to(sink)

        # pads and links
        self.assertIs(src.outputs[0].link.output, lutrgb.inputs[0])
        self.assertIs(lutrgb.inputs[0].link.input, src.outputs[0])

        frame = sink.pull()
        self.assertIsInstance(frame, VideoFrame)

        if Image:
            frame.to_image().save(self.sandboxed("mandelbrot2.png"))
Exemplo n.º 11
0
    def test_auto_find_sink(self):

        graph = Graph()
        src = graph.add('testsrc')
        src.link_to(graph.add('buffersink'))
        graph.configure()

        frame = graph.pull()
        frame.to_image().save('sandbox/mandelbrot3.png')
Exemplo n.º 12
0
    def test_audio_buffer_sink(self):
        graph = Graph()
        audio_buffer = graph.add_abuffer(
            format="fltp",
            sample_rate=48000,
            layout="stereo",
            time_base=Fraction(1, 48000),
        )
        audio_buffer.link_to(graph.add("abuffersink"))
        graph.configure()

        try:
            graph.pull()
        except OSError as e:
            # we haven't pushed any input so expect no frames / EAGAIN
            if e.errno != errno.EAGAIN:
                raise
Exemplo n.º 13
0
    def test_delegate_sink(self):

        graph = Graph()
        src = graph.add('testsrc')
        src.link_to(graph.add('buffersink'))
        graph.configure()

        frame = src.pull()

        if Image:
            frame.to_image().save(self.sandboxed('mandelbrot4.png'))
Exemplo n.º 14
0
    def test_delegate_sink(self):

        graph = Graph()
        src = graph.add('testsrc')
        src.link_to(graph.add('buffersink'))
        graph.configure()

        print src.outputs
        
        frame = src.pull()
        frame.to_image().save('sandbox/mandelbrot4.png')
Exemplo n.º 15
0
    def test_haldclut_graph(self):
        
        raise SkipTest()

        graph = Graph()
        
        img = Image.open(fate_suite('png1/lena-rgb24.png'))
        frame = VideoFrame.from_image(img)
        img_source = graph.add_buffer(frame)
        
        hald_img = Image.open('hald_7.png')
        hald_frame = VideoFrame.from_image(hald_img)
        hald_source = graph.add_buffer(hald_frame)
        
        try:
            hald_filter = graph.add('haldclut')
        except ValueError:
            # Not in Libav.
            raise SkipTest()

        sink = graph.add('buffersink')
        
        img_source.link(0, hald_filter, 0)
        hald_source.link(0, hald_filter, 1)
        hald_filter.link(0, sink, 0)
        graph.config()
        
        self.assertIs(img_source.outputs[0].linked_to, hald_filter.inputs[0])
        self.assertIs(hald_source.outputs[0].linked_to, hald_filter.inputs[1])
        self.assertIs(hald_filter.outputs[0].linked_to, sink.inputs[0])
        
        hald_source.push(hald_frame)
        
        img_source.push(frame)
        
        frame = sink.pull()
        self.assertIsInstance(frame, VideoFrame)
        frame.to_image().save('sandbox/filtered.png')
        
Exemplo n.º 16
0
    def test_haldclut_graph(self):
        
        raise SkipTest()

        graph = Graph()
        
        img = Image.open(fate_suite('png1/lena-rgb24.png'))
        frame = VideoFrame.from_image(img)
        img_source = graph.add_buffer(frame)
        
        hald_img = Image.open('hald_7.png')
        hald_frame = VideoFrame.from_image(hald_img)
        hald_source = graph.add_buffer(hald_frame)
        
        try:
            hald_filter = graph.add('haldclut')
        except ValueError:
            # Not in Libav.
            raise SkipTest()

        sink = graph.add('buffersink')
        
        img_source.link(0, hald_filter, 0)
        hald_source.link(0, hald_filter, 1)
        hald_filter.link(0, sink, 0)
        graph.config()
        
        self.assertIs(img_source.outputs[0].linked_to, hald_filter.inputs[0])
        self.assertIs(hald_source.outputs[0].linked_to, hald_filter.inputs[1])
        self.assertIs(hald_filter.outputs[0].linked_to, sink.inputs[0])
        
        hald_source.push(hald_frame)
        
        img_source.push(frame)
        
        frame = sink.pull()
        self.assertIsInstance(frame, VideoFrame)
        frame.to_image().save('sandbox/filtered.png')