Skip to content

Commit

Permalink
Support max_width/max_height options.
Browse files Browse the repository at this point in the history
Fixes #2467
  • Loading branch information
tdaede committed Aug 10, 2020
1 parent c200bc2 commit d8898c6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/api/config/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub struct EncoderConfig {
pub width: usize,
/// Height of the frames in pixels.
pub height: usize,
/// Maximum width of the frames in pixels (for seq header)
pub max_width: usize,
/// Maximum height of the frames in pixels (for seq header)
pub max_height: usize,
/// Video time base.
pub time_base: Rational,

Expand Down Expand Up @@ -129,7 +133,8 @@ impl EncoderConfig {
EncoderConfig {
width: 640,
height: 480,

max_width: 0,
max_height: 0,
bit_depth: 8,
chroma_sampling: ChromaSampling::Cs420,
chroma_sample_position: ChromaSamplePosition::Unknown,
Expand Down
3 changes: 3 additions & 0 deletions src/bin/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ fn parse_config(matches: &ArgMatches<'_>) -> Result<EncoderConfig, CliError> {
cfg.tile_cols = matches.value_of("TILE_COLS").unwrap().parse().unwrap();
cfg.tile_rows = matches.value_of("TILE_ROWS").unwrap().parse().unwrap();

cfg.max_width = matches.value_of("MAX_WIDTH").unwrap().parse().unwrap();
cfg.max_height = matches.value_of("MAX_HEIGHT").unwrap().parse().unwrap();

cfg.tiles = matches.value_of("TILES").unwrap().parse().unwrap();

if cfg.tile_cols > 64 || cfg.tile_rows > 64 {
Expand Down
6 changes: 6 additions & 0 deletions src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,12 @@ unsafe fn option_match(
match key {
"width" => enc.width = check_frame_size(value.parse().map_err(|_| ()))?,
"height" => enc.height = check_frame_size(value.parse().map_err(|_| ()))?,
"max_width" => {
enc.max_width = check_frame_size(value.parse().map_err(|_| ()))?
}
"max_height" => {
enc.max_heightheight = check_frame_size(value.parse().map_err(|_| ()))?
}
"speed" => {
enc.speed_settings =
rav1e::SpeedSettings::from_preset(value.parse().map_err(|_| ())?)
Expand Down
12 changes: 8 additions & 4 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,12 @@ pub struct Sequence {

impl Sequence {
pub fn new(config: &EncoderConfig) -> Sequence {
let width_bits = 32 - (config.width as u32).leading_zeros();
let height_bits = 32 - (config.height as u32).leading_zeros();
let max_width =
if config.max_width > 0 { config.max_width } else { config.width };
let max_height =
if config.max_height > 0 { config.max_height } else { config.height };
let width_bits = 32 - (max_width as u32).leading_zeros();
let height_bits = 32 - (max_height as u32).leading_zeros();
assert!(width_bits <= 16);
assert!(height_bits <= 16);

Expand Down Expand Up @@ -223,8 +227,8 @@ impl Sequence {
color_description: config.color_description,
mastering_display: config.mastering_display,
content_light: config.content_light,
max_frame_width: config.width as u32,
max_frame_height: config.height as u32,
max_frame_width: config.max_width as u32,
max_frame_height: config.max_height as u32,
frame_id_numbers_present_flag: false,
frame_id_length: FRAME_ID_LENGTH,
delta_frame_id_length: DELTA_FRAME_ID_LENGTH,
Expand Down
12 changes: 4 additions & 8 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
fn write_frame_size<T: Pixel>(
&mut self, fi: &FrameInvariants<T>,
) -> io::Result<()> {
// width_bits and height_bits will have to be moved to the sequence header OBU
// when we add support for it.
let width_bits = 32 - (fi.width as u32).leading_zeros();
let height_bits = 32 - (fi.height as u32).leading_zeros();
let width_bits = fi.sequence.num_bits_width;
let height_bits = fi.sequence.num_bits_height;
assert!(width_bits <= 16);
assert!(height_bits <= 16);
self.write(4, width_bits - 1)?;
Expand All @@ -884,10 +882,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
fn write_frame_size_override<T: Pixel>(
&mut self, fi: &FrameInvariants<T>,
) -> io::Result<()> {
// width_bits and height_bits will have to be moved to the sequence header OBU
// when we add support for it.
let width_bits = 32 - (fi.width as u32).leading_zeros();
let height_bits = 32 - (fi.height as u32).leading_zeros();
let width_bits = fi.sequence.num_bits_width;
let height_bits = fi.sequence.num_bits_height;
assert!(width_bits <= 16);
assert!(height_bits <= 16);
self.write(width_bits, (fi.width - 1) as u16)?;
Expand Down

0 comments on commit d8898c6

Please sign in to comment.