Improving Media Performance
There are a number of actions you can consider and explore when seeking to improve the performance of JavaFX media. As always with performance issues, it is very important to ensure that you have sufficient computing power and bandwidth available to handle the task.
Here are some ways that you can improve the performance of your JavaFX media:
- Check that you have sufficient computing power.
JavaFX media can run on a very wide range of hardware. However, you still need to have realistic expectations. For instance, you should not expect to see full-screen HD video (720p or 1080p) on an old, memory-constrained, 1-GHz Pentium processor with an old video card and low VRAM. If you have an older/slower machine, you will have to confine your media to smaller resolution and/or lower bitrate media. JavaFX technology will take advantage of existing hardware acceleration if present. No additional work is necessary from the developer's perspective. A high-quality video card with lots of video RAM will have a huge impact on your performance. - Get the latest version of the Java Runtime Environment (JRE).
Some significant performance improvements were made in JRE 6 Update 14 (JRE 6u14) software. You can download the latest JRE version from the following location: http://java.sun.com/javase/downloads/index.jsp. - Reduce unnecessary scene complexity.
All visual JavaFX objects (including a media view) are managed by using an optimized, retained-mode graphics data structure called a "scene graph." This graph contains all the objects that have some type of visual representation. One way to ensure that your media performs well is to remove, or otherwise make inactive, those objects in the scene graph that are not vital while the media is playing. - Remove gratuitous graphics effects and animations.
The scene graph also contains objects that perform some function or effect on media and graphics. These objects include, for example, scaling transformations, mirroring and reflection effects, and animations. Depending on how many of these objects you have in your scene, and how powerful your system is, they can have a dramatic effect on performance. - Encode for desired resolution and quality.
Perhaps one of the most important actions you can do to improve media performance is to encode the video intelligently. To demonstrate with an example, imagine encoding a video at an HD resolution, and then scaling it down to a small window on your screen. The video decoder still has to decode the very large resolution data and this chews up a lot of your compute cycles. In addition, if you scale the video down, you then have an additional scaling transformation occurring many times a second. Finally, if you are streaming this information across the Internet, you are incurring additional unnecessary bandwidth. So, the best thing to do is to encode the data at the resolution at which you expect it to be consumed. Often this means that you should make a few different resolutions available. In addition, some of the media conversion tools, such as Apple QuickTime, enable you to configure the media for Internet streaming by setting Fast Start or Fast Start - Compressed Header. These settings also help in faster startup of the media by giving the media information to the engine through the header. Also, see the next suggestion. - Encode for better seeking performance.
If you are encoding primarily for streaming, this suggestion is not of much value. However, if your application requires fast seeking, you can improve the performance of seeking by encoding more key frames into your video. These key frames are like full-resolution snapshots of a particular frame in the video and are used by the seeking technology to both index the media and provide starting points for seeking ahead and behind. The more key frames that you have, the less time the decoder has to search and compute frames to get to the desired frame. All video encoders insert key frames automatically, and most enable you to add more. They come at a cost, so be judicious. - Initialize the media engine.
For faster playback of a streaming media that is progressively downloaded, it helps to initialize the engine first by using the same media behind the scenes. One way to do this is to mute the player (perhaps set the playback screen to a static image), play the media, setcurrentTimeto 0, unmute the player, and hand it over to the user. This strategy will give the user the experience that the media starts playing immediately because the engine is already initialized. - Do not put media in jar files.
This is currently not supported. See the FAQ for more information - Optmize the streaming server configuration.
If the streaming server is not configured correctly, the performance of streamed media playback is low. This is because the progressive download and playback are not enabled until the MIME settings on the media server are configured properly. To play media when the MIME type is not configured properly, the whole stream has to be downloaded and then decoded. If the media file is small, downloading and decoding do not take much time. However, for a large file, or if a downloading client of low bandwidth, this process takes much more time. The default MIME-type setting of any given web or application server is set to "text/plain". To enable progressive download and faster playback, you need to configure the server-side MIME setting to one of the following options to suit the type of media being served. On a typical Apache server this adjustment is performed by editing themime.typesfile in the<Apache Home>/confdirectory.
MIME Type Associated Media video/mpeg MPEG, MPG, MPE video/quicktime QT MOV video/x-msvideo AVI video/x-ms-wmv WMV video/x-flv FLV video/x-javafx FXM audio/mpeg MPGA, MP2, MP3
We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
Sandeep Konchady
Staff Engineer, Sun Microsystems
Alla Redko
Technical Writer, Sun Microsystems
Larry McDonough
Engineering Manager, Sun Microsystems