您当前的位置: 首页 > 

令狐掌门

暂无认证

  • 0浏览

    0关注

    513博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ffmpeg对视频数据进行h264编码为并封装成mp4

令狐掌门 发布时间:2021-05-24 22:37:00 ,浏览量:0

ffmpeg抽取视频1.mp4 30秒的rgb数据,指令如下:

ffmpeg -i 1.mp4 -t 30 -pix_fmt rgb24 -s 960x640 data24.rgb

-t 30表示时间,30秒

下面是rgb–>yuv–>h264–>mp4的流程

/*

ffmpeg视频编码 rgb转mp4

*/

#include 

extern "C"
{
	#include 
	#include 
}

using namespace std;

#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avutil.lib")
#pragma comment(lib,"swscale.lib")

#define CHANNEL 3   //3通道

int main()
{
	char infile[] = "D:/VideoTest/data24.rgb";
	char outfile[] = "D:/VideoTest/rgb.mp4";

	av_register_all();
	avcodec_register_all();

	FILE *fp = fopen(infile, "rb");

	if (!fp)
	{
		cout max_b_frames = 0;

	c->pix_fmt = AV_PIX_FMT_YUV420P;
	c->codec_id = AV_CODEC_ID_H264;
	c->thread_count = 4;
	
	//全局的编码信息
	c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

    //打开编码器
	int ret = avcodec_open2(c, codec, NULL);
	if (ret < 0)
	{
		cout codecpar, c);

	cout width = width;
	yuv->height = height;
	ret = av_frame_get_buffer(yuv, CHANNEL * 8);

	if (ret < 0)
	{
		cout             
关注
打赏
1652240117
查看更多评论
0.0359s