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 Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 23rd September 2017, 20:51   #1  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
AviSynth and mp4

I'm lost.

I'm trying to use avisynth to modify an mp4 file.

I've downloaded FFmpegSource. I have unzipped the downloaded file into its own folder. Now what?

The documentation isn't doing it for me.

How do I operate on an .mp4 file using avisynth and FFmpegSource?

Thank you.
chris319 is offline   Reply With Quote
Old 23rd September 2017, 21:03   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by chris319 View Post
I'm lost.

I'm trying to use avisynth to modify an mp4 file.

I've downloaded FFmpegSource. I have unzipped the downloaded file into its own folder. Now what?

The documentation isn't doing it for me.

How do I operate on an .mp4 file using avisynth and FFmpegSource?

Thank you.





1) install avisynth

2) most plugins such as .dll's will autoload if you place them in the plugins folder. In your case it's ffms2.dll so place that into the avisynth/plugins folder

or you can explicitly load plugins in the script with LoadPlugin("PATH\whatever.dll")

3) create a script. You can use notepad or a script editor like avspmod . You can preview with avspmod or vdub. To do it in notepad you would open a text file, type the following (change paths and names to match the file), save it, rename the extension from .txt to .avs
e.g
myscript.avs

Code:
FFVideoSource("PATH\video.mp4")
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 01:20   #3  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
Doesn't work.

Here is the line of code I'm using:

Code:
FFVideoSource("D:\Videos\2017-09-23 11-44-44.mp4")
ffms2.dll is in the plugins folder. Windows media player opens and gives an error message -- can't find FFVideoSource.

This doesn't work either:
Code:
LoadPlugin("D:\Programs\AviSynth\plugins\ffms2.dll")
WMP can't load the dll.

This code does work:

Code:
Version()
chris319 is offline   Reply With Quote
Old 24th September 2017, 01:44   #4  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Do you have the correct matching version(s) ?

ie. if you have avisynth 32bit, you would use the 32bit version. If 64bit, use the 64bit version

Which ffms2 version are you using ? Some versions are "C" plugins and they need to be loaded differently with LoadCPlugin
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 01:48   #5  |  Link
hello_hello
Registered User
 
Join Date: Mar 2011
Posts: 4,823
Avisynth is obviously working but are you using 32 bit Avisynth & 32 bit ffms2 or 64bit and 64bit? (edit: whoops, poisondeathray beat me to it)

"Can't find FFVideoSource" sounds like an Avisynth complaint and WMP is just displaying it. Is the error message actually "no function named FFVideoSource"?

I'd try AvsPmod rather than WMP. Not that it'll magically fix the problem, but it'll make creating/previewing scripts a bit easier.
hello_hello is offline   Reply With Quote
Old 24th September 2017, 02:03   #6  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
I had to change to the 32-bit dll.

This did not work:

Code:
#LoadPlugin("D:\Programs\AviSynth\plugins\ffms2.dll")
Next is to try to get avisynth to actually do something.
chris319 is offline   Reply With Quote
Old 24th September 2017, 06:04   #7  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
OK, this code works, playing back on WMP.

Code:
DirectShowSource("D:\Videos\2017-09-23 11-44-44.mp4")
FlipVertical
This code doesn't:

Code:
ColorYUV(off_y = 216)

This returns "Windows Media Player cannot play the file":

Code:
FFVideoSource("D:\Videos\2017-09-23 11-44-44.mp4")
This code complains that it's not a YUV file:

Code:
ColorYUV(gamma_y=128, off_y=-16, off_u=5)
MediaInfo reports:

Quote:
Color space : YUV
Still lost. The docs are not helping.

Last edited by chris319; 24th September 2017 at 06:21.
chris319 is offline   Reply With Quote
Old 24th September 2017, 06:09   #8  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
What is the FlipVertical for ?

If you had to "flip" it, that suggests your directshow filter chain is probably serving RGB (it's being inadvertently converted somewhere). That probably also explains why coloryuv doesn't work for you. You would have to "fix" your directshow system . Or better get some other more reliable source filter working like ffms2 or lsmash. Directshow is prone to many problems like the one you're having now, also other issues like frame accuracy

You can check with info() to see where you are at, after each stage

Code:
DirectShowSource("D:\Videos\2017-09-23 11-44-44.mp4")
info()
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 06:15   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
If wmp can't play the avs directly, likely you need to match x86 vs. x64 (if wmp version is x64, it can't "see" an x86 script)

I would try avspmod (again use x86 or x64 depending on which version you're currently using) , because you're going to want to use the preview and edit and probably look at some monitoring functions like waveform (histogram) . It also has built in color picker that can read off RGB and YUV values

I have both x64 and x86 versions concurrently installed on one of my machines, but the x64 version is avisynth+ . But the point is x86 programs can only "see" x86 scripts and same with x64 programs and scripts
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 06:28   #10  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
Here is all I'm trying to do:

1. Raise the luminance levels by 16

2. Hard clip luminance levels at 235. Yes, hard clip. I don't want to adjust the luminance here by lowering the gain; just a hard clip. I don't want to reduce 255 to 235. Just clip off the video, viz.:

Code:
if Y > 235; Y = 235
Nothing fancy.

The .mp4 file was created by OBS.

Last edited by chris319; 24th September 2017 at 06:39.
chris319 is offline   Reply With Quote
Old 24th September 2017, 07:10   #11  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by chris319 View Post
Here is all I'm trying to do:

1. Raise the luminance levels by 16
More than one way to do this, but easy way is
coloryuv(off_y=16)


Quote:
2. Hard clip luminance levels at 235. Yes, hard clip. I don't want to adjust the luminance here by lowering the gain; just a hard clip. I don't want to reduce 255 to 235. Just clip off the video, viz.:

Code:
if Y > 235; Y = 235
Nothing fancy.

The .mp4 file was created by OBS.
Again, more than one way , but easy way is limiter to set min/max luma . I left min at zero, but you can change to whatever you want clipped. You can visualize the pixels getting zapped by using the show option
http://avisynth.nl/index.php/Limiter

Code:
limiter(min_luma=0, max_luma=235)


Are you sure you want to do this? What is the reason?
A YUV MP4 file created by OBS would likely already have normal range
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 07:51   #12  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
Quote:
easy way is
coloryuv(off_y=16)
Not so easy. MediaInfo reports YUV. avisynth/DirectShowSource say it is not, no can do.

Quote:
Are you sure you want to do this? What is the reason?
Yes. I want the luminance to be 235 or less without changing the middle tones as would happen if I applied a gain factor.

The .mp4 file I'm using for testing came from OBS. Other files will likely come from a camcorder with no OBS involved. Here is what I use to check camcorder video levels, along with Elgato Cam Link and a wavform monitor program I have written.

https://www.bhphotovideo.com/bnh/con...m=Y&sku=813250

Last edited by chris319; 24th September 2017 at 08:26.
chris319 is offline   Reply With Quote
Old 24th September 2017, 15:41   #13  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
[QUOTE=chris319;1819525]Not so easy. MediaInfo reports YUV. avisynth/DirectShowSource say it is not, no can do.

[quote]

I already answered this one. Very likely it is YUV, but your DirectShow subsystem is screwed up. You can verify with info() to see what the source filter output colorspace and a bunch of other information

I asked which version of ffms2, but you never replied. Exactly where did you download it from ? I'm not asking for fun or to strike up a conversation; there are certain versions that are better than others. Also, there are "C" versions that require LoadCPlugin (not LoadPlugin) . l-smash is actually preferred for most types of MP4 (at least for me), because it doesn't require an index

DirectShowSource() relies on your system installed and configured directshow filters. So it's very unreliable and therefore questionable accuracy. The decoder configuration akes a difference. If decoder "A" outputs full range, but decoder "B" ouputs standard range, you're in trouble. You might get something on one computer but completely different on another. Your flipvertical strongly suggests you're actually serving RGB - you can check with info() . To configure your directshow system , You can use preferred filter tweaker, along with graphstudio. Likely you have the microsoft decoder with the highest merit. You want something else like LAV or FFDShow . But directshow is a "last resort" type source filter. Prone to many problems. For the most part ffms2 and lsmash are much more consistent in those regards

If you have 32bit avisynth, 32bit ffms2, open it up with 32bit vdub or mpchc or avspmod for now. Ditch WMP for now because there are too many other variables (such as directshow configuration) when you are starting out

You don't *have* to use avisynth. You can do what you want with other programs. But avspmod is nice because you can preview, assess and visualize with various scopes, RGB/YUV pickers, and edit scripts at the same time - and it's free

>90% of consumer camcorders record in the 16-255 range. The majority of those actually have usable data in the 235-255 range.
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 17:38   #14  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
If you want to avoid avisynth (or maybe revisit it later when you have more time) and do the equivalent in ffmpeg-ese , you can do it with lutyuv

This lifts Y +16, then hard clips 16-235.

Code:
-vf lutyuv=y='clip(val+16,16,235)'
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 17:46   #15  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
Flipping the video is not mandatory. It was done to demonstrate that avisynth is working. That line has since been commented out.

ffms2 came from here: https://github.com/FFMS/ffms2

My camcorder is in the 10% that puts out blacks at 0.
chris319 is offline   Reply With Quote
Old 24th September 2017, 17:57   #16  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by chris319 View Post
Flipping the video is not mandatory. It was done to demonstrate that avisynth is working. That line has since been commented out.

ffms2 came from here: https://github.com/FFMS/ffms2

My camcorder is in the 10% that puts out blacks at 0.
Is it ffms2-2.23.1-msvc.7z ? Did you unzip the 32bit version?

If coloryuv line complains that video is not YUV, then the video being served is not YUV . Still the most likely explanation is DirectShow has converted it to RGB behind your back (reason #27 not to use DirectShow)

Or, maybe the video isn't YUV ? IIRC You can setup OBS to record RGB

What model is your camcorder ? Some record full range (with full range flag) . So it depends on how you configure the decoder and what software you are using, and if you obey the flag or not. For example, many canon DSLR's do this , but they are supposed to be clamped (not clipped) .
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 18:32   #17  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
The camcorder is a Canon Vixia HF R800. No tweak points that I can find for video levels, aside from some consumer-y gimmicks for shooting scenes at the beach, etc.

I seem to be making some progress with ffmpeg.
chris319 is offline   Reply With Quote
Old 24th September 2017, 19:52   #18  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by chris319 View Post
The camcorder is a Canon Vixia HF R800. No tweak points that I can find for video levels, aside from some consumer-y gimmicks for shooting scenes at the beach, etc.

I seem to be making some progress with ffmpeg.


Yes - many consumer canon models have limited manual controls . But if it's like 99% of other canon consumer camcorders, you probably want to adjust the clip to Y~16-235, CbCr~16-240 ; not clip it. You probably want to "clamp" it, then make some other minor adjustments

eg . If you had some bright highlights , they are going to be lost if you shift Y+16 "blindly" and then clip it. Instead you should "recover" the highlights because 90% have usuable information in the 236-255 range, and 100% will have usable information in the 219-235 range - which you just clipped

I would recommend checking first to see how much is "usuable data" in the various ranges.

Instead of linear adjustments, you could also do other manipulations, non linear adjustments. e.g. preferentially bring up shadows, but not clip the highlights.

As much as avisynth is "clunky" to use for this (compared to real grading software), ffmpeg is even "clunkier". When you use avspmod, you can see and check the waveform / various scopes at the same time to fine tune your adjustments
poisondeathray is offline   Reply With Quote
Old 24th September 2017, 20:27   #19  |  Link
chris319
Registered User
 
Join Date: Apr 2017
Posts: 16
I will check out avspmod. I do need to see this on a scope to make sure I'm actually getting what I want.

There are two ways to handle this with ffmpeg:

Code:
-vf lutyuv=y='clip(val+16,1,235)'
Code:
-vf lutyuv=y='clip(val*0.8588235294117647+16,1,254)'
Where the gain factor = (235 - 16) / 255. The latter is probably preferable. The clipping at 1 and 254 keeps video data out of the sync.

Will avspmod have an easier time dealing with .mp4 files? I spent many hours yesterday trying to get avisynth to work with .mp4 and got nowhere with it.

Last edited by chris319; 24th September 2017 at 20:49.
chris319 is offline   Reply With Quote
Old 24th September 2017, 21:00   #20  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
avspmod is like a GUI of sorts for avisynth. So if you can't get avisynth working , forget about avspmod. If you can't get ffms2 working you can try l-smash. You're going through what is affectionately known as "dll hell" . Everyone goes through it at some point with avisynth


Quote:
Code:
-vf lutyuv=y='clip(val*0.8588235294117647+16,1,254)'
Where the gain factor = (235 - 16) / 255.

I think something is off with that ffmpeg multiply factor; it's clamping too much compared to a levels(0,1,255,16,235,false) , so levels are washed out , low contrast . I'm getting about 30-218 on a full range clip

EDIT: I think I might know why - my test clip is flagged full range, so I think ffmpeg might be double clamping... I'll run some more tests. Or I guess it depends if your camera flags it or not. This canon does

Last edited by poisondeathray; 24th September 2017 at 21:03.
poisondeathray is offline   Reply With Quote
Reply

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 03:01.


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