Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- chcp 65001
- for %%i in (*.mkv *.mp4) do (
- echo %%~nxi
- call :write-avs "%%~nxi" "%%~nxi.avs"
- )
- pause & exit
- :write-avs
- (
- echo path = "%~1" # 8.3 name is "%~snx1"
- echo Assert^(FunctionExists^("FFVideoSource"^), "FFMS2 plugin is required"^)
- echo Assert^(Exist^(path, utf8=true^), "'" + path + ^"^"^"' does not exist
- echo or .avs is not in UTF8-no-BOM
- echo or Unicode path is not supported by this AviSynth compatible program
- echo ^(AvsPmod issue - as a workaround, use 8.3 path^)^"^"^"^)
- echo # mpv-related issue with Unicode .avs filename ^(mpv crash at launch^):
- echo # https://forum.doom9.org/showthread.php?p=1903673#post1903673
- echo # as a workaround, rename .avs
- echo v = FFVideoSource^(path^)
- echo try {
- echo a = FFAudioSource^(path^)
- echo } catch^(err_msg^) { # if file has no audio track
- echo return v.Subtitle^(err_msg^)
- echo }
- echo a_length = a.AudioDuration
- echo v_length = v.FrameCount/v.FrameRate
- echo # v--- real clip length
- echo # ^|----------a-----------^|
- echo # ^|---v---^|---v---^|---v---^|
- echo # ^^--- to be trimmed by AudioTrim^(0, a_length^)
- echo v_repeat_count = Ceil^(a_length/v_length^)
- echo v = v.Loop^(v_repeat_count^)
- echo c = AudioDub^(v, a^).AudioTrim^(0, a_length^)
- echo c_repeat_count = int^(10*60*60/a_length^) # 10 hours ^(even longer "-1" has
- echo c = c.Loop^(c_repeat_count^) # compatibility issue with MPC-BE^)
- echo return c
- ) > "%~2"
- exit /b
- :: Drawbacks:
- :: 1) AviSynth+ & AviSynth FFMS2 plugin dependency
- :: 2) junk index files (.ffindex)
- :: 3) counter-intuitive .avs playback (not .mp4/.mkv)
- :: 4) AviSynth Unicode issues
- :: ============================ Readable AviSynth+ code ============================
- :: without escaping needed for .bat: ^) ^( ^^
- :: ### Naive solution with desync ###
- ::
- :: path = "___.mp4"
- :: a = FFAudioSource(path).Loop(-1)
- :: v = FFVideoSource(path).Loop(-1)
- :: c = AudioDub(v, a)
- :: # |----------a-----------|----------a-----------|--...
- :: # |---v---|---v---|---v---|---v---|---v---|---v---|...
- :: # ^--- desync
- :: ### Final solution ###
- ::
- :: path = "___.mp4" # 8.3 name is "___~1.MP4"
- :: Assert(FunctionExists("FFVideoSource"), "FFMS2 plugin is required")
- :: Assert(Exist(path, utf8=true), "'" + path + """' does not exist
- :: or .avs is not in UTF8-no-BOM
- :: or Unicode path is not supported by this AviSynth compatible program
- :: (AvsPmod issue - as a workaround, use 8.3 path)""")
- :: # mpv-related issue with Unicode .avs filename (mpv crash at launch):
- :: # https://forum.doom9.org/showthread.php?p=1903673#post1903673
- :: # as a workaround, rename .avs
- :: v = FFVideoSource(path)
- :: try {
- :: a = FFAudioSource(path)
- :: } catch(err_msg) { # if file has no audio track
- :: return v.Subtitle(err_msg)
- :: }
- :: a_length = a.AudioDuration
- :: v_length = v.FrameCount/v.FrameRate
- :: # v--- real clip length
- :: # |----------a-----------|
- :: # |---v---|---v---|---v---|
- :: # ^--- to be trimmed by AudioTrim(0, a_length)
- :: v_repeat_count = Ceil(a_length/v_length)
- :: v = v.Loop(v_repeat_count)
- :: c = AudioDub(v, a).AudioTrim(0, a_length)
- :: c_repeat_count = int(10*60*60/a_length) # 10 hours (even longer "-1" has
- :: c = c.Loop(c_repeat_count) # compatibility issue with MPC-BE)
- :: return c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement