用mediastream+ortp库使用本机摄像头的简单程序

本文提供了一个使用mediastream和ortp库的本地摄像头程序示例,包括初始化、视频预览、循环处理及输出设置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用mediastream+ortp库使用本机摄像头的简单程序

#include "mediastreamer2/mediastream.h"
#include "mediastreamer2/msvideoout.h"
#include "mediastreamer2/msv4l.h"

int main(int argc, char *argv[]){
VideoStream *vs;
MSWebCam *cam;
MSVideoSize vsize;
int i;

vsize.width=MS_VIDEO_SIZE_CIF_W;
vsize.height=MS_VIDEO_SIZE_CIF_H;

ortp_init();
ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
ms_init();
cam=ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get());
//vs=video_preview_start(cam,vsize);
//while(1);
/* this is to test the sequence start/stop */
for(i=0;i<1;++i){
int n;
vs=video_preview_start(cam,vsize);

for(n=0;n<1000;++n){
#ifdef WIN32
MSG msg;
Sleep(100);
while (PeekMessage(&msg, NULL, 0, 0,1)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#else
struct timespec ts;
ts.tv_sec=0;
ts.tv_nsec=10000000;
nanosleep(&ts,NULL);

if (vs) video_stream_iterate(vs);
#endif

/* test code */
if (n==400)
{
printf("this is 400/n");
ms_ticker_detach (vs->ticker, vs->source);

vs->tee = ms_filter_new(MS_TEE_ID);

ms_filter_unlink(vs->pixconv,0, vs->output,0);

ms_filter_link(vs->pixconv,0,vs->tee,0);
ms_filter_link(vs->tee,0,vs->output,0);
ms_filter_link(vs->tee,1,vs->output,1);

//ms_filter_unlink(vs->tee,0,vs->output,0);
ms_ticker_attach (vs->ticker, vs->source);

}
if (n==500)
{
printf("this is 500/n");
int corner=1;
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);
}
if (n==600)
{
printf("this is 600/n");
int corner=2;
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);
}
if (n==700)
{
printf("this is 700/n");
int corner=3;
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);
}
if (n==800)
{
printf("this is 800/n");
int corner=-1;
ms_filter_call_method(vs->output,MS_VIDEO_OUT_SET_CORNER,&corner);
}
if (n==900)
{
printf("this is 900/n");
ms_ticker_detach (vs->ticker, vs->source);

ms_filter_unlink(vs->pixconv,0,vs->tee,0);
ms_filter_unlink(vs->tee,0,vs->output,0);
ms_filter_unlink(vs->tee,1,vs->output,1);
ms_filter_destroy(vs->tee);
vs->tee=NULL;

ms_filter_link(vs->pixconv,0, vs->output,0);


ms_ticker_attach (vs->ticker, vs->source);
}
}
video_preview_stop(vs);
}
return 0;
}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值