文章目录
推荐一个零声学院免费公开课程,个人觉得老师讲得不错,分享给大家: Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,TCP/IP,协程,DPDK等技术内容,立即学习
开发环境搭建
windows 开发环境搭建
windows下安装搭建android开发环境
Qt在线安装
Qt 安卓开发环境搭建
linux 开发环境搭建
开发测试
简单的测试
开发引入第三方库
测试vlc部分代码
#include "widget.h"
#include <QApplication>
#include <vlc/vlc.h>
#include <QDebug>
#include <QMutex>
#include "main.h"
struct Context {
QMutex mutex;
uchar *pixels;
};
CIns* CIns::m_ins = nullptr;
static void *lock(void *opaque, void **planes)
{
struct Context *ctx = (struct Context *)opaque;
ctx->mutex.lock();
// 告诉 VLC 将解码的数据放到缓冲区中
*planes = ctx->pixels;
return nullptr;
}
// 获取 argb 图片并保存到文件中
static void unlock(void *opaque, void *picture, void *const *planes)
{
Q_UNUSED(picture);
struct Context *ctx = (struct Context *)opaque;
unsigned char *data = static_cast<unsigned char *>(*planes);
static int frameCount = 1;
QImage image(data, 512, 288, QImage::Format_ARGB32);
// image.save(QString("frame_%1.png").arg(frameCount++));
emit CIns::Ins()->SigImage(image);
ctx->mutex.unlock();
}
static void display(void *opaque, void *picture)
{
Q_UNUSED(picture);
(void)opaque;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
QObject::connect(CIns::Ins(), &CIns::SigImage, &w, &Widget::SlotImage);
const char* const vlc_args[] = {
"--demux=h264",
"--ipv4",
"--no-prefer-system-codecs",
"--rtsp-caching=300",
"--network-caching=500", //网络额外缓存值 (ms)
"--rtsp-frame-buffer-size=10000000",
"--rtsp-tcp", //RTSP采用TCP传输方式
};
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
struct Context ctx;
ctx.pixels = new uchar[512 * 288 * 4];
memset(ctx.pixels, 0, 512 * 288 * 4);
//libvlc_time_t length;
/* Load the VLC engine */
inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
QString strUrl = "rtsp://wowzaec2demo.streamlock.net/vod/mp4";
m = libvlc_media_new_location (inst, strUrl.toStdString().c_str());
mp = libvlc_media_player_new_from_media (m);
// libvlc_media_player_set_hwnd(mp, (void *)wgt.winId());
// 设置回调,用于提取帧或者在界面上显示。
libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
libvlc_video_set_format(mp, "RGBA", 512, 288, 512 * 4);
libvlc_media_release (m);
libvlc_media_player_play (mp);
int ret = a.exec();
libvlc_media_player_stop (mp);
// Free the media_player
libvlc_media_player_release (mp);
libvlc_release (inst);
return ret;
参考文档
配置Qt5.12.3的安卓开发环境
Qt5.14.2在Android项目中添加第三方库(.a,.so)
android开发cmake编译引入第三方库的常用写法