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
关注
打赏