【发布时间】:2016-10-09 18:00:46
【问题描述】:
我正在使用 FFMPEg 开展一个项目,但不知何故我无法创建任何媒体文件。我已经设置了参数、编解码器等,但是当我调用 avformat_write_header 时,应用程序就会停止工作。 这是我的代码:
AVOutputFormat *fmt;
AVCodecContext *codecctx;
AVFormatContext *fmtctx;
fmt=av_guess_format(NULL,filename,NULL);
AVCodec *codec = avcodec_find_encoder(fmt->video_codec);
codecctx = avcodec_alloc_context3(codec);
codecctx->codec_id = fmt->video_codec;
codecctx->codec_type = AVMEDIA_TYPE_VIDEO;
codecctx->gop_size = 12;
codecctx->bit_rate = WIDTH*HEIGHT*4;
codecctx->width = WIDTH;
codecctx->height = HEIGHT;
codecctx->time_base.den = 2;
codecctx->time_base.num =1;
//codecctx->time_base =(AVRational){1,FPS};
codecctx->max_b_frames=1;
codecctx->pix_fmt= STREAM_PIX_FMT;
fmtctx = avformat_alloc_context();
fmtctx->oformat = fmt;
fmtctx->video_codec_id = fmt->video_codec;
avcodec_open2(codecctx, codec, NULL);
AVStream *VideoStream = avformat_new_stream(fmtctx,codec);
avformat_write_header(fmtctx,NULL);
【问题讨论】:
-
当你说你的应用程序停止工作你到底是什么意思?
-
谢谢,问题是我转移到 cal avio_open。现在我正在尝试将 png 图像添加到流中,但不知道如何将 ti 转换为可用的帧。你能给我一些提示吗?