>
>
> If I understand correctly, the AVCodecContext is instantiated separately
> from the FormatContext and Streams.
> So what I have to do is:
>
> 1- Instanciate the codec context and configure it as you suggested
> 2- Instanciate an AVFormatContext
> 3- Add a stream without codec using avformat_new_stream(fmt_ctx, NULL)
> 4- set stream id and update codecpar using avcodec_parameters_from_context
> 5- generate the format header with avformat_write_header
> 6- proceed to the frame encoding loop
>
> right?
>
There is a transcoding.c example on FFmpeg's github repo. But in essence you
create new AVFormatContext first using the
avformat_alloc_output_context2(ofmt_ctx, NULL, NULL, ofn.c_str());
After that you add streams, as much as you need or as much as your
container
supports using the
out_stream = avformat_new_stream(ofmt_ctx, NULL);
Once you have your stream then you open the appropriate encoder for data
that
you want to encode
encoder = avcodec_find_encoder(AV_CODEC_ID_H264);
and based on returned value you create your AVCodecContext with
enc_ctx = avcodec_alloc_context3(encoder);
You set required options using the
av_opt_set_double(enc_ctx->priv_data, "crf", 23.00, 0);
and then simply open the AVCodecContext calling the
ret = avcodec_open2(enc_ctx, encoder, NULL);
You then copy encoder properties to the streams AVCodecParameters
ret = avcodec_parameters_from_context(out_stream->codecpar, enc_ctx);
open the file and write header.
ret = avio_open(ofmt_ctx->pb, ofn.c_str(), AVIO_FLAG_WRITE);
ret = avformat_write_header(ofmt_ctx, NULL);
--
Regards
Strahinja Radman
_______________________________________________
Libav-user mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/libav-user
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".