How to use the av.AudioFormat function in av

To help you get started, we’ve selected a few av examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikeboers / PyAV / tests / test_codec.py View on Github external
def test_codec_opus_encoder(self):
        c = Codec('opus', 'w')
        self.assertIn(c.name, ('opus', 'libopus'))
        self.assertIn(c.long_name, ('Opus', 'libopus Opus'))
        self.assertEqual(c.type, 'audio')
        self.assertTrue(c.is_encoder)
        self.assertFalse(c.is_decoder)

        # audio
        formats = c.audio_formats
        self.assertTrue(formats)
        self.assertIsInstance(formats[0], AudioFormat)
        self.assertTrue(any(f.name in ['flt', 'fltp'] for f in formats))

        self.assertIsNotNone(c.audio_rates)
        self.assertIn(48000, c.audio_rates)

        # video
        self.assertIsNone(c.video_formats)
        self.assertIsNone(c.frame_rates)
github mikeboers / PyAV / tests / test_audioformat.py View on Github external
def test_s16_inspection(self):
        fmt = AudioFormat('s16')
        self.assertEqual(fmt.name, 's16')
        self.assertFalse(fmt.is_planar)
        self.assertEqual(fmt.bits, 16)
        self.assertEqual(fmt.bytes, 2)
        self.assertEqual(fmt.container_name, 's16' + postfix)
        self.assertEqual(fmt.planar.name, 's16p')
        self.assertIs(fmt.packed, fmt)
github mikeboers / PyAV / tests / test_audioformat.py View on Github external
def test_s32p_inspection(self):
        fmt = AudioFormat('s32p')
        self.assertEqual(fmt.name, 's32p')
        self.assertTrue(fmt.is_planar)
        self.assertEqual(fmt.bits, 32)
        self.assertEqual(fmt.bytes, 4)
        self.assertRaises(ValueError, lambda: fmt.container_name)
github mikeboers / PyAV / scratchpad / audio.py View on Github external
arg_parser.add_argument('-d', '--data', action='store_true')
arg_parser.add_argument('-f', '--format')
arg_parser.add_argument('-l', '--layout')
arg_parser.add_argument('-r', '--rate', type=int)
arg_parser.add_argument('-s', '--size', type=int, default=1024)
arg_parser.add_argument('-c', '--count', type=int, default=5)
args = arg_parser.parse_args()

ffplay = None

container = av.open(args.path)
stream = next(s for s in container.streams if s.type == 'audio')

fifo = av.AudioFifo() if args.size else None
resampler = av.AudioResampler(
    format=av.AudioFormat(args.format or stream.format.name).packed if args.format else None,
    layout=int(args.layout) if args.layout and args.layout.isdigit() else args.layout,
    rate=args.rate,
) if (args.format or args.layout or args.rate) else None

read_count = 0
fifo_count = 0
sample_count = 0

for i, packet in enumerate(container.demux(stream)):

    for frame in packet.decode():

        read_count += 1
        print('>>>> %04d' % read_count, frame)
        if args.data:
            print_data(frame)
github mikeboers / PyAV / scratchpad / audio_player.py View on Github external
from qtproxy import Q

import av


parser = argparse.ArgumentParser()
parser.add_argument('path')
args = parser.parse_args()

container = av.open(args.path)
stream = next(s for s in container.streams if s.type == 'audio')

fifo = av.AudioFifo()
resampler = av.AudioResampler(
    format=av.AudioFormat('s16').packed,
    layout='stereo',
    rate=48000,
)



qformat = Q.AudioFormat()
qformat.setByteOrder(Q.AudioFormat.LittleEndian)
qformat.setChannelCount(2)
qformat.setCodec('audio/pcm')
qformat.setSampleRate(48000)
qformat.setSampleSize(16)
qformat.setSampleType(Q.AudioFormat.SignedInt)

output = Q.AudioOutput(qformat)
output.setBufferSize(2 * 2 * 48000)