FFMPEG(一)--读取本地视频流和网络视频流

1.读取本地视频流

// An highlighted block
#include<iostream>
using namespace std;
extern "C"
{
#include<libavcodec\avcodec.h>
#include<libavformat\avformat.h>
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
int main()
{
	printf("%s\n", avcodec_configuration());

	av_register_all();

	AVFormatContext *pFormat = NULL;
	const char* path = "D:/vswork/ffmpeg/work/11.mp4";
	int ret=avformat_open_input(&pFormat,path,NULL,NULL);	//该函数用于打开多媒体数据并且获取一些信息
	//int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options);
	if (ret)
	{
		printf("avformat_open_input is faild\n");
		return -1;
	}
	printf("avformat_open_input succeed\n");

	ret=avformat_find_stream_info(pFormat,NULL);	//它可以从读取到的包中获得到流的信息
	//int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
	if (ret)
	{
		printf("avformat_find_stream_info is faild\n");
		return -1;
	}

	int time = pFormat->duration;
	int mbittime = (time / 1000000)/60;
	int mmintime = (time / 1000000) % 60;
	printf("%d分%d秒\n", mbittime, mmintime);
	av_dump_format(pFormat, NULL, path, 0);		//最后一个参数  0:打印输入流   1:打印输出流
	//void av_dump_format(AVFormatContext *ic,int index,const char *url,int is_output);

	system("pause");
	return 0;
}

在这里插入图片描述
2.读取网络视频流

// An highlighted block
#include<iostream>
using namespace std;

extern "C"
{
#include<libavcodec\avcodec.h>
#include<libavformat\avformat.h>
#include<libavutil\opt.h>
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")

int main()
{
	//测试动态链接库是否成功
	printf("%s\n", avcodec_configuration());
	//注册dll
	av_register_all();
	//网络
	avformat_network_init();

	AVFormatContext *pFormat = NULL;

	//const char* path = "D:/vswork/ffmpeg/work/11.mp4";
	//http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8
	const char *path = "http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8";
	AVDictionary* opt = NULL;
	av_dict_set(&opt,"rtsp_transport","tcp",0);
	av_dict_set(&opt, "max_delay", "550", 0);

	int ret=avformat_open_input(&pFormat,path,NULL,&opt);	//该函数用于打开多媒体数据并且获取一些信息
	//int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options);
	if (ret)
	{
		printf("avformat_open_input is faild\n");
		return -1;
	}
	printf("avformat_open_input succeed\n");

	ret=avformat_find_stream_info(pFormat,NULL);	//它可以从读取到的包中获得到流的信息
	//int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);
	if (ret)
	{
		printf("avformat_find_stream_info is faild\n");
		return -1;
	}

	int time = pFormat->duration;
	int mbittime = (time / 1000000)/60;
	int mmintime = (time / 1000000) % 60;
	printf("%d分%d秒\n", mbittime, mmintime);
	av_dump_format(pFormat, NULL, path, 0);		//最后一个参数  0:打印输入流   1:打印输出流
	//void av_dump_format(AVFormatContext *ic,int index,const char *url,int is_output);

	system("pause");
	return 0;
}

在这里插入图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值