lib/video_converter/mp4info.rb
# Get the output of mp4info for path. Caches the results.
# Automatically reruns the command if the file has been
# updated since the last invocation.
#
# @param path [String] Path to an MP4 video file
# @return [String] Output of the mp4info command for the path
Get the output of mp4info for path. Caches the results.
Automatically reruns the command if the file has been
updated since the last invocation.
Get the output of mp4info for path . Caches the results . Automatically reruns the command if the file has been updated since the last invocation .
def mp4info_output(path)
      return '' unless path.is_mp4? && File.exist?(path)
      @mp4info_time = {} if @mp4info_time.nil?
      @mp4info_output = {} if @mp4info_output.nil?
      path = File.expand_path path
      mtime = File.mtime path
      return @mp4info_output[path] unless @mp4info_output[path].nil? || @mp4info_time[path] < mtime
      Open3.popen2e 'mp4info', path do |_input, output, wait_thr|
        lines = output.readlines
        @mp4info_time[path] = Time.now
        if !wait_thr.value.success? || lines.first =~ /can't open/
          @mp4info_output[path] = ''
        else
          @mp4info_output[path] = lines.join("\n")
        end
      end
    end
def mp4info_output ( path ) return '' unless path . is_mp4? && File . exist? ( path ) @mp4info_time = { } if @mp4info_time . nil? @mp4info_output = { } if @mp4info_output . nil? path = File . expand_path path mtime = File . mtime path return @mp4info_output [ path ] unless @mp4info_output [ path ] . nil? || @mp4info_time [ path ] < mtime Open3 . popen2e 'mp4info' , path do | _input , output , wait_thr | lines = output . readlines @mp4info_time [ path ] = Time . now if ! wait_thr . value . success? || lines . first =~ / can't open / @mp4info_output [ path ] = '' else @mp4info_output [ path ] = lines . join ( "\n" ) end end end
Get the output of mp4info for path.
Get the output of mp4info for path .
# Rerun mp4info if the file has been modified since the last invocation.
Output of the mp4info command for the path
Output of the mp4info command for the path
String
path
Path to an MP4 video file
Path to an MP4 video file