我在使用Carrierwave-Video寶石上傳縱向視頻時遇到了問題。上傳縱向視頻時(尤其是在移動設備上捕捉的視頻)時,順時針旋轉90度。在Carrierwave-Video文檔中,有一個用於動態配置的選項,但我沒有看到動態傳遞自定義參數以基於視頻方向對視頻進行轉碼的方法。我知道,如果我運行以下命令行,我能夠旋轉視頻90度CCW:ffmpeg視頻的條件旋轉
encode_video(:mp4, custom: "-vf transpose=1")
但我需要一個可靠的方式來檢測視頻是否需要旋轉或不。我想知道是否有一些方法可以讓我用ffmpeg運行條件參數,只有在視頻是肖像的情況下才運行。
在情況下,它是有幫助的,這就是我的視頻上傳的樣子在我的Rails應用程序(出於某種原因,轉碼進程正在檢測的視頻的方向,即使之前運行):
require 'carrierwave/processing/mime_types'
class VideoPathUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
include CarrierWave::Video::Thumbnailer
include CarrierWave::MimeTypes
process :encode
def encode
Rails.logger.debug "in encode"
video = FFMPEG::Movie.new(@file.path)
video_width = video.width
video_height = video.height
Rails.logger.debug "video widthxheight: #{video.width}x#{video.height}"
aspect_ratio = video_width/video_height
if video_height > video_width
# rotate video
Rails.logger.debug "portrait video"
encode_video(:mp4, custom: "-vf transpose=1", aspect: aspect_ratio)
else
encode_video(:mp4, aspect: aspect_ratio)
end
instance_variable_set(:@content_type, "video/mp4")
:set_content_type_mp4
end
end
benalavi exiftool buildpack的路徑不正確。 bin目錄不包括在內。這就是爲什麼它不起作用。 voodoorai2000分叉並修復路徑([更新路徑提交](https://github.com/voodoorai2000/buildpack-exiftool/commit/0a8c8245d89f38b665f93b84b36baea8746e55d6))。他似乎在爲我工作。 https://github.com/voodoorai2000/buildpack-exiftool – Ari