Smooth Video Transitions for WPF - wpf

I'm using VB.net 2010 and WPF 4. I need to have a smooth transition between two videos played on the mediaelement. I absolutely cannot use anything that requires me to use a winhost in the WPF window, as that will make my project impossible (since the video is full screen, and the controls are over the video)
Basically, I need for the video to play through, and then smoothly go to another video specified in code behind. I cannot splice the two videos together - they must be separate.
How do I have the videos transition smoothly, with no "blink"?

I'm guessing without testing here. You're probably going to need some CPU cores and a good video card.
If you have the memory, use two MediaElements.
Queue up both videos, one on each element.
Set the opacity of the second one to completely transparent. They're UIElements so this should work...
Use timers of some kind keyed from the start of playback on the first one so that you get an event a couple of seconds before playback ends.
With that event delegate, start the video in the second MediaElement, animate the first one's opacity to zero while simultaneously animating the second one to fully opaque.
If you need to do it again, set up the timer again and make sure your delegate animates things the other way.

Related

Rendering video using WriteableBitmap causes choppy animation

So here's my setup:
Camera images coming in at 1920x1080 # 25 FPS
Writing image data to WriteableBitmap on UI thread (simple copy, no processing)
Two Image controls in two different windows on two different monitors has their Source property set to the WriteableBitmap
Some generic UI stuff goes over the camera images
This works great, uses about 4% CPU on an old laptop (8 logical processors). The video is as smooth as can be. However, my UI has some animations (stuff moving around). When the camera display is running, those animations gets choppy.
Right now, the camera image is in Gray8 format, so it will be converted (I guess when calling WritePixels?). I also tried forcing one of the animations to 25 FPS too, no change.
Where should I start to resolve this? Is the issue that I'm locking the bitmap for too long, or is there something else going on? From what I can see locking the bitmap will cause the render thread to block, so moving that to another thread seems pointless. And it does feel like that somewhat defeats the purpose of WriteableBitmap.
This is always going to be tricky because you're capturing at 25FPS whilst WPF tries to update at 60. It's difficult to offer any meaninful advice without seeing a testable project but I'd probably start by doing the updates in a CompositionTarget.Rendering handler.

WPF MediaElement video won't play after being hidden in storyboard

I'll start of by describing the problem, and then follow up with details about the process I'm going though.
Problem:
I'm having an issue where I'm playing a MediaElement on one storyboard and then setting the same MediaElement to hidden in another. After having the MediaElement set to hidden, I'm unable to replay the video portion of that storyboard again (non-MediaElement animations still happen.) Videos are WMVs encoded in VC-1 at 10,000 Kbps at a resolution of 1560x1004 and provided alongside the project as relative assets.
Details:
I'm working on a Kiosk application which makes use of a large number of videos combined with some graphical effects for real-time animation. Presently I'm creating storyboards using Blend, layering the videos for playback in the desired sequence. Below details two sample storyboard from the page:
Open performs the following:
Set's meOpen's visibility to 100%, Visible
Set's meIn's visibility to Hidden at 1 second (masking the start of meOpen)
Starts playing meOpen at 0:00.900.
Before playing the Close storyboard the Open storyboard is played, and the system waits for user input to continue. Once Close is triggered, the following happens:
meOpen - A MediaElement that has it's visibility set to 'Hidden' at 1 second
meClose - A MediaElement that is the desired video to play. I have it starting slightly before meOpen is hidden to mask the first frame 'black frame' while the element is loading the video
The rest of the items is just fading visibility of overlay elements.
The storyboard works for running through the video; however, if I try and play the Open storyboard a second time, meOpen does not play.
Thanks

strong animation in silverlight

I want to make an animation in the Silverlight 4 Expression Blend 4 - a running man.
How is it possible to do, because the only way I see it to be done is to draw him frame by frame with the interval, say, 0.2s?
Your options are bitmap animation or key-frame animation of body parts.
Key-frame animation seems appropriate unless you want photo-realistic movement.
You will need to select regular time internals in Blend and place the various components of the man (legs segments, arm segments etc) in the correct positions for that key frame. Silverlight will do the interpolation between frames.
Build up one complete cycle and set the storyboard property to repeat the sequence.

SpeedRatio & MediaTimeline

I'm trying to be able to affect SpeedRatio on a MediaElement whilst having the media play in a continous loop.
This is possible through code behind; I can reset the position of the media once it has ended, but that creates a seam in the playback.
For seamless playback, I use a MediaTimeline, but when I use I media timeline, I can't change the SpeedRatio.
Has anyone got a different approach to looping playback in a mediaElement, or handling SpeedRatio?
UPDATE:
If I stop the timeline, change the timeline's SpeedRatio, I can produce the result I'm looking for. The only remaining problem is getting the timeline to start from the same position that it was stopped at. Pausing the timeline does not allow for the SpeedRatio to be changed.
I still welcome any alternatives.
My MediaUriElement in my open-source project has a "Loop" property that can provide seemless looping. Get it from the source because it's the newest.
The only solution I've found for this is to use XNA to control audio. It's got a lot more responsiveness.

Prevent WPF stutter / dropped frames

I've written a simple game-like app in WPF. The number of objects drawn is well within WPF capabilities - something like a few hundred ellipses and lines with simple fills. I have a DispatcherTimer to adjust the positions of the objects from time to time (1/60th of a second).
The code to compute the new positions can be quite intensive when there are lots of objects, and can fully load a processor. Whenever this occurs, WPF starts skipping frames, presumably trying to compensate for the "slowness" of my application.
What I would much rather happen is for all the frames to be drawn anyway, only slower. The dropped frames do not add any speed - because visual updates were pretty quick anyway.
Can I somehow force WPF to have my changes to the visuals be reflected on the screen regardless of whether WPF thinks it's a good idea?
Unfortunately I don't think there's anything you can do about this, although I will happily be corrected! WPF is designed to be an application creation framework, not a games library, so it priortises application performance and "usability" over framerate. This actually works very well when producing applications as it allows you to use quite rich animations and effects while maintaining perceived performance on lower end systems.
The only thing I think you might be able to try is push your movement code's Dispatcher priority down slightly to below Render (Loaded is the next one down) using something like:
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, MoveMyStuff);
I don't have any kind of test harness to verify if that will help though.
This issue was fixed by using a Canvas with an OnRender override instead of creating and moving UIElements. This does mean that everything needs to be drawn by hand in OnRender, but it can now run at any FPS consistently, without skipping any frames.

Resources