Code Monkey home page Code Monkey logo

wagtailvideos's Introduction

wagtailvideos

image

Based on wagtailimages. The aim was to have feature parity with images but for html5 videos. Includes the ability to transcode videos to a html5 compliant codec using ffmpeg.

Requirements

Installing

Install using pypi

pip install wagtailvideos

Using

On a page model:

Implement as a ForeignKey relation, same as wagtailimages.

from django.db import models

from wagtail.admin.edit_handlers import FieldPanel
from wagtail.core.fields import RichTextField
from wagtail.core.models import Page

from wagtailvideos.edit_handlers import VideoChooserPanel


class HomePage(Page):
    body = RichtextField()
    header_video = models.ForeignKey('wagtailvideos.Video',
                                     related_name='+',
                                     null=True,
                                     on_delete=models.SET_NULL)

    content_panels = Page.content_panels + [
        FieldPanel('body'),
        VideoChooserPanel('header_video'),
    ]

In a Streamfield:

A VideoChooserBlock is included

from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtail.core.models import Page

from wagtailvideos.blocks import VideoChooserBlock


class ContentPage(Page):
  body = StreamField([
      ('video', VideoChooserBlock()),
  ])

  content_panels = Page.content_panels + [
      StreamFieldPanel('body'),
  ]

In template:

The video template tag takes one required postitional argument, a video field. All extra attributes are added to the surrounding <video> tag. The original video and all extra transcodes are added as <source> tags.

{% load wagtailvideos_tags %}
{% video self.header_video autoplay controls width=256 %}

Jinja2 extensions are also included.

How to transcode using ffmpeg:

Using the video collection manager from the left hand menu. In the video editing section you can see the available transcodes and a form that can be used to create new transcodes. It is assumed that your compiled version of ffmpeg has the matching codec libraries required for the transcode.

Custom Video models:

Same as Wagtail Images, a custom model can be used to replace the built in Video model using the WAGTAILVIDEOS_VIDEO_MODEL setting.

# settings.py
WAGTAILVIDEOS_VIDEO_MODEL = 'videos.AttributedVideo'

# app.videos.models
from django.db import models
from modelcluster.fields import ParentalKey
from wagtailvideos.models import AbstractVideo, AbstractVideoTranscode

class AttributedVideo(AbstractVideo):
    attribution = models.TextField()

    admin_form_fields = (
        'title',
        'attribution',
        'file',
        'collection',
        'thumbnail',
        'tags',
    )

class CustomTranscode(AbstractVideoTranscode):
    video = models.ForeignKey(AttributedVideo, related_name='transcodes', on_delete=models.CASCADE)

    class Meta:
        unique_together = (
            ('video', 'media_format')
        )

# Only needed if you are using the text tracks feature
class CustomTrackListing(AbstractTrackListing):
    video = models.OneToOneField(AttributedVideo, related_name='track_listing', on_delete=models.CASCADE)

class CustomVideoTrack(AbstractVideoTrack):
    listing = ParentalKey(CustomTrackListing, related_name='tracks', on_delete=models.CASCADE)

Video text tracks:

To enable the uploading and displaying of VTT tracks (e.g. subtitles, captions) you'll need to add wagtail.contrib.modeladmin to your installed apps. Once added, there will be an new area in the admin for attaching VTT files to videos with associaled metadata.

Future features

  • Some docs
  • Richtext embed
  • Transcoding via amazon service rather than ffmpeg

wagtailvideos's People

Contributors

seb-b avatar liambrenner avatar mx-moth avatar jkevingutierrez avatar jdavid avatar nickyspag avatar kcidau avatar delph avatar dirkmoors avatar buczek avatar skeletorxvi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.