Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 21st June 2017, 10:10   #3461  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,054
Quote:
Originally Posted by MysteryX View Post
What is causing such a bottleneck at 42% CPU usage?
I've noticed the same with John Meyer's simpler script. It has to be one (or a combination) of the mvtools2 functions that does not scale well with MT.

Edit: Throwing more threads at it seems to improve things without compromising efficiency (CPU with 4 cores/threads):

Code:
Prefetch(4):
FPS (min | max | average):      4.755 | 275350 | 48.26
Memory usage (phys | virt):     310 | 409 MiB
Thread count:                   15
CPU usage (average):            66%
Efficiency index:               0.7312


Prefetch(6):
FPS (min | max | average):      17.36 | 167.1 | 57.60
Memory usage (phys | virt):     413 | 514 MiB
Thread count:                   17
CPU usage (average):            79%
Efficiency index:               0.7292


Prefetch(8):
FPS (min | max | average):      14.93 | 4436 | 69.60
Memory usage (phys | virt):     527 | 628 MiB
Thread count:                   19
CPU usage (average):            95%
Efficiency index:               0.7326


Prefetch(10):
FPS (min | max | average):      15.04 | 158387 | 72.15
Memory usage (phys | virt):     654 | 756 MiB
Thread count:                   21
CPU usage (average):            99%
Efficiency index:               0.7288
Please note that this was done with John Meyer's script and an older version of mvtools2 (2.5.11.22) but the trend should be similar with your FrameRateConverter and pinterf's latest mvtools.

Last edited by Groucho2004; 21st June 2017 at 10:47.
Groucho2004 is offline  
Old 21st June 2017, 13:37   #3462  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,852
Quote:
Originally Posted by Sharc View Post
I think I found the culprit. I am using in my script
Code:
temporalsoften(4,4,8,10,mode=2)
It seems to have no effect with AVS+ r2506, while it works as expected in AVS260.
r2506 is giving identical results to the very early (1576) avs+ versions.
Maybe this sse2 part was a bit overoptimized, because now I replaced it with something I could understand and it is giving the same result as classic Avisynth 2.6.
I think using max thresholds (like QTGMC does) there is no problem with latest avs+ versions, I have put that special case in a separate optimized code path earlier.

So expect a fix for this.

And until then read this comment from Myrsloik.
pinterf is offline  
Old 21st June 2017, 15:13   #3463  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 3,820
Quote:
Originally Posted by pinterf View Post

.... So expect a fix for this.

And until then read this comment from Myrsloik.
Excellent, thanks!
Well, maybe there exist better substitutes for temporalsoften(). I found it however to be a very useful and effective filter for VHS sources.
Sharc is offline  
Old 21st June 2017, 16:19   #3464  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
There is no SetMemory. I'm using x86.

The only thing that comes into the log is
Code:
INFO: LSMASHSource_LWLibavVideoSource() does not have any MT-mode specification.
Because it is a source filter, it will use MT_SERIALIZED instead of the default MT mode.
until it ran out of memory with 8 threads and crashed.

Here's the code, running on a 1080p source
Code:
file="Female President.mp4"
SetLogParams("log.txt", LOG_DEBUG)
LWLibavVideoSource(file, cache=False)
ConvertToYV12()
FrameRateConverter(60)
Prefetch(8)
Code:
FPS (min | max | average):      1.157 | 101672 | 13.12
Memory usage (phys | virt):     1446 | 1451 MiB
Thread count:                   29
CPU usage (average):            52%
Output="flow"
Code:
FPS (min | max | average):      2.674 | 93538 | 18.11
Memory usage (phys | virt):     1423 | 1434 MiB
Thread count:                   29
CPU usage (average):            64%
jm_fps alone
Code:
FPS (min | max | average):      3.096 | 97436 | 16.91
Memory usage (phys | virt):     1457 | 1465 MiB
Thread count:                   29
CPU usage (average):            63%
I was wondering whether unused script filters were being initiated and causing performance or memory problems. I can see it's not an issue.

Yes, the issue is in MvTools2 and should be tested on jm_fps. In my case, I can't fix performance by increasing threads (8 cores). 12 gives a slight performance increase, and 16 gives a performance decrease.

and here's performance on a 1080p source with DCT=1 (preset="slow")
Code:
FPS (min | max | average):      0.083 | 83516 | 0.484
Memory usage (phys | virt):     1168 | 1166 MiB
Thread count:                   26
CPU usage (average):            26%
I'd get a nice 1.5fps if CPU would work fully.

Last edited by MysteryX; 21st June 2017 at 16:25.
MysteryX is offline  
Old 22nd June 2017, 12:38   #3465  |  Link
chummy
Registered User
 
Join Date: Aug 2014
Posts: 39
I'm facing a problem with specific source VP9 file with single keyframe. FFMS2 cause error and Directshowsource change clip duration by few millliseconds and cause framecount to change, this is enough to audio come out of sync.

Code:
[avisynth @ 0358ba40] FFVideoSource: Out of bounds frame requestede=16629.7kbits/s speed=0.247x
Unknown error occurred
Input check with FFMpeg:
Code:
Duration: 00:02:02.56, start: -0.007000, bitrate: 11360 kb/s
    Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc (default)
When feeding Avisynth+(ffms2) script to FFMpeg:
Code:
Duration: 00:02:02.12, start: 0.000000, bitrate: 0 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 29.97 fps, 29.97 tbr, 29.97 tbn, 29.97 tbc
When feeding with Avs+ and Directshowsource:
Code:
Input #0, avisynth, from 'GTA5 1600mhz low.avs':
  Duration: 00:02:02.59, start: 0.000000, bitrate: 0 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 29.97 fps, 29.97 tbr, 29.97 tbn, 29.97 tbc
Directshowsource is only changing by 3ms, but for videos longer than 5 minutes there is noticeable out of sync audio.

Encoding the video directly with FFMpeg cause no such issue.

Last edited by chummy; 22nd June 2017 at 12:46.
chummy is offline  
Old 23rd June 2017, 02:30   #3466  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
Under Avisynth 2.6, BitsPerComponent returns 0 instead of 8. Seems like a bug to me.
MysteryX is offline  
Old 23rd June 2017, 08:26   #3467  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,054
Quote:
Originally Posted by MysteryX View Post
Under Avisynth 2.6, BitsPerComponent returns 0 instead of 8. Seems like a bug to me.
I checked your FramerateConverter git repository, the avisynth.h you're using does not have the fallback mechanism. Update to the latest headers and it will work correctly.

Last edited by Groucho2004; 23rd June 2017 at 13:49.
Groucho2004 is offline  
Old 23rd June 2017, 16:54   #3468  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,473
Quote:
Originally Posted by chummy View Post
I'm facing a problem with specific source VP9 file with single keyframe. FFMS2 cause error and Directshowsource change clip duration by few millliseconds and cause framecount to change, this is enough to audio come out of sync.
I think DirectShowSource uses 29.970fps as the frame rate. Maybe adding AssumeFPS(3000,1001) to the end of the script will fix it, although the difference is very small.

There'd probably be minor differences in the way the timing is rounded, as at 29.970fps (3000/1001) each frame has a duration of 33.366666_ ms.
If my maths is correct your clip's duration should be 00:02:02.53.4666666 ms (at frame number 3658). I checked a clip with Avisynth using Info() and at frame 3658 it reports 00:02:02.55 ms. Maybe ffmpeg uses a slightly different pattern for rounding frames to the nearest ms.

Try this:
DirectShowSource("E:\video.mkv", audio=false, fps=29.970, convertfps=true).AssumeFPS(3000,1001)

Or this:
FFVideoSource("E:\video.mkv", threads=1, fpsnum=30000, fpsden=1001)
hello_hello is offline  
Old 23rd June 2017, 17:41   #3469  |  Link
stax76
Registered User
 
stax76's Avatar
 
Join Date: Jun 2002
Location: On thin ice
Posts: 6,712
FFVideoSource fpsnum/fpsden drops/adds frame though
stax76 is online now  
Old 23rd June 2017, 17:53   #3470  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,570
You guys realize a/v sync is about video and audio, right?
sneaker_ger is offline  
Old 23rd June 2017, 18:31   #3471  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
Quote:
Originally Posted by Groucho2004 View Post
I've noticed the same with John Meyer's simpler script. It has to be one (or a combination) of the mvtools2 functions that does not scale well with MT.
I've just done an encoding test and it ran at about ~15% CPU usage which is unacceptable.

If I were to guess, it looks like incorrect mutex locks preventing proper MT execution.
MysteryX is offline  
Old 23rd June 2017, 18:45   #3472  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,054
Quote:
Originally Posted by MysteryX View Post
If I were to guess, it looks like incorrect mutex locks preventing proper MT execution.
What mutex? Where?
Groucho2004 is offline  
Old 23rd June 2017, 19:44   #3473  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
Quote:
Originally Posted by Groucho2004 View Post
What mutex? Where?
jm_fps has that issue, so in MvTools2. I haven't looked at the code.
MysteryX is offline  
Old 23rd June 2017, 20:52   #3474  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,473
Quote:
Originally Posted by stax76 View Post
FFVideoSource fpsnum/fpsden drops/adds frame though
So does convertfps=true for DirectShowSource, but if the frame rate is just a little off that might be enough to fix it (I've never understood why it isn't changefps=true for DirectShowSource, given it behaves the same ways as Avisynth's ChangeFPS).

chummy probably needs to add Info() to a script and preview the output to determine the frame rate and whether adding any sort of frame rate conversion would fix the audio sync.

Assuming that's actually the problem. We don't know how chummy is extracting/muxing the audio or whether it's being converted etc.
hello_hello is offline  
Old 23rd June 2017, 21:19   #3475  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,054
Quote:
Originally Posted by MysteryX View Post
jm_fps has that issue, so in MvTools2. I haven't looked at the code.
MVTools2 is single-threaded so any thread synchronisation issues would be within Avisynth itself I suppose. SEt's AVS MT is even worse with this script.

Maybe the large temporal range and non-linear frame requests wreak havoc with the multi-threading.
Groucho2004 is offline  
Old 23rd June 2017, 22:52   #3476  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
Quote:
Originally Posted by Groucho2004 View Post
MVTools2 is single-threaded so any thread synchronisation issues would be within Avisynth itself I suppose. SEt's AVS MT is even worse with this script.

Maybe the large temporal range and non-linear frame requests wreak havoc with the multi-threading.
What temporal range does it have? What's different in this plugin that could make it function worse than other filters?

Or is it requesting frames in the wrong order or something? Perhaps something is getting mixed up in the buffers or something.
MysteryX is offline  
Old 24th June 2017, 13:33   #3477  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
Quote:
Originally Posted by Groucho2004 View Post
MVTools2 is single-threaded so any thread synchronisation issues would be within Avisynth itself I suppose. SEt's AVS MT is even worse with this script.

Maybe the large temporal range and non-linear frame requests wreak havoc with the multi-threading.
SVP has the same temporal range as MvTools2 and performs extremely well, so it cannot explain the performance issues -- unless it requests them in a different order.
MysteryX is offline  
Old 24th June 2017, 13:46   #3478  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,054
Quote:
Originally Posted by MysteryX View Post
SVP has the same temporal range as MvTools2 and performs extremely well, so it cannot explain the performance issues -- unless it requests them in a different order.
Apples and oranges.

If you really want to find out run a profiler.
Groucho2004 is offline  
Old 25th June 2017, 02:50   #3479  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,190
Here's an interesting case.

Code:
file="1080p.mp4"
LWLibavVideoSource(file, cache=False)
Spline36Resize(Width/2, Height/2)

FPS (min | max | average):      70.50 | 168.0 | 113.8
Memory usage (phys | virt):     108 | 105 MiB
Thread count:                   21
CPU usage (average):            25%
Code:
file="1080p.mp4"
LWLibavVideoSource(file, cache=False)
Spline36Resize(Width/2, Height/2)
Prefetch(8)

FPS (min | max | average):      1.816 | 212585 | 42.70
Memory usage (phys | virt):     160 | 157 MiB
Thread count:                   29
CPU usage (average):            67%
Adding Threads=1 to LWLibavVideoSource makes fps drop to 16

Code:
file="1080p.mp4"
LWLibavVideoSource(file, cache=False)
Spline36Resize(Width/2, Height/2)
jm_fps()  # Without Recalculate
Prefetch(8)

FPS (min | max | average):      1.844 | 101671 | 77.29
Memory usage (phys | virt):     650 | 648 MiB
Thread count:                   29
CPU usage (average):            71%
Going from 42.7 to 77.3 fps by adding jm_fps, really? This doesn't happen if we remove SplineResize.

replacing jm_fps with
FrameRateConverter(60, Output="Flow")
Code:
FPS (min | max | average):      3.539 | 129914 | 49.19
Memory usage (phys | virt):     956 | 955 MiB
Thread count:                   29
CPU usage (average):            60%
FrameRateConverter(60)
Code:
FPS (min | max | average):      2.222 | 137555 | 33.69
Memory usage (phys | virt):     735 | 735 MiB
Thread count:                   29
CPU usage (average):            42%
If I replace the source with ColorBarsHD, jm_fps with Recalculate runs at 75% CPU which isn't bad. FrameRateConverter runs at 54% CPU.

Here's the jm_fps function I'm using. Note: I did the test with super=superfilt line which isn't correct but that's how I ran the tests.
Code:
function jm_fps(clip C) {
    Blksize=16
    BlkSizeV=16
    Dct=0
    NewNum=60
    NewDen=1
    Recalculate = true
    Prefilter = C.RemoveGrain(22)
    superfilt = MSuper(prefilter, hpad=16, vpad=16) # all levels for MAnalyse
    super = superfilt #MSuper(C, hpad=16, vpad=16, levels=1)
    bak = MAnalyse(superfilt, isb=true, blksize=BlkSize, blksizev=BlkSizeV, overlap = BlkSize>4?(BlkSize/4+1)/2*2:0, overlapv = BlkSizeV>4?(BlkSizeV/4+1)/2*2:0, search=3, dct=Dct)
    fwd = MAnalyse(superfilt, isb=false, blksize=BlkSize, blksizev=BlkSizeV, overlap = BlkSize>4?(BlkSize/4+1)/2*2:0, search=3, dct=Dct)
    fwd = Recalculate ? MRecalculate(super, fwd, blksize=BlkSize/2, blksizev=BlkSizeV/2, overlap = BlkSize/2>4?(BlkSize/8+1)/2*2:0, overlapv = BlkSizeV/2>4?(BlkSizeV/8+1)/2*2:0, thSAD=100) : fwd
    bak = Recalculate ? MRecalculate(super, bak, blksize=BlkSize/2, blksizev=BlkSizeV/2, overlap = BlkSize/2>4?(BlkSize/8+1)/2*2:0, overlapv = BlkSizeV/2>4?(BlkSizeV/8+1)/2*2:0, thSAD=100) : bak
    Flow = MFlowFps(C, super, bak, fwd, num=NewNum, den=NewDen, blend=false, ml=200, mask=2, thSCD2=255)
    return Flow
}

Last edited by MysteryX; 25th June 2017 at 02:59.
MysteryX is offline  
Old 27th June 2017, 08:47   #3480  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,054
Quote:
Originally Posted by Groucho2004 View Post
MVTools2 is single-threaded so any thread synchronisation issues would be within Avisynth itself I suppose.
I should mention that pinterf's latest mvtools2 still supports multi-threading through avstp.dll and that it is enabled by default (mt = true).
Adding avstp.dll to your plugin directory may improve things - or not.
Groucho2004 is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 16:06.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.