media assets: save more metadata for videos.

Include the following metadata tags for videos:

* FFmpeg:MajorBrand (e.g. mp42)
* FFmpeg:PixFmt (e.g. yuv420p. Indicates bit depth and color subsampling mode)
* FFmpeg:FrameCount (e.g. total number of frames in the video)
* FFmpeg:VideoCodec (e.g. h264)
* FFmpeg:VideoProfile (e.g. Main)
* FFmpeg:AudioCodec (e.g. AAC)
* FFmpeg:AudioProfile (e.g. LC)
* FFmpeg:AudioLayout (e.g. stereo)
* FFmpeg:AudioBitRate (e.g. 128kb/s)
This commit is contained in:
evazion
2022-11-02 21:43:21 -05:00
parent 3172031caa
commit 523d7afdd1
2 changed files with 25 additions and 2 deletions

View File

@@ -83,6 +83,10 @@ class FFmpeg
frame_count / duration
end
def major_brand
metadata.dig(:format, :tags, :major_brand)
end
def pix_fmt
video_stream[:pix_fmt]
end
@@ -99,6 +103,14 @@ class FFmpeg
metadata[:streams].to_a.select { |stream| stream[:codec_type] == "video" }
end
def audio_codec
audio_stream[:codec_name]
end
def audio_stream
audio_streams.first || {}
end
def audio_streams
metadata[:streams].to_a.select { |stream| stream[:codec_type] == "audio" }
end

View File

@@ -5,7 +5,7 @@
#
# @see https://github.com/streamio/streamio-ffmpeg
class MediaFile::Video < MediaFile
delegate :duration, :frame_count, :frame_rate, :has_audio?, :is_corrupt?, :pix_fmt, :video_codec, :video_stream, :video_streams, :audio_streams, :error, to: :video
delegate :duration, :frame_count, :frame_rate, :has_audio?, :is_corrupt?, :major_brand, :pix_fmt, :video_codec, :video_stream, :video_streams, :audio_codec, :audio_stream, :audio_streams, :error, to: :video
def dimensions
[video.width, video.height]
@@ -16,7 +16,18 @@ class MediaFile::Video < MediaFile
end
def metadata
super.merge({ "FFmpeg:Error" => error }.compact_blank)
super.merge({
"FFmpeg:Error" => error,
"FFmpeg:MajorBrand" => major_brand,
"FFmpeg:PixFmt" => pix_fmt,
"FFmpeg:FrameCount" => frame_count,
"FFmpeg:VideoCodec" => video_codec,
"FFmpeg:VideoProfile" => video_stream[:profile],
"FFmpeg:AudioCodec" => audio_codec,
"FFmpeg:AudioProfile" => audio_stream[:profile],
"FFmpeg:AudioLayout" => audio_stream[:channel_layout],
"FFmpeg:AudioBitRate" => audio_stream[:bit_rate],
}.compact_blank)
end
def is_supported?