Comments (5)
I found that you can manually rotate images with the ffmpeg command "-vf transpose=1"
I'm trying to detect the orientation of the video within my uploader model to determine whether or not the video needs to be rotated. I tried the dynamic configuration you outlined in the documentation, but my method "encode" is not being called until after the video is transcoded. How can I fix this?
This is what I have:
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
In my logs, I get:
Running transcoding...
ffmpeg -y -i /tmp/1390509835-32689-5471/VID_01-16-2014-17-34-35.mp4 -vcodec libx264 -acodec libfaac -s 640x360 -qscale 0 -preset slow -g 30 -aspect 1 /tmp/1390509835-32689-5471/tmpfile.mp4
Transcoding of /tmp/1390509835-32689-5471/VID_01-16-2014-17-34-35.mp4 to /tmp/1390509835-32689-5471/tmpfile.mp4 succeeded
Started POST "/videos" for 127.0.0.1 at 2014-01-23 15:43:55 -0500
Processing by VideosController#create as JS
in encode
video widthxheight: 1920x1080
...
from carrierwave-video.
Would it be possible to use the before_transcode callback to do this?
from carrierwave-video.
Didn't get a chance to update this with my fix! I ended up using the MiniExiftool gem to get the rotation of the video. Here's the full uploader:
require 'carrierwave/processing/mime_types'
require 'rubygems'
require 'mini_exiftool'
class VideoPathUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
include CarrierWave::Video::Thumbnailer
include CarrierWave::MimeTypes
process :encode
def encode
video = MiniExiftool.new(@file.path)
orientation = video.rotation
model.rotation = orientation
Rails.logger.debug("orientation: #{orientation}")
Rails.logger.debug("video wxh #{video.imagewidth} #{video.imageheight}")
if orientation == 90 && video.imagewidth.to_f > video.imageheight.to_f
Rails.logger.debug("rotating video")
aspect_ratio = video.imageheight.to_f / video.imagewidth.to_f
encode_video(:mp4, custom: "-vf transpose=1", resolution: :same, aspect: aspect_ratio)
else
aspect_ratio = video.imagewidth.to_f / video.imageheight.to_f
encode_video(:mp4, resolution: :same, aspect: aspect_ratio)
end
instance_variable_set(:@content_type, "video/mp4")
:set_content_type_mp4
end
end
from carrierwave-video.
Awesome! Thank you.
from carrierwave-video.
I am facing the issue with a portrait video.The thumbnail is rotating right. I am using the above code.Can you suggest me on that.
when i am removing custom attribute working fine but image is a blur and stretch more.
please tell me what type of custom attribut need to use.
from carrierwave-video.
Related Issues (20)
- S3 support
- Why is there a default resolution?! HOT 3
- Rename gem? HOT 1
- Transcoding passes but video not uploaded (rollback transaction) HOT 3
- after_transcoding callback called too soon
- Resize to Pad (Adding of Black Bars around Videos)
- scaling not work HOT 1
- Compatibility with streamio-ffmpeg 2.1.0 HOT 4
- Failed to transcode with FFmpeg HOT 10
- Aspect ratio distorted with newer Samsung Galaxy videos
- Failed to transcode with FFmpeg HOT 1
- set uploaded video length limit HOT 1
- How do you configure the encoder to include audio?
- Are video files being saved at a later time frame than the initial commit?
- video files are not processing on commit
- I don't need encode video to size 1920x1080 if source size 1280x720. How to solve?
- store multiple quality HOT 1
- No such filter: '"movie'
- percentage progress HOT 1
- Successfully converted file is not moved from cache to the actual storage directory.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carrierwave-video.