FFmpegInteropX icon indicating copy to clipboard operation
FFmpegInteropX copied to clipboard

Video/Screen Frame Padding for Subtitle Display

Open softworkz opened this issue 2 years ago • 5 comments
trafficstars

Hi,

do you have any way to set a padding at the screen or video frame level?

We have two values in our config which allow to set a minimum distance from the top and from the bottom for subtitle areas, so when the bottom value is 5%, no subtitles will be shown in that bottom 5% area.

Any idea how I can achieve this? (easily would be good - LOL)

Thanks, sw

softworkz avatar Nov 21 '23 00:11 softworkz

Hi, You can achieve this by modifying the MPE control template. Subtitles are displayed in a Grid named "TimedTextSourcePresenter" that's zindexed above the video presenter. You can set margins to this grid and obtain what you want.

brabebhin avatar Nov 21 '23 07:11 brabebhin

Thanks a lot for the pointer, I'll try this now.

softworkz avatar Nov 23 '23 19:11 softworkz

Oh yeah, on winui 3 you will probably be blocked by https://github.com/microsoft/microsoft-ui-xaml/issues/8973

Lovely, isn't it? but it should work for UWP.

brabebhin avatar Nov 28 '23 20:11 brabebhin

Lovely, isn't it?

Despicable...

but it should work for UWP.

That's the more important one. For Windows (i.e. non-xbox) we'll probably use mpv player anyway, but I'm targeting implementation for FFmpegInteropX as well, so we have two options available.

softworkz avatar Nov 28 '23 20:11 softworkz

So this can actually be solved without subclassing the MediaPlayerElement. If you locally override the style of the MediaPlayerElement, you can change the template in place

<MediaPlayerElement.Style>
     <Style TargetType="MediaPlayerElement">
         <Setter Property="HorizontalAlignment" Value="Stretch"/>
         <Setter Property="VerticalAlignment" Value="Stretch"/>
         <Setter Property="IsTabStop" Value="False"/>
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="MediaPlayerElement">
                     <Grid x:Name="LayoutRoot">
                         <Border Background="Transparent"/>
                         <MediaPlayerPresenter x:Name="MediaPlayerPresenter" IsFullWindow="{TemplateBinding IsFullWindow}" MediaPlayer="{TemplateBinding MediaPlayer}" Stretch="{TemplateBinding Stretch}"/>
                         <Image x:Name="PosterImage" Stretch="{TemplateBinding Stretch}" Source="{TemplateBinding PosterSource}" Visibility="Visible"/>

                         <ContentPresenter x:Name="TransportControlsPresenter" Visibility="{TemplateBinding AreTransportControlsEnabled}"/>
                         <Grid x:Name="TimedTextSourcePresenter"/>

                     </Grid>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>
 </MediaPlayerElement.Style>

You can then technically bind the TimedTextSourcePresenter to apply your padding.

brabebhin avatar Jan 28 '24 20:01 brabebhin