Class: TivoHMO::Adapters::StreamIO::Transcoder

Inherits:
Object
  • Object
show all
Includes:
GemLogger::LoggerSupport, TivoHMO::API::Transcoder
Defined in:
lib/tivohmo/adapters/streamio/transcoder.rb

Overview

Transcodes video to tivo format using the streamio gem (ffmpeg)

Direct Known Subclasses

Plex::Transcoder

Constant Summary

Constants included from TivoHMO::API::Transcoder

TivoHMO::API::Transcoder::AUDIO_CODECS, TivoHMO::API::Transcoder::AUDIO_SAMPLE_RATES, TivoHMO::API::Transcoder::VIDEO_CODECS, TivoHMO::API::Transcoder::VIDEO_FRAME_RATES, TivoHMO::API::Transcoder::VIDEO_HEIGHTS, TivoHMO::API::Transcoder::VIDEO_WIDTHS

Instance Attribute Summary

Attributes included from TivoHMO::API::Transcoder

#item

Instance Method Summary collapse

Methods included from TivoHMO::API::Transcoder

#initialize

Instance Method Details

#transcode(writeable_io, format = "video/x-tivo-mpeg") ⇒ Object

TODO: add ability to pass through data (copy codec) for files that are already (partially?) in the right format for tivo. Check against a mapping of tivo serial->allowed_formats code.google.com/p/streambaby/wiki/video_compatibility



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tivohmo/adapters/streamio/transcoder.rb', line 17

def transcode(writeable_io, format="video/x-tivo-mpeg")
  tmpfile = Tempfile.new('tivohmo_transcode')
  begin
    transcode_thread = run_transcode(tmpfile.path, format)

    # give the transcode thread a chance to start up before we
    # start copying from it.  Not strictly necessary, but makes
    # the log messages show up in the right order
    sleep 0.1

    run_copy(tmpfile.path, writeable_io, transcode_thread)
  ensure
    tmpfile.close
    tmpfile.unlink
  end

  nil
end

#transcoder_options(format = "video/x-tivo-mpeg") ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tivohmo/adapters/streamio/transcoder.rb', line 36

def transcoder_options(format="video/x-tivo-mpeg")
  opts = {
      video_max_bitrate: 30_000_000,
      buffer_size: 4096,
      audio_bitrate: 448_000,
      format: format,
      custom: []
  }

  opts = select_video_frame_rate(opts)
  opts = select_video_dimensions(opts)
  opts = select_video_codec(opts)
  opts = select_video_bitrate(opts)
  opts = select_audio_codec(opts)
  opts = select_audio_bitrate(opts)
  opts = select_audio_sample_rate(opts)
  opts = select_container(opts)
  opts = select_subtitle(opts)

  custom = opts.delete(:custom)
  opts[:custom] = custom.join(" ") if custom
  opts.delete(:format)

  opts
end