R
R
rusrich2018-09-15 21:02:14
Ruby on Rails
rusrich, 2018-09-15 21:02:14

How to exclude conversion in 1920x1080 resolution in paperclip-streamio-ffmpeg if video size is 1280x720?

How to exclude conversion in 1920x1080 resolution in paperclip-streamio-ffmpeg if video size is 1280x720?
We need a universal solution, because they upload videos of different sizes.
And in order not to take up extra memory on the server and not waste its resources, I would like to implement such an option.
https://github.com/daichirata/paperclip-streamio-f...
Here it is indicated that you can add the ">" sign in the papperclip encoding version and then those resolutions that are larger than the width of the uploaded video will be skipped.
But in this case, the converted file is duplicated, which was closer in size.
It would be great if someone could advise.
As an option, I'm considering setting a condition, but I don't fully understand how to get the width of the uploaded video.
Example

has_attached_file :media,
                  processors: [:transcoder],
                  styles: {
                    thumb: {
                      format: :jpeg,
                      convert_options: {
                        resolution: "640x360",
                        screenshot: true,
                        seek_time: 3,
                      },
                      transcoder_options: {
                        preserve_aspect_ratio: :width
                      }
                    },
                    large: {
                      format: :mp4,
                      convert_options: {
                        resolution: "1920x1080",
                        video_codec: "libx264",
                        frame_rate: 25,
                        video_bitrate: 4000,
                        x264_preset: "slow"
                      }
                    },
                    big: {
                      format: :mp4,
                      convert_options: {
                        resolution: "1280x720",
                        video_codec: "libx264",
                        frame_rate: 25,
                        video_bitrate: 2500,
                        x264_preset: "slow"
                      }
                    },
                    medium: {
                      format: :mp4,
                      convert_options: {
                        resolution: "856x480",
                        video_codec: "libx264",
                        frame_rate: 25,
                        video_bitrate: 1200,
                        x264_preset: "slow"
                      }
                    },
                    small: {
                      format: :mp4,
                      convert_options: {
                        resolution: "640x360",
                        video_codec: "libx264",
                        frame_rate: 25,
                        video_bitrate: 800,
                        x264_preset: "slow"
                      }
                    }
                  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question