Skip to content

Commit

Permalink
guacenc: Rudimentary support for non-legally encumbered video codec f…
Browse files Browse the repository at this point in the history
…ormat
  • Loading branch information
robert-scheck committed Dec 30, 2022
1 parent add7ce3 commit 73130bb
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/guacenc/guacenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@

int main(int argc, char* argv[]) {

int i;
int i, size;
bool codec_valid = false;
char* codec_names[] = { "mpeg4", "libvpx" };
char* codec_suffixes[] = { "m4v", "avi" };

/* Load defaults */
bool force = false;
int width = GUACENC_DEFAULT_WIDTH;
int height = GUACENC_DEFAULT_HEIGHT;
int bitrate = GUACENC_DEFAULT_BITRATE;
int codec_suffix = 0;
char* codec_name = codec_names[codec_suffix];

/* Parse arguments */
int opt;
while ((opt = getopt(argc, argv, "s:r:f")) != -1) {
while ((opt = getopt(argc, argv, "s:r:f:c:")) != -1) {

/* -s: Dimensions (WIDTHxHEIGHT) */
if (opt == 's') {
Expand All @@ -65,6 +70,25 @@ int main(int argc, char* argv[]) {
else if (opt == 'f')
force = true;

/* -c: Codec */
else if (opt == 'c') {
codec_name = optarg;

size = sizeof(codec_names) / sizeof(codec_names[0]);
for (i = 0; i < size; i++) {
if (strcmp(codec_name, codec_names[i]) == 0) {
codec_valid = true;
codec_suffix = i;
break;
}
}

if (codec_valid != true) {
guacenc_log(GUAC_LOG_ERROR, "Invalid codec.");
goto invalid_codecs;
}
}

/* Invalid option */
else {
goto invalid_options;
Expand Down Expand Up @@ -108,7 +132,8 @@ int main(int argc, char* argv[]) {

/* Generate output filename */
char out_path[4096];
int len = snprintf(out_path, sizeof(out_path), "%s.m4v", path);
int len = snprintf(out_path, sizeof(out_path), "%s.%s", path,
codec_suffixes[codec_suffix]);

/* Do not write if filename exceeds maximum length */
if (len >= sizeof(out_path)) {
Expand All @@ -118,7 +143,7 @@ int main(int argc, char* argv[]) {
}

/* Attempt encoding, log granular success/failure at debug level */
if (guacenc_encode(path, out_path, "mpeg4",
if (guacenc_encode(path, out_path, codec_name,
width, height, bitrate, force)) {
failures++;
guacenc_log(GUAC_LOG_DEBUG,
Expand Down Expand Up @@ -148,9 +173,23 @@ int main(int argc, char* argv[]) {
" [-s WIDTHxHEIGHT]"
" [-r BITRATE]"
" [-f]"
" [-c CODEC]"
" [FILE]...\n", argv[0]);

return 1;

invalid_codecs:

fprintf(stderr, "ERROR: Unsupported codec! Supported codecs are: ");

size = sizeof(codec_names) / sizeof(codec_names[0]);
for (i = 0; i < size; i++) {
fprintf(stderr, "%s ", codec_names[i]);
}

fprintf(stderr, "\n");

return 1;

}

0 comments on commit 73130bb

Please sign in to comment.