]> git.sesse.net Git - nageru-docs/blob - futatabi.rst
Document unsynchronized HDMI/SDI output.
[nageru-docs] / futatabi.rst
1 Futatabi: Real-time instant replay with slow motion
2 ===================================================
3
4 Futatabi (after the Japanese word *futatabi*, 再び, meaning “again” or
5 “for the second time”) is a system for instant replay. Even though Futatabi
6 is meant to be used with Nageru, shares some code with it and is built from
7 the same source distribution, it is a separate
8 application. Futatabi is meant for slow motion for e.g. sports broadcasts, but
9 can also be used as a more generic multitrack recorder for later editing.
10
11 Futatabi supports *interpolated* slow motion, meaning you do not need to buy
12 a high-speed 120 fps camera to get smooth 60 fps output after slowdown—Futatabi
13 will automatically synthesize in-between frames for you during playback.
14 Good interpolation, especially in realtime, is a difficult problem, and not all
15 content will do equally well. Most content should do quite acceptably, especially
16 considering that half of the frames will actually be originals, but you
17 will need to see in practice what actually works for you. Interpolation can
18 also be used for frame rate conversion (e.g. 50 to 59.94 fps).
19
20 Futatabi currently uses a GPU reimplementation of
21 `Fast Optical Flow using Dense Inverse Search (DIS) <https://github.com/tikroeger/OF_DIS>`_
22 by Kroeger et al, together with about half of the algorithm from
23 `Occlusion Reasoning for Temporal Interpolation Using Optical Flow <https://www.microsoft.com/en-us/research/publication/occlusion-reasoning-for-temporal-interpolation-using-optical-flow/>`_
24 (to do the actual interpolation based on the estimated
25 optical flow), although this may change in the future.
26
27 Since Futatabi is part of the Nageru source distribution, its version number
28 mirrors Nageru.
29
30
31 System requirements
32 -------------------
33
34 It is strongly recommended to run Futatabi on a separate machine from Nageru,
35 not the least because you probably want a different person to operate the replay
36 while the producer is operating Nageru. (See :ref:`coop`.)
37
38 Like Nageru, Futatabi uses your GPU for nearly all image processing.
39 However, unlike Nageru, Futatabi requires a powerful GPU for interpolation;
40 a GTX 1080 or similar is recommended for interpolated 720p60. (Futatabi
41 was initially developed on a GTX 950, which is passable, but has little
42 performance margin.) If you have a slower GPU and are happy with worse
43 quality, or just wish to test, you can use a faster preset, or turn off
44 interpolation entirely. Futatabi requires OpenGL 4.5 or newer.
45
46 For other required libraries, see :ref:`compile`; when you build Nageru,
47 you also build Futatabi.
48
49
50 Getting started
51 ---------------
52
53 Futatabi always pulls data from Nageru over the network; it doesn't support SDI
54 input or output. Assuming you have a recent version of Nageru (typically one
55 that comes with Futatabi), it is capable of sending all of its cameras as one
56 video stream (see :ref:`futatabiformat`), so you can start Futatabi with
57
58   ./futatabi http://nageru-server.example.org:9095/multicam.mp4
59
60 If you do not have a running Nageru installation, see :ref:`sampledata`.
61
62 Once you are up and connected, Futatabi will start recording all of the frames
63 to disk. This process happens continuously for as long as you have disk space,
64 even if you are playing something back or editing clips, and the streams are
65 displayed in real time in mini-display as they come in. You make replays in
66 the form of *clips* (the top list is the clip list), which are then queued into
67 the *playlist* (the bottom list). Your end result is a live HTTP stream that
68 can be fed back into Nageru as a video input; by default, Futatabi listens
69 on port 9096.
70
71 Futatabi has the concept of a *workspace*, which defaults to your current
72 directory (you can change it with the -d option). This holds all of the
73 recorded frames, all metadata about clips, and preferences set from the menus
74 (interpolation quality and cue point padding).  If you quit Futatabi and
75 restart it (or you go down as the result of a power failure or the likes),
76 it will remember all the state and frames for you. As a special case,
77 if you give */dev/null* in place of an input URL or file, you can keep using
78 your workspace without getting any new frames added.
79
80 .. _basicui:
81
82 Basic UI operations
83 '''''''''''''''''''
84
85 Nageru can be operated using either the keyboard and mouse, or using a MIDI
86 controller with some help of the mouse. In this section, we will be discussing
87 the keyboard and mouse only; see :ref:`midi-futatabi` for details on using MIDI
88 controllers.
89
90 A clip in the clip list consists simply of an in and an out point; it represents
91 an interval of physical time (although timed to the video clock). A clip in the
92 playlist contains the same information plus some playback parameters, in particular
93 which camera (stream) to play back.
94
95 Clicking the ”Cue in” button, or pressing the A key, will start a new clip in
96 the clip list that begins at the current time. Similarly, clicking the ”Cue
97 out” button, or pressing the S key, will set the end point for said clip.
98 (If you click a button twice, it will overwrite the previous result.)
99 Now it is in a state where you can queue it to the play list (mark the camera
100 you want to use and click the “Queue” button, or Q on the keyboard—you can queue
101 a clip multiple times with different cameras) for
102 playing, or you can preview them using the “Preview” button (W on the
103 keyboard). Previewing can be done either from the clip list the clip list or
104 the playlist; they will not be interpolated or faded, but will be played back
105 in the right
106
107 You can edit cue points, both in the clip and the playlist, in two ways:
108 Either use the scroll wheel on the mouse, or hold down the left mouse button
109 and scrub left or right. (You can hold down Shift to change ten times as fast,
110 or Alt to change at one-tenth the speed.) You'll see the new cue points as you
111 change them in the preview window. You can also give clips names; these don't
112 mean anything, but can be good references to locate a specific kind of clip
113 for later use. Once you're happy with a playlist, and your producer is ready
114 to cut to your channel, click on the first clip you want to play back and
115 click the “Play” button (space on the keyboard); the result will both be
116 visible in the top screen and go out live over the network to Nageru.
117
118 .. _speed:
119
120 Controlling the playback speed
121 ''''''''''''''''''''''''''''''
122
123 Most slow motion is at 0.5x speed (or equivalently, “2x slow motion”),
124 and when you queue a clip from the clip list to the playlist, this is what
125 it gets by default. However, you are free to change it to whatever you wish,
126 like 0.333x, 0.25x (both are fairly common “super slow” standards) or even 1.0x.
127 As long as you are reasonably close to a rational number with low integers
128 (e.g. 1/2, 2/3, etc.), Futatabi will do its best to try to reuse as many
129 original frames as possible, keeping quality and performance at their highest
130 levels.
131
132 In addition to the per-clip speed, it is often interesting to change the
133 speed *during* playback of a clip. For instance, you could keep normal
134 slow motion (0.5x) speed in the run-up to a shot, ramp down to 0.1x to get
135 a good look at the actual shot, and then ramp back once it's done.
136 When done right and not overused, this can create a dramatic effect that's
137 hard to replicate using constant slowdown.
138
139 To this effect, Futatabi supports a *master speed* control. It is found at
140 the bottom of the window (or you can :ref:`control it using a MIDI device <midi-futatabi>`);
141 note that by default, it is locked at 100% until you click the lock button
142 to unlock it. (This is particularly important when using a MIDI device, where it is very easy
143 to touch a slider inadvertedly, and very hard to set it back exactly at 100%.)
144 The master speed control is multiplied in on top of all other speed factors,
145 so if you have e.g. a clip at 0.5x and the master speed is set to 70%,
146 the clip will effectively play back at 0.35x. The master speed can be set between
147 10% and 200%, inclusive.
148
149 Note that the master speed control governs the speed of the *output* clock,
150 unlike any other speed control in Futatabi. In particular, this means that unlike
151 the regular clip speeds, it affects fade times; if fade time is at 0.5 seconds
152 and master speed is set to 70%, the fade will take approximately 0.714 seconds
153 (0.5 divided by 0.7). It also means that the “remaining time” displays will be
154 wrong if master speed is not at 100%. This is because the master speed
155 is by nature unpredictable (the user can change it at any time); one cannot
156 e.g. delay fades when the master speed is reduced, since turning it back up
157 would mean the start of the fade were simply missed. Similarly, it is impossible
158 to give a proper estimate of time remaining that takes master speed into account;
159 it would be overestimating time significantly, given that the operator is likely
160 to turn it back up to 100% again soon.
161
162 Finally, note that when changing master speed, the speed is no longer at a
163 rational, so most frames will be interpolated frames. If your GPU is not fast
164 enough to interpolate every frame (ie., it is reliant on Futatabi's usual
165 reuse of original frames), it will drop output frames. Normal behavior will
166 resume from the next clip, when the clocks will again go in lockstep (assuming the master
167 speed is at 100% at that point). If you're not ramping, or if you're done ramping,
168 it's recommended to keep the speed lock on to avoid inadvertedly changing the speed.
169
170 .. _coop:
171
172 Working with your producer
173 ''''''''''''''''''''''''''
174
175 Generally, we recommend that the producer (Nageru operator) and slow motion
176 operator (Futatabi operator) sit closely together and can communicate verbally.
177 Good cooperation between the two is essential to get a good final product;
178 especially the switches to and from the replays can be a critical point.
179
180 The general rule for working together is fairly obvious: The producer should
181 switch to a replay when there's something to show, and switch away when there's
182 nothing more to show (or, less ideally, when something live takes priority).
183 Generally, when you have a playlist ready, inform your producer; they will
184 count you in (three, two, one, go). At one, start playing so that you have some
185 margin. If the Nageru theme is set up correctly (see :ref:`talkback`), they will
186 know how much is queued up so that they can switch back before the replay runs
187 out, but it doesn't hurt to give a warning up-front. The producer might also
188 be able to request replays of specific events, or ask you to save something
189 for later if they can't show it right now (e.g. a foul situation that wasn't called).
190
191 Audio support
192 '''''''''''''
193
194 Futatabi has limited audio support. It is recorded and saved for all inputs,
195 and played back when showing a replay, but only when the replay speed is at
196 100%, or very close to it. (At other speeds, you will get silence.)
197 Furthermore, there is no local audio output; the Futatabi operator will not
198 hear any audio, unless they use a video player into the Futatabi stream locally
199 (with associated delay). All of this may change in the future.
200
201
202 White balance
203 '''''''''''''
204
205 Futatabi integrates with Nageru for white balance;
206 the white balance set in Nageru will be recorded, and properly applied on
207 playback (including fades). Note that this assumes you are using the built-in
208 white balance adjustment, not adding WhiteBalanceEffect manually
209 to the scene; see :ref:`white-balance` for an example.
210
211
212 Replay workflows
213 ----------------
214
215 On top of the basics outlined in :ref:`basicui`, there are many possible
216 workflows; we'll discuss only two. Try out a few and see which ones fit your
217 style and type of event.
218
219 Repeated cue-in
220 '''''''''''''''
221
222 In many sports, you don't necessarily know when a replay-worthy event has happened
223 before it's already happened. However, you may reasonably know when something is
224 *not* happening, and it would be a good time to start a clip if something is happening
225 immediately afterwards. At these points, you can make repeated cue-ins, ie., start
226 a clip without finishing it. As long as you keep making cue-ins, the previous one
227 will be discarded. Once you see that something *is* happening, you can wait until
228 it's done, and then do a cue-out, which gives you a good clip immediately.
229
230 For instance, in a basketball game, you could be seeing a series of uninteresting
231 passes, clicking cue-in on each of them. However, once it looks like there's an
232 opportunity for a score, you can hold and see what happens; if the shot happens,
233 you can click cue-out, and if not, you can go back.
234
235 Before playing the clip, you can make adjustments to the in and out points
236 as detailed above. This will help you trim away any uninteresting lead-ups,
237 or add more margins for fades. If you consistently find that you have too
238 little margin, you can use the *cue point padding* feature (either from the
239 command line using *--cue-in-point-padding* and *--cue-out-point-padding*, or set from the menu). If you set
240 cue in point padding to e.g. two seconds, the cue-in point will automatically be set
241 two seconds ago when you cue-in, and similarly, if you set cue out point padding,
242 the cue-out point will be set two seconds
243 into the future when you cue-out.
244
245
246 Instant clips
247 '''''''''''''
248
249 Like the previous section explained how you generally would know the *start*
250 of an interesting event (at least if discarding most of the candidates),
251 you would be even more sure about the *end* of one. Thus, you can wait
252 until something interesting has happened, and then click cue-in immediately
253 followed by cue-out. This will give you a clip of near zero length, ending
254 at the right point. Then, edit this clip to set the starting point as needed,
255 and it's ready to play.
256
257 Again, you can use the cue point padding feature to your advantage; if so,
258 your clips will not be of zero length, but rather of some predefined length
259 given by your chosen cue point padding.
260
261
262 .. _sampledata:
263
264 Sample multicamera data
265 '''''''''''''''''''''''
266
267 Good multicamera sample video is hard to come by, so it can be hard to
268 test or train before an actual event. To alleviate this, I've uploaded some
269 real-world video from the very first event where an early version of Futatabi
270 was tested. (There are some issues with the JPEG quality, but it should
271 largely be unproblematic.) You are free to use these for training or
272 demonstration purposes. Do note that they will not be displayed entirely
273 correctly in most video players (see :ref:`futatabiformat`), although
274 they will certainly be watchable.
275
276 There are two files:
277
278  * `Trøndisk 2018, final only (MJPEG, 126 GB) <https://storage.sesse.net/trondisk2018-final-multicam-mjpeg.mkv>`_:
279    The final match, in MJPEG format (about 73 minutes). This can be downloaded
280    and then fed directly to Futatabi as if it were a real camera stream
281    (remember the --slow-down-input option).
282  * `Trøndisk 2018, entire tournament (H.264, 74 GB) <https://storage.sesse.net/trondisk2018-multicam-h264.mp4>`_:
283    The entire first part of the tournament,
284    with no cuts (about 12 hours). However, due to space and bandwidth
285    constraints, it has been transcoded to H.264 (with some associated
286    quality loss), and needs to be transcoded to MJPEG before Nageru can use it.
287
288 Both files are mixed-resolution, with some cameras at 1080p59.94 and some
289 at 720p59.94 (one even switches between matches, as the camera was replaced).
290 They contain four different camera angles (overview camera on crane, detail camera
291 in tripod, two fixed endzone overhead cameras) with differing quality depending
292 on the camera operators. In short, they should be realistic input material
293 to practice with.
294
295
296 .. _futatabiformat:
297
298 Internal video format details
299 -----------------------------
300
301 Futatabi expects to get data in MJPEG format only; though MJPEG is old,
302 it yields fairly good quality per bit for an intraframe format, supports
303 4:2:2 without too many issues, and has hardware support through VA-API
304 for both decode (since Ivy Bridge) and encode (since Skylake). The latter
305 is especially important for Futatabi, since there are so many high-resolution
306 streams; software encode/decode of several 1080p60 streams at the same time
307 is fairly taxing on the CPU if done in software. This means we can easily
308 send 4:2:2 camera streams back and forth between Nageru and Futatabi without having
309 to scale or do other lossy processing (except of course the compression itself).
310
311 However, JPEG as such does not have any way of specifying things like color
312 spaces and chroma placement. JFIF, the *de facto* JPEG standard container,
313 specifies conventions that are widely followed, but they do not match what
314 comes out of a capture card. Nageru's multicam export _does_ set the appropriate
315 fields in the output Matroska mux (which is pretty much the only mux that can
316 hold such information), but there are few if any programs that read them and give
317 them priority over JFIF's defaults. Thus, if you want to use the multicam stream
318 for something other than Futatabi, or feed Futatabi with data not from Nageru,
319 there are a few subtle issues to keep in mind.
320
321 In particular:
322
323   * Capture cards typically send limited-range Y'CbCr (luma between 16..235
324     and chroma between 16..240); JFIF is traditionally full-range (0..255
325     for both). (See also :ref:`synthetictests`.) Note that there is a special
326     private JPEG comment added to signal this, which FFmpeg understands.
327   * JFIF, like MPEG, assumes center chroma placement; capture cards and most
328     modern video standards assume left.
329   * JFIF assumes Rec. 601 Y'CbCr coefficients, while all modern HD processing
330     uses Rec. 709 Y'CbCr coefficients. (Futatabi does not care much about
331     the actual RGB color space; Nageru assumes it is Rec. 709, like for capture
332     cards, but the differences between 601 and 709 here are small. sRGB gamma
333     is assumed throughout, like in JFIF.)
334   * The white balance (gray point) is stored in a minimal EXIF header,
335     and echoed back for original and interpolated frames. (During fades, Futatabi
336     applies white balance itself, and does not require gray point adjustment
337     from the client.)
338
339 Many players may also be confused by the fact that the resolution can change
340 from frame to frame; this is because for original (uninterpolated) frames,
341 Futatabi will output the received JPEG frame directly to the output
342 stream, which can be a different resolution from the interpolated frames.
343
344 Also, even though Futatabi exists to make a fixed-framerate stream out of
345 something that's not, the output stream can be variable-framerate (VFR) due to
346 pauses and frame drops. In particular, when the stream is paused, frames are
347 only output about every 100 milliseconds.
348
349 Finally, the subtitle track with status information (see :ref:`talkback`) is
350 not marked as metadata due to FFmpeg limitations, and as such will show up
351 raw in subtitle-enabled players.
352
353
354 .. _midi-futatabi:
355
356 Using MIDI controllers
357 ----------------------
358
359 This section assumes you have already read the section about
360 `MIDI controllers in Nageru <audio.html#midi-controllers>`__. MIDI controllers
361 in Futatabi are fairly similar, but there are also some important differences,
362 since they control replay and not audio:
363
364   * There is no concept of a bus (there is only one video output channel).
365     Thus, the concept of guessing also is obsolete.
366   * Since there are no buses, there are also usually plenty of buttons
367     and controls, rendering the bank concept less useful. It *is* supported,
368     but activity highlights (to show which bank is active) are not.
369   * Finally, outputs (controller lights and button lights) frequently have
370     more than one state depending on the velocity sent, e.g. 1 for on and 2 for
371     blinking. Thus, the Futatabi MIDI mapping editor allows you to change the
372     note velocities from the default 1.
373
374 Futatabi has been tested with the `Behringer CMD PL-1 <https://www.musictribe.com/Categories/Behringer/Computer-Audio/DJ-Controllers/CMD-PL-1/p/P0AJF>`_;
375 it is not originally designed for slow motion (it is a DJ controller), but provides everything you
376 need (a jog wheel, a slider that works as a T bar for master speed, and plenty
377 of buttons) at a fraction of the price of a “real” slow motion remote.
378 A sample MIDI mapping is included with Futatabi.
379
380 Futatabi currently does not support classic RS-422 controllers, only MIDI
381 controllers.
382
383
384 Monitoring
385 ----------
386
387 .. _talkback:
388
389 Tally and status talkback
390 '''''''''''''''''''''''''
391
392 In addition to the verbal communication between the two operators
393 (see :ref:`coop`), it is also useful to have automatic communication
394 between Nageru and Futatabi. This goes both ways.
395
396 First, Futatabi can consume :ref:`Nageru's tally data <tally>` like any camera
397 can; give the correct channel URL to *--tally-url* on the Futatabi command line,
398 and the color around the live view will show up when you are ready or playing
399 (e.g. *--tally-url http://nageru-server.example.org:9096/channels/2*).
400
401 Second, Futatabi can export its current status in two ways. The simplest is
402 through a REST call; the HTTP server that exposes the stream also exposes
403 the endpoint */queue_status* (e.g. http://futatabi-server.example.org:9096/queue_status).
404 This contains the same text as is below the live window, ie., how much time
405 is queued or left.
406
407 The same status is also exported programmatically in the video output from
408 Futatabi, as a subtitle track. This allows the Nageru theme not only to display
409 it if desired, but even to act automatically to switch to a different channel
410 when the playlist is nearing its end. (See :ref:`subtitle-ingest` for information
411 on how to digest such information from the Nageru side.)
412
413 Each subtitle entry is displayed momentarily before the frame it belongs to,
414 and has the following format:
415
416   Futatabi 1.8.2;PLAYING;6.995;0:06.995 left
417
418 The semicolon-separated columns are as follows:
419
420   * The first column is the identifier for the Futatabi version in use; if the format
421     should ever diverge between versions, it can serve as a way to distinguish between
422     them if needed. (The version may also change without the format changing.)
423     For now, however, you can ignore it.
424   * The second column is either PLAYING or PAUSED, depending on the current status.
425   * The third column is how many seconds is queued up (PAUSED) or remaining (PLAYING).
426     It is always in C locale, no matter what the user has set (ie., the decimal point
427     will always be a period). Note that this does not take into account the master
428     speed (see :ref:`speed`).
429   * Finally, the fourth column is a human-readable string, the same as is exposed
430     on the /queue_status endpoint above.
431
432 Prometheus metrics
433 ''''''''''''''''''
434
435 Like Nageru, Futatabi supports a series of Prometheus metrics for monitoring;
436 see :doc:`monitoring` for general information. Futatabi provides entirely different
437 metrics, though, mostly related to performance. There is no predefined Grafana
438 dashboard available at the current time.