Teach you to easily make java video player

preface

Skip the nonsense and look directly at the text

Java went into the pit because of its cross platform advantages. At that time, I thought, "write once and run everywhere." This sounds awesome. It should be the ultimate way for the development of all languages. Java is bound to dominate the world.

However, it turned out that I was still too young at that time.

As the saying goes, you can't have both fish and bear's paw. If you want to enjoy the convenience brought by cross platform, you will inevitably accept the lack of performance. In fact, Java has been committed to improving the performance of virtual machines (JIT and other technologies), but in the face of high requirements for real-time computing performance or tasks related to hardware optimization (hardware coding and decoding of video), it is still far inferior to C or C + +. Therefore, few people can see such software written in Java.

Back to the point, if you want to write a video player, you must deal with different video formats (MP4, avi, RMVB, flv, etc.). Each type of video must have a corresponding decoder to play. The vast majority of decoder libraries are written based on efficient C or C + +, and there are very few decoder libraries written in Java.

Therefore, to write a video player in Java, there are only two options:

• use pure java to write the software decoder of mainstream video format and complete the video decoding task in combination with Java media framework (JMF). • use JNI to call the existing C or C + + decoder library to complete the video decoding task

The advantage of using java to write software decoder is that it can truly realize cross platform, and can also be easily and flexibly combined with swing framework. However, the disadvantage is that it is too troublesome. Not to mention the efficiency of software decoder, whether the wheels of decoders of various mainstream video formats can be successfully rebuilt is a debatable problem.

Therefore, I adopt the second method, which calls the existing third-party video decoding library through JNI to complete the task of video decoding, while the logic of video display and control is completed by Java. In this way, an efficient video player can be realized. It is worth mentioning that although calling different platforms according to the platform type can also realize cross platform, it will be subject to many restrictions, which is inevitable.

Next, let's see how to implement a video player.

text

Decoder selection

There are many video formats and many decoders, so it is a cumbersome task to find the corresponding decoder and package it into JNI interface for calling. Therefore, we can find a library of media processing framework (video player) that has encapsulated a variety of mainstream decoders to call directly. VLC is a very good choice.

VLC media player VLC is a free and open source cross platform multimedia player and framework, which can play most multimedia files, DVD, audio CD, VCD and various streaming media protocols.

For the project address, see https://github.com/caprica/vlcj-player

For the project address, see https://github.com/clayandgithub/javaplayer

Attached: vlcj's official documents

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>