Last active
August 29, 2015 14:10
-
-
Save wiig-with-a-k/2ecdaa437d8962194b9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace GeOda.PicturesEh | |
type SnapConfig = | |
{ | |
programmeId: string | |
carrierId: string | |
outputSnapPath: string | |
outputSnapName: string | |
outputSnapTime: string | |
} | |
module PicturesEh = | |
open System.Diagnostics | |
open System | |
open System.IO | |
let GenerateSearchPaths (programmeId: string, carrierId: string) = | |
[@"\\somePath\6\"; @"\\somePath\5\"; @"\\somePath\4\"; @"\\somePath\3\"; @"\\somePath\2\";] | |
|> List.map(fun path -> System.String.Format("{0}{1}{2}{3}{4}", path | |
, programmeId.Substring(0, 6) + "\\" | |
, programmeId.Substring(6, 2) + "\\" | |
, programmeId.Substring(0, 12) + "\\" | |
, carrierId + "_ID180.mp4")) | |
let FindFilePath searchPaths = | |
searchPaths | |
|> List.find(fun searchPath -> System.IO.File.Exists(searchPath)) | |
let GenerateFFmpegParameters time outputPath filePath = | |
System.String.Format("{0}{1}{2}{3}{4}", @"-y -ss ", time, " -i ", | |
filePath, @" -s 96x54 -f image2 -vframes 1 " | |
+ outputPath) | |
let RunCommand parameters = | |
let processInfo = new ProcessStartInfo(@"C:\test\ffmpeg\bin\ffmpeg.exe", parameters) | |
processInfo.UseShellExecute <- false | |
processInfo.CreateNoWindow <- true | |
processInfo.RedirectStandardOutput <- true | |
processInfo.RedirectStandardError <- true | |
try | |
let proc = System.Diagnostics.Process.Start(processInfo) | |
let output = proc.StandardError.ReadToEnd() //writes to standard error not output, why? | |
proc.WaitForExit() | |
output | |
with | |
| :? Exception as ex -> | |
"" | |
let TakeSnap snapConfig = | |
GenerateSearchPaths (snapConfig.programmeId, snapConfig.carrierId) | |
|> FindFilePath | |
|> GenerateFFmpegParameters snapConfig.outputSnapTime (snapConfig.outputSnapPath + snapConfig.outputSnapName) | |
|> RunCommand | |
|> printfn "output: %s" | |
snapConfig.outputSnapPath + snapConfig.outputSnapName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment