mod_video
Adds support for viewing and handling video medium items.
This module converts uploaded videos to h264 and adds a poster (preview) image of the movie.
Note
mod_video uses the command-line utilities ffmpeg and ffprobe. For mod_video to function correctly they must be
present in the search path of Zotonic.
Uploading & conversion
The video module hooks into the media model to intercept any video upload. If a video is uploaded the following steps are done:
- The original video is stored in CAFS and pinned by its persistent conversion task.
- A video conversion task is added to the pivot task queue, this task will restart a video conversion in case of any problems.
- A video conversion process is started, supervised by the video module.
- The uploaded medium is replaced by a static
lib/images/processing.pngimage.
The worker obtains a temporary local input from CAFS, including when the original
has been moved to remote storage. Completion or cancellation releases the source
pin. Existing tasks using files/video_queue/ remain supported.
Only a single video conversion process is allowed to run at any time. This to prevent overloading the server.
After the video is converted the resource’s medium record is replaced with the converted video. The frame at 10 seconds (at 1 second for movies shorter than 30 seconds) is added as the preview image of the video.
Validated terminal conversion failures replace the medium with lib/images/broken.png.
Temporary runner failures retain the task and original (including legacy queue files),
retrying with exponential backoff from 30 seconds to one hour, plus up to ten seconds
of jitter. After 24 hours of failed automatic retries the task pauses. Invalid
credentials, configuration, integrity errors and unclassified failures pause immediately.
A failed medium commit also retains its input. Paused tasks reconcile hourly so a
replaced or deleted medium releases its retained source.
Retry metadata is stored in the pivot task's {convert_v4, OriginalTask, RetryMap}
argument. It records attempts, started, last_reason, next_attempt and paused.
Administrators can resume a stored task with mod_video:retry_task(Task, Context).
Retry preserves the processing identity and the expected-medium check; it cannot
overwrite a newer upload. These retry policy values are fixed defaults, not site
configuration keys.
Viewing
The video module extends the {% media %} tag for viewing video/mp4 videos.
It uses the template _video_viewer.tpl for viewing. For the best viewing results, add css/video.css to your included
css files.
Accepted Events
This module handles the following notifier callbacks:
observe_media_stillimage: Return the filename of a still image to be used for image tags usingsupervisor:start_link.observe_media_upload_preprocess: If a video file is uploaded, queue it for conversion to video/mp4 usingz_video_info:info.observe_media_upload_props: After a video file is processed, generate a preview image usingz_media_archive:abspath.observe_media_viewer: Return the media viewer for the mp4 video usingz_template:render.