<div dir="ltr"><div>Thank you so much! It worked like a charm. <br></div><div><br></div><div>This is a basic resume to the implementation I made to replace the deprecated stream->codec data structure<br>successfully:<br>1. Initialize AVFormatContext, AVOutputFormat variables (using av_guess_format and avformat_alloc_output_context2)<br>2. Open video codec (using avcodec_find_encoder)<br>3. Add/Initialize AVStream variable (using avformat_new_stream)<br>4. Initialize AVCodecContext variable (using avcodec_alloc_context3)<br>5. Customize AVCodecContext parameters (if you need to. In example: width, height, bit_rate, etc)<br>6. Add this piece of code:<br>   if (formatContext->oformat->flags & AVFMT_GLOBALHEADER)<br>       videoCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;<br>7. Open AVCodecContext variable (using avcodec_open2)<br>8. Copy AVCodecContext codecpar structure into AVStream codecpar (using avcodec_parameters_from_context)<br><br>From this point, you will be able to create and add frames to your output file. Good luck!<br><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 23, 2022 at 11:13 PM Yurii Monakov <<a href="mailto:monakov.y@gmail.com">monakov.y@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Hi,</div><div dir="auto"><br></div><div dir="auto">You should initialize AVCodecContext, open it and then you can fill AVStream::codecpar with avcodec_parameters_from_context function. Please look at doc/examples/muxing.c for sample code.</div><div dir="auto"><br></div><div dir="auto">Yurii</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">ср, 23 марта 2022 г. в 14:07, Gustav González <<a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>
                
<p>Hi,<br></p><p>A long time ago, I implemented a C++ class to create MP4 video files 
from an array of images. The code works pretty well, nevertheless, I 
discovered a deprecation warning that I want to rid off. The parameter "<strong>codec</strong>" from the <strong>AVStream</strong> structure has been deprecated and I want to replace it.</p>
<p>Here is my current working code:</p>
<pre><code>AVOutputFormat *outputFormat = av_guess_format("ffh264", movieFile.toLocal8Bit().data(), nullptr);
if (!outputFormat)
    return false;

enum AVCodecID videoCodecID = outputFormat->video_codec;

AVCodec *videoCodec = avcodec_find_encoder(videoCodecID);
if (!videoCodec)
    return false;

AVStream *stream = avformat_new_stream(formatContext, videoCodec);
if (!stream)
    return false;

AVCodecContext *videoCodecContext = stream->codec; // <- codec is a deprecated parameter

videoCodecContext->width = videoW;
videoCodecContext->height = videoH;
</code></pre>
<p>Now, to replace the "<strong>codec</strong>" parameter, it is recommended to use the parameter "<strong>codecpar</strong>" (<strong>AVCodecParameters</strong>) that was included in the AVStream structure. The usual way is this:</p>
<pre><code>if (avcodec_parameters_to_context(videoCodecContext, stream->codecpar) < 0)
    return nullptr;
</code></pre>

<p>Unfortunately, when I try to use that code, I got this problem: usually, all the information stored in the <strong>codecpar</strong>
 parameter comes from the data structure from a previous video file that
 was opened previously. In other words, the information already exists. 
In my case, the situation is different because I am creating an MP4 file
 from scratch so there is no previous <strong>codecpar</strong> record 
to use, therefore I have to create a new instance of AVCodecParameters 
structure by myself, setting every variable manually.</p>
<p>As far, I was able to set all the variables from the <strong>codecpar</strong> structure, except for two:</p>
<pre><code>uint8_t * extradata 
int       extradata_size
</code></pre>
<p>Note: currently I can create an MP4 file "successfully" without 
setting those variables, but the file is incomplete and when I try to 
play it using "mplayer" I got this error message:</p>
<pre><code>[extract_extradata @ 0x55b5bb7e45c0] No start code is found.
</code></pre>
<p>I was researching these two fields, and it seems they store some kind
 of information related to the codec, which in my case is H264.</p>
<p>So, my specific question is: if I am setting a <strong>codecpar</strong> variable (<strong>AVCodecParameters</strong>) from scratch, how can I set values for the fields <strong>extradata</strong> and <strong>extradata_size</strong> in the right way for the codec H264?</p>
    </div><div dir="ltr"><div dir="ltr"><div>Thanks,<br></div><div>--<br>  Gustav Gonzalez<br>  <a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a><br><br></div></div></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>--<br>  Gustav Gonzalez<br>  <a href="mailto:xtingray@gmail.com" target="_blank">xtingray@gmail.com</a><br><br></div></div></div>