Reputation: 1987
I have been looking for an answer on SO, but didn't find any conclusive solution. I have almost everything, so I think I'm missing something.
I'm creating a batch script that takes the filename as an argument and creates an avisynth script from it.
See below:
echo.#BEGIN------------------------------------------------------------------------- >> %~n1-timecode.avs
echo.#Found at: http://superuser.com/questions/113666/how-can-i-burn-a-timecode-into-a-movie-file >> %~n1-timecode.avs
echo.global xPos = 10 >> %~n1-timecode.avs
echo.global yPos = 10 >> %~n1-timecode.avs
echo.global subsize = 40 >> %~n1-timecode.avs
echo.global subfont = "Arial" >> %~n1-timecode.avs
echo.#------------------------------------------------------------------------------ >> %~n1-timecode.avs
echo.function SubtitleTime( obj ) >> %~n1-timecode.avs
echo.{ >> %~n1-timecode.avs
echo. obj = ScriptClip( obj, "Subtitle( >> %~n1-timecode.avs
echo. \ String( chr(32) ) >> %~n1-timecode.avs
echo. \ + String( RightStr( String( ((int(current_frame/Framerate)/60)/60) ), 2 ) ) >> %~n1-timecode.avs
echo. \ + String( chr(58) ) >> %~n1-timecode.avs
echo. \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate)/60)-(((int(current_frame/Framerate)/60)/60)*60) ) ), 2 ) ) >> %~n1-timecode.avs
echo. \ + String( chr(58) ) >> %~n1-timecode.avs
echo. \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate))-(((int(current_frame/Framerate))/60)*60) ) ), 2 ) ) >> %~n1-timecode.avs
echo. \ + MidStr( String( (current_frame/Framerate) - (int(current_frame/Framerate)) ), 2, 4 ) >> %~n1-timecode.avs
echo. \ , font=subfont, size=subsize, x=xPos, y=yPos) >> %~n1-timecode.avs
echo. \ ") >> %~n1-timecode.avs
echo. return obj >> %~n1-timecode.avs
echo.} >> %~n1-timecode.avs
echo.#------------------------------------------------------------------------------ >> %~n1-timecode.avs
echo.DirectshowSource("%1").SubtitleTime >> %~n1-timecode.avs
echo.#END--------------------------------------------------------------------------- >> %~n1-timecode.avs
But the following two lines give problems:
echo. obj = ScriptClip( obj, "Subtitle( >> %~n1-timecode.avs
echo. \ ") >> %~n1-timecode.avs
I have tried double quotes, backslash, ^ ... none of them work - either they show the double quote or the line dissappears. Anybody can give me a hint on how to get this solved?
Upvotes: 0
Views: 391
Reputation: 130869
The unbalanced quote in the offending lines is turning your redirection into a string literal instead of a redirection operation. The quickest way to fix your original code is to escape the offending quotes.
echo. obj = ScriptClip( obj, ^"Subtitle( >> %~n1-timecode.avs
echo. \ ^") >> %~n1-timecode.avs
But your code has extra spaces at the end of each line in the output.
You could move the redirection to the front as MC ND did, and that would safely eliminate the extra space.
Note that you can often eliminate the space even with the redirection at the end if you remove any space before the redirection, but that will not work in your global declaration lines because the digit at the end will be taken to be part of the redirection.
But there is a simpler solution, and it runs faster because it only needs to open and position the file position for the output file once :-)
>> %~n1-timecode.avs (
echo.#BEGIN-------------------------------------------------------------------------
echo.#Found at: http://superuser.com/questions/113666/how-can-i-burn-a-timecode-into-a-movie-file
echo.global xPos = 10
echo.global yPos = 10
echo.global subsize = 40
echo.global subfont = "Arial"
echo.#------------------------------------------------------------------------------
echo.function SubtitleTime( obj )
echo.{
echo. obj = ScriptClip( obj, "Subtitle(
echo. \ String( chr(32) )
echo. \ + String( RightStr( String( ((int(current_frame/Framerate)/60)/60) ), 2 ) )
echo. \ + String( chr(58) )
echo. \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate)/60)-(((int(current_frame/Framerate)/60)/60)*60) ) ), 2 ) )
echo. \ + String( chr(58) )
echo. \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate))-(((int(current_frame/Framerate))/60)*60) ) ), 2 ) )
echo. \ + MidStr( String( (current_frame/Framerate) - (int(current_frame/Framerate)) ), 2, 4 )
echo. \ , font=subfont, size=subsize, x=xPos, y=yPos)
echo. \ ")
echo. return obj
echo.}
echo.#------------------------------------------------------------------------------
echo.DirectshowSource("%1").SubtitleTime
echo.#END---------------------------------------------------------------------------
)
Sometimes your output may have special characters that may need escaping. In such cases, it may be easier to do something like this that avoids the need for any escaping:
>> %~n1-timecode.avs (
for /f "tokens=* delims=:" %%L in ('findstr /b ::: "%~f0"') do echo(%%L
)
:::#BEGIN-------------------------------------------------------------------------
:::#Found at: http://superuser.com/questions/113666/how-can-i-burn-a-timecode-into-a-movie-file
:::global xPos = 10
:::global yPos = 10
:::global subsize = 40
:::global subfont = "Arial"
:::#------------------------------------------------------------------------------
:::function SubtitleTime( obj )
:::{
::: obj = ScriptClip( obj, "Subtitle(
::: \ String( chr(32) )
::: \ + String( RightStr( String( ((int(current_frame/Framerate)/60)/60) ), 2 ) )
::: \ + String( chr(58) )
::: \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate)/60)-(((int(current_frame/Framerate)/60)/60)*60) ) ), 2 ) )
::: \ + String( chr(58) )
::: \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate))-(((int(current_frame/Framerate))/60)*60) ) ), 2 ) )
::: \ + MidStr( String( (current_frame/Framerate) - (int(current_frame/Framerate)) ), 2, 4 )
::: \ , font=subfont, size=subsize, x=xPos, y=yPos)
::: \ ")
::: return obj
:::}
:::#------------------------------------------------------------------------------
:::DirectshowSource("%1").SubtitleTime
:::#END---------------------------------------------------------------------------
Upvotes: 2
Reputation: 70953
@echo off
> "%~n1-timecode.avs" break
>> "%~n1-timecode.avs" echo.#BEGIN-------------------------------------------------------------------------
>> "%~n1-timecode.avs" echo.#Found at: http://superuser.com/questions/113666/how-can-i-burn-a-timecode-into-a-movie-file
>> "%~n1-timecode.avs" echo.global xPos = 10
>> "%~n1-timecode.avs" echo.global yPos = 10
>> "%~n1-timecode.avs" echo.global subsize = 40
>> "%~n1-timecode.avs" echo.global subfont = "Arial"
>> "%~n1-timecode.avs" echo.#------------------------------------------------------------------------------
>> "%~n1-timecode.avs" echo.function SubtitleTime( obj )
>> "%~n1-timecode.avs" echo.{
>> "%~n1-timecode.avs" echo. obj = ScriptClip( obj, "Subtitle(
>> "%~n1-timecode.avs" echo. \ String( chr(32) )
>> "%~n1-timecode.avs" echo. \ + String( RightStr( String( ((int(current_frame/Framerate)/60)/60) ), 2 ) )
>> "%~n1-timecode.avs" echo. \ + String( chr(58) )
>> "%~n1-timecode.avs" echo. \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate)/60)-(((int(current_frame/Framerate)/60)/60)*60) ) ), 2 ) )
>> "%~n1-timecode.avs" echo. \ + String( chr(58) )
>> "%~n1-timecode.avs" echo. \ + String( RightStr( String( String( 0 ) + String( (int(current_frame/Framerate))-(((int(current_frame/Framerate))/60)*60) ) ), 2 ) )
>> "%~n1-timecode.avs" echo. \ + MidStr( String( (current_frame/Framerate) - (int(current_frame/Framerate)) ), 2, 4 )
>> "%~n1-timecode.avs" echo. \ , font=subfont, size=subsize, x=xPos, y=yPos)
>> "%~n1-timecode.avs" echo. \ ")
>> "%~n1-timecode.avs" echo. return obj
>> "%~n1-timecode.avs" echo.}
>> "%~n1-timecode.avs" echo.#------------------------------------------------------------------------------
>> "%~n1-timecode.avs" echo.DirectshowSource("%1").SubtitleTime
>> "%~n1-timecode.avs" echo.#END---------------------------------------------------------------------------
Upvotes: 1