From 803e375b8439563dc1b79f450628155674ae25a8 Mon Sep 17 00:00:00 2001 From: Thomasssb1 Date: Sat, 17 Feb 2024 05:51:30 +0000 Subject: [PATCH 1/4] Add option for abbreviation to VideoSize --- lib/src/ffmpeg/video_size.dart | 15 +++--- lib/src/ffmpeg/video_size_abbreviation.dart | 60 +++++++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 lib/src/ffmpeg/video_size_abbreviation.dart diff --git a/lib/src/ffmpeg/video_size.dart b/lib/src/ffmpeg/video_size.dart index 337f71f..735a272 100644 --- a/lib/src/ffmpeg/video_size.dart +++ b/lib/src/ffmpeg/video_size.dart @@ -1,14 +1,15 @@ +import 'package:ffmpeg_cli/src/ffmpeg/video_size_abbreviation.dart'; + class VideoSize { - const VideoSize({ - required this.width, - required this.height, - }); + const VideoSize({this.width, this.height, this.abbreviation}) + : assert(width != null && height != null || abbreviation != null); - final num width; - final num height; + final num? width; + final num? height; + final VideoSizeAbbreviation? abbreviation; @override - String toString() => '[Size]: ${width}x$height'; + String toString() => abbreviation?.toCli() ?? '${width}x$height'; @override bool operator ==(Object other) => diff --git a/lib/src/ffmpeg/video_size_abbreviation.dart b/lib/src/ffmpeg/video_size_abbreviation.dart new file mode 100644 index 0000000..531899b --- /dev/null +++ b/lib/src/ffmpeg/video_size_abbreviation.dart @@ -0,0 +1,60 @@ +class VideoSizeAbbreviation { + static const ntsc = VideoSizeAbbreviation._('ntsc'); + static const pal = VideoSizeAbbreviation._('pal'); + static const qntsc = VideoSizeAbbreviation._('qntsc'); + static const qpal = VideoSizeAbbreviation._('qpal'); + static const sntsc = VideoSizeAbbreviation._('sntsc'); + static const spal = VideoSizeAbbreviation._('spal'); + static const film = VideoSizeAbbreviation._('film'); + static const ntscFilm = VideoSizeAbbreviation._('ntsc-film'); + static const sqcif = VideoSizeAbbreviation._('sqcif'); + static const qcif = VideoSizeAbbreviation._('qcif'); + static const cif = VideoSizeAbbreviation._('cif'); + static const cif4 = VideoSizeAbbreviation._('4cif'); + static const cif16 = VideoSizeAbbreviation._('16cif'); + static const qqvga = VideoSizeAbbreviation._('qqvga'); + static const qvga = VideoSizeAbbreviation._('qvga'); + static const vga = VideoSizeAbbreviation._('vga'); + static const svga = VideoSizeAbbreviation._('svga'); + static const xga = VideoSizeAbbreviation._('xga'); + static const uxga = VideoSizeAbbreviation._('uxga'); + static const qxga = VideoSizeAbbreviation._('qxga'); + static const sxga = VideoSizeAbbreviation._('sxga'); + static const qsxga = VideoSizeAbbreviation._('qsxga'); + static const hsxga = VideoSizeAbbreviation._('hsxga'); + static const wvga = VideoSizeAbbreviation._('wvga'); + static const wxga = VideoSizeAbbreviation._('wxga'); + static const wsxga = VideoSizeAbbreviation._('wsxga'); + static const wuxga = VideoSizeAbbreviation._('wuxga'); + static const woxga = VideoSizeAbbreviation._('woxga'); + static const wqsxga = VideoSizeAbbreviation._('wqsxga'); + static const wquxga = VideoSizeAbbreviation._('wquxga'); + static const whsxga = VideoSizeAbbreviation._('whsxga'); + static const whuxga = VideoSizeAbbreviation._('whuxga'); + static const cga = VideoSizeAbbreviation._('cga'); + static const ega = VideoSizeAbbreviation._('ega'); + static const hd480 = VideoSizeAbbreviation._('hd480'); + static const hd720 = VideoSizeAbbreviation._('hd720'); + static const hd1080 = VideoSizeAbbreviation._('hd1080'); + static const resolution2k = VideoSizeAbbreviation._('2k'); + static const flat2k = VideoSizeAbbreviation._('2kflat'); + static const scope2k = VideoSizeAbbreviation._('2kscope'); + static const resolution4k = VideoSizeAbbreviation._('4k'); + static const flat4k = VideoSizeAbbreviation._('4kflat'); + static const scope4k = VideoSizeAbbreviation._('4kscope'); + static const nhd = VideoSizeAbbreviation._('nhd'); + static const hqvga = VideoSizeAbbreviation._('hqvga'); + static const wqvga = VideoSizeAbbreviation._('wqvga'); + static const fwqvga = VideoSizeAbbreviation._('fwqvga'); + static const hvga = VideoSizeAbbreviation._('hvga'); + static const qhd = VideoSizeAbbreviation._('qhd'); + static const dci2k = VideoSizeAbbreviation._('2kdci'); + static const dci4k = VideoSizeAbbreviation._('4kdci'); + static const uhd2160 = VideoSizeAbbreviation._('uhd2160'); + static const uhd4320 = VideoSizeAbbreviation._('uhd4320'); + + const VideoSizeAbbreviation._(this.cliValue); + final String cliValue; + + String toCli() => cliValue; +} From e05794abd5c8f7a9959568a53987350877e3aa7d Mon Sep 17 00:00:00 2001 From: Thomasssb1 Date: Wed, 21 Feb 2024 17:14:55 +0000 Subject: [PATCH 2/4] Change VideoSize priority when both size options are provided --- lib/src/ffmpeg/filters/scale_filter.dart | 6 +++--- lib/src/ffmpeg/video_size.dart | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/ffmpeg/filters/scale_filter.dart b/lib/src/ffmpeg/filters/scale_filter.dart index 56a9414..ac672fc 100644 --- a/lib/src/ffmpeg/filters/scale_filter.dart +++ b/lib/src/ffmpeg/filters/scale_filter.dart @@ -52,14 +52,14 @@ class ScaleFilter implements Filter { @override String toCli() { final properties = [ - if (width != null) 'width=$width', - if (height != null) 'height=$height', + if (width != null && size == null) 'width=$width', + if (height != null && size == null) 'height=$height', if (eval != null) 'eval=$eval', if (interl != null) 'interl=$interl', if (swsFlags != null) 'sws_flags=${swsFlags!.cliValue}', if (param0 != null) 'param0=$param0', if (param1 != null) 'param1=$param1', - if (size != null) 'size=$size', + if (size != null) 'size=${size!.toCli()}', ]; return 'scale=${properties.join(':')}'; diff --git a/lib/src/ffmpeg/video_size.dart b/lib/src/ffmpeg/video_size.dart index 735a272..e4d03af 100644 --- a/lib/src/ffmpeg/video_size.dart +++ b/lib/src/ffmpeg/video_size.dart @@ -8,8 +8,10 @@ class VideoSize { final num? height; final VideoSizeAbbreviation? abbreviation; + String toCli() => abbreviation?.cliValue ?? '${width}x$height'; + @override - String toString() => abbreviation?.toCli() ?? '${width}x$height'; + String toString() => "[Size]: ${width}x$height"; @override bool operator ==(Object other) => From 585e3e064d08d011875cff4ceebcf26a1c1da296 Mon Sep 17 00:00:00 2001 From: Thomasssb1 Date: Wed, 21 Feb 2024 17:23:02 +0000 Subject: [PATCH 3/4] Allow negaitive values for width and height --- lib/src/ffmpeg/filters/scale_filter.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/src/ffmpeg/filters/scale_filter.dart b/lib/src/ffmpeg/filters/scale_filter.dart index ac672fc..52401ba 100644 --- a/lib/src/ffmpeg/filters/scale_filter.dart +++ b/lib/src/ffmpeg/filters/scale_filter.dart @@ -14,9 +14,7 @@ class ScaleFilter implements Filter { this.param0, this.param1, this.size, - }) : assert(width == null || width >= -1), - assert(height == null || height >= -1), - assert(eval == null || eval == 'init' || eval == 'frame'), + }) : assert(eval == null || eval == 'init' || eval == 'frame'), assert(interl == null || interl == 1 || interl == 0 || interl == -1); /// Width for scale From 73148e926249ea1be6a427bfa4b106864b427b84 Mon Sep 17 00:00:00 2001 From: Thomasssb1 Date: Wed, 21 Feb 2024 17:34:32 +0000 Subject: [PATCH 4/4] Fix string formatting in VideoSize toString method Changed to match other strings in the project --- lib/src/ffmpeg/video_size.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ffmpeg/video_size.dart b/lib/src/ffmpeg/video_size.dart index e4d03af..de03278 100644 --- a/lib/src/ffmpeg/video_size.dart +++ b/lib/src/ffmpeg/video_size.dart @@ -11,7 +11,7 @@ class VideoSize { String toCli() => abbreviation?.cliValue ?? '${width}x$height'; @override - String toString() => "[Size]: ${width}x$height"; + String toString() => '[Size]: ${width}x$height'; @override bool operator ==(Object other) =>