0

我正在使用一个 api,我可以在其中请求视频的每一帧。我正在尝试将所有帧加载到我的 c# 应用程序中并将其作为视频播放,并且能够浏览每一帧。

我想知道是否有合适的库可以使这变得更快和更高效。

我尝试将所有 1500 帧加载到一个文件夹中,然后将它们读回我的应用程序,但是下载图像需要很长时间才能播放视频。

WPF:

<Image Source="{Binding Path=ImageSource}"/>

<StackPanel Grid.Row="1"  Orientation="Horizontal">
    <Button Content="Play" Command="{Binding PlayCommand}"/>
    <Button Content="Pause" Command="{Binding StopCommand}"/>

    <Slider Name="mcSlider" Width="234" Height="20"  
            Background="Gray" Maximum="100" Minimum="0" Margin="0,2,0,1" Value="{Binding ImageIndex}">
    </Slider>
</StackPanel>

C#:

void Play()
{
    timer = new SmartDispatcherTimer()
    {
        IsReentrant = false,
        Interval = TimeSpan.FromSeconds(1f / 120f),
        TickTask = async () => { await PlayBack(); }
    };

    timer.Start();
}

private async Task PlayBack()
{
    NextFrame();

    await GetData("54000", _imageIndex, _entry, _imageIndex);
    var fullFilePath = Directory.GetCurrentDirectory() + @"\preview\output" + _imageIndex + ".jpg";

    //Create a new bitmap to assign our image to
    BitmapImage bitmap = new BitmapImage();
    bitmap.BeginInit();
    bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
    bitmap.CacheOption = BitmapCacheOption.None;
    bitmap.UriSource = new Uri(fullFilePath, UriKind.RelativeOrAbsolute);
    bitmap.EndInit();

    ImagesArray.Add(bitmap);
}

上面的代码是我目前正在尝试的,但是每帧的下载跟不上播放的需求。

是否有一个库可以让我的视频播放器流畅运行?

4

0 回答 0