-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaEncoder.fs
More file actions
53 lines (40 loc) 路 1.55 KB
/
Copy pathMediaEncoder.fs
File metadata and controls
53 lines (40 loc) 路 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
锘縨odule TrickyCat.VideoEncoder.MediaEncoder
open MediaInfo
open System.Diagnostics
type EncodedFilePath = string
type MediaEncoderError = {
sourceFilePath: string
targetFilePath: string
error: string
}
let private getErrorDetails sourceFilePath targetFilePath error =
{
sourceFilePath = sourceFilePath
targetFilePath = targetFilePath
error = error
}
let private ``get ffmpeg encode query`` sourceFilePath targetFilePath dimensions =
$"-i \"{sourceFilePath}\" -loglevel fatal -y -c:v libx264 -crf 24 -pix_fmt yuv420p -tune film -c:a aac -b:a 192k -ar 44100 -vol 300 -strict -2 -speed fastest -s {dimensions.width}x{dimensions.height} \"{targetFilePath}\""
let private ``run ffmpeg query`` ffmpegQuery =
ProcessUtils.runProcessSuccessfully'
{
preStart = (fun process' ->
process'.StartInfo.RedirectStandardOutput <- false
process'.StartInfo.RedirectStandardError <- false
)
postStart = (fun process' ->
process'.PriorityClass <- ProcessPriorityClass.BelowNormal
)
}
"ffmpeg"
ffmpegQuery
|> Result.map ignore
let encodeFile
(sourceFilePath: string)
(targetFilePath: string)
(dimensions: Dimensions)
: Result<EncodedFilePath, MediaEncoderError> =
``get ffmpeg encode query`` sourceFilePath targetFilePath dimensions
|> ``run ffmpeg query``
|> Result.map (fun () -> targetFilePath)
|> Result.mapError (getErrorDetails sourceFilePath targetFilePath)