Log in

View Full Version : Encoding script AviSynth with FFmpeg


skywalker
6th August 2020, 17:22
Hey guys, how are you?

I would like to know if it is possible to encode an avisynth script using FFmpeg without loss of quality with. I want at maximum quality (lossless). I don't care if the videos are going to get big in size, I appreciate the quality more.

How do I do this step by step?

Can I create a bat file to do this?

What are the command lines to do this?

How do I do this step by step?

Can I create a bat file to do this?

What are the command lines for doing this?

If that is possible, could someone donate me a little time to teach me how to do this? I will be immensely grateful.

xD

Boulder
6th August 2020, 17:26
Lossless is going to be bigger in size so better just use the original video track.

johnmeyer
6th August 2020, 18:01
Have you actually done any tests? I fully understand the quest for quality, but you may or may not be able to see the differences between various ways to encode a particular video, and you won't know for sure if you can see any differences until and unless you do your own tests.

First of all, you don't mention the source of your videos. Are they from a video camera? If so, they have already been massively compressed. The same statement applies to DVD, BD, streaming sources, etc. Unless you are in a studio and have the ability to capture uncompressed directly from the unaltered output of a professional video camera, your video source has already been compressed and will contain artifacts from that operation.

So, it makes zero sense to take such a source and store it as uncompressed.

You can use a "lossless" compression to at least make the file size smaller. It would be silly not to do this, because uncompressed not only consumes massive amounts of storage, but can be difficult to play back without hiccups.

My advice is to do tests, as I've already recommended, and to A/B between the original and h.264 or h.265 at a high bitrate.

ffmpeg can cut videos losslessly, and if that is all you want to do then something like this:

ffmpeg -i MAH05691.MP4 -ss 00:15:29.112 -c copy -t 00:07:14.250 Action_Cam_01.mp4

(which I took from something I actually did) will work. Just substitute your own timecodes.

skywalker
6th August 2020, 18:16
Have you actually done any tests? I fully understand the quest for quality, but you may or may not be able to see the differences between various ways to encode a particular video, and you won't know for sure if you can see any differences until and unless you do your own tests.

First of all, you don't mention the source of your videos. Are they from a video camera? If so, they have already been massively compressed. The same statement applies to DVD, BD, streaming sources, etc. Unless you are in a studio and have the ability to capture uncompressed directly from the unaltered output of a professional video camera, your video source has already been compressed and will contain artifacts from that operation.

So, it makes zero sense to take such a source and store it as uncompressed.

You can use a "lossless" compression to at least make the file size smaller. It would be silly not to do this, because uncompressed not only consumes massive amounts of storage, but can be difficult to play back without hiccups.

My advice is to do tests, as I've already recommended, and to A/B between the original and h.264 or h.265 at a high bitrate.

ffmpeg can cut videos losslessly, and if that is all you want to do then something like this:

ffmpeg -i MAH05691.MP4 -ss 00:15:29.112 -c copy -t 00:07:14.250 Action_Cam_01.mp4

(which I took from something I actually did) will work. Just substitute your own timecodes.

Actually I have a video clip, it has an average of 5 minutes. I did an avisynth script with improvements for the video.

I usualy did the encoder to get the out video with MEGUI. But I wanted to make this encoder by FFmpeg using a variable bitrate rate. But I don't know how to do this for FFmpeg. I think that maybe this is better than in MeGui.

Boulder
6th August 2020, 18:40
They both probably use the same encoder, if not the same version then quite close anyway. MeGUI is just a GUI.

skywalker
6th August 2020, 18:46
Thank u guys.

qyot27
6th August 2020, 18:50
So the video is being filtered by AviSynth, and you simply want to preserve that when encoding. What you want to do in that instance is to use a lossless format as an intermediate or archive copy, but use lossy at the distribution/viewing stage. Depending on the specs of the computer involved, it may not be able to cope with playing back a losslessly-encoded file in realtime, but you absolutely want to do all the editing or filtering in the lossless space.

The answer, of course, is this:
ffmpeg -i test.avs -vcodec CODECNAME -acodec copy output.avi
where CODECNAME is the name of the video format encoder in FFmpeg. You most probably want either ffv1 or ffvhuff, but there are others (you could even use libx264 or libx265 in lossless mode if you pass the correct options).

StainlessS
6th August 2020, 18:58
Do you believe that your source cannot be improved at all ?
(I've spent last two weeks 'improving' a DVD series, it is tedious but I did not do it without cause).
[EDIT: well 8 series]

skywalker
6th August 2020, 19:06
The answer, of course, is this:
ffmpeg -i test.avs -vcodec CODECNAME -acodec copy output.avi
where CODECNAME is the name of the video format encoder in FFmpeg. You most probably want either ffv1 or ffvhuff, but there are others (you could even use libx264 or libx265 in lossless mode if you pass the correct options).
Thanks, but I have an error that says:
Script error: There is no function named 'FFVideoSource'.
My script.avs: Unknown error occurred
:(

skywalker
6th August 2020, 19:09
Do you believe that your source cannot be improved at all ?
(I've spent last two weeks 'improving' a DVD series, it is tedious but I did not do it without cause).
[EDIT: well 8 series]

I do believe, and a lot.:) I've been trying my best DVD sources for a long time. It funy me. :)

qyot27
6th August 2020, 19:26
Thanks, but I have an error that says:
Script error: There is no function named 'FFVideoSource'.
My script.avs: Unknown error occurred
:(
You need to make sure the script is written correctly. Most GUIs get by with a certain amount of hand-holding, obfuscating where tools are installed, or relying on copies they provide themselves in directories they have control over rather than it being available system-wide; if you're setting the GUIs aside, you've got to make sure the right plugins are installed and that the script works under a normal AviSynth+ system installation and usage first. Then you can give it to FFmpeg.

FranceBB
6th August 2020, 20:13
Exactly... Make sure you:

A) Have the latest Avisynth+ version installed: https://github.com/AviSynth/AviSynthPlus/releases
B) Have the right plugins inside the "C:\Program Files\Avisynth\Plugin+" directory
C) Make sure that if you're using Avisynth x64, your plugins are 64bit and your ffmpeg build is 64bit as well (same for 32bit) https://ffmpeg.zeranoe.com/builds/
D) Your environment is ok and your script is working

AVSMeter is your friend for checking the environment: https://forum.doom9.org/showthread.php?t=173259
AVSPmod is your friend for writing and testing scripts: https://forum.doom9.org/showthread.php?t=175823


Side note: unlike some other fella, I'm totally against GUIs like MeGUI. Although it's true that they use the very same things you would be using with a BAT like Avisynth, x264, x265, ffmpeg etc, they choose the options for you most of the time and you have little to no idea about what settings it's using. In particular, MeGUI has been using some rather controversial settings in x264 for years, while with a BAT you have total control over what's going on and what settings to use. So... I understand that it's gonna be a big step for you to switch from a GUI based approach to a command line one, but believe me, it's totally worth it and you'll never look back ever again. ;)

stax76
6th August 2020, 21:19
I don't agree on your sentiment against GUIs. Bat is one of the worst command languages that ever existed and one of the worst products MS ever created, so it's not particular good advice either and understanding PowerShell on a level that it's useful is actually hard, even for an experienced programmer, if it would be so easy there would be a lot more people here using console related tools, like for instance mpv.

FranceBB
6th August 2020, 22:10
if it would be so easy there would be a lot more people here using console related tools, like for instance mpv.

MPV is my favorite player on Linux. :P I use it all the time. Same goes for Windows, although I keep both MPC-HC and PotPlayer installed and updated "just in case".


understanding PowerShell on a level that it's useful is actually hard, even for an experienced programmer

C'mon, it's not so terribly bad; besides, there are some very good explanations (with tests) for free on the Microsoft Virtual Academy with functions, commands and other things explained directly by Jeffrey Snover (the inventor of PowerShell). I watched 'em all, they're definitely useful and Jeffrey is also kinda funny to listen to as he puts a joke every now and then to keep people entertained. :D


Anyway, I know that you're the author of Staxrip which has a UI. I've never used it, so I can't say anything about it, but since people find it useful, it's nice that you develop and maintain it, so well done :) . You see, I'm not against each and every GUI, in the sense that it's not like I would never use a GUI, "period", but the reason why I try to avoid them is 'cause most of the time devs just don't let users know what things are going on under the hood and take decisions for them, however if a GUI allows the user to choose everything and it's transparent about what is doing, then I have no problem about that and I'm actually in favor of it in that case. :) I'll show you an example: take AVID Media Composer. If you use it and apply a resizing filter for instance, you can easily draw and move x and y axes to decide how much you want to "zoom" in the image and then you can render your effect and export. Too bad that the "zoom" is actually a crop and upscale, so how does it do it? Which resizing kernel does it use? And what about interlaced contents? Another example would be 10bit contents "imported" in an 8bit timeline. What is it gonna do? Is it gonna truncate everything to get 8bit? Is it gonna apply some sort of dithering? And what about clips with a different framerate? Is it gonna use blending? Is it gonna duplicate frames? And how about denoise filters? How do they work? Are they both spatial and temporal? Which blocks/macroblock size are gonna be analysed? And how about the frames in the temporal denoise? And which Transform do they use? DFT? And at which bitdepth? And so on and on and on... I could go on forever... There are countless examples where GUIs don't really allow you to tweak parameters or know what is going on under the hood, which is why I love Avisynth and the command line and I hate closed source UI, 'cause I know EXACTLY what is going on in the command line while I have little to no clue about closed source UI...

stax76
7th August 2020, 09:51
Side note: unlike some other fella, I'm totally against GUIs like MeGUI.

I know that you're the author of Staxrip which has a UI. I've never used it, so I can't say anything about it

I'm the original author and one of about 5 people that currently maintain it. So you never used it, can't say anything about it except that you are totally against it, that's amazing.

Although it's true that they use the very same things you would be using with a BAT like Avisynth, x264, x265, ffmpeg etc, they choose the options for you most of the time and you have little to no idea about what settings it's using.

Sorry but your main argument is completely wrong, in staxrip there is a code preview and a code editor and the interaction between code and GUI is achieved by numerous methods like splitting the script into categorized sections, with macros, environment variables, script evaluation and script generation.

FranceBB
7th August 2020, 11:31
I'm the original author and one of about 5 people that currently maintain it. So you never used it, can't say anything about it except that you are totally against it, that's amazing.



Sorry but your main argument is completely wrong, in staxrip there is a code preview and a code editor and the interaction between code and GUI is achieved by numerous methods like splitting the script into categorized sections, with macros, environment variables, script evaluation and script generation.

You don't get it. I never said that I'm against StaxRip, I said that I never used it so I can't say anything about it. I'm against GUIs who don't allow users to choose settings and take decisions for them, in fact I quoted Avid Media Composer as an example. I said that I never used YOUR specific software so that I couldn't comment on that! I even "praised" you 'cause some people use it, what else do you want? XD
I'm gonna repeat it once again: I'm generally against GUIs who don't allow people to choose settings and take decisions for them, unlike the command line where you can choose everything. AVID Media Composer is an example. I even said that IF and only IF a GUI is transparent about what it's doing, then I have no problem with that and I also said that I know that you're an author of a GUI and that you might find yourself "attacked" by my statement, but that it wasn't referred to you specifically 'cause I never used Staxrip, so I can't comment about it (and I'm not planning to do so) but since users are using it you're absolutely right to maintain it and develop it so that it can help people out. You're helping the community and that's great.

Is it clear now? :)

I mean, don't get me wrong, I didn't really want to argue or upset you or make you angry, I mean, it wasn't my intention, but on the other hand, as I said before, I've seen many user interfaces that just don't allow users to choose things to make their life easier and I don't like that, that's why I don't like GUIs. Again, there are exceptions, sure, and if your program is one of the exceptions that allows users to do everything then great, I trust your words, but that's the way I think.

By the way, why are we even arguing about this? We're probably derailing the topic from its own original purpose. Let's call it off, shall we. :)

stax76
7th August 2020, 13:34
It's not just this thread, you say it all the time. I'm also totally against many things (like totalitarianism) but I can keep it for me if it doesn't harm me and I'm not particularly well-informed and experienced about a topic.

videoh
7th August 2020, 14:37
'cause I know EXACTLY what is going on in the command line while I have little to no clue about closed source UI DGDemuxGUI (closed source) displays the command line that will be executed by DGDemux (CLI executable) and it allows all DGDemux options to be controlled. That's the best of both the CLI and GUI worlds. ;)

You'd have to be out of your mind or a zealot to prefer using DGDemux directly (instead of via the GUI) unless you are doing batch operations. I also think you make a logical misstep in going from "GUI A is not transparent" to "I hate GUIs."

IIANM staxrip also allows the command lines to be viewed.

http://rationalqm.us/misc/dgdemux_screen.jpg

Hacker?pcs
7th August 2020, 14:44
IIANM staxrip also allows the command lines to be viewed.
Any operation in StaxRip has the command line below which can be modified

videoh
7th August 2020, 14:58
That clinches it then!

FranceBB
7th August 2020, 17:13
DGDemuxGUI (closed source) displays the command line that will be executed by DGDemux (CLI executable) and it allows all DGDemux options to be controlled. That's the best of both the CLI and GUI worlds. ;)


Well yeah, which is the reason why I use DGDecode from the GUI and it works like a charm. :)
Again, if the GUI offers all the options, I have nothing against it. As a matter of fact, I've been using DGDecode for years and years and I'm totally happy with it (including the NV version which runs on my Quadro. :) )


I also think you make a logical misstep in going from "GUI A is not transparent" to "I hate GUIs."


Perhaps I shouldn't dislike 'em all, but still I've seen examples in which they're useful with developers very keen to show options for everything and some others that are very limited...


IIANM staxrip also allows the command lines to be viewed.


Well, fair enough then, if you say so, I trust you, it means that our fella here Stax did things the right way and didn't hide things to users, which is totally ok for me then. :)

videoh
9th August 2020, 20:46
Well yeah, which is the reason why I use DGDecode from the GUI and it works like a charm. "the GUI"?

I would have expected precision from you. DGDecode(NV) does not have a GUI (it's an Avisynth/Vapoursynth source filter), unless you are referring to some third-party application. Or maybe you meant DGIndex(NV).

FranceBB
9th August 2020, 23:25
"the GUI"?

I would have expected precision from you. DGDecode(NV) does not have a GUI (it's an Avisynth/Vapoursynth source filter), unless you are referring to some third-party application. Or maybe you meant DGIndex(NV).

Yeah, my bad (I shouldn't really post while at work between a show and another), I meant DGIndex of course, which also shows me which frame is what (IPB), whether it's interlaced or progressive etc. Of course I manually check as well, but that's particularly useful 'cause I can batch several files. I've been using it extensively for .vob files in DVDs and for .ts files from TV Stations. As to the NV version it's particularly useful 'cause long before ffms2 and LSMASH began to slowly introduce hardware decoding, it was possible to actually decode using GPU and finally my NVIDIA Quadro had something to do when using Avisynth instead of lying there rendering the deskop xD