[Libav-user] Using av_channel_layout_copy() function in Win, Linux, Mac (c++)

John Regan john at jrjrtech.com
Wed Aug 30 17:14:03 EEST 2023


On Wed, 30 Aug 2023 15:39:08 +0200
Denis Gottardello <info at denisgottardello.it> wrote:

> Hi. When I try to compile the following line of code
> 
> av_channel_layout_copy(&c->ch_layout,
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
> 
> taken from mux.c example I obtain the error:
> 
> /home/denis/Cpp/ffmpeg-6.0/libavutil/channel_layout.h:362: *error:
> taking address of rvalue [-fpermissive]*
> ../../ffmpeg-6.0/libavutil/channel_layout.h:362:5: error: taking
> address of rvalue [-fpermissive] 362 |     { .order =
> AV_CHANNEL_ORDER_NATIVE, .nb_channels = (nb), .u = { .mask = (m) }} |
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../../ffmpeg-6.0/libavutil/channel_layout.h:369:45: note: in
> expansion of macro ‘AV_CHANNEL_LAYOUT_MASK’ 369 | #define
> AV_CHANNEL_LAYOUT_STEREO            AV_CHANNEL_LAYOUT_MASK(2,
> AV_CH_LAYOUT_STEREO) |
> ^~~~~~~~~~~~~~~~~~~~~~ ../ffmpegTest/main.cpp:157:65: note: in
> expansion of macro ‘AV_CHANNEL_LAYOUT_STEREO’ 157 |
> av_channel_layout_copy(&c->ch_layout,
> &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); |
>                                          ^~~~~~~~~~~~~~~~~~~~~~~~
> 
> How can I translate it to work in Windows, Linux and Mac?
> Something like this?
> 
>         AVChannelLayout a= AV_CHANNEL_LAYOUT_STEREO;
>         av_channel_layout_copy(&c->ch_layout, &a);
> 

If you're assigning one of the standard layouts you should be able to
just do

    c->ch_layout = AV_CHANNEL_LAYOUT_STEREO;

At least, assuming that the AVCodecContext has just been allocated
(like it is in mux.c). If you had an existing channel layout set, you'd
want to do a copy since that will free any custom channel layout data
for you.

From your output it looks like you're compiling as C++, and some of the
code in mux.c is valid C code, but not valid C++ code (such as taking
the address of an rvalue).


More information about the Libav-user mailing list