Skip to content

fix -Wcast-user-defined warning#3103

Merged
davisking merged 1 commit intodavisking:masterfrom
ribbon-otter:user-convert
Aug 11, 2025
Merged

fix -Wcast-user-defined warning#3103
davisking merged 1 commit intodavisking:masterfrom
ribbon-otter:user-convert

Conversation

@ribbon-otter
Copy link
Copy Markdown
Contributor

The tests compile and run mostly. I get deprecated warnings for something in ffmpeg which can an error on one of the final tests. I am not enough of an expert at cmake to understand why only some of the files are compiled with -Werror.

Please look carefully at this pull request as I turned something that was const into non-const. I am not convinced it is correct. Though the c-style cast was likely modifying a const variable through a non-const reference anyway.

static_cast did not work.

I am planning on adding a flag to the CMakelist.txt test file that lets me turn off -Werror so I can at least fully test changes before submitting them. Particularly while I am patching away warnings like this.

@ribbon-otter
Copy link
Copy Markdown
Contributor Author

Specifically I get warnings/errors that ch_layouts is deprecated, in dlib/media/ffmpeg_muxer.h

@pfeatherstone
Copy link
Copy Markdown
Contributor

You'll need to submit an issue with a reproducible example for me to diagnose that. To be honest i think we should drop support for the older FFMpeg libs now.

@arrufat
Copy link
Copy Markdown
Contributor

arrufat commented Aug 11, 2025

I get a lot of deprecation warnings on Arch Linux with FFmpeg 7.1.1, the ch_layouts deprecation included, just by running:

$ cd examples
$ cmake -G Ninja -B build
...
-- Searching for FFMPEG/LIBAV
-- Checking for modules 'libavdevice;libavfilter;libavformat;libavcodec;libswresample;libswscale;libavutil'
--   Found libavdevice, version 61.3.100
--   Found libavfilter, version 10.4.100
--   Found libavformat, version 61.7.100
--   Found libavcodec, version 61.19.101
--   Found libswresample, version 5.3.100
--   Found libswscale, version 8.3.100
--   Found libavutil, version 59.39.100
-- Found FFMPEG/LIBAV via pkg-config in `/usr/lib`
...
$ ninja -C build ffmpeg_webcam_face_pose_ex
...
dlib/media/ffmpeg_muxer.h:814:80: warning: ‘AVCodec::ch_layouts’ is deprecated [-Wdeprecated-declarations]
  814 |                         av_channel_layout_copy(&pCodecCtx->ch_layout, &pCodec->ch_layouts[0]);
      |                                                                                ^~~~~~~~~~
...

@pfeatherstone
Copy link
Copy Markdown
Contributor

Maybe the easiest thing to do is drop support for older versions. I'll have a look later though

@pfeatherstone
Copy link
Copy Markdown
Contributor

I'm willing to bet it's because the following isn't working as expected with all versions of ffmpeg

https://github.com/davisking/dlib/blob/4cf8f5759fe715b0defb0ba998ac1c354b814cca/dlib/media/ffmpeg_details.h#L67C1-L69C7

@pfeatherstone
Copy link
Copy Markdown
Contributor

pfeatherstone commented Aug 11, 2025

Oh i see the problem. Yeah, I fixed this in my own repo ages ago. Sorry. I can submit a PR at some point. FFmpeg is quite annoying at constantly changing APIs. In my own private repos i only ever support the latest version since i always build from source direct from cmake (using ExternalProject_Add)

@davisking
Copy link
Copy Markdown
Owner

Thanks for the PR, it's a reasonable way to avoid that warning :)

@davisking davisking merged commit fb0865b into davisking:master Aug 11, 2025
8 checks passed
@pfeatherstone
Copy link
Copy Markdown
Contributor

I've started #3105 for ffmpeg 7 warnings

davisking pushed a commit to smu-sc-gj/dlib that referenced this pull request Aug 18, 2025
Co-authored-by: ribbon-otter <ribbon-otter@github.invalid>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants