Use libvlc for Video Transcoding

Source: Internet
Author: User

The transcoding function was added to the video forwarding program yesterday: the input (Stream/file) is transcoded into the video stream and audio stream in the specified format.

After research, we found that the vlc comes with the transcoding function, but the parameter settings are troublesome.

 

Our specific requirements are:

Input: rtsp stream or udp multicast data (there is no difference in setting transcoding parameters)

Output: H264 video (644 k) + mp2 audio (56 k), total bit rate 700 k, ts encapsulation, udp forwarding to local unicast

The complete transcoding parameters for calling libvlc are:

Sendudp = "-- sout = # duplicate {dst = \" transcode {venc = x264 {profile = baseline}, vcodec = h264, acodec = mpga, vb = 644, AB = 56}: std {access = udp, mux = ts, dst = 127.0.0.1: "+ m_strport + "}\"}"

 

If you directly use the vlc player for transcoding, run the following command:

Vlc udp: // @ 230.0.0.1: 8001 -- sout '# duplicate {dst = "transcode {venc = x264 {profile = baseline}, vcodec = h264, acodec = mpga, vb = 644, AB = 56 }: std {access = udp, mux = ts, dst = 127.0.0.1: 18009 }"}'

 

Considering that the transcoding parameters may change in the future, you can set the parameters in the configuration file. When using the file, you can configure the relevant transcoding parameters as required. If the value is not set, no transcoding is performed.

In this way, the code when we start libvlc for forwarding (transcoding) is as follows:

 1 void CInputVideoVLC::InitVlc(int localport)
2 {
3 string m_strport = "";
4 string sendudp = "";
5 m_strport = CStringExt::Int2String(localport);
6 //sendudp = "--sout=#duplicate{dst=std{access=udp,mux=ts,dst=127.0.0.1:" + m_strport + "}}";
7
8 //transcode
9 sendudp = "--sout=#duplicate{dst=\"";
10 //sendudp += "transcode{venc=x264{profile=baseline},vcodec=h264,acodec=mpga,vb=644,ab=56}:";
11 sendudp += m_strTranscode;
12 sendudp += "std{access=udp,mux=ts,dst=127.0.0.1:" + m_strport + "}\"}";
13
14 const char * const vlc_args[] = {
15 "-I", "dummy", // Don't use any interface
16 "--ignore-config", // Don't use VLC's config
17 "--extraintf=logger", //log anything
18 "--verbose=0", //be much more verbose then normal for debugging purpose
19 "--repeat",
20 sendudp.c_str()
21 };
22 //printf("sendudp:%s\n", sendudp.c_str());
23
24 libvlc_exception_init(&_vlcexcep); //Initialize an exception structure
25 _vlcinstance = libvlc_new(sizeof (vlc_args) / sizeof (vlc_args[0]), vlc_args, &_vlcexcep); //Calculation character space
26 raise(&_vlcexcep);
27 _mp = libvlc_media_player_new(_vlcinstance, &_vlcexcep); //Create an empty Media Player object
28 raise(&_vlcexcep);
29 }

 

Specific transcoding parameter description, you can view the vlc documentation: http://www.videolan.org/doc/streaming-howto/en/ch03.html

And related examples: http://www.videolan.org/doc/streaming-howto/en/ch04.html

You can also refer to: http://www.cnitblog.com/buf/archive/2011/08/06/74993.html

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.