Fix it being possible to upload arbitrary .mkv files and have them be treated as .webm. This was possible because WebM uses the Matroska container format, and we only checked for the Matroska header, not that the file was actually a WebM. There were only 6 such files in production: * https://danbooru.donmai.us/posts?tags=exif:Matroska:DocType=matroska * https://danbooru.donmai.us/posts/5522036 * https://danbooru.donmai.us/posts/4743498 * https://danbooru.donmai.us/posts/3925427 * https://danbooru.donmai.us/posts/3147897 * https://danbooru.donmai.us/posts/2965862 * https://danbooru.donmai.us/posts/2430436 These videos are playable in Chrome, but not in Firefox, since Firefox doesn't support .mkv files (it supports some, depending on which codecs are used, but not .mkv files in general).
41 lines
790 B
Ruby
41 lines
790 B
Ruby
# frozen_string_literal: true
|
|
|
|
# A MediaFile for a webm or mp4 video. Uses ffmpeg to generate preview
|
|
# thumbnails.
|
|
#
|
|
# @see https://github.com/streamio/streamio-ffmpeg
|
|
class MediaFile::Video < MediaFile
|
|
delegate :duration, :frame_count, :frame_rate, :has_audio?, to: :video
|
|
|
|
def dimensions
|
|
[video.width, video.height]
|
|
end
|
|
|
|
def preview(max_width, max_height, **options)
|
|
preview_frame.preview(max_width, max_height, **options)
|
|
end
|
|
|
|
def is_supported?
|
|
case file_ext
|
|
when :webm
|
|
metadata["Matroska:DocType"] == "webm"
|
|
when :mp4
|
|
true
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def video
|
|
FFmpeg.new(file)
|
|
end
|
|
|
|
def preview_frame
|
|
video.smart_video_preview
|
|
end
|
|
|
|
memoize :video, :preview_frame, :dimensions, :duration, :has_audio?
|
|
end
|