unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.17k stars 240 forks source link

System.AccessViolationException when Loading WebM files #527

Closed nevaran closed 3 years ago

nevaran commented 3 years ago

At random times when opening Webm files, there is a big chance of crashing the app with a memory access violation. Certain Webm files also (for unknown reasons) will not load at all and straight up crash the app 100% of the time. There is also a (probably) unrelated bug where when the media is loaded (gifs, mainly) it will not always start playing even if .Play() is added in events that get called when it is successfully loaded.


Update: It would seem it can also crash after a webm is loaded and then you proceed to load anything else using the library (seems to happen randomly, not always on the first load)

Update 2: The access violations also happen when opening gifs. I am unsure if its library-related or something wrong with my code, but loading them straight from ffplay seems to work flawlessly

Update 3: Source code's error is in the MediaInfo.ExtractStreams @ line 131; code var dar = s->display_aspect_ratio; This crash also happens with the sample project provided in the git repo (by swapping media)

Update 4: The crashes seem to be happening only on newest ffmpeg builds, oldest build in the git repo (Oct 1st) seems to be working fine: Auto-Build 2020-09-30 23:26 But everything after it, the crash occurs.

image

Example file for testing: http://streams.videolan.org/samples/vp8_webm/big-buck-bunny_trailer.webm (or any other webm)

Issue Categories

Version Information

Expected Results

Sample Code

XAML

<MainWindow>
<ffme:MediaElement
                                x:Name="MediaView"
                                Background="Transparent"
                                Focusable="False"
                                IsMuted="True"
                                LoadedBehavior="Play"
                                LoopingBehavior="Play"
                                MediaClosed="MediaView_MediaClosed"
                                MediaOpened="MediaView_MediaOpened"
                                PositionChanged="MediaView_PositionChanged"
                                ScrollViewer.VerticalScrollBarVisibility="Disabled"
                                StretchDirection="{Binding Settings.StretchImageToggle, Converter={StaticResource BoolToStretchDirectionConverter}, Mode=OneWay}"
                                UnloadedBehavior="Close"
                                />
</MainWindow>

C

//---------------------MainWindow (simplified)

public MainWindow()
        {
            //...

            Library.FFmpegLoadModeFlags = FFmpegLoadMode.MinimumFeatures;
        }

//---------------------App Loaded Method (simplified)

private async void OnAppLoaded(object sender, RoutedEventArgs e)
        {
            string[] args = Environment.GetCommandLineArgs();

            if (args.Length > 0)//get startup path
            {
                Library.FFmpegDirectory = @$"{Path.GetDirectoryName(args[0])}\ffmpeg\bin";
            }
        }

//---------------------Loading File Method (simplified)

private void NewUri(string path)
        {

            if (ImageItem.IsAnimated || Path.GetExtension(ImageItem.ThumbnailName) == ".webp")
            {
                Uri uri = new Uri(path, UriKind.Absolute);

                MediaView.Open(uri);
            }
            else
            {
                MediaView.Close();
            }
        }

//---------------------Pause Control Methods

private void TogglePause()
        {
            if (ImageItem is null) return;

            if (ImageItem.IsAnimated)
            {
                if (MediaView.IsPaused)
                {
                    MediaView.Play();
                }
                else
                {
                    MediaView.Pause();
                }
            }
        }

//---------------------Event Methods

private void MediaView_MediaOpened(object sender, Unosquare.FFME.Common.MediaOpenedEventArgs e)
        {
            if (ImagesData.Count > 0)
            {
                ImgWidth = MediaView.NaturalVideoWidth;
                ImgHeight = MediaView.NaturalVideoHeight;
                ImageRotation = Rotation.Rotate0;

                totalMediaTime = MediaView.NaturalDuration.Value.TotalMilliseconds;
            }
        }

        private void MediaView_PositionChanged(object sender, Unosquare.FFME.Common.PositionChangedEventArgs e)//for a progression bar only
        {
            double currentTime = e.Position.TotalMilliseconds;

            if (totalMediaTime == 0 || currentTime == 0)
                MediaProgression.Value = 0;
            else
                MediaProgression.Value = (currentTime / totalMediaTime) * 100;
        }

        private void MediaView_MediaClosed(object sender, EventArgs e)//for when it is being flagged for deleting only (probably unrelated)
        {
           //...
        }
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

nevaran commented 3 years ago

It was noted that this has been fixed? Because it would still crash randomly