View Full Version : How to use RegEx in avisynth ?
wthreex
13th May 2020, 15:30
Excuse me i'm newbie in avisynth, Which function used for regex ? I want to get filename in <input> variable which megui provide
When i put the <input> variable into Subtitle function like
Subtitle(<input>)
it become and return:
Subtitle(LoadPlugin("C:\Users\Downloads\Programs\MeGui\tools\ffms\ffms2.dll")
FFVideoSource("C:\Users\Downloads\Video\file.mkv", cachefile="C:\Users\Downloads\file.mkv.ffindex", fpsnum=24000, fpsden=1001, threads=1))
So my plan is to get path of file which is "C:\Users\Downloads\Video\file.mkv"
StainlessS
13th May 2020, 15:54
Not sure what you are trying to do here or what regex has to do with it.
Your question would seem to have been better suited for MeGUi thread anyway.
but,
Subtitle(<input>)
would seem to want path to a SUBTITLE file, not a plugin.
I dont have MeGUI set up at the moment on this machine, but presume you need something like this.
LoadPlugin("C:\Users\Downloads\Programs\MeGui\tools\ffms\ffms2.dll")
FFVideoSource("C:\Users\Downloads\Video\file.mkv", cachefile="C:\Users\Downloads\Blinded by the Light 2019.mkv.ffindex", fpsnum=24000, fpsden=1001, threads=1))
and if you are wanting to supply a the name of subtitle file, then
add the file path in below where it says <input>. [Just copy and paste it]
Subtitle(<input>) # replace <input> with your subtitle file pathname, eg, Subtitle("D:\mdir\mySub.srt")
EDIT: If you have Avisynth installed as an individual program on your system, and you also have ffms2.dll in your plugins, then you will not need the
LoadPlugin line at all, it would be auto loaded for you anyway.
wthreex
13th May 2020, 16:21
Ok I did https://forum.doom9.org/showthread.php?p=1911775
I think i couldn't explain enough, When i open a file in MeGui, There is a variable inside of avisnyth which is "<input>" it will translated to:
Subtitle(LoadPlugin("C:\Users\Downloads\Programs\MeGui\tools\ffms\ffms2.dll")
FFVideoSource("C:\Users\Downloads\Video\file.mkv", cachefile="C:\Users\Downloads\file.mkv.ffindex", fpsnum=24000, fpsden=1001, threads=1))
I need this part: "C:\Users\Downloads\Video\file.mkv" and i wanna put it into variabe, So i though it would be nice if i use Regular Expression to get that part
StainlessS
13th May 2020, 20:02
Well that translation inserting LoadPlugin into Subtitle() is clearly wrong, dont know what MeGUI thinks its doing.
Anyways, I'm sure that the guys in MeGUI thread will sort out what has gone wrong.
wthreex
14th May 2020, 08:01
I was using Subtitle just want to know what would be the result (echo it out)
StainlessS
14th May 2020, 08:10
Sorry, cant help, I have never used any of the fancy MeGUI stuff, I only ever load final Avs file into it where everythng already
setup exaclty how I want it. I use AutoEncode, and if I do want to add a subtitle I just tick the "Add Additional Content (audio, subs, chapters)" box and add the subtitle.
If by 'echo it out' you mean comment it out, then I say yes if you dont want subtitles.
EDIT: Your thread title in MP4 encoder forum, "How to get full path of current file as string ?",
maybe add the word "MeGUI" somewhere would get more views.
wthreex
14th May 2020, 15:31
@StainlessS first of all thank you so much to come along with me, In last attempt i recorded my issue: https://streamable.com/cdkk1d i hope it make sense now xD, In video one thing i didnt mention that megui can queue all files in folder and encode them as i mentioned in previous posts ("Select Folder") but the problem is it only pick one script in the queue, So the " get current file path" means the file which megui pick for encode in the queue.
StainlessS
15th May 2020, 12:20
Hi wthreex,
The thing with the '<input>' stuff is an Avisynth script template, it just allows you to add some avisynth scripting.
It might be possible to convert the source file name into a subtitle file eg "D:\myfile.avi' to 'D:\myfile.srt' if you had access to the
sourcefile name from within avisynth called via MeGUI, however I am not aware that the source filename is available to avisynth script.
Additionally, even if you did have access to the source filename, and hence a similar subtitle filename, all you could do from within
avisynth would be to add a 'Hard Coded' subtitle to the video, ie always there and could not switch off subtitle as it is part of the video.
I'm guessing that what you want is to be able to auto add eg myfile.srt to the files to be multiplexed together at the final encode stage.
I dont think that this is possible, (and the avisynth script template has nothing to do with that type of functionality).
I can only suggest that you ask in MeGUI forum if it is possible to auto add an associated subtitle file (eg myfile.srt) to the files to be
multiplexed together and the end of encode. [I doubt that this is currently possible, I wish it were otherwise as I would also like to be able
auto do that, and for more than a single subtitle file].
EDIT:
When I use AutoEncode and want to add multiple subtitle [single subs file can be added quite easily by ticking the 'Add additional content' box],
I have to encode normal, and then use the Tools/Muxer/MP4 Muxer tool to mux the separate video, audio and subtitle streams together.
EDIT: Similar where multiple audio files require adding to the final encode. [DIrectors commentary, Cast commentary, Video Effects crew commentary etc]
wthreex
15th May 2020, 13:34
Yeah, You got my point, Its really annoying me to create a script for each files with same structure just imagine 50 file with 50 srt file i have to create 50 script just manipulate the file path... I created multiple threads around the internet hope it gets somewhere xD
StainlessS
15th May 2020, 14:34
Maybe take peek at RipBot, dont know if it supports such functionality, but given that Atak_Snajpera goes to great lengths to make a mass production tool, so maybe he has
also provided similar auto add subs type functionality.
Some Guides on Videohelp:- https://www.videohelp.com/guides?tools=1039&archive=%25
D9 thread:- https://forum.doom9.org/showthread.php?t=127611
If it does support auto subs, then say so here in thread. thanks.
qyot27
15th May 2020, 14:48
for n in *.mkv ; do echo "FFVideoSource(\"$n\") > "$n".avs ; done
If the files aren't all in the same directory, have the list of filepaths in a text file, then use a while loop that reads from the text file instead of a for loop.
Or do it the manual way and have the list of filepaths in a text file, but use a regex-aware text editor to apply the AviSynth syntax around the paths, including the command to dump each line to an external file. Then run it as either a batch or shell script. All the scripts get generated in less than a second.
tebasuna51
16th May 2020, 02:53
If all of you need is create a bounch of .avs files for your .mkv and .jpg files, you can create a .bat file like this:
FOR %%A IN (*.mkv) DO echo I=ImageSource("%%~dpnA.jpg",end=0) > "%%~nA.avs"
FOR %%A IN (*.mkv) DO echo v=FFvideoSource("%%~fA") >> "%%~nA.avs"
FOR %%A IN (*.mkv) DO echo v=v.Trim(0,0).ConvertToYV12() >> "%%~nA.avs"
FOR %%A IN (*.mkv) DO echo ...
The first one create (>) a .avs with the same name than mkv
The next lines add (>>) avs lines to the same .avs files
stax76
16th May 2020, 10:25
In staxrip the easiest way would be using macros:
TextSubMod("%source_dir%%source_name%.srt")
wthreex
16th May 2020, 14:09
Thanks guys, Some dude in videohelp forum solved my issue https://forum.videohelp.com/threads/397225-MeGui-How-to-get-path-name-of-current-file-in-the-queue-dynamically#post2583330
@qyot27, @tebasuna51 The problem is if i want to generate avisynth script I have to manaully encode audio, merge , etc ... by my self, Besides the batch encoding only apply one script at the time...
@stax76 wish something like that was in Megui...
StainlessS
16th May 2020, 14:45
@Hello_Hello, that was some real fancy footwork, keeping copy of that Videohelp post, thanks very much. :)
qyot27
16th May 2020, 16:39
@qyot27, @tebasuna51 The problem is if i want to generate avisynth script I have to manaully encode audio, merge , etc ... by my self, Besides the batch encoding only apply one script at the time...
Just set up an encoding for loop to do those steps every time.
for n in *.avs ; do
x264 --preset ultrafast --crf 18 -o "${n%.*}.mp4" "$n"
ffmpeg -i "$n" -vn -acodec libopus -b:a 192k "${n%.*}.opus"
mkvmerge -o "${n%.*}.mkv" "${n%.*}.mp4" "${n%.*}.opus"
done
or not bothering with encoding anything separately
for n in *.avs ; do
ffmpeg -i "$n" -vcodec libx264 -preset ultrafast -crf 18 -acodec libopus -b:a 192k "${n%.*}.mkv"
done
Or even combine the script generation and encoding loops into one:
for n in *.mkv ; do
echo "FFVideoSource(\"$n\")" > "${n%.*}.avs"
ffmpeg -i "${n%.*}.avs" -vcodec libx264 -preset ultrafast -crf 18 -acodec libopus -b:a 192k "${n%.*}-reencoded.mkv"
done
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.