Encode Timecodes into WebM stub
This commit is contained in:
parent
120fe26b6b
commit
b76f244022
3 changed files with 14 additions and 0 deletions
|
@ -10,6 +10,10 @@ pub fn main() {
|
|||
encode_webm_element(WebmElement::Segment, &mut cursor).unwrap();
|
||||
|
||||
encode_webm_element(WebmElement::Cluster, &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::Timecode(0), &mut cursor).unwrap();
|
||||
|
||||
encode_webm_element(WebmElement::Cluster, &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::Timecode(1000), &mut cursor).unwrap();
|
||||
|
||||
stdout().write_all(&cursor.get_ref()).unwrap();
|
||||
}
|
||||
|
|
|
@ -202,6 +202,15 @@ pub fn encode_string<T: Write>(tag: u64, string: &str, output: &mut T) -> IoResu
|
|||
encode_tag_header(tag, Varint::Value(string.len() as u64), output)?;
|
||||
output.write_all(string.as_ref())
|
||||
}
|
||||
|
||||
/// Tries to write a simple EBML tag with an integer value
|
||||
pub fn encode_integer<T: Write>(tag: u64, value: u64, output: &mut T) -> IoResult<()> {
|
||||
encode_tag_header(tag, Varint::Value(8), output)?;
|
||||
|
||||
let mut buffer = Cursor::new([0; 8]);
|
||||
buffer.put_u64::<BigEndian>(value);
|
||||
|
||||
output.write_all(&buffer.get_ref()[..])
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
|
|
@ -89,6 +89,7 @@ pub fn encode_webm_element<T: Write + Seek>(element: WebmElement, output: &mut T
|
|||
WebmElement::SeekHead => Ok(()),
|
||||
WebmElement::Cues => Ok(()),
|
||||
WebmElement::Cluster => encode_tag_header(CLUSTER_ID, Varint::Unknown, output),
|
||||
WebmElement::Timecode(time) => encode_integer(TIMECODE_ID, time, output),
|
||||
_ => Err(IoError::new(ErrorKind::InvalidInput, WriteError::OutOfRange))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue