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

MP4 conversion - Performance improvements #234

Closed
alxbl opened this issue Jun 15, 2020 · 3 comments
Closed

MP4 conversion - Performance improvements #234

alxbl opened this issue Jun 15, 2020 · 3 comments
Labels
enhancement New feature or request investigate Needs more thought / experience

Comments

@alxbl
Copy link
Collaborator

alxbl commented Jun 15, 2020

The time it takes to convert a replay file to MP4 seems to be an order of magnitude slower that actual replay playback.

I'd guess it's because the code is not using the PyAV bindings efficiently, or the default preset is too aggressive.

I tried saving individual PNGs (and BMPs) for each frames and using ffmpeg to convert to the final mp4 and this is roughly 10x faster. FFMPEG is multithreading the encoding, but I haven't figured out whether it's possible/exposed with PyAV.

Dumping stills is not practical for very long replays due to the disk space and additional steps required for conversion.


We should experiment with the PyAV API whether some multithreading can be done, and whether chunking the data (i.e. sending batches of X frames at once for muxing) improves performance.

@alxbl alxbl added enhancement New feature or request investigate Needs more thought / experience labels Jun 15, 2020
@xshill xshill self-assigned this Dec 17, 2020
@obilodeau
Copy link
Collaborator

For the record, on my system, encoding a 45s (2 megabytes) session took almost 7 minutes:

$ date && pyrdp-convert.py -f mp4 pyrdp_output/replays/rdp_replay_20200224_18-55-17_457_Hugh675853.pyrdp && date
Thu Dec 17 03:54:52 PM EST 2020
[*] Converting 'pyrdp_output/replays/rdp_replay_20200224_18-55-17_457_Hugh675853.pyrdp' to MP4
Converting to MP4|                                                           #                                             | Elapsed: 0:06:44
[+] Succesfully wrote 'rdp_replay_20200224_18-55-17_457_Hugh675853.mp4'
Converting to MP4|                                                                                                        #| Elapsed: 0:06:49
Thu Dec 17 04:01:48 PM EST 2020

@xshill xshill removed their assignment Jan 22, 2021
@obilodeau
Copy link
Collaborator

The fix done in #273 accelerated the encoding by 2x:

$ date && pyrdp-convert.py -f mp4 pyrdp_output/replays/rdp_replay_20200224_18-55-17_457_Hugh675853.pyrdp && date
Wed Jan 27 10:44:42 AM EST 2021
[*] Converting 'pyrdp_output/replays/rdp_replay_20200224_18-55-17_457_Hugh675853.pyrdp' to MP4
100% (225 of 225) |####################################################################################| Elapsed Time: 0:03:04 Time:  0:03:04

[+] Succesfully wrote 'rdp_replay_20200224_18-55-17_457_Hugh675853.mp4'
Wed Jan 27 10:47:50 AM EST 2021

I'm going to write it in the changelog. 🎈

@obilodeau
Copy link
Collaborator

The fix done in #349 led to a 6x improvement! Combined with #273 this means a 12x improvement since this issue was opened.

There's a comment in the code about threading now. I just re-tested it and it had a net negative impact on performance. We would need to rewrite the encoder to proceed in batches but even then I'm not sure. PyAV is not super clear about threading encoding performance.

I'm closing this for now since we did achieve 12x. We will open another one when we hit another wall after the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request investigate Needs more thought / experience
Projects
None yet
Development

No branches or pull requests

3 participants