History

fftools/ffmpeg: switch -map parsing to new stream specifier API

Makes optional map handling less hacky, fixes combining optional maps with metadata matching on tags/values containing the '?' character/ Forward errors from stream specifier parsing, previously the code would ignore them.

Anton Khirnov committed 2 years ago

Commit 9e3b5b81 parent d1bdd891 file · +37 −17Browse files

Unified · Split

fftools/ffmpeg_opt.c+37−17
@@ -427,22 +427,20 @@ static int opt_map(void *optctx, const char *opt, const char *arg) · 426 unmodified lines
427{427{
428 OptionsContext *o = optctx;428 OptionsContext *o = optctx;
429 StreamMap *m = NULL;429 StreamMap *m = NULL;
430 StreamSpecifier ss;
430 int i, negative = 0, file_idx, disabled = 0;431 int i, negative = 0, file_idx, disabled = 0;
431 int ret;432 int ret, allow_unused = 0;
432 char *map, *p;433
433 char *allow_unused;434 memset(&ss, 0, sizeof(ss));
434 435
435 if (*arg == '-') {436 if (*arg == '-') {
436 negative = 1;437 negative = 1;
437 arg++;438 arg++;
438 }439 }
439 map = av_strdup(arg);
440 if (!map)
441 return AVERROR(ENOMEM);
442 440
443 if (map[0] == '[') {441 if (arg[0] == '[') {
444 /* this mapping refers to lavfi output */442 /* this mapping refers to lavfi output */
445 const char *c = map + 1;443 const char *c = arg + 1;
446 444
447 ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);445 ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
448 if (ret < 0)446 if (ret < 0)
@@ -451,33 +449,55 @@ static int opt_map(void *optctx, const char *opt, const char *arg) · 2 unmodified lines
451 m = &o->stream_maps[o->nb_stream_maps - 1];449 m = &o->stream_maps[o->nb_stream_maps - 1];
452 m->linklabel = av_get_token(&c, "]");450 m->linklabel = av_get_token(&c, "]");
453 if (!m->linklabel) {451 if (!m->linklabel) {
454 av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);452 av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", arg);
455 ret = AVERROR(EINVAL);453 ret = AVERROR(EINVAL);
456 goto fail;454 goto fail;
457 }455 }
458 } else {456 } else {
459 if (allow_unused = strchr(map, '?'))457 char *endptr;
460 *allow_unused = 0;458
461 file_idx = strtol(map, &p, 0);459 file_idx = strtol(arg, &endptr, 0);
462 if (file_idx >= nb_input_files || file_idx < 0) {460 if (file_idx >= nb_input_files || file_idx < 0) {
463 av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);461 av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
464 ret = AVERROR(EINVAL);462 ret = AVERROR(EINVAL);
465 goto fail;463 goto fail;
466 }464 }
465 arg = endptr;
466
467 ret = stream_specifier_parse(&ss, *arg == ':' ? arg + 1 : arg, 1, NULL);
468 if (ret < 0) {
469 av_log(NULL, AV_LOG_ERROR, "Invalid stream specifier: %s\n", arg);
470 goto fail;
471 }
472
473 if (ss.remainder) {
474 if (!strcmp(ss.remainder, "?"))
475 allow_unused = 1;
476 else {
477 av_log(NULL, AV_LOG_ERROR, "Trailing garbage after stream specifier: %s\n",
478 ss.remainder);
479 ret = AVERROR(EINVAL);
480 goto fail;
481 }
482 }
483
467 if (negative)484 if (negative)
468 /* disable some already defined maps */485 /* disable some already defined maps */
469 for (i = 0; i < o->nb_stream_maps; i++) {486 for (i = 0; i < o->nb_stream_maps; i++) {
470 m = &o->stream_maps[i];487 m = &o->stream_maps[i];
471 if (file_idx == m->file_index &&488 if (file_idx == m->file_index &&
472 check_stream_specifier(input_files[m->file_index]->ctx,489 stream_specifier_match(&ss,
490 input_files[m->file_index]->ctx,
473 input_files[m->file_index]->ctx->streams[m->stream_index],491 input_files[m->file_index]->ctx->streams[m->stream_index],
474 *p == ':' ? p + 1 : p) > 0)492 NULL))
475 m->disabled = 1;493 m->disabled = 1;
476 }494 }
477 else495 else
478 for (i = 0; i < input_files[file_idx]->nb_streams; i++) {496 for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
479 if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],497 if (!stream_specifier_match(&ss,
480 *p == ':' ? p + 1 : p) <= 0)498 input_files[file_idx]->ctx,
499 input_files[file_idx]->ctx->streams[i],
500 NULL))
481 continue;501 continue;
482 if (input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) {502 if (input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) {
483 disabled = 1;503 disabled = 1;
@@ -511,7 +531,7 @@ static int opt_map(void *optctx, const char *opt, const char *arg) · 27 unmodified lines
511 }531 }
512 ret = 0;532 ret = 0;
513fail:533fail:
514 av_freep(&map);534 stream_specifier_uninit(&ss);
515 return ret;535 return ret;
516}536}
517 537

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t