media assets: track corrupted files in media metadata.
If a media asset is corrupt, include the error message from libvips or ffmpeg in the "Vips:Error" or "FFmpeg:Error" fields in the media metadata table. Corrupt files can't be uploaded nowadays, but they could be in the past, so we have some old corrupted files that we can't generate thumbnails for. This lets us mark these files in the metadata so they're findable with the tag search `exif:Vips:Error`. Known bug: Vips has a single global error buffer that is shared between threads and that isn't cleared between operations. So we can't reliably get the actual error message because it may pick up errors from other threads, or from previous operations in the same thread.
This commit is contained in:
@@ -41,8 +41,8 @@ class FFmpeg
|
||||
output = shell!("ffprobe -v quiet -print_format json -show_format -show_streams #{file.path.shellescape}")
|
||||
json = JSON.parse(output)
|
||||
json.with_indifferent_access
|
||||
rescue Error
|
||||
{}
|
||||
rescue Error => e
|
||||
{ error: e.message.strip }.with_indifferent_access
|
||||
end
|
||||
|
||||
def width
|
||||
@@ -107,6 +107,16 @@ class FFmpeg
|
||||
audio_streams.present?
|
||||
end
|
||||
|
||||
# @return [Boolean] True if the video is unplayable.
|
||||
def is_corrupt?
|
||||
error.present?
|
||||
end
|
||||
|
||||
# @return [String, nil] The error message if the video is unplayable, or nil if no error.
|
||||
def error
|
||||
metadata[:error] || playback_info[:error]
|
||||
end
|
||||
|
||||
# Decode the full video and return a hash containing the frame count, fps, and runtime.
|
||||
def playback_info
|
||||
output = shell!("ffmpeg -i #{file.path.shellescape} -f null /dev/null")
|
||||
@@ -117,7 +127,7 @@ class FFmpeg
|
||||
info = status_line.scan(/\S+=\s*\S+/).map { |pair| pair.split(/=\s*/) }.to_h
|
||||
info.with_indifferent_access
|
||||
rescue Error => e
|
||||
{}
|
||||
{ error: e.message.strip }.with_indifferent_access
|
||||
end
|
||||
|
||||
def shell!(command)
|
||||
@@ -127,5 +137,5 @@ class FFmpeg
|
||||
output
|
||||
end
|
||||
|
||||
memoize :metadata, :playback_info, :frame_count, :duration
|
||||
memoize :metadata, :playback_info, :frame_count, :duration, :error
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user