Skip to content

Attempt to fix FFMPEG 5.0 compatibility #5644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Mar 25, 2022
Merged

Conversation

bjuncek
Copy link
Contributor

@bjuncek bjuncek commented Mar 18, 2022

Attempting to address #5616 via simple API update.
Should be properly tested in FB internals.

cc @datumbox

@facebook-github-bot
Copy link

facebook-github-bot commented Mar 18, 2022

💊 CI failures summary and remediations

As of commit 3c7e998 (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

1 failure not recognized by patterns:

Job Step Action
CircleCI cmake_linux_gpu Build torchvision C++ distribution and test 🔁 rerun

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjuncek Thanks for fixing this. The changes look good to me. I've only added one comment for your attention.

Our CI is currently broken, so I propose not to merge this until #5648 is merged and it's properly tested on FB infra as you suggested. We'll get back to you on the latter.

Copy link
Contributor

@jdsgomes jdsgomes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have imported the PR and pointed out a few things to be considered.

// update 03/22: moving memory management to ffmpeg
AVPacket* avPacket;
avPacket = av_packet_alloc();
if (avPacket == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this NULL be replaced by nullptr? the internal linter CLANGTID is complaining about this line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return inside this if-clause, otherwise we will access the NULL pointer in the next line.

@jdsgomes
Copy link
Contributor

jdsgomes commented Mar 22, 2022

@bjuncek I made a few changes in an attempt to fix the memory leak and the static code analysis warnings, but there are a few things that came up that would need discussion when you are back as you will probably have more context:

  • if you agree with the approach here and here, we probably need to follow the same in torchvision/csrc/io/decoder/subtitle_stream.cpp
  • it is not 100% clear to me what is the difference between av_packet_unref and av_packet_free. From what I can gather in the documentation, the former unreferences the inner buffer and resets the default values and the later frees the actual avPacket object but please confirm that is the case and that we need both in the way it has been used

@bjuncek
Copy link
Contributor Author

bjuncek commented Mar 23, 2022

if you agree with the approach here and here, we probably need to follow the same in torchvision/csrc/io/decoder/subtitle_stream.cpp

Yup, have added the changes; this is something you might need checking in FB infra as subtitle stream was (yet) not used in TV, but might have been used internally (I've been long gone).

it is not 100% clear to me what is the difference between av_packet_unref and av_packet_free. From what I can gather in the documentation, the former unreferences the inner buffer and resets the default values and the later frees the actual avPacket object but please confirm that is the case and that we need both in the way it has been used

My understanding in this case is the same as yours, and I do thing we'd need both; do these changes pass the static memory leak checks?

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work @bjuncek. I think it looks good.

@jdsgomes Could you check if this works OK internally?

LOG(ERROR)
<< "decoder as not able to allocate the subtitle-specific packet.";
// alternative to ENOMEM
return AVERROR_BUFFER_TOO_SMALL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we align the error code with the corresponding bit in decoder.cpp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdsgomes The two methods return different enums. Originally Bruno had them synced; no strong opinions on my side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdsgomes would you like me to change it to match?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer for consistency, unless there is a reason not to. Other than that the PR looks good and the internal tests are passing. Thank you for these changes

@@ -43,21 +43,34 @@ int SubtitleStream::initFormat() {
int SubtitleStream::analyzePacket(const AVPacket* packet, bool* gotFrame) {
// clean-up
releaseSubtitle();

// FIXME: should this even be created?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree - I am also not sure if this should be created. Is the plan to follow up on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think this would require a bit of coordination on Meta's side, as this is not used nor tested in TV.

@jdsgomes
Copy link
Contributor

For reference the internal tests are passing: https://www.internalfb.com/diff/D35115411

@bjuncek
Copy link
Contributor Author

bjuncek commented Mar 25, 2022

@datumbox I'll leave it up to you to decide if it's ready for merge.

@jdsgomes
Copy link
Contributor

I have a nit regarding he return codes but definitely non blocking.

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjuncek LGTM, thanks!

@jdsgomes I agree that a good API should align the return error codes across functions. I'm OK if you want to merge this now and follow up in a new PR. I'm also OK if you want to push the change directly on this branch. I leave it to you how we should proceed. At any case, we should merge this soon. We are already a week with broken CI and the issue is masking other potential problems that are not reported to the release engineering team.

@jdsgomes jdsgomes merged commit da03f51 into pytorch:main Mar 25, 2022
facebook-github-bot pushed a commit that referenced this pull request Apr 5, 2022
Summary:
* fix for FFMPEG 5.0

* Attempt to fix memory leak

* early stop when mem alloc fails

* fix c lint error

* fix bug

* revert changes

* remove incorrect av_packet_free

* add `av_packet_free` to subtitle stream

* Addressing subtitle stream comments

* addressing decoder changes

* nit

* addressing datumbox concernsz

* averror push

* addressing comments

* Apply suggestions from code review

* add new error code to documentation

* re-introducing timeout

* fix c++ syntax

(Note: this ignores all push blocking failures!)

Reviewed By: datumbox

Differential Revision: D35216769

fbshipit-source-id: e3489471406663c8e71fc239164a682993771db3

Co-authored-by: Bruno Korbar <[email protected]>
Co-authored-by: Vasilis Vryniotis <[email protected]>
Co-authored-by: Joao Gomes <[email protected]>
Co-authored-by: Joao Gomes <[email protected]>
@bjuncek bjuncek deleted the bkorbar/5616_v2 branch April 14, 2022 10:39
Miriup pushed a commit to Miriup/torchvision-cuda-10.2 that referenced this pull request Dec 9, 2024
* fix for FFMPEG 5.0

* Attempt to fix memory leak

* early stop when mem alloc fails

* fix c lint error

* fix bug

* revert changes

* remove incorrect av_packet_free

* add `av_packet_free` to subtitle stream

* Addressing subtitle stream comments

* addressing decoder changes

* nit

* addressing datumbox concernsz

* averror push

* addressing comments

* Apply suggestions from code review

* add new error code to documentation

* re-introducing timeout

* fix c++ syntax

Co-authored-by: Bruno Korbar <[email protected]>
Co-authored-by: Vasilis Vryniotis <[email protected]>
Co-authored-by: Joao Gomes <[email protected]>
Co-authored-by: Joao Gomes <[email protected]>
(cherry picked from commit da03f51)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants