更多音视频知识分享 腾讯课堂 零声教育
v4l2-ctl -d /dev/video0 --list-formats-ext
V4L2 目前已经设置为MJPEG输出格式,对于使用到的FFmpeg解码也固定为MJPEG格式 需要需要修改为YUV,请自行修改程序,比如取消解码器过程,直接使用YUV数据进行编码
在include/config.h 修改分辨率格式和摄像头
#define CAMERA_DEV_NAME "/dev/video0"
#define CAMERA_WIDTH 640
#define CAMERA_HEIGHT 480
# 官方下载较新稳定的live555
git clone https://github.com/rgaufman/live555.git
# 进入live555目录
cd live555
# 产生配置文件
./genMakefiles linux
# 编译
make
# 安装
sudo make install
本项目已经把该https://github.com/rgaufman/live555.git 拷贝到live555目录,可以直接
cd live555
# 编译
make
# 安装
sudo make install
live555被安装到的路径:
在本项目目录直接make
make
生成v4l2_ipc_live555执行文件
运行
sudo ./v4l2_ipc_live555
运行该程序后终端打印出来url地址,客户端使用该url地址访问。
比如:ffplay rtsp://192.168.1.21:8554/video0
重点在于
通过gdb下断点重点debug的函数
#0 Camera::Camera (this=0x682e30, bufferCount=3) at /home/lqf/media/v4l2_ipc_live555/src/camera.cpp:3
#1 0x0000000000402870 in CameraFramedSource::CameraFramedSource (this=0x682d30, env=...)
at /home/lqf/media/v4l2_ipc_live555/src/CameraFramed.cpp:35
#2 0x0000000000403ed4 in main () at /home/lqf/media/v4l2_ipc_live555/src/main.cpp:23
sms->addSubsession(new H264OnDemandServerMediaSubsession(*env, new CameraFramedSource(*env))); 添加摄像头源
#0 Camera::initDev (this=0x682e30, devName=0x4419b8 "/dev/video0", width=1920, height=1920)
at /home/lqf/media/v4l2_ipc_live555/src/camera.cpp:13
#1 0x00000000004028bd in CameraFramedSource::CameraFramedSource (this=0x682d30, env=...)
at /home/lqf/media/v4l2_ipc_live555/src/CameraFramed.cpp:37
#2 0x0000000000403ed4 in main () at /home/lqf/media/v4l2_ipc_live555/src/main.cpp:23
CameraFramedSource里创建Camera和初始化Camera
#0 Camera::startStream (this=0x682e30) at /home/lqf/media/v4l2_ipc_live555/src/camera.cpp:143
#1 0x0000000000402914 in CameraFramedSource::CameraFramedSource (this=0x682d30, env=...)
at /home/lqf/media/v4l2_ipc_live555/src/CameraFramed.cpp:42
#2 0x0000000000403ed4 in main () at /home/lqf/media/v4l2_ipc_live555/src/main.cpp:23
启动源-启动摄像头
#0 H264Encoder::x264Init (this=0x682e80, picture=0x68afc0, width=1920, height=1080)
at /home/lqf/media/v4l2_ipc_live555/src/H264Encoder.cpp:26
#1 0x000000000040295e in CameraFramedSource::CameraFramedSource (this=0x682d30, env=...)
at /home/lqf/media/v4l2_ipc_live555/src/CameraFramed.cpp:43
#2 0x0000000000403ed4 in main () at /home/lqf/media/v4l2_ipc_live555/src/main.cpp:23
初始化h264编码器
有客户端访问触发读取流
#0 Camera::readFrame (this=0x682e30, picDest=0x68afc0, picFmt=AV_PIX_FMT_YUV420P, picWidth=1920, picHeight=1080)
at /home/lqf/media/v4l2_ipc_live555/src/camera.cpp:188
#1 0x0000000000402a2f in CameraFramedSource::doGetNextFrame (this=0x682d30)
at /home/lqf/media/v4l2_ipc_live555/src/CameraFramed.cpp:56
#2 0x0000000000436ca1 in StreamParser::ensureValidBytes1(unsigned int) ()
#3 0x00000000004229dd in H264or5VideoStreamParser::parse() ()
#4 0x0000000000420341 in MPEGVideoStreamFramer::continueReadProcessing() ()
#5 0x000000000042c493 in H264or5Fragmenter::doGetNextFrame() ()
#6 0x0000000000406ee7 in MultiFramedRTPSink::packFrame() ()
#7 0x000000000040702e in MultiFramedRTPSink::continuePlaying() ()
#8 0x000000000041b0f0 in StreamState::startPlaying(Destinations*, unsigned int, void (*)(void*), void*, void (*)(void*, unsigned char), void*) ()
#9 0x000000000041b288 in OnDemandServerMediaSubsession::startStream(unsigned int, void*, void (*)(void*), void*, unsigned short&, unsigned int&, void (*)(void*, unsigned char), void*) ()
#10 0x000000000040b767 in RTSPServer::RTSPClientSession::handleCmd_PLAY(RTSPServer::RTSPClientConnection*, ServerMediaSubsession*, char const*) ()
#11 0x000000000040cdcd in RTSPServer::RTSPClientSession::handleCmd_withinSession(RTSPServer::RTSPClientConnection*, char const*, char const*, char const*, char const*) ()
---Type <return> to continue, or q <return> to quit---
#12 0x000000000040a686 in RTSPServer::RTSPClientConnection::handleRequestBytes(int) ()
#13 0x0000000000408867 in GenericMediaServer::ClientConnection::incomingRequestHandler() ()
#14 0x000000000043b5cd in BasicTaskScheduler::SingleStep(unsigned int) ()
#15 0x000000000043cacc in BasicTaskScheduler0::doEventLoop(char volatile*) ()
#16 0x0000000000403f57 in main () at /home/lqf/media/v4l2_ipc_live555/src/main.cpp:26
本项目基于https://github.com/lam2003/v4l2_webstream_server.git进行修改
主要改动:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。