Skip to content

Commit fe5fb4e

Browse files
author
Joe Drago
committed
Add AVIF speed dial to cmdline
1 parent 09d4f76 commit fe5fb4e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/include/colorist/context.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ typedef struct clWriteParams
164164
int quantizerMax; // AVIF only. 0-63 range. 0 is lossless. -1 is "ignore and use quality"
165165
int tileRowsLog2; // AVIF only. 0-6 range. 0 is disabled. Requests 2^n tile rows during encoding.
166166
int tileColsLog2; // AVIF only. 0-6 range. 0 is disabled. Requests 2^n tile cols during encoding.
167+
int speed; // AVIF only. [-1,10] range. -1 is "let the codec choose a default".
168+
// 0 is best quality, 10 is fastest encoding speed
167169
const char * codec; // AVIF only. Specify a codec to write with (NULL == auto)
168170
} clWriteParams;
169171
void clWriteParamsSetDefaults(struct clContext * C, clWriteParams * writeParams);

lib/src/context.c

+10
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ void clWriteParamsSetDefaults(struct clContext * C, clWriteParams * writeParams)
452452
writeParams->quantizerMax = -1;
453453
writeParams->tileRowsLog2 = 0;
454454
writeParams->tileColsLog2 = 0;
455+
writeParams->speed = -1;
455456
writeParams->codec = NULL;
456457
}
457458

@@ -905,6 +906,14 @@ clBool clContextParseArgs(clContext * C, int argc, const char * argv[])
905906
}
906907
C->params.writeParams.quantizerMin = CL_CLAMP(C->params.writeParams.quantizerMin, 0, 63);
907908
C->params.writeParams.quantizerMax = CL_CLAMP(C->params.writeParams.quantizerMax, 0, 63);
909+
} else if (!strcmp(arg, "--speed")) {
910+
NEXTARG();
911+
if (!strcmp(arg, "auto")) {
912+
C->params.writeParams.speed = -1;
913+
} else {
914+
C->params.writeParams.speed = atoi(arg);
915+
C->params.writeParams.speed = CL_CLAMP(C->params.writeParams.speed, 0, 10);
916+
}
908917
} else if (!strcmp(arg, "--tiling")) {
909918
NEXTARG();
910919
char tmpBuffer[16]; // the biggest legal string is "6,6", so I don't mind truncation here
@@ -1100,6 +1109,7 @@ void clContextPrintSyntax(clContext * C)
11001109
clContextLog(C, NULL, 0, " --quantizer MIN,MAX : Choose min and max quantizer values directly instead of using -q (AVIF only, 0-63 range, 0,0 is lossless)");
11011110
clContextLog(C, NULL, 0, " --tiling ROWS,COLS : Enable tiling when encoding (AVIF only, 0-6 range, log2 based. Enables 2^ROWS rows and/or 2^COLS cols)");
11021111
clContextLog(C, NULL, 0, " --codec READ,WRITE : Specify which internal codec to be used when decoding (AVIF only, auto,auto is default, see libavif version below for choices)");
1112+
clContextLog(C, NULL, 0, " --speed SPEED : Specify the quality/speed tradeoff when encoding (AVIF only, [0-10] range. auto = default (let the codec decide), 0=best quality, 10=fastest)");
11031113
clContextLog(C, NULL, 0, "");
11041114
clContextLog(C, NULL, 0, "Convert Options:");
11051115
clContextLog(C, NULL, 0, " --resize w,h,filter : Resize dst image to WxH. Use optional filter (auto (default), box, triangle, cubic, catmullrom, mitchell, nearest)");

lib/src/format_avif.c

+6
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ clBool clFormatWriteAVIF(struct clContext * C, struct clImage * image, const cha
293293
} else {
294294
clContextLog(C, "avif", 1, "Encoding tiling (log2): disabled");
295295
}
296+
encoder->speed = writeParams->speed;
297+
if (encoder->speed == -1) {
298+
clContextLog(C, "avif", 1, "Encoding speed (0=BestQuality, 10=Fastest): default (%s)", codecName);
299+
} else {
300+
clContextLog(C, "avif", 1, "Encoding speed (0=BestQuality, 10=Fastest): %d", encoder->speed);
301+
}
296302
avifResult encodeResult = avifEncoderWrite(encoder, avif, &avifOutput);
297303
if (encodeResult != AVIF_RESULT_OK) {
298304
clContextLogError(C, "AVIF encoder failed (%s)", avifResultToString(encodeResult));

0 commit comments

Comments
 (0)