Clear ISO C++ Warning and Enable ffmpeg V5.0 Support #14

Merged
SlavekB merged 2 commits from ffmpeg-5.0 into master 2 years ago
Collaborator
  • "libk3b/jobs/k3bvideodvdtitletranscodingjob.cpp" declares two instances of "s_codecFeatures" as static char * and initialises them with string constants. This produces the compiler warning "ISO C++ forbids converting a string constant to 'char*'". Both declarations have been changed to "const".
  • The release of version 5.0 of ffmpeg removes a lot of deprecated API functions, some of which are being used by k3b. The ffmpeg support has been modified to support 5.0 as well as older versions.
- "libk3b/jobs/k3bvideodvdtitletranscodingjob.cpp" declares two instances of "s_codecFeatures" as ```static char *``` and initialises them with string constants. This produces the compiler warning "ISO C++ forbids converting a string constant to 'char*'". Both declarations have been changed to "const". - The release of version 5.0 of ffmpeg removes a lot of deprecated API functions, some of which are being used by k3b. The ffmpeg support has been modified to support 5.0 as well as older versions.
aneejit1 added 2 commits 2 years ago
1f4a3ab86e
Make s_codecFeatures a "const char *" to remove ISO C++ warning
a0033d986d
Enable ffmpeg 5.0 compatibility
aneejit1 force-pushed ffmpeg-5.0 from a0033d986d to 1e526c4704 2 years ago
Poster
Collaborator

I had to search around to find out how to actually get the ffmpeg plugin to run. Turns out, you need to convert a .wma file:

  • open a new audio cd project;
  • drag a .wma file from the file dialog into the playlist;
  • select Project -> Convert Tracks from the menu;
  • set the "Filetype" to "Wave;
  • click Start.

The output seems to be written to a directory entitled "unknown - unknown" as a .wav file. The conversion is giving a playable file.

I had to search around to find out how to actually get the ffmpeg plugin to run. Turns out, you need to convert a .wma file: - open a new audio cd project; - drag a .wma file from the file dialog into the playlist; - select Project -> Convert Tracks from the menu; - set the "Filetype" to "Wave; - click Start. The output seems to be written to a directory entitled "unknown - unknown" as a .wav file. The conversion is giving a playable file.
aneejit1 changed title from WIP: Clear ISO C++ Warning and Enable ffmpeg V5.0 Support to Clear ISO C++ Warning and Enable ffmpeg V5.0 Support 2 years ago
MicheleC reviewed 2 years ago
::AVFormatContext *formatContext;
::AVCodec *codec;
::AVStream *audio_stream;
::AVCodecContext *audio_stream_ctx;
Owner

Shouldn't these be a conditional #if based on version? audio_stream and audio_stream_ctx.

Shouldn't these be a conditional #if based on version? audio_stream and audio_stream_ctx.
Owner

AVCodecContext is not new – there are also other already existing occurrences. So there is no need to wrap it into #ifdefs. At the same time, AVCodecContext is used below for both older versions and newer versions, so it is not desirable to be conditional.

`AVCodecContext` is not new – there are also other already existing occurrences. So there is no need to wrap it into `#ifdefs`. At the same time, `AVCodecContext` is used below for both older versions and newer versions, so it is not desirable to be conditional.
Poster
Collaborator

The removal of the "codec" state variable from AVStream is a common cause of problems when building against ffmpeg 5. Unfortunately, it's usually used across functions/methods (as it is here) and since the new way of getting the AVCodecContext is to call "avcodec_alloc_context3" to allocate it you need somewhere common to stow the returned pointer, private state being a good place to use.

As with the AVPacket problem, it adds a little overhead when building for the older API (one pointer) to avoid more conditional code to support both versions.

The removal of the "codec" state variable from AVStream is a common cause of problems when building against ffmpeg 5. Unfortunately, it's usually used across functions/methods (as it is here) and since the new way of getting the AVCodecContext is to call "avcodec_alloc_context3" to allocate it you need somewhere common to stow the returned pointer, private state being a good place to use. As with the AVPacket problem, it adds a little overhead when building for the older API (one pointer) to avoid more conditional code to support both versions.
Owner

Ok, my bad. Thanks for the feedback.

Ok, my bad. Thanks for the feedback.
MicheleC marked this conversation as resolved
d->formatContext = NULL;
d->codec = NULL;
d->audio_stream = NULL;
d->audio_stream_ctx = NULL;
Owner

Shouldn't these be a conditional #if based on version? audio_stream and audio_stream_ctx.

Shouldn't these be a conditional #if based on version? audio_stream and audio_stream_ctx.
Owner

This seems to be okay – see the comment above.

This seems to be okay – see the comment above.
MicheleC marked this conversation as resolved
MicheleC reviewed 2 years ago
::AVSampleFormat sampleFormat;
::AVFrame *frame;
::AVPacket packet;
::AVPacket *packet;
Owner

Shouldn't these be a conditional #if based on version?

Shouldn't these be a conditional #if based on version?
Owner

I understood that for older versions, a combination of *packet and _packet (which is wrapped in #ifdefs) is used here to make the code easier and use *packet for all cases. That seems to me a good solution.

I understood that for older versions, a combination of `*packet` and `_packet` (which is wrapped in `#ifdefs`) is used here to make the code easier and use `*packet` for all cases. That seems to me a good solution.
Poster
Collaborator

It's based on something I picked up while doing a change to another project using ffmpeg.

The older "av_init_alloc" takes a pointer to an existing AVPacket whereas its replacement, "av_packet_alloc" returns a pointer to a new AVPacket. The net result is that all the references to the AVPacket state have to be converted from "." to "->" for the newer call. Declaring both in this way means everything can be converted to "->" without having to add more conditional code.

It's based on something I picked up while doing a change to another project using ffmpeg. The older "av_init_alloc" takes a pointer to an existing AVPacket whereas its replacement, "av_packet_alloc" returns a pointer to a new AVPacket. The net result is that all the references to the AVPacket state have to be converted from "." to "->" for the newer call. Declaring both in this way means everything can be converted to "->" without having to add more conditional code.
Owner

Yes, I understood this reason and I liked the solution you used.

Yes, I understood this reason and I liked the solution you used.
MicheleC marked this conversation as resolved
SlavekB reviewed 2 years ago
SlavekB left a comment
Owner

So far I haven't done tests, but there are some little comments.

So far I haven't done tests, but there are some little comments.
if (d->audio_stream->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
#else
d->audio_stream_ctx = d->audio_stream->codec;
if (d->audio_stream_ctx->codec_type != AVMEDIA_TYPE_AUDIO) {
Owner

I propose to move the opening parenthesis of the block below #ifdefs so that there is one common parenthesis opening the block instead of two parentheses related to the same block.

I propose to move the opening parenthesis of the block below `#ifdefs` so that there is one common parenthesis opening the block instead of two parentheses related to the same block.
Poster
Collaborator

OK, 'tis done.

OK, 'tis done.
SlavekB marked this conversation as resolved
// open the codec on our context
kdDebug() << "(K3bFFMpegFile) found codec for " << m_filename;
if (::avcodec_open2(codecContext, d->codec, NULL) < 0) {
kdDebug() << "(K3bFFMpegFile) found codec for " << m_filename << "\n";
Owner

Instead of "\n" it may be good to use endl.

Instead of `"\n"` it may be good to use `endl`.
Poster
Collaborator

I did try that initially but couldn't get it to work. I'd put "std::endl" which it doesn't seem to like. Just tried it with only "endl" and that's worked fine, so done!

I did try that initially but couldn't get it to work. I'd put "std::endl" which it doesn't seem to like. Just tried it with only "endl" and that's worked fine, so done!
Owner

Yes, the simple endl is what I meant.
Thank you.

Yes, the simple `endl` is what I meant. Thank you.
SlavekB marked this conversation as resolved
aneejit1 force-pushed ffmpeg-5.0 from 1e526c4704 to 8e7556b9a8 2 years ago
SlavekB approved these changes 2 years ago
SlavekB left a comment
Owner

I did a test building with an old distribution and it was successful.
I will wait for reactions and approval from @MicheleC.

I did a test building with an old distribution and it was successful. I will wait for reactions and approval from @MicheleC.
Owner

I did a test building with an old distribution and it was successful.
I will wait for reactions and approval from @MicheleC.

It's ok from my side. I did a quick review yesterday but without going too deep, hence my comments turned up to be inaccurate. You can proceed and merge.

> I did a test building with an old distribution and it was successful. > I will wait for reactions and approval from @MicheleC. It's ok from my side. I did a quick review yesterday but without going too deep, hence my comments turned up to be inaccurate. You can proceed and merge.
SlavekB merged commit 8e7556b9a8 into master 2 years ago
SlavekB deleted branch ffmpeg-5.0 2 years ago
SlavekB added this to the R14.0.13 release milestone 2 years ago

Reviewers

SlavekB approved these changes 2 years ago
The pull request has been merged as 8e7556b9a8.
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: TDE/k3b#14
Loading…
There is no content yet.