[vlc-commits] [Git][videolan/vlc][master] 5 commits: packetizer: h264: explicitly set crop to 0 when frame_cropping_flag is 0
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed May 20 02:09:02 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
5fd6c06b by Steve Lhomme at 2026-05-20T01:55:41+00:00
packetizer: h264: explicitly set crop to 0 when frame_cropping_flag is 0
As per the H.264 specs:
> When frame_cropping_flag is equal to 0, the values of frame_crop_left_offset,
> frame_crop_right_offset, frame_crop_top_offset, and frame_crop_bottom_offset
> shall be inferred to be equal to 0.
- - - - -
82d7d12b by Steve Lhomme at 2026-05-20T01:55:41+00:00
packetizer: h264: only set dimensions+crop if valid
Otherwise we keep the previous values.
- - - - -
c688141a by Steve Lhomme at 2026-05-20T01:55:41+00:00
packetizer: h264: check the crop values are valid
- - - - -
c20103ac by Steve Lhomme at 2026-05-20T01:55:41+00:00
packetizer: h264: check potential integer overflow when computing offsets
- - - - -
2375b90c by Steve Lhomme at 2026-05-20T01:55:41+00:00
packetizer: h264: get closer to the specs
A minus1 is usually added 1.
- - - - -
2 changed files:
- modules/packetizer/h264.c
- modules/packetizer/h264_nal.c
Changes:
=====================================
modules/packetizer/h264.c
=====================================
@@ -211,13 +211,19 @@ static void ActivateSets( decoder_t *p_dec, const h264_sequence_parameter_set_t
p_dec->fmt_out.i_level = pl[1];
}
- (void) h264_get_picture_size( p_sps,
- &p_dec->fmt_out.video.i_x_offset,
- &p_dec->fmt_out.video.i_y_offset,
- &p_dec->fmt_out.video.i_width,
- &p_dec->fmt_out.video.i_height,
- &p_dec->fmt_out.video.i_visible_width,
- &p_dec->fmt_out.video.i_visible_height );
+ unsigned x_offset, y_offset, width, height, visible_width, visible_height;
+ if( h264_get_picture_size( p_sps,
+ &x_offset, &y_offset,
+ &width, &height,
+ &visible_width, &visible_height ) )
+ {
+ p_dec->fmt_out.video.i_x_offset = x_offset;
+ p_dec->fmt_out.video.i_y_offset = y_offset;
+ p_dec->fmt_out.video.i_width = width;
+ p_dec->fmt_out.video.i_height = height;
+ p_dec->fmt_out.video.i_visible_width = visible_width;
+ p_dec->fmt_out.video.i_visible_height = visible_height;
+ }
h264_get_aspect_ratio( p_sps,
&p_dec->fmt_out.video.i_sar_num,
@@ -1255,4 +1261,3 @@ static bool ParseSeiCallback( const hxxx_sei_data_t *p_sei_data, void *cbdata )
return true;
}
-
=====================================
modules/packetizer/h264_nal.c
=====================================
@@ -32,6 +32,7 @@
#include <vlc_boxes.h>
#include <vlc_es.h>
#include <limits.h>
+#include <stdckdint.h>
/* H264 Level limits from Table A-1 */
typedef struct
@@ -418,6 +419,13 @@ static bool h264_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
p_sps->frame_crop.top_offset = bs_read_ue( p_bs );
p_sps->frame_crop.bottom_offset = bs_read_ue( p_bs );
}
+ else
+ {
+ p_sps->frame_crop.left_offset = 0;
+ p_sps->frame_crop.right_offset = 0;
+ p_sps->frame_crop.top_offset = 0;
+ p_sps->frame_crop.bottom_offset = 0;
+ }
/* vui */
p_sps->vui_parameters_present_flag = bs_read( p_bs, 1 );
@@ -925,14 +933,25 @@ bool h264_get_picture_size( const h264_sequence_parameter_set_t *p_sps,
}
}
- *p_w = 16 * p_sps->pic_width_in_mbs_minus1 + 16;
- *p_h = 16 * p_sps->pic_height_in_map_units_minus1 + 16;
+ *p_w = 16 * (p_sps->pic_width_in_mbs_minus1 + 1);
+ *p_h = 16 * (p_sps->pic_height_in_map_units_minus1 + 1);
*p_h *= ( 2 - p_sps->frame_mbs_only_flag );
- *p_ox = p_sps->frame_crop.left_offset * CropUnitX;
- *p_oy = p_sps->frame_crop.top_offset * CropUnitY;
- *p_vw = *p_w - ( p_sps->frame_crop.left_offset + p_sps->frame_crop.right_offset ) * CropUnitX;
- *p_vh = *p_h - ( p_sps->frame_crop.bottom_offset + p_sps->frame_crop.top_offset ) * CropUnitY;
+ unsigned offset_w, offset_h;
+ if( ckd_add( &offset_w, p_sps->frame_crop.left_offset, p_sps->frame_crop.right_offset ) ||
+ ckd_mul( &offset_w, CropUnitX, offset_w ) ||
+ ckd_mul( p_ox, CropUnitX, p_sps->frame_crop.left_offset ) )
+ return false;
+ if( ckd_add( &offset_h, p_sps->frame_crop.bottom_offset, p_sps->frame_crop.top_offset ) ||
+ ckd_mul( &offset_h, CropUnitY, offset_h ) ||
+ ckd_mul( p_oy, CropUnitY, p_sps->frame_crop.top_offset ) )
+ return false;
+ if( *p_w < offset_w )
+ return false;
+ if( *p_h < offset_h )
+ return false;
+ *p_vw = *p_w - offset_w;
+ *p_vh = *p_h - offset_h;
return true;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d179ce4ffa63dbdee36a097ff502f2434ec54531...2375b90cc670dcf81faf7973308f5f8e1424c16b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d179ce4ffa63dbdee36a097ff502f2434ec54531...2375b90cc670dcf81faf7973308f5f8e1424c16b
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list