Skip to content
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

FFmpeg with CFFI for faster video decompression #1361

Merged
merged 25 commits into from
Jan 26, 2022

Conversation

FayazRahman
Copy link
Contributor

🚀 🚀 Pull Request

Checklist:

  • My code follows the style guidelines of this project and the Contributing document
  • I have commented my code, particularly in hard-to-understand areas
  • I have kept the coverage-rate up
  • I have performed a self-review of my own code and resolved any problems
  • I have checked to ensure there aren't any other open Pull Requests for the same change
  • I have described and made corresponding changes to the relevant documentation
  • New and existing unit tests pass locally with my changes

Changes

Implement video decompression in C and interface with it using CFFI

@CLAassistant
Copy link

CLAassistant commented Nov 30, 2021

CLA assistant check
All committers have signed the CLA.

@AbhinavTuli
Copy link
Contributor

Any numbers you can share on how much faster this will be?

@FayazRahman
Copy link
Contributor Author

FayazRahman commented Dec 2, 2021

@AbhinavTuli in-memory decompression is around 65 percent faster and close to 40 percent faster for decompression from files. This is average over all file types. The increase will be different for each of them seperately.

@AbhinavTuli AbhinavTuli added the trigger-test Label trigger to run tests on PRs label Jan 17, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 17, 2022
int decompressVideo(unsigned char *file, int size, int ioBufferSize, unsigned char *decompressed, int isBytes, int nbytes)
{
av_log_set_level(AV_LOG_QUIET);
AVFormatContext *pFormatContext = 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 we allocate context once and store it in python object? It seems redundant to me to do it every time. Also prone to memory leak of something goes wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so because we will have a pointer to a pointer and when the underlying object gets freed we will point to garbage.

"pipe:",
]
nbytes = np.prod(shape)
decompressed = ffi.new(f"unsigned char[{nbytes}]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this always holds ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Where it is de-allocated ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It holds for the uint8 videos that we are supporting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deallocation is taken care of by CFFI

@farizrahman4u farizrahman4u added the trigger-test Label trigger to run tests on PRs label Jan 20, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 20, 2022
@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 21, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 21, 2022
@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 25, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 25, 2022
@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 25, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 25, 2022
@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #1361 (bd1d229) into main (e5be11f) will decrease coverage by 0.51%.
The diff coverage is 54.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1361      +/-   ##
==========================================
- Coverage   92.09%   91.58%   -0.52%     
==========================================
  Files         178      179       +1     
  Lines       14311    14397      +86     
==========================================
+ Hits        13180    13185       +5     
- Misses       1131     1212      +81     
Flag Coverage Δ
unittests 91.58% <54.25%> (-0.52%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
hub/core/pyffmpeg/build_ffmpeg_ffi.py 0.00% <0.00%> (ø)
setup.py 0.00% <0.00%> (ø)
hub/core/sample.py 87.87% <66.66%> (-0.95%) ⬇️
hub/api/tests/test_video.py 93.10% <71.42%> (-6.90%) ⬇️
hub/core/compression.py 78.96% <75.00%> (-10.20%) ⬇️
hub/core/ipc.py 0.00% <0.00%> (ø)
hub/__init__.py 97.77% <0.00%> (+0.05%) ⬆️
hub/tests/path_fixtures.py 93.58% <0.00%> (+0.53%) ⬆️
hub/core/meta/encode/chunk_id.py 96.74% <0.00%> (+0.81%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5be11f...bd1d229. Read the comment docs.

@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@FayazRahman FayazRahman added the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@activeloop-bot activeloop-bot removed the trigger-test Label trigger to run tests on PRs label Jan 26, 2022
@farizrahman4u farizrahman4u merged commit 19a0059 into activeloopai:main Jan 26, 2022
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.

6 participants