Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36915
  • 博文数量: 23
  • 博客积分: 30
  • 博客等级: 民兵
  • 技术积分: 137
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-07 10:58
个人简介

http://blog.csdn.net/shanshanpt/article/details/7419184

文章存档

2017年(22)

2012年(1)

我的朋友

分类: 嵌入式

2017-02-09 14:37:49

前言

文章主要对H264视频流封装为MP4格式文件的讲述,有实时H264视频流的封装和h264文件的封装,本文主要针对飞思卡尔I.MX6Q-vpu视频编码后的视频封装,所以没涉及到音频,


一、h264视频文件的封装

这部分代码主要是从雷博那里借鉴过来的,雷博的文章是音频和视频封装,我这里只实现视频的封装,雷博的文章网站:http://blog.csdn.net/leixiaohua1020/article/details/39802913/,具体实现方法差不多,就是少了音频这一路,代码如下:


[cpp] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. #include   
  2. #define __STDC_CONSTANT_MACROS  
  3. #include   
  4. /* 
  5.  
  6. FIX: H.264 in some container format (FLV, MP4, MKV etc.) need  
  7.  
  8. "h264_mp4toannexb" bitstream filter (BSF) 
  9.  
  10.   *Add SPS,PPS in front of IDR frame 
  11.  
  12.   *Add start code ("0,0,0,1") in front of NALU 
  13.  
  14. H.264 in some container (MPEG2TS) don't need this BSF. 
  15.  
  16. */  
  17.   
  18. //'1': Use H.264 Bitstream Filter   
  19.   
  20. #define USE_H264BSF 0  
  21. /* 
  22.  
  23. FIX:AAC in some container format (FLV, MP4, MKV etc.) need  
  24.  
  25. "aac_adtstoasc" bitstream filter (BSF) 
  26.  
  27. */  
  28.   
  29. //'1': Use AAC Bitstream Filter   
  30.   
  31. #define USE_AACBSF 0  
  32. int main(int argc, char* argv[])  
  33.   
  34. {  
  35.   
  36.     AVOutputFormat *ofmt = NULL;  
  37.     //Input AVFormatContext and Output AVFormatContext  
  38.     AVFormatContext *ifmt_ctx_v = NULL, *ifmt_ctx_a = NULL,*ofmt_ctx = NULL;  
  39.     AVPacket pkt;  
  40.     int ret, i;  
  41.     int videoindex_v=0,videoindex_out=0;  
  42.     int frame_index=0;  
  43.     int64_t cur_pts_v=0,cur_pts_a=0;  
  44.     //const char *in_filename_v = "cuc_ieschool.ts";//Input file URL  
  45.     const char *in_filename_v = "vpu.h264";  
  46.     //const char *in_filename_a = "cuc_ieschool.mp3";  
  47.     //const char *in_filename_a = "gowest.m4a";  
  48.     //const char *in_filename_a = "gowest.aac";  
  49.     const char *in_filename_a = "huoyuanjia.mp3";  
  50.     const char *out_filename = "vpu.mp4";//Output file URL  
  51.     av_register_all();  
  52.     //Input  
  53.     if ((ret = avformat_open_input(&ifmt_ctx_v, in_filename_v, 0, 0)) < 0) {  
  54.         printf( "Could not open input file.");  
  55.         goto end;  
  56.   
  57.     }  
  58.     if ((ret = avformat_find_stream_info(ifmt_ctx_v, 0)) < 0) {  
  59.         printf( "Failed to retrieve input stream information");  
  60.         goto end;  
  61.     }  
  62.     /*if ((ret = avformat_open_input(&ifmt_ctx_a, in_filename_a, 0, 0)) < 0) { 
  63.         printf( "Could not open input file."); 
  64.         goto end; 
  65.     } 
  66.     if ((ret = avformat_find_stream_info(ifmt_ctx_a, 0)) < 0) { 
  67.         printf( "Failed to retrieve input stream information"); 
  68.         goto end; 
  69.     }*/  
  70.     printf("===========Input Information==========\n");  
  71.     av_dump_format(ifmt_ctx_v, 0, in_filename_v, 0);  
  72.     //av_dump_format(ifmt_ctx_a, 0, in_filename_a, 0);  
  73.     printf("======================================\n");  
  74.     //Output  
  75.     avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);  
  76.     if (!ofmt_ctx) {  
  77.         printf( "Could not create output context\n");  
  78.         ret = AVERROR_UNKNOWN;  
  79.         goto end;  
  80.     }  
  81.     ofmt = ofmt_ctx->oformat;  
  82.     printf("ifmt_ctx_v->nb_streams=%d\n",ifmt_ctx_v->nb_streams);  
  83.     for (i = 0; i < ifmt_ctx_v->nb_streams; i++) {  
  84.         //Create output AVStream according to input AVStream  
  85.         //if(ifmt_ctx_v->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)  
  86.         {  
  87.             AVStream *in_stream = ifmt_ctx_v->streams[i];  
  88.             AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);  
  89.             videoindex_v=i;  
  90.             if (!out_stream) {  
  91.                 printf( "Failed allocating output stream\n");  
  92.                 ret = AVERROR_UNKNOWN;  
  93.                 goto end;  
  94.             }  
  95.             videoindex_out=out_stream->index;  
  96.             //Copy the settings of AVCodecContext  
  97.             if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) {  
  98.                 printf( "Failed to copy context from input to output stream codec context\n");  
  99.                 goto end;  
  100.             }  
  101.             out_stream->codec->codec_tag = 0;  
  102.             if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)  
  103.                 out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;  
  104.             //break;  
  105.         }  
  106.     }  
  107. /* 
  108.     for (i = 0; i < ifmt_ctx_a->nb_streams; i++) { 
  109.         //Create output AVStream according to input AVStream 
  110.         if(ifmt_ctx_a->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO){ 
  111.             AVStream *in_stream = ifmt_ctx_a->streams[i]; 
  112.             AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec); 
  113.             audioindex_a=i; 
  114.             if (!out_stream) { 
  115.                 printf( "Failed allocating output stream\n"); 
  116.                 ret = AVERROR_UNKNOWN; 
  117.                 goto end; 
  118.             } 
  119.             audioindex_out=out_stream->index; 
  120.             //Copy the settings of AVCodecContext 
  121.             if (avcodec_copy_context(out_stream->codec, in_stream->codec) < 0) { 
  122.                 printf( "Failed to copy context from input to output stream codec context\n"); 
  123.                 goto end; 
  124.             } 
  125.             out_stream->codec->codec_tag = 0; 
  126.             if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) 
  127.                 out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER; 
  128.             break; 
  129.         } 
  130.     } 
  131. */  
  132.     printf("==========Output Information==========\n");  
  133.     av_dump_format(ofmt_ctx, 0, out_filename, 1);  
  134.     printf("======================================\n");  
  135.     //Open output file  
  136.     if (!(ofmt->flags & AVFMT_NOFILE)) {  
  137.         if (avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE) < 0) {  
  138.             printf( "Could not open output file '%s'", out_filename);  
  139.             goto end;  
  140.         }  
  141.     }  
  142.     //Write file header  
  143.     if (avformat_write_header(ofmt_ctx, NULL) < 0) {  
  144.         printf( "Error occurred when opening output file\n");  
  145.         goto end;  
  146.     }  
  147.     //FIX  
  148. #if USE_H264BSF  
  149.     AVBitStreamFilterContext* h264bsfc =  av_bitstream_filter_init("h264_mp4toannexb");   
  150. #endif  
  151. #if USE_AACBSF  
  152.     AVBitStreamFilterContext* aacbsfc =  av_bitstream_filter_init("aac_adtstoasc");   
  153. #endif  
  154.     while (1) {  
  155.         AVFormatContext *ifmt_ctx;  
  156.         int stream_index=0;  
  157.         AVStream *in_stream, *out_stream;  
  158.         //Get an AVPacket  
  159.         //if(av_compare_ts(cur_pts_v,ifmt_ctx_v->streams[videoindex_v]->time_base,cur_pts_a,ifmt_ctx_a->streams[audioindex_a]->time_base) <= 0)  
  160.         {  
  161.             ifmt_ctx=ifmt_ctx_v;  
  162.             stream_index=videoindex_out;  
  163.             if(av_read_frame(ifmt_ctx, &pkt) >= 0){  
  164.                 do{  
  165.                     in_stream  = ifmt_ctx->streams[pkt.stream_index];  
  166.                     out_stream = ofmt_ctx->streams[stream_index];  
  167.                     printf("stream_index==%d,pkt.stream_index==%d,videoindex_v=%d\n", stream_index,pkt.stream_index,videoindex_v);  
  168.                     if(pkt.stream_index==videoindex_v){  
  169.                         //FIX:No PTS (Example: Raw H.264)  
  170.                         //Simple Write PTS  
  171.                         if(pkt.pts==AV_NOPTS_VALUE){  
  172.                             printf("frame_index==%d\n",frame_index);  
  173.                             //Write PTS  
  174.                             AVRational time_base1=in_stream->time_base;  
  175.                             //Duration between 2 frames (us)  
  176.                             int64_t calc_duration=(double)AV_TIME_BASE/av_q2d(in_stream->r_frame_rate);  
  177.                             //Parameters  
  178.                             pkt.pts=(double)(frame_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE);  
  179.                             pkt.dts=pkt.pts;  
  180.                             pkt.duration=(double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE);  
  181.                             frame_index++;  
  182.                         }  
  183.                         cur_pts_v=pkt.pts;  
  184.                         break;  
  185.                     }  
  186.                 }while(av_read_frame(ifmt_ctx, &pkt) >= 0);  
  187.             }else{  
  188.                 break;  
  189.             }  
  190.         }  
  191.         /*else 
  192.         { 
  193.             ifmt_ctx=ifmt_ctx_a; 
  194.             stream_index=audioindex_out; 
  195.             if(av_read_frame(ifmt_ctx, &pkt) >= 0){ 
  196.                 do{ 
  197.                     in_stream  = ifmt_ctx->streams[pkt.stream_index]; 
  198.                     out_stream = ofmt_ctx->streams[stream_index]; 
  199.                     if(pkt.stream_index==audioindex_a){ 
  200.                         //FIX:No PTS 
  201.                         //Simple Write PTS 
  202.                         if(pkt.pts==AV_NOPTS_VALUE){ 
  203.                             //Write PTS 
  204.                             AVRational time_base1=in_stream->time_base; 
  205.                             //Duration between 2 frames (us) 
  206.                             int64_t calc_duration=(double)AV_TIME_BASE/av_q2d(in_stream->r_frame_rate); 
  207.                             //Parameters 
  208.                             pkt.pts=(double)(frame_index*calc_duration)/(double)(av_q2d(time_base1)*AV_TIME_BASE); 
  209.                             pkt.dts=pkt.pts; 
  210.                             pkt.duration=(double)calc_duration/(double)(av_q2d(time_base1)*AV_TIME_BASE); 
  211.                             frame_index++; 
  212.                         } 
  213.                         cur_pts_a=pkt.pts; 
  214.                         break; 
  215.                     } 
  216.                 }while(av_read_frame(ifmt_ctx, &pkt) >= 0); 
  217.             }else{ 
  218.                 break; 
  219.             } 
  220.         }*/  
  221.         //FIX:Bitstream Filter  
  222. #if USE_H264BSF  
  223.         av_bitstream_filter_filter(h264bsfc, in_stream->codec, NULL, &pkt.data, &pkt.size, pkt.data, pkt.size, 0);  
  224. #endif  
  225. #if USE_AACBSF  
  226.         av_bitstream_filter_filter(aacbsfc, out_stream->codec, NULL, &pkt.data, &pkt.size, pkt.data, pkt.size, 0);  
  227. #endif  
  228.         //Convert PTS/DTS  
  229.         pkt.pts = av_rescale_q_rnd(pkt.pts, in_stream->time_base, out_stream->time_base, (AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));  
  230.         pkt.dts = av_rescale_q_rnd(pkt.dts, in_stream->time_base, out_stream->time_base, (AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));  
  231.         pkt.duration = av_rescale_q(pkt.duration, in_stream->time_base, out_stream->time_base);  
  232.         pkt.pos = -1;  
  233.         pkt.stream_index=stream_index;  
  234.         printf("Write 1 Packet. size:%5d\tpts:%lld\n",pkt.size,pkt.pts);  
  235.         //Write  
  236.         if (av_interleaved_write_frame(ofmt_ctx, &pkt) < 0) {  
  237.             printf( "Error muxing packet\n");  
  238.             break;  
  239.         }  
  240.         av_free_packet(&pkt);  
  241.     }  
  242.     //Write file trailer  
  243.     av_write_trailer(ofmt_ctx);  
  244. #if USE_H264BSF  
  245.     av_bitstream_filter_close(h264bsfc);  
  246. #endif  
  247. #if USE_AACBSF  
  248.     av_bitstream_filter_close(aacbsfc);  
  249. #endif  
  250. end:  
  251.     avformat_close_input(&ifmt_ctx_v);  
  252.     //avformat_close_input(&ifmt_ctx_a);  
  253.     /* close output */  
  254.     if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))  
  255.         avio_close(ofmt_ctx->pb);  
  256.     avformat_free_context(ofmt_ctx);  
  257.     if (ret < 0 && ret != AVERROR_EOF) {  
  258.         printf( "Error occurred.\n");  
  259.         return -1;  
  260.     }  
  261.     return 0;  
  262. }  



二、h264视频实时流的封装

    大体思路和上面文件操作是差不多的,区别在于不能像上面一样可以获取文件中视频流的信息,这样你就得自己去设置这些参数,下面程序是根据我自己的视频流设置的,如果你的不同,需要修改;具体参数如下:

(1)AVCodecContext 的配置参数

enum AVMediaType codec_type:编解码器的类型(视频,音频...)

struct AVCodec  *codec:采用的解码器AVCodec(H.264,MPEG2...)

int bit_rate:平均比特率

uint8_t *extradata; int extradata_size:针对特定编码器包含的附加信息(例如对于H.264解码器来说,存储SPS,PPS等)

AVRational time_base:根据该参数,可以把PTS转化为实际的时间(单位为秒s)

int width, height:如果是视频的话,代表宽和高

int refs:运动估计参考帧的个数(H.264的话会有多帧,MPEG2这类的一般就没有了)

int sample_rate:采样率(音频)

int channels:声道数(音频)

enum AVSampleFormat sample_fmt:采样格式

int profile:型(H.264里面就有,其他编码标准应该也有)

int level:级(和profile差不太多)


(2)还有一个结构体参数也需要去设置,在AVPacket结构体中,重要的变量有以下几个:

uint8_t *data:压缩编码的数据。

例如对于H.264来说。1个AVPacket的data通常对应一个NAL。

注意:在这里只是对应,而不是一模一样。他们之间有微小的差别:使用FFMPEG类库分离出多媒体文件中的H.264码流

因此在使用FFMPEG进行视音频处理的时候,常常可以将得到的AVPacket的data数据直接写成文件,从而得到视音频的码流文件。


int   size:data的大小

int64_t pts:显示时间戳

int64_t dts:解码时间戳

int   stream_index:标识该AVPacket所属的视频/音频流。


总体代码如下:



[cpp] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. #include"ffmpeg_mp4.h"  
  2.   
  3. int getVopType( const void *p, int len )  
  4. {  
  5.     if ( !p || 6 >= len )  
  6.         return -1;  
  7.     unsigned char *b = (unsigned char*)p;  
  8.     // Verify NAL marker  
  9.     if ( b[ 0 ] || b[ 1 ] || 0x01 != b[ 2 ] )  
  10.     {   b++;  
  11.         if ( b[ 0 ] || b[ 1 ] || 0x01 != b[ 2 ] )  
  12.             return -1;  
  13.     } // end if  
  14.     b += 3;  
  15.     // Verify VOP id  
  16.     if ( 0xb6 == *b )  
  17.     {     
  18.         b++;  
  19.         return ( *b & 0xc0 ) >> 6;  
  20.     } // end if  
  21.     switch( *b )  
  22.     {    
  23.         case 0x65 : return 0;  
  24.         case 0x61 : return 1;  
  25.         case 0x01 : return 2;  
  26.     } // end switch  
  27.     return -1;  
  28. }  
  29. /* Add an output stream */  
  30. AVStream *add_stream(AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id)  
  31. {  
  32.     AVCodecContext *c;  
  33.     AVStream *st;  
  34.     /* find the encoder */  
  35.     *codec = avcodec_find_encoder(codec_id);  
  36.     if (!*codec)  
  37.     {  
  38.         printf("could not find encoder for '%s' \n", avcodec_get_name(codec_id));  
  39.         exit(1);  
  40.     }  
  41.     st = avformat_new_stream(oc, *codec);  
  42.     if (!st)  
  43.     {  
  44.         printf("could not allocate stream \n");  
  45.         exit(1);  
  46.     }  
  47.     st->id = oc->nb_streams-1;  
  48.     c = st->codec;  
  49.     vi = st->index;  
  50.     switch ((*codec)->type)  
  51.     {  
  52.     case AVMEDIA_TYPE_AUDIO:  
  53.         printf("AVMEDIA_TYPE_AUDIO\n");  
  54.         c->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;  
  55.         c->bit_rate = 64000;  
  56.         c->sample_rate = 44100;  
  57.         c->channels = 2;  
  58.         break;  
  59.     case AVMEDIA_TYPE_VIDEO:  
  60.         printf("AVMEDIA_TYPE_VIDEO\n");  
  61.         c->codec_id = AV_CODEC_ID_H264;  
  62.         c->bit_rate = 0;  
  63.         c->width = 1920;  
  64.         c->height = 1080;  
  65.         c->time_base.den = 50;  
  66.         c->time_base.num = 1;  
  67.         c->gop_size = 1;  
  68.         c->pix_fmt = STREAM_PIX_FMT;  
  69.         if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO)  
  70.         {  
  71.             c->max_b_frames = 2;  
  72.         }  
  73.         if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO)  
  74.         {  
  75.             c->mb_decision = 2;  
  76.         }  
  77.         break;  
  78.     default:  
  79.         break;  
  80.     }  
  81.     if (oc->oformat->flags & AVFMT_GLOBALHEADER)  
  82.     {  
  83.         c->flags |= CODEC_FLAG_GLOBAL_HEADER;  
  84.     }  
  85.     return st;  
  86. }  
  87. void open_video(AVFormatContext *oc, AVCodec *codec, AVStream *st)  
  88. {  
  89.     int ret;  
  90.     AVCodecContext *c = st->codec;  
  91.     /* open the codec */  
  92.     ret = avcodec_open2(c, codec, NULL);  
  93.     if (ret < 0)  
  94.     {  
  95.         printf("could not open video codec");  
  96.        //exit(1);  
  97.     }  
  98. }  
  99. int CreateMp4()  
  100. {  
  101.     int ret; // 成功返回0,失败返回1  
  102.     const char* pszFileName = "/udisk/vpu.mp4";  
  103.     AVOutputFormat *fmt;  
  104.     AVCodec *video_codec;  
  105.     AVStream *m_pVideoSt;  
  106.     av_register_all();  
  107.     avformat_alloc_output_context2(&m_pOc, NULL, NULL, pszFileName);  
  108.     if (!m_pOc)  
  109.     {  
  110.         printf("Could not deduce output format from file extension: using MPEG. \n");  
  111.         avformat_alloc_output_context2(&m_pOc, NULL, "mpeg", pszFileName);  
  112.     }  
  113.     if (!m_pOc)  
  114.     {  
  115.         return 1;  
  116.     }  
  117.     fmt = m_pOc->oformat;  
  118.     if (fmt->video_codec != AV_CODEC_ID_NONE)  
  119.     {  
  120.         printf("1111111111111111add_stream\n");  
  121.         m_pVideoSt = add_stream(m_pOc, &video_codec, fmt->video_codec);  
  122.     }  
  123.     if (m_pVideoSt)  
  124.     {  
  125.         printf("1111111111111111open_video\n");  
  126.         open_video(m_pOc, video_codec, m_pVideoSt);  
  127.     }  
  128.     printf("==========Output Information==========\n");  
  129.     av_dump_format(m_pOc, 0, pszFileName, 1);  
  130.     printf("======================================\n");  
  131.     /* open the output file, if needed */  
  132.     if (!(fmt->flags & AVFMT_NOFILE))  
  133.     {  
  134.         ret = avio_open(&m_pOc->pb, pszFileName, AVIO_FLAG_WRITE);  
  135.         if (ret < 0)  
  136.         {  
  137.             printf("could not open %s\n", pszFileName);  
  138.             return 1;  
  139.         }  
  140.     }  
  141.     /* Write the stream header, if any */  
  142.     ret = avformat_write_header(m_pOc, NULL);  
  143.     if (ret < 0)  
  144.     {  
  145.         printf("Error occurred when opening output file");  
  146.         return 1;  
  147.     }  
  148. }  
  149. /* write h264 data to mp4 file 
  150.  
  151.  * 创建mp4文件返回2;写入数据帧返回0 */  
  152. void WriteVideo(void* data, int nLen)  
  153. {  
  154.     int ret;  
  155.     if ( 0 > vi )  
  156.     {  
  157.        printf("vi less than 0");  
  158.         //return -1;  
  159.     }  
  160.     AVStream *pst = m_pOc->streams[ vi ];  
  161.     //printf("vi=====%d\n",vi);  
  162.     // Init packet  
  163.     AVPacket pkt;  
  164.     // 我的添加,为了计算pts  
  165.     AVCodecContext *c = pst->codec;  
  166.     av_init_packet( &pkt );  
  167.     pkt.flags |= ( 0 >= getVopType( data, nLen ) ) ? AV_PKT_FLAG_KEY : 0;  
  168.     pkt.stream_index = pst->index;  
  169.     pkt.data = (uint8_t*)data;  
  170.     pkt.size = nLen;  
  171.     // Wait for key frame  
  172.     if ( waitkey )  
  173.         if ( 0 == ( pkt.flags & AV_PKT_FLAG_KEY ) )  
  174.             return ;  
  175.         else  
  176.             waitkey = 0;  
  177.     pkt.pts = (ptsInc++) * (90000/STREAM_FRAME_RATE);  
  178.     pkt.pts = av_rescale_q((ptsInc++)*2, pst->codec->time_base,pst->time_base);  
  179.     //pkt.dts = (ptsInc++) * (90000/STREAM_FRAME_RATE);  
  180.   //  pkt.pts=av_rescale_q_rnd(pkt.pts, pst->time_base,pst->time_base,(AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));  
  181.     pkt.dts=av_rescale_q_rnd(pkt.dts, pst->time_base,pst->time_base,(AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));  
  182.     pkt.duration = av_rescale_q(pkt.duration,pst->time_base, pst->time_base);  
  183.     pkt.pos = -1;  
  184.     printf("pkt.size=%d\n",pkt.size);  
  185.     ret = av_interleaved_write_frame( m_pOc, &pkt );  
  186.     if (ret < 0)  
  187.     {  
  188.         printf("cannot write frame");  
  189.     }  
  190. }  
  191. void CloseMp4()  
  192. {  
  193.     waitkey = -1;  
  194.     vi = -1;  
  195.     if (m_pOc)  
  196.         av_write_trailer(m_pOc);  
  197.     if (m_pOc && !(m_pOc->oformat->flags & AVFMT_NOFILE))  
  198.         avio_close(m_pOc->pb);  
  199.     if (m_pOc)  
  200.     {  
  201.         avformat_free_context(m_pOc);  
  202.         m_pOc = NULL;  
  203.     }  
  204. }  
阅读(1312) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~