codemirror-lang-liquidsoap 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/dist/cli.js +13 -13
  2. package/dist/index.js +15 -13
  3. package/package.json +2 -2
  4. package/src/index.ts +2 -0
  5. package/src/liquidsoap.grammar +9 -1
  6. package/src/parser.js +8 -8
  7. package/src/parser.terms.js +6 -5
  8. package/tests/liquidsoap/.github/scripts/build-posix.sh +0 -3
  9. package/tests/liquidsoap/.github/workflows/ci.yml +35 -10
  10. package/tests/liquidsoap/.pre-commit-config.yaml +1 -1
  11. package/tests/liquidsoap/CHANGES.md +1 -0
  12. package/tests/liquidsoap/CITATION.cff +17 -0
  13. package/tests/liquidsoap/doc/Makefile +17 -0
  14. package/tests/liquidsoap/doc/content/beets.md +6 -47
  15. package/tests/liquidsoap/doc/content/blank.md +5 -17
  16. package/tests/liquidsoap/doc/content/complete_case.md +1 -53
  17. package/tests/liquidsoap/doc/content/cookbook.md +23 -170
  18. package/tests/liquidsoap/doc/content/crossfade.md +1 -73
  19. package/tests/liquidsoap/doc/content/dynamic_sources.md +1 -47
  20. package/tests/liquidsoap/doc/content/external_decoders.md +6 -118
  21. package/tests/liquidsoap/doc/content/external_encoders.md +2 -4
  22. package/tests/liquidsoap/doc/content/external_streams.md +6 -20
  23. package/tests/liquidsoap/doc/content/ffmpeg_cookbook.md +9 -147
  24. package/tests/liquidsoap/doc/content/ffmpeg_filters.md +6 -93
  25. package/tests/liquidsoap/doc/content/harbor.md +4 -40
  26. package/tests/liquidsoap/doc/content/harbor_http.md +10 -118
  27. package/tests/liquidsoap/doc/content/help.md +1 -9
  28. package/tests/liquidsoap/doc/content/hls_output.md +6 -102
  29. package/tests/liquidsoap/doc/content/http_input.md +2 -4
  30. package/tests/liquidsoap/doc/content/icy_metadata.md +2 -24
  31. package/tests/liquidsoap/doc/content/in_production.md +2 -7
  32. package/tests/liquidsoap/doc/content/json.md +10 -36
  33. package/tests/liquidsoap/doc/content/language.md +1 -1
  34. package/tests/liquidsoap/doc/content/liq/Makefile +8 -0
  35. package/tests/liquidsoap/doc/content/liq/append-silence.liq +46 -0
  36. package/tests/liquidsoap/doc/content/liq/beets-amplify.liq +29 -0
  37. package/tests/liquidsoap/doc/content/liq/beets-protocol.liq +26 -0
  38. package/tests/liquidsoap/doc/content/liq/beets-source.liq +21 -0
  39. package/tests/liquidsoap/doc/content/liq/blank-detect.liq +10 -0
  40. package/tests/liquidsoap/doc/content/liq/blank-sorry.liq +11 -0
  41. package/tests/liquidsoap/doc/content/liq/check +4 -0
  42. package/tests/liquidsoap/doc/content/liq/complete-case.liq +69 -0
  43. package/tests/liquidsoap/doc/content/liq/cross.smart.liq +37 -0
  44. package/tests/liquidsoap/doc/content/liq/crossfade.liq +120 -0
  45. package/tests/liquidsoap/doc/content/liq/decoder-faad.liq +122 -0
  46. package/tests/liquidsoap/doc/content/liq/decoder-flac.liq +19 -0
  47. package/tests/liquidsoap/doc/content/liq/decoder-metaflac.liq +24 -0
  48. package/tests/liquidsoap/doc/content/liq/dump-hourly.liq +7 -0
  49. package/tests/liquidsoap/doc/content/liq/dump-hourly2.liq +4 -0
  50. package/tests/liquidsoap/doc/content/liq/dynamic-source.liq +55 -0
  51. package/tests/liquidsoap/doc/content/liq/external-output.file.liq +7 -0
  52. package/tests/liquidsoap/doc/content/liq/fallback.liq +4 -0
  53. package/tests/liquidsoap/doc/content/liq/ffmpeg-filter-dynamic-volume.liq +36 -0
  54. package/tests/liquidsoap/doc/content/liq/ffmpeg-filter-flanger-highpass.liq +10 -0
  55. package/tests/liquidsoap/doc/content/liq/ffmpeg-filter-hflip.liq +9 -0
  56. package/tests/liquidsoap/doc/content/liq/ffmpeg-filter-hflip2.liq +23 -0
  57. package/tests/liquidsoap/doc/content/liq/ffmpeg-filter-parallel-flanger-highpass.liq +36 -0
  58. package/tests/liquidsoap/doc/content/liq/ffmpeg-live-switch.liq +23 -0
  59. package/tests/liquidsoap/doc/content/liq/ffmpeg-relay-ondemand.liq +31 -0
  60. package/tests/liquidsoap/doc/content/liq/ffmpeg-relay.liq +19 -0
  61. package/tests/liquidsoap/doc/content/liq/ffmpeg-shared-encoding-rtmp.liq +43 -0
  62. package/tests/liquidsoap/doc/content/liq/ffmpeg-shared-encoding.liq +28 -0
  63. package/tests/liquidsoap/doc/content/liq/frame-size.liq +10 -0
  64. package/tests/liquidsoap/doc/content/liq/harbor-auth.liq +18 -0
  65. package/tests/liquidsoap/doc/content/liq/harbor-insert-metadata.liq +28 -0
  66. package/tests/liquidsoap/doc/content/liq/harbor-metadata.liq +14 -0
  67. package/tests/liquidsoap/doc/content/liq/harbor-redirect.liq +10 -0
  68. package/tests/liquidsoap/doc/content/liq/harbor-simple.liq +10 -0
  69. package/tests/liquidsoap/doc/content/liq/harbor-usage.liq +16 -0
  70. package/tests/liquidsoap/doc/content/liq/harbor.http.register.liq +48 -0
  71. package/tests/liquidsoap/doc/content/liq/harbor.http.response.liq +20 -0
  72. package/tests/liquidsoap/doc/content/liq/hls-metadata.liq +18 -0
  73. package/tests/liquidsoap/doc/content/liq/hls-mp4.liq +35 -0
  74. package/tests/liquidsoap/doc/content/liq/http-input.liq +6 -0
  75. package/tests/liquidsoap/doc/content/liq/icy-update.liq +31 -0
  76. package/tests/liquidsoap/doc/content/liq/input.mplayer.liq +26 -0
  77. package/tests/liquidsoap/doc/content/liq/json-ex.liq +29 -0
  78. package/tests/liquidsoap/doc/content/liq/json-stringify.liq +2 -0
  79. package/tests/liquidsoap/doc/content/liq/json1.liq +3 -0
  80. package/tests/liquidsoap/doc/content/liq/liquidsoap +4 -0
  81. package/tests/liquidsoap/doc/content/liq/live-switch.liq +23 -0
  82. package/tests/liquidsoap/doc/content/liq/medialib.liq +4 -0
  83. package/tests/liquidsoap/doc/content/liq/multitrack-add-video-track.liq +24 -0
  84. package/tests/liquidsoap/doc/content/liq/multitrack-add-video-track2.liq +10 -0
  85. package/tests/liquidsoap/doc/content/liq/multitrack-default-video-track.liq +14 -0
  86. package/tests/liquidsoap/doc/content/liq/multitrack.liq +11 -0
  87. package/tests/liquidsoap/doc/content/liq/multitrack2.liq +16 -0
  88. package/tests/liquidsoap/doc/content/liq/multitrack3.liq +10 -0
  89. package/tests/liquidsoap/doc/content/liq/output.file.hls.liq +44 -0
  90. package/tests/liquidsoap/doc/content/liq/prometheus-callback.liq +18 -0
  91. package/tests/liquidsoap/doc/content/liq/prometheus-settings.liq +3 -0
  92. package/tests/liquidsoap/doc/content/liq/radiopi.liq +467 -0
  93. package/tests/liquidsoap/doc/content/liq/re-encode.liq +14 -0
  94. package/tests/liquidsoap/doc/content/liq/regular.liq +8 -0
  95. package/tests/liquidsoap/doc/content/liq/replaygain-metadata.liq +6 -0
  96. package/tests/liquidsoap/doc/content/liq/replaygain-playlist.liq +6 -0
  97. package/tests/liquidsoap/doc/content/liq/rtmp.liq +10 -0
  98. package/tests/liquidsoap/doc/content/liq/samplerate3.liq +8 -0
  99. package/tests/liquidsoap/doc/content/liq/scheduling.liq +7 -0
  100. package/tests/liquidsoap/doc/content/liq/seek-telnet.liq +23 -0
  101. package/tests/liquidsoap/doc/content/liq/settings.liq +8 -0
  102. package/tests/liquidsoap/doc/content/liq/shoutcast.liq +5 -0
  103. package/tests/liquidsoap/doc/content/liq/space_overhead.liq +9 -0
  104. package/tests/liquidsoap/doc/content/liq/split-cue.liq +21 -0
  105. package/tests/liquidsoap/doc/content/liq/srt-receiver.liq +8 -0
  106. package/tests/liquidsoap/doc/content/liq/srt-sender.liq +4 -0
  107. package/tests/liquidsoap/doc/content/liq/transcoding.liq +18 -0
  108. package/tests/liquidsoap/doc/content/liq/video-anonymizer.liq +31 -0
  109. package/tests/liquidsoap/doc/content/liq/video-bluescreen.liq +14 -0
  110. package/tests/liquidsoap/doc/content/liq/video-in-video.liq +7 -0
  111. package/tests/liquidsoap/doc/content/liq/video-logo.liq +9 -0
  112. package/tests/liquidsoap/doc/content/liq/video-osc.liq +26 -0
  113. package/tests/liquidsoap/doc/content/liq/video-simple.liq +12 -0
  114. package/tests/liquidsoap/doc/content/liq/video-static.liq +20 -0
  115. package/tests/liquidsoap/doc/content/liq/video-text.liq +5 -0
  116. package/tests/liquidsoap/doc/content/liq/video-transition.liq +5 -0
  117. package/tests/liquidsoap/doc/content/liq/video-weather.liq +7 -0
  118. package/tests/liquidsoap/doc/content/liq/video-webcam.liq +1 -0
  119. package/tests/liquidsoap/doc/content/memory.md +2 -14
  120. package/tests/liquidsoap/doc/content/multitrack.md +6 -81
  121. package/tests/liquidsoap/doc/content/prometheus.md +8 -22
  122. package/tests/liquidsoap/doc/content/quick_start.md +1 -1
  123. package/tests/liquidsoap/doc/content/radiopi.md +1 -298
  124. package/tests/liquidsoap/doc/content/replay_gain.md +2 -7
  125. package/tests/liquidsoap/doc/content/seek.md +2 -18
  126. package/tests/liquidsoap/doc/content/shoutcast.md +1 -5
  127. package/tests/liquidsoap/doc/content/split-cue.md +1 -26
  128. package/tests/liquidsoap/doc/content/video-static.md +1 -20
  129. package/tests/liquidsoap/doc/content/video.md +23 -111
  130. package/tests/liquidsoap/doc/dune +6 -0
  131. package/tests/liquidsoap/doc/dune.inc +11350 -406
  132. package/tests/liquidsoap/doc/gen_dune.ml +81 -31
  133. package/tests/liquidsoap/doc/no-pandoc +1 -1
  134. package/tests/liquidsoap/liquidsoap +2 -1
  135. package/tests/liquidsoap/src/core/io/srt_io.ml +12 -3
  136. package/tests/liquidsoap/src/core/operators/video_effects.ml +3 -1
  137. package/tests/liquidsoap/src/core/outputs/output.ml +4 -2
  138. package/tests/liquidsoap/src/core/outputs/output.mli +2 -0
  139. package/tests/liquidsoap/src/core/visualization/video_volume.ml +7 -4
  140. package/tests/liquidsoap/src/js/index.html +2 -2
  141. package/tests/liquidsoap/src/lang/parser.mly +10 -10
  142. package/tests/liquidsoap/src/lang/term/parsed_term.ml +7 -11
  143. package/tests/liquidsoap/src/lang/term/term_reducer.ml +32 -32
  144. package/tests/liquidsoap/src/lang/utils.ml +3 -3
  145. package/tests/liquidsoap/src/libs/file.liq +15 -2
  146. package/tests/liquidsoap/src/libs/playlist.liq +3 -0
  147. package/tests/liquidsoap/src/runtime/main.ml +3 -0
  148. package/tests/liquidsoap/src/tooling/parsed_json.ml +9 -10
  149. package/tests/liquidsoap/tests/language/file.liq +4 -0
  150. package/tests/liquidsoap/tests/language/record.liq +33 -0
  151. package/tests/liquidsoap/tests/language/regexp.liq +2 -0
@@ -19,80 +19,8 @@ You can find its documentation in the [language reference](reference.html).
19
19
 
20
20
  Liquidsoap also includes a ready-to-use operator defined using `cross`, it is called `crossfade` and is defined in the pervasive helper script `utils.liq`. Its code is:
21
21
 
22
- ```liquidsoap
23
- # Smart transition for crossfade
24
- # @category Source / Track Processing
25
- # @param ~log Default logger
26
- # @param ~fade_in Fade-in duration, if any.
27
- # @param ~fade_out Fade-out duration, if any.
28
- # @param ~high Value, in dB, for loud sound level.
29
- # @param ~medium Value, in dB, for medium sound level.
30
- # @param ~margin Margin to detect sources that have too different sound level for crossing.
31
- # @param ~default Smart crossfade: transition used when no rule applies (default: sequence).
32
- # @param a Ending track
33
- # @param b Starting track
34
- def cross.smart(~log=log(label="cross.smart"),
35
- ~fade_in=3.,~fade_out=3.,
36
- ~default=(fun (a,b) -> (sequence([a, b]):source)),
37
- ~high=-15., ~medium=-32., ~margin=4.,
38
- a, b)
39
- let fade.out = fade.out(type="sin",duration=fade_out)
40
- let fade.in = fade.in(type="sin",duration=fade_in)
41
- add = fun (a,b) -> add(normalize=false,[b, a])
22
+ ```{.liquidsoap include="crossfade.liq"}
42
23
 
43
- # This is for the type system..
44
- ignore(a.metadata["foo"])
45
- ignore(b.metadata["foo"])
46
-
47
- if
48
- # If A and B are not too loud and close, fully cross-fade them.
49
- a.db_level <= medium and b.db_level <= medium and abs(a.db_level - b.db_level) <= margin
50
- then
51
- log("Old <= medium, new <= medium and |old-new| <= margin.")
52
- log("Old and new source are not too loud and close.")
53
- log("Transition: crossed, fade-in, fade-out.")
54
- add(fade.out(a.source),fade.in(b.source))
55
-
56
- elsif
57
- # If B is significantly louder than A, only fade-out A.
58
- # We don't want to fade almost silent things, ask for >medium.
59
- b.db_level >= a.db_level + margin and a.db_level >= medium and b.db_level <= high
60
- then
61
- log("new >= old + margin, old >= medium and new <= high.")
62
- log("New source is significantly louder than old one.")
63
- log("Transition: crossed, fade-out.")
64
- add(fade.out(a.source),b.source)
65
-
66
- elsif
67
- # Opposite as the previous one.
68
- a.db_level >= b.db_level + margin and b.db_level >= medium and a.db_level <= high
69
- then
70
- log("old >= new + margin, new >= medium and old <= high")
71
- log("Old source is significantly louder than new one.")
72
- log("Transition: crossed, fade-in.")
73
- add(a.source,fade.in(b.source))
74
-
75
- elsif
76
- # Do not fade if it's already very low.
77
- b.db_level >= a.db_level + margin and a.db_level <= medium and b.db_level <= high
78
- then
79
- log("new >= old + margin, old <= medium and new <= high.")
80
- log("Do not fade if it's already very low.")
81
- log("Transition: crossed, no fade.")
82
- add(a.source,b.source)
83
-
84
- # What to do with a loud end and a quiet beginning ?
85
- # A good idea is to use a jingle to separate the two tracks,
86
- # but that's another story.
87
-
88
- else
89
- # Otherwise, A and B are just too loud to overlap nicely, or the
90
- # difference between them is too large and overlapping would completely
91
- # mask one of them.
92
- log("No transition: using default.")
93
- default(a.source, b.source)
94
- end
95
- end
96
24
  ```
97
25
 
98
26
  You can use it directly in your script, or use this code to define yours!
@@ -14,54 +14,8 @@ a dynamic restreaming platform.
14
14
 
15
15
  Here's the code:
16
16
 
17
- ```liquidsoap
18
- settings.init.force_start := true
19
- settings.server.telnet := true
17
+ ```{.liquidsoap include="dynamic-source.liq"}
20
18
 
21
- # Replace the path here with a path to some video files:
22
- s = playlist("/path/to/files")
23
-
24
- streams = ref([])
25
- count = ref(0)
26
-
27
- enc = %ffmpeg(
28
- format="flv",
29
- %audio.copy,
30
- %video.copy
31
- )
32
-
33
- def create_stream(url) =
34
- if list.assoc.mem(url, !streams) then
35
- "Stream for url #{url} already exists!"
36
- else
37
- out = output.url(id="restream-#{!count}", fallible=true, url=url, enc, s)
38
- count := !count + 1
39
- streams := [...!streams, (url, out.shutdown)]
40
- "OK!"
41
- end
42
- end
43
-
44
- def delete_stream(url) =
45
- if not list.assoc.mem(url, !streams) then
46
- "Stream for url #{url} does not exists!"
47
- else
48
- shutdown = list.assoc(url, !streams)
49
- shutdown()
50
- streams := list.filter((fun (el) -> fst(el) != url), !streams)
51
- "OK!"
52
- end
53
- end
54
-
55
- server.register(namespace="restream",
56
- description="Redirect a stream.",
57
- usage="start <url>",
58
- "start",
59
- create_stream)
60
- server.register(namespace="restream",
61
- description="Stop a dynamic playlist.",
62
- usage="stop <url>",
63
- "stop",
64
- delete_stream)
65
19
  ```
66
20
 
67
21
  After executing this script, you should see two telnet commands:
@@ -79,57 +79,14 @@ The flac decoder uses the `flac` command line. It is enabled if the binary can b
79
79
 
80
80
  Its code is the following:
81
81
 
82
- ```liquidsoap
83
- def test_flac(file) =
84
- if process.test("which metaflac") then
85
- channels = list.hd(default="",process.read.lines("metaflac \
86
- --show-channels #{quote(file)} \
87
- 2>/dev/null"))
88
- # If the value is not an int, this returns 0 and we are ok :)
89
- int_of_string(channels)
90
- else
91
- # Try to detect using mime test..
92
- mime = get_mime(file)
93
- if string.match(pattern="flac",file) then
94
- # We do not know the number of audio channels
95
- # so setting to -1
96
- (-1)
97
- else
98
- # All tests failed: no audio decodable using flac..
99
- 0
100
- end
101
- end
102
- end
103
- decoder.add(name="FLAC",description="Decode files using the flac \
104
- decoder binary.", test=test_flac,flac_p)
82
+ ```{.liquidsoap include="decoder-flac.liq"}
83
+
105
84
  ```
106
85
 
107
86
  Additionally, a metadata resolver is registered when the `metaflac` command can be found in the `$PATH`:
108
87
 
109
- ```liquidsoap
110
- if process.test("which metaflac") then
111
- log(level=3,"Found metaflac binary: \
112
- enabling flac external metadata resolver.")
113
- def flac_meta(file)
114
- ret = process.read.lines("metaflac --export-tags-to=- \
115
- #{quote(file)} 2>/dev/null")
116
- ret = list.map(string.split(separator="="),ret)
117
- # Could be made better..
118
- def f(l',l)=
119
- if list.length(l) >= 2 then
120
- list.append([(list.hd(default="",l),list.nth(default="",l,1))],l')
121
- else
122
- if list.length(l) >= 1 then
123
- list.append([(list.hd(default="",l),"")],l')
124
- else
125
- l'
126
- end
127
- end
128
- end
129
- list.fold(f,[],ret)
130
- end
131
- decoder.metadata.add("FLAC",flac_meta)
132
- end
88
+ ```{.liquidsoap include="decoder-metaflac.liq"}
89
+
133
90
  ```
134
91
 
135
92
  ### The faad decoder
@@ -141,75 +98,6 @@ registered using `decoder.oblivious.add`.
141
98
 
142
99
  Its code is the following:
143
100
 
144
- ```liquidsoap
145
- aac_mimes = ["audio/aac", "audio/aacp", "audio/3gpp", "audio/3gpp2", "audio/mp4",
146
- "audio/MP4A-LATM", "audio/mpeg4-generic", "audio/x-hx-aac-adts"]
147
- aac_filexts = ["m4a", "m4b", "m4p", "m4v",
148
- "m4r", "3gp", "mp4", "aac"]
149
-
150
- # Faad is not very selective so
151
- # We are checking only file that
152
- # end with a known extension or mime type
153
- def faad_test(file) =
154
- # Get the file's mime
155
- mime = get_mime(file)
156
- # Test mime
157
- if list.mem(mime,aac_mimes) then
158
- true
159
- else
160
- # Otherwise test file extension
161
- ret = string.extract(pattern='\.(.+)$',file)
162
- if list.length(ret) != 0 then
163
- ext = ret["1"]
164
- list.mem(ext,aac_filexts)
165
- else
166
- false
167
- end
168
- end
169
- end
170
-
171
- if process.test("which faad") then
172
- log(level=3,"Found faad binary: enabling external faad decoder and \
173
- metadata resolver.")
174
- faad_p = (fun (f) -> "faad -w #{quote(f)} 2>/dev/null")
175
- def test_faad(file) =
176
- if faad_test(file) then
177
- channels = list.hd(default="",process.read.lines("faad -i #{quote(file)} 2>&1 | \
178
- grep 'ch,'"))
179
- ret = string.extract(pattern=", (\d) ch,",channels)
180
- ret =
181
- if list.length(ret) == 0 then
182
- # If we pass the faad_test, chances are
183
- # high that the file will contain aac audio data..
184
- "-1"
185
- else
186
- ret["1"]
187
- end
188
- int_of_string(default=(-1),ret)
189
- else
190
- 0
191
- end
192
- end
193
- decoder.oblivious.add(name="FAAD",description="Decode files using \
194
- the faad binary.", test=test_faad, faad_p)
195
- def faad_meta(file) =
196
- if faad_test(file) then
197
- ret = process.read.lines("faad -i \
198
- #{quote(file)} 2>&1")
199
- # Yea, this is tuff programming (again) !
200
- def get_meta(l,s)=
201
- ret = string.extract(pattern="^(\w+):\s(.+)$",s)
202
- if list.length(ret) > 0 then
203
- list.append([(ret["1"],ret["2"])],l)
204
- else
205
- l
206
- end
207
- end
208
- list.fold(get_meta,[],ret)
209
- else
210
- []
211
- end
212
- end
213
- decoder.metadata.add("FAAD",faad_meta)
214
- end
101
+ ```{.liquidsoap include="decoder-faad.liq"}
102
+
215
103
  ```
@@ -53,8 +53,6 @@ Videos can also be encoded by programs able to read files in avi format from
53
53
  standard input. To use it, the flag `video=true` of `%external` should be
54
54
  used. For instance, a compressed avi file can be generated with `ffmpeg` using
55
55
 
56
- ```liquidsoap
57
- output.file(
58
- %external(process="ffmpeg -i pipe:0 -f avi pipe:1",video=true),
59
- "/tmp/test.avi", s)
56
+ ```{.liquidsoap include="external-output.file.liq" from="BEGIN"}
57
+
60
58
  ```
@@ -10,7 +10,10 @@ though it should work too.
10
10
 
11
11
  ## Basic operator
12
12
 
13
- The basic operator for creating an external stream is `input.external`. Its parameters are:
13
+ The basic operators for creating an external stream are `input.external.wav`,
14
+ `input.external.rawaudio`, `input.external.avi` and `input.external.rawvideo`
15
+ (depending on the format of the data produced by the external program). The
16
+ parameters for the two first are
14
17
 
15
18
  - `buffer`: Duration of the pre-buffered data.
16
19
  - `max`: Maximum duration of the buffered data.
@@ -27,23 +30,6 @@ run the external program.
27
30
  A wrapper, `input.mplayer`, is defined to use mplayer as the external decoder.
28
31
  Its code is:
29
32
 
30
- ```liquidsoap
31
- # Stream data from mplayer
32
- # @category Source / Input
33
- # @param s data URI.
34
- # @param ~restart restart on exit.
35
- # @param ~restart_on_error restart on exit with error.
36
- # @param ~buffer Duration of the pre-buffered data.
37
- # @param ~max Maximum duration of the buffered data.
38
- def input.mplayer(~id="input.mplayer",
39
- ~restart=true,~restart_on_error=false,
40
- ~buffer=0.2,~max=10.,s) =
41
- input.external(id=id,restart=restart,
42
- restart_on_error=restart_on_error,
43
- buffer=buffer,max=max,
44
- "mplayer -really-quiet \
45
- -ao pcm:file=/dev/stdout \
46
- -vc null -vo null #{quote(s)} \
47
- 2>/dev/null")
48
- end
33
+ ```{.liquidsoap include="input.mplayer.liq"}
34
+
49
35
  ```
@@ -6,26 +6,8 @@ Here are some examples of what is possible to do with the ffmpeg support in liqu
6
6
 
7
7
  With ffmpeg support, Liquidsoap can relay encoded streams without re-encoding them, making it possible to re-send a stream to multiple destinations. Here's an example:
8
8
 
9
- ```liquidsoap
10
- # Input the stream,
11
- # from an Icecast server or any other source
12
- encoded_source = input.http("https://icecast.radiofrance.fr/fip-hifi.aac")
13
-
14
- # Send to one server here:
15
- output.icecast(
16
- %ffmpeg(format="adts", %audio.copy),
17
- fallible=true,
18
- mount="/restream",
19
- host="streaming.example.com", port=8000, password="xxx",
20
- encoded_source)
21
-
22
- # An another one here:
23
- output.icecast(
24
- %ffmpeg(format="adts", %audio.copy),
25
- fallible=true,
26
- mount="/restream",
27
- host="streaming2.example.com", port=8000, password="xxx",
28
- encoded_source)
9
+ ```{.liquidsoap include="ffmpeg-relay.liq"}
10
+
29
11
  ```
30
12
 
31
13
  We cannot use `mksafe` here because the content is not plain `pcm` samples, which this operator is designed to produce. There
@@ -43,38 +25,8 @@ In the script below, you need to match the encoded format of the stream with a b
43
25
  The `output.harbor` will then relay the data from the file if no one is connected and start/stop the underlying
44
26
  input when there are listeners:
45
27
 
46
- ```liquidsoap
47
- stream = input.http(start = false, "https://wwoz-sc.streamguys1.com/wwoz-hi.mp3")
48
-
49
- listeners_count = ref(0)
50
-
51
- def on_connect(~headers, ~uri, ~protocol, _) =
52
- listeners_count := !listeners_count + 1
53
- if !listeners_count > 0 and not stream.is_started() then
54
- log("Starting input")
55
- stream.start()
56
- end
57
- end
58
-
59
- def on_disconnect(_) =
60
- listeners_count := !listeners_count - 1
61
- if !listeners_count == 0 and stream.is_started() then
62
- log("Stopping input")
63
- stream.stop()
64
- end
65
- end
66
-
67
- blank = single("/tmp/blank.mp3")
68
-
69
- stream = fallback(track_sensitive=false, [stream, blank])
70
-
71
- output.harbor(
72
- %ffmpeg(format="mp3", %audio.copy),
73
- format="audio/mpeg",
74
- mount="relay",
75
- on_connect=on_connect,
76
- on_disconnect=on_disconnect,
77
- stream)
28
+ ```{.liquidsoap include="ffmpeg-relay-ondemand.liq"}
29
+
78
30
  ```
79
31
 
80
32
  ## Shared encoding
@@ -82,82 +34,16 @@ output.harbor(
82
34
  Liquidsoap can also encode in one place and share the encoded with data with multiple outputs, making it possible to
83
35
  minimize CPU resources. Here's an example adapted from the previous one:
84
36
 
85
- ```liquidsoap
86
- # Input the stream,
87
- # from an Icecast server or any other source
88
- source = input.http("https://icecast.radiofrance.fr/fip-hifi.aac")
89
-
90
- # Make it infallible:
91
- source = mksafe(source)
92
-
93
- # Encode it in mp3:
94
- source = ffmpeg.encode.audio(
95
- %ffmpeg(%audio(codec="libmp3lame")),
96
- source)
97
-
98
- # Send to one server here:
99
- output.icecast(
100
- %ffmpeg(format="mp3", %audio.copy),
101
- mount="/restream",
102
- host="streaming.example.com", port=8000, password="xxx",
103
- source)
104
-
105
- # An another one here:
106
- output.icecast(
107
- %ffmpeg(format="mp3", %audio.copy),
108
- mount="/restream",
109
- host="streaming2.example.com", port=8000, password="xxx",
110
- source)
37
+ ```{.liquidsoap include="ffmpeg-shared-encoding.liq"}
38
+
111
39
  ```
112
40
 
113
41
  Shared encoding is even more useful when dealing with video encoding, which is very costly. Here's a fun example
114
42
  sharing audio and video encoding and sending to different destinations, both via Icecast and to YouTube/Facebook
115
43
  via the rtmp protocol:
116
44
 
117
- ```liquidsoap
118
- # An audio source
119
- audio = ...
120
-
121
- # Encode it in mp3
122
- audio = ffmpeg.encode.audio(
123
- %ffmpeg(%audio(codec="libmp3lame")),
124
- audio)
125
-
126
- # Send it to icecast
127
- output.icecast(
128
- %ffmpeg(format="mp3", %audio.copy),
129
- host = "...",
130
- password = "...",
131
- mount = "/stream",
132
- audio
133
- )
134
-
135
- # A video source, for instance a static image
136
- video = ...
137
-
138
- # Encode it in h264 format
139
- video = ffmpeg.encode.video(
140
- %ffmpeg(%video(codec="libx264")),
141
- video)
142
-
143
- # Mux it with the audio
144
- stream = source.mux.video(video=video, audio)
145
-
146
- # Copy encoder for the rtmp stream
147
- enc = %ffmpeg(
148
- format="flv",
149
- %audio.copy,
150
- %video.copy)
151
-
152
- # Send to YouTube
153
- key = "..."
154
- url = "rtmp://a.rtmp.youtube.com/live2/#{key}"
155
- output.url(url=url, enc, stream)
156
-
157
- # Send to Facebook
158
- key = "..."
159
- url = "rtmps://live-api-s.facebook.com:443/rtmp/#{key}"
160
- output.url(self_sync=true, url=url, enc, stream)
45
+ ```{.liquidsoap include="ffmpeg-shared-encoding-rtmp.liq"}
46
+
161
47
  ```
162
48
 
163
49
  ## Add transparent logo and video
@@ -177,32 +63,8 @@ to adapt the binary data and, it's possible some new filters will need to be wri
177
63
 
178
64
  Here's a use case that has been tested: live switch between a playlist of mp4 files and a rtmp flv input:
179
65
 
180
- ```liquidsoap
181
- s1 = input.rtmp(listen=false,"rtmp://....")
182
- s1 = ffmpeg.filter.bitstream.h264_mp4toannexb(s1)
183
-
184
- s2 = playlist("/path/to/playlist")
185
- s2 = ffmpeg.filter.bitstream.h264_mp4toannexb(s2)
186
-
187
- s = fallback(track_sensitive=false, [s1, s2])
188
-
189
- mpegts = %ffmpeg(
190
- format="mpegts",
191
- fflags="-autobsf",
192
- %audio.copy, %video.copy)
193
-
194
- streams = [
195
- ("mpegts",mpegts),
196
- ]
197
-
198
- output_dir = "/tmp/hls"
66
+ ```{.liquidsoap include="live-switch.liq"}
199
67
 
200
- output.file.hls(playlist="live.m3u8",
201
- fallible=true,
202
- segment_duration=5.,
203
- output_dir,
204
- streams,
205
- s)
206
68
  ```
207
69
 
208
70
  - We need the `h264_mp4toannexb` on each stream to make sure that the mp4 data conforms to what the mpegts container expect
@@ -44,17 +44,8 @@ Conversely, tracks can be created from them using `ffmpeg.filter.audio.output` a
44
44
 
45
45
  Filters are configured within the closure of a function. Here's an example:
46
46
 
47
- ```liquidsoap
48
- def flanger_highpass(audio_track) =
49
- def mkfilter(graph) =
50
- audio_track = ffmpeg.filter.audio.input(graph, audio_track)
51
- audio_track = ffmpeg.filter.flanger(graph, audio_track, delay=10.)
52
- audio_track = ffmpeg.filter.highpass(graph, audio_track, frequency=4000.)
53
- ffmpeg.filter.audio.output(graph, audio_track)
54
- end
55
-
56
- ffmpeg.filter.create(mkfilter)
57
- end
47
+ ```{.liquidsoap include="ffmpeg-filter-flanger-highpass.liq"}
48
+
58
49
  ```
59
50
 
60
51
  This filter receives an audio input, creates a `ffmpeg.filter.audio.input` with it that can be passed
@@ -62,16 +53,8 @@ to filters, applies a flanger effect and then a high pass effect, creates an aud
62
53
 
63
54
  Here's another example for video:
64
55
 
65
- ```liquidsoap
66
- def hflip(video_track) =
67
- def mkfilter(graph) =
68
- video_track = ffmpeg.filter.video.input(graph, video_track)
69
- video_track = ffmpeg.filter.hflip(graph, video_track)
70
- ffmpeg.filter.video.output(graph, video_track)
71
- end
56
+ ```{.liquidsoap include="ffmpeg-filter-hflip.liq"}
72
57
 
73
- ffmpeg.filter.create(mkfilter)
74
- end
75
58
  ```
76
59
 
77
60
  This filter receives a video input, creates a `ffmpeg.filter.video.input` with it that can be passed to filters,
@@ -87,30 +70,8 @@ if they are simply copied.
87
70
 
88
71
  Here's an example with the previous filter:
89
72
 
90
- ```liquidsoap
91
- def hflip(s) =
92
- def mkfilter(graph) =
93
- let { audio = audio_track, video = video_track} = source.tracks(s)
94
-
95
- video_track = ffmpeg.filter.video.input(graph, video_track)
96
- video_track = ffmpeg.filter.hflip(graph, video_track)
97
-
98
- audio_track = ffmpeg.filter.audio.input(graph, audio_track)
99
- audio_track = ffmpeg.filter.acopy(graph, audio)
100
-
101
- video_track = ffmpeg.filter.video.output(graph, video_track)
102
- audio_track = ffmpeg.filter.audio.output(graph, audio_track)
103
-
104
- source({
105
- audio = audio_track,
106
- video = video_track,
107
- metadata = track.metadata(audio_track),
108
- track_marks = track.track_marks(audio_track)
109
- })
110
- end
73
+ ```{.liquidsoap include="ffmpeg-filter-hflip2.liq"}
111
74
 
112
- ffmpeg.filter.create(mkfilter)
113
- end
114
75
  ```
115
76
 
116
77
  FFmpeg filters are very powerful, they can also convert audio to video, for instance displaying information about the
@@ -123,35 +84,8 @@ supported in liquidsoap.
123
84
 
124
85
  In order to do so, you have to use a slightly different API:
125
86
 
126
- ```liquidsoap
127
- def dynamic_volume(s) =
128
- def mkfilter(graph) =
129
- filter = ffmpeg.filter.volume.create(graph)
130
-
131
- def set_volume(v) =
132
- ignore(filter.process_command("volume", "#{v}"))
133
- end
134
-
135
- let {audio = audio_track} = source.tracks(s)
136
-
137
- audio_track = ffmpeg.filter.audio.input(graph, audio_track)
138
- filter.set_input(audio_track)
139
- audio_track = filter.output
140
- audio_track = ffmpeg.filter.audio.output(graph, audio_track)
141
-
142
- s = source({
143
- audio = audio_track,
144
- metadata = track.metadata(audio_track),
145
- track_marks = track.track_marks(audio_track)
146
- }
87
+ ```{.liquidsoap include="ffmpeg-filter-dynamic-volume.liq" to="END"}
147
88
 
148
- (s, set_volume)
149
- end
150
-
151
- ffmpeg.filter.create(mkfilter)
152
- end
153
-
154
- let (s, set_volume) = dynamic_volume(s)
155
89
  ```
156
90
 
157
91
  First, we instantiate a volume filter via `ffmpeg.filter.volume.create`. The filter instance has a `process_command`, which we use to create the `set_volume` function. Then,
@@ -225,27 +159,6 @@ This filter receives an array of possible `audio` inputs as well as an array of
225
159
 
226
160
  Put together, this can be used as such:
227
161
 
228
- ```liquidsoap
229
- def parallel_flanger_highpass(s) =
230
- def mkfilter(graph) =
231
- audio_track = ffmpeg.filter.audio.input(graph, audio_track)
232
-
233
- let (audio, _) = ffmpeg.filter.asplit(outputs=2, graph, audio_track)
234
-
235
- let [a1, a2] = audio
236
-
237
- a1 = ffmpeg.filter.flanger(graph, a1, delay=10.)
238
- a2 = ffmpeg.filter.highpass(graph, a2, frequency=4000.)
239
-
240
- # For some reason, we need to enforce the format here.
241
- a1 = ffmpeg.filter.aformat(sample_fmts="s16", sample_rates="44100", channel_layouts="stereo", graph, a1)
242
- a2 = ffmpeg.filter.aformat(sample_fmts="s16", sample_rates="44100", channel_layouts="stereo", graph, a2)
243
-
244
- audio_track = ffmpeg.filter.amerge(inputs=2, graph, [a1, a2], [])
245
-
246
- ffmpeg.filter.audio.output(graph, audio_track)
247
- end
162
+ ```{.liquidsoap include="ffmpeg-filter-parallel-flanger-highpass.liq"}
248
163
 
249
- ffmpeg.filter.create(mkfilter)
250
- end
251
164
  ```