Detailed analysis of VLC Video Player principles, including TS Stream format Analysis

Source: Internet
Author: User
Tags win32 window

VLC is a powerful tool that can do a lot of interesting things.
The simplest way is to open a file from the interface and play it back. You can also use it in the command line, as shown in figure
C: \ Program Files \ VideoLAN \ VLC> vlc.exe test. Ts
The help of the website will be written to vlc-help.txt.
C: \ Program Files \ VideoLAN \ VLC> vlc.exe-H
For more detailed help, there are a lot of options to introduce
C: \ Program Files \ VideoLAN \ VLC> vlc.exe-H
Online Help
Http://www.videolan.org/doc/play-howto/en/play-howto-en.html
Http://www.videolan.org/doc/streaming-howto/en/streaming-howto-en.html
Search for and display the list of available modules
C: \ Program Files \ VideoLAN \ VLC> vlc.exe-l
In Windows, the configuration file of VLC is % appdata % \ VLC \ vlcrc by default.
% Appdata % in XP is usually c: \ Documents ents and Settings \ User Name \ Application Data
In Linux
VLC options can be set by modifying vlcrc. The interface is just a little more convenient.
Reset all options to the default status
C: \ Program Files \ VideoLAN \ VLC> vlc.exe-reset-config
VLC recursively searches for plugin from the Plugin-path specified in vlcrc and the modules and plugins directories in the current directory.
Most VLC functions are implemented through plugin. By default, VLC has a large number of dynamic plug-ins. For example, the official VLC 0.8.6e has 210 plug-ins. To speed up startup, VLC caches the plugin list in % appdata % \ VLC \ cache. The plugins-Cache option is set to 0 to disable caching plugin.
Open a UDP multicast stream. The default port is 4567.
For the RTP protocol, the VLC will automatically identify it, and it is okay to write UDP or RTP.
C: \ Program Files \ VideoLAN \ VLC> vlc.exe UDP: // @ 239.20.1.1: 4567
When receiving a stream on the local UDP port 888, "@" indicates binding an address instead of connecting to the address.
C: \ Program Files \ VideoLAN \ VLC> vlc.exe UDP: // @ 888
Streaming output means to transmit videos to external devices in some way during playback.
Streaming/saving settings will be more convenient
For example, test. Ts is cyclically played and transmitted to port 1234 on port 224.1.1.1 in RTP mode. The video is displayed at the same time.
Vlc.exe test. Ts-loop: sout = # duplicate {DST = STD {access = RTP, MUX = ts, DST = 224.1.1.1: 1234}, DST = display}
For example, if you receive UDP port 888, all the data is saved to c: \ dump. Ts.
Vlc.exe UDP: // @ 888: Demux = dump: demuxdump-file = "C: \ dump. Ts"
About the video output module in Windows
Direct3d: the effect is worse than DirectX, but it is convenient. You can also implement Alpha on the image.
DirectX: The best effect. Display acceleration using DirectX
OpenGL: performance is not the same on different hardware.
Wingdi: the slowest type, requiring no video card Acceleration
Caca: It is very interesting to use the color assic characters for display.
Temporarily enable a video output.
C: \ Program Files \ VideoLAN \ VLC-0.8.6e> VLC test. Ts-vout = caca
ActiveX Control
The officially released VLC comes with the ActiveX control axvlc. dll, which can be conveniently applied after registrationProgram And webpage
Using VLC, the registration method is
C: \ Program Files \ VideoLAN \ VLC-0.8.6e> regsvr32 axvlc. dll
For how to use ActiveX VLC, refer Source code Readme.txtand test.html
ActiveX Control interfaces are available in the first and second editions. The first editions are simple and have few functions and are no longer maintained.
We recommend that you use version 2 with more features.
Mozilla plugin
You can also use VLC in Firefox for Windows and Linux. You can choose to install VLC in windows.
Mozilla plugin. In fact, it adds a VLC sub-key under the hklm_software_shortillaplugin key.
Linux is not clear, but you can put libvlcplugin. So (or npvlc. So) and plug-in Directory
Put it in the Firefox plugins directory to make it take effect.
This applies to xulrunner-based applications. In fact, XUL applications such as Miro and Songbird are all used.
This plugin.
Similar to ActiveX, VLC's Mozilla in also has two sets of interfaces. We recommend that you use the new version 2.
Registry
In Windows, VLC only uses a small amount of registry information. The most important one is the hklm_software_vlc key.
The installdir item under. The Mozilla in and ActiveX Controls of VLC use this item to locate the directory of their plug-ins.
Telnet and HTTP Control
For VLC, the control interface is an interface module. You can use various control modules. Windows
The wxWidgets GUI is used by default. You can also use HTTP, telnet, and other interfaces to remotely control VLC,
Cool enough? If you use VLC for Video Stream forwarding on the server, this remote interface
It can help you a lot.
Video Filter
The 0.8 series contains up to 13 video filters to add effects and special processing to videos. Usage ratio
Most of them are anti-staggered deinterlace filters, which are useful when watching MPEG2 videos.
Skin2 Interface
A nice, skin-changing interface that is rarely used if it is unstable.
Other
Play a DVD or VCD, open the DirectShow device, and play the current screen... A lot of interesting functions can be explored
Some Problems
Currently, VLC cannot play real videos, such as RM and rmvb. In fact, VLC of version 0.9 can depend on other decoding methods.
Player. However, in the current test, sequence playback is normal, but dragging is ineffective.
There is a problem with RTSP playback and dragging, and there is a defect in obtaining the playback position. For example, cooperation with Darwin server.
Basic Principles of Video Playback
VLC Code It took a lot of time. The major reason was that I was not familiar with the basic principles of video playback. It seems that almost all video players, such as VLC, mplayer, and xine, include DirectShow. The principles and architecture of Playing videos are very similar, understanding this will get twice the result of understanding the source code of VLC.
Generally speaking, playing a video involves four steps:
1. Access acess, or read, obtain, or obtain
2. Demux demultiplexing means to separate audio and video (subtitles are also possible) that are normally combined)
3. Decode decoding, including audio and video decoding
4. Output output, also divided into audio and video output (aout and Vout)
Let's take a UDP multicast mpeg ts stream for example. The access part is responsible for receiving multicast streams from the network and placing them in the VLC memory buffer. The access module focuses on the IP protocol, for example, whether IPv6, multicast address, multicast protocol, port, and other information are detected. If the RTP protocol is detected (the RTP protocol simply adds a fixed 12-byte information to the UDP header ), the RTP Header information is also analyzed. For this part, see VLC source code/modules/access/udp. C. You can also see a large number of access modules in the same directory, such as file, HTTP, DVD, FTP, SMB, TCP, dshow, MMS, v4l... And so on.
The Demux part first needs to parse the TS stream information. The ts format is part of the MPEG2 protocol. In summary, ts is usually a 188-byte packet. a ts stream can contain multiple programs (programs ), A program can contain multiple elasticsearch streams of video, audio, and text information. Each elasticsearch stream has a different PID. To analyze these es streams, TS has some fixed PID tables used to send program and ES stream information at intervals: Pat and PMT tables. For more information about ts format, go to Google.
VLC implements an independent library libdvbpsi to parse and encode ts streams. For the code that calls it, see VLC source code/modules/Demux/ts. C.
In fact, Demux is required because audio and video are actually independently encoded during production and separate data is obtained. To facilitate transmission, you must combine them in a certain way, in this case, Demux is available for various encapsulation formats.
The audio and video streams decomposed by Demux are sent to the audio decoder and Video Decoder respectively. Because the original audio and video occupy a large amount of space, and the data with high redundancy is usually compressed during production. This is a well-known audio and video encoding format, including mpeg1 (VCD), MPEG2 (DVD), MPEG4, H.264, and rmvb. The audio and video decoder is used to restore the compressed data to the original audio and video data. VLC decoding MPEG2 uses an independent library libmp eg2. The source file called is/modules/codec/libmp eg2.c. VLC codec modules are all placed under the/modules/codec directory, including the famous huge FFMPEG.
Decoder. For example, a video decoder outputs an image similar to a bitmap format, but a video output module is required to be visible on the screen. Of course, the image can be directly painted to the window DC like a Win32 window program -- wingdi, an output module of VLC, does this, but it is usually too slow, it also consumes a lot of CPU. In Windows, it is better to use the DirectX interface to automatically call the acceleration function of the video card.
Such functional decomposition makes modularization easier. Each module needs to focus on its own business. In general, the functions are powerful and flexible.
But things are always not that simple. In terms of access, media access is hierarchical. For example, RTSP involves multiple levels of agreement between IPv4, TCP, UDP, RTCP, and RTSP. Some video formats include transmission, encapsulation, and editing code format, such as the mpeg series. Some encapsulation formats are independent containers, but many people will misunderstand that they are codec formats, such as MKV and Avi.
Audio and video are independent after Demux, but a mechanism is required to synchronize them. At the same time, we need a set of mechanisms to control speed, pause, stop, and jump to obtain various media information. These are very complicated and important.
In addition, you may need to insert some modifications somewhere to achieve some effect. For example, audio EQ and video brightness adjustment, VLC specially designs access_filter, audio_filter, and video_filter modules to do this.
The unique feature of VLC is the integration of the original VLS functions, which relies on stream_output modules in VLC. They can re-transcode and send the video being played in some way, such as HTTP, UDP, and files.
The structure of mplayer is similar. For example, the/stream directory corresponds to the access function, the Demux function corresponding to/mpdemux, And the/libmp codecs decoder, /libvo and/libao2 are video and audio outputs respectively.
DirectShow is similar, but classification is more complex. The modules in DirectShow are called "filter", and filters are connected by "pin. The access module corresponds to the Source Filter in DirectShow. Only the output pin does not contain the input pin. The Demux module corresponds to the splitter filter, which has one input pin and multiple output pins. The decoding module is a kind of transform filter with an input pin and an output pin. The output module corresponds to readering filter and has an input pin without an output pin. Of course, transform filter is not necessarily a decoder, it may be some other processing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.