diff --git a/mobile/lib/models/ffmpeg/ffprobe_keys.dart b/mobile/lib/models/ffmpeg/ffprobe_keys.dart index 55c26c29f1..c983dec5d8 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_keys.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_keys.dart @@ -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 { diff --git a/mobile/lib/models/ffmpeg/ffprobe_props.dart b/mobile/lib/models/ffmpeg/ffprobe_props.dart index 545a39c5ed..5ad017d462 100644 --- a/mobile/lib/models/ffmpeg/ffprobe_props.dart +++ b/mobile/lib/models/ffmpeg/ffprobe_props.dart @@ -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 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]; } } }