]> git.sesse.net Git - nageru-docs/blob - video.rst
Write about controlling video playback.
[nageru-docs] / video.rst
1 Video inputs
2 ============
3
4 This section deals with video inputs from other sources than regular
5 capture cards (which are typically known as “live inputs”, although
6 they also carry video). The most obvious example would be a video file on disk
7 (say, to play in a loop during pauses), but video inputs are quite
8 flexible and can be used also for other things.
9
10 Before reading trying to use video inputs, you should read and understand how
11 themes work in general (see :doc:`theme`). Video inputs are available from
12 Nageru 1.6.0 onwards. There is currently no support for audio from video inputs;
13 all videos are silent. (This may change in the future.) If a file contains
14 multiple video streams, like different angles or resolutions, only the first
15 will be used.
16
17
18 Basic video inputs
19 ------------------
20
21 Adding video to an existing chain happens in two phases; first, the video
22 must be *loaded*, giving it an identifier, and then that video can be used
23 as inputs in a chain, much like :ref:`images <images>` or regular live inputs.
24 Anything FFmpeg accepts, including network streams, can be used (probably even
25 V4L input cards, although this is untested).
26
27 When loading a video, you need to decide what format to use; Y'CbCr or BGRA.
28 (Whatever you choose, if you get a mismatch with what the video actually is in,
29 FFmpeg will convert it on the CPU with no warning.) Most video is Y'CbCr,
30 so this should be your default unless you know the video is encoded as RGB/BGR,
31 and/or it has an alpha channel you want to use. Getting the format right makes
32 for better efficiency; you not only save a conversion step on the CPU, but
33 sometimes also on the GPU.
34
35 Videos are loaded like this::
36
37   local video = VideoInput.new("filename.mp4", Nageru.VIDEO_FORMAT_YCBCR)
38
39 or, for a network stream, perhaps::
40
41   local video = VideoInput.new("http://localhost/file.nut", Nageru.VIDEO_FORMAT_BGRA)
42
43 It can then be added to any chain like this::
44
45   local input = chain:add_video_input(video, false)
46
47 The second parameter specifies no deinterlacing. Note that interlaced video
48 is currently not supported, not even with deinterlacing, so this parameter
49 must always be false.
50
51 You can use the same video object to create many different video inputs::
52   
53   local input1 = chain1:add_video_input(video, false)
54   local input2 = chain2:add_video_input(video, false)
55
56 Videos run in the correct frame rate and on their own timer (generally the
57 system clock in the computer), and loop when they get to the end or whenever an
58 error occurs. If a video is changed while you're running Nageru, it will be
59 reloaded (just like images) when it's at its end—but be aware, unless you're
60 moving the new file atomically into place, you could end up corrupting the file
61 Nageru is playing from, causing it to automatically rewind before the end of
62 the segment.
63
64 Videos are assigned an arbitrary signal number when loaded. Whenever you need
65 to refer to this signal number (say, to get its width or height for display),
66 you should use *video:get_signal_num()*. Like any other signal, videos have
67 a width and height, an interlaced flag (currently always false), a frame rate
68 (which can vary during playback) and has_signal/is_connected member functions.
69 The former is always true, but the former will be false if the video isn't
70 currently playing for whatever reason (e.g., the file is corrupted, or a network
71 stream is broken and hasn't reconnected yet).
72
73
74 Controlling video playback
75 --------------------------
76
77 Themes have some programmatic control over video playback. In particular,
78 if you want to make a video start from the beginning, you can do::
79
80   video:rewind()
81
82 which will instantly make it start from the first frame again. This can be
83 useful if you e.g. want the video to start when you're switching to it,
84 or if you're not really using it to loop (e.g. as a transition marker).
85
86 You can also change its rate, e.g. by::
87
88   video:change_rate(2.0)
89
90 This will make it play at twice its usual speed. Your rate should not be
91 negative nor exactly zero. Be aware that once you've set a rate, the player
92 will wait for the next frame before considering any other commands,
93 so if you set your rate to e.g. 0.001 to nearly stop it, you will indeed
94 need to wait 16.67 seconds (assuming 60 fps video) before you can speed it
95 up again. This restriction may be lifted in the future.
96
97
98 Integration with CasparCG
99 -------------------------
100
101 TODO