Silverlight MediaElement progress - silverlight

I am trying to create a custom media player in Silverlight. I am working on the Progress Bar. I want the progress bar to display the current Download Progress as well as the Current Position of the MediaElement while it is playing.
To do this I have a Progress Bar to display the download progress and a Slider overlaid to display the current position.
I set the value for both as a percentage out of 100.
For example:
ProgressBar.Value = MediaElement.DownloadProgress;
Slider.Value = (MediaElement.Position.TotalMilliseconds) / (MediaElement.NaturalDuration.TimeSpan.TotalMilliseconds);
The problem is the Slider.Value becomes larger than the ProgressBar.Value. How is this possible? How can I be playing the video at a farther position than what has been downloaded?
Any advice on how to get these to sync up properly?
Thanks.

It's possible because video stream compression algorithms do not result in byte counts proportional to time. Take for example a 300MB video file that runs for say 60 minutes it does not automatically follow that 30 minutes into the file would be that the 150MB point.
If the first part of video is relatively "quiet", it's likely it will compress well whereas busier sections later may not compress so well. As a result it's possible to have downloaded only a small percentage of the file size and yet have played a larger percentage of its overall playing time.
Edit:
So how do I get them to sync up?
You fudge it by limiting the slider to minimum of either the download progress or time.
Slider.Value = Math.Min(mediaelement.Position.TotalMilliseconds / mediaelement.NaturalDuration.TimeSpan.TotalMilliseconds, mediaelement.downloadprogress);

Related

Microblink SDK: Take only the photo which is inside rectangle

I am using Microblink Sdk with reactjs. So, when I open the camera to take the photo of some document it takes the picture of whole frame not just inside the reactange.
Is there any option to take only the picture only inside the rectangle.
Thanks!!!
The rectangle displayed on the screen is there to help the user position the document they are scanning.
Specifically, the detection of the document and data extraction works best if the entire image is sent to processing, and if the document is positioned roughly around the rectangle.
That means that if you “cropped” the image to the rectangle before recognition, you would effectively lower the success rate of scanning or you would have to move the camera further away from the document to keep it in that sweet spot where the document has a margin around it, resulting in a lower resolution image, lowering the success rate once more and defeating the purpose of the initial cropping.

How to know how long the animation last and how to stop gif at the end in Maple

How do I know how long an animation lasts and how do I stop the gif at the end?
I created a GIF from export tool (Maple) but I don't know how long the animation is, or how to make GIF run in real time. I made a gif for showing how something falls down from an altitude. I need to show some figures like t(time) , h(height), v(speed) while it falls down.
Commands that generate animations in Maple often have an option that controls the default number frames. For example, the plots:-animate uses 25 frames. Moreover, animations that are shown in the Maple GUI can be controlled by the animation toolbar, which sets animations to run at 10 frames per second (fps) by default. When you use the right-click menu to export your animation to a GIF file, the exporter will take the current setting for fps into consideration and produce an animation that is 25 frames / 10 frames per second = 2.5 seconds long. Changing this value in the animation toolbar will result in shorter or longer animations accordingly.
From a couple of quick tests, exporting the animation programmatically does not respect the choice of fps, so in this case you may need to play with the number of frames in order to compensate for the default 10 fps setting.
With respect to stopping the gif, as far as I know, there is no way to control this using Maple. I believe that the only solution is to use a GIF editing program to manually turn off the 'loop' option.

Animated gif texture in 3ds max

and thanks in advance.
I don't know what I am doing wrong, I have created an animated .gif in Photoshop to use as a texture map for a model in 3ds max 2010. The Texture displays well enough in max and in renders, however it is not animated. I had it working at one point, but I cannot figure out what I might have changed in the settings that would cause animated textures to not play. That being said; I am very interested in learning of other file types that are better suited for animated textures in Max.
Try use image sequence (png,tiff)
Save each frame animation as file with names
some_name__000.ext
some_name__001.ext
some_name__002.ext
and load first as image sequence.
Max will create IFL file when you load texture as image sequence
Next time you can load IFL
IFL is text file, so it is easy to edit

WPF - Is RenderTargetBitmap better than changing an Image Source?

Im trying to create a PNG sequencer class that will allow me to change an ImageBrush's ImageSource property via an animation.
The issue is that I have around 150 PNG files to load, and it really really affects performance when I have a few animations on the screen.
I have read a little about RenderTargetBitmap and also WriteableBitmap but Im not sure how to get a big performance boost, because I really do need it.
Im getting down to 6fps in some cases, which is obviously not acceptable.
In my Sequencer class, I just update a CurrentFrame DP that changes the ImageSource property of the ImageBrush.
Any ideas on how to increase the performance here?
Step 1 is loading all your images in ahead of time (preferably on a background thread). You should have your BitmapImage objects initialized with the CacheOption = BitmapCacheOption.OnLoad. You may already be doing this or it might not be the problem (the images cache by default).
However the rendering thread also needs to do some work when you change the image source. If you're not displaying at the source image size, that might be a problem, as by default the Image control uses the high quality Fant scaling algorithm. In that case you could get a performance increase by calling RenderOptions.SetBitmapScalingMode(uiImage, BitmapScalingMode.LowQuality); on your Image. Low quality scaling is orders of magnitude faster. However even after that there's still a bit of work involved. If you want to get the fastest animation possible, you can create an Image control for every frame, then overlap them all on the same place and change which one appears on top. You'll still take the hit on the render thread loading all the images in, but the actual animation should be quite snappy.

WPF render performance with BitmapSource

I've created a WPF control (inheriting from FrameworkElement) that displays a tiled graphic that can be panned. Each tile is 256x256 pixels at 24bpp. I've overridden OnRender. There, I load any new tiles (as BitmapFrame), then draw all visible tiles using drawingContext.DrawImage.
Now, whenever there are more than a handful new tiles per render cycle, the framerate drops from 60fps to zero for about a second. This is not caused by loading the images (which takes in the order of milliseconds), nor by DrawImage (which takes no time at all, as it merely fills some intermediate render data structure).
My guess is that the render thread itself chokes whenever it gets a large number (~20) of new BitmapSource instances (that is, ones it had not already cached). Either it spends a lot of time converting them to some internal DirectX-compatible format or it might be a caching issue. It cannot be running out of video RAM; Perforator shows peaks at below 60MB, I have 256MB. Also, Perforator says all render targets are hardware-accelerated, so that can't be it, either.
Any insights would be appreciated!
Thanks in advance
Daniel
#RandomEngy:
BitmapScalingMode.LowQuality reduced the problem a little, but did not get rid of it. I am already loading tiles at the intended resolution. And it can't be the graphics driver, which is up-to-date (Nvidia).
I'm a little surprised to learn that scaling takes that much time. The way I understood it, a bitmap (regardless of its size) is just loaded as a Direct3D texture and then hardware-scaled. As a matter of fact, once the bitmap has been rendered for the first time, I can change its rotation and scale without any further freezes.
It's not just with a large number of images. Just one large image is enough to hold up rendering until it has been loaded in, and that can be quite noticable when your image dimensions start getting up in the thousands.
I do agree with you that it's probably the render thread: I did a test and the UI thread was still happily dispatching messages while this render delay was taking place from trying to display a fully pre-cached BitmapImage.
It must be doing some sort of conversion or preparation on the image, like you were speculating. I've tried to mitigate this in my app by "rendering" but hiding the image, then revealing it when I need to show it. However this is less than ideal because the rendering freezes happen anyway.
(Edit)
Some followup: After a discussion on the MS WPF alias I found what was causing the delays. On my Server 2008 machine it was a combination of old video drivers that don't support the new WDDM driver model and a delay for resizing the image.
If the source image size is different from the display size, that will delay the render thread before the image shows up. By default an image is set to the highest quality, but you can change the scaling options for rendering by calling RenderOptions.SetBitmapScalingMode(uiImage, BitmapScalingMode.LowQuality); . Once I did that, the mysterious freeze before displaying an image went away. An alternative, if you don't like the quality drop in scaling, is to load the BitmapImage with DecodePixelWidth/Height equal to the size it will be displayed at. Then if you load the BitmapImage on a background thread, you should have no delay in displaying it.
Also try these;
/* ivis is declared in XAML <Image x:Name="iVis" UseLayoutRounding="True" SnapsToDevicePixels="True" /> */
iVis.Stretch = Stretch.None;
RenderOptions.SetBitmapScalingMode(iVis, BitmapScalingMode.NearestNeighbor);
RenderOptions.SetEdgeMode(iVis, EdgeMode.Aliased);
VisualBitmapScalingMode = BitmapScalingMode.NearestNeighbor;
iVis.Source = **** your bitmap source ****
I was having some trouble with performance when using a huge amount of "A" channel color's, waiting until after the image had rendered to scale it worked much better for me.
Also, as you said your using a tiled graphic?
You would usually use a TileBrush to simply set as the Brush on your FrameworkElement. If you are animating them or adding new ones dynamically, you could generate your brushes then apply them to your object as you go manually too, be sure to Freeze them if you can. Also, VisualBitmapScalingMode is a property of any Visual.

Resources