Module: Robocap::SDK::FfmpegCli

Defined in:
lib/robocap/sdk/ffmpeg_cli.rb

Class Method Summary collapse

Class Method Details

.decrypt_cenc_copy(input_mp4:, output_mp4:, cek_hex:, kid_hex: nil, ffmpeg_executable: nil) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/robocap/sdk/ffmpeg_cli.rb', line 38

def decrypt_cenc_copy(input_mp4:, output_mp4:, cek_hex:, kid_hex: nil, ffmpeg_executable: nil)
  exe = resolve_ffmpeg_executable(ffmpeg_executable)
  FileUtils.mkdir_p(Pathname(output_mp4).parent)
  cmd = [exe, '-y', '-decryption_key', cek_hex]
  cmd.push('-decryption_kid', kid_hex) if kid_hex && !kid_hex.empty?
  cmd.push(
    '-i', input_mp4.to_s,
    '-map', '0',
    '-map_metadata', '0',
    '-c', 'copy',
    '-movflags', '+use_metadata_tags',
  )
  Mp4Cenc::CENC_STRIP_TAGS_ON_DECRYPT.each do |tag|
    cmd.push('-metadata', "#{tag}=")
  end
  cmd.push(output_mp4.to_s)

  begin
    _stdout, stderr, status = open3_capture3(*cmd)
  rescue SystemCallError => exc
    raise Error.new(
      code: ErrorCode::ERR_CENC_DECRYPT_FAILED,
      message: 'ffmpeg CENC decrypt subprocess failed',
      detail: { reason: exc.message },
    )
  end

  return if status.exitstatus.zero?
  raise Error.new(
    code: ErrorCode::ERR_CENC_DECRYPT_FAILED,
    message: "ffmpeg CENC decrypt failed: #{stderr}",
  )
end

.open3_capture3(*args) ⇒ Object



14
15
16
# File 'lib/robocap/sdk/ffmpeg_cli.rb', line 14

def open3_capture3(*args)
  Open3.capture3(*args)
end

.resolve_ffmpeg_executable(explicit = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/robocap/sdk/ffmpeg_cli.rb', line 28

def resolve_ffmpeg_executable(explicit = nil)
  resolve_executable(
    explicit: explicit,
    tool: 'ffmpeg',
    sibling_for: nil,
    missing_code: ErrorCode::ERR_FFMPEG_NOT_FOUND,
    env_key: Config::FFMPEG_ENV_VAR,
  )
end

.resolve_ffprobe_executable(explicit = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/robocap/sdk/ffmpeg_cli.rb', line 18

def resolve_ffprobe_executable(explicit = nil)
  resolve_executable(
    explicit: explicit,
    tool: 'ffprobe',
    sibling_for: ENV['ROBOCAP_FFMPEG'],
    missing_code: ErrorCode::ERR_FFPROBE_NOT_FOUND,
    env_key: Config::FFPROBE_ENV_VAR,
  )
end