Code Monkey home page Code Monkey logo

go-video-transcoder's Introduction

Go Video Transcoder - Govitra

Provides a simple API for uploading videos to be transcoded.

Note: This does not actually implement the serving part. You need some other server, for example Nginx, to serve the uploaded content.

API

The API is very simple and has only two endpoints, one for uploading and one for deleting.

Uploading

POST /uploads with raw video data in body. You can also trim videos by passing the query parameters end and start, to crop off length from the video beginning and end, respectively. Both the timestamps should be specified in milliseconds.

{
    "video": "$host/$id.mp4",
    "thumbnail": "$host/$id.jpg",
    "deleteUrl": "$self/uploads/$id"
}

or

{ "error": "Human readable error description" }

Deleting

DELETE /uploads/$id

These URLs should not be made by hand as the ID is not a real thing, but the URL can be retrieved from the upload JSON response deleteUrl You should pass the header 'Delete-Authorization' with the correct shared token between achrails and govitra to authenticate the deletion request!

Returns 204 No Content or

{ "error": "Human readable error description" }

Production setup

Dependencies

Environment variables

Govitra itself requires some amount of configuration to run, this is provided as environment variables. It also requires a server to serve the actual video files, or AWS credentials. Note: You forbid the server from serving .owner files as they are used to store who uploaded the video.

  • Common:
    • GOTR_TEMP_PATH: Path to download and process videos in
    • GOTR_SERVE_PATH: Path to copy transcoded videos. Needs to be in the same mount as GOTR_TEMP_PATH since the processed videos are renamed to here when done.
    • GOTR_STORAGE_URL_PATH: Base path appeneded to GOTR_URI or LAYERS_API_URI that serves files from GOTR_SERVE_PATH
    • GOTR_API_URL_PATH: Base path appended to GOTR_UR or LAYERS_API_URI that is used for the API calls
    • GOTR_DELETE_SECRET: The key used to authenticate delete requests
  • Amazon AWS S3:
    • USE_AWS: Whether to enable AWS or not
    • AWS_BUCKET_NAME: The name of your bucket
    • AWS_BUCKET_REGION: The region your S3 bucket is located at
    • AWS_ACCESS_KEY_ID: The secret id for your app
    • AWS_SECRET_ACCESS_KEY: The secret key for your AWS
  • Layers Box:
    • LAYERS_API_URI: URL of the box (should be predefined by Layers Box)
    • AUTH_URL_PATH: Path appended to LAYERS_API_URI for the authentication /userinfo endpoint
  • Standalone:

Usage with AWS S3

If instead of serving videos and thumbnails locally you'd prefer to use AWS S3, simply set the following environment variables

    USE_AWS=1
    AWS_BUCKET_NAME=<YOUR S3 BUCKET NAME HERE>
    AWS_BUCKET_REGION=<YOUR S3 REGION HERE>
    AWS_ACCESS_KEY_ID=<YOUR AWS ACCESS KEY HERE>
    AWS_SECRET_ACCESS_KEY=<YOUR AWS SECRET KEY HERE>

If you choose to host files on S3, anything related to .owner files are not in use, as we can use AWS metadata to determine file ownership

Usage with Docker

    git clone https://github.com/bqqbarbhg/go-video-transcoder
    docker build -t govitra .
    docker run --env-file=govitra.env -p 8080:8080 govitra

Example setup:

Dependencies and server:

apt-get update

# Golang (and git for 'go get')
apt-get install -y golang git

# Govitra dependencies
apt-get install -y libav-tools exiftool

# Download and build Govitra
go get github.com/bqqbarbhg/go-video-transcoder

Govitra environment:

GOTR_TEMP_PATH = /var/govitra-uploads/temp
GOTR_SERVE_PATH = /var/govitra-uploads/serve

GOTR_STORAGE_URL_PATH=/govitra-videos/
GOTR_API_URL_PATH=/govitra-api/

GOTR_URI=https://server.com
AUTH_URI=https://server.com/achrails/oidc/auth

Server configuration (nginx):

# Proxy the API to Govitra
location /govitra-api/ {
    client_max_body_size 0;
    proxy_pass http://localhost:8080/;
}

# Serve the uploaded files
location /govitra-videos/ {
    root /var/govitra-uploads/data;
    try_files $uri =404;

    # Deny .owner-files
    location ~ \.owner$ {
        deny all;
        return 404;
    }
}

Now the API should be hosted at https://server.com/govitra-api/ and videos at https://server.com/govitra-videos/

Development setup

  • Get the production dependencies
  • Clone achrails
  • Follow the achrails development setup
  • Clone this repository and cd into it
  • Build Govitra: go build
  • To run it for testing: ./test.sh, this points Govitra to the default achrails address http://10.11.12.13:9292
  • Go to 10.11.12.13:9292/oidc/authorize?response_type=code&client_id=client&redirect_uri=http://example.com and authenticate using the Developer authentication
  • After being redirected to http://example.com?code=<CODE> copy the <CODE>
  • Request POST http://10.11.12.13:9292/oidc/token with code=<CODE>&client_id=client&client_secret=secret&grant_type=authorization_code and copy the access token
  • Now you can do authenticated requests to localhost:8080 using the header Authorization: Bearer <ACCESS-TOKEN>

Development

Made for Ach so! and Learning Layers in Aalto University

Authors

  • Samuli Raivio (@bqqbarbhg)
  • Matti Jokitulppo (@melonmanchan)

Licence

The MIT License (MIT)

Copyright © 2016 Aalto University

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

go-video-transcoder's People

Contributors

melonmanchan avatar bqqbarbhg avatar oamaok avatar

Stargazers

Sohel Mia avatar Arthur Gavazza avatar Paul Osinga avatar Brian Wojtczak avatar Thomas Lekanger avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

viddla

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.