栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ffmpeg create

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ffmpeg create

创建一个原始的视频文件.
不足百行代码, 见识一下什么叫yuv420p 原始数据, 直接手工生成.
怎样播放视频原始数据.
ffplay -f rawvideo -pix_fmt yuv420p -video_size 800x600 video

#include 

static void fill_yuv_image(uint8_t *data[4], int linesize[4],
                           int width, int height, int frame_index)
{
    int x, y;

    
    for (y = 0; y < height; y++)
        for (x = 0; x < width; x++)
            data[0][y * linesize[0] + x] = x + y + frame_index * 3;

    
    for (y = 0; y < height / 2; y++) {
        for (x = 0; x < width / 2; x++) {
            data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;
            data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;
        }
    }
}

int main(int argc, char **argv)
{

    if (argc != 2) {
        fprintf(stderr, 
                "API example program to show how to create an image n"
                "This program generates a series of pictures of 800*600 sizenn"
				"Usage: %s output_file nn"
                , argv[0]);
        exit(1);
    }
    char *filename = argv[1];
    FILE *file = fopen(filename, "wb");
    if (!file) {
        fprintf(stderr, "Could not open destination file %sn", filename);
        exit(1);
    }

    uint8_t *data[4]={0};
    int linesize[4] ={0};
    int w = 800, h = 600 ;
    enum AVPixelFormat pix_fmt = AV_PIX_FMT_YUV420P;
	int ret;
    
	//data, linesize 被赋值并可以储存数据了.
	//当然你不用av_image_alloc 用其它malloc 也可以,但注意数据排布要符合要求.
    if ((ret = av_image_alloc(data, linesize,
                              w, h, pix_fmt, 16)) < 0) {
        fprintf(stderr, "Could not allocate source imagen");
        goto end;
    }

    int bufsize = ret;
	int i;
    for (i = 0; i < 100; i++) {
        
        fill_yuv_image(data, linesize, w, h, i);

        
        fwrite(data[0], 1, bufsize, file);
    }

    fprintf(stderr, "Play the output file with the command:n"
           "ffplay -f rawvideo -pix_fmt %s -video_size %dx%d %sn",
           av_get_pix_fmt_name(pix_fmt), w, h, filename);

end:
    fclose(file);
    av_freep(&data[0]);
    return ret < 0;
}

上传视频不方便,就免去了.视频还是挺漂亮的.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/738457.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号