Skip to content

Fix size being serialized properly in ScaleFilter #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/src/ffmpeg/filters/scale_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,14 +50,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(':')}';
Expand Down
15 changes: 9 additions & 6 deletions lib/src/ffmpeg/video_size.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
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 VideoSizeAbbreviation? abbreviation;

final num width;
final num height;
String toCli() => abbreviation?.cliValue ?? '${width}x$height';

@override
String toString() => '[Size]: ${width}x$height';
Expand Down
60 changes: 60 additions & 0 deletions lib/src/ffmpeg/video_size_abbreviation.dart
Original file line number Diff line number Diff line change
@@ -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;
}