24
24
25
25
open Ffmpeg_encoder_common
26
26
27
+ let replace_default opts name default =
28
+ Hashtbl. replace opts name (Option. value ~default (Hashtbl. find_opt opts name))
29
+
27
30
let () =
28
31
Plug. register Encoder. plug " ffmpeg" ~doc: " " (function
29
32
| Encoder. Ffmpeg ffmpeg ->
@@ -32,28 +35,14 @@ let () =
32
35
(* Inject hls params. *)
33
36
let ffmpeg =
34
37
if hls then (
35
- let opts =
36
- match ffmpeg.Ffmpeg_format. format with
37
- | Some "mp4" ->
38
- let opts = Hashtbl. copy ffmpeg.Ffmpeg_format. opts in
39
- let movflags =
40
- Option. value
41
- ~default:
42
- (`String
43
- " +dash+skip_sidx+skip_trailer+frag_custom" )
44
- (Hashtbl. find_opt ffmpeg.Ffmpeg_format. opts
45
- " movflags" )
46
- in
47
- Hashtbl. replace opts " movflags" movflags;
48
- let frag_duration =
49
- Option. value ~default: (`Int 10 )
50
- (Hashtbl. find_opt ffmpeg.Ffmpeg_format. opts
51
- " frag_duration" )
52
- in
53
- Hashtbl. replace opts " frag_duration" frag_duration;
54
- opts
55
- | _ -> ffmpeg.Ffmpeg_format. opts
56
- in
38
+ let opts = Hashtbl. copy ffmpeg.Ffmpeg_format. opts in
39
+ replace_default opts " flush_packets" (`Int 1 );
40
+ (match ffmpeg.Ffmpeg_format. format with
41
+ | Some "mp4" ->
42
+ replace_default opts " movflags"
43
+ (`String " +dash+skip_sidx+skip_trailer+frag_custom" );
44
+ replace_default opts " frag_duration" (`Int 10 )
45
+ | _ -> () );
57
46
let streams =
58
47
List. map
59
48
(function
@@ -62,11 +51,8 @@ let () =
62
51
({ Ffmpeg_format. opts } as stream :
63
52
Ffmpeg_format. encoded_stream) ) ->
64
53
let opts = Hashtbl. copy opts in
65
- let flags =
66
- Option. value ~default: (`String " +global_header" )
67
- (Hashtbl. find_opt opts " flags" )
68
- in
69
- Hashtbl. replace opts " flags" flags;
54
+ replace_default opts " flags"
55
+ (`String " +global_header" );
70
56
(lbl, `Encode { stream with Ffmpeg_format. opts })
71
57
| s -> s)
72
58
ffmpeg.Ffmpeg_format. streams
0 commit comments