I'm trying to create a control that will allow a user to create clips of a video. The modeling for a clip contains a Uri to the video and a start/end TimeSpan:
public class ClipModel
{
public Uri Source { get; }
public TimeSpan Start{ get; }
public TimeSpan End { get; }
}
I want to display a preview of all clips in a control, but my implementation has performance issues. I believe this is because I create a MediaElement for each clip, which forces the file to be loaded many times. I expect to have dozens of clips for a given video, so loading a video file ~20 times really tanks performance.
The xaml for all that is:
<ScrollViewer Grid.Row="3" Padding="0,20,0,0" Background="White" FocusVisualStyle="{x:Null}"
HorizontalScrollBarVisibility="Visible">
<ItemsControl x:Name="Clips">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:ClipModel}">
<MediaElement Source="{Binding VideoPath}"
helpers:MediaElementHelper.Position="{Binding Start}"
ScrubbingEnabled="True"
LoadedBehavior="Pause"
Height="50"
Width="100"
Margin="5"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
Is there a better control for viewing a single frame from a video which won't tank performance when there are many of them?
The model allows for many clips to come from different video files. However, there will generally be many clips for a single video, rather than from many different videos.
Given that, perhaps a better question would be: is there some way I can load a video into memory once, and use that single Stream/byte[] across many MediaElements to get all the thumbnails?