Advertisement
Erlord

GeOda_ffmpeg

Dec 4th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.28 KB | None | 0 0
  1. type SnapConfig =
  2.     {
  3.         programmeId: string
  4.         carrierId: string
  5.         outputSnapPath: string
  6.         outputSnapName: string
  7.         outputSnapTime: string
  8.     }
  9.  
  10. module PicturesEh =
  11.     open System.Diagnostics
  12.     open System
  13.     open System.IO
  14.  
  15.     let GenerateSearchPaths (programmeId: string, carrierId: string) =
  16.         [@"\\somePath\6\"; @"\\somePath\5\"; @"\\somePath\4\"; @"\\somePath\3\"; @"\\somePath\2\";]
  17.         |> List.map(fun path -> System.String.Format("{0}{1}{2}{3}{4}", path
  18.                                                             , programmeId.Substring(0, 6) + "\\"
  19.                                                             , programmeId.Substring(6, 2) + "\\"
  20.                                                             , programmeId.Substring(0, 12) + "\\"
  21.                                                             , carrierId + "_ID180.mp4"))
  22.  
  23.     let FindFilePath searchPaths =
  24.         searchPaths
  25.         |> List.find(fun searchPath -> System.IO.File.Exists(searchPath))
  26.  
  27.     let GenerateFFmpegParameters time outputPath filePath =
  28.         System.String.Format("{0}{1}{2}{3}{4}", @"-y -ss ", time, " -i ",
  29.                                 filePath, @" -s 96x54 -f image2 -vframes 1 "
  30.                                 + outputPath)
  31.  
  32.     let RunCommand parameters =
  33.         let processInfo = new ProcessStartInfo(@"C:\test\ffmpeg\bin\ffmpeg.exe", parameters)
  34.         processInfo.UseShellExecute <- false
  35.         processInfo.CreateNoWindow <- true
  36.         processInfo.RedirectStandardOutput <- true
  37.         processInfo.RedirectStandardError <- true
  38.         try
  39.             let proc = System.Diagnostics.Process.Start(processInfo)
  40.             let output = proc.StandardError.ReadToEnd() //writes to standard error not output, why?
  41.             proc.WaitForExit()
  42.             output
  43.         with
  44.             | :? Exception as ex ->
  45.                 ""
  46.  
  47.     let TakeSnap snapConfig =
  48.         GenerateSearchPaths (snapConfig.programmeId, snapConfig.carrierId)
  49.         |> FindFilePath
  50.         |> GenerateFFmpegParameters snapConfig.outputSnapTime (snapConfig.outputSnapPath + snapConfig.outputSnapName)
  51.         |> RunCommand
  52.         |> printfn "output: %s"
  53.        
  54.         snapConfig.outputSnapPath + snapConfig.outputSnapName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement