无法在ruby中使用ffmpeg carrierwave将mov转换为mp4
我无法使用carrierwave和FFmpeg将MOV文件转换为MP4 它确实上传mp4文件,但不将其转换为mp4,因此只播放浏览器声音而不播放视频 我错过了什么?我尝试了大多数解决方案 代码:无法在ruby中使用ffmpeg carrierwave将mov转换为mp4,ruby,ffmpeg,carrierwave,Ruby,Ffmpeg,Carrierwave,我无法使用carrierwave和FFmpeg将MOV文件转换为MP4 它确实上传mp4文件,但不将其转换为mp4,因此只播放浏览器声音而不播放视频 我错过了什么?我尝试了大多数解决方案 代码: class VideoUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick include CarrierWave::Video include CarrierWave::Video::Thumbn
class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include CarrierWave::Video
include CarrierWave::Video::Thumbnailer
include CarrierWave::FFmpeg
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :video, :if => :video? do
process :encode
end
version :thumb do
process thumbnail: [{format: 'jpg', quality: 8, size: 360, logger: Rails.logger, square: false}]
def full_filename for_file
jpg_name for_file, version_name
end
end
def encode
tmp_path = File.join( File.dirname(current_path), "tmpfile.mp4" )
movie = FFMPEG::Movie.new(current_path)
movie.transcode(tmp_path, custom: %w(-c:v libx264 -c:a aac -vf format=yuv420p -movflags +faststart)) do |progress|
puts progress
end
File.rename tmp_path, current_path
end
protected
def video?(new_file)
new_file.content_type.include? 'video'
end
end
I, [2021-04-09T15:33:24.783337 #9397] INFO -- : Running transcoding...
["/usr/local/bin/ffmpeg", "-y", "-i", "/Users/osx/workspace_ror/xxx-react/tmp/1617964403-459168728101935-0021-9213/video/sample_iTunes__1_.mov", "-c:v", "libx264", "-c:a", "aac", "-vf", "format=yuv420p", "-movflags", "+faststart", "/Users/osx/workspace_ror/xxx-react/tmp/1617964403-459168728101935-0021-9213/video/tmpfile.mp4"]
0.0
0.08304093567251461
0.1672514619883041
0.2327485380116959
0.3229239766081871
0.4008187134502924
0.45426900584795327
0.5033918128654971
0.5403508771929825
0.6100584795321637
0.663859649122807
0.711812865497076
0.7657309941520468
0.8196491228070175
0.87953216374269
0.9394152046783625
1.0
1.0
I, [2021-04-09T15:33:33.555508 #9397] INFO -- : Transcoding of /Users/osx/workspace_ror/xxx-react/tmp/1617964403-459168728101935-0021-9213/video/sample_iTunes__1_.mov to /Users/osx/workspace_ror/xxx-react/tmp/1617964403-459168728101935-0021-9213/video/tmpfile.mp4 succeeded
Running....ffmpegthumbnailer -i /Users/osx/workspace_ror/xxx-react/tmp/1617964403-459168728101935-0021-9213/thumb/sample_iTunes__1_.mov -o /Users/osx/workspace_ror/xxx-react/tmp/1617964403-459168728101935-0021-9213/thumb/tmpfile.jpg -c jpg -q 8 -s 360
Success!