]> git.sesse.net Git - nageru-docs/blob - futatabi.rst
Document the /dev/null special case.
[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://path.to.nageru.host/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` 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 .. _coop:
119
120 Working with your producer
121 ''''''''''''''''''''''''''
122
123 Generally, we recommend that the producer (Nageru operator) and slow motion
124 operator (Futatabi operator) sit closely together and can communicate verbally.
125 Good cooperation between the two is essential to get a good final product;
126 especially the switches to and from the replays can be a critical point.
127
128 The general rule for working together is fairly obvious: The producer should
129 switch to a replay when there's something to show, and switch away when there's
130 nothing more to show (or, less ideally, when something live takes priority).
131 Generally, when you have a playlist ready, inform your producer; they will
132 count you in (three, two, one, go). At one, start playing so that you have some
133 margin. If the Nageru theme is set up correctly (see :ref:`talkback`), they will
134 know how much is queued up so that they can switch back before the replay runs
135 out, but it doesn't hurt to give a warning up-front. The producer might also
136 be able to request replays of specific events, or ask you to save something
137 for later if they can't show it right now (e.g. a foul situation that wasn't called).
138
139 Replay workflows
140 ----------------
141
142 On top of the basics outlined in :ref:`basicui`, there are many possible
143 workflows; we'll discuss only two. Try out a few and see which ones fit your
144 style and type of event.
145
146 Repeated cue-in
147 '''''''''''''''
148
149 In many sports, you don't necessarily know when a replay-worthy event has happened
150 before it's already happened. However, you may reasonably know when something is
151 *not* happening, and it would be a good time to start a clip if something is happening
152 immediately afterwards. At these points, you can make repeated cue-ins, ie., start
153 a clip without finishing it. As long as you keep making cue-ins, the previous one
154 will be discarded. Once you see that something *is* happening, you can wait until
155 it's done, and then do a cue-out, which gives you a good clip immediately.
156
157 For instance, in a basketball game, you could be seeing a series of uninteresting
158 passes, clicking cue-in on each of them. However, once it looks like there's an
159 opportunity for a score, you can hold and see what happens; if the shot happens,
160 you can click cue-out, and if not, you can go back.
161
162 Before playing the clip, you can make adjustments to the in and out points
163 as detailed above. This will help you trim away any uninteresting lead-ups,
164 or add more margins for fades. If you consistently find that you have too
165 little margin, you can use the *cue point padding* feature (either from the
166 command line using *--cue-point-padding*, or set from the menu). If you set
167 cue point padding to e.g. two seconds, the cue-in point will automatically be set
168 two seconds ago when you cue-in, and the cue-out point will be set two seconds
169 into the future when you cue-out.
170
171
172 Instant clips
173 '''''''''''''
174
175 Like the previous section explained how you generally would know the *start*
176 of an interesting event (at least if discarding most of the candidates),
177 you would be even more sure about the *end* of one. Thus, you can simply wait
178 until something interesting has happened, and then click cue-in immediately
179 followed by cue-out. This will give you a clip of near zero length, ending
180 at the right point. Then, edit this clip to set the starting point as needed,
181 and it's ready to play.
182
183 Again, you can use the cue point padding feature to your advantage; if so,
184 your clips will not be of zero length, but rather of some predefined length
185 given by your chosen cue point padding.
186
187
188 .. _sampledata:
189
190 Sample multicamera data
191 '''''''''''''''''''''''
192
193 Good multicamera sample video is hard to come by, so it can be hard to
194 test or train before an actual event. To alleviate this, I've uploaded some
195 real-world video from the very first event where an early version of Futatabi
196 was tested. (There are some issues with the JPEG quality, but it should
197 largely be unproblematic.) You are free to use these for training or
198 demonstration purposes. Do note that they will not be displayed entirely
199 correctly in most video players (see :ref:`futatabiformat`), although
200 they will certainly be watchable.
201
202 There are two files:
203
204  * `Trøndisk 2018, finals only (MJPEG, 77 GB) <https://storage.sesse.net/trondisk2018-finals-multicam-mjpeg.mkv>`_:
205    The final match, in MJPEG format (about 30 minutes). This can be downloaded
206    and then fed directly to Nageru as if it were a real camera stream
207    (remember the --slow-down-input option).
208  * `Trøndisk 2018, entire tournament (H.264, 74 GB) <https://storage.sesse.net/trondisk2018-multicam-h264.mp4>`_: The entire tournament,
209    with no cuts (about 12 hours). However, due to space and bandwidth
210    constraints, it has been transcoded to H.264 (with some associated
211    quality loss), and needs to be transcoded to MJPEG before Nageru can use it.
212
213 Both files are mixed-resolution, with some cameras at 1080p59.94 and some
214 at 720p59.94 (one even switches between matches, as the camera was replaced).
215 They contain four different camera angles (overview camera on crane, detail camera
216 in tripod, two fixed endzone overhead cameras) with differing quality depending
217 on the camera operators. In short, they should be realistic input material
218 to practice with.
219
220
221 Transferring data to and from Nageru
222 ------------------------------------
223
224 .. _futatabiformat:
225
226 Video format specification
227 ''''''''''''''''''''''''''
228
229 Futatabi expects to get data in MJPEG format only; though MJPEG is old,
230 it yields fairly good quality per bit for an intraframe format, supports
231 4:2:2 without too many issues, and has hardware support through VA-API
232 for both decode (since Ivy Bridge) and encode (since Skylake). The latter
233 is especially important for Futatabi, since there are so many high-resolution
234 streams; software encode/decode of several 1080p60 streams at the same time
235 is fairly taxing on the CPU if done in software. This means we can easily
236 send 4:2:2 camera streams back and forth between Nageru and Futatabi without having
237 to scale or do other lossy processing (except of course the compression itself).
238
239 However, JPEG as such does not have any way of specifying things like color
240 spaces and chroma placement. JFIF, the *de facto* JPEG standard container,
241 specifies conventions that are widely followed, but they do not match what
242 comes out of a capture card. Nageru's multicam export _does_ set the appropriate
243 fields in the output Matroska mux (which is pretty much the only mux that can
244 hold such information), but there are few if any programs that read them and give
245 them priority over JFIF's defaults. Thus, if you want to use the multicam stream
246 for something other than Futatabi, or feed Futatabi with data not from Nageru,
247 there are a few subtle issues to keep in mind.
248
249 In particular:
250
251   * Capture cards typically send limited-range Y'CbCr (luma between 16..235
252     and chroma between 16..240); JFIF is traditionally full-range (0..255
253     for both). (See also :ref:`synthetictests`.) Note that there is a special
254     private JPEG comment added to signal this, which FFmpeg understands.
255   * JFIF, like MPEG, assumes center chroma placement; capture cards and most
256     modern video standards assume left.
257   * JFIF assumes Rec. 601 Y'CbCr coefficients, while all modern HD processing
258     uses Rec. 709 Y'CbCr coefficients. (Futatabi does not care much about
259     the actual RGB color space; Nageru assumes it is Rec. 709, like for capture
260     cards, but the differences between 601 and 709 here are small. sRGB gamma
261     is assumed throughout, like in JFIF.)
262
263 Many players may also be confused by the fact that the resolution can change
264 from frame to frame; this is because for original (uninterpolated) frames,
265 Futatabi will simply output the received JPEG frame directly to the output
266 stream, which can be a different resolution from the interpolated frames.
267
268 Finally, the subtitle track with status information (see :ref:`talkback`) is
269 not marked as metadata due to FFmpeg limitations, and as such will show up
270 raw in subtitle-enabled players.
271
272
273 .. _midi:
274
275 Using MIDI controllers
276 ----------------------
277
278
279 Monitoring
280 ----------
281
282 .. _talkback:
283
284 Tally and status talkback
285 '''''''''''''''''''''''''
286
287 Prometheus metrics
288 ''''''''''''''''''