<div dir="ltr"><div>Hello!<br><br></div><div>I am trying to adapt our program to API removed in ffmpeg 7.0</div><div><br></div><div><a href="https://git.cinelerra-gg.org/git/?p=goodguy/cinelerra.git;a=blob;f=cinelerra-5.1/cinelerra/fileac3.C;h=dd3b4536d0d0997ba90001474ead3f520e828123;hb=HEAD">https://git.cinelerra-gg.org/git/?p=goodguy/cinelerra.git;a=blob;f=cinelerra-5.1/cinelerra/fileac3.C;h=dd3b4536d0d0997ba90001474ead3f520e828123;hb=HEAD</a></div><div><br></div><div>currently it reads</div><div><br></div><div> codec = avcodec_find_encoder(AV_CODEC_ID_AC3);<br> 131                 if(!codec)<br> 132                 {<br> 133                         eprintf(_("FileAC3::open_file codec not found.\n"));<br> 134                         result = 1;<br> 135                 }<br> 136                 if( !result && !(fd = fopen(asset->path, "w")))<br> 137                 {<br> 138                         eprintf(_("Error while opening \"%s\" for writing. \n%m\n"), asset->path);<br> 139                         result = 1;<br> 140                 }<br> 141                 if( !result ) {<br> 142                         int channels = asset->channels;<br> 143                         int sample_rate = asset->sample_rate;<br> 144                         int64_t layout = get_channel_layout(channels);<br> 145                         int bitrate = asset->ac3_bitrate * 1000;<br> 146                         av_init_packet(&avpkt);<br> 147                         codec_context = avcodec_alloc_context3(codec);<br> 148                         codec_context->bit_rate = bitrate;<br> 149                         codec_context->sample_rate = sample_rate;<br> 150                         codec_context->channels = channels;<br> 151                         codec_context->channel_layout = layout;<br> 152                         codec_context->sample_fmt = codec->sample_fmts[0];<br> 153                         resample_context = swr_alloc_set_opts(NULL,<br> 154                                         layout, codec_context->sample_fmt, sample_rate,<br> 155                                         layout, AV_SAMPLE_FMT_S16, sample_rate,<br> 156                                         0, NULL);<br> 157                         swr_init(resample_context);<br> 158                         if(avcodec_open2(codec_context, codec, 0))<br> 159                         {<br> 160                                 eprintf(_("FileAC3::open_file failed to open codec.\n"));<br> 161                                 result = 1;<br> 162                         }<br> 163                 }</div><div><br></div><div>I tried to mod it like this</div><div><br></div><div>if( !result ) {<br>                     int channels = asset->channels;<br>                    int sample_rate = asset->sample_rate;<br>                      int64_t layout = get_channel_layout(channels);<br>                        AVChannelLayout ch_layout;<br>                    av_channel_layout_default(&ch_layout, channels);<br>                  int bitrate = asset->ac3_bitrate * 1000;<br>                   av_init_packet(&avpkt);<br>                   codec_context = avcodec_alloc_context3(codec);<br>                        codec_context->bit_rate = bitrate;<br>                 codec_context->sample_rate = sample_rate;<br>                  //codec_context->ch_layout.nb_channels = channels;<br>                 //codec_context->ch_layout.u.mask = layout;<br>                        av_channel_layout_copy(&codec_context->ch_layout, &ch_layout);<br>                     codec_context->sample_fmt = codec->sample_fmts[0];<br>                      SwrContext *resample_context = NULL;<br>                  swr_alloc_set_opts2(&resample_context,<br>                                    &ch_layout, codec_context->sample_fmt, sample_rate,<br>                                    &ch_layout, AV_SAMPLE_FMT_S16, sample_rate,<br>                                       0, NULL);<br>                     swr_init(resample_context);<br>                   if(avcodec_open2(codec_context, codec, 0))<br>                    {<br>                             eprintf(_("FileAC3::open_file failed to open codec.\n"));<br>                           result = 1;<br>                   }</div><div><br></div><div>but unfortunately resulting file is empty ???</div><div><br></div><div>I tried to augment another function down in file, FileAC3::write_samples, by av_channel_layout_copy() too but then  whole program crash :) :(</div><div><br></div><div>strangely enough similar changes in ffmpeg.C works, even if I initially tried to  adapt fileac3.C</div><div><br></div><div>Other cinelerra forks currently use older ffmpeg so I am on my own here.</div><div><br></div><div>Attached two patches against cinelerra-gg git where I tried to make it compile and work. It compiles and partially works, but ac3 encoding is a bust ...<br></div><div><br></div></div>