Avisynth+64, Multithreading, Etc.#7
Conversation
Zinfidel
commented
May 3, 2021
- Plugin loading accomplished via Avisynth+ methods.
- All plugins updated to 64 bit versions
- Multithreading support added as well as new threads variable for user to set.
- Moved assrender line in encode.avs up to fix a problem where .ass subtitles get applied to a video that was originally >60fps but is no longer (e.g. youtube conversion) and caused a desync
- Removed avs2pipemod. x264 can use avisynth scripts directly, and ffprobe.exe has been introduced for timestamp generation.
- Audio encoding programs removed, replaced by custom ffmpeg
- Added build scripts/instructions for ffmpeg/ffprobe
- Changed command for VB encodes to use mkvmerge. This removes the reliance on a larger version of ffmpeg that can handle h264 encoding etc.
- Re-added ssl license thing that tvcman comes with
- Removed lots of vestigial dlls
Use AviSynth+ functions for plugin loading. Use new multithreading functions. Update all plugins to 64-bitness. Remove avs2pipemode.exe entirely and replace with ffprobe.exe. Replace all audio encoding with custom ffmpeg.exe.
|
Aside from general testing, there is a line in the original global.bat that I'm not sure about: |
| @@ -1,230 +0,0 @@ | |||
| Autolevels 0.6 for Avisynth, Jan. 2011 | |||
There was a problem hiding this comment.
We need to keep it somewhere.
There was a problem hiding this comment.
I can add it back. There are however a lot of readme files and licenses that could be added though - the plugins each have their own readme, and some plugins (like assrender) have an entire folder of licenses that go with it. Should we add all plugin readmes/licenses?
There was a problem hiding this comment.
I've added a docs folder with all licenses and readmes from programs and plugins that we use. We can roll back and take stuff out if we don't want everything.
There was a problem hiding this comment.
Oh, right! Would it be too annoying to put them in folders corresponding to what they belong to? ffmpeg-config is technically docs too.
|
Let's have those unzipped, in a folder. |
|
When I tried building x264 on my own I also noticed that it was like 20 times smaller, so might make sense to use a lighter build here too. |
|
Some BG info for qaac: http://tasvideos.org/forum/viewtopic.php?p=454950#454950 |
|
Thread about currently used delays: http://tasvideos.org/forum/viewtopic.php?t=19507 |
|
On building x264 - building ffmpeg here makes it much smaller because I'm stripping it down to almost nothing. If you can strip stuff out of x264 as well it might be worth it indeed. I don't know that I want to invest the energy into figuring out how to build it right now though. On the audio delays: Interestingly, after running the audio through the encoders inside of ffmpeg, the opus and ogg output are lined up exactly, the aac-he audio is delayed now. For the test data I'm using, it's a delay of 0.161 seconds, or 7048 samples. Working on this. Another issue: It appears that the opus format does not support any sampling rates besides 48,000hz and is in fact heavily optimized for this. When opusenc.exe encodes a file, it will insert the original sampling rate into the header of the opus/ogg container, which then can be read by some programs (like mkvmerge in our case) to report the original sampling rate. However, opus always encodes and decodes audio at 48khz regardless of what the original frequency is listed as in the header. ffmpeg does not set this header data though, and I can't find a way to force it to. So, when we encode using libopus inside of ffmpeg, the audio that comes out is shown as 48khz, regardless of the sampling rate of the original audio. It's been doing this for all of our encodes up until now as far as I can tell, it has just been "lying" to us about how it gets decoded. Read me here: https://trac.ffmpeg.org/ticket/5240 . So how big a problem is this do you think? Our modern encodes would now say 48khz sampling rate, unless we use some external tool to change the tags or something. |
|
I've just spent the night learning a lot more about aac then I really would have preferred. The issue with decoder priming (the set amount of samples that show up at the start of an aac stream) gets more difficult to deal with when using ffmpeg's libfdk_aac. Wheras tools like qaac and various others that implement libfdk have options for dealing with the priming samples for a/v sync (as was made use of by the people in that tasvideos thread), ffmpeg does not. What makes it worse is that the amount of priming data changes depending on the sample frequency, so there isn't a one-size-fits all trim value we can apply. For 44.1khz data, there are about ~7000 samples that need to be trimmed, but at 48khz, there are about 200 more. The time difference between this is tiny, about 1 frame, but it's still not exact so that's frustrating because qaac can do it, but ffmpeg seemingly can't. I've tested sampling frequency and a few other parameters and the numbers change each time, which isn't good. So the question now is - if we really need to use something other than ffmpeg for doing aac encoding, then is it worth trying to use ffmpeg for any audio encoding? I feel it's kind of all or nothing here, and the amount of effort it feels like it's going to take to get automatically correctly-aligned aac audio out of ffmpeg is just too high considering we have something that works already. I've actually got the custom ffmpeg built with pipe support anyway and I'm pretty sure it will happily pipe to whatever audio programs we have, so dropping avs2pipemod will still work. It's a shame because I wanted to consolidate stuff but I don't want to spend a week on this either. I did think of one solution to the problem, but it's overly complicated and would be slow. Encoding the audio to aac-he once, then using ffprobe to get the duration. Duration could be compared to original pcm stream, and the difference would be the required offset. The stream would have to be re-encoded with a trim. A re-encode could probably be avoided by just muxing into mp4 with a negative offset, but I'm not sure that muxing with negative offsets is something we want to do with a compatibility download in the first place. Links I found useful: Open questions I have:
|
Yeah, maybe someday. It was rather easy to build with mingw.
Does it actually resample it though? All bizhawk output is 44100Hz for example.
Is it to get resolve the variable delay length based on samplerate? If so, we could just force some known sameplerate and fix the delay value.
Trim using which tool?
The mp4 encode is almost useless anyway, so I'm not sure if we're losing anything really. I think even if we use this offset feature and just wait for user complaints, there will not be any, ever. 10 years ago we were still considering video players that people have at home, but these days everyone just watches youtube. Which is an entirely different beast btw: it's probably the only video hosting other than archive that allows to upload infinite amount of video with almost infinite resolution, and hosts them indefinitely. But if the channel gets banned, there's no way to restote all those uploads. And no way to have a backup, because they're very huge.
For test purposes, we could use the official build just to know if it helps first. |
All of my info about this is coming from https://trac.ffmpeg.org/ticket/5240 . According to the conversation in that link, input is resampled to 48khz and encoded, with the original sampling rate then added as metadata to the file. Upon decoding, the application doing the decoding can decide to act on that data and resample the 48khz opus stream to the original value. In my tests,
Moot point now, I found out my testing methodology was flawed. The version of
|
|
We could just force-resample all our audio, or only what goes to opus. Or resample everything to 44100 and what goes to opus to 48000. Feels like the most straightforward approach would be to force 48000 on everything. I don't think there will be any artifacts, but I don't know much about audio. |
|
The AAC lag is fixed using a fixed sample trim of 7106 samples. Opus and Vorbis line up perfectly without modification so that is good. I have a program that can write the Opus metadata if we want - would just be another line in the Modern encodes sections to run it with the original audio sampling rate. It's not included in this PR as it stands though. |
|
I'm marking this as ready since it feels like it's there or at least pretty close. Only other thing is looking into that custom x264 you built if you want to include it. |
|
Why not! |
|
You should create a release after this PR as well, since the repo now weighs in at 153MB due to the binary file replacements over time. |
|
Ah, I didn't realize that downloading a zip from github removed all of the git stuff. I checked the size of the repo on my machine that has all of the git history and my recent branch, which is where the 153MB came from. No release necessary since the zip already removes the git folders! |
