[vlc-commits] [Git][videolan/vlc][3.0.x] 3 commits: demux: mkv: apply the stretching of visible area after cropping

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Mon Jun 29 09:03:21 UTC 2026



Felix Paul Kühne pushed to branch 3.0.x at VideoLAN / VLC


Commits:
e667b835 by Steve Lhomme at 2026-06-29T10:29:21+02:00
demux: mkv: apply the stretching of visible area after cropping

We can also apply the pixel cropping no matter what, if the value is 0 it will
have no side effect.

Ref. #26501

(cherry picked from commit 32f4a9925b1c1ab4ff156b129cc369116d6f08da) (rebased)
rebased:
* the surrounding code was slightly different

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
7d978d15 by Steve Lhomme at 2026-06-29T10:29:21+02:00
demux: mkv: set the video format SAR based on the DisplayUnit of the track

We can apply the SAR once we know the cropped pixels dimensions and the actual
display dimension requested.

Apply the DAR when DisplayUnit is 3 [1].

[1] https://www.ietf.org/archive/id/draft-ietf-cellar-matroska-08.html#name-displayunit-element

(cherry picked from commit cc4faf0c2c4ca3950872501abf5e027569923939)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
1a29dce2 by Steve Lhomme at 2026-06-29T10:29:21+02:00
demux: mkv: set the default display width/height when DisplayUnit is 0

As specified in the format [1].

> If the DisplayUnit of the same TrackEntry is 0, then the default value for
> DisplayWidth is equal toPixelWidth - PixelCropLeft - PixelCropRight,
> else there is no default value.

[1] https://www.ietf.org/archive/id/draft-ietf-cellar-matroska-08.html#section-8.1.4.1.31.11

(cherry picked from commit 267cf709fb0b31716ff558c7e739b2e8d9ba09d6)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -


1 changed file:

- modules/demux/mkv/matroska_segment_parse.cpp


Changes:

=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -503,28 +503,70 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
             unsigned int i_crop_bottom = vars.track_video_info.i_crop_bottom;
             unsigned int i_crop_left   = vars.track_video_info.i_crop_left;
 
-            unsigned int i_display_unit   = vars.track_video_info.i_display_unit; VLC_UNUSED(i_display_unit);
+            unsigned int i_display_unit   = vars.track_video_info.i_display_unit;
             unsigned int i_display_width  = vars.track_video_info.i_display_width;
             unsigned int i_display_height = vars.track_video_info.i_display_height;
 
-            if( i_display_height && i_display_width )
+            unsigned int h_crop;
+            if (!add_overflow(i_crop_left, i_crop_right, &h_crop))
             {
-                tk->fmt.video.i_sar_num = i_display_width  * tk->fmt.video.i_height;
-                tk->fmt.video.i_sar_den = i_display_height * tk->fmt.video.i_width;
+                debug( vars, "invalid horizontal crop %u+%u",
+                              i_crop_left, i_crop_right );
+                i_crop_left = i_crop_right = 0;
             }
+            else if (unlikely(h_crop >= tk->fmt.video.i_width))
+            {
+                debug( vars, "Horizontal crop (left=%u, right=%u) "
+                             "greater than the picture width (%u)",
+                              i_crop_left, i_crop_right, tk->fmt.video.i_width );
+                i_crop_left = i_crop_right = 0;
+            }
+
+            unsigned int v_crop;
+            if (!add_overflow(i_crop_top, i_crop_bottom, &v_crop))
+            {
+                debug( vars, "invalid vertical crop %u+%u",
+                              i_crop_top, i_crop_bottom);
+                i_crop_top = i_crop_bottom = 0;
+            }
+            if (unlikely(v_crop >= tk->fmt.video.i_height))
+            {
+                debug( vars, "Vertical crop (top=%u, bottom=%u) "
+                             "greater than the picture height (%u)",
+                              i_crop_top, i_crop_bottom, tk->fmt.video.i_height );
+                i_crop_top = i_crop_bottom = 0;
+            }
+
+            tk->fmt.video.i_x_offset      = i_crop_left;
+            tk->fmt.video.i_y_offset      = i_crop_top;
+            tk->fmt.video.i_visible_width = tk->fmt.video.i_width -
+                                            (i_crop_left + i_crop_right);
+            tk->fmt.video.i_visible_height = tk->fmt.video.i_height -
+                                            (i_crop_top + i_crop_bottom);
 
-            tk->fmt.video.i_visible_width   = tk->fmt.video.i_width;
-            tk->fmt.video.i_visible_height  = tk->fmt.video.i_height;
+            if (i_display_unit == 0 && i_display_width == 0)
+                i_display_width = tk->fmt.video.i_width;
+            if (i_display_unit == 0 && i_display_height == 0)
+                i_display_height = tk->fmt.video.i_height;
 
-            if( i_crop_left || i_crop_right || i_crop_top || i_crop_bottom )
+            if (i_display_height && i_display_width)
             {
-                tk->fmt.video.i_x_offset        = i_crop_left;
-                tk->fmt.video.i_y_offset        = i_crop_top;
-                tk->fmt.video.i_visible_width  -= i_crop_left + i_crop_right;
-                tk->fmt.video.i_visible_height -= i_crop_top + i_crop_bottom;
+                switch (i_display_unit)
+                {
+                    case 0: // pixels
+                    case 1: // centimeters
+                    case 2: // inches
+                        vlc_ureduce( &tk->fmt.video.i_sar_num, &tk->fmt.video.i_sar_den,
+                                     i_display_width * tk->fmt.video.i_visible_height,
+                                     i_display_height * tk->fmt.video.i_visible_width, 0);
+                        break;
+                    case 3: // display aspect ratio
+                        vlc_ureduce( &tk->fmt.video.i_sar_num, &tk->fmt.video.i_sar_den,
+                                     i_display_height * tk->fmt.video.i_visible_width,
+                                     i_display_width * tk->fmt.video.i_visible_height, 0);
+                        break;
+                }
             }
-            /* FIXME: i_display_* allows you to not only set DAR, but also a zoom factor.
-               we do not support this atm */
         }
 #if LIBMATROSKA_VERSION >= 0x010406
         E_CASE( KaxVideoProjection, proj )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ccc644b4aedccfbce28e6bc99ad7fec15b8f7d43...1a29dce2291685d907addcffc36cc9d518f20c82

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ccc644b4aedccfbce28e6bc99ad7fec15b8f7d43...1a29dce2291685d907addcffc36cc9d518f20c82
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