Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 2 ■ an IntroduCtIon to Content CreatIon: 2d new MedIa asset FundaMentals


end result during the book in less than a megabyte. The calculation for digital video is a bit different; as with
digital video, you have hundreds, or thousands, of frames. For digital video you would multiply your raw
image data size by the number of frames per second (the frame rate), which the digital video is set to play
back at (this frame rate value is specified during the compression process), and then multiply that result by
the total number of seconds of content duration, which is contained in your video file.
To continue with the VGA example used earlier, you now know a 24-bit VGA image is 900KB. This
makes the calculation to take this to the next level very easy. Digital video traditionally runs at 30 FPS, so one
second of standard definition (SD, or VGA) raw (uncompressed) digital video in system memory prior to
play back on the screen would be 30 image frames, each of which is 900KB, yielding a total data footprint in
memory of 27000KB, about 27MB!
You can see why having digital video compression file formats such as the MPEG-4 H.264 AVC format,
which can significantly compress this massive raw data footprint that digital video can create, is extremely
important.
The JavaFX multimedia package uses one of the most impressive video compression codecs (codec
stands for COde-DECode) that is also supported in HTML5 and Android: the aforementioned MPEG-4
H.264 Advanced Video Codec (AVC). This “cross open platform support” spanning the three major “open
platforms” today (Java, HTML5, and Android) is extremely convenient for developer asset optimization
because one single digital video asset can be used across Java, JavaFX, HTML5, and Android applications.
There is also a “native” digital video codec, called VP6, included in the JavaFX engine in case H.264 is not
installed. I am going to cover the basics of digital video asset compression and data footprint optimization
next, before I get into digital audio, to be thorough. Then, in the next chapter, we will get into the
complexities of 3D so you have a complete foundational understanding of new media elements in games.


Digital Video Compression Concepts: Bit Rate, Data Streaming, SD,


HD, and UHD


Let’s start out covering the primary or standard resolutions that are used in commercial video. These also
happen to be common consumer electronics device screen resolutions, probably because if the display
screen pixel resolution matches the video pixel resolution that is being played “full screen” on the screen,
there will be zero “scaling,” which can cause scaling artifacts. Before HDTV or high definition came along,
video was called standard definition (SD) and used a standard pixel vertical resolution of 480 pixels.
VGA is an SD resolution, and 720 by 480 could be called Wide SD resolution. High Definition (HD) video
comes in two resolutions, 1280 by 720, which I call Pseudo HD, and 1920 by 1080, which the industry calls
true HD. Both HD resolutions feature a 16:9 aspect ratio and are used in TV and iTV sets, smartphones,
tablets, e-book readers, and game consoles. There is also an UHD resolution out now that features 4096 by
2160 pixels. IMAX resolution was 4096 by 4096, so UHD has IMAX resolution in the horizontal, or x-axis,
resolution, which is pretty impressive since consumers can now have IMAX in their living rooms for $1,000!
Video streaming is a more complicated concept than resolution because it involves playing back video
data over a wide expanse, such as the one between your Java game application and the remote video data
servers that will hold your potentially massive digital video assets. Streaming is complicated because the
device that your Java game app is running on will be communicating, in real time, with remote data servers,
receiving video data packets as the video plays! This is why it is termed streaming; as the video is streaming
from the video server over the Internet and into the hardware devices. Video streaming is supported by the
MPEG-4 H.264 AVC format codec (encoder-decoder pair).
The last concept that we need to cover in this section is the concept of bit rate. Bit rate is the key setting
used in the video compression process; bit rates represent your target bandwidth, or data pipe size, that
is able to accommodate a certain number of bits streaming through it every second. Your bit-rate setting
should also take into consideration the CPU processing power that exists within any given Java-capable
device, making your digital video’s data optimization even more challenging. Fortunately, most devices
these days feature dual-core or quad-core CPUs!

Free download pdf