]> git.sesse.net Git - nageru-docs/blob - futatabi.rst
Document the split cue point padding in 1.8.3.
[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. Thus, the first version of Futatabi is version 1.8.0,
29 which is the Nageru version when it was first introduced.
30
31
32 System requirements
33 -------------------
34
35 It is strongly recommended to run Futatabi on a separate machine from Nageru,
36 not the least because you probably want a different person to operate the replay
37 while the producer is operating Nageru. (See :ref:`coop`.)
38
39 Like Nageru, Futatabi uses your GPU for nearly all image processing.
40 However, unlike Nageru, Futatabi requires a powerful GPU for interpolation;
41 a GTX 1080 or similar is recommended for interpolated 720p60. (Futatabi
42 was initially developed on a GTX 950, which is passable, but has little
43 performance margin.) If you have a slower GPU and are happy with worse
44 quality, or just wish to test, you can use a faster preset, or turn off
45 interpolation entirely. Futatabi requires OpenGL 4.5 or newer.
46
47 For other required libraries, see :ref:`compile`; when you build Nageru,
48 you also build Futatabi.
49
50
51 Getting started
52 ---------------
53
54 Futatabi always pulls data from Nageru over the network; it doesn't support SDI
55 input or output. Assuming you have a recent version of Nageru (typically one
56 that comes with Futatabi), it is capable of sending all of its cameras as one
57 video stream (see :ref:`futatabiformat`), so you can start Futatabi with
58
59   ./futatabi http://nageru-server.example.org/multicam.mp4
60
61 If you do not have a running Nageru installation, see :ref:`sampledata`.
62
63 Once you are up and connected, Futatabi will start recording all of the frames
64 to disk. This process happens continuously for as long as you have disk space,
65 even if you are playing something back or editing clips, and the streams are
66 displayed in real time in mini-display as they come in. You make replays in
67 the form of *clips* (the top list is the clip list), which are then queued into
68 the *playlist* (the bottom list). Your end result is a live HTTP stream that
69 can be fed back into Nageru as a video input; by default, Futatabi listens
70 on port 9096.
71
72 Futatabi has the concept of a *workspace*, which defaults to your current
73 directory (you can change it with the -d option). This holds all of the
74 recorded frames, all metadata about clips, and preferences set from the menus
75 (interpolation quality and cue point padding).  If you quit Futatabi and
76 restart it (or you go down as the result of a power failure or the likes),
77 it will remember all the state and frames for you. As a special case,
78 if you give */dev/null* in place of an input URL or file, you can keep using
79 your workspace without getting any new frames added.
80
81 .. _basicui:
82
83 Basic UI operations
84 '''''''''''''''''''
85
86 Nageru can be operated using either the keyboard and mouse, or using a MIDI
87 controller with some help of the mouse. In this section, we will be discussing
88 the keyboard and mouse only; see :ref:`midi-futatabi` for details on using MIDI
89 controllers.
90
91 A clip in the clip list consists simply of an in and an out point; it represents
92 an interval of physical time (although timed to the video clock). A clip in the
93 playlist contains the same information plus some playback parameters, in particular
94 which camera (stream) to play back.
95
96 Clicking the ”Cue in” button, or pressing the A key, will start a new clip in
97 the clip list that begins at the current time. Similarly, clicking the ”Cue
98 out” button, or pressing the S key, will set the end point for said clip.
99 (If you click a button twice, it will overwrite the previous result.)
100 Now it is in a state where you can queue it to the play list (mark the camera
101 you want to use and click the “Queue” button, or Q on the keyboard) 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 .. _coop:
124
125 Working with your producer
126 ''''''''''''''''''''''''''
127
128 Generally, we recommend that the producer (Nageru operator) and slow motion
129 operator (Futatabi operator) sit closely together and can communicate verbally.
130 Good cooperation between the two is essential to get a good final product;
131 especially the switches to and from the replays can be a critical point.
132
133 The general rule for working together is fairly obvious: The producer should
134 switch to a replay when there's something to show, and switch away when there's
135 nothing more to show (or, less ideally, when something live takes priority).
136 Generally, when you have a playlist ready, inform your producer; they will
137 count you in (three, two, one, go). At one, start playing so that you have some
138 margin. If the Nageru theme is set up correctly (see :ref:`talkback`), they will
139 know how much is queued up so that they can switch back before the replay runs
140 out, but it doesn't hurt to give a warning up-front. The producer might also
141 be able to request replays of specific events, or ask you to save something
142 for later if they can't show it right now (e.g. a foul situation that wasn't called).
143
144 Replay workflows
145 ----------------
146
147 On top of the basics outlined in :ref:`basicui`, there are many possible
148 workflows; we'll discuss only two. Try out a few and see which ones fit your
149 style and type of event.
150
151 Repeated cue-in
152 '''''''''''''''
153
154 In many sports, you don't necessarily know when a replay-worthy event has happened
155 before it's already happened. However, you may reasonably know when something is
156 *not* happening, and it would be a good time to start a clip if something is happening
157 immediately afterwards. At these points, you can make repeated cue-ins, ie., start
158 a clip without finishing it. As long as you keep making cue-ins, the previous one
159 will be discarded. Once you see that something *is* happening, you can wait until
160 it's done, and then do a cue-out, which gives you a good clip immediately.
161
162 For instance, in a basketball game, you could be seeing a series of uninteresting
163 passes, clicking cue-in on each of them. However, once it looks like there's an
164 opportunity for a score, you can hold and see what happens; if the shot happens,
165 you can click cue-out, and if not, you can go back.
166
167 Before playing the clip, you can make adjustments to the in and out points
168 as detailed above. This will help you trim away any uninteresting lead-ups,
169 or add more margins for fades. If you consistently find that you have too
170 little margin, you can use the *cue point padding* feature (either from the
171 command line using *--cue-in-point-padding* and *--cue-out-point-padding*, or set from the menu). If you set
172 cue in point padding to e.g. two seconds, the cue-in point will automatically be set
173 two seconds ago when you cue-in, and similarly, if you set cue out point padding,
174 the cue-out point will be set two seconds
175 into the future when you cue-out. (Cue-in and cue-out point padding were one
176 joint setting before Futatabi 1.8.3.)
177
178
179 Instant clips
180 '''''''''''''
181
182 Like the previous section explained how you generally would know the *start*
183 of an interesting event (at least if discarding most of the candidates),
184 you would be even more sure about the *end* of one. Thus, you can simply wait
185 until something interesting has happened, and then click cue-in immediately
186 followed by cue-out. This will give you a clip of near zero length, ending
187 at the right point. Then, edit this clip to set the starting point as needed,
188 and it's ready to play.
189
190 Again, you can use the cue point padding feature to your advantage; if so,
191 your clips will not be of zero length, but rather of some predefined length
192 given by your chosen cue point padding.
193
194
195 .. _sampledata:
196
197 Sample multicamera data
198 '''''''''''''''''''''''
199
200 Good multicamera sample video is hard to come by, so it can be hard to
201 test or train before an actual event. To alleviate this, I've uploaded some
202 real-world video from the very first event where an early version of Futatabi
203 was tested. (There are some issues with the JPEG quality, but it should
204 largely be unproblematic.) You are free to use these for training or
205 demonstration purposes. Do note that they will not be displayed entirely
206 correctly in most video players (see :ref:`futatabiformat`), although
207 they will certainly be watchable.
208
209 There are two files:
210
211  * `Trøndisk 2018, finals only (MJPEG, 77 GB) <https://storage.sesse.net/trondisk2018-finals-multicam-mjpeg.mkv>`_:
212    The final match, in MJPEG format (about 30 minutes). This can be downloaded
213    and then fed directly to Nageru as if it were a real camera stream
214    (remember the --slow-down-input option).
215  * `Trøndisk 2018, entire tournament (H.264, 74 GB) <https://storage.sesse.net/trondisk2018-multicam-h264.mp4>`_: The entire tournament,
216    with no cuts (about 12 hours). However, due to space and bandwidth
217    constraints, it has been transcoded to H.264 (with some associated
218    quality loss), and needs to be transcoded to MJPEG before Nageru can use it.
219
220 Both files are mixed-resolution, with some cameras at 1080p59.94 and some
221 at 720p59.94 (one even switches between matches, as the camera was replaced).
222 They contain four different camera angles (overview camera on crane, detail camera
223 in tripod, two fixed endzone overhead cameras) with differing quality depending
224 on the camera operators. In short, they should be realistic input material
225 to practice with.
226
227
228 Transferring data to and from Nageru
229 ------------------------------------
230
231 .. _futatabiformat:
232
233 Video format specification
234 ''''''''''''''''''''''''''
235
236 Futatabi expects to get data in MJPEG format only; though MJPEG is old,
237 it yields fairly good quality per bit for an intraframe format, supports
238 4:2:2 without too many issues, and has hardware support through VA-API
239 for both decode (since Ivy Bridge) and encode (since Skylake). The latter
240 is especially important for Futatabi, since there are so many high-resolution
241 streams; software encode/decode of several 1080p60 streams at the same time
242 is fairly taxing on the CPU if done in software. This means we can easily
243 send 4:2:2 camera streams back and forth between Nageru and Futatabi without having
244 to scale or do other lossy processing (except of course the compression itself).
245
246 However, JPEG as such does not have any way of specifying things like color
247 spaces and chroma placement. JFIF, the *de facto* JPEG standard container,
248 specifies conventions that are widely followed, but they do not match what
249 comes out of a capture card. Nageru's multicam export _does_ set the appropriate
250 fields in the output Matroska mux (which is pretty much the only mux that can
251 hold such information), but there are few if any programs that read them and give
252 them priority over JFIF's defaults. Thus, if you want to use the multicam stream
253 for something other than Futatabi, or feed Futatabi with data not from Nageru,
254 there are a few subtle issues to keep in mind.
255
256 In particular:
257
258   * Capture cards typically send limited-range Y'CbCr (luma between 16..235
259     and chroma between 16..240); JFIF is traditionally full-range (0..255
260     for both). (See also :ref:`synthetictests`.) Note that there is a special
261     private JPEG comment added to signal this, which FFmpeg understands.
262   * JFIF, like MPEG, assumes center chroma placement; capture cards and most
263     modern video standards assume left.
264   * JFIF assumes Rec. 601 Y'CbCr coefficients, while all modern HD processing
265     uses Rec. 709 Y'CbCr coefficients. (Futatabi does not care much about
266     the actual RGB color space; Nageru assumes it is Rec. 709, like for capture
267     cards, but the differences between 601 and 709 here are small. sRGB gamma
268     is assumed throughout, like in JFIF.)
269
270 Many players may also be confused by the fact that the resolution can change
271 from frame to frame; this is because for original (uninterpolated) frames,
272 Futatabi will simply output the received JPEG frame directly to the output
273 stream, which can be a different resolution from the interpolated frames.
274
275 Also, even though Futatabi exists to make a fixed-framerate stream out of
276 something that's not, the output stream can be variable-framerate (VFR) due to
277 pauses and frame drops. In particular, when the stream is paused, frames are
278 only output about every 100 milliseconds.
279
280 Finally, the subtitle track with status information (see :ref:`talkback`) is
281 not marked as metadata due to FFmpeg limitations, and as such will show up
282 raw in subtitle-enabled players.
283
284
285 .. _midi-futatabi:
286
287 Using MIDI controllers
288 ----------------------
289
290 This section assumes you have already read the section about
291 `MIDI controllers in Nageru <audio.html#midi-controllers>`__. MIDI controllers
292 in Futatabi are fairly similar, but there are also some important differences,
293 since they control replay and not audio:
294
295   * There is no concept of a bus (there is only one video output channel).
296     Thus, the concept of guessing also is obsolete.
297   * Since there are no buses, there are also usually plenty of buttons
298     and controls, rendering the bank concept less useful. It *is* supported,
299     but activity highlights (to show which bank is active) are not.
300   * Finally, outputs (controller lights and button lights) frequently have
301     more than one state depending on the velocity sent, e.g. 1 for on and 2 for
302     blinking. Thus, the Futatabi MIDI mapping editor allows you to change the
303     note velocities from the default 1.
304
305 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>`_;
306 it is not originally designed for slow motion (it is a DJ controller), but provides everything you
307 need (a jog wheel, a slider that works as a T bar for master speed, and plenty
308 of buttons) at a fraction of the price of a “real” slow motion remote.
309 A sample MIDI mapping is included with Futatabi.
310
311 Futatabi currently does not support classic RS-422 controllers, only MIDI
312 controllers.
313
314
315 Monitoring
316 ----------
317
318 .. _talkback:
319
320 Tally and status talkback
321 '''''''''''''''''''''''''
322
323 In addition to the verbal communication between the two operators
324 (see :ref:`coop`), it is also useful to have automatic communication
325 between Nageru and Futatabi. This goes both ways.
326
327 First, Futatabi can consume :ref:`Nageru's tally data <tally>` like any camera
328 can; give the correct channel URL to *--tally-url* on the Futatabi command line,
329 and the color around the live view will show up when you are ready or playing
330 (e.g. *--tally-url http://nageru-server.example.org:9096/channels/2*).
331
332 Second, Futatabi can export its current status in two ways. The simplest is
333 through a REST call; the HTTP server that exposes the stream also exposes
334 the endpoint */queue_status* (e.g. http://futatabi-server.example.org:9096/queue_status).
335 This contains the same text as is below the live window, ie., how much time
336 is queued or left.
337
338 The same status is also exported programmatically in the video output from
339 Futatabi, as a subtitle track. This allows the Nageru theme not only to display
340 it if desired, but even to act automatically to switch to a different channel
341 when the playlist is nearing its end. (See :ref:`subtitle-ingest` for information
342 on how to digest such information from the Nageru side.)
343
344 Each subtitle entry is displayed momentarily before the frame it belongs to,
345 and has the following format:
346
347   Futatabi 1.8.2;PLAYING;6.995;0:06.995 left
348
349 The semicolon-separated columns are as follows:
350
351   * The first column is the identifier for the Futatabi version in use; if the format
352     should ever diverge between versions, it can serve as a way to distinguish between
353     them if needed. (The version may also change without the format changing.)
354     For now, however, you can ignore it.
355   * The second column is either PLAYING or PAUSED, depending on the current status.
356   * The third column is how many seconds is queued up (PAUSED) or remaining (PLAYING).
357     It is always in C locale, no matter what the user has set (ie., the decimal point
358     will always be a period). Note that this does not take into account the master
359     speed (see :ref:`speed`).
360   * Finally, the fourth column is a human-readable string, the same as is exposed
361     on the /queue_status endpoint above.
362
363 Prometheus metrics
364 ''''''''''''''''''
365
366 Like Nageru, Futatabi supports a series of Prometheus metrics for monitoring;
367 see :doc:`monitoring` for general information. Futatabi provides entirely different
368 metrics, though, mostly related to performance. There is no predefined Grafana
369 dashboard available at the current time.