[Libav-user] Create a muxer without enc_ctx = out_stream->codec
Charles
linux2 at orion15.org
Tue Aug 23 15:30:50 EEST 2016
Just posted the current version
https://gist.github.com/LinuxwitChdoCtOr/74c1721dd7688cf1d16509ea2a52d231
Thanks
cco
On 08/23/2016 07:22 AM, Charles wrote:
> Thank you for looking.
>
> Yes, I pretty much started there, and pretty much have it open all the time.
> From what I can tell my code is doing the same thing:
>
> av_encode_codec_ctx = avcodec_alloc_context3( av_encode_codec );
> if ( !av_encode_codec_ctx ) { PRINT_AV_ERROR( "ERROR:avcodec_alloc_context3:" ); return -1; }
> av_encode_codec_ctx->bit_rate = 5e6;
> av_encode_codec_ctx->width = 1024; /// \note multiple of 2
> av_encode_codec_ctx->height = 768; /// \note multiple of 2
> av_encode_codec_ctx->time_base = (AVRational) { 1, 60 }; //* 2;
> av_encode_codec_ctx->gop_size = 15; // Intra frames per x P frames
> av_encode_codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; // (MUST) DO NOT CHANGE nvenc required
>
> That code does not setup the output with
> avio_open( &av_out_fmt_ctx->pb, f.c_str(), AVIO_FLAG_WRITE )
> avformat_write_header( av_out_fmt_ctx, NULL )
>
> The header is where I see my error, either the muxer is unhappy or the encoder is unhappy
>
> Output #0, mp4, to 'enc.mp4':
> Stream #0:0: Unknown: none (h264_nvenc) ([33][0][0][0] / 0x0021)
> av_dump_format enc.mp4
> [mp4 @ 0x786d60] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
> [mp4 @ 0x786d60] dimensions not set
> ERROR:avformat_write_header::
>
> Thanks
> cco
>
> On 08/23/2016 07:01 AM, salsaman wrote:
>> Charles,
>> perhaps the example here can help ?
>>
>> https://ffmpeg.org/doxygen/3.1/decoding__encoding_8c_source.html#l00347
>>
>>
>>
>>
>>
>> http://lives-video.com
>> https://www.openhub.net/accounts/salsaman
>>
>> On Tue, Aug 23, 2016 at 8:39 AM, Charles <linux2 at orion15.org <mailto:linux2 at orion15.org>> wrote:
>>
>> On 08/23/2016 03:08 AM, Nicolas George wrote:
>>
>> Le sextidi 6 fructidor, an CCXXIV, Charles a écrit :
>>
>> 6 - avcodec_parameters_to_context( av_encode_codec_ctx, av_out_fmt_ctx->streams[ 0 ]->codecpar )
>>
>>
>> You are copying the parameters from a newly created blank stream to an
>> initialized encoder. That feels wrong.
>>
>> Regards,
>>
>>
>> Thanks for the look, I did some rearranging and I am to the point where the muxer is happy or the encoder is happy but cant get both at
>> the same time:
>>
>> Currently Op order:
>> 1) av_encode_codec = avcodec_find_encoder( AV_CODEC_ID_H264 )
>> 2) avformat_alloc_output_context2( &av_out_fmt_ctx, NULL, NULL, f.c_str() )
>> 3) video_st = avformat_new_stream( av_out_fmt_ctx, av_encode_codec )
>> video_st->id = 0;
>> video_st->time_base.den = 60; // * 2;
>> video_st->time_base.num = 1;
>> // This solved the time_base error
>> 4) parameters = video_st->codecpar;
>> parameters->codec_tag = tag;
>> parameters->format = AV_PIX_FMT_YUV420P;
>> parameters->bit_rate = 5e6;
>> parameters->width = 1024;
>> parameters->height = 768;
>> parameters->bit_rate = 5e6;
>> av_dict_set( &av_dict_opts, "b", "2.5M", 0);
>> av_dict_set( &av_dict_opts, "preset", "losslesshp", 0 );
>> av_dict_set( &av_dict_opts, "profile", "high", 0 );
>> av_dict_set( &av_dict_opts, "rc", "vbr_minqp", 0 );
>> av_dict_set( &av_dict_opts, "gpu", "1", 0 );
>> 5) av_encode_codec_ctx = avcodec_alloc_context3( av_encode_codec )
>> av_encode_codec_ctx->bit_rate = 5e6;
>> av_encode_codec_ctx->width = 1024; /// \note multiple of 2
>> av_encode_codec_ctx->height = 768; /// \note multiple of 2
>> av_encode_codec_ctx->time_base = (AVRational) { 1, 60 }; //* 2;
>> av_encode_codec_ctx->gop_size = 15; // Intra frames per x P frames
>> av_encode_codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; // MUST DO NOT CHANGE nvenc required
>> // This appears to make h264_nvenc happy
>> 6) avcodec_parameters_to_context( av_encode_codec_ctx, parameters )
>> 7) avcodec_open2( av_encode_codec_ctx, av_encode_codec, &av_dict_opts )
>>
>> [mp4 @ 0xc2ed60] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
>> [mp4 @ 0xc2ed60] dimensions not set
>>
>> AVStream does not have dimensions, and the error makes me think its in the ctx but I am setting those dims.
>>
>> Clearly I am not setting something, just haven't found it.
>>
>>
>> Thanks
>> cco
>>
>>
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org <mailto:Libav-user at ffmpeg.org>
>> http://ffmpeg.org/mailman/listinfo/libav-user <http://ffmpeg.org/mailman/listinfo/libav-user>
>>
>>
>>
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
More information about the Libav-user
mailing list