Skip to content

Commit b008646

Browse files
committed
Cleanup code.
1 parent 003ec7f commit b008646

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ New:
1010
Fixed:
1111

1212
- Optimized CPU usage (#4369, #4370)
13+
- Fixed empty initial HLS segment (#4401)
1314
- Fixed support for `duration` metadata in image decoder (#4397)
1415
- Fixed cue-out bug in cue file parsing (#4381)
1516
- Bring back parse error location. (#4362)

src/core/encoder/encoders/ffmpeg_encoder.ml

+13-27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
open Ffmpeg_encoder_common
2626

27+
let replace_default opts name default =
28+
Hashtbl.replace opts name (Option.value ~default (Hashtbl.find_opt opts name))
29+
2730
let () =
2831
Plug.register Encoder.plug "ffmpeg" ~doc:"" (function
2932
| Encoder.Ffmpeg ffmpeg ->
@@ -32,28 +35,14 @@ let () =
3235
(* Inject hls params. *)
3336
let ffmpeg =
3437
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+
| _ -> ());
5746
let streams =
5847
List.map
5948
(function
@@ -62,11 +51,8 @@ let () =
6251
({ Ffmpeg_format.opts } as stream :
6352
Ffmpeg_format.encoded_stream) ) ->
6453
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");
7056
(lbl, `Encode { stream with Ffmpeg_format.opts })
7157
| s -> s)
7258
ffmpeg.Ffmpeg_format.streams

0 commit comments

Comments
 (0)