1 use nihav_core::muxers::*;
4 bw: &'a mut ByteWriter<'a>,
7 impl<'a> Y4MMuxer<'a> {
8 fn new(bw: &'a mut ByteWriter<'a>) -> Self {
15 fn get_format_name(fmt: NAPixelFormaton) -> MuxerResult<&'static str> {
16 if fmt.model.is_yuv() && fmt.get_max_depth() == 8 {
17 match fmt.components {
20 let uinfo = fmt.comp_info[1].unwrap();
21 let vinfo = fmt.comp_info[2].unwrap();
22 if uinfo.h_ss != vinfo.h_ss || uinfo.v_ss != vinfo.v_ss {
23 return Err(MuxerError::UnsupportedFormat);
25 match (uinfo.h_ss, vinfo.v_ss) {
30 _ => Err(MuxerError::UnsupportedFormat),
33 _ => Err(MuxerError::UnsupportedFormat),
36 Err(MuxerError::UnsupportedFormat)
40 impl<'a> MuxCore<'a> for Y4MMuxer<'a> {
41 fn create(&mut self, strmgr: &StreamManager) -> MuxerResult<()> {
42 if strmgr.get_num_streams() != 1 {
43 return Err(MuxerError::InvalidArgument);
45 let vstr = strmgr.get_stream(0).unwrap();
46 if vstr.get_media_type() != StreamType::Video {
47 return Err(MuxerError::UnsupportedFormat);
49 let info = vstr.get_info();
50 let vinfo = info.get_properties().get_video_info().unwrap();
51 self.bw.write_buf(format!("YUV4MPEG2 W{} H{} F{}:{} C{}\n", vinfo.width, vinfo.height, vstr.tb_den, vstr.tb_num, get_format_name(vinfo.format)?).as_bytes())?;
55 fn mux_frame(&mut self, _strmgr: &StreamManager, pkt: NAPacket) -> MuxerResult<()> {
56 if self.bw.tell() == 0 {
57 return Err(MuxerError::NotCreated);
59 let src = pkt.get_buffer();
60 self.bw.write_buf(b"FRAME\n")?;
61 self.bw.write_buf(&src)?;
64 fn flush(&mut self) -> MuxerResult<()> {
67 fn end(&mut self) -> MuxerResult<()> {
72 impl<'a> NAOptionHandler for Y4MMuxer<'a> {
73 fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
74 fn set_options(&mut self, _options: &[NAOption]) { }
75 fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
78 pub struct Y4MMuxerCreator {}
80 impl MuxerCreator for Y4MMuxerCreator {
81 fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
82 Box::new(Y4MMuxer::new(bw))
84 fn get_name(&self) -> &'static str { "yuv4mpeg" }
85 fn get_capabilities(&self) -> MuxerCapabilities { MuxerCapabilities::SingleVideo("rawvideo") }
90 use nihav_core::codecs::*;
91 use nihav_core::demuxers::*;
92 use nihav_core::muxers::*;
93 use nihav_codec_support::test::enc_video::*;
98 let mut dmx_reg = RegisteredDemuxers::new();
99 generic_register_all_demuxers(&mut dmx_reg);
100 // sample: self-created with avconv
101 let dec_config = DecoderTestParams {
103 in_name: "assets/Misc/test.y4m",
105 stream_type: StreamType::None,
106 dmx_reg, dec_reg: RegisteredDecoders::new(),
108 let mut mux_reg = RegisteredMuxers::new();
109 generic_register_all_muxers(&mut mux_reg);
110 /*let enc_config = EncoderTestParams {
113 out_name: "muxed.y4m",
114 mux_reg, enc_reg: RegisteredEncoders::new(),
116 test_remuxing(&dec_config, &enc_config);*/
117 test_remuxing_md5(&dec_config, "yuv4mpeg", &mux_reg,
118 [0x7586c1c5, 0x388209b8, 0xe08af8f8, 0x4b6b96c7]);