Git Product home page Git Product logo

Comments (5)

ttseng avatar ttseng commented on July 26, 2024

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.

rheaton avatar rheaton commented on July 26, 2024

Would it be possible to use the before_transcode callback to do this?

from carrierwave-video.

ttseng avatar ttseng commented on July 26, 2024

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.

rheaton avatar rheaton commented on July 26, 2024

Awesome! Thank you.

from carrierwave-video.

damujay avatar damujay commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.