Sign inSign up

ntodd/video-transcoding

By ntodd

•Updated over 6 years ago

Docker wrapper for https://github.com/donmelton/video_transcoding

Image
18

100K+

ntodd/video-transcoding repository overview

For more information about this image and its history, please see the Dockerfile repository⁠ on Github.

⁠Prerequisites

You must be running Docker for Mac⁠, Docker for Linux⁠, or Docker for Windows⁠.

⁠Usage

To run the video_transcoding gem in Docker, execute the following:

# Docker for Mac and Linux
$ docker run -itv "`pwd`":/data ntodd/video-transcoding

# Docker for Windows
$ docker run -itv C:\My\Current\Path:/data ntodd/video-transcoding

# Update to the latest image
$ docker pull ntodd/video-transcoding

This will:

  1. Download the ntodd/video-transcoding Docker image (unless already downloaded)
  2. Mount the current working directory on your host machine as a shared volume inside the container
  3. Run an interactive bash shell with access to your current directory and the video_transcoding cli tools

For best results on Docker for Mac or Windows, set your CPU count in preferences to the maximum available for your machine.

⁠Batch Transcoding

The docker image is easily scriptable. Below is an example of a ruby script that will batch transcode videos in the current directory. Add the script to your path to execute in any directory.

#!/usr/bin/env ruby

supported_types = %w(mov flv wmv avi divx mpg mpeg mp4 mkv)
output_dir = "./output"
docker_command = "docker run -itv \"`pwd`\":/data ntodd/video-transcoding"

glob = "./*\.{#{supported_types.join(',')}}"

if Dir.glob(glob).length > 0
  # Make the output dir
  system("mkdir -p #{output_dir}")
  # Pull the latest docker image
  system("docker pull ntodd/video-transcoding")
else
  puts "No supported video types in directory. Supported types: #{supported_types.join(', ')}"
end

Dir.glob(glob).each do |input_path|
  output_path = "#{output_dir}/#{File.basename(input_path, '.*')}.mp4"
  transcode_command = "transcode-video --crop detect --handbrake-option encoder=x265 --target small --mp4 \"#{input_path}\" -o \"#{output_path}\""
  command = "#{docker_command} #{transcode_command}"

  begin
    IO.popen(command, err: [:child, :out]) do |io|
      Signal.trap 'INT' do
        Process.kill 'INT', io.pid
      end

      io.each_char do |char|
        print char
      end
    end
  rescue SystemCallError => error
    raise "transcoding failed: #{error}"
  end
end

This will:

  1. Create an output dir in the current directory
  2. Pull the latest docker image
  3. Use docker to transcode any video found with a supported type (see supported_types) to an h265 "small" mp4 with a detected crop

This is not comprehensive, but can be used as a starting point for your own scripts.

Tag summary

Content type

Image

Digest

Size

356.7 MB

Last updated

over 7 years ago

docker pull ntodd/video-transcoding