[Libav-user] How to access the struct AVCodecTag?
Carl Eugen Hoyos
ceffmpeg at gmail.com
Wed Mar 18 03:14:10 EET 2020
Am Di., 17. März 2020 um 23:16 Uhr schrieb Anton Shekhovtsov
<shekh.anton at gmail.com>:
>
>
>
> вт, 17 мар. 2020 г. в 23:51, Giuseppe Torelli <giutorcom at gmail.com>:
>>>
>>>
>>> I'm not sure if this is completely sane but I'm using this method for testing how FFMpeg can mix codec and container: create memory writing context, prepare writing of container, add single stream with the specific encoding format, try to finish.
>>> If there is any error assume the format is not supported in the container.
>>
>>
>> Would you please share some code?
>
>
> https://sourceforge.net/p/vdfiltermod/cch_input/ci/master/tree/export.cpp#l884
> This is part of VirtualDub2
>
> IOWBuffer io;
> int buf_size = 4096;
> void* buf = av_malloc(buf_size);
> AVIOContext* avio_ctx = avio_alloc_context((unsigned char*)buf,buf_size,1,&io,0,&IOWBuffer::Write,&IOWBuffer::Seek);
> AVFormatContext* ofmt = avformat_alloc_context();
> ofmt->pb = avio_ctx;
> ofmt->oformat = this->ofmt->oformat;
> AVStream* st = avformat_new_stream(ofmt, 0);
> avcodec_parameters_copy(st->codecpar, si.st->codecpar);
> st->sample_aspect_ratio = si.st->sample_aspect_ratio;
> st->avg_frame_rate = si.st->avg_frame_rate;
> av_stream_set_r_frame_rate(st,st->avg_frame_rate);
> st->time_base = si.st->time_base;
>
> if(st->codecpar->codec_type==AVMEDIA_TYPE_AUDIO){
> if(ofmt->oformat==av_guess_format("mp4", 0, 0)){
> st->codecpar->codec_tag = 0;
> }
> }
>
> bool failed = true;
> if(avformat_write_header(ofmt, 0)<0) goto cleanup;
> if(av_write_trailer(ofmt)<0) goto cleanup;
As explained, this will not fail for some invalid combinations.
Carl Eugen
More information about the Libav-user
mailing list