【问题标题】:Cannot wrie header FFMPEG无法写入标头 FFMPEG
【发布时间】: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 转换为可用的帧。你能给我一些提示吗?

标签: c++ ffmpeg streaming


【解决方案1】:

用于复用的主要 API 函数是用于写入文件头的 avformat_write_header()、用于写入数据包的 av_write_frame()/av_interleaved_write_frame() 和用于完成文件的 av_write_trailer()。

查看此链接

http://ffmpeg.org/doxygen/trunk/group__lavf__encoding.html#details

【讨论】:

    猜你喜欢
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 2015-01-07
    • 2021-07-16
    • 1970-01-01
    • 2023-04-02
    • 2020-02-24
    相关资源
    最近更新 更多