Skip to content

Commit d8898c6

Browse files
committed
Support max_width/max_height options.
Fixes #2467
1 parent c200bc2 commit d8898c6

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

src/api/config/encoder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub struct EncoderConfig {
2929
pub width: usize,
3030
/// Height of the frames in pixels.
3131
pub height: usize,
32+
/// Maximum width of the frames in pixels (for seq header)
33+
pub max_width: usize,
34+
/// Maximum height of the frames in pixels (for seq header)
35+
pub max_height: usize,
3236
/// Video time base.
3337
pub time_base: Rational,
3438

@@ -129,7 +133,8 @@ impl EncoderConfig {
129133
EncoderConfig {
130134
width: 640,
131135
height: 480,
132-
136+
max_width: 0,
137+
max_height: 0,
133138
bit_depth: 8,
134139
chroma_sampling: ChromaSampling::Cs420,
135140
chroma_sample_position: ChromaSamplePosition::Unknown,

src/bin/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ fn parse_config(matches: &ArgMatches<'_>) -> Result<EncoderConfig, CliError> {
655655
cfg.tile_cols = matches.value_of("TILE_COLS").unwrap().parse().unwrap();
656656
cfg.tile_rows = matches.value_of("TILE_ROWS").unwrap().parse().unwrap();
657657

658+
cfg.max_width = matches.value_of("MAX_WIDTH").unwrap().parse().unwrap();
659+
cfg.max_height = matches.value_of("MAX_HEIGHT").unwrap().parse().unwrap();
660+
658661
cfg.tiles = matches.value_of("TILES").unwrap().parse().unwrap();
659662

660663
if cfg.tile_cols > 64 || cfg.tile_rows > 64 {

src/capi.rs

+6
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ unsafe fn option_match(
632632
match key {
633633
"width" => enc.width = check_frame_size(value.parse().map_err(|_| ()))?,
634634
"height" => enc.height = check_frame_size(value.parse().map_err(|_| ()))?,
635+
"max_width" => {
636+
enc.max_width = check_frame_size(value.parse().map_err(|_| ()))?
637+
}
638+
"max_height" => {
639+
enc.max_heightheight = check_frame_size(value.parse().map_err(|_| ()))?
640+
}
635641
"speed" => {
636642
enc.speed_settings =
637643
rav1e::SpeedSettings::from_preset(value.parse().map_err(|_| ())?)

src/encoder.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ pub struct Sequence {
182182

183183
impl Sequence {
184184
pub fn new(config: &EncoderConfig) -> Sequence {
185-
let width_bits = 32 - (config.width as u32).leading_zeros();
186-
let height_bits = 32 - (config.height as u32).leading_zeros();
185+
let max_width =
186+
if config.max_width > 0 { config.max_width } else { config.width };
187+
let max_height =
188+
if config.max_height > 0 { config.max_height } else { config.height };
189+
let width_bits = 32 - (max_width as u32).leading_zeros();
190+
let height_bits = 32 - (max_height as u32).leading_zeros();
187191
assert!(width_bits <= 16);
188192
assert!(height_bits <= 16);
189193

@@ -223,8 +227,8 @@ impl Sequence {
223227
color_description: config.color_description,
224228
mastering_display: config.mastering_display,
225229
content_light: config.content_light,
226-
max_frame_width: config.width as u32,
227-
max_frame_height: config.height as u32,
230+
max_frame_width: config.max_width as u32,
231+
max_frame_height: config.max_height as u32,
228232
frame_id_numbers_present_flag: false,
229233
frame_id_length: FRAME_ID_LENGTH,
230234
delta_frame_id_length: DELTA_FRAME_ID_LENGTH,

src/header.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
868868
fn write_frame_size<T: Pixel>(
869869
&mut self, fi: &FrameInvariants<T>,
870870
) -> io::Result<()> {
871-
// width_bits and height_bits will have to be moved to the sequence header OBU
872-
// when we add support for it.
873-
let width_bits = 32 - (fi.width as u32).leading_zeros();
874-
let height_bits = 32 - (fi.height as u32).leading_zeros();
871+
let width_bits = fi.sequence.num_bits_width;
872+
let height_bits = fi.sequence.num_bits_height;
875873
assert!(width_bits <= 16);
876874
assert!(height_bits <= 16);
877875
self.write(4, width_bits - 1)?;
@@ -884,10 +882,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
884882
fn write_frame_size_override<T: Pixel>(
885883
&mut self, fi: &FrameInvariants<T>,
886884
) -> io::Result<()> {
887-
// width_bits and height_bits will have to be moved to the sequence header OBU
888-
// when we add support for it.
889-
let width_bits = 32 - (fi.width as u32).leading_zeros();
890-
let height_bits = 32 - (fi.height as u32).leading_zeros();
885+
let width_bits = fi.sequence.num_bits_width;
886+
let height_bits = fi.sequence.num_bits_height;
891887
assert!(width_bits <= 16);
892888
assert!(height_bits <= 16);
893889
self.write(width_bits, (fi.width - 1) as u16)?;

0 commit comments

Comments
 (0)