创建一个原始的视频文件.
不足百行代码, 见识一下什么叫yuv420p 原始数据, 直接手工生成.
怎样播放视频原始数据.
ffplay -f rawvideo -pix_fmt yuv420p -video_size 800x600 video
#includestatic 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; }
上传视频不方便,就免去了.视频还是挺漂亮的.



