FFmepeg:avformat_alloc_output_context2(),初始化AVFormatContext返回空值时的解决方法

avformat_alloc_output_context2()函数可以初始化一个用于输出的AVFormatContext结构体。

#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"

int main(int argc, char * argv[] )
{
    int ret;
	char filename[64] = "test.ts";
	AVFormatContext *oc = NULL;//封装格式的上下文结构体,是统领全局的结构体,保存了视频文件封装格式的相关信息
	av_register_all();
	
	avformat_alloc_output_context2(&oc, NULL, "mpegts", filename);
	if (!oc) {
		printf("\nCould not deduce output format from file extension.\n");
		return -1;
	}

	ret = avio_open(&(oc->pb), filename, AVIO_FLAG_WRITE);
	if (ret < 0) {
		fprintf(stderr, "Could not open '%s'   %d: %s\n", filename, ret, av_err2str(ret));
		return -1;
	}
    
    ......
}

问题:在调用avformat_alloc_output_context2()时,初始化AVFormatContext  *oc结构体失败,出现:Requested output format 'mpegts' is not a suitable output format 。结构体 oc 返回的是一个空值,如图:

解决方法 1:在FFmepeg移植时,加入了  ./configure --disable-everything  --enble....选项,可以把 --disable-everything 该选项去掉,在重新编译移植FFmepeg,FFmepeg就会把所有的复用和解复用器注册完成。不过编译出来的执行文件会相应的变大。

解决方法 2:在FFmepeg移植时,加入你需要复用解复用器的类型:./configure --enable-muxer=NAME --enable-demuxer=NAME , 在重新编译FFmepeg即可。(优点:后面编译的执行文件不会增大,缺点:你所需要的复用器要一个个去添加:如:--enable-muxer=mpegts  --enable-demuxer=mpegts等)。

--enable-demuxer=NAME,其中NAME的类型如下:

aa			 bit			  flic			   image_jpegls_pipe	    microdvd		     pcm_alaw		      rtp		       tmv
aac			 bmv			  flv			   image_pam_pipe	    mjpeg		     pcm_f32be		      rtsp		       truehd
ac3			 boa			  fourxm		   image_pbm_pipe	    mjpeg_2000		     pcm_f32le		      s337m		       tta
acm			 brstm			  frm			   image_pcx_pipe	    mlp			     pcm_f64be		      sami		       tty
act			 c93			  fsb			   image_pgm_pipe	    mlv			     pcm_f64le		      sap		       txd
adf			 caf			  g722			   image_pgmyuv_pipe	    mm			     pcm_mulaw		      sbc		       ty
adp			 cavsvideo		  g723_1		   image_pictor_pipe	    mmf			     pcm_s16be		      sbg		       v210
ads			 cdg			  g726			   image_png_pipe	    mov			     pcm_s16le		      scc		       v210x
adx			 cdxl			  g726le		   image_ppm_pipe	    mp3			     pcm_s24be		      sdp		       vag
aea			 cine			  g729			   image_psd_pipe	    mpc			     pcm_s24le		      sdr2		       vc1
afc			 codec2			  gdv			   image_qdraw_pipe	    mpc8		     pcm_s32be		      sds		       vc1t
aiff			 codec2raw		  genh			   image_sgi_pipe	    mpegps		     pcm_s32le		      sdx		       vivo
aix			 concat			  gif			   image_sunrast_pipe	    mpegts		     pcm_s8		      segafilm		       vmd
amr			 data			  gsm			   image_svg_pipe	    mpegtsraw		     pcm_u16be		      ser		       vobsub
amrnb			 daud			  gxf			   image_tiff_pipe	    mpegvideo		     pcm_u16le		      shorten		       voc
amrwb			 dcstr			  h261			   image_webp_pipe	    mpjpeg		     pcm_u24be		      siff		       vpk
anm			 dfa			  h263			   image_xpm_pipe	    mpl2		     pcm_u24le		      sln		       vplayer
apc			 dirac			  h264			   image_xwd_pipe	    mpsub		     pcm_u32be		      smacker		       vqf
ape			 dnxhd			  hevc			   ingenient		    msf			     pcm_u32le		      smjpeg		       w64
apng			 dsf			  hls			   ipmovie		    msnwc_tcp		     pcm_u8		      smush		       wav
aptx			 dsicin			  hnm			   ircam		    mtaf		     pcm_vidc		      sol		       wc3
aptx_hd			 dss			  ico			   iss			    mtv			     pjs		      sox		       webm_dash_manifest
aqtitle			 dts			  idcin			   iv8			    musx		     pmp		      spdif		       webvtt
asf			 dtshd			  idf			   ivf			    mv			     pva		      srt		       wsaud
asf_o			 dv			  iff			   ivr			    mvi			     pvf		      stl		       wsd
ass			 dvbsub			  ilbc			   jacosub		    mxf			     qcp		      str		       wsvqa
ast			 dvbtxt			  image2		   jv			    mxg			     r3d		      subviewer		       wtv
au			 dxa			  image2_alias_pix	   live_flv		    nc			     rawvideo		      subviewer1	       wv
avi			 ea			  image2_brender_pix	   lmlm4		    nistsphere		     realtext		      sup		       wve
avr			 ea_cdata		  image2pipe		   loas			    nsp			     redspark		      svag		       xa
avs			 eac3			  image_bmp_pipe	   lrc			    nsv			     rl2		      swf		       xbin
avs2			 epaf			  image_dds_pipe	   lvf			    nut			     rm			      tak		       xmv
bethsoftvid		 ffmetadata		  image_dpx_pipe	   lxf			    nuv			     roq		      tedcaptions	       xvag
bfi			 filmstrip		  image_exr_pipe	   m4v			    ogg			     rpl		      thp		       xwma
bfstm			 fits			  image_j2k_pipe	   matroska		    oma			     rsd		      threedostr	       yop
bink			 flac			  image_jpeg_pipe	   mgsts		    paf			     rso		      tiertexseq	       yuv4mpegpipe

--enable-muxer=NAME,其中NAME的类型如下:

a64			 codec2raw		  g722			   ismv			    mpeg1video		     pcm_f64be		      rm		       swf
ac3			 crc			  g723_1		   ivf			    mpeg2dvd		     pcm_f64le		      roq		       tee
adts			 dash			  g726			   jacosub		    mpeg2svcd		     pcm_mulaw		      rso		       tg2
adx			 data			  g726le		   latm			    mpeg2video		     pcm_s16be		      rtp		       tgp
aiff			 daud			  gif			   lrc			    mpeg2vob		     pcm_s16le		      rtp_mpegts	       truehd
amr			 dirac			  gsm			   m4v			    mpegts		     pcm_s24be		      rtsp		       tta
apng			 dnxhd			  gxf			   matroska		    mpjpeg		     pcm_s24le		      sap		       uncodedframecrc
aptx			 dts			  h261			   matroska_audio	    mxf			     pcm_s32be		      sbc		       vc1
aptx_hd			 dv			  h263			   md5			    mxf_d10		     pcm_s32le		      scc		       vc1t
asf			 eac3			  h264			   microdvd		    mxf_opatom		     pcm_s8		      segafilm		       voc
asf_stream		 f4v			  hash			   mjpeg		    null		     pcm_u16be		      segment		       w64
ass			 ffmetadata		  hds			   mkvtimestamp_v2	    nut			     pcm_u16le		      singlejpeg	       wav
ast			 fifo			  hevc			   mlp			    oga			     pcm_u24be		      smjpeg		       webm
au			 fifo_test		  hls			   mmf			    ogg			     pcm_u24le		      smoothstreaming	       webm_chunk
avi			 filmstrip		  ico			   mov			    ogv			     pcm_u32be		      sox		       webm_dash_manifest
avm2			 fits			  ilbc			   mp2			    oma			     pcm_u32le		      spdif		       webp
avs2			 flac			  image2		   mp3			    opus		     pcm_u8		      spx		       webvtt
bit			 flv			  image2pipe		   mp4			    pcm_alaw		     pcm_vidc		      srt		       wtv
caf			 framecrc		  ipod			   mpeg1system		    pcm_f32be		     psp		      stream_segment	       wv
cavsvideo		 framehash		  ircam			   mpeg1vcd		    pcm_f32le		     rawvideo		      sup		       yuv4mpegpipe
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值