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

Thread Tools Search this Thread Display Modes
Old 5th November 2019, 21:40   #1  |  Link
Registered User
Join Date: Oct 2019
Posts: 3
Script to scale videos with waifu2x.

Script to scale videos with waifu2x.

It allows you to scale your videos using Waifu2x, without the need to export all images(10Gb-50Gb), as well as the possibility to detect duplicate frames, and save processing time.

Work with any command line program(Windows), such as:

waifu2x-conver-cpp, waifu2x-caffe, waifu2x-ncnn-vulkan. (This is supported by CUDA,CUDNN, GPU AMD, Vulkan)

"waifu2x.- Image Super-Resolution for Anime-style art using Deep Convolutional Neural Networks. And it supports photo"

Note: The code can be easily modified to work with any program, including gimp.
The script exports a single image, then it is processed with the program, and then the processed image is loaded.

Link Tutorial.
In the description of the YouTube video, comes a compressed file with all the necessary files (dlls)


NameVideo= "c:\My path\My Video.mp4"

#~ directory Temp

Space=" "
DirectoryProgram=""" "C:\Program Files\waifu2x-converter\" """
PImageInOut = "-i" + Space + "'" +  InputImage + "'" + Space + "-o" + Space + "'" + OutputImage + "'" + Space
Parameters ="-m noise-scale -v 3 --noise-level" + Space + string(Noise) + Space + "--scale-ratio" + Space + string(Scale)
LineCommand= DirectoryProgram + Space + NameProgram + Space + Parameters + Space + PImageInOut

ScriptClip("""ImageWriter(InputImage+"%n",start =current_frame, end =current_frame)""",after_frame = true)
#~ Same scale and color necessary
ScriptClip("""Call( "cmd /C title Frame:" + string(current_frame)+ "/" + string(last.FrameCount) + " & start /wait /B /D " + LineCommand, string(current_frame))""",after_frame = True)
ScriptClip("""ImageSourceAnim(OutputImage).BilinearResize(last.Width,last.Height)""",after_frame =true)
You can easily include the audio as well as video clippings.
Attached Files
File Type: zip OnlyScriptAvsWaifu.zip (5.7 KB, 130 views)
AvengerOne is offline   Reply With Quote
Old 6th November 2019, 12:27   #2  |  Link
HeartlessS Usurer
StainlessS's Avatar
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
You might like to try CallCmd() instead of Call_25,
CallCmd() written to overcome problems inherent in Call_25.

CallCmd:- https://forum.doom9.org/showthread.php?t=166063

CallCmd() by StainlessS:- http://forum.doom9.org/showthread.php?t=166063 

Based on Call by Nic:- http://forum.doom9.org/showthread.php?t=46506

CallCmd() by StainlessS

CallCmd(clip,string "Command"="", string "Frames"="",string "Insert"="",int "Digits"=6,bool "Once"=true,int "Offset"=0,
  bool "Hide"=false,bool "Debug"=false,string "Open"="",string "Close"="",int "Synchronous"=7)

Command (default"")
 A command string that will be executed on each frame specified by the Frames arg. Can contain a single INSERT arg character
 which will be replaced by a string representing the frame number with optional OFFSET. If the command naturally contains the
 INSERT character then choose a different INSERT charcter or use two INSERT characters in the Command string to escape it
 (one of them will be removed in the executed command).

Frames (default "")
 String to specify the frames upon which the COMMAND arg is executed.
 Comments beginning with '#' can occur in the FRAMES arg, SEMICOLON Cannot be used in a comment.
 SEMICOLON ";" or NewLine [Chr(10)] is used as a frame specifier terminator.
 COMMA "," specifies a frame range where the 2nd range end number can be '0' meaning last frame, and eg '-4' meaning 4 frames. 
 "0,0" Specifies ALL frames.
      1           # This is a comment, calls on frame 1.
      3;5;7       # Calls on frames 3 and 5 and 7, SEMICOLON is SOFT End Of Line and terminates any COMMENT.
      8           # Call Frame 8 ; 10 # *** IMPORTANT *** And because of SEMICOLON also calls on Frame 10.
      14,16       # Calls on frames 14 to 16, COMMA specifies a frame range.
      18,20;22    # Calls on Frame range 18 to 20 and frame 22.
      24,-4       # Specifies frames 24 to 27, ie 4 frames starting at frame 24.

Insert (default "")
  Single character which will be replaced in the Command arg string by frame number + OFFSET arg.
  If the command naturally contains an INSERT character then choose a different INSERT arg charcter or use two INSERT characters 
  in the Command string to escape the naturally occuring one (one of them will be removed in the executed command).

Digits (default 6)
  Minimum number of digits generated in inserted text that replaces the INSERT character in the COMMAND arg.
Once (default=true)
  If true then only executes frame commands once on each frame, if replayed, does not exec 2nd time.
Offset (default 0)
  Offset added to frame number when generating text inserted into a frame command replacing the INSERT character.

Hide (default false)
 If true, hide black console window on command execution.

Debug (default false)
 If true, sends debug info to DebugView Window.
 DebugView (Highly recommended, allows viewing of info and warnings from the plugins and other programs)

Open (default "")
  Command executed on plugin start up (Constructor), before first frame.
  No string replacements, ie INSERT, DIGITS and OFFSET have no effect.

Close (default "")
  Command executed on plugin close down (Destructor), after last frame.
  No string replacements, ie INSERT, DIGITS and OFFSET have no effect.

Synchronous (default 7, range 0 - 7)
  The Synchronous arg is a group of 3 bitflags, 
    bit 0 if set means wait for process to terminate before returning from the 'Open' command.
    bit 1 if set means wait for process to terminate before returning from the 'Frames' commands.
    bit 2 if set means wait for process to terminate before returning from the 'Close' command.
      0 = All Asynchronous, ie dont wait at all.
      1 = Wait only on 'Open' command.
      2 = Wait only on 'Frames' commands.
      3 = Wait on 'Open' and 'Frames' commands.
      4 = Wait on 'Close' command.
      5 = Wait on 'Open' and 'Close' commands.
      6 = Wait on 'Frames' and 'Close' commands.
      7 = Wait on ALL commands (default).

   Beware, if you dont wait it is very possible that any future reliance upon output of command may fail due to the
   output file being in use. Also, if debug true and waiting for process to complete, then will also show the process return
   code on successful process creation (and completion) in DebugView, cannot do this if NOT waiting completion.


CallCmd, does NOT replace single quotes with double quotes in Command string, was source of problems in Call().
Instead wrap eg filenames containing spaces in double-quotes using perhaps:

 Function QuoteStr(String s) { return Chr(34) + s + Chr(34) }

or use triple and single double-quotes eg

  CallCmd(BlankClip,Close="""d:\nicecho.exe @d:\report.txt "Appending" """)

Executing on each playing, on every frame, hiding console window, sending debug info to debugview, and converting
command string on frame eg 0 to  "C:\PortableApps\ImageMagick\Mogrify.exe -flop C:\Temp\000000.tif"

  CallCmd(clip,"C:\PortableApps\ImageMagick\Mogrify.exe -flop C:\Temp\#.tif", "0,0",Insert="#",Once=false,Hide=true,Debug=true)

At Open, executes delete on wildcard files silently, without asking confirmation.
  CallCmd(Open="""cmd /c DEL /Q "C:\TEMP\test_*.tif" """)

To execute DOS type commands, in DOS console type "cmd /?" for cmd options, and eg DEL /? for delete options.
included Avsiynth v2.58, avs+ v2.6 x86, and Avs+ x64 dll's.

There is also RT_Call() in RT_Stats, simpler but could probably also be more usable than Call_25 and avoids its problems.

Post from CallCmd thread, where Vampirdom used a hack to try overcome Call_25 problems
Originally Posted by vampiredom View Post
I simply MUST try this ... I would love to get rid of my crazy Call25Helper.exe hack. Unfortunately, I have been really short on time to test out new things. I will try this out and get back to you. Thanks, Stainless.
Link into Original Call_25 thread:- https://forum.doom9.org/showthread.php?p=1547266

EDIT: There was mention of a copy to/from clipboard idea in above linked Call_25 thread, I implemented that some time ago too:- https://forum.doom9.org/showthread.php?t=176145

EDIT: There are also some threads where Martin53 had some unusual requirements for CallCmd(), and ways to achieve them, maybe do search if of interest.

EDIT: I quite often use CallCmd() to delete temp files on clip closure.
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 6th November 2019 at 14:46.
StainlessS is offline   Reply With Quote
Old 6th November 2019, 20:31   #3  |  Link
Registered User
Join Date: Oct 2019
Posts: 3
Thanks, I will try it.
AvengerOne is offline   Reply With Quote

anime, cuda, vulkan, waifu2x

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 11:47.

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