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

Add audio_async_render #79

Closed

Conversation

Ichunjo
Copy link
Contributor

@Ichunjo Ichunjo commented Oct 14, 2021

This PR adds audio_async_render. It works the same way as clip_aync_render, requesting frames asynchronously using get_frame_async.

I had to modify a part of the code to make it work like renaming RenderContext and finish_frame.
I tried to add a lot of comments to better understand the code since I had to document myself to write the function.

I think adding the URLs I used in the code wouldn't be best idea so here are them:

https://web.archive.org/web/20051028052230/http://media.vcs.de/Downloads/Sony_Wave64.pdf
https://github.com/vapoursynth/vapoursynth/blob/master/src/common/wave.cpp
https://github.com/xiph/flac/blob/27c615706cedd252a206dd77e3910dfa395dcc49/src/flac/encode.c
https://github.com/tpn/winsdk-10/blob/master/Include/10.0.14393.0/shared/mmreg.h#L2107
https://docs.microsoft.com/en-us/windows/win32/api/mmreg/ns-mmreg-waveformatextensible
scipy/scipy#6852
https://gist.github.com/josephernest/3f22c5ed5dabf1815f16efa8fa53d476
https://stackoverflow.com/questions/31739143/when-to-use-wave-extensible-format

Why in lvsfunc?

Well there is already clip_async_render and there is relatively duplicated code. I didn't change anything inside clip_aync_render but changes could be made now that audio is a thing in Vapoursynth.

Why numpy?

A vapoursynth.RawFrame is a Sequence like of memoryviews. We need to stack them to perform computations. I don't know if a solution without numpy exists but it would probably be slower.
Numpy is used quite enough in python environment and some vapoursynth *funcs need it. Plus it's a pretty solid package highly maintained.

Performance

I still need to do proper performance comparisons but it's ~40 % slower than vspipe. Makes sense since it's done in python and not in C.

24:28 minutes 24 bit wave file:

  • audio_async_render Duration: 16.13 seconds
  • vspipe Duration 11.20 seconds

@Ichunjo
Copy link
Contributor Author

Ichunjo commented Oct 14, 2021

Mypy's complains is the out of date stubs. They don't include audio stuff yet. I could update them but I think louis used his fork to generate them.

@Ichunjo
Copy link
Contributor Author

Ichunjo commented Oct 15, 2021

Performance tests:

# audio_async_render

# Wav 16 bits
# Best duration: 9.78
# Mean duration: 13.22

# Wav 24 bits
# Best duration: 15.34
# Mean duration: 19.14

# Wav 32 bits
# Best duration: 17.22
# Mean duration: 22.37
# vspipe

# Wav 16 bits
# Mean duration: 7.86

# Wav 24 bits
# Mean duration: 11.25

# Wav 32 bits
# Wave64 header -> Mean duration: 15.14
# Wave header -> Mean duration: 20.49

Made on a 24:28 minutes wave file

@Ichunjo
Copy link
Contributor Author

Ichunjo commented Dec 6, 2021

Added in Ichunjo/vardautomation@a334b2c using clip.frames(...) instead. Speed isn’t impacted, thanks to the updates of the function.

@Ichunjo Ichunjo closed this Dec 6, 2021
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.

None yet

1 participant