<p>Just like <ahref="../imageops/">images</a>, videos are separate files that are embedded into HTML files. Since they are media files, it's often desirable to read metadata or manipulate them in some way.</p>
<divclass="admonition admonition-info"><p>Video metadata access is powered by <ahref="https://ffmpeg.org/">FFmpeg</a>. In order to use it FFmpeg must be installed on your system and detected by Lektor. If Lektor is unable to find FFmpeg you will see the error message <code>Unable to locate ffmpeg or ffprobe executable. Is it installed?</code> in your console output if you try to use functionality that requires it.</p></div><h2id="accessing-videos">Accessing videos</h2><divclass="hll"><pre><span></span><spanclass="cp">{%</span><spanclass="k">for</span><spanclass="nv">video</span><spanclass="k">in</span><spanclass="nv">this.attachments.videos</span><spanclass="cp">%}</span>
<p>Just like images you can also access them using <code>site.get('/myfolder').attachments.videos</code> or <code>site.get('/myfolder').attachments.get('examplevideo.mp4')</code>. Note that not all formats are detected as videos (see <ahref="../../content/attachments/">attachments</a>). If your format is not in the list you may still be able to get it detected as a video by adding it to your <ahref="../../project/file/#attachment-types">Lektor project file</a>.</p>
<h2id="generating-thumbnails">Generating thumbnails</h2><p>The main difference between video and image attachments is how thumbnails are handled. Since a video basically is a long sequence of images you must first choose where in the video the thumbnail should be generated. This is done using the `.frame() method. There are multiple ways of calling it:</p>
<table>
<thead><tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>frame()</code></td>
<td>Use a frame from the middle of the video <em>(default)</em></td>
</tr>
<tr>
<td><code>frame(seek: float)</code></td>
<td>Fraction between 0.0 and 1.0 of the video duration from where to extract the frame. The value <code>0.5</code> means that the middle of the video will be used. It can be seen as a shorthand for <code>video.frame(video.duration * seek)</code>.</td>
<td>Use a frame at the given seek distance from the beginning of the video. This is useful when you want to seek a fix time into a video.</td>
</tr>
</tbody>
</table>
<p>Calling this method will return a <code>VideoFrame</code> instance, which is not usable by itself. It does however just like an image have a thumbnail method.</p>
<spanclass="p"><</span><spanclass="nt">img</span><spanclass="na">src</span><spanclass="o">=</span><spanclass="s">"</span><spanclass="cp">{{</span><spanclass="nv">video.frame</span><spanclass="o">()|</span><spanclass="nf">url</span><spanclass="cp">}}</span><spanclass="s">"</span><spanclass="p">></span><spanclass="cm"><!-- This is not valid --></span>
Please enable JavaScript to view the <ahref="https://disqus.com/?ref_noscript"
rel="nofollow">comments powered by Disqus.</a>
</noscript>
</div>
</div>
</div>
</div>
</div>
<divclass="bottomsummary">
<divclass="container">
</div>
</div>
<footer>
<divclass="container">
<divclass="row">
<divclass="col-sm-4 icon-bar">
<ahref="https://github.com/lektor/lektor/"title="Lektor on GitHub"
><iclass="fa fa-github"></i></a>
<ahref="https://github.com/lektor/lektor/issues/"title="Report Issues for Lektor"
><iclass="fa fa-bug"></i></a>
<ahref="https://twitter.com/getlektor"title="Find Lektor on Twitter"
><iclass="fa fa-twitter"></i></a>
<ahref="https://gitter.im/lektor/lektor"title="Chat on Gitter"
><iclass="fa fa-comment"></i></a>
<ahref="https://github.com/lektor/lektor-website/tree/master/content/docs/templates/videoops/contents.lr"title="View source for this page"><iclass="fa fa-code"></i></a>