ivf-0.1.4/.cargo_vcs_info.json0000644000000001410000000000100116160ustar { "git": { "sha1": "1fd67cd1b4a39f69303f28ed27c5d2d3833110c4" }, "path_in_vcs": "ivf" }ivf-0.1.4/CHANGELOG.md000064400000000000000000000001161046102023000122210ustar 00000000000000## Version 0.1.2 - Fix additional clippy lints - Update to Rust Version 2021 ivf-0.1.4/Cargo.lock0000644000000014610000000000100075770ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "bitstream-io" version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a4952b106ee0920c957fc00cf32ddb1e885c5d8beee8f66ab973458129ff5b" dependencies = [ "core2", ] [[package]] name = "core2" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" dependencies = [ "memchr", ] [[package]] name = "ivf" version = "0.1.4" dependencies = [ "bitstream-io", ] [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" ivf-0.1.4/Cargo.toml0000644000000022300000000000100076150ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "ivf" version = "0.1.4" authors = ["Thomas Daede "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Simple ivf muxer" homepage = "https://github.com/xiph/rav1e" readme = false license = "BSD-2-Clause" [lib] name = "ivf" path = "src/lib.rs" [dependencies.bitstream-io] version = "4.1.0" [lints.clippy] comparison_chain = "allow" doc_link_with_quotes = "warn" doc_markdown = "warn" enum_variant_names = "allow" missing_errors_doc = "warn" missing_panics_doc = "warn" missing_safety_doc = "warn" needless_range_loop = "allow" too_many_arguments = "allow" upper_case_acronyms = "allow" ivf-0.1.4/Cargo.toml.orig000064400000000000000000000010341046102023000132770ustar 00000000000000[package] name = "ivf" version = "0.1.4" authors = ["Thomas Daede "] edition = "2021" description = "Simple ivf muxer" license = "BSD-2-Clause" homepage = "https://github.com/xiph/rav1e" [dependencies] bitstream-io = "4.1.0" [lints.clippy] doc_link_with_quotes = "warn" doc_markdown = "warn" missing_errors_doc = "warn" missing_panics_doc = "warn" missing_safety_doc = "warn" comparison_chain = "allow" enum_variant_names = "allow" needless_range_loop = "allow" too_many_arguments = "allow" upper_case_acronyms = "allow" ivf-0.1.4/LICENSE000064400000000000000000000024641046102023000114250ustar 00000000000000BSD 2-Clause License Copyright (c) 2017-2021, the rav1e contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ivf-0.1.4/src/lib.rs000064400000000000000000000105041046102023000123150ustar 00000000000000// Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved // Copyright (c) 2017-2022, The rav1e contributors. All rights reserved // // This source code is subject to the terms of the BSD 2 Clause License and // the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License // was not distributed with this source code in the LICENSE file, you can // obtain it at www.aomedia.org/license/software. If the Alliance for Open // Media Patent License 1.0 was not distributed with this source code in the // PATENTS file, you can obtain it at www.aomedia.org/license/patent. //! Simple ivf muxer use std::io; use bitstream_io::{BitRead, BitReader, BitWrite, BitWriter, LittleEndian}; /// # Panics /// /// - If header cannot be written to output file. pub fn write_ivf_header( output_file: &mut dyn io::Write, width: usize, height: usize, framerate_num: usize, framerate_den: usize, ) { let mut bw = BitWriter::endian(output_file, LittleEndian); bw.write_bytes(b"DKIF").unwrap(); bw.write::<16, _>(0).unwrap(); // version bw.write::<16, _>(32).unwrap(); // version bw.write_bytes(b"AV01").unwrap(); bw.write::<16, _>(width as u16).unwrap(); bw.write::<16, _>(height as u16).unwrap(); bw.write::<32, _>(framerate_num as u32).unwrap(); bw.write::<32, _>(framerate_den as u32).unwrap(); bw.write::<32, _>(0).unwrap(); bw.write::<32, _>(0).unwrap(); } /// # Panics /// /// - If frame cannot be written to output file. pub fn write_ivf_frame( output_file: &mut dyn io::Write, pts: u64, data: &[u8], ) { let mut bw = BitWriter::endian(output_file, LittleEndian); bw.write::<32, _>(data.len() as u32).unwrap(); bw.write::<64, _>(pts).unwrap(); bw.write_bytes(data).unwrap(); } #[derive(Debug, PartialEq, Eq)] pub struct Header { pub tag: [u8; 4], pub w: u16, pub h: u16, pub timebase_num: u32, pub timebase_den: u32, } /// # Errors /// /// - Returns `io::Error` if packet cannot be read /// - Returns `io::ErrorKind::InvalidData` if header signature is invalid pub fn read_header(r: &mut dyn io::Read) -> io::Result
{ let mut br = BitReader::endian(r, LittleEndian); let mut signature = [0u8; 4]; let mut tag = [0u8; 4]; br.read_bytes(&mut signature)?; if &signature != b"DKIF" { return Err(io::ErrorKind::InvalidData.into()); } let _v0: u16 = br.read::<16, _>()?; let _v1: u16 = br.read::<16, _>()?; br.read_bytes(&mut tag)?; let w: u16 = br.read::<16, _>()?; let h: u16 = br.read::<16, _>()?; let timebase_den: u32 = br.read::<32, _>()?; let timebase_num: u32 = br.read::<32, _>()?; let _: u32 = br.read::<32, _>()?; let _: u32 = br.read::<32, _>()?; Ok(Header { tag, w, h, timebase_num, timebase_den }) } pub struct Packet { pub data: Box<[u8]>, pub pts: u64, } /// # Errors /// /// - Returns `io::Error` if packet cannot be read pub fn read_packet(r: &mut dyn io::Read) -> io::Result { let mut br = BitReader::endian(r, LittleEndian); let len: u32 = br.read::<32, _>()?; let pts: u64 = br.read::<64, _>()?; let mut buf = vec![0u8; len as usize]; br.read_bytes(&mut buf)?; Ok(Packet { data: buf.into_boxed_slice(), pts }) } #[cfg(test)] mod tests { use std::io::{BufReader, ErrorKind::InvalidData}; use crate::{read_header, read_packet}; #[test] fn read_invalid_headers() { // Invalid magic. let mut br = BufReader::new(&b"FIKD"[..]); let result = read_header(&mut br).map_err(|e| e.kind()); let expected = Err(InvalidData); assert_eq!(result, expected); } #[test] fn read_valid_headers() { let bytes: [u8; 32] = [ 0x44, 0x4b, 0x49, 0x46, 0x00, 0x00, 0x20, 0x00, 0x41, 0x56, 0x30, 0x31, 0x80, 0x07, 0x38, 0x04, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; let mut br = BufReader::new(&bytes[..]); let header = read_header(&mut br).unwrap(); assert_eq!(header.tag, [0x41, 0x56, 0x30, 0x31]); assert_eq!(header.w, 1920); assert_eq!(header.h, 1080); assert_eq!(header.timebase_num, 1); assert_eq!(header.timebase_den, 24); } #[test] fn read_valid_packet() { let bytes: [u8; 13] = [ 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ]; let mut br = BufReader::new(&bytes[..]); let packet = read_packet(&mut br).unwrap(); assert_eq!(packet.pts, 3u64); } }