Implement ffmpeg version 5 support #5

Merged
SlavekB merged 1 commits from ffmpeg5-support into master 2 years ago
Collaborator

Version 5.0 of ffmpeg drops a load of deprecated API functions causing k9copy to fail its build. The necessary changes have been made to enable k9copy to build against ffmpeg 5.0 as well as retaining support for older versions. Support for older pre-0.5.1 versions has been dropped as has runtime linking of the ffmpeg libraries. libswscale is now mandatory.

Signed-off-by: aneejit1 aneejit1@gmail.com

Version 5.0 of ffmpeg drops a load of deprecated API functions causing k9copy to fail its build. The necessary changes have been made to enable k9copy to build against ffmpeg 5.0 as well as retaining support for older versions. Support for older pre-0.5.1 versions has been dropped as has runtime linking of the ffmpeg libraries. libswscale is now mandatory. Signed-off-by: aneejit1 <aneejit1@gmail.com>
aneejit1 added 1 commit 2 years ago
c897f17660
Implement ffmpeg version 5 support
Poster
Collaborator

The following will trigger the running of the ffmpeg code:

  • Select "Actions" from the menu
  • Select "DVD Author"
  • Use the "Video file" field or it's file dialog button to select a ".avi"
  • Click "Add"

The thumbnail that gets added to the "Video files" list does appear to depend upon the file used. It appears to select the first image it can get and if that image is a black screen or incomplete then the results can look a little off.

This needs to be run against an older distribution version. k9copy calls out to drkonqi. I don't seem to be able to build tdelibs on Debian 9 at the moment as "make" just does nothing, so k9copy bombs out because drkonqi isn't there.

The following will trigger the running of the ffmpeg code: - Select "Actions" from the menu - Select "DVD Author" - Use the "Video file" field or it's file dialog button to select a ".avi" - Click "Add" The thumbnail that gets added to the "Video files" list does appear to depend upon the file used. It appears to select the first image it can get and if that image is a black screen or incomplete then the results can look a little off. This needs to be run against an older distribution version. k9copy calls out to drkonqi. I don't seem to be able to build tdelibs on Debian 9 at the moment as "make" just does nothing, so k9copy bombs out because drkonqi isn't there.
Owner

In Debian we now build using ninja, if you use the tde-packaging files.

In Debian we now build using ninja, if you use the tde-packaging files.
Poster
Collaborator

I did try with ninja but it did the same only with the message "No work to do".

I did try with ninja but it did the same only with the message "No work to do".
Owner

in you use the tde-packaging repo files, after you setup your source folder code (repo + packaging file), you can build locally with debian/rules binary. This will do all the work for you in a local build. Of course if you want a build in a clean environment you should use pbuilder or similar programs.
You can also look at these scripts, they may help you :-)

in you use the tde-packaging repo files, after you setup your source folder code (repo + packaging file), you can build locally with ```debian/rules binary```. This will do all the work for you in a local build. Of course if you want a build in a clean environment you should use pbuilder or similar programs. You can also look at these [scripts](https://mirror.git.trinitydesktop.org/gitea/TDE/tde-packaging/src/branch/master/debian/_buildscripts/local), they may help you :-)
Poster
Collaborator

Yeah, I've found the problem.

Missing "-DBUILD_ALL=ON".

8-)

Yeah, I've found the problem. Missing "-DBUILD_ALL=ON". 8-)
Poster
Collaborator

I've got tdebase/drkonqi sorted but there's a problem in the readFrame method with it failing the "av_read_frame" call, so it ain't quite working on Debian 9.

I've got tdebase/drkonqi sorted but there's a problem in the readFrame method with it failing the "av_read_frame" call, so it ain't quite working on Debian 9.
aneejit1 changed title from Implement ffmpeg version 5 support to WIP: Implement ffmpeg version 5 support 2 years ago
aneejit1 force-pushed ffmpeg5-support from c897f17660 to 1d8a9637b3 2 years ago
Poster
Collaborator

OK, that's got it. Problem was to do with the freeing or unrefing of the packet that needed to happen with each pass through the loop before the next av_read_frame. It's now working on my setup and under Debian 9.

OK, that's got it. Problem was to do with the freeing or unrefing of the packet that needed to happen with each pass through the loop before the next av_read_frame. It's now working on my setup and under Debian 9.
aneejit1 changed title from WIP: Implement ffmpeg version 5 support to Implement ffmpeg version 5 support 2 years ago
Ray-V commented 2 years ago
Collaborator

Commit 1d8a9637b3 works for me, amended for 14.0.12.
k9copy builds and the thumbnail is displayed for ffmpeg versions 3.1.2, 3.4.11, 4.4.2, and 5.0.1.

Commit 1d8a9637b3 works for me, amended for 14.0.12. k9copy builds and the thumbnail is displayed for ffmpeg versions 3.1.2, 3.4.11, 4.4.2, and 5.0.1.
Owner

Good to see such team cooperation.
I guess at this point we need a test on old distros from @SlavekB :-)

Good to see such team cooperation. I guess at this point we need a test on old distros from @SlavekB :-)
Owner

FTBFS during test on old distribution:

/root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp: In member function 'bool k9AviDecode::open(const TQString&)':
/root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp:108:82: error: 'AVStream' has no member named 'codec_id'
     m_Codec=(AVCodec *)avcodec_find_decoder(m_FormatCtx->streams[m_videoStream]->codec_id);
                                                                                  ^
/root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp: In member function 'void k9AviDecode::seek(double)':
/root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp:191:57: error: 'av_rescale_q' was not declared in this scope
     fspos=av_rescale_q(fspos, AV_TIME_BASE_Q,  time_base);
                                                         ^
FTBFS during test on old distribution: ``` /root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp: In member function 'bool k9AviDecode::open(const TQString&)': /root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp:108:82: error: 'AVStream' has no member named 'codec_id' m_Codec=(AVCodec *)avcodec_find_decoder(m_FormatCtx->streams[m_videoStream]->codec_id); ^ /root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp: In member function 'void k9AviDecode::seek(double)': /root/k9copy-trinity-14.0.13~pre1/./k9author/k9avidecode.cpp:191:57: error: 'av_rescale_q' was not declared in this scope fspos=av_rescale_q(fspos, AV_TIME_BASE_Q, time_base); ^ ```
Poster
Collaborator

Which distro?

Which distro?
Poster
Collaborator

The "av_rescale_q" one is interesting...

I've not changed anything around that particular call other than removing the "dlsym" functionality. The function has been in the public API since ~0.5.1, so anything earlier and the built code wouldn't run, anything since should build OK. I've checked to make sure that "mathematics.h" is brought in by "avutil.h" and it's not that as the relelevant "#include" is there back to 0.5.1.

Puzzling.

The "av_rescale_q" one is interesting... I've not changed anything around that particular call other than removing the "dlsym" functionality. The function has been in the public API since ~0.5.1, so anything earlier and the built code wouldn't run, anything since should build OK. I've checked to make sure that "mathematics.h" is brought in by "avutil.h" and it's not that as the relelevant "#include" is there back to 0.5.1. Puzzling.
Owner

Which distro?

I use Jessie to test for a very old distribution, although we no longer build packages for this distro 😉

> Which distro? I use Jessie to test for a _very old distribution_, although we no longer build packages for this distro 😉
aneejit1 force-pushed ffmpeg5-support from 1d8a9637b3 to e71518b16c 2 years ago
Poster
Collaborator

That's avutil 54.3.0 which puts it somewhere between 2.3.6 (52.92.100) and 2.4 (54.7.100), so probably a pre-release version.

The problem comes from the fact that "avutil.h" seems to have been modified. The Debian 8 version has

/**
 * @}
 */

#include "error.h"
#include "rational.h"
#include "version.h"
#include "macros.h"

and the 2.3.6/2.4 versions have

/**
 * @}
 */

#include "common.h"
#include "error.h"
#include "rational.h"
#include "version.h"
#include "macros.h"
#include "mathematics.h"
#include "log.h"
#include "pixfmt.h"

Quite why this is, I don't know, but the lack of "mathematics.h" is the cause of the problem.

I've implemented the obvious solution which is to specifically include "libavutil/mathematics.h" in "k9avidecode.h". It's protected against being included multiple times so shouldn't cause any duplication issues.

Please give it another go.

That's avutil 54.3.0 which puts it somewhere between 2.3.6 (52.92.100) and 2.4 (54.7.100), so probably a pre-release version. The problem comes from the fact that "avutil.h" seems to have been modified. The Debian 8 version has ``` /** * @} */ #include "error.h" #include "rational.h" #include "version.h" #include "macros.h" ``` and the 2.3.6/2.4 versions have ``` /** * @} */ #include "common.h" #include "error.h" #include "rational.h" #include "version.h" #include "macros.h" #include "mathematics.h" #include "log.h" #include "pixfmt.h" ``` Quite why this is, I don't know, but the lack of "mathematics.h" is the cause of the problem. I've implemented the obvious solution which is to specifically include "libavutil/mathematics.h" in "k9avidecode.h". It's protected against being included multiple times so shouldn't cause any duplication issues. Please give it another go.
SlavekB approved these changes 2 years ago
SlavekB left a comment
Owner

Tested on old distribution and also on testing – both built without problems.

Tested on old distribution and also on testing – both built without problems.
SlavekB merged commit e71518b16c into master 2 years ago
SlavekB deleted branch ffmpeg5-support 2 years ago
SlavekB added this to the R14.0.13 release milestone 2 years ago
Ray-V commented 2 years ago
Collaborator

This is an ffmpeg version issue for me.
All the builds I did were with libavformat >= 57, 33, 100.

If I build with ffmpeg-3.0.9, libavformat == 57, 25, 100, I get the same failure.

With commit e71518b16c, the build completes and k9copy runs, but crashes at selecting the .avi.

If it's any help, there is one of two konsole messages at the point of crashing:
double free or corruption (!prev)
or
corrupted size vs. prev_size while consolidating.

This is just feedback and not an issue for Slackware builds as ffmpeg was introduced to the distro at release 3.2.3, for which the latest patch works.

This is an ffmpeg version issue for me. All the builds I did were with libavformat >= 57, 33, 100. If I build with ffmpeg-3.0.9, libavformat == 57, 25, 100, I get the same failure. With commit e71518b16c, the build completes and k9copy runs, but crashes at selecting the .avi. If it's any help, there is one of two konsole messages at the point of crashing: `double free or corruption (!prev)` or `corrupted size vs. prev_size while consolidating`. This is just feedback and not an issue for Slackware builds as ffmpeg was introduced to the distro at release 3.2.3, for which the latest patch works.
Owner

double free or corruption (!prev)

means a pointer to an object allocated with new is being deleted twice, so it definitely highlights an issue there if we use such version of ffmeg.

> ```double free or corruption (!prev)``` means a pointer to an object allocated with ```new``` is being ```delete```d twice, so it definitely highlights an issue there if we use such version of ffmeg.
Owner

@Ray-V: do akode and k3b build and works fine with ffmpeg-3.0.9 on your system?
If so, I would suggest we adjust the code of this PR to make k9copy also work fine.
If not, then maybe we don't need any extra work here.

@Ray-V: do akode and k3b build and works fine with ffmpeg-3.0.9 on your system? If so, I would suggest we adjust the code of this PR to make k9copy also work fine. If not, then maybe we don't need any extra work here.
Poster
Collaborator

I'll have a dig around and see if I can find anything. I've got an old ffmpeg building so hopefully I can reproduce the problem.

I'll have a dig around and see if I can find anything. I've got an old ffmpeg building so hopefully I can reproduce the problem.
Poster
Collaborator

OK, I think I see the problem and it's down to what ffmpeg is doing when it closes the AVFormat_Context as part of closing the input file. I've just got to work out which version it changed in and it should be easy enough to fix.

OK, I think I see the problem and it's down to what ffmpeg is doing when it closes the AVFormat_Context as part of closing the input file. I've just got to work out which version it changed in and it should be easy enough to fix.
Poster
Collaborator

Got it! Pull request #6 raised to fix the problem.

I'd linked the calling of avcodec_free_context to when it appeared in the API rather than when the "codec" field in AVStream was replaced by "codecpar". As "avformat_close_input" cleans up the AVCodecContext in prior versions, the additional avcodec_free_context call caused the exception.

I've got it wrong in k3b as well, so I'll need to revisit that one shortly. akode needs changing too.

Got it! Pull request #6 raised to fix the problem. I'd linked the calling of avcodec_free_context to when it appeared in the API rather than when the "codec" field in AVStream was replaced by "codecpar". As "avformat_close_input" cleans up the AVCodecContext in prior versions, the additional avcodec_free_context call caused the exception. I've got it wrong in k3b as well, so I'll need to revisit that one shortly. akode needs changing too.
Owner

I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode. What do you think?

I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode. What do you think?
Ray-V commented 2 years ago
Collaborator

do akode and k3b build and works fine with ffmpeg-3.0.9 on your system?
I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode

akode - no

/tmp/build/tmp-akode/akode-trinity-14.0.12/akode/plugins/ffmpeg_decoder/ffmpeg_decoder.cpp:382:15: error: use of undeclared identifier 'avcodec_receive_frame'; did you mean 'avcodec_profile_name'?
    int len = avcodec_receive_frame(d->audioStream_ctx, decodeFrame);
              ^~~~~~~~~~~~~~~~~~~~~
              avcodec_profile_name
/usr/local/include/libavcodec/avcodec.h:5067:13: note: 'avcodec_profile_name' declared here
const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
            ^
/tmp/build/tmp-akode/akode-trinity-14.0.12/akode/plugins/ffmpeg_decoder/ffmpeg_decoder.cpp:382:37: error: cannot initialize a parameter of type 'enum AVCodecID' with an lvalue of type 'AVCodecContext *'
    int len = avcodec_receive_frame(d->audioStream_ctx, decodeFrame);
                                    ^~~~~~~~~~~~~~~~~~
/usr/local/include/libavcodec/avcodec.h:5067:49: note: passing argument to parameter 'codec_id' here
const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
                                                ^
/tmp/build/tmp-akode/akode-trinity-14.0.12/akode/plugins/ffmpeg_decoder/ffmpeg_decoder.cpp:391:15: error: use of undeclared identifier 'avcodec_send_packet'
        len = avcodec_send_packet(d->audioStream_ctx, d->packet);
              ^
3 errors generated.

k3b - no

/tmp/build/tmp-k3b/k3b-trinity-14.0.12/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp:362:15: error: use of undeclared identifier 'avcodec_receive_frame'; did you mean 'avcodec_profile_name'?
    int len = avcodec_receive_frame(d->audio_stream_ctx, d->frame);
              ^~~~~~~~~~~~~~~~~~~~~
              avcodec_profile_name
/usr/local/include/libavcodec/avcodec.h:5067:13: note: 'avcodec_profile_name' declared here
const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
            ^
/tmp/build/tmp-k3b/k3b-trinity-14.0.12/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp:362:37: error: cannot initialize a parameter of type 'enum AVCodecID' with an lvalue of type '::AVCodecContext *' (aka 'AVCodecContext *')
    int len = avcodec_receive_frame(d->audio_stream_ctx, d->frame);
                                    ^~~~~~~~~~~~~~~~~~~
/usr/local/include/libavcodec/avcodec.h:5067:49: note: passing argument to parameter 'codec_id' here
const char *avcodec_profile_name(enum AVCodecID codec_id, int profile);
                                                ^
/tmp/build/tmp-k3b/k3b-trinity-14.0.12/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp:371:13: error: use of undeclared identifier 'avcodec_send_packet'
      len = avcodec_send_packet(d->audio_stream_ctx, d->packet);
            ^
3 errors generated.
> do akode and k3b build and works fine with ffmpeg-3.0.9 on your system? I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode akode - no ``` /tmp/build/tmp-akode/akode-trinity-14.0.12/akode/plugins/ffmpeg_decoder/ffmpeg_decoder.cpp:382:15: error: use of undeclared identifier 'avcodec_receive_frame'; did you mean 'avcodec_profile_name'? int len = avcodec_receive_frame(d->audioStream_ctx, decodeFrame); ^~~~~~~~~~~~~~~~~~~~~ avcodec_profile_name /usr/local/include/libavcodec/avcodec.h:5067:13: note: 'avcodec_profile_name' declared here const char *avcodec_profile_name(enum AVCodecID codec_id, int profile); ^ /tmp/build/tmp-akode/akode-trinity-14.0.12/akode/plugins/ffmpeg_decoder/ffmpeg_decoder.cpp:382:37: error: cannot initialize a parameter of type 'enum AVCodecID' with an lvalue of type 'AVCodecContext *' int len = avcodec_receive_frame(d->audioStream_ctx, decodeFrame); ^~~~~~~~~~~~~~~~~~ /usr/local/include/libavcodec/avcodec.h:5067:49: note: passing argument to parameter 'codec_id' here const char *avcodec_profile_name(enum AVCodecID codec_id, int profile); ^ /tmp/build/tmp-akode/akode-trinity-14.0.12/akode/plugins/ffmpeg_decoder/ffmpeg_decoder.cpp:391:15: error: use of undeclared identifier 'avcodec_send_packet' len = avcodec_send_packet(d->audioStream_ctx, d->packet); ^ 3 errors generated. ``` k3b - no ``` /tmp/build/tmp-k3b/k3b-trinity-14.0.12/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp:362:15: error: use of undeclared identifier 'avcodec_receive_frame'; did you mean 'avcodec_profile_name'? int len = avcodec_receive_frame(d->audio_stream_ctx, d->frame); ^~~~~~~~~~~~~~~~~~~~~ avcodec_profile_name /usr/local/include/libavcodec/avcodec.h:5067:13: note: 'avcodec_profile_name' declared here const char *avcodec_profile_name(enum AVCodecID codec_id, int profile); ^ /tmp/build/tmp-k3b/k3b-trinity-14.0.12/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp:362:37: error: cannot initialize a parameter of type 'enum AVCodecID' with an lvalue of type '::AVCodecContext *' (aka 'AVCodecContext *') int len = avcodec_receive_frame(d->audio_stream_ctx, d->frame); ^~~~~~~~~~~~~~~~~~~ /usr/local/include/libavcodec/avcodec.h:5067:49: note: passing argument to parameter 'codec_id' here const char *avcodec_profile_name(enum AVCodecID codec_id, int profile); ^ /tmp/build/tmp-k3b/k3b-trinity-14.0.12/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp:371:13: error: use of undeclared identifier 'avcodec_send_packet' len = avcodec_send_packet(d->audio_stream_ctx, d->packet); ^ 3 errors generated. ```
Owner

I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode. What do you think?

@Ray-V how about k9copy #6?

>I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode. What do you think? @Ray-V how about k9copy #6?
Owner

I don't know what case you have, but mine case on Debian 9.x (Stretch) as well as on Debian 10.x (Buster) is:

  1. Run k9copy.
  2. Switch to DVD Author mode.
  3. Click icon Extract MPEG2.
  4. K9copy crashes immediately.

This occurs independent of the patch in this PR => I tried downgrade to the version R14.0.12 and it crashes the same way.

I don't know what case you have, but mine case on Debian 9.x (Stretch) as well as on Debian 10.x (Buster) is: 1. Run k9copy. 2. Switch to DVD Author mode. 3. Click icon Extract MPEG2. 4. K9copy crashes immediately. This occurs independent of the patch in this PR => I tried downgrade to the version R14.0.12 and it crashes the same way.
Poster
Collaborator

I don't know what case you have, but mine case on Debian 9.x (Stretch) as well as on Debian 10.x (Buster) is:

  1. Run k9copy.
  2. Switch to DVD Author mode.
  3. Click icon Extract MPEG2.
  4. K9copy crashes immediately.

This occurs independent of the patch in this PR => I tried downgrade to the version R14.0.12 and it crashes the same way.

I've got that too. Looks like a different problem unrelated to the ffmpeg issues. It's going over in "k9copy.cpp" and there's no ffmpeg code in there.

> I don't know what case you have, but mine case on Debian 9.x (Stretch) as well as on Debian 10.x (Buster) is: > > 1. Run k9copy. > 2. Switch to DVD Author mode. > 3. Click icon Extract MPEG2. > 4. K9copy crashes immediately. > > This occurs independent of the patch in this PR => I tried downgrade to the version R14.0.12 and it crashes the same way. I've got that too. Looks like a different problem unrelated to the ffmpeg issues. It's going over in "k9copy.cpp" and there's no ffmpeg code in there.
Poster
Collaborator

I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode. What do you think?

@Ray-V how about k9copy #6?

There's a k3b #16 that should sort out the build problem there. I'll hold off on akode for now as that will be the same again.

> >I suggest we wait for @Ray-V to confirm it works fine with ffmpeg-3.0.9 before fixing up k3b and akode. What do you think? > > @Ray-V how about k9copy #6? There's a k3b #16 that should sort out the build problem there. I'll hold off on akode for now as that will be the same again.

Reviewers

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

No due date set.

Dependencies

No dependencies set.

Reference: TDE/k9copy#5
Loading…
There is no content yet.