Maintain aspect ratio when converting video? - ffmpeg - iphone

I'm trying to convert movies from .avi to an iphone readable format
wherever I look, people suggest the following options for ffmpeg
ffmpeg -s 320x240 -aspect 320:240 [...]
This does not bode well for videos with a different aspect ratio!
How can I keep the aspect ratio from changing? Is there a way to set the size dynamically?
e.g. have the height to be 240 and the width variable?

Abstract from a rich article found here : http://www.frasq.org/en/transcoding-an-audio-or-a-video-file
To fit a video for a particular display, recompute its width and its height with the following formular:
aspect_ratio_of_display = width_of_display / height_of_display
aspect_ratio_of_video = width_of_video / height_of_video
if aspect_ratio_of_video > aspect_ratio_of_display
then
height = (height_of_video / aspect_ratio_of_video) and width = width_of_display
else
width = (height_of_display x aspect_ratio_of_video) and height = height_of_display
Remember to round the width and the height of the video to a multiple of 16.

Use a simple script in whatever language and get the video details, and adjust accordingly for a target size, you can also "letter box" or pad the top and bottoms for a better aspect ratio.
http://ubuntuforums.org/showthread.php?t=702188
http://stream0.org/2008/01/find-and-extract-video-file-de.html
http://www.mythtv.org/wiki/Ipod_export

Related

how to get device pixel ratio using flutter

as you might know there are two types of size in flutter app (physical,logical).
for margin and padding if we want the app to be responsive we must get context size (width,height).
for a reason I don't want to use MediaQuery.of(context).size so I'm using
Size screenSize = WidgetsBinding.instance.window.physicalSize;
double width = screenSize.width;
double height = screenSize.height;
in such case the size is physical and can't be used like before for padding and margin with edgeinsets.
what I'm asking is a way to either change physical pixel size to logical without using context and MediaQuery or a way to use physical pixels to give responsive margin and padding.
thanks in advance.
I tried to get the ratio with testing results it differs between devices so we can't use static ratio.
The ratio is not the ratio of height/width of physical size.
You can get the screen size without context like this:
var size = MediaQueryData.fromWindow(WidgetsBinding.instance.window).size;
now if you print this size, you can see it is equals to the size that you get from MediaQuery with context.

kCVPixelBufferHeightKey and width not working

Is there a way to set a custom AVCaptureVideoDataOutput for a desired output setting. What Im trying to achieve is below. However the buffer width and height never change .What Im trying to achieve is a custom height and a width for the video pixel output. What am I missing ?
AVCaptureVideoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey: Int(kCVPixelFormatType_32BGRA),
kCVPixelBufferHeightKey: 300,
kCVPixelBufferWidthKey: 300] as [String : Any]
Thus, I tried with the same objective with the session preset, but they are not capable of setting a custom width and height. If I can get a 300x300 output thats a win
You won't get any change in video dimensions use Presets
if it doesn't fit your need use this NextLevelSessionExporter
to resize the video with or without aspect fit of the original record dimensions

Preserving Aspect Ratio in Image::Magick's Thumbnail function

I'm trying to use the Perl Image::Magick library to use ImageMagick's thumbnail function. Everything I read suggests that ImageMagick preserves aspect ratio when it is given both a width and height, almost functioning more like max-width and max-height in CSS parlance. However, in practice, it seems to be jamming the image into the dimensions I give, disregarding aspect ratio. Am I missing a flag I need to turn on? My impression is that preserving aspect ratio is default behavior.
my $image = Image::Magick->new;
$image->BlobToImage($imageData);
$image->SetAttribute(quality => 80);
$image->SetAttribute(compression => 'JPEG');
$image->Thumbnail(width => $thumbnailWidth, height => $thumbnailHeight);
There are options for comprehensive size manipulation under geometry parameter
scale% Height and width both scaled by specified percentage.
...
width Width given, height automagically selected to preserve aspect ratio.
...
widthxheight Maximum values of height and width given, aspect ratio preserved.
widthxheight^ Minimum values of width and height given, aspect ratio preserved.
widthxheight! Width and height emphatically given, original aspect ratio ignored.
...
This is from the Image Geometry section of the page on ImageMagick's command-line use. The fact that Perl module's documentation doesn't give this level of API detail usually implies that its binding implements most (all?) of these, and is covered by the generic documentation.
A command-line example, scaling an image down to 20%
perl -MImage::Magick -we'$f = shift // die "Pass image filename\n";
$img = Image::Magick->new;
$img->Read($f);
$img->Thumbnail(geometry => "20%");
$img->Write(filename => "scaled_$f")'
Judged by the example in the question it looks like you'd want the parameter value
widthxheight Maximum values of height and width given, aspect ratio preserved.
The more generic Resize and Scale methods also have geometry parameter.

Is there a way to define a view's frame in terms of inches instead of points?

Given any screen resolution, is there a way that I can figure out the amount of points in an inch? For instance, if I wanted to create an NSView that was 8.5 inches by 11 inches (like a sheet of a paper), is there an algorithm that will allow me to obtain the correct point values for the frame across many different types of Macs and screen resolutions?
It's not straightforward. I'm not sure there's a good way. I can provide an approach, but I haven't confirmed that this works reliably:
First, you can use CGDisplayScreenSize() to get the screen's physical size in millimeters. You can obtain the CGDirectDisplayID for a screen from NSScreen, which you can, in turn, get from the window. Obtain the screen's deviceDescription and get the value for the "NSScreenNumber" key. That may need to be cast to CGDirectDisplayID.
The problem from there is that the display mode may not fill the screen. It could be letterboxed or pillarboxed. Or, it might be stretched. This should be fairly uncommon these days, but still possible. You can obtain the display mode using CGDisplayCopyDisplayMode(). To determine if it's stretched, you can examine its ioFlags to see if they contain the bitmask kDisplayModeStretchedFlag (declared in IOKit).
If it's stretched, the screen's frame will have to be mapped to its size in millimeters separately for the X and Y axes. You assume the screen's frame.width (in points) maps to the full physical width, and similarly for the height.
If the mode is not stretched, you'll have to check the aspect ratio of the frame and the screen physical size to see if it's letter- or pillarboxed. If the aspect ratios are very close, then it's presumably not. That case is similar to the stretched case, but the width and height mappings should be equivalent.
If the aspect ratios differ significantly, then you compare them. If the screen's physical aspect ratio is larger than the frame's, then the screen is physically wider than the mode is using (pillarboxed). So, you compute the mapping from points to millimeters from the two heights. If the physical aspect ratio is smaller than the logical one, then the mode is letterboxed and you use the widths to compute the mapping.

Difference between stretching and scaling an image

Can anybody please tell me what is the exact difference between stretching and scaling an image? Because you can anyway set the size of image and imageView both to match your requirements.
It depends on how you define stretching, but I would divide scaling into two distinct options based on whether or not the aspect ratio is preserved. Often it is desired to preserve the aspect ratio when scaling an image.
I would consider an increase in one dimension, but not proportionally in the other to be a "stretch". Similarly, a decrease in one dimension, but not proportionally in the other would be a "squash".
You may find this Daring Fireball post interesting.
Stretching sounds like showing small size (10x10) image at (100x100) or (100x10). so some times it gets pix-elated.
And scaling means to show a image to different size either small or big with maintaining its aspect ratio (programmetically), so it will look not improper, because when you stretch to different aspect ratio then some objects in image gets improper visibility.
Stretching (in iphone IB) means '9-slice scaling', scaling means just scaling.
When stretching you can determine which part of the image may be used for stretching and which part may not. For example when you have a rounded square, you do not want the roundings to stretch, especially when you're only stretching horizontally or vertically.
You indicate that you only want to use the middle pixel to stretch by (in IB) setting the X & Y values to 0.50 (half way) and the width & height values to 0.00 (minimum amount of pixels)
Lookup contentStretch in the docs for more info
when you don,t keep the congruence of your image, you see the image incongruous and height and width of your image is not suitable for showing. for resolving this issue you can multiply your image's width and height to to a constant coefficient.
Stretching and scaling don't mean anything different except maybe in connotation.
Is there a particular piece of text somewhere that you are trying to understand? Maybe we can help with that.
stretching image is stretching the size of a small image.
on the other hand scaling of image is scaling the image accoring the the viewport's width and viewport's height....
scaling can be done by small as well as large image.
you should take a good quality image and then should scale it
sprite.setscale(x,y);