Automatically save files under a user-defined filename when extracted

(Originally posted by Anson on 7/10/2006)

I would like to convert an avi file into a sequence of jpeg files with a certain sampling frequency. I know this can be done using the extract command under the sequence menu. Each jpeg file will then be opened as an untitled document. It is very time consuming to save each of the jpeg file one by one manually. Therefore, I would like to know if there is a way (perhaps with a macro?) so that the jpeg files can be saved automatically under a user-defined set of filenames when the jpeg files are extracted?

 

Comments

  • edited June 2013

    (Originally posted by Chris Tully on 7/10/2006)

    Save the following code to a file with the .ipm extension, change the value of the EXT constant to "jpg", and load this as the current macri in Image-Pro Plus. It should do exactly what you want.

    Option Explicit
    '**********************************************************************
    ' Filename:   Split Sequence.scr
    ' Copyright Media Cybernetics, Inc. 2002
    '
    ' Free for use as demonstration code.
    '
    '----------------------------------------------------------------------
    ' PROBLEM SOLVED:
    ' Automatically copies each frame of a sequence and saves it to a new
    ' Tiff file named as OriginalImage 001.tif. Where the original sequence
    ' file was name Original Image.seq, and had at least 100 frames.  The
    ' number will be padded with zeros to allow proper sorting of the files
    ' by Windows.
    '
    '----------------------------------------------------------------------
    ' WHO WOULD USE THIS:
    ' Anybody who wants to sperate a sequence into its individual frames
    ' and automatically save those frames to a numbered series of files.
    '
    '----------------------------------------------------------------------
    ' SYSTEM REQUIREMENTS:
    ' Image-Pro Plus 4.x
    '
    '----------------------------------------------------------------------
    'HISTORY OF CHANGES:
    'Macro Version:    1.0
    'Created:          5/23/02
    'Modified:        
    'Author:           Chris Tully
    'Application:      IPWin
    'Version:          4.x
    'Change History:
    '     1.0:        
    '**********************************************************************

    ' Change the value of this constant to change the file save type
    Const EXT = "tif"
    'Const EXT = "jpg"

    Sub SplitSeq()
     Dim nFrames As Integer
     Dim i As Integer
     Dim TrimIndex As Integer
     Dim DocID As Integer
     Dim SeqID As Integer
     Dim DummyPt As POINTAPI
     Dim fName As String
     Dim pName As String*255
     Dim Pre As String
     Dim NumFrmt As String
     Dim Skip As Integer
     
     SeqID = IpDocClick("Click on the sequence to split.", DummyPt)
     ret = IpDocGetStr(INF_FILENAME, SeqID, pName)
     fName = IpTrim(pName)
     TrimIndex = InStrRev(fName, ".")

     Pre = Left$(fName, TrimIndex-1) + " "

     ret = IpStGetInt("Save every nth farme.  n =", Skip, 1, 1, nFrames)
     
     ret = IpSeqGet(SEQ_NUMFRAMES, nFrames)
     NumFrmt = ""
     For i = 1 To Len(CStr(nFrames))
      NumFrmt = NumFrmt + "0"
     Next i
     
     For i = 0 To nFrames-1 Step Skip
      ret = IpAppSelectDoc(SeqID)
      ret = IpSeqPlay(i)
      DocID = IpSeqExtractFrames(i, 1)
      ret = IpWsSaveAs(Pre + Format$(i+1, NumFrmt) + "." + EXT, EXT)
      ret = IpDocCloseEx(DocID)
     Next i
    End Sub

Sign In or Register to comment.