Announcement

Collapse
No announcement yet.

Floating point calculations?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Floating point calculations?

    I'm trying to perform a simple calculation in a batch file but I'm having difficulties.

    Here is what I'm working with:

    Code:
    set /a Factor= 480 / (%SOURCE_VIDWIDTH%000)
    set "Scale_Factor=%Factor:~0,-3%.%Factor:~-3%"
    set /a Output_Height= %Scale_Factor% * %SOURCE_VIDHEIGHT%
    set /a Border_Value= (320 - %Output_Height%) / 2
    
    Echo.
    Echo.
    Echo\ Spline64Resize(480,%Output_Height%)
    Echo\ AddBorders(0,%Border_Value%,0,%Border_Value%)
    Echo.
    Echo.
    In the example that I'm working with:

    SOURCE_VIDWIDTH=1280
    SOURCE_VIDHEIGHT=720

    Spline64Resize(480,0)
    AssumeFPS(0,160,0,160)
    Last edited by rack04; 21st July 2009, 22:15.

  • #2
    Re: Floating point calculations?

    The "Set /a" statement has its limitations and bugs.
    IMHO it is better to start with translating your script to vbs.

    vbs sample
    Code:
    SOURCE_VIDWIDTH = 1280
    SOURCE_VIDHEIGHT = 720
    
    
    Factor = 480 / (SOURCE_VIDWIDTH * 1e3)
    Scale_Factor = Factor * 1e3
    Output_Height = Scale_Factor * SOURCE_VIDHEIGHT
    Crop_Value = (320 - Output_Height) / 2
    
    wsh.Echo "Spline64Resize(480," & Output_Height & ")" & vbNewLine _
           & "AssumeFPS(0," & Crop_Value & ",0," & Crop_Value & ")"
    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Floating point calculations?

      I guess it's never to late to learn vbs. Is there anyway to create a vbs just for this calculation and import the results to the batch file?

      Here is the batch file that I'm working with:

      Code:
      @SET MediaInfo_PATH=C:\Program Files\MediaInfo\CLI\MediaInfo.exe
      @SET WORKING_DIRECTORY=C:\Personal\Videos
      
      @Echo off
      SET /p    INPUT_VIDEO="Full path to input video: "
      
      Echo General;%%FileName%%>"%WORKING_DIRECTORY%\temporary-generalfilename.txt"
      "%MediaInfo_PATH%" --Inform=file://"%WORKING_DIRECTORY%\temporary-generalfilename.txt" "%INPUT_VIDEO%">"%WORKING_DIRECTORY%\temporary-analyzegeneralfilename.txt"
      Echo General;%%FolderName%%>"%WORKING_DIRECTORY%\temporary-generalfolder.txt"
      "%MediaInfo_PATH%" --Inform=file://"%WORKING_DIRECTORY%\temporary-generalfolder.txt" "%INPUT_VIDEO%">"%WORKING_DIRECTORY%\temporary-analyzegeneralfolder.txt"
      type "%WORKING_DIRECTORY%\temporary-analyzegeneralfilename.txt">"%WORKING_DIRECTORY%\temporary-analyzegeneralfilename.tmp"
      type "%WORKING_DIRECTORY%\temporary-analyzegeneralfolder.txt">"%WORKING_DIRECTORY%\temporary-analyzegeneralfolder.tmp"
      SET /p    SOURCE_FILENAME=<"%WORKING_DIRECTORY%\temporary-analyzegeneralfilename.tmp"
      SET /p    SOURCE_FOLDER=<"%WORKING_DIRECTORY%\temporary-analyzegeneralfolder.tmp"
      
      Echo Video;%%Width%%>"%WORKING_DIRECTORY%\temporary-videowidth.txt"
      "%MediaInfo_PATH%" --Inform=file://"%WORKING_DIRECTORY%\temporary-videowidth.txt" "%INPUT_VIDEO%">"%WORKING_DIRECTORY%\temporary-analyzevideowidth.txt"
      Echo Video;%%Height%%>"%WORKING_DIRECTORY%\temporary-videoheight.txt"
      "%MediaInfo_PATH%" --Inform=file://"%WORKING_DIRECTORY%\temporary-videoheight.txt" "%INPUT_VIDEO%">"%WORKING_DIRECTORY%\temporary-analyzevideoheight.txt"
      type "%WORKING_DIRECTORY%\temporary-analyzevideowidth.txt">"%WORKING_DIRECTORY%\temporary-analyzevideowidth.tmp"
      type "%WORKING_DIRECTORY%\temporary-analyzevideoheight.txt">"%WORKING_DIRECTORY%\temporary-analyzevideoheight.tmp"
      SET /p    SOURCE_VIDWIDTH=<"%WORKING_DIRECTORY%\temporary-analyzevideowidth.tmp"
      SET /p    SOURCE_VIDHEIGHT=<"%WORKING_DIRECTORY%\temporary-analyzevideoheight.tmp"
      
      DEL "%WORKING_DIRECTORY%\temporary-generalfilename.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzegeneralfilename.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzegeneralfilename.tmp"
      DEL "%WORKING_DIRECTORY%\temporary-generalfolder.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzegeneralfolder.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzegeneralfolder.tmp"
      DEL "%WORKING_DIRECTORY%\temporary-videowidth.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzevideowidth.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzevideowidth.tmp"
      DEL "%WORKING_DIRECTORY%\temporary-videoheight.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzevideoheight.txt"
      DEL "%WORKING_DIRECTORY%\temporary-analyzevideoheight.tmp"
      
      SET /a scale= 480 / (%SOURCE_VIDWIDTH%000)
      SET "factor=%scale:~0,-3%.%scale:~-3%"
      SET /a height= %factor% * %SOURCE_VIDHEIGHT%
      SET /a value= (320 - %height%) / 2
      
      Echo.
      Echo.
      Echo\ scale=%scale%
      Echo\ factor=%factor%
      Echo\ Spline64Resize(480,%height%)
      Echo\ AddBorders(0,%value%,0,%value%)
      Echo.
      Echo.
      Pause
      Last edited by rack04; 22nd July 2009, 14:09.

      Comment


      • #4
        Re: Floating point calculations?

        Originally posted by rack04 View Post
        I guess it's never to late to learn vbs. Is there anyway to create a vbs just for this calculation and import the results to the batch file?
        Maybe Powershell would be better a bet - unless you work with Server 2008 Core. It so happens there is no .Net available in Core, so no Poweshell either. This is supposed to change in R2.

        Anyway, I'd suggest you to take a look at W3Schools VBScripting pages. The content is not too detailed, but I often use the reference section. Another a good place is MSDN and Hey, Scripting Guy.

        For the batch -> VBS transforming, here are some pointers:

        File manipulation is done via Scripting.FileSystemObject methods.
        Console IO is done via VBScript.StdIn.Read(Line), .StdOut.Write(Line), msgbox and VBScript.Echo.

        -vP

        Comment

        Working...
        X