#include <QCoreApplication>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
}
//等于命令:
//ffmpeg -list_devices true -f dshow -i dummy
//Show Dshow Device
void show_dshow_device()
{
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options,"list_devices","true",0);
AVInputFormat *iformat = av_find_input_format("dshow");
qDebug("========Device Info=============\n");
avformat_open_input(&pFormatCtx,"video=dummy",iformat,&options);
printf("================================\n");
}
//Show Dshow Device Option
void show_dshow_device_option(){
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options,"list_options","true",0);
AVInputFormat *iformat = av_find_input_format("dshow");
printf("========Device Option Info======\n");
avformat_open_input(&pFormatCtx,"video=Integrated Camera",iformat,&options);
printf("================================\n");
}
//Show VFW Device
void show_vfw_device(){
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVInputFormat *iformat = av_find_input_format("vfwcap");
printf("========VFW Device Info======\n");
avformat_open_input(&pFormatCtx,"list",iformat,NULL);
printf("=============================\n");
}
//Show AVFoundation Device
void show_avfoundation_device(){
AVFormatContext *pFormatCtx = avformat_alloc_context();
AVDictionary* options = NULL;
av_dict_set(&options,"list_devices","true",0);
AVInputFormat *iformat = av_find_input_format("avfoundation");
printf("==AVFoundation Device Info===\n");
avformat_open_input(&pFormatCtx,"",iformat,&options);
printf("=============================\n");
}
#define USE_DSHOW 1
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
int i, videoindex;
av_register_all();
avformat_network_init();
avdevice_register_all();//Register Device
//列出设备
show_dshow_device();
AVFormatContext *pFormatCtx = avformat_alloc_context();
#if USE_DSHOW
AVInputFormat *ifmt=av_find_input_format("dshow");
//摄像头的名字
/*
========Device Info=============
[dshow @ 03d020a0] DirectShow video devices
[dshow @ 03d020a0] "Integrated Camera"
[dshow @ 03d020a0] DirectShow audio devices
[dshow @ 03d020a0] "楹﹀厠椋庨樀鍒?(Realtek High Definit
================================*
*/
/* 如果在Linux下:
AVInputFormat *ifmt=av_find_input_format("video4linux2");
if(avformat_open_input(&pFormatCtx,"/dev/video0",ifmt,NULL)!=0){
printf("Couldn't open input stream.\n");
return -1;
*/
//if(avformat_open_input(&pFormatCtx, "video=Integrated Camera",ifmt,NULL)!=0)
if(avformat_open_input(&pFormatCtx, "video=EasyCamera",ifmt,NULL)!=0)
{
printf("Couldn't open input stream.\n");
return -1;
}
#else
AVInputFormat *ifmt=av_find_input_format("vfwcap");
if(avformat_open_input(&pFormatCtx,"0",ifmt,NULL)!=0){
printf("Couldn't open input stream.\n");
return -1;
}
#endif
if(avformat_find_stream_info(pFormatCtx, NULL)<0)
{
printf("Couldn't find stream information.\n");
return -1;
}
videoindex=-1;
for(i=0; i<pFormatCtx->nb_streams; i++)
{
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
videoindex=i;
}
}
//打印音视频设备的信息
printf("videoindex=%d\n", videoindex);
av_dump_format(pFormatCtx, 0, 0, 0);
if(videoindex==-1)
{
printf("Couldn't find a video stream.\n");
return -1;
}
AVCodecContext *pCodecCtx=pFormatCtx->streams[videoindex]->codec;
AVCodec *pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
printf("Codec not found.\n");
return -1;
}
if(avcodec_open2(pCodecCtx, pCodec, NULL)<0)
{
printf("Could not open codec.\n");
return -1;
}
AVFrame *pFrame;//*pFrameYUV;
pFrame=av_frame_alloc();
//pFrameYUV=av_frame_alloc();
//uint8_t *out_buffer=(uint8_t *)av_malloc(avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height));
//avpicture_fill((AVPicture *)pFrameYUV, out_buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
int ret, got_picture;
AVPacket *packet=(AVPacket *)av_malloc(sizeof(AVPacket));
char strName[512]={0};
sprintf(strName, "e:/video/output_%d_%d.yuyv422", pCodecCtx->width, pCodecCtx->height);
FILE *fp=fopen(strName,"wb");
//这里已经需不要了
// struct SwsContext *img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height,
// pCodecCtx->pix_fmt, //从摄像头中肚读出的原始格式为:yuyv422
// pCodecCtx->width, pCodecCtx->height,
// PIX_FMT_YUV420P, SWS_BICUBIC,
// NULL, NULL, NULL);
///这里打印出视频的宽高
printf("w= %d h= %d\n",pCodecCtx->width, pCodecCtx->height);
//return -1;
///我们就读取100张图像
for(int i=0;i<100;i++)
{
//读入到 packet
if(av_read_frame(pFormatCtx, packet) < 0)
{
break;
}
if(packet->stream_index==videoindex)
{
// packet ---> pFrame
ret = avcodec_decode_video2(
pCodecCtx,
pFrame, //输出
&got_picture,
packet //输入
);
if(ret < 0){
printf("Decode Error.\n");
return -1;
}
if(got_picture)
{
/*
sws_scale(img_convert_ctx,
(const uint8_t* const*)pFrame->data, //输入源
pFrame->linesize, 0,
pCodecCtx->height,
pFrameYUV->data, //目的
pFrameYUV->linesize);
printf("%d\n", i);
int y_size=pCodecCtx->width*pCodecCtx->height;
fwrite(pFrameYUV->data[0],1,y_size, fp); //Y
fwrite(pFrameYUV->data[1],1,y_size/4,fp); //U
fwrite(pFrameYUV->data[2],1,y_size/4,fp); //V
*/
// yuyv422 一帧存储为 2倍 的 w×h 个字节
printf("%d\n", i);
int y_size=pCodecCtx->width*pCodecCtx->height;
fwrite(pFrame->data[0],1,y_size*2, fp);
}
}
av_free_packet(packet);
}
//sws_freeContext(img_convert_ctx);
fclose(fp);
//av_free(out_buffer);
//av_free(pFrameYUV);
avcodec_close(pCodecCtx);
avformat_close_input(&pFormatCtx);
printf("finish\n");
return a.exec();
}
没有合适的资源?快使用搜索试试~ 我知道了~
ffmpeg编程读取摄像头信息,保存为裸yuv420p、yuyv422视频流
共134个文件
h:91个
dll:8个
lib:8个
4星 · 超过85%的资源 需积分: 49 81 下载量 104 浏览量
2019-01-05
22:51:07
上传
评论 4
收藏 11.15MB RAR 举报
温馨提示
ffmpeg编程:读取摄像头信息,保存为裸yuv420p、yuyv422视频流,参见文档:https://blog.csdn.net/dijkstar/article/details/85881709
资源推荐
资源详情
资源评论
收起资源包目录
ffmpeg编程读取摄像头信息,保存为裸yuv420p、yuyv422视频流 (134个子文件)
recordCam.pro.user.163ce12 23KB
recordCam.pro.user.163ce12 23KB
libavutil.dll.a 275KB
libavcodec.dll.a 142KB
libavformat.dll.a 103KB
libavfilter.dll.a 54KB
libswscale.dll.a 23KB
libswresample.dll.a 14KB
libavdevice.dll.a 11KB
libpostproc.dll.a 7KB
main.cpp 7KB
main.cpp 7KB
avutil-54.def 10KB
avcodec-56.def 6KB
avformat-56.def 4KB
avfilter-5.def 2KB
swscale-3.def 781B
avdevice-56.def 491B
swresample-1.def 433B
postproc-53.def 233B
avcodec-56.dll 18.74MB
avformat-56.dll 5.57MB
avfilter-5.dll 2.21MB
avdevice-56.dll 1.3MB
avutil-54.dll 442KB
swscale-3.dll 437KB
swresample-1.dll 264KB
postproc-53.dll 119KB
ffplay.exe 464KB
ffmpeg.exe 317KB
ffprobe.exe 149KB
avcodec.h 176KB
avformat.h 100KB
avfilter.h 56KB
opt.h 37KB
pixfmt.h 32KB
frame.h 23KB
swresample.h 19KB
avio.h 18KB
intreadwrite.h 18KB
avdevice.h 16KB
mem.h 14KB
old_pix_fmts.h 14KB
pixdesc.h 14KB
common.h 14KB
avstring.h 13KB
swscale.h 12KB
old_codec_ids.h 10KB
log.h 10KB
samplefmt.h 10KB
buffer.h 10KB
channel_layout.h 9KB
avutil.h 8KB
imgutils.h 8KB
dict.h 8KB
bprint.h 8KB
buffersink.h 7KB
parseutils.h 7KB
vdpau.h 7KB
version.h 6KB
xvmc.h 6KB
error.h 5KB
vda.h 5KB
timecode.h 5KB
eval.h 5KB
mathematics.h 5KB
fifo.h 5KB
buffersrc.h 5KB
cpu.h 5KB
audio_fifo.h 4KB
attributes.h 4KB
rational.h 4KB
vaapi.h 4KB
version.h 4KB
dv_profile.h 4KB
stereo3d.h 4KB
hash.h 4KB
asrc_abuffer.h 3KB
downmix_info.h 3KB
display.h 3KB
threadmessage.h 3KB
avfft.h 3KB
postprocess.h 3KB
version.h 3KB
hmac.h 3KB
bswap.h 3KB
crc.h 3KB
timestamp.h 3KB
file.h 2KB
version.h 2KB
avcodec.h 2KB
dxva2.h 2KB
vorbis_parser.h 2KB
blowfish.h 2KB
avassert.h 2KB
base64.h 2KB
pixelutils.h 2KB
lzo.h 2KB
sha512.h 2KB
ripemd.h 2KB
共 134 条
- 1
- 2
资源评论
- 电饭锅吃的老巢2019-07-04资源不错 先使用
dijkstar
- 粉丝: 266
- 资源: 120
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功