[mob][photos] Consider sample aspect ratio or pixel aspect ratio when parsing width and height of video used for calculating aspect ratio
This commit is contained in:
@@ -73,6 +73,7 @@ class FFProbeKeys {
|
||||
static const sideDataList = 'side_data_list';
|
||||
static const rotation = 'rotation';
|
||||
static const sideDataType = 'side_data_type';
|
||||
static const sampleAspectRatio = 'sample_aspect_ratio';
|
||||
}
|
||||
|
||||
class MediaStreamTypes {
|
||||
|
||||
@@ -35,16 +35,31 @@ class FFProbeProps {
|
||||
|
||||
int? get width {
|
||||
if (_width == null || _height == null) return null;
|
||||
final intWidth = int.tryParse(_width!);
|
||||
if (_rotation == null) {
|
||||
return intWidth;
|
||||
} else {
|
||||
if ((_rotation! ~/ 90).isEven) {
|
||||
return intWidth;
|
||||
} else {
|
||||
return int.tryParse(_height!);
|
||||
int? finalWidth = int.tryParse(_width!);
|
||||
if (propData?[FFProbeKeys.sampleAspectRatio] != null &&
|
||||
finalWidth != null) {
|
||||
finalWidth = _calculateWidthConsideringSAR(finalWidth);
|
||||
}
|
||||
if (_rotation != null) {
|
||||
if ((_rotation! ~/ 90).isOdd) {
|
||||
finalWidth = int.tryParse(_height!);
|
||||
}
|
||||
}
|
||||
return finalWidth;
|
||||
}
|
||||
|
||||
/// To know more, read about Sample Aspect Ratio (SAR), Display Aspect Ratio (DAR)
|
||||
/// and Pixel Aspect Ratio (PAR)
|
||||
int _calculateWidthConsideringSAR(int width) {
|
||||
final List<String> sar =
|
||||
propData![FFProbeKeys.sampleAspectRatio].toString().split(":");
|
||||
if (sar.length == 2) {
|
||||
final int sarWidth = int.tryParse(sar[0]) ?? 1;
|
||||
final int sarHeight = int.tryParse(sar[1]) ?? 1;
|
||||
return (width * (sarWidth / sarHeight)).toInt();
|
||||
} else {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
|
||||
int? get height {
|
||||
@@ -202,6 +217,8 @@ class FFProbeProps {
|
||||
parsedData[FFProbeKeys.rotation] = result._rotation;
|
||||
}
|
||||
}
|
||||
} else if (key == FFProbeKeys.sampleAspectRatio) {
|
||||
parsedData[key] = stream[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user