def main(args): """Main example""" frame_count = 0 with pyvpl.raw_frame_file_reader_by_name(args.width, args.height, pyvpl.color_format_fourcc.i420, args.input) as source: with open("raw.out", "wb") as sink: opts = pyvpl.properties() opts.api_version = (2, 5) opts.impl = pyvpl.implementation_type.sw sel_default = pyvpl.default_selector(opts) # Load session and initialize decoder params = pyvpl.vpp_video_param() in_frame = pyvpl.frame_info() in_frame.FourCC = pyvpl.color_format_fourcc.i420 in_frame.ChromaFormat = pyvpl.chroma_format_idc.yuv420 in_frame.PicStruct = pyvpl.pic_struct.progressive in_frame.frame_rate = (30, 1) in_frame.ROI = ((0, 0), (args.width, args.height)) in_frame.frame_size = (roundup(args.width, 16), roundup(args.height, 16)) params.in_frame_info = in_frame out_frame = pyvpl.frame_info() out_frame.FourCC = pyvpl.color_format_fourcc.i420 out_frame.ChromaFormat = pyvpl.chroma_format_idc.yuv420 out_frame.PicStruct = pyvpl.pic_struct.progressive out_frame.frame_rate = (30, 1) out_frame.ROI = ((0, 0), (args.dest_width, args.dest_height)) out_frame.frame_size = (roundup(args.dest_width, 16), roundup(args.dest_height, 16)) params.out_frame_info = out_frame params.IOPattern = pyvpl.io_pattern.io_system_memory init_reset_list = pyvpl.vpp_init_reset_list() session = pyvpl.vpp_session(sel_default, source) session.Init(params, init_reset_list) # check and report implementation details version = session.version print(f"{version.Major}.{version.Minor}") verify(version.Major > 1, "Sample requires 2.x API implementation, exiting") impl = session.implementation print(impl) frame_count = 0 for frame in session: frame_count += 1 info, data = frame.map(pyvpl.memory_access.read) try: planes = data.get_planes(info) for plane in planes: sink.write(plane) finally: frame.unmap() print(f"Processed {frame_count} frames")
def main(args): """Main example""" frame_count = 0 with pyvpl.bitstream_file_reader_name(args.input) as source: with open("raw.out", "wb") as sink: opts = pyvpl.properties() opts.api_version = (2, 5) opts.decoder.codec_id = [pyvpl.codec_format_fourcc.hevc] if args.impl == 'sw': opts.impl = pyvpl.implementation_type.sw elif args.impl == 'hw': opts.impl = pyvpl.implementation_type.hw sel_default = pyvpl.default_selector(opts) # Load session and initialize decoder params = pyvpl.decoder_video_param() params.IOPattern = pyvpl.io_pattern.out_system_memory params.CodecId = pyvpl.codec_format_fourcc.hevc decoder = pyvpl.decode_session(sel_default, params, source) # check and report implementation details version = decoder.version print(f"{version.Major}.{version.Minor}") verify(version.Major > 1, "Sample requires 2.x API implementation, exiting") i, v = decoder.implementation print(f"{str(i)} {v}") init_header_list = pyvpl.decoder_init_header_list() init_reset_list = pyvpl.decoder_init_reset_list() decoder.init_by_header(init_header_list, init_reset_list) print(f"Decoding {args.input} -> raw.out") print("Output colorspace: ") fourcc = decoder.Params.frame_info.FourCC print(f" {fourcc}") for frame in decoder: frame_count += 1 info, data = frame.map(pyvpl.memory_access.read) try: planes = data.get_planes(info) for plane in planes: sink.write(plane) finally: frame.unmap() # TODO: debug why we get a segfault if we don't do this. frame = None print(f"Decoded {frame_count} frames")
def test_decode(self): """Test Decode""" frame_count = 0 with pyvpl.bitstream_file_reader_name(HEVC_CLIP) as source: with open("raw.out", "wb") as sink: try: opts = pyvpl.properties() opts.impl = pyvpl.implementation_type.sw opts.api_version = (2, 5) opts.decoder.codec_id = [pyvpl.codec_format_fourcc.hevc] print("") print(str(opts)) sel_default = pyvpl.default_selector(opts) except pyvpl.base_exception as e: print(e) # Load session and initialize decoder params = pyvpl.decoder_video_param() params.IOPattern = pyvpl.io_pattern.out_system_memory params.CodecId = pyvpl.codec_format_fourcc.hevc decoder = pyvpl.decode_session(sel_default, params, source) # check and report implementation details version = decoder.version self.assertGreater( version.Major, 1, "Sample requires 2.x API implementation, exiting") init_header_list = pyvpl.decoder_init_header_list() init_reset_list = pyvpl.decoder_init_reset_list() decoder.init_by_header(init_header_list, init_reset_list) for frame in decoder: frame_count += 1 info, data = frame.map(pyvpl.memory_access.read) try: planes = data.get_planes(info) for plane in planes: sink.write(plane) finally: frame.unmap() # TODO: debug why we get a segfault if we don't do this. frame = None self.assertEqual(frame_count, 30)
def main(args): """Main example""" frame_count = 0 opts = pyvpl.properties() opts.api_version = (2, 5) input_fourcc = pyvpl.color_format_fourcc.i420 if args.impl == 'sw': opts.impl = pyvpl.implementation_type.sw elif args.impl == 'hw': opts.impl = pyvpl.implementation_type.hw input_fourcc = pyvpl.color_format_fourcc.nv12 opts.encoder.enc_profile.enc_mem_desc.color_format = input_fourcc opts.encoder.codec_id = [pyvpl.codec_format_fourcc.hevc] sel_default = pyvpl.default_selector(opts) with pyvpl.raw_frame_file_reader_by_name(args.width, args.height, input_fourcc, args.input) as source: with open("out.h265", "wb") as sink: # Load session and initialize encoder session = pyvpl.encode_session(sel_default, source) params = pyvpl.encoder_video_param() info = pyvpl.frame_info() info.frame_rate = (30, 1) info.frame_size = (roundup(args.width, 16), roundup(args.height, 16)) info.FourCC = input_fourcc info.ChromaFormat = pyvpl.chroma_format_idc.yuv420 info.ROI = ((0, 0), (args.width, args.height)) info.PicStruct = pyvpl.pic_struct.progressive params.RateControlMethod = pyvpl.rate_control_method.cqp params.frame_info = info params.CodecId = pyvpl.codec_format_fourcc.hevc params.IOPattern = pyvpl.io_pattern.in_system_memory # Getting VAAPI handle not supported in Python sample init_list = pyvpl.encoder_init_list() try: session.Init(params, init_list) except pyvpl.base_exception as e: print(f"Encoder init failed: {e}") return -1 print(str(info)) print("Init done") print(f"Encoding {args.input} -> out.h265") # check and report implementation details version = session.version verify(version.Major > 1, "Sample requires 2.x API implementation, exiting") for bits in session: # frame_count += 1 frame_count += 1 sink.write(bits) print(f"Encoded {frame_count} frames") print("") print("-- Encode information --") print("") print(session.working_params()) return 0