yuv序列转avi源代码
来源:互联网 发布:图片制作软件下载 编辑:程序博客网 时间:2024/05/21 15:03
// http://yeyingxian.blog.163.com/blog/static/344712420096296270569/
yuv2avi,用ffmpeg SDK做的,用的还是output_example.c的一套代码。关键是写好codec_tag,I420是YUV格式,YV12是YVU格式。ffmpeg sdk下载地址
http://www.bairuitech.com/html/ruanjianxiazai/ffmpeg/20080414/89.html
#include "libavformat/avformat.h"const int WIDTH = 320;const int HEIGHT = 240;unsigned char buf[WIDTH *HEIGHT *3];int main(){ int i; FILE *fin = fopen("e:\\1031.yuv", "rb"); AVOutputFormat *pOutputFormat; AVFormatContext *pFormatCtxEnc; AVStream *video_st; AVCodecContext *pCodecCtxEnc; const char *filename = "1.avi"; av_register_all(); // auto detect the output format from the name pOutputFormat = guess_format(NULL, filename, NULL); // allocate the output media context pFormatCtxEnc = av_alloc_format_context(); pFormatCtxEnc->oformat = pOutputFormat; snprintf(pFormatCtxEnc->filename, sizeof(pFormatCtxEnc->filename), "%s", filename); video_st = av_new_stream(pFormatCtxEnc, 0); pCodecCtxEnc = video_st->codec; pCodecCtxEnc->codec_id = CODEC_ID_RAWVIDEO; pCodecCtxEnc->codec_type = CODEC_TYPE_VIDEO; pCodecCtxEnc->codec_tag = MKTAG('I', '4', '2', '0'); // put sample parameters // resolution must be a multiple of two pCodecCtxEnc->width = WIDTH; pCodecCtxEnc->height = HEIGHT; // frames per second pCodecCtxEnc->time_base.den = 25; pCodecCtxEnc->time_base.num = 1; pCodecCtxEnc->pix_fmt = PIX_FMT_YUV420P; // set the output parameters (must be done even if no parameters). if (av_set_parameters(pFormatCtxEnc, NULL) < 0) { return -1; } dump_format(pFormatCtxEnc, 0, filename, 1); if (url_fopen(&pFormatCtxEnc->pb, filename, URL_WRONLY) < 0) { fprintf(stderr, "Could not open '%s'\n", filename); return -1; } // write the stream header, if any av_write_header(pFormatCtxEnc); for ( i = 0; i < 300; i++) { fread(buf, WIDTH, HEIGHT, fin); fread(buf + WIDTH*HEIGHT, WIDTH/2, HEIGHT/2, fin); fread(buf + WIDTH*HEIGHT*5/4, WIDTH/2, HEIGHT/2, fin); AVPacket pkt; av_init_packet(&pkt); pkt.flags |= PKT_FLAG_KEY; pkt.stream_index= video_st->index; pkt.data= buf; pkt.size= WIDTH*HEIGHT*3/2; // write the compressed frame in the media file av_write_frame(pFormatCtxEnc, &pkt); } // write the trailer, if any av_write_trailer(pFormatCtxEnc); // free the streams for(i = 0; i < pFormatCtxEnc->nb_streams; i++) { av_freep(&pFormatCtxEnc->streams[i]->codec); av_freep(&pFormatCtxEnc->streams[i]); } if (!(pOutputFormat->flags & AVFMT_NOFILE)) { /* close the output file */ url_fclose(pFormatCtxEnc->pb); } /* free the stream */ av_free(pFormatCtxEnc); fclose(fin); return 0;}
- yuv序列转avi源代码
- yuv转avi
- jpeg序列转avi
- matlab下avi视频转yuv格式
- avi视频格式转yuv格式与播放yuv视频
- AVI转YUV的详细过程以及注意事项
- 实验二 图像文件的读写和转换(AVI转YUV)
- 最常用的blog,论坛,以及下载开源代码的网站,下载YUV序列的网站
- YUV 测试序列收集
- YUV 测试序列
- 彩色图像转YUV格式序列存取(陆)
- yuv h264 avi WindowsMediaPlayer播放成功,虽然时间很短
- YUV测试序列下载地址
- yuv测试序列下载地址
- YUV测试序列下载地址
- YUV测试序列下载地址
- YUV测试序列下载地址
- YUV测试序列下载地址
- Android发送和接收自定义Broadcast
- HDU3535分组背包
- CXF+Spring+Tomcat简明示例
- wifi的设计
- 什么是架构
- yuv序列转avi源代码
- 常用快捷键 vs2005 + sqlserver2005
- 实现函数atoi和itoa
- JAVA中synchronized和lock详解
- Google + SEO
- js 获取当前时间 YYYY-MM-DD
- 我的新浪博客
- x264函数说明(zhuan)
- 我拿了一个小铁棒 即时通讯