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

Massive MP4 conversion speed improvement #349

Merged
merged 9 commits into from
Aug 30, 2021

Conversation

obilodeau
Copy link
Member

Did some profiling with snakeviz today. It was clear where the bulk of our time was spent:

2021-08-27_12-50

Reading about ImageQt.fromqimage() I found out that it would compress to png the whole frame. That operation is completely unnecessary here since PyAV will perform compression to video as well. I found a way to pass an array of bytes instead using numpy. Here are the benchmarks.

with from_image via QTImage:

$ time pyrdp-convert.py pyrdp_output/replays/rdp_replay_20210826_12-15-33_512_Stephen215343.pyrdp -f mp4
[*] Converting 'pyrdp_output/replays/rdp_replay_20210826_12-15-33_512_Stephen215343.pyrdp' to MP4
100% (1465 of 1465) |##################################################################################| Elapsed Time: 0:07:08 Time:  0:07:08

[+] Succesfully wrote 'rdp_replay_20210826_12-15-33_512_Stephen215343.mp4'

real	7m23.110s
user	7m33.381s
sys	0m8.217s

with from_ndarray and qimage2ndarray:

$ time pyrdp-convert.py pyrdp_output/replays/rdp_replay_20210826_12-15-33_512_Stephen215343.pyrdp -f mp4
[*] Converting 'pyrdp_output/replays/rdp_replay_20210826_12-15-33_512_Stephen215343.pyrdp' to MP4
100% (1465 of 1465) |##################################################################################| Elapsed Time: 0:00:55 Time:  0:00:55

[+] Succesfully wrote 'rdp_replay_20210826_12-15-33_512_Stephen215343.mp4'

real	0m59.565s
user	1m20.037s
sys	0m1.196s

This will probably have an impact of our full image size since numpy will be pulled in. However, I think I can get rid of PIL. I'll let CI decide.

I compared the resulting MP4 visually and didn't find a noticeable difference.

@obilodeau obilodeau added this to the v1.2.0 milestone Aug 27, 2021
@obilodeau obilodeau added the enhancement New feature or request label Aug 27, 2021
@obilodeau obilodeau self-assigned this Aug 27, 2021
We no longer require pillow since we convert images to numpy arrays when encoding video now.
I couldn't use the current session test since it doesn't carry the
capabilities packet and I couldn't paint the correct first frame and we
don't support live resize for the video conversion yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant