Can I set the frames per second of a MediaElement in C#? - c#

I have a media element that normally plays videos fine, but some videos with high framerates(120) play at the wrong speed. I assume it is something to do with the video not having the right information in the header, and am looking into setting it manually.
Is there a good way to set the Frames Per Second of a MediaElement?

Because there are no methods or variables in the Media Element to get or set the frame rate, the only viable solution I found was to have a text area that set a frame rate multiplier. This multiplier can then be applied to the SpeedRatio of the Media Element, as well as anywhere else where events dependent on the video time are determined.

Related

UWP Application with video playback

How can I get the time of video playback in UWP C# Application?
I'm using Media Element and I have video playback in my app after I choose it from the file. I can pause it and start it again, but I don't know how can I get the real time of this video, when it's playing.
For retrieve current position of duration look at the MediaElement.Position property.
The amount of time since the beginning of the media. The default is a TimeSpan with value 0:0:0
If you want to know the playback duration you can use MediaElement.NaturalDuration property:
The natural duration of the media. The default value is a Duration structure that evaluates as Automatic, which is the value held if you query this property before MediaOpened.
You can bind on Position property of MediaLement like this:
<MediaElement x:Name="MediaElement1"/>
<TextBlock Text="{Binding Position, ElementName=MediaElement1}"/>

Delay between on screen display and parallel port trigger

I am working on a research project which needs precise timing/synchronize between the on screen display and a trigger from parallel port in Unity.
What I am trying to do is to flash the screen to white while sending a trigger to the parellel port at the same time (desired difference is within 10ms).
I mesured the screen flash with a photodiode to determine the exact time it turns white, and synchronize it with the trigger from parellel port. I always observed a delay of 40 - 70ms between the trigger and the flash (the flash arrived slower) which is my main problem.
What I have tried so far:
- Update the flash and send the trigger in the same frame (bigger delay)
- Update the flash -> WaitForEndOfFrame() -> send trigger (lower delay but still big). Below is a sample code:
IEnumerator UpdateParallelPort()
{
while (true)
{
yield return new WaitForEndOfFrame();
if (flashed == FlashState.ToWhite)
{
parallelPort.SendTrigger();
}
}
}
I also tested if the flash take multiple frames to be rendered by using ReadPixels to determine at what frame the screen turn white, but it was not the case, it was in the same frame when I issued the command. So I guess the delay comes from the time the buffer being sent to screen ? If that is the case, is there anyway to determine/synchronize the exact timing, or to minimize it ?
This is my first post in Stackoverflow, hope that I explained it clear enough. Thank you in advance for your help!
which needs precise timing
I have bad news, completely forget it.
Unity is a game engine through-and-through.
The whole entire raison d'etre, the most fundamental aspects of it, is that it lets you render mesh of dinosaurs etc, with "total compromise" of granular time, and reasonable overall perceptive time.
Unfortunately, you literally could not choose a worse milieu for the project! Sorry! :O

WPF / C#: async load/buffer next movie clip

I need a main 'home' video (full screen HD) running in a loop, and then at some point (say the user presses a key) another short movie plays (one of twelve selected at random), and then back to the home movie loop.
I'm using the mediaElement in WPF from my C# code - Is there a way to load the next movie into memory so that it's ready to play instantly? It currently takes about a second or so...
(I'm actually using two media elements with the triggered movie on top - I was doing a cross fade but have taken that out now until I can buffer the next clip. Not sure if this is the best way of doing this, any ideas? Many Thanks.
I figured out a way in case anyone is interested.
You can just specify a bunch of mediaElements on top of each other (can have different z index but not essential). Then did
video.Opacity = 0.0;
video.Play();
video.Pause();
for all of them, then when you want to play one you just set the opacity to 1 and play it and it'll play instantly.
Don't know if that's the best way, but works well. Now going to implement a cross fade to finish up. Happy days.

Silverlight media element not showing buffering state after increase play rate

I am using silverlight plugin for playing media files.
I am taking Play rate control for increase/decrease media play rate speed.
There is on pop up with progress bar which is shown when media element is in buffering mode.
This is code for checking media is buffering mode.
if(_myMediaElement.CurrentState == MediaElementState.Buffering)
{
//Show pop_up for with buffering progress bar
}
Issue : when I increase play rate using play rate slider control and than increase media position by reset media element with new time span position than media element goes buffering mode. but _myMediaElement.CurrentState is always showing playing mode. therefore unable to showing pop_up for with buffering progress bar.
Code for changing play rate
_myMediaElement.PlaybackRate = _playRateSliderControl.Value; // it can be 0.5, 1.0, 1.5
Code for increase media position
_myMediaElement.Position = new TimeSpan(0, 0, newPosition);
Any help is appreciate
Thanks
I have fixed it.
when I increase playrate from 1.0 than if media element is in buffering process that time I have assign
playrate = 1.0 and take in another variable of increase playrate value. and than when buffering is completed and media element player played the stream than reset playrate by increase value.

track bar in media file using DirectShow lib in c#

i want to use a track bar in a window form which opens a media file as the video or audio plays i want to move the slider of the track bar accordingly . I had set all the properties of the track bar tool like maximun,minimun, tickfreguency small and large change accordingly.
using mediaposition i collect the currentPosition of the media and total duration using get_duration() method and sets the trackbar value to the current position but the problem is as the media is running the slider of the bar is not moving . i know i am missing something in the code .
Make sure you actually update that information in LOOP. So it would be updated, for example, in timer. Every 1 second.
You can also check what values you get from those two calls(get_duration and get_position) using debugger.

Categories

Resources