Comments (6)
// Add in your's loaded function or other init function,it's global ^-^
Library.FFmpegDirectory ="c:\\ffmpeg"; // The ffmpeg install path
Library.LoadFFmpeg();
from ffmediaelement.
`private void FfPlayer_OnMediaOpening(object? sender, MediaOpeningEventArgs e) { if (e.Options.VideoStream is { } videoStream) { // Hardware device priorities var deviceCandidates = new[] { AVHWDeviceType.AV_HWDEVICE_TYPE_CUDA, AVHWDeviceType.AV_HWDEVICE_TYPE_D3D11VA, AVHWDeviceType.AV_HWDEVICE_TYPE_DXVA2 };
// Hardware device selection if (videoStream.FPS <= 30) foreach (var deviceType in deviceCandidates) { var accelerator = videoStream.HardwareDevices.FirstOrDefault(d => d.DeviceType == deviceType); if (accelerator == null) continue; if (Debugger.IsAttached) e.Options.VideoHardwareDevice = accelerator; break; } } }`
I don't know why, but after I added this code, the problem was solved
I'll try it and then reply,thanks!
from ffmediaelement.
I can confirm: bug exist, reproducible and pretty annoying; trick above (with providing VideoHardwareDevice) just hides the issue (especially if you update your project to NET Core 3.1, crashes become very rare) but not resolving it completely.
It's a pity, FFME is a pretty useful project.
from ffmediaelement.
FFME crashes silently in WPF application
I have a .Net 6.0 WPF application that uses FFME.Windows 4.4.350. Occasionally, the application exits when a call to MediaElement.Open is made.
Issue Categories
- [X ] Bug
- Feature Request
- Question
- [X ] Not sure
Version Information
- [X ] NuGet Package 4.4.350
- Build From Master branch, Commit Enter commit id. Example: 704c482
- Build from Branch Name, Commit Enter commit id. Example: 704c482
Steps to Reproduce
- Step 1
Call MediaElement.Open- Step 2
Several seconds later, call MediaElement.Open again- Step 3
CrashExpected Results
Second media is played.
Sample Code
XAML
<ffme:MediaElement x:Name="MediaPlayer" Background="Gray" LoadedBehavior="Play" UnloadedBehavior="Manual" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
C#
if (mDispatcher != Dispatcher.CurrentDispatcher) { mDispatcher.Invoke(() => PlayFile(fileName, loop)); } else { try { if (MediaPlayer.MediaState != MediaPlaybackState.Stop) { await MediaPlayer.Stop(); await MediaPlayer.Close(); } MediaPlayer.LoopingBehavior = loop ? MediaPlaybackState.Play : MediaPlaybackState.Stop; await MediaPlayer.Open(new FileInputStream(fileName)); mLogger?.Info($"Playing {fileName}."); } catch (Exception ex) { mLogger?.Error($"Error trying to play video {fileName}.{Environment.NewLine}{ex.Message}"); } }I am ensuring the call is being made from the main UI thread and it is wrapped in a try/catch block. However, I never catch the exception in that try/catch or even the Dispatcher.UnhandledException handler in the main application. My understanding is that for c# 5.0 and above, I should be able to catch the exception using that syntax. Any suggestions on how to catch this exception and/or find out what is going on via a log file, etc. would be greatly appreciated.
I guess that the exception is thrown on another thread.
Maybe this will give you some guidance.
AppDomain.CurrentDomain.FirstChanceException += (sender, eventArgs) =>
{
Debug.WriteLine(eventArgs.Exception.ToString());
};
Is the origin of the exception in the native code, there might be a need to wrap-around a native c++ try-catch that then submits the exception as an out parameter to the CLR that rethrows the exception as an CLR exception.
from ffmediaelement.
@MrBean2016, actually issue isn't how to catch an exception but how to make FFME working with .NET standard stack without crashing. Same code is working perfectly on .NET Framework from 3.7 till 3.8.1 but crashes periodically on media opening on NET 5.0 - .NET Core 3.1
from ffmediaelement.
@MrBean2016, actually issue isn't how to catch an exception but how to make FFME working with .NET standard stack without crashing. Same code is working perfectly on .NET Framework from 3.7 till 3.8.1 but crashes periodically on media opening on NET 5.0 - .NET Core 3.1
Sorry, I was a bit unclear. The purpose of catching the native exception is to find out which part of the code where the problem is. C/C++ exceptions are not compatible with .Net 5/6/7 so one must build a CLR-wrapper and catching the native exceptions in the wrapper (they wont show up in the debugger).
But one thing to try is in the example in the first post to change from invoke() to begininvoke() since you may not want a thread to wait on finish execution, especially if that delegate performs I/O (which could make the delegate and your gui thread block) and the risk of deadlock since the mediaopening event will be called.
from ffmediaelement.
Related Issues (20)
- ffme:MediaElement shows a wrong rotated frame at begin. HOT 1
- Add Rotation, Width, Height, to MediaInfo
- Unable to load ffmpeg Binaries HOT 1
- help a newbie HOT 3
- Memory_Heap_Corruption when opening MP3 files
- Which method turns on hardware acceleration? HOT 1
- Latest FFMPEG version is incompatible HOT 44
- Audio pitch is changing when increasing the speed ratio HOT 2
- Video with Resetting Clock Pauses and Cannot resume
- Where can I find the .Net 4.6.x verion of the Unosquare.FFME.Windows? Looking for the source code to strong name sign it with pfx/snk HOT 1
- Black video when opening media with multiple players active HOT 1
- Then tow instance,FfmediaElement non't work
- MediaElement control can not work if FFmpeg.AutoGen update to the latest version.
- Can not play subtitle file for audio file.
- Video Not Showing HOT 1
- Play Crash with Screen Capture Video HOT 2
- sws_scale crashes with small resolution HOT 3
- When will a new Nuget package be published? HOT 1
- Outdated docs and undefined functions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ffmediaelement.