Use live555 to live camera data from V4L2

Source: Internet
Author: User

Using live555 to live the camera data from V4L2, in my project, the basic idea is to use V4L2 to capture camera data, then encode the camera data using the x264 library, format the H264 data, and then write the data to the named pipe. Finally, we use live555 to send out the data from the pipeline to realize the video broadcast.

In my project commissioning process, the use of Logitech C270 Camera, out of the YUYV data format. x264 and live555 Use the latest libraries. The project catalog is as follows:

├──h264framedlivesource.cpp├──h264videostreamer.cpp├──include│  ├──encoder│ & nbsp │  ├──encoder_define.hh│  │  ├──h264framedlivesource.hh│  │   └──stdint.h│  ├──live555│  │  ├──basicUsageEnvironment│  │   ├──groupsock│  │  ├──livemedia│  │  └──usageenvironment│ &n Bsp └──x264│  ├──x264_config.h│  └──x264.h├──lib│  ├──livelib│   │  ├──libbasicusageenvironment.a│  │  ├──libgroupsock.a│  │       ├──libliveMedia.a│  │  └──libUsageEnvironment.a│  └──x264lib│   ├──libx264.a│  └──libx264.so.148└──makefile 
A new device class is created in H264FramedLiveSource.cpp to implement V4L2 data acquisition and x264 encoding. Its function is defined as follows:

/*============================================================================= * # FileName: H264FRAMEDLIVESOURCE.HH * # Desc: * # * # Author:licaibiao * # Version: * # La stchange:2017-02-24 * =============================================================================*/#ifndef _ H264FRAMEDLIVESOURCE_HH #define _H264FRAMEDLIVESOURCE_HH #include <FramedSource.hh> #include <
    usageenvironment.hh> #include "encoder_define.hh" class Device {public:void init_mmap (void);
    void Init_camera (void);
    void Init_encoder (void);  
    void Open_camera (void);
    void Close_camera (void);
    void Read_one_frame (void);
    void GetNextFrame (void);
    void start_capture (void);
    void stop_capture (void); 
    void Close_encoder ();
    int camera_able_read (void);
    void Compress_begin (Encoder *en, int width, int height);
    int Compress_frame (Encoder *en, int type, char *in, int len, char *out); void Compress_end (ENCoder *en);
    void Init ();
    void Intoloop ();;
void Destory ();
	Public:int FD;
    FILE *save_fd;
    int n_nal;
	int Frame_len;
	Char *h264_buf;
	unsigned int n_buffer;
    Encoder en;
    FILE *H264_FP;
	Buftype *usr_buf;
FILE *pipe_fd;
}; #endif
H264VideoStreamer.cpp implementation of RTSP creation. Its code is implemented as follows:

/********** This library was free software;  You can redistribute it and/or modify it under the terms of the GNU Lesser general public License as published by the free Software Foundation; Either version 3 of the License, or (at your option) any later version.

(see Download and compile installation of x264 and live555 libraries, as already mentioned in the previous blog, is not repeated here. Compile and run the entire project as follows:

[Root@redhat pipelive]# ls
H264FramedLiveSource.cpp  h264framedlivesource.o  h264videostreamer  H264VideoStreamer.cpp  h264videostreamer.o  include  Lib  Makefile
[root@redhat pipelive]#./  H264videostreamer

Camera driver name is:uvcvideo
camera device name IS:UVC camera (046d:0825)
camera bus  information:usb-0000:00:1a.0-1.1
n_buffer = 4
x264 [WARNING]: lookaheadless mb-tree requires intra refresh or Infinite keyint
x264 [INFO]: Using CPU capabilities:mmx2 sse2fast SSSE3 SSE4.2 AVX
x264 [INFO]: Profile 4 : 2:2, Level 3.0, 4:2:2 8-bit
Play This stream using the URL "Rtsp://192.168.0.127:8554/teststream"
Beginning St
reaming ... Beginning to read from file ...
Open the network stream Rtsp://192.168.0.127:8554/teststream in VLC player to see the data in the camera:




The actual test, using the pipeline to transmit the camera data will appear some delay, if the picture size set in 320*240 delay will be very small, but the picture size set in 640*480, the delay phenomenon will be very obvious. This is also related to the camera I use, and the UVC camera can read data relatively slowly.

The complete project can be downloaded from here: live555 Live camera data from V4L2



================2018-03-16 Update ==================

Because the project contains x264 dynamic library files, a user download the project files after antivirus software reported virus ... The download link failed after being reported ....

If there is a need for engineering code to do a reference can be in the comment area to leave a mailbox, see after the mail sent to the person in need.





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.