This project has moved and is read-only. For the latest updates, please go here.

Converting SONY Vegas sfl file to file suitable for import into Drax

Jan 20, 2012 at 2:38 PM

If it is of use to anyone, here is an oorexx (a free download) script to convert a SONY Vegas video sfl file to a txt file suitable for importing into Drax:

Rem /* Rexx command to extract chapter information from SONY Vegas sfl file
@REXX %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
@Goto :EOF
*/

Numeric Digits 10

Parse Arg SFLFile

SFLFile = Strip(SFLFile)
SFLFile = Strip(SFLFile,,"""")
SFLFile = Strip(SFLFile)

If Right(SFLFile,4) \= ".sfl" Then Do
   Say SFLFile "is not an sfl file!"
   Exit 3
End

Cue = Pos(".ac3.",SFLFile)

If Cue \= 0 Then Do
   Say SFLFile "is ac3 version of sfl file!"
   Exit 3
End

If (Right(SFLFile,8) \= ".mpg.sfl") & (Right(SFLFile,8) \= ".m2v.sfl") Then Do
   Say SFLFile "is not an mpg.sfl file!"
   Exit 3
End

say "Reading" SFLFile

Frametime = 1764 /* Frametime for PAL */
/* FrameTime = 1471.47 Frametime for NTSC (untested) */

Path = Stream(SFLFile, C, "Query Exists")
say path
Rc = Stream(SFLFile, C, "Close")
If Length(Path) = 0 Then Do
   Say "File" SFLFile "not found!"
   Exit 2
End
Cue = Pos("cue ",File)

TxtFile = Substr(SFLFile,1,Length(SFLFile)-8)||".txt"

If 0 \= Lines(TxtFile) Then Do
   Say TxtFile 'already exists - deleting!'
   Rc = Stream(TxtFile, C, "Close")
   Call SysFileDelete TxtFile
End

Say "Creating" TxtFile

Rc = Lineout(TxtFile, Right(0,2,"0")":"Right(0,2,"0")":"Right(0,2,"0")"."Right(0,3,"0") "Titles")

Size = Stream(SFLFile, C, "Query Size")

File = Charin(SFLFile, 1, Size)

Rc = Stream(SFLFile, C, "Close")

Cue = Pos("cue ",File)

If Cue = 0 Then Do
   Say "cue information not found"
   Exit 3
End

NoChaps = C2d(Reverse(Substr(File,Cue+8,4)))

Say NoChaps "chapters found"

If "LIST" \= Substr(File,Cue + 12 + (NoChaps * 24),4) Then Do
   Say "List section not found"
   Exit
End

If "adtl" \= Substr(File,Cue + 20 + (NoChaps * 24),4) Then Do
   Say "Adtl section not found"
   Exit 4
End

LPtr = Cue + 24 + (NoChaps * 24) /* Pointer to first labl entry - follows adtl entry */

Chaps.0 = 0
Do Di = 0 To NoChaps - 1
   Dip = Cue + 12 + (24 * Di)
   If "data" \= Substr(File,Dip+8,4) Then Do
      Say "Data section not found for chapter" (Di + 1)
      Exit 4
   End
   DiCnt = C2d(Reverse(Substr(File,Dip,4)))
   If DiCnt \= (Di + 1) Then Do
      Say "Data counter" DiCnt "does not match chapter number" (Di + 1)
   End
   DiTC = C2d(Reverse(Substr(File,Dip+4,4)))

   Frames = ditc % Frametime

   Secs = Frames % 25
   Mins = Secs % 60
   Hrs = Mins % 60
   /* say ditc frames secs mins hrs Right(Hrs,2,"0")":"Right(Mins//60,2,"0")":"Right(Secs//60,2,"0")"."Right(40*(Frames//25),3,"0") */

   If "labl" \= Substr(File,LPtr,4) Then Do
      Say "Data section not found for chapter" (Di + 1)
      Exit 4
   End
   LLen = C2d(Reverse(Substr(File,Lptr+4,4)))
   LId = C2d(Reverse(Substr(File,Lptr+8,4)))
   If LId \= (Di + 1) Then Do
      Say "Labl counter" Lid "does not match chapter number" (Di + 1)
   End

   ChTxt = Strip(Substr(File,Lptr+12,LLen-5))

   If Di > 0 Then Do /* Check for duplicates */
     Do Dii = 0 To Di - 1
        If Chaps.Dii = ChTxt Then
           ChTxt = ChTxt||" " /* Add a space to keep drax happy */
     End
   End
   Chaps.Di = ChTxt
   Chaps.0 = Di  

   Say Right(Hrs,2,"0")":"Right(Mins//60,2,"0")":"Right(Secs//60,2,"0") """"ChTxt""""
   Rc = Lineout(TxtFile, Right(Hrs,2,"0")":"Right(Mins//60,2,"0")":"Right(Secs//60,2,"0")"."Right(40*(Frames//25),3,"0") ChTxt)
  
   If 1 = LLen//2 Then
      LPtr = LPtr + 1
   LPtr = LPtr + LLen + 8

End

Rc = Stream(TxtFile, C, "Close")

Exit 0

Sep 10, 2012 at 4:04 AM

Interesting, and worth a try.

FWIW, Drax already imports chapter markers from .txt copied from Vegas Edit Details.