1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
|
/*****************************************************************
* gmerlin - a general purpose multimedia framework and applications
*
* Copyright (c) 2001 - 2024 Members of the Gmerlin project
* http://github.com/bplaum
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <config.h>
#include <gmerlin/translation.h>
#include <gmerlin/pluginregistry.h>
#include <gmerlin/transcoder_track.h>
#include <gmerlin/utils.h>
#include <gmerlin/bggavl.h>
#include <gmerlin/textrenderer.h>
#include <gmerlin/filters.h>
#include <gmerlin/log.h>
#define LOG_DOMAIN "transcoder_track"
#include <gavl/metatags.h>
void bg_transcoder_track_set_encoders(bg_transcoder_track_t * t,
const gavl_dictionary_t * encoder_section)
{
int i;
int num;
int num_text_streams;
const gavl_value_t * val;
const gavl_dictionary_t * enc = NULL;
const gavl_dictionary_t * dict = NULL;
const gavl_dictionary_t * video_dict;
const char * name;
gavl_dictionary_t * track_encoder_section;
gavl_dictionary_t * stream_encoder_section;
fprintf(stderr, "bg_transcoder_track_set_encoders\nEncoder section:\n");
gavl_dictionary_dump(encoder_section, 2);
if((val = gavl_dictionary_get(encoder_section, "ve")))
video_dict = gavl_value_get_dictionary(val);
else
video_dict = NULL;
track_encoder_section = bg_transcoder_track_get_cfg_encoder_nc(t);
gavl_dictionary_reset(track_encoder_section);
if((num = gavl_track_get_num_audio_streams(t)))
{
dict = gavl_dictionary_get_dictionary(encoder_section, "ae");
gavl_dictionary_copy_value(track_encoder_section,
encoder_section, "ae");
if((!(name = gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME)) ||
!strcmp(name, "$to_video")))
{
if(video_dict)
enc = bg_cfg_section_find_subsection_c(video_dict, "$audio");
else
fprintf(stderr, "Wrong audio encoder configuration");
}
else
enc = bg_cfg_section_find_subsection_c(dict, "$audio");
for(i = 0; i < num; i++)
{
stream_encoder_section = bg_transcoder_track_get_cfg_encoder_nc(gavl_track_get_audio_stream_nc(t, i));
gavl_dictionary_reset(stream_encoder_section);
if(enc)
gavl_dictionary_copy(stream_encoder_section, enc);
}
}
if((num = gavl_track_get_num_video_streams(t)))
{
gavl_dictionary_copy_value(track_encoder_section,
encoder_section, "ve");
enc = bg_cfg_section_find_subsection_c(video_dict, "$video");
for(i = 0; i < num; i++)
{
stream_encoder_section = bg_transcoder_track_get_cfg_encoder_nc(gavl_track_get_video_stream_nc(t, i));
gavl_dictionary_reset(stream_encoder_section);
if(enc)
gavl_dictionary_copy(stream_encoder_section, enc);
}
}
if((num_text_streams = gavl_track_get_num_text_streams(t)))
{
gavl_dictionary_copy_value(track_encoder_section,
encoder_section, "te");
if(!(name = gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME)) ||
!strcmp(name, "$to_video"))
enc = bg_cfg_section_find_subsection_c(video_dict, "$text");
else
enc = bg_cfg_section_find_subsection_c(dict, "$text");
for(i = 0; i < num_text_streams; i++)
{
stream_encoder_section = bg_transcoder_track_get_cfg_encoder_text_nc(gavl_track_get_text_stream_nc(t, i));
gavl_dictionary_reset(stream_encoder_section);
if(enc)
gavl_dictionary_copy(stream_encoder_section, enc);
}
}
num = 0;
if(num_text_streams || (num = gavl_track_get_num_overlay_streams(t)))
{
gavl_dictionary_copy_value(track_encoder_section,
encoder_section, "oe");
if(!(name = gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME)) ||
!strcmp(name, "$to_video"))
enc = bg_cfg_section_find_subsection_c(video_dict, "$overlay");
else
enc = bg_cfg_section_find_subsection_c(dict, "$overlay");
for(i = 0; i < num_text_streams; i++)
{
stream_encoder_section = bg_transcoder_track_get_cfg_encoder_overlay_nc(gavl_track_get_text_stream_nc(t, i));
gavl_dictionary_reset(stream_encoder_section);
if(enc)
gavl_dictionary_copy(stream_encoder_section, enc);
}
for(i = 0; i < num; i++)
{
stream_encoder_section = bg_transcoder_track_get_cfg_encoder_nc(gavl_track_get_overlay_stream_nc(t, i));
gavl_dictionary_reset(stream_encoder_section);
if(enc)
gavl_dictionary_copy(stream_encoder_section, enc);
}
}
}
void bg_transcoder_track_get_encoders(const bg_transcoder_track_t * t,
gavl_dictionary_t * encoder_section)
{
// gavl_value_t * val;
// const gavl_dictionary_t * dict;
const gavl_dictionary_t * track_encoder_section;
track_encoder_section = bg_transcoder_track_get_cfg_encoder(t);
gavl_dictionary_copy_value(encoder_section,
track_encoder_section, "ae");
/*
fprintf(stderr, "Get encoders:\n");
gavl_value_dump(gavl_dictionary_get(encoder_section, "ae"), 2);
fprintf(stderr, "\n");
*/
gavl_dictionary_copy_value(encoder_section,
track_encoder_section, "ve");
gavl_dictionary_copy_value(encoder_section,
track_encoder_section, "te");
/*
fprintf(stderr, "Get encoders te:\n");
gavl_value_dump(gavl_dictionary_get(encoder_section, "te"), 2);
fprintf(stderr, "\n");
*/
gavl_dictionary_copy_value(encoder_section,
track_encoder_section, "oe");
}
static const bg_parameter_info_t parameters_general[] =
{
{
.name = "subdir",
.long_name = TRS("Subdirectory"),
.type = BG_PARAMETER_STRING,
.help_string = TRS("Subdirectory, where this track will be written to"),
},
{ /* End of parameters */ }
};
/* Subtitle text parameters */
static const bg_parameter_info_t general_parameters_text[] =
{
{
.name = "action",
.long_name = TRS("Action"),
.type = BG_PARAMETER_STRINGLIST,
.val_default = GAVL_VALUE_INIT_STRING("forget"),
.multi_names = (char const *[]){ "forget",
"transcode",
"transcode_overlay",
"blend",
NULL },
.multi_labels = (char const *[]){ TRS("Forget"),
TRS("Transcode as text"),
TRS("Transcode as overlay"),
TRS("Blend onto video"),
NULL },
.help_string = TRS("Select action for this subtitle stream.")
},
{
.name = GAVL_META_LANGUAGE,
.long_name = TRS("Language"),
.type = BG_PARAMETER_STRINGLIST,
.val_default = GAVL_VALUE_INIT_STRING("eng"),
.multi_names = bg_language_codes,
.multi_labels = bg_language_labels,
},
{
.name = "force_language",
.long_name = TRS("Force language"),
.type = BG_PARAMETER_CHECKBUTTON,
.val_default = GAVL_VALUE_INIT_INT(0),
.help_string = TRS("Force the given language even if the input has the language set differently.")
},
{
.name = "time_offset",
.long_name = TRS("Time offset"),
.flags = BG_PARAMETER_SYNC,
.type = BG_PARAMETER_FLOAT,
.val_min = GAVL_VALUE_INIT_FLOAT(-600.0),
.val_max = GAVL_VALUE_INIT_FLOAT(600.0),
.num_digits = 3,
},
{ /* End of parameters */ }
};
/* Subtitle overlay parameters */
static const bg_parameter_info_t general_parameters_overlay[] =
{
{
.name = "action",
.long_name = TRS("Action"),
.type = BG_PARAMETER_STRINGLIST,
.multi_names = (char const *[]){ "forget",
"copy",
"transcode",
"blend",
NULL },
.multi_labels = (char const *[]){ TRS("Forget"),
TRS("Copy (if possible)"),
TRS("Transcode"),
TRS("Blend onto video"),
NULL },
.val_default = GAVL_VALUE_INIT_STRING("forget"),
},
{
.name = GAVL_META_LANGUAGE,
.long_name = TRS("Language"),
.type = BG_PARAMETER_STRINGLIST,
.val_default = GAVL_VALUE_INIT_STRING("eng"),
.multi_names = bg_language_codes,
.multi_labels = bg_language_labels,
},
{
.name = "force_language",
.long_name = TRS("Force language"),
.type = BG_PARAMETER_CHECKBUTTON,
.val_default = GAVL_VALUE_INIT_INT(0),
.help_string = TRS("Force the given language even if the input has the language set differently.")
},
{ /* End of parameters */ }
};
/* Create parameters if the config sections are already there */
bg_parameter_info_t *
bg_transcoder_track_create_parameters(bg_transcoder_track_t * track)
{
bg_parameter_info_t * ret;
ret = bg_parameter_info_copy_array(parameters_general);
return ret;
}
static char * create_stream_label(const gavl_dictionary_t * m)
{
const char * info;
const char * language;
info = gavl_dictionary_get_string(m, GAVL_META_LABEL);
language = gavl_dictionary_get_string(m, GAVL_META_LANGUAGE);
if(language && info)
return gavl_sprintf("%s [%s]", info, bg_get_language_name(language));
else if(language)
return gavl_strdup(bg_get_language_name(language));
else if(info)
return gavl_strdup(info);
else
return NULL;
}
static void set_language(gavl_dictionary_t * general_section_dst,
const gavl_dictionary_t * general_section_cfg,
const gavl_dictionary_t * stream_m)
{
const char * lang_m;
const char * lang_cfg;
lang_m = gavl_dictionary_get_string(stream_m, GAVL_META_LANGUAGE);
lang_cfg = gavl_dictionary_get_string(general_section_cfg, GAVL_META_LANGUAGE);
if(lang_m && lang_cfg && strcmp(lang_m, lang_cfg))
{
int force = 0;
gavl_dictionary_get_int(general_section_cfg, "force_language", &force);
gavl_dictionary_set_string(general_section_dst,
GAVL_META_LANGUAGE,
force ? lang_cfg : lang_m);
}
}
static void sanitize_label(char* str)
{
int len;
int i;
if(str == NULL || *str == '\0')
{
return;
}
len = strlen(str);
for(i = 0; i < len; i++)
{
char c = str[i];
if((c >= 0 && c <= 31) || c == 127)
{
str[i] = '_';
continue;
}
if(strchr("<>:\"/\\|?*", c) != NULL)
{
str[i] = '_';
}
}
for(i = 0; i < len && str[i] == '.'; i++)
{
str[i] = '_';
}
for(i = len - 1; i > 0 && (str[i] == '.' || str[i] == ' '); i--)
{
str[i] = '_';
len = i;
}
}
static int set_track(bg_transcoder_track_t * track,
const gavl_dictionary_t * media_info,
const gavl_dictionary_t * track_info,
gavl_dictionary_t * track_defaults_section,
gavl_dictionary_t * encoder_section)
{
int i;
const char * disk_name;
int num;
gavl_dictionary_t * sm;
gavl_dictionary_t * s;
const gavl_dictionary_t * global_metadata;
gavl_dictionary_t * metadata;
/* Create sections */
gavl_dictionary_t * general_section_cfg;
gavl_dictionary_t * general_section_dst;
const gavl_dictionary_t * filter_section;
gavl_dictionary_t * textrenderer_section;
gavl_dictionary_t * sec;
gavl_dictionary_copy(track, track_info);
if((metadata = gavl_track_get_metadata_nc(track)))
{
char * label = gavl_dictionary_get_string_nc(metadata, GAVL_META_LABEL);
if(label)
sanitize_label(label);
}
if(!gavl_dictionary_get(track, GAVL_META_STREAMS))
{
int num_variants;
bg_plugin_handle_t * h;
gavl_dictionary_t * ti;
/* Open location to load the streams */
if(!(h = bg_load_track(track, 0, &num_variants)))
return 0;
ti = bg_input_plugin_get_track_info(h, -1);
gavl_dictionary_copy_value(track, ti, GAVL_META_STREAMS);
bg_plugin_unref(h);
}
/* Create sections */
if(bg_transcoder_track_get_cfg_general(track))
return 1; /* Transcoding specific stuff is already there */
general_section_cfg =
bg_cfg_section_find_subsection(track_defaults_section, "general");
sec = bg_transcoder_track_get_cfg_general_nc(track);
gavl_dictionary_copy(sec, general_section_cfg);
if(media_info &&
(global_metadata = gavl_dictionary_get_dictionary(media_info, GAVL_META_METADATA)) &&
(disk_name = gavl_dictionary_get_string(global_metadata, GAVL_META_DISK_NAME)))
gavl_dictionary_set_string(sec, "subdir", disk_name);
bg_transcoder_track_set_encoders(track, encoder_section);
if((num = gavl_track_get_num_audio_streams(track)))
{
general_section_cfg =
bg_cfg_section_find_subsection(track_defaults_section, "audio");
filter_section = bg_plugin_config_get_section(BG_PLUGIN_FILTER_AUDIO);
for(i = 0; i < num; i++)
{
s = gavl_track_get_audio_stream_nc(track, i);
sm = gavl_track_get_audio_metadata_nc(track, i);
general_section_dst = bg_transcoder_track_get_cfg_general_nc(s);
gavl_dictionary_copy(general_section_dst, general_section_cfg);
gavl_dictionary_copy(bg_transcoder_track_get_cfg_filter_nc(s), filter_section);
gavl_dictionary_set_string_nocopy(general_section_dst, GAVL_META_LABEL,
create_stream_label(sm));
set_language(general_section_dst, general_section_cfg, sm);
}
}
if((num = gavl_track_get_num_video_streams(track)))
{
general_section_cfg = bg_cfg_section_find_subsection(track_defaults_section,
"video");
filter_section =
bg_plugin_config_get_section(BG_PLUGIN_FILTER_VIDEO);
for(i = 0; i < num; i++)
{
s = gavl_track_get_video_stream_nc(track, i);
sm = gavl_track_get_video_metadata_nc(track, i);
general_section_dst = bg_transcoder_track_get_cfg_general_nc(s);
gavl_dictionary_copy(general_section_dst, general_section_cfg);
gavl_dictionary_copy(bg_transcoder_track_get_cfg_filter_nc(s), filter_section);
gavl_dictionary_set_string_nocopy(general_section_dst,
GAVL_META_LABEL,
create_stream_label(sm));
}
}
if((num = gavl_track_get_num_text_streams(track)))
{
general_section_cfg = bg_cfg_section_find_subsection(track_defaults_section,
"text");
textrenderer_section = bg_cfg_section_find_subsection(track_defaults_section,
"textrenderer");
for(i = 0; i < num; i++)
{
sm = gavl_track_get_text_metadata_nc(track, i);
s = gavl_track_get_text_stream_nc(track, i);
general_section_dst = bg_transcoder_track_get_cfg_general_nc(s);
gavl_dictionary_copy(general_section_dst, general_section_cfg);
gavl_dictionary_copy(bg_transcoder_track_get_cfg_textrenderer_nc(s), textrenderer_section);
gavl_dictionary_set_string_nocopy(general_section_dst,
GAVL_META_LABEL,
create_stream_label(sm));
set_language(general_section_dst, general_section_cfg, sm);
}
}
if((num = gavl_track_get_num_overlay_streams(track)))
{
general_section_cfg = bg_cfg_section_find_subsection(track_defaults_section,
"overlay");
for(i = 0; i < num; i++)
{
s = gavl_track_get_overlay_stream_nc(track, i);
sm = gavl_track_get_overlay_metadata_nc(track, i);
general_section_dst = bg_transcoder_track_get_cfg_general_nc(s);
gavl_dictionary_copy(general_section_dst, general_section_cfg);
gavl_dictionary_set_string_nocopy(general_section_cfg,
GAVL_META_LABEL,
create_stream_label(sm));
set_language(general_section_dst, general_section_cfg, sm);
}
}
return 1;
}
gavl_array_t *
bg_transcoder_track_create(const char * url,
gavl_dictionary_t * track_defaults_section,
gavl_dictionary_t * encoder_section)
{
int i;
int num_tracks;
gavl_dictionary_t * media_info;
const gavl_dictionary_t * edl;
const gavl_dictionary_t * dict;
gavl_dictionary_t vars;
gavl_array_t * ret = NULL;
int track = -1;
const char * var;
// fprintf(stderr, "bg_transcoder_track_create\n");
// gavl_dictionary_dump(encoder_section, 2);
/* Load the plugin */
gavl_dictionary_init(&vars);
gavl_url_get_vars_c(url, &vars);
if((var = gavl_dictionary_get_string(&vars, GAVL_URL_VAR_TRACK)))
track = atoi(var) - 1;
gavl_dictionary_free(&vars);
if(!(media_info = bg_plugin_registry_load_media_info(bg_plugin_reg, url, 0)))
return NULL;
if((edl = gavl_dictionary_get_dictionary(media_info, GAVL_META_EDL)))
dict = edl;
else
dict = media_info;
if((num_tracks = gavl_get_num_tracks(dict)))
{
gavl_value_t val;
gavl_dictionary_t * t;
ret = gavl_array_create();
for(i = 0; i < num_tracks; i++)
{
if((track >= 0) && (i != track))
continue;
gavl_value_init(&val);
t = gavl_value_set_dictionary(&val);
set_track(t, dict, gavl_get_track(dict, i),
track_defaults_section,
encoder_section);
gavl_array_splice_val_nocopy(ret, ret->num_entries, 0, &val);
gavl_value_free(&val);
}
}
if(media_info)
gavl_dictionary_destroy(media_info);
return ret;
}
gavl_array_t *
bg_transcoder_tracks_import(const gavl_array_t * tracks,
gavl_dictionary_t * track_defaults_section,
gavl_dictionary_t * encoder_section)
{
int i;
gavl_array_t * ret = gavl_array_create();
for(i = 0; i < tracks->num_entries; i++)
{
gavl_value_t dst_val;
gavl_dictionary_t * dst;
const gavl_dictionary_t * src = gavl_value_get_dictionary(&tracks->entries[i]);
if(!src)
continue;
gavl_value_init(&dst_val);
dst = gavl_value_set_dictionary(&dst_val);
if(set_track(dst, NULL, src,
track_defaults_section,
encoder_section))
gavl_array_splice_val_nocopy(ret, -1, 0, &dst_val);
else
{
gavl_value_free(&dst_val);
}
}
fprintf(stderr, "Imported tracks:\n");
gavl_array_dump(ret, 2);
return ret;
}
gavl_array_t *
bg_transcoder_track_create_from_urilist(const char * list,
int len,
gavl_dictionary_t * track_defaults_section,
gavl_dictionary_t * encoder_section)
{
int i;
char ** uri_list;
gavl_array_t * arr = NULL;
gavl_array_t * ret = NULL;
uri_list = bg_urilist_decode(list, len);
if(!uri_list)
return NULL;
i = 0;
while(uri_list[i])
{
if((arr = bg_transcoder_track_create(uri_list[i], track_defaults_section,
encoder_section)))
{
if(!ret)
ret = gavl_array_create();
gavl_array_splice_array(ret, ret->num_entries, 0, arr);
gavl_array_destroy(arr);
}
i++;
}
bg_urilist_free(uri_list);
return ret;
}
static const bg_parameter_info_t general_parameters_video[] =
{
{
.name = "general",
.long_name = TRS("General"),
.type = BG_PARAMETER_SECTION
},
{
.name = "action",
.long_name = TRS("Action"),
.type = BG_PARAMETER_STRINGLIST,
.multi_names = (char const *[]){ "transcode", "copy", "forget", NULL },
.multi_labels = (char const *[]){ TRS("Transcode"),
TRS("Copy (if possible)"),
TRS("Forget"), NULL },
.val_default = GAVL_VALUE_INIT_STRING("transcode"),
.help_string = TRS("Choose the desired action for the stream. If copying is not possible, the stream will be transcoded"),
},
{
.name = "twopass",
.long_name = TRS("Enable 2-pass encoding"),
.type = BG_PARAMETER_CHECKBUTTON,
.help_string = TRS("Encode this stream in 2 passes, i.e. analyze it first and do the final\
transcoding in the second pass. This enables higher quality within the given bitrate constraints but roughly doubles the video encoding time."),
},
BG_GAVL_PARAM_CONVERSION_QUALITY,
BG_GAVL_PARAM_ALPHA,
BG_GAVL_PARAM_RESAMPLE_CHROMA,
BG_GAVL_PARAM_THREADS,
{ /* End of parameters */ }
};
static const bg_parameter_info_t general_parameters_audio[] =
{
{
.name = "action",
.long_name = TRS("Action"),
.type = BG_PARAMETER_STRINGLIST,
.multi_names = (char const *[]){ "transcode", "copy", "forget", NULL },
.multi_labels = (char const *[]){ TRS("Transcode"),
TRS("Copy (if possible)"),
TRS("Forget"), NULL },
.val_default = GAVL_VALUE_INIT_STRING("transcode"),
.help_string = TRS("Choose the desired action for the stream. If copying is not possible, the stream will be transcoded"),
},
{
.name = GAVL_META_LANGUAGE,
.long_name = TRS("Language"),
.type = BG_PARAMETER_STRINGLIST,
.val_default = GAVL_VALUE_INIT_STRING("eng"),
.multi_names = bg_language_codes,
.multi_labels = bg_language_labels,
},
{
.name = "force_language",
.long_name = TRS("Force language"),
.type = BG_PARAMETER_CHECKBUTTON,
.val_default = GAVL_VALUE_INIT_INT(0),
.help_string = TRS("Force the given language even if the input has the language set differently.")
},
{
.name = "normalize",
.long_name = TRS("Normalize audio"),
.type = BG_PARAMETER_CHECKBUTTON,
.help_string = TRS("This will enable 2 pass transcoding. In the first pass, the peak volume\
is detected. In the second pass, the stream is transcoded with normalized volume.")
},
BG_GAVL_PARAM_CONVERSION_QUALITY,
BG_GAVL_PARAM_AUDIO_DITHER_MODE,
BG_GAVL_PARAM_RESAMPLE_MODE,
BG_GAVL_PARAM_CHANNEL_SETUP,
{ /* End of parameters */ }
};
/* Audio stream parameters */
const bg_parameter_info_t *
bg_transcoder_track_audio_get_general_parameters()
{
return general_parameters_audio;
}
/* Video stream parameters */
const bg_parameter_info_t *
bg_transcoder_track_video_get_general_parameters()
{
return general_parameters_video;
}
const bg_parameter_info_t *
bg_transcoder_track_text_get_general_parameters()
{
return general_parameters_text;
}
const bg_parameter_info_t *
bg_transcoder_track_overlay_get_general_parameters()
{
return general_parameters_overlay;
}
const bg_parameter_info_t *
bg_transcoder_track_get_general_parameters()
{
return parameters_general;
}
const char * bg_transcoder_track_get_name(const bg_transcoder_track_t * t)
{
return gavl_dictionary_get_string(gavl_track_get_metadata(t), GAVL_META_LABEL);
}
const char * bg_transcoder_track_get_audio_encoder(const bg_transcoder_track_t * t)
{
const char * ret;
const gavl_dictionary_t * dict;
if((dict = gavl_dictionary_get_dictionary(bg_transcoder_track_get_cfg_encoder(t),
"ae")) &&
(ret = gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME)) &&
strcmp(ret, "$to_video"))
return ret;
else
return NULL;
}
const char * bg_transcoder_track_get_video_encoder(const bg_transcoder_track_t * t)
{
const gavl_dictionary_t * dict;
if((dict = gavl_dictionary_get_dictionary(bg_transcoder_track_get_cfg_encoder(t),
"ve")))
return gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME);
else
return NULL;
}
const char * bg_transcoder_track_get_text_encoder(const bg_transcoder_track_t * t)
{
const char * ret;
const gavl_dictionary_t * dict;
if((dict = gavl_dictionary_get_dictionary(bg_transcoder_track_get_cfg_encoder(t),
"te")) &&
(ret = gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME)) &&
strcmp(ret, "$to_video"))
return ret;
else
return NULL;
}
const char * bg_transcoder_track_get_overlay_encoder(const bg_transcoder_track_t * t)
{
const char * ret;
const gavl_dictionary_t * dict;
if((dict = gavl_dictionary_get_dictionary(bg_transcoder_track_get_cfg_encoder(t),
"oe")) &&
(ret = gavl_dictionary_get_string(dict, BG_CFG_TAG_NAME)) &&
strcmp(ret, "$to_video"))
return ret;
else
return NULL;
}
#if 1
void
bg_transcoder_track_split_at_chapters(gavl_array_t * ret, const bg_transcoder_track_t * t)
{
int i;
gavl_time_t time;
const char * label_orig = NULL;
char * label_new;
int num;
int timescale;
const gavl_dictionary_t * cl;
const gavl_dictionary_t * m;
gavl_value_t new_track_val;
gavl_dictionary_t * new_track;
gavl_dictionary_t * new_m;
gavl_dictionary_t * general_section;
if(!(m = gavl_track_get_metadata(t)) ||
!(cl = gavl_dictionary_get_chapter_list(m)) ||
((num = gavl_chapter_list_get_num(cl)) <= 1))
return;
label_orig = gavl_dictionary_get_string(m, GAVL_META_LABEL);
timescale = gavl_chapter_list_get_timescale(cl);
for(i = 0; i < num; i++)
{
gavl_value_init(&new_track_val);
new_track = gavl_value_set_dictionary(&new_track_val);
gavl_dictionary_copy(new_track, t);
new_m = gavl_track_get_metadata_nc(new_track);
gavl_dictionary_set(new_m, GAVL_CHAPTERLIST_CHAPTERLIST, NULL);
general_section = bg_transcoder_track_get_cfg_general_nc(new_track);
if(i > 0)
{
time = gavl_time_unscale(timescale, gavl_chapter_list_get_time(cl, i));
gavl_dictionary_set_int(general_section, "set_start_time", 1);
gavl_dictionary_set_long(general_section, "start_time", time);
}
if(i < num-1)
{
time = gavl_time_unscale(timescale, gavl_chapter_list_get_time(cl, i + 1));
gavl_dictionary_set_int(general_section, "set_end_time", 1);
gavl_dictionary_set_long(general_section, "end_time", time);
}
if(label_orig)
label_new = gavl_sprintf("%s (Chapter %02d)", label_orig, i+1);
else
label_new = gavl_sprintf("Chapter %02d", i+1);
gavl_dictionary_set_string(new_m, GAVL_META_LABEL, label_new);
gavl_array_splice_val_nocopy(ret, -1, 0, &new_track_val);
}
}
#endif
|