Commit fce17a24 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato

Add a function to produce a container-compatible sequence header

parent e8186fdf
...@@ -140,6 +140,36 @@ impl Context { ...@@ -140,6 +140,36 @@ impl Context {
Ok(()) Ok(())
} }
pub fn container_sequence_header(&mut self) -> Vec<u8> {
use bitstream_io::*;
use std::io;
fn sequence_header_inner(seq: &Sequence) -> io::Result<Vec<u8>> {
let mut buf = Vec::new();
{
let mut bw = BitWriter::endian(&mut buf, BigEndian);
bw.write_bit(true)?; // marker
bw.write(7, 1)?; // version
bw.write(3, seq.profile)?;
bw.write(5, 32)?; // level
bw.write_bit(false)?; // tier
bw.write_bit(seq.bit_depth > 8)?; // high_bitdepth
bw.write_bit(seq.bit_depth == 12)?; // twelve_bit
bw.write_bit(seq.bit_depth == 1)?; // monochrome
bw.write_bit(seq.bit_depth == 12)?; // twelve_bit
bw.write_bit(seq.chroma_sampling != ChromaSampling::Cs444)?; // chroma_subsampling_x
bw.write_bit(seq.chroma_sampling == ChromaSampling::Cs420)?; // chroma_subsampling_y
bw.write(2, 0)?; // sample_position
bw.write(3, 0)?; // reserved
bw.write_bit(false)?; // initial_presentation_delay_present
bw.write(4, 0)?; // reserved
}
Ok(buf)
}
sequence_header_inner(&self.seq).unwrap()
}
pub fn receive_packet(&mut self) -> Result<Packet, EncoderStatus> { pub fn receive_packet(&mut self) -> Result<Packet, EncoderStatus> {
let f = self.frame_q.pop_front().ok_or(EncoderStatus::NeedMoreData)?; let f = self.frame_q.pop_front().ok_or(EncoderStatus::NeedMoreData)?;
if let Some(frame) = f { if let Some(frame) = f {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment