1 /***************************************************************************
4 * Fri Mar 28 10:38:44 2008
5 * Copyright 2008 John Stebbins
6 * <john at stebbins dot name>
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
29 #include <glib/gstdio.h>
30 #include "hb-backend.h"
32 #include "callbacks.h"
33 #include "subtitlehandler.h"
34 #include "audiohandler.h"
35 #include "x264handler.h"
43 const gchar *shortOpt;
54 static gchar **index_str = NULL;
55 static gint index_str_size = 0;
58 index_str_init(gint max_index)
62 if (max_index+1 > index_str_size)
64 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
65 for (ii = index_str_size; ii <= max_index; ii++)
67 index_str[ii] = g_strdup_printf("%d", ii);
69 index_str_size = max_index + 1;
73 static options_map_t d_when_complete_opts[] =
75 {"Do Nothing", "nothing", 0, "0"},
76 {"Show Notification", "notify", 1, "1"},
77 {"Put Computer To Sleep", "sleep", 2, "2"},
78 {"Shutdown Computer", "shutdown", 3, "3"},
80 combo_opts_t when_complete_opts =
82 sizeof(d_when_complete_opts)/sizeof(options_map_t),
86 static options_map_t d_par_opts[] =
89 {"Strict", "1", 1, "1"},
90 {"Loose", "2", 2, "2"},
91 {"Custom", "3", 3, "3"},
93 combo_opts_t par_opts =
95 sizeof(d_par_opts)/sizeof(options_map_t),
99 static options_map_t d_alignment_opts[] =
104 {"16", "16", 16, "16"},
106 combo_opts_t alignment_opts =
108 sizeof(d_alignment_opts)/sizeof(options_map_t),
112 static options_map_t d_logging_opts[] =
118 combo_opts_t logging_opts =
120 sizeof(d_logging_opts)/sizeof(options_map_t),
124 static options_map_t d_log_longevity_opts[] =
126 {"Week", "week", 7, "7"},
127 {"Month", "month", 30, "30"},
128 {"Year", "year", 365, "365"},
129 {"Immortal", "immortal", 366, "366"},
131 combo_opts_t log_longevity_opts =
133 sizeof(d_log_longevity_opts)/sizeof(options_map_t),
137 static options_map_t d_appcast_update_opts[] =
139 {"Never", "never", 0, "never"},
140 {"Daily", "daily", 1, "daily"},
141 {"Weekly", "weekly", 2, "weekly"},
142 {"Monthly", "monthly", 3, "monthly"},
144 combo_opts_t appcast_update_opts =
146 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
147 d_appcast_update_opts
150 static options_map_t d_vqual_granularity_opts[] =
152 {"0.2", "0.2", 0.2, "0.2"},
153 {"0.25", "0.25", 0.25, "0.25"},
154 {"0.5", "0.5", 0.5, "0.5"},
157 combo_opts_t vqual_granularity_opts =
159 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
160 d_vqual_granularity_opts
163 static options_map_t d_container_opts[] =
165 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
166 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
168 combo_opts_t container_opts =
170 sizeof(d_container_opts)/sizeof(options_map_t),
174 static options_map_t d_detel_opts[] =
176 {"Off", "off", 0, ""},
177 {"Custom", "custom", 1, ""},
178 {"Default","default",2, NULL},
180 combo_opts_t detel_opts =
182 sizeof(d_detel_opts)/sizeof(options_map_t),
186 static options_map_t d_decomb_opts[] =
188 {"Off", "off", 0, ""},
189 {"Custom", "custom", 1, ""},
190 {"Default","default",2, NULL},
192 combo_opts_t decomb_opts =
194 sizeof(d_decomb_opts)/sizeof(options_map_t),
198 static options_map_t d_deint_opts[] =
200 {"Off", "off", 0, ""},
201 {"Custom", "custom", 1, ""},
202 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
203 {"Slow", "slow", 3, "2:-1:-1:0:1"},
204 {"Slower", "slower", 4, "0:-1:-1:0:1"},
206 combo_opts_t deint_opts =
208 sizeof(d_deint_opts)/sizeof(options_map_t),
212 static options_map_t d_denoise_opts[] =
214 {"Off", "off", 0, ""},
215 {"Custom", "custom", 1, ""},
216 {"Weak", "weak", 2, "2:1:2:3"},
217 {"Medium", "medium", 3, "3:2:2:3"},
218 {"Strong", "strong", 4, "7:7:5:5"},
220 combo_opts_t denoise_opts =
222 sizeof(d_denoise_opts)/sizeof(options_map_t),
226 static options_map_t d_vcodec_opts[] =
228 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
229 {"MPEG-4 (FFmpeg)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
230 {"VP3 (Theora)", "theora", HB_VCODEC_THEORA, ""},
232 combo_opts_t vcodec_opts =
234 sizeof(d_vcodec_opts)/sizeof(options_map_t),
238 static options_map_t d_acodec_opts[] =
240 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
241 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
242 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
243 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
244 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
245 {"Choose For Me", "auto", HB_ACODEC_MASK, "auto"},
247 combo_opts_t acodec_opts =
249 sizeof(d_acodec_opts)/sizeof(options_map_t),
253 static options_map_t d_direct_opts[] =
255 {"None", "none", 0, "none"},
256 {"Spatial", "spatial", 1, "spatial"},
257 {"Temporal", "temporal", 2, "temporal"},
258 {"Automatic", "auto", 3, "auto"},
260 combo_opts_t direct_opts =
262 sizeof(d_direct_opts)/sizeof(options_map_t),
266 static options_map_t d_badapt_opts[] =
268 {"Off", "0", 0, "0"},
269 {"Fast", "1", 1, "1"},
270 {"Optimal", "2", 2, "2"},
272 combo_opts_t badapt_opts =
274 sizeof(d_badapt_opts)/sizeof(options_map_t),
278 static options_map_t d_me_opts[] =
280 {"Diamond", "dia", 0, "dia"},
281 {"Hexagon", "hex", 1, "hex"},
282 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
283 {"Exhaustive", "esa", 3, "esa"},
284 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
286 combo_opts_t me_opts =
288 sizeof(d_me_opts)/sizeof(options_map_t),
292 static options_map_t d_subme_opts[] =
303 {"10", "10", 10, "10"},
305 combo_opts_t subme_opts =
307 sizeof(d_subme_opts)/sizeof(options_map_t),
311 static options_map_t d_analyse_opts[] =
313 {"Some", "some", 0, "some"},
314 {"None", "none", 1, "none"},
315 {"All", "all", 2, "all"},
316 {"Custom", "custom", 3, "all"},
318 combo_opts_t analyse_opts =
320 sizeof(d_analyse_opts)/sizeof(options_map_t),
324 static options_map_t d_trellis_opts[] =
326 {"Disabled", "0", 0, "0"},
327 {"Final Macro Block", "1", 1, "1"},
328 {"Always", "2", 2, "2"},
330 combo_opts_t trellis_opts =
332 sizeof(d_trellis_opts)/sizeof(options_map_t),
336 combo_opts_t subtitle_opts =
342 combo_opts_t title_opts =
348 combo_opts_t audio_track_opts =
360 combo_name_map_t combo_name_map[] =
362 {"WhenComplete", &when_complete_opts},
363 {"PicturePAR", &par_opts},
364 {"PictureModulus", &alignment_opts},
365 {"LoggingLevel", &logging_opts},
366 {"LogLongevity", &log_longevity_opts},
367 {"check_updates", &appcast_update_opts},
368 {"VideoQualityGranularity", &vqual_granularity_opts},
369 {"FileFormat", &container_opts},
370 {"PictureDeinterlace", &deint_opts},
371 {"PictureDecomb", &decomb_opts},
372 {"PictureDetelecine", &detel_opts},
373 {"PictureDenoise", &denoise_opts},
374 {"VideoEncoder", &vcodec_opts},
375 {"AudioEncoder", &acodec_opts},
376 {"x264_direct", &direct_opts},
377 {"x264_b_adapt", &badapt_opts},
378 {"x264_me", &me_opts},
379 {"x264_subme", &subme_opts},
380 {"x264_analyse", &analyse_opts},
381 {"x264_trellis", &trellis_opts},
382 {"SubtitleTrack", &subtitle_opts},
383 {"title", &title_opts},
384 {"AudioTrack", &audio_track_opts},
388 const gchar *srt_codeset_table[] =
427 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
430 typedef struct iso639_lang_t
432 char * eng_name; /* Description in English */
433 char * native_name; /* Description in native language */
434 char * iso639_1; /* ISO-639-1 (2 characters) code */
435 char * iso639_2; /* ISO-639-2/t (3 character) code */
436 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
440 const iso639_lang_t ghb_language_table[] =
442 { "Any", "", "zz", "und" },
443 { "Afar", "", "aa", "aar" },
444 { "Abkhazian", "", "ab", "abk" },
445 { "Afrikaans", "", "af", "afr" },
446 { "Akan", "", "ak", "aka" },
447 { "Albanian", "", "sq", "sqi", "alb" },
448 { "Amharic", "", "am", "amh" },
449 { "Arabic", "", "ar", "ara" },
450 { "Aragonese", "", "an", "arg" },
451 { "Armenian", "", "hy", "hye", "arm" },
452 { "Assamese", "", "as", "asm" },
453 { "Avaric", "", "av", "ava" },
454 { "Avestan", "", "ae", "ave" },
455 { "Aymara", "", "ay", "aym" },
456 { "Azerbaijani", "", "az", "aze" },
457 { "Bashkir", "", "ba", "bak" },
458 { "Bambara", "", "bm", "bam" },
459 { "Basque", "", "eu", "eus", "baq" },
460 { "Belarusian", "", "be", "bel" },
461 { "Bengali", "", "bn", "ben" },
462 { "Bihari", "", "bh", "bih" },
463 { "Bislama", "", "bi", "bis" },
464 { "Bosnian", "", "bs", "bos" },
465 { "Breton", "", "br", "bre" },
466 { "Bulgarian", "", "bg", "bul" },
467 { "Burmese", "", "my", "mya", "bur" },
468 { "Catalan", "", "ca", "cat" },
469 { "Chamorro", "", "ch", "cha" },
470 { "Chechen", "", "ce", "che" },
471 { "Chinese", "", "zh", "zho", "chi" },
472 { "Church Slavic", "", "cu", "chu" },
473 { "Chuvash", "", "cv", "chv" },
474 { "Cornish", "", "kw", "cor" },
475 { "Corsican", "", "co", "cos" },
476 { "Cree", "", "cr", "cre" },
477 { "Czech", "", "cs", "ces", "cze" },
478 { "Danish", "Dansk", "da", "dan" },
479 { "German", "Deutsch", "de", "deu", "ger" },
480 { "Divehi", "", "dv", "div" },
481 { "Dzongkha", "", "dz", "dzo" },
482 { "English", "English", "en", "eng" },
483 { "Spanish", "Espanol", "es", "spa" },
484 { "Esperanto", "", "eo", "epo" },
485 { "Estonian", "", "et", "est" },
486 { "Ewe", "", "ee", "ewe" },
487 { "Faroese", "", "fo", "fao" },
488 { "Fijian", "", "fj", "fij" },
489 { "French", "Francais", "fr", "fra", "fre" },
490 { "Western Frisian", "", "fy", "fry" },
491 { "Fulah", "", "ff", "ful" },
492 { "Georgian", "", "ka", "kat", "geo" },
493 { "Gaelic (Scots)", "", "gd", "gla" },
494 { "Irish", "", "ga", "gle" },
495 { "Galician", "", "gl", "glg" },
496 { "Manx", "", "gv", "glv" },
497 { "Greek, Modern", "", "el", "ell", "gre" },
498 { "Guarani", "", "gn", "grn" },
499 { "Gujarati", "", "gu", "guj" },
500 { "Haitian", "", "ht", "hat" },
501 { "Hausa", "", "ha", "hau" },
502 { "Hebrew", "", "he", "heb" },
503 { "Herero", "", "hz", "her" },
504 { "Hindi", "", "hi", "hin" },
505 { "Hiri Motu", "", "ho", "hmo" },
506 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
507 { "Igbo", "", "ig", "ibo" },
508 { "Ido", "", "io", "ido" },
509 { "Icelandic", "Islenska", "is", "isl", "ice" },
510 { "Sichuan Yi", "", "ii", "iii" },
511 { "Inuktitut", "", "iu", "iku" },
512 { "Interlingue", "", "ie", "ile" },
513 { "Interlingua", "", "ia", "ina" },
514 { "Indonesian", "", "id", "ind" },
515 { "Inupiaq", "", "ik", "ipk" },
516 { "Italian", "Italiano", "it", "ita" },
517 { "Javanese", "", "jv", "jav" },
518 { "Japanese", "", "ja", "jpn" },
519 { "Kalaallisut", "", "kl", "kal" },
520 { "Kannada", "", "kn", "kan" },
521 { "Kashmiri", "", "ks", "kas" },
522 { "Kanuri", "", "kr", "kau" },
523 { "Kazakh", "", "kk", "kaz" },
524 { "Central Khmer", "", "km", "khm" },
525 { "Kikuyu", "", "ki", "kik" },
526 { "Kinyarwanda", "", "rw", "kin" },
527 { "Kirghiz", "", "ky", "kir" },
528 { "Komi", "", "kv", "kom" },
529 { "Kongo", "", "kg", "kon" },
530 { "Korean", "", "ko", "kor" },
531 { "Kuanyama", "", "kj", "kua" },
532 { "Kurdish", "", "ku", "kur" },
533 { "Lao", "", "lo", "lao" },
534 { "Latin", "", "la", "lat" },
535 { "Latvian", "", "lv", "lav" },
536 { "Limburgan", "", "li", "lim" },
537 { "Lingala", "", "ln", "lin" },
538 { "Lithuanian", "", "lt", "lit" },
539 { "Luxembourgish", "", "lb", "ltz" },
540 { "Luba-Katanga", "", "lu", "lub" },
541 { "Ganda", "", "lg", "lug" },
542 { "Macedonian", "", "mk", "mkd", "mac" },
543 { "Hungarian", "Magyar", "hu", "hun" },
544 { "Marshallese", "", "mh", "mah" },
545 { "Malayalam", "", "ml", "mal" },
546 { "Maori", "", "mi", "mri", "mao" },
547 { "Marathi", "", "mr", "mar" },
548 { "Malay", "", "ms", "msa", "msa" },
549 { "Malagasy", "", "mg", "mlg" },
550 { "Maltese", "", "mt", "mlt" },
551 { "Moldavian", "", "mo", "mol" },
552 { "Mongolian", "", "mn", "mon" },
553 { "Nauru", "", "na", "nau" },
554 { "Navajo", "", "nv", "nav" },
555 { "Dutch", "Nederlands", "nl", "nld", "dut" },
556 { "Ndebele, South", "", "nr", "nbl" },
557 { "Ndebele, North", "", "nd", "nde" },
558 { "Ndonga", "", "ng", "ndo" },
559 { "Nepali", "", "ne", "nep" },
560 { "Norwegian", "Norsk", "no", "nor" },
561 { "Norwegian Nynorsk", "", "nn", "nno" },
562 { "Norwegian Bokmål", "", "nb", "nob" },
563 { "Chichewa; Nyanja", "", "ny", "nya" },
564 { "Occitan", "", "oc", "oci" },
565 { "Ojibwa", "", "oj", "oji" },
566 { "Oriya", "", "or", "ori" },
567 { "Oromo", "", "om", "orm" },
568 { "Ossetian", "", "os", "oss" },
569 { "Panjabi", "", "pa", "pan" },
570 { "Persian", "", "fa", "fas", "per" },
571 { "Pali", "", "pi", "pli" },
572 { "Polish", "", "pl", "pol" },
573 { "Portuguese", "Portugues", "pt", "por" },
574 { "Pushto", "", "ps", "pus" },
575 { "Quechua", "", "qu", "que" },
576 { "Romansh", "", "rm", "roh" },
577 { "Romanian", "", "ro", "ron", "rum" },
578 { "Rundi", "", "rn", "run" },
579 { "Russian", "", "ru", "rus" },
580 { "Sango", "", "sg", "sag" },
581 { "Sanskrit", "", "sa", "san" },
582 { "Serbian", "", "sr", "srp", "scc" },
583 { "Sinhala", "", "si", "sin" },
584 { "Slovak", "", "sk", "slk", "slo" },
585 { "Slovenian", "", "sl", "slv" },
586 { "Northern Sami", "", "se", "sme" },
587 { "Samoan", "", "sm", "smo" },
588 { "Shona", "", "sn", "sna" },
589 { "Sindhi", "", "sd", "snd" },
590 { "Somali", "", "so", "som" },
591 { "Sotho, Southern", "", "st", "sot" },
592 { "Sardinian", "", "sc", "srd" },
593 { "Swati", "", "ss", "ssw" },
594 { "Sundanese", "", "su", "sun" },
595 { "Finnish", "Suomi", "fi", "fin" },
596 { "Swahili", "", "sw", "swa" },
597 { "Swedish", "Svenska", "sv", "swe" },
598 { "Tahitian", "", "ty", "tah" },
599 { "Tamil", "", "ta", "tam" },
600 { "Tatar", "", "tt", "tat" },
601 { "Telugu", "", "te", "tel" },
602 { "Tajik", "", "tg", "tgk" },
603 { "Tagalog", "", "tl", "tgl" },
604 { "Thai", "", "th", "tha" },
605 { "Tibetan", "", "bo", "bod", "tib" },
606 { "Tigrinya", "", "ti", "tir" },
607 { "Tonga", "", "to", "ton" },
608 { "Tswana", "", "tn", "tsn" },
609 { "Tsonga", "", "ts", "tso" },
610 { "Turkmen", "", "tk", "tuk" },
611 { "Turkish", "", "tr", "tur" },
612 { "Twi", "", "tw", "twi" },
613 { "Uighur", "", "ug", "uig" },
614 { "Ukrainian", "", "uk", "ukr" },
615 { "Urdu", "", "ur", "urd" },
616 { "Uzbek", "", "uz", "uzb" },
617 { "Venda", "", "ve", "ven" },
618 { "Vietnamese", "", "vi", "vie" },
619 { "Volapük", "", "vo", "vol" },
620 { "Welsh", "", "cy", "cym", "wel" },
621 { "Walloon", "", "wa", "wln" },
622 { "Wolof", "", "wo", "wol" },
623 { "Xhosa", "", "xh", "xho" },
624 { "Yiddish", "", "yi", "yid" },
625 { "Yoruba", "", "yo", "yor" },
626 { "Zhuang", "", "za", "zha" },
627 { "Zulu", "", "zu", "zul" },
628 {NULL, NULL, NULL, NULL}
630 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
632 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
635 del_tree(const gchar *name, gboolean del_top)
639 if (g_file_test(name, G_FILE_TEST_IS_DIR))
641 GDir *gdir = g_dir_open(name, 0, NULL);
642 file = g_dir_read_name(gdir);
646 path = g_strdup_printf("%s/%s", name, file);
647 del_tree(path, TRUE);
649 file = g_dir_read_name(gdir);
664 return hb_get_version(NULL);
669 signal_user_data_t *ud,
677 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
686 *step = ghb_settings_combo_double(ud->settings,
687 "VideoQualityGranularity");
688 if (*step == 0.2 || *step == 0.5)
690 else if (*step == 0.25)
695 case HB_VCODEC_FFMPEG:
703 case HB_VCODEC_THEORA:
722 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
726 const gchar *result = "";
728 str = ghb_value_string(gval);
729 for (ii = 0; ii < opts->count; ii++)
731 if (strcmp(opts->map[ii].shortOpt, str) == 0)
733 result = opts->map[ii].svalue;
742 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
748 str = ghb_value_string(gval);
749 for (ii = 0; ii < opts->count; ii++)
751 if (strcmp(opts->map[ii].shortOpt, str) == 0)
753 result = opts->map[ii].ivalue;
762 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
768 str = ghb_value_string(gval);
769 for (ii = 0; ii < opts->count; ii++)
771 if (strcmp(opts->map[ii].shortOpt, str) == 0)
773 result = opts->map[ii].ivalue;
782 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
786 const gchar *result = "";
788 str = ghb_value_string(gval);
789 for (ii = 0; ii < opts->count; ii++)
791 if (strcmp(opts->map[ii].shortOpt, str) == 0)
793 result = opts->map[ii].option;
802 lookup_mix_int(const GValue *mix)
809 str = ghb_value_string(mix);
810 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
812 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
814 result = hb_audio_mixdowns[ii].amixdown;
823 lookup_mix_option(const GValue *mix)
827 gchar *result = "None";
830 str = ghb_value_string(mix);
831 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
833 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
835 result = hb_audio_mixdowns[ii].human_readable_name;
844 lookup_video_rate_int(const GValue *vrate)
850 str = ghb_value_string(vrate);
851 for (ii = 0; ii < hb_video_rates_count; ii++)
853 if (strcmp(hb_video_rates[ii].string, str) == 0)
855 result = hb_video_rates[ii].rate;
860 // Default to "same as source"
865 lookup_video_rate_option(const GValue *vrate)
869 const gchar *result = "Same as source";
871 str = ghb_value_string(vrate);
872 for (ii = 0; ii < hb_video_rates_count; ii++)
874 if (strcmp(hb_video_rates[ii].string, str) == 0)
876 result = hb_video_rates[ii].string;
881 // Default to "same as source"
886 lookup_audio_rate_int(const GValue *rate)
892 // Coincidentally, the string "source" will return 0
893 // which is our flag to use "same as source"
894 str = ghb_value_string(rate);
895 for (ii = 0; ii < hb_audio_rates_count; ii++)
897 if (strcmp(hb_audio_rates[ii].string, str) == 0)
899 result = hb_audio_rates[ii].rate;
908 lookup_audio_rate_option(const GValue *rate)
912 const gchar *result = "Same as source";
914 // Coincidentally, the string "source" will return 0
915 // which is our flag to use "same as source"
916 str = ghb_value_string(rate);
917 for (ii = 0; ii < hb_audio_rates_count; ii++)
919 if (strcmp(hb_audio_rates[ii].string, str) == 0)
921 result = hb_audio_rates[ii].string;
930 lookup_audio_bitrate_int(const GValue *rate)
936 // Coincidentally, the string "source" will return 0
937 // which is our flag to use "same as source"
938 str = ghb_value_string(rate);
939 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
941 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
943 result = hb_audio_bitrates[ii].rate;
952 lookup_audio_bitrate_option(const GValue *rate)
956 const gchar *result = "Same as source";
958 // Coincidentally, the string "source" will return 0
959 // which is our flag to use "same as source"
960 str = ghb_value_string(rate);
961 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
963 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
965 result = hb_audio_bitrates[ii].string;
974 lookup_audio_lang_int(const GValue *rate)
980 // Coincidentally, the string "source" will return 0
981 // which is our flag to use "same as source"
982 str = ghb_value_string(rate);
983 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
985 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
996 lookup_audio_lang_option(const GValue *rate)
1000 const gchar *result = "Same as source";
1002 // Coincidentally, the string "source" will return 0
1003 // which is our flag to use "same as source"
1004 str = ghb_value_string(rate);
1005 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1007 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1009 if (ghb_language_table[ii].native_name[0] != 0)
1010 result = ghb_language_table[ii].native_name;
1012 result = ghb_language_table[ii].eng_name;
1021 get_acodec_value(gint val)
1023 GValue *value = NULL;
1026 for (ii = 0; ii < acodec_opts.count; ii++)
1028 if ((int)acodec_opts.map[ii].ivalue == val)
1030 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1038 get_amix_value(gint val)
1040 GValue *value = NULL;
1043 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1045 if (hb_audio_mixdowns[ii].amixdown == val)
1047 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1054 // Handle for libhb. Gets set by ghb_backend_init()
1055 static hb_handle_t * h_scan = NULL;
1056 static hb_handle_t * h_queue = NULL;
1058 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
1065 hb_get_tempory_directory(h_scan, dir);
1066 return g_strdup(dir);
1070 ghb_hb_cleanup(gboolean partial)
1074 hb_get_tempory_directory(h_scan, dir);
1075 del_tree(dir, !partial);
1079 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1087 titleindex = ghb_settings_combo_int(ud->settings, "title");
1093 hb_subtitle_t * sub;
1095 if (h_scan == NULL) return VOBSUB;
1096 list = hb_get_titles( h_scan );
1097 if( !hb_list_count( list ) )
1099 /* No valid title, stop right there */
1102 title = hb_list_item( list, titleindex );
1103 if (title == NULL) return VOBSUB; // Bad titleindex
1104 sub = hb_list_item( title->list_subtitle, track);
1112 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1115 const gchar * name = "Unknown";
1128 titleindex = ghb_settings_combo_int(ud->settings, "title");
1134 hb_subtitle_t * sub;
1138 list = hb_get_titles( h_scan );
1139 if( !hb_list_count( list ) )
1142 title = hb_list_item( list, titleindex );
1146 sub = hb_list_item( title->list_subtitle, track);
1149 switch (sub->source)
1171 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1175 titleindex = ghb_settings_combo_int(ud->settings, "title");
1179 return ghb_get_user_audio_lang(ud, titleindex, 0);
1185 hb_subtitle_t * sub;
1190 list = hb_get_titles( h_scan );
1191 if( !hb_list_count( list ) )
1193 /* No valid title, stop right there */
1196 title = hb_list_item( list, titleindex );
1197 if (title == NULL) // Bad titleindex
1199 sub = hb_list_item( title->list_subtitle, track);
1201 return g_strdup(sub->iso639_2);
1204 return g_strdup("und");
1208 ghb_get_title_number(gint titleindex)
1213 if (h_scan == NULL) return 1;
1214 list = hb_get_titles( h_scan );
1215 if( !hb_list_count( list ) )
1217 /* No valid title, stop right there */
1220 title = hb_list_item( list, titleindex );
1221 if (title == NULL) return 1; // Bad titleindex
1222 return title->index;
1225 static hb_audio_config_t*
1226 get_hb_audio(gint titleindex, gint track)
1230 hb_audio_config_t *audio = NULL;
1232 if (h_scan == NULL) return NULL;
1233 list = hb_get_titles( h_scan );
1234 if( !hb_list_count( list ) )
1236 /* No valid title, stop right there */
1239 title = hb_list_item( list, titleindex );
1240 if (title == NULL) return NULL; // Bad titleindex
1241 if (!hb_list_count(title->list_audio))
1245 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1250 search_rates(hb_rate_t *rates, gint rate, gint count)
1253 for (ii = 0; ii < count; ii++)
1255 if (rates[ii].rate == rate)
1261 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1263 static GtkListStore*
1264 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1267 GtkListStore *store;
1269 g_debug("get_combo_box_store() %s\n", name);
1270 // First modify the combobox model to allow greying out of options
1271 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1272 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1277 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1279 GtkListStore *store;
1282 store = get_combo_box_store(builder, name);
1283 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1285 gtk_list_store_set(store, &iter,
1292 ghb_grey_combo_options(GtkBuilder *builder)
1295 gint container, track, titleindex, acodec;
1296 hb_audio_config_t *audio = NULL;
1299 widget = GHB_WIDGET (builder, "title");
1300 gval = ghb_widget_value(widget);
1301 titleindex = ghb_lookup_combo_int("title", gval);
1302 ghb_value_free(gval);
1303 widget = GHB_WIDGET (builder, "AudioTrack");
1304 gval = ghb_widget_value(widget);
1305 track = ghb_lookup_combo_int("AudioTrack", gval);
1306 ghb_value_free(gval);
1307 audio = get_hb_audio(titleindex, track);
1308 widget = GHB_WIDGET (builder, "FileFormat");
1309 gval = ghb_widget_value(widget);
1310 container = ghb_lookup_combo_int("FileFormat", gval);
1311 ghb_value_free(gval);
1313 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1314 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1315 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1316 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1318 gboolean allow_dca = TRUE;
1319 allow_dca = (container != HB_MUX_MP4);
1321 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1323 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1325 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1327 if (audio && audio->in.codec != HB_ACODEC_AC3)
1329 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1331 if (audio && audio->in.codec != HB_ACODEC_DCA)
1333 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1335 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1337 widget = GHB_WIDGET (builder, "AudioEncoder");
1338 gval = ghb_widget_value(widget);
1339 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1340 ghb_value_free(gval);
1341 if (acodec != HB_ACODEC_AC3)
1343 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1345 if (container == HB_MUX_MP4)
1347 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1348 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1349 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1352 gboolean allow_mono = TRUE;
1353 gboolean allow_stereo = TRUE;
1354 gboolean allow_dolby = TRUE;
1355 gboolean allow_dpl2 = TRUE;
1356 gboolean allow_6ch = TRUE;
1357 allow_mono = acodec & ~HB_ACODEC_LAME;
1358 allow_6ch = acodec & ~HB_ACODEC_LAME;
1361 allow_mono = allow_mono &&
1362 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA));
1363 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1365 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1367 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1368 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1369 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1370 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1371 allow_6ch = allow_6ch &&
1372 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1373 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1374 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1376 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1377 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1378 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1379 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1380 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1384 ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
1386 if (acodec & HB_ACODEC_FAAC)
1388 int maxbr = channels * 80;
1396 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1398 hb_audio_config_t *audio = NULL;
1399 gboolean allow_mono = TRUE;
1400 gboolean allow_stereo = TRUE;
1401 gboolean allow_dolby = TRUE;
1402 gboolean allow_dpl2 = TRUE;
1403 gboolean allow_6ch = TRUE;
1405 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1407 // Audio codec pass-thru. No mixdown
1410 audio = get_hb_audio(titleindex, track);
1414 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1415 (acodec & ~HB_ACODEC_LAME);
1416 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1418 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1420 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1421 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1422 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1423 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1425 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1426 (acodec & ~HB_ACODEC_LAME) &&
1427 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1428 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1430 gboolean greater = FALSE;
1433 // If no mix is specified, select the best available.
1434 mix = HB_AMIXDOWN_6CH;
1436 if (mix == HB_AMIXDOWN_6CH)
1439 if (allow_6ch) return HB_AMIXDOWN_6CH;
1441 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1444 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1446 if (mix == HB_AMIXDOWN_DOLBY || greater)
1449 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1451 if (mix == HB_AMIXDOWN_STEREO || greater)
1454 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1456 if (mix == HB_AMIXDOWN_MONO || greater)
1459 if (allow_mono) return HB_AMIXDOWN_MONO;
1461 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1462 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1463 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1464 if (allow_6ch) return HB_AMIXDOWN_6CH;
1468 // Set up the model for the combo box
1470 init_combo_box(GtkBuilder *builder, const gchar *name)
1473 GtkListStore *store;
1474 GtkCellRenderer *cell;
1476 g_debug("init_combo_box() %s\n", name);
1477 // First modify the combobox model to allow greying out of options
1478 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1482 // 1 - String to display
1483 // 2 - bool indicating whether the entry is selectable (grey or not)
1484 // 3 - String that is used for presets
1485 // 4 - Int value determined by backend
1486 // 5 - String value determined by backend
1487 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1488 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1489 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1491 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1493 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1494 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1495 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1496 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1497 "markup", 0, "sensitive", 1, NULL);
1500 { // Combo box entry
1501 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1506 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1509 GtkListStore *store;
1513 g_debug("audio_samplerate_opts_set ()\n");
1514 store = get_combo_box_store(builder, name);
1515 gtk_list_store_clear(store);
1516 // Add an item for "Same As Source"
1517 gtk_list_store_append(store, &iter);
1518 gtk_list_store_set(store, &iter,
1519 0, "<small>Same as source</small>",
1525 for (ii = 0; ii < count; ii++)
1527 gtk_list_store_append(store, &iter);
1528 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1529 gtk_list_store_set(store, &iter,
1532 2, rates[ii].string,
1533 3, (gdouble)rates[ii].rate,
1534 4, rates[ii].string,
1541 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1544 GtkListStore *store;
1547 g_debug("video_rate_opts_set ()\n");
1548 store = get_combo_box_store(builder, name);
1549 gtk_list_store_clear(store);
1550 // Add an item for "Same As Source"
1551 gtk_list_store_append(store, &iter);
1552 gtk_list_store_set(store, &iter,
1553 0, "Same as source",
1559 for (ii = 0; ii < count; ii++)
1563 if (strcmp(rates[ii].string, "23.976") == 0)
1565 desc = "(NTSC Film)";
1567 else if (strcmp(rates[ii].string, "25") == 0)
1569 desc = "(PAL Film/Video)";
1571 else if (strcmp(rates[ii].string, "29.97") == 0)
1573 desc = "(NTSC Video)";
1575 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1576 gtk_list_store_append(store, &iter);
1577 gtk_list_store_set(store, &iter,
1580 2, rates[ii].string,
1581 3, (gdouble)rates[ii].rate,
1582 4, rates[ii].string,
1589 mix_opts_set(GtkBuilder *builder, const gchar *name)
1592 GtkListStore *store;
1596 g_debug("mix_opts_set ()\n");
1597 store = get_combo_box_store(builder, name);
1598 gtk_list_store_clear(store);
1599 gtk_list_store_append(store, &iter);
1600 gtk_list_store_set(store, &iter,
1601 0, "<small>None</small>",
1607 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1609 gtk_list_store_append(store, &iter);
1610 str = g_strdup_printf("<small>%s</small>",
1611 hb_audio_mixdowns[ii].human_readable_name);
1612 gtk_list_store_set(store, &iter,
1615 2, hb_audio_mixdowns[ii].short_name,
1616 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1617 4, hb_audio_mixdowns[ii].internal_name,
1624 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1627 GtkListStore *store;
1630 g_debug("srt_codeset_opts_set ()\n");
1631 store = get_combo_box_store(builder, name);
1632 gtk_list_store_clear(store);
1633 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1635 gtk_list_store_append(store, &iter);
1636 gtk_list_store_set(store, &iter,
1637 0, srt_codeset_table[ii],
1639 2, srt_codeset_table[ii],
1641 4, srt_codeset_table[ii],
1644 GtkComboBoxEntry *cbe;
1646 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1647 //gtk_combo_box_entry_set_text_column(cbe, 0);
1651 language_opts_set(GtkBuilder *builder, const gchar *name)
1654 GtkListStore *store;
1657 g_debug("language_opts_set ()\n");
1658 store = get_combo_box_store(builder, name);
1659 gtk_list_store_clear(store);
1660 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1664 if (ghb_language_table[ii].native_name[0] != 0)
1665 lang = ghb_language_table[ii].native_name;
1667 lang = ghb_language_table[ii].eng_name;
1669 gtk_list_store_append(store, &iter);
1670 gtk_list_store_set(store, &iter,
1673 2, ghb_language_table[ii].iso639_2,
1675 4, ghb_language_table[ii].iso639_1,
1680 static gchar **titles = NULL;
1683 title_opts_set(GtkBuilder *builder, const gchar *name)
1686 GtkListStore *store;
1687 hb_list_t * list = NULL;
1688 hb_title_t * title = NULL;
1692 g_debug("title_opts_set ()\n");
1693 store = get_combo_box_store(builder, name);
1694 gtk_list_store_clear(store);
1697 list = hb_get_titles( h_scan );
1698 count = hb_list_count( list );
1699 if (count > 100) count = 100;
1701 if (titles) g_strfreev(titles);
1702 if (title_opts.map) g_free(title_opts.map);
1705 title_opts.count = count;
1706 title_opts.map = g_malloc(count*sizeof(options_map_t));
1707 titles = g_malloc((count+1) * sizeof(gchar*));
1711 title_opts.count = 1;
1712 title_opts.map = g_malloc(sizeof(options_map_t));
1717 // No titles. Fill in a default.
1718 gtk_list_store_append(store, &iter);
1719 gtk_list_store_set(store, &iter,
1726 title_opts.map[0].option = "No Titles";
1727 title_opts.map[0].shortOpt = "none";
1728 title_opts.map[0].ivalue = -1;
1729 title_opts.map[0].svalue = "none";
1732 for (ii = 0; ii < count; ii++)
1734 title = (hb_title_t*)hb_list_item(list, ii);
1735 if (title->duration != 0)
1737 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1738 title->index, title->hours, title->minutes, title->seconds);
1742 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1744 gtk_list_store_append(store, &iter);
1745 gtk_list_store_set(store, &iter,
1752 title_opts.map[ii].option = titles[ii];
1753 title_opts.map[ii].shortOpt = titles[ii];
1754 title_opts.map[ii].ivalue = ii;
1755 title_opts.map[ii].svalue = titles[ii];
1761 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1764 gboolean foundit = FALSE;
1766 if (gtk_tree_model_get_iter_first (store, iter))
1770 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1771 if (value == (int)ivalue)
1776 } while (gtk_tree_model_iter_next (store, iter));
1782 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1785 GtkListStore *store;
1786 hb_list_t * list = NULL;
1787 hb_title_t * title = NULL;
1788 hb_audio_config_t * audio;
1793 g_debug("audio_track_opts_set ()\n");
1794 store = get_combo_box_store(builder, name);
1795 gtk_list_store_clear(store);
1798 list = hb_get_titles( h_scan );
1799 title = (hb_title_t*)hb_list_item( list, titleindex );
1802 count = hb_list_count( title->list_audio );
1805 if (count > 100) count = 100;
1806 if (audio_track_opts.map) g_free(audio_track_opts.map);
1809 audio_track_opts.count = count;
1810 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1814 audio_track_opts.count = 1;
1815 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1819 // No audio. set some default
1820 gtk_list_store_append(store, &iter);
1821 gtk_list_store_set(store, &iter,
1822 0, "<small>No Audio</small>",
1828 audio_track_opts.map[0].option = "No Audio";
1829 audio_track_opts.map[0].shortOpt = "none";
1830 audio_track_opts.map[0].ivalue = -1;
1831 audio_track_opts.map[0].svalue = "none";
1834 index_str_init(count-1);
1835 for (ii = 0; ii < count; ii++)
1837 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1838 gtk_list_store_append(store, &iter);
1839 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
1840 gtk_list_store_set(store, &iter,
1848 audio_track_opts.map[ii].option = audio->lang.description,
1849 audio_track_opts.map[ii].shortOpt = index_str[ii];
1850 audio_track_opts.map[ii].ivalue = ii;
1851 audio_track_opts.map[ii].svalue = index_str[ii];
1856 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1859 GtkListStore *store;
1860 hb_list_t * list = NULL;
1861 hb_title_t * title = NULL;
1862 hb_subtitle_t * subtitle;
1864 static char ** options = NULL;
1866 g_debug("subtitle_track_opts_set ()\n");
1867 store = get_combo_box_store(builder, name);
1868 gtk_list_store_clear(store);
1871 list = hb_get_titles( h_scan );
1872 title = (hb_title_t*)hb_list_item( list, titleindex );
1875 count = hb_list_count( title->list_subtitle );
1878 if (count > 100) count = 100;
1879 if (subtitle_opts.map) g_free(subtitle_opts.map);
1882 subtitle_opts.count = count+1;
1883 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1887 subtitle_opts.count = LANG_TABLE_SIZE+1;
1888 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1890 gtk_list_store_append(store, &iter);
1891 gtk_list_store_set(store, &iter,
1892 0, "Foreign Audio Search",
1898 subtitle_opts.map[0].option = "Foreign Audio Search";
1899 subtitle_opts.map[0].shortOpt = "-1";
1900 subtitle_opts.map[0].ivalue = -1;
1901 subtitle_opts.map[0].svalue = "auto";
1904 if (options != NULL)
1905 g_strfreev(options);
1906 options = g_malloc((count+1)*sizeof(gchar*));
1907 index_str_init(count-1);
1908 for (ii = 0; ii < count; ii++)
1910 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1911 // Skip subtitles that must be burned if there is already
1912 // a burned subtitle in the list
1913 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1914 subtitle_opts.map[ii+1].option = options[ii];
1915 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1916 subtitle_opts.map[ii+1].ivalue = ii;
1917 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1918 gtk_list_store_append(store, &iter);
1919 gtk_list_store_set(store, &iter,
1924 4, subtitle->iso639_2,
1927 options[count] = NULL;
1931 index_str_init(LANG_TABLE_SIZE-1);
1932 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1936 if (ghb_language_table[ii].native_name[0] != 0)
1937 lang = ghb_language_table[ii].native_name;
1939 lang = ghb_language_table[ii].eng_name;
1941 subtitle_opts.map[ii+1].option = lang;
1942 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1943 subtitle_opts.map[ii+1].ivalue = ii;
1944 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1945 gtk_list_store_append(store, &iter);
1946 gtk_list_store_set(store, &iter,
1951 4, ghb_language_table[ii].iso639_2,
1964 guint64 longest = 0;
1965 gint titleindex = 0;
1967 g_debug("ghb_longest_title ()\n");
1968 if (h_scan == NULL) return 0;
1969 list = hb_get_titles( h_scan );
1970 count = hb_list_count( list );
1971 if (count > 100) count = 100;
1972 for (ii = 0; ii < count; ii++)
1974 title = (hb_title_t*)hb_list_item(list, ii);
1975 if (title->duration > longest)
1978 longest = title->duration;
1985 ghb_get_source_audio_lang(gint titleindex, gint track)
1989 hb_audio_config_t * audio;
1992 g_debug("ghb_lookup_1st_audio_lang ()\n");
1995 list = hb_get_titles( h_scan );
1996 title = (hb_title_t*)hb_list_item( list, titleindex );
1999 if (hb_list_count( title->list_audio ) <= track)
2002 audio = hb_list_audio_config_item(title->list_audio, track);
2006 lang = g_strdup(audio->lang.iso639_2);
2011 ghb_find_audio_track(
2015 GHashTable *track_indices)
2019 hb_audio_config_t * audio;
2026 g_debug("find_audio_track ()\n");
2027 if (h_scan == NULL) return -1;
2028 list = hb_get_titles( h_scan );
2029 title = (hb_title_t*)hb_list_item( list, titleindex );
2032 count = hb_list_count( title->list_audio );
2034 if (count > 10) count = 10;
2035 used = g_hash_table_lookup(track_indices, &acodec);
2038 used = g_malloc0(count * sizeof(gboolean));
2039 g_hash_table_insert(track_indices, &acodec, used);
2041 // Try to find an item that matches the preferred language and
2042 // the passthru codec type
2043 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2045 for (ii = 0; ii < count; ii++)
2052 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2053 title->list_audio, ii );
2054 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2055 audio->in.channel_layout);
2056 // Find a track that is not visually impaired or dirctor's
2057 // commentary, and has the highest channel count.
2058 if ((audio->in.codec & acodec) &&
2059 (audio->lang.type < 2) &&
2060 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2061 (strcmp(lang, "und") == 0)))
2063 if (channels > max_chan)
2066 max_chan = channels;
2076 // Try to find an item that matches the preferred language
2077 for (ii = 0; ii < count; ii++)
2081 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2082 title->list_audio, ii );
2083 // Find a track that is not visually impaired or dirctor's commentary
2084 if ((audio->lang.type < 2) &&
2085 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2086 (strcmp(lang, "und") == 0)))
2097 // Try to fine an item that does not match the preferred language and
2098 // matches the passthru codec type
2099 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2101 for (ii = 0; ii < count; ii++)
2108 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2109 title->list_audio, ii );
2110 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2111 audio->in.channel_layout);
2112 // Find a track that is not visually impaired or dirctor's
2113 // commentary, and has the highest channel count.
2114 if ((audio->in.codec & acodec) &&
2115 (audio->lang.type < 2))
2117 if (channels > max_chan)
2120 max_chan = channels;
2130 // Try to fine an item that does not match the preferred language
2131 for (ii = 0; ii < count; ii++)
2135 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2136 title->list_audio, ii );
2137 // Find a track that is not visually impaired or dirctor's commentary
2138 if (audio->lang.type < 2)
2149 // Last ditch, anything goes
2150 for (ii = 0; ii < count; ii++)
2152 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2153 title->list_audio, ii );
2168 ghb_find_pref_subtitle_track(const gchar *lang)
2171 count = subtitle_opts.count;
2172 for (ii = 0; ii < count; ii++)
2174 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2176 return subtitle_opts.map[ii].ivalue;
2183 ghb_find_cc_track(gint titleindex)
2187 hb_subtitle_t * subtitle;
2190 g_debug("ghb_find_cc_track ()\n");
2191 if (h_scan == NULL) return -2;
2192 list = hb_get_titles( h_scan );
2193 title = (hb_title_t*)hb_list_item( list, titleindex );
2196 count = hb_list_count( title->list_subtitle );
2197 // Try to find an item that matches the preferred language
2198 for (ii = 0; ii < count; ii++)
2200 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2201 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2209 ghb_find_subtitle_track(
2215 GHashTable * track_indices)
2219 hb_subtitle_t * subtitle;
2223 g_debug("find_subtitle_track ()\n");
2224 if (strcmp(lang, "auto") == 0)
2226 if (h_scan == NULL) return -1;
2227 list = hb_get_titles( h_scan );
2228 title = (hb_title_t*)hb_list_item( list, titleindex );
2231 count = hb_list_count( title->list_subtitle );
2232 used = g_hash_table_lookup(track_indices, lang);
2235 used = g_malloc0(count * sizeof(gboolean));
2236 g_hash_table_insert(track_indices, g_strdup(lang), used);
2238 // Try to find an item that matches the preferred language and source
2239 for (ii = 0; ii < count; ii++)
2244 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2245 if (source == subtitle->source &&
2246 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2247 (strcmp(lang, "und") == 0)))
2253 // Try to find an item that matches the preferred language
2254 for (ii = 0; ii < count; ii++)
2259 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2260 if (((burn || force) && (subtitle->source == VOBSUB)) &&
2261 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2262 (strcmp(lang, "und") == 0)))
2273 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2276 GtkListStore *store;
2279 g_debug("generic_opts_set ()\n");
2280 if (name == NULL || opts == NULL) return;
2281 store = get_combo_box_store(builder, name);
2282 gtk_list_store_clear(store);
2283 for (ii = 0; ii < opts->count; ii++)
2285 gtk_list_store_append(store, &iter);
2286 gtk_list_store_set(store, &iter,
2287 0, opts->map[ii].option,
2289 2, opts->map[ii].shortOpt,
2290 3, opts->map[ii].ivalue,
2291 4, opts->map[ii].svalue,
2297 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2300 GtkListStore *store;
2304 g_debug("generic_opts_set ()\n");
2305 if (name == NULL || opts == NULL) return;
2306 store = get_combo_box_store(builder, name);
2307 gtk_list_store_clear(store);
2308 for (ii = 0; ii < opts->count; ii++)
2310 gtk_list_store_append(store, &iter);
2311 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2312 gtk_list_store_set(store, &iter,
2315 2, opts->map[ii].shortOpt,
2316 3, opts->map[ii].ivalue,
2317 4, opts->map[ii].svalue,
2324 find_combo_table(const gchar *name)
2328 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2330 if (strcmp(name, combo_name_map[ii].name) == 0)
2332 return combo_name_map[ii].opts;
2339 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2343 if (strcmp(name, "AudioBitrate") == 0)
2344 return lookup_audio_bitrate_int(gval);
2345 else if (strcmp(name, "AudioSamplerate") == 0)
2346 return lookup_audio_rate_int(gval);
2347 else if (strcmp(name, "VideoFramerate") == 0)
2348 return lookup_video_rate_int(gval);
2349 else if (strcmp(name, "AudioMixdown") == 0)
2350 return lookup_mix_int(gval);
2351 else if (strcmp(name, "SrtLanguage") == 0)
2352 return lookup_audio_lang_int(gval);
2353 else if (strcmp(name, "PreferredLanguage") == 0)
2354 return lookup_audio_lang_int(gval);
2357 return lookup_generic_int(find_combo_table(name), gval);
2359 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2364 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2368 if (strcmp(name, "AudioBitrate") == 0)
2369 return lookup_audio_bitrate_int(gval);
2370 else if (strcmp(name, "AudioSamplerate") == 0)
2371 return lookup_audio_rate_int(gval);
2372 else if (strcmp(name, "VideoFramerate") == 0)
2373 return lookup_video_rate_int(gval);
2374 else if (strcmp(name, "AudioMixdown") == 0)
2375 return lookup_mix_int(gval);
2376 else if (strcmp(name, "SrtLanguage") == 0)
2377 return lookup_audio_lang_int(gval);
2378 else if (strcmp(name, "PreferredLanguage") == 0)
2379 return lookup_audio_lang_int(gval);
2382 return lookup_generic_double(find_combo_table(name), gval);
2384 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2389 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2393 if (strcmp(name, "AudioBitrate") == 0)
2394 return lookup_audio_bitrate_option(gval);
2395 else if (strcmp(name, "AudioSamplerate") == 0)
2396 return lookup_audio_rate_option(gval);
2397 else if (strcmp(name, "VideoFramerate") == 0)
2398 return lookup_video_rate_option(gval);
2399 else if (strcmp(name, "AudioMixdown") == 0)
2400 return lookup_mix_option(gval);
2401 else if (strcmp(name, "SrtLanguage") == 0)
2402 return lookup_audio_lang_option(gval);
2403 else if (strcmp(name, "PreferredLanguage") == 0)
2404 return lookup_audio_lang_option(gval);
2407 return lookup_generic_option(find_combo_table(name), gval);
2409 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2414 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2418 if (strcmp(name, "AudioBitrate") == 0)
2419 return lookup_audio_bitrate_option(gval);
2420 else if (strcmp(name, "AudioSamplerate") == 0)
2421 return lookup_audio_rate_option(gval);
2422 else if (strcmp(name, "VideoFramerate") == 0)
2423 return lookup_video_rate_option(gval);
2424 else if (strcmp(name, "AudioMixdown") == 0)
2425 return lookup_mix_option(gval);
2426 else if (strcmp(name, "SrtLanguage") == 0)
2427 return lookup_audio_lang_option(gval);
2428 else if (strcmp(name, "PreferredLanguage") == 0)
2429 return lookup_audio_lang_option(gval);
2432 return lookup_generic_string(find_combo_table(name), gval);
2434 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2439 ghb_update_ui_combo_box(
2440 signal_user_data_t *ud,
2445 GtkComboBox *combo = NULL;
2447 gint handler_id = 0;
2451 g_debug("ghb_update_ui_combo_box() %s\n", name);
2452 // Clearing a combo box causes a rash of "changed" events, even when
2453 // the active item is -1 (inactive). To control things, I'm disabling
2454 // the event till things are settled down.
2455 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2456 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2459 // Valid signal id found. This should always succeed.
2460 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2461 signal_id, 0, 0, 0, 0);
2464 // This should also always succeed
2465 g_signal_handler_block ((gpointer)combo, handler_id);
2471 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2472 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2473 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2474 mix_opts_set(ud->builder, "AudioMixdown");
2475 language_opts_set(ud->builder, "SrtLanguage");
2476 language_opts_set(ud->builder, "PreferredLanguage");
2477 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2478 title_opts_set(ud->builder, "title");
2479 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2480 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2481 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2482 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2483 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2484 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2485 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2486 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2487 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2488 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2489 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2490 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2491 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2492 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2493 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2494 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2495 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2496 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2497 generic_opts_set(ud->builder, "x264_me", &me_opts);
2498 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2499 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2500 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2504 if (strcmp(name, "AudioBitrate") == 0)
2505 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2506 else if (strcmp(name, "AudioSamplerate") == 0)
2507 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2508 else if (strcmp(name, "VideoFramerate") == 0)
2509 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2510 else if (strcmp(name, "AudioMixdown") == 0)
2511 mix_opts_set(ud->builder, "AudioMixdown");
2512 else if (strcmp(name, "SrtLanguage") == 0)
2513 language_opts_set(ud->builder, "SrtLanguage");
2514 else if (strcmp(name, "PreferredLanguage") == 0)
2515 language_opts_set(ud->builder, "PreferredLanguage");
2516 else if (strcmp(name, "SrtCodeset") == 0)
2517 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2518 else if (strcmp(name, "title") == 0)
2519 title_opts_set(ud->builder, "title");
2520 else if (strcmp(name, "SubtitleTrack") == 0)
2521 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2522 else if (strcmp(name, "AudioTrack") == 0)
2523 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2525 generic_opts_set(ud->builder, name, find_combo_table(name));
2529 g_signal_handler_unblock ((gpointer)combo, handler_id);
2534 init_ui_combo_boxes(GtkBuilder *builder)
2538 init_combo_box(builder, "AudioBitrate");
2539 init_combo_box(builder, "AudioSamplerate");
2540 init_combo_box(builder, "VideoFramerate");
2541 init_combo_box(builder, "AudioMixdown");
2542 init_combo_box(builder, "SrtLanguage");
2543 init_combo_box(builder, "PreferredLanguage");
2544 init_combo_box(builder, "SrtCodeset");
2545 init_combo_box(builder, "title");
2546 init_combo_box(builder, "AudioTrack");
2547 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2549 init_combo_box(builder, combo_name_map[ii].name);
2553 static const char * turbo_opts =
2554 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2555 "no-fast-pskip=0:8x8dct=0";
2557 // Construct the x264 options string
2558 // The result is allocated, so someone must free it at some point.
2560 ghb_build_x264opts_string(GValue *settings)
2563 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2570 result = g_strdup("");
2576 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2580 hb_chapter_t * chapter;
2583 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2584 *hh = *mm = *ss = 0;
2585 if (h_scan == NULL) return;
2586 list = hb_get_titles( h_scan );
2587 title = (hb_title_t*)hb_list_item( list, ti );
2588 if (title == NULL) return;
2589 count = hb_list_count( title->list_chapter );
2590 if (ii >= count) return;
2591 chapter = hb_list_item(title->list_chapter, ii);
2592 if (chapter == NULL) return;
2593 *hh = chapter->hours;
2594 *mm = chapter->minutes;
2595 *ss = chapter->seconds;
2599 ghb_get_chapters(gint titleindex)
2603 hb_chapter_t * chapter;
2605 GValue *chapters = NULL;
2607 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2608 if (h_scan == NULL) return NULL;
2609 list = hb_get_titles( h_scan );
2610 title = (hb_title_t*)hb_list_item( list, titleindex );
2611 if (title == NULL) return NULL;
2612 count = hb_list_count( title->list_chapter );
2613 chapters = ghb_array_value_new(count);
2614 for (ii = 0; ii < count; ii++)
2616 chapter = hb_list_item(title->list_chapter, ii);
2617 if (chapter == NULL) break;
2618 if (chapter->title == NULL || chapter->title[0] == 0)
2621 str = g_strdup_printf ("Chapter %2d", ii+1);
2622 ghb_array_append(chapters, ghb_string_value_new(str));
2627 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2634 ghb_ac3_in_audio_list(const GValue *audio_list)
2638 count = ghb_array_len(audio_list);
2639 for (ii = 0; ii < count; ii++)
2644 asettings = ghb_array_get_nth(audio_list, ii);
2645 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2646 if (acodec & HB_ACODEC_AC3)
2653 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2656 GtkListStore *store;
2659 g_debug("audio_bitrate_opts_add ()\n");
2661 if (rate < 8) return;
2663 store = get_combo_box_store(builder, name);
2664 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2666 str = g_strdup_printf ("<small>%d</small>", rate);
2667 gtk_list_store_append(store, &iter);
2668 gtk_list_store_set(store, &iter,
2680 audio_bitrate_opts_clean(
2681 GtkBuilder *builder,
2687 GtkListStore *store;
2689 gboolean done = FALSE;
2691 guint last = (guint)last_rate;
2692 guint first = (guint)first_rate;
2694 g_debug("audio_bitrate_opts_clean ()\n");
2695 store = get_combo_box_store(builder, name);
2696 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2700 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2702 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2704 done = !gtk_list_store_remove(store, &iter);
2706 else if (ivalue < first || ivalue > last)
2709 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2710 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2715 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2716 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2723 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2726 GtkListStore *store;
2730 g_debug("audio_bitrate_opts_set ()\n");
2731 store = get_combo_box_store(builder, name);
2732 gtk_list_store_clear(store);
2733 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2735 gtk_list_store_append(store, &iter);
2736 str = g_strdup_printf ("<small>%s</small>",
2737 hb_audio_bitrates[ii].string);
2738 gtk_list_store_set(store, &iter,
2741 2, hb_audio_bitrates[ii].string,
2742 3, (gdouble)hb_audio_bitrates[ii].rate,
2743 4, hb_audio_bitrates[ii].string,
2750 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2752 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2756 ghb_set_default_bitrate_opts(
2757 GtkBuilder *builder,
2761 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
2764 static ghb_status_t hb_status;
2767 ghb_combo_init(signal_user_data_t *ud)
2769 // Set up the list model for the combos
2770 init_ui_combo_boxes(ud->builder);
2771 // Populate all the combos
2772 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2776 ghb_backend_init(gint debug)
2779 h_scan = hb_init( debug, 0 );
2780 h_queue = hb_init( debug, 0 );
2791 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2793 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2794 hb_status.scan.state |= GHB_STATE_SCANNING;
2795 // initialize count and cur to something that won't cause FPE
2796 // when computing progress
2797 hb_status.scan.title_count = 1;
2798 hb_status.scan.title_cur = 0;
2802 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2804 g_debug("ghb_backend_queue_scan()");
2805 hb_scan( h_queue, path, titlenum, 10, 0 );
2806 hb_status.queue.state |= GHB_STATE_SCANNING;
2810 ghb_get_scan_state()
2812 return hb_status.scan.state;
2816 ghb_get_queue_state()
2818 return hb_status.queue.state;
2822 ghb_clear_scan_state(gint state)
2824 hb_status.scan.state &= ~state;
2828 ghb_clear_queue_state(gint state)
2830 hb_status.queue.state &= ~state;
2834 ghb_set_scan_state(gint state)
2836 hb_status.scan.state |= state;
2840 ghb_set_queue_state(gint state)
2842 hb_status.queue.state |= state;
2846 ghb_get_status(ghb_status_t *status)
2848 memcpy(status, &hb_status, sizeof(ghb_status_t));
2857 if (h_scan == NULL) return;
2858 hb_get_state( h_scan, &s_scan );
2859 switch( s_scan.state )
2861 #define p s_scan.param.scanning
2862 case HB_STATE_SCANNING:
2864 hb_status.scan.state |= GHB_STATE_SCANNING;
2865 hb_status.scan.title_count = p.title_count;
2866 hb_status.scan.title_cur = p.title_cur;
2870 case HB_STATE_SCANDONE:
2872 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2873 hb_status.scan.state |= GHB_STATE_SCANDONE;
2876 #define p s_scan.param.working
2877 case HB_STATE_WORKING:
2878 hb_status.scan.state |= GHB_STATE_WORKING;
2879 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2880 hb_status.scan.job_cur = p.job_cur;
2881 hb_status.scan.job_count = p.job_count;
2882 hb_status.scan.progress = p.progress;
2883 hb_status.scan.rate_cur = p.rate_cur;
2884 hb_status.scan.rate_avg = p.rate_avg;
2885 hb_status.scan.hours = p.hours;
2886 hb_status.scan.minutes = p.minutes;
2887 hb_status.scan.seconds = p.seconds;
2888 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2892 case HB_STATE_PAUSED:
2893 hb_status.scan.state |= GHB_STATE_PAUSED;
2896 case HB_STATE_MUXING:
2898 hb_status.scan.state |= GHB_STATE_MUXING;
2901 #define p s_scan.param.workdone
2902 case HB_STATE_WORKDONE:
2906 hb_status.scan.state |= GHB_STATE_WORKDONE;
2907 hb_status.scan.state &= ~GHB_STATE_MUXING;
2908 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2909 hb_status.scan.state &= ~GHB_STATE_WORKING;
2913 hb_status.scan.error = GHB_ERROR_NONE;
2915 case HB_ERROR_CANCELED:
2916 hb_status.scan.error = GHB_ERROR_CANCELED;
2919 hb_status.scan.error = GHB_ERROR_FAIL;
2922 // Delete all remaining jobs of this encode.
2923 // An encode can be composed of multiple associated jobs.
2924 // When a job is stopped, libhb removes it from the job list,
2925 // but does not remove other jobs that may be associated with it.
2926 // Associated jobs are taged in the sequence id.
2927 while ((job = hb_job(h_scan, 0)) != NULL)
2928 hb_rem( h_scan, job );
2932 hb_get_state( h_queue, &s_queue );
2933 switch( s_queue.state )
2935 #define p s_queue.param.scanning
2936 case HB_STATE_SCANNING:
2938 hb_status.queue.state |= GHB_STATE_SCANNING;
2939 hb_status.queue.title_count = p.title_count;
2940 hb_status.queue.title_cur = p.title_cur;
2944 case HB_STATE_SCANDONE:
2946 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2947 hb_status.queue.state |= GHB_STATE_SCANDONE;
2950 #define p s_queue.param.working
2951 case HB_STATE_WORKING:
2952 hb_status.queue.state |= GHB_STATE_WORKING;
2953 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2954 hb_status.queue.job_cur = p.job_cur;
2955 hb_status.queue.job_count = p.job_count;
2956 hb_status.queue.progress = p.progress;
2957 hb_status.queue.rate_cur = p.rate_cur;
2958 hb_status.queue.rate_avg = p.rate_avg;
2959 hb_status.queue.hours = p.hours;
2960 hb_status.queue.minutes = p.minutes;
2961 hb_status.queue.seconds = p.seconds;
2962 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2966 case HB_STATE_PAUSED:
2967 hb_status.queue.state |= GHB_STATE_PAUSED;
2970 case HB_STATE_MUXING:
2972 hb_status.queue.state |= GHB_STATE_MUXING;
2975 #define p s_queue.param.workdone
2976 case HB_STATE_WORKDONE:
2980 hb_status.queue.state |= GHB_STATE_WORKDONE;
2981 hb_status.queue.state &= ~GHB_STATE_MUXING;
2982 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2983 hb_status.queue.state &= ~GHB_STATE_WORKING;
2987 hb_status.queue.error = GHB_ERROR_NONE;
2989 case HB_ERROR_CANCELED:
2990 hb_status.queue.error = GHB_ERROR_CANCELED;
2993 hb_status.queue.error = GHB_ERROR_FAIL;
2996 // Delete all remaining jobs of this encode.
2997 // An encode can be composed of multiple associated jobs.
2998 // When a job is stopped, libhb removes it from the job list,
2999 // but does not remove other jobs that may be associated with it.
3000 // Associated jobs are taged in the sequence id.
3001 while ((job = hb_job(h_queue, 0)) != NULL)
3002 hb_rem( h_queue, job );
3009 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3014 if (h_scan == NULL) return FALSE;
3015 list = hb_get_titles( h_scan );
3016 if( !hb_list_count( list ) )
3018 /* No valid title, stop right there */
3022 title = hb_list_item( list, titleindex );
3023 if (title == NULL) return FALSE; // Bad titleindex
3024 tinfo->width = title->width;
3025 tinfo->height = title->height;
3026 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3027 // Don't allow crop to 0
3028 if (title->crop[0] + title->crop[1] >= title->height)
3029 title->crop[0] = title->crop[1] = 0;
3030 if (title->crop[2] + title->crop[3] >= title->width)
3031 title->crop[2] = title->crop[3] = 0;
3032 tinfo->num_chapters = hb_list_count(title->list_chapter);
3033 tinfo->rate_base = title->rate_base;
3034 tinfo->rate = title->rate;
3035 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3036 title->width * title->pixel_aspect_width,
3037 title->height * title->pixel_aspect_height);
3038 tinfo->hours = title->hours;
3039 tinfo->minutes = title->minutes;
3040 tinfo->seconds = title->seconds;
3041 tinfo->duration = title->duration;
3043 tinfo->angle_count = title->angle_count;
3048 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3050 hb_audio_config_t *audio;
3052 audio = get_hb_audio(titleindex, audioindex);
3053 if (audio == NULL) return FALSE; // Bad audioindex
3054 ainfo->codec = audio->in.codec;
3055 ainfo->bitrate = audio->in.bitrate;
3056 ainfo->samplerate = audio->in.samplerate;
3061 ghb_audio_is_passthru(gint acodec)
3063 g_debug("ghb_audio_is_passthru () \n");
3064 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
3068 ghb_get_default_acodec()
3070 return HB_ACODEC_FAAC;
3074 picture_settings_deps(signal_user_data_t *ud)
3076 gboolean autoscale, keep_aspect, enable_keep_aspect;
3077 gboolean enable_scale_width, enable_scale_height;
3078 gboolean enable_disp_width, enable_disp_height, enable_par;
3082 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3085 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3086 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3087 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3089 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3090 if (!enable_keep_aspect)
3092 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3094 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3095 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3097 enable_scale_width = !autoscale && (pic_par != 1);
3098 enable_scale_height = !autoscale && (pic_par != 1);
3099 enable_disp_width = (pic_par == 3) && !keep_aspect;
3100 enable_par = (pic_par == 3) && !keep_aspect;
3101 enable_disp_height = FALSE;
3103 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3104 gtk_widget_set_sensitive(widget, pic_par != 1);
3105 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3106 gtk_widget_set_sensitive(widget, pic_par != 1);
3107 widget = GHB_WIDGET(ud->builder, "scale_width");
3108 gtk_widget_set_sensitive(widget, enable_scale_width);
3109 widget = GHB_WIDGET(ud->builder, "scale_height");
3110 gtk_widget_set_sensitive(widget, enable_scale_height);
3111 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3112 gtk_widget_set_sensitive(widget, enable_disp_width);
3113 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3114 gtk_widget_set_sensitive(widget, enable_disp_height);
3115 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3116 gtk_widget_set_sensitive(widget, enable_par);
3117 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3118 gtk_widget_set_sensitive(widget, enable_par);
3119 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3120 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3121 widget = GHB_WIDGET(ud->builder, "autoscale");
3122 gtk_widget_set_sensitive(widget, pic_par != 1);
3126 ghb_set_scale(signal_user_data_t *ud, gint mode)
3131 gboolean keep_aspect;
3133 gboolean autocrop, autoscale, noscale;
3134 gint crop[4], width, height, par_width, par_height;
3135 gint crop_width, crop_height;
3136 gint aspect_n, aspect_d;
3137 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3138 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3143 gint max_height = 0;
3144 static gboolean busy = FALSE;
3146 g_debug("ghb_set_scale ()\n");
3147 if (h_scan == NULL) return;
3148 list = hb_get_titles( h_scan );
3149 if( !hb_list_count( list ) )
3151 /* No valid title, stop right there */
3156 titleindex = ghb_settings_combo_int(ud->settings, "title");
3157 title = hb_list_item( list, titleindex );
3158 if (title == NULL) return;
3160 if (job == NULL) return;
3162 picture_settings_deps(ud);
3166 if (!ud->dont_clear_presets && (keep_width || keep_height))
3168 ghb_settings_set_int(ud->settings, "PictureWidth", 0);
3169 ghb_settings_set_int(ud->settings, "PictureHeight", 0);
3172 // First configure widgets
3173 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3174 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3175 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3176 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3177 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3178 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3179 // alignment constraints rather than scaling to satisfy them.
3180 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3181 // Align dimensions to either 16 or 2 pixels
3182 // The scaler crashes if the dimensions are not divisible by 2
3183 // x264 also will not accept dims that are not multiple of 2
3187 keep_height = FALSE;
3189 // Step needs to be at least 2 because odd widths cause scaler crash
3191 widget = GHB_WIDGET (ud->builder, "scale_width");
3192 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3193 widget = GHB_WIDGET (ud->builder, "scale_height");
3194 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3197 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3198 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3199 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3200 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3201 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3202 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3203 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3204 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3208 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3209 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3210 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3211 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3212 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3213 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3214 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3215 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3217 ghb_title_info_t tinfo;
3218 ghb_get_title_info (&tinfo, titleindex);
3221 crop[0] = tinfo.crop[0];
3222 crop[1] = tinfo.crop[1];
3223 crop[2] = tinfo.crop[2];
3224 crop[3] = tinfo.crop[3];
3225 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3226 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3227 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3228 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3232 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3233 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3234 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3235 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3241 // Adjust the cropping to accomplish the desired width and height
3242 crop_width = tinfo.width - crop[2] - crop[3];
3243 crop_height = tinfo.height - crop[0] - crop[1];
3244 width = MOD_DOWN(crop_width, mod);
3245 height = MOD_DOWN(crop_height, mod);
3247 need1 = (crop_height - height) / 2;
3248 need2 = crop_height - height - need1;
3251 need1 = (crop_width - width) / 2;
3252 need2 = crop_width - width - need1;
3255 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3256 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3257 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3258 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3260 hb_reduce(&aspect_n, &aspect_d,
3261 title->width * title->pixel_aspect_width,
3262 title->height * title->pixel_aspect_height);
3263 crop_width = title->width - crop[2] - crop[3];
3264 crop_height = title->height - crop[0] - crop[1];
3268 height = crop_height;
3272 width = ghb_settings_get_int(ud->settings, "scale_width");
3273 height = ghb_settings_get_int(ud->settings, "scale_height");
3274 max_width = MOD_DOWN(
3275 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3276 max_height = MOD_DOWN(
3277 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3279 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3282 width = title->width - crop[2] - crop[3];
3284 height = title->height - crop[0] - crop[1];
3286 width = MOD_ROUND(width, mod);
3287 height = MOD_ROUND(height, mod);
3289 // Adjust dims according to max values
3291 height = MIN(height, max_height);
3293 width = MIN(width, max_width);
3297 job->anamorphic.mode = pic_par;
3298 // The scaler crashes if the dimensions are not divisible by 2
3299 // Align mod 2. And so does something in x264_encoder_headers()
3300 job->anamorphic.modulus = mod;
3301 job->anamorphic.par_width = title->pixel_aspect_width;
3302 job->anamorphic.par_height = title->pixel_aspect_height;
3303 job->anamorphic.dar_width = 0;
3304 job->anamorphic.dar_height = 0;
3306 if (keep_height && pic_par == 2)
3307 width = ((double)height * crop_width / crop_height) + mod / 2;
3309 job->height = height;
3310 job->maxWidth = max_width;
3311 job->maxHeight = max_height;
3312 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3313 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3314 if (job->anamorphic.mode == 3 && !keep_aspect)
3316 job->anamorphic.keep_display_aspect = 0;
3317 if (mode & GHB_PIC_KEEP_PAR)
3319 job->anamorphic.par_width =
3320 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3321 job->anamorphic.par_height =
3322 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3326 job->anamorphic.dar_width =
3327 ghb_settings_get_int(ud->settings,
3328 "PictureDisplayWidth");
3329 job->anamorphic.dar_height = height;
3334 job->anamorphic.keep_display_aspect = 1;
3336 hb_set_anamorphic_size( job, &width, &height,
3337 &par_width, &par_height );
3338 if (job->anamorphic.mode == 3 && !keep_aspect &&
3339 mode & GHB_PIC_KEEP_PAR)
3341 // hb_set_anamorphic_size reduces the par, which we
3342 // don't want in this case because the user is
3343 // explicitely specifying it.
3344 par_width = ghb_settings_get_int(ud->settings,
3346 par_height = ghb_settings_get_int(ud->settings,
3347 "PicturePARHeight");
3352 job->anamorphic.mode = pic_par;
3356 gint new_width, new_height;
3358 // Compute pixel aspect ration.
3359 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3360 // Must scale so that par becomes 1:1
3361 // Try to keep largest dimension
3362 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3363 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3365 if (max_width && new_width > max_width)
3367 height = new_height;
3369 else if (max_height && new_height > max_height)
3373 else if (keep_width)
3375 height = new_height;
3377 else if (keep_height)
3381 else if (width > new_width)
3383 height = new_height;
3389 g_debug("new w %d h %d\n", width, height);
3391 width = MOD_ROUND(width, mod);
3392 height = MOD_ROUND(height, mod);
3394 height = MIN(height, max_height);
3396 width = MIN(width, max_width);
3397 par_width = par_height = 1;
3399 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3400 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3402 gint disp_width, dar_width, dar_height;
3405 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3406 hb_reduce(&dar_width, &dar_height, disp_width, height);
3408 gint iaspect = dar_width * 9 / dar_height;
3409 if (dar_width > 2 * dar_height)
3411 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3413 else if (iaspect <= 16 && iaspect >= 15)
3415 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3417 else if (iaspect <= 12 && iaspect >= 11)
3419 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3423 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3425 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3427 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3428 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3429 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3430 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3435 set_preview_job_settings(hb_job_t *job, GValue *settings)
3437 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3438 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3439 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3440 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3442 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3443 job->anamorphic.modulus =
3444 ghb_settings_combo_int(settings, "PictureModulus");
3445 job->width = ghb_settings_get_int(settings, "scale_width");
3446 job->height = ghb_settings_get_int(settings, "scale_height");
3447 if (ghb_settings_get_boolean(settings, "show_crop"))
3449 gdouble xscale = (gdouble)job->width /
3450 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3451 gdouble yscale = (gdouble)job->height /
3452 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3454 job->width += xscale * (job->crop[2] + job->crop[3]);
3455 job->height += yscale * (job->crop[0] + job->crop[1]);
3460 job->anamorphic.modulus = 2;
3463 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3466 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3467 job->deinterlace = (decomb == 0) ? 0 : 1;
3471 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3472 job->deinterlace = (deint == 0) ? 0 : 1;
3475 gboolean keep_aspect;
3476 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3477 if (job->anamorphic.mode)
3479 job->anamorphic.par_width = job->title->pixel_aspect_width;
3480 job->anamorphic.par_height = job->title->pixel_aspect_height;
3481 job->anamorphic.dar_width = 0;
3482 job->anamorphic.dar_height = 0;
3484 if (job->anamorphic.mode == 3 && !keep_aspect)
3486 job->anamorphic.keep_display_aspect = 0;
3487 job->anamorphic.par_width =
3488 ghb_settings_get_int(settings, "PicturePARWidth");
3489 job->anamorphic.par_height =
3490 ghb_settings_get_int(settings, "PicturePARHeight");
3494 job->anamorphic.keep_display_aspect = 1;
3500 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3507 if (h_scan == NULL) return 1500;
3508 list = hb_get_titles( h_scan );
3509 title = hb_list_item( list, titleindex );
3510 if (title == NULL) return 1500;
3512 if (job == NULL) return 1500;
3513 size = ghb_settings_get_int(settings, "VideoTargetSize");
3514 return hb_calc_bitrate( job, size );
3518 ghb_validate_filter_string(const gchar *str, gint max_fields)
3524 if (str == NULL || *str == 0) return TRUE;
3527 val = g_strtod(str, &end);
3529 { // Found a numeric value
3531 // negative max_fields means infinate
3532 if (max_fields >= 0 && fields > max_fields) return FALSE;
3546 ghb_validate_filters(signal_user_data_t *ud)
3552 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3554 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3555 if (!decomb_deint && index == 1)
3557 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3558 if (!ghb_validate_filter_string(str, -1))
3560 message = g_strdup_printf(
3561 "Invalid Deinterlace Settings:\n\n%s\n",
3563 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3571 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3574 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3575 if (!ghb_validate_filter_string(str, -1))
3577 message = g_strdup_printf(
3578 "Invalid Detelecine Settings:\n\n%s\n",
3580 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3588 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3589 if (decomb_deint && index == 1)
3591 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3592 if (!ghb_validate_filter_string(str, -1))
3594 message = g_strdup_printf(
3595 "Invalid Decomb Settings:\n\n%s\n",
3597 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3605 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3608 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3609 if (!ghb_validate_filter_string(str, -1))
3611 message = g_strdup_printf(
3612 "Invalid Denoise Settings:\n\n%s\n",
3614 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3625 ghb_validate_video(signal_user_data_t *ud)
3630 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3631 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3632 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
3634 // mp4/theora combination is not supported.
3635 message = g_strdup_printf(
3636 "Theora is not supported in the MP4 container.\n\n"
3637 "You should choose a different video codec or container.\n"
3638 "If you continue, FFMPEG will be chosen for you.");
3639 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3645 vcodec = HB_VCODEC_FFMPEG;
3646 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3652 ghb_validate_subtitles(signal_user_data_t *ud)
3658 if (h_scan == NULL) return FALSE;
3659 list = hb_get_titles( h_scan );
3660 if( !hb_list_count( list ) )
3662 /* No valid title, stop right there */
3663 g_message("No title found.\n");
3669 titleindex = ghb_settings_combo_int(ud->settings, "title");
3670 title = hb_list_item( list, titleindex );
3671 if (title == NULL) return FALSE;
3672 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3674 const GValue *slist, *settings;
3675 gint count, ii, source;
3676 gboolean burned, one_burned = FALSE;
3678 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3679 count = ghb_array_len(slist);
3680 for (ii = 0; ii < count; ii++)
3682 settings = ghb_array_get_nth(slist, ii);
3683 source = ghb_settings_get_int(settings, "SubtitleSource");
3684 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3685 if (burned && one_burned)
3687 // MP4 can only handle burned vobsubs. make sure there isn't
3688 // already something burned in the list
3689 message = g_strdup_printf(
3690 "Only one subtitle may be burned into the video.\n\n"
3691 "You should change your subtitle selections.\n"
3692 "If you continue, some subtitles will be lost.");
3693 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3705 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3707 // MP4 can only handle burned vobsubs. make sure there isn't
3708 // already something burned in the list
3709 message = g_strdup_printf(
3710 "Your chosen container does not support soft bitmap subtitles.\n\n"
3711 "You should change your subtitle selections.\n"
3712 "If you continue, some subtitles will be lost.");
3713 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3714 "Cancel", "Continue"))
3722 if (source == SRTSUB)
3726 filename = ghb_settings_get_string(settings, "SrtFile");
3727 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3729 message = g_strdup_printf(
3730 "Srt file does not exist or not a regular file.\n\n"
3731 "You should choose a valid file.\n"
3732 "If you continue, this subtitle will be ignored.");
3733 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3734 "Cancel", "Continue"))
3748 ghb_select_audio_codec(signal_user_data_t *ud, gint track)
3752 hb_audio_config_t *audio;
3754 if (h_scan == NULL) return -1;
3755 list = hb_get_titles( h_scan );
3756 if( !hb_list_count( list ) )
3763 titleindex = ghb_settings_combo_int(ud->settings, "title");
3764 title = hb_list_item( list, titleindex );
3765 if (title == NULL) return -1;
3767 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3769 if (track < 0 || track >= hb_list_count(title->list_audio))
3772 audio = (hb_audio_config_t *) hb_list_audio_config_item(
3773 title->list_audio, track );
3774 if (mux == HB_MUX_MP4)
3776 if (audio->in.codec == HB_ACODEC_AC3)
3777 return audio->in.codec;
3779 return HB_ACODEC_FAAC;
3783 if (audio->in.codec == HB_ACODEC_AC3 || audio->in.codec == HB_ACODEC_DCA)
3784 return audio->in.codec;
3786 return HB_ACODEC_LAME;
3791 ghb_select_audio_codec_str(signal_user_data_t *ud, gint track)
3795 acodec = ghb_select_audio_codec(ud, track);
3796 for (ii = 0; ii < acodec_opts.count; ii++)
3798 if (acodec_opts.map[ii].ivalue == acodec)
3799 return acodec_opts.map[ii].option;
3805 ghb_validate_audio(signal_user_data_t *ud)
3812 if (h_scan == NULL) return FALSE;
3813 list = hb_get_titles( h_scan );
3814 if( !hb_list_count( list ) )
3816 /* No valid title, stop right there */
3817 g_message("No title found.\n");
3823 titleindex = ghb_settings_combo_int(ud->settings, "title");
3824 title = hb_list_item( list, titleindex );
3825 if (title == NULL) return FALSE;
3826 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3828 const GValue *audio_list;
3831 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3832 count = ghb_array_len(audio_list);
3833 for (ii = 0; ii < count; ii++)
3836 hb_audio_config_t *taudio;
3838 asettings = ghb_array_get_nth(audio_list, ii);
3839 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3840 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3841 if (codec == HB_ACODEC_MASK)
3844 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3845 title->list_audio, track );
3846 if (!(taudio->in.codec & codec) &&
3847 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3849 // Not supported. AC3 is passthrough only, so input must be AC3
3850 message = g_strdup_printf(
3851 "The source does not support Pass-Thru.\n\n"
3852 "You should choose a different audio codec.\n"
3853 "If you continue, one will be chosen for you.");
3854 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3860 if (mux == HB_MUX_MKV)
3862 codec = HB_ACODEC_LAME;
3866 codec = HB_ACODEC_FAAC;
3868 value = get_acodec_value(codec);
3869 ghb_settings_take_value(asettings, "AudioEncoder", value);
3871 gchar *a_unsup = NULL;
3872 gchar *mux_s = NULL;
3873 if (mux == HB_MUX_MP4)
3876 // mp4/mp3|vorbis combination is not supported.
3877 if (codec == HB_ACODEC_LAME)
3880 codec = HB_ACODEC_FAAC;
3882 if (codec == HB_ACODEC_VORBIS)
3885 codec = HB_ACODEC_FAAC;
3887 if (codec == HB_ACODEC_DCA)
3890 codec = HB_ACODEC_FAAC;
3895 message = g_strdup_printf(
3896 "%s is not supported in the %s container.\n\n"
3897 "You should choose a different audio codec.\n"
3898 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3899 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3905 value = get_acodec_value(codec);
3906 ghb_settings_take_value(asettings, "AudioEncoder", value);
3908 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3909 gboolean allow_mono = TRUE;
3910 gboolean allow_stereo = TRUE;
3911 gboolean allow_dolby = TRUE;
3912 gboolean allow_dpl2 = TRUE;
3913 gboolean allow_6ch = TRUE;
3915 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3916 (codec & ~HB_ACODEC_LAME);
3917 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3919 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3921 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3922 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3923 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3924 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3926 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3927 (codec & ~HB_ACODEC_LAME) &&
3928 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3929 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3931 gchar *mix_unsup = NULL;
3932 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3936 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3938 mix_unsup = "stereo";
3940 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3942 mix_unsup = "Dolby";
3944 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3946 mix_unsup = "Dolby Pro Logic II";
3948 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3950 mix_unsup = "6 Channel";
3954 message = g_strdup_printf(
3955 "The source audio does not support %s mixdown.\n\n"
3956 "You should choose a different mixdown.\n"
3957 "If you continue, one will be chosen for you.", mix_unsup);
3958 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3964 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3965 value = get_amix_value(mix);
3966 ghb_settings_take_value(asettings, "AudioMixdown", value);
3973 ghb_validate_vquality(GValue *settings)
3979 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3980 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3982 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3983 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3987 case HB_VCODEC_X264:
3993 case HB_VCODEC_FFMPEG:
3999 case HB_VCODEC_THEORA:
4011 if (vquality < min || vquality > max)
4013 message = g_strdup_printf(
4014 "Interesting video quality choise: %d\n\n"
4015 "Typical values range from %d to %d.\n"
4016 "Are you sure you wish to use this setting?",
4017 (gint)vquality, min, max);
4018 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4019 "Cancel", "Continue"))
4031 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4036 static gchar *x264opts;
4038 gboolean tweaks = FALSE;
4039 gchar *detel_str = NULL;
4040 gchar *decomb_str = NULL;
4041 gchar *deint_str = NULL;
4042 gchar *deblock_str = NULL;
4043 gchar *denoise_str = NULL;
4044 gchar *dest_str = NULL;
4046 g_debug("add_job()\n");
4047 if (h == NULL) return;
4048 list = hb_get_titles( h );
4049 if( !hb_list_count( list ) )
4051 /* No valid title, stop right there */
4055 title = hb_list_item( list, titleindex );
4056 if (title == NULL) return;
4058 /* Set job settings */
4060 if (job == NULL) return;
4062 job->angle = ghb_settings_get_int(js, "angle");
4063 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4064 if (job->start_at_preview)
4066 job->seek_points = ghb_settings_get_int(js, "preview_count");
4067 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4070 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4071 job->mux = ghb_settings_combo_int(js, "FileFormat");
4072 if (job->mux == HB_MUX_MP4)
4074 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4075 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4079 job->largeFileSize = FALSE;
4080 job->mp4_optimize = FALSE;
4082 if (!job->start_at_preview)
4084 gint chapter_start, chapter_end;
4085 chapter_start = ghb_settings_get_int(js, "start_chapter");
4086 chapter_end = ghb_settings_get_int(js, "end_chapter");
4087 gint num_chapters = hb_list_count(title->list_chapter);
4088 job->chapter_start = MIN( num_chapters, chapter_start );
4089 job->chapter_end = MAX( job->chapter_start, chapter_end );
4091 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4092 if (job->chapter_start == job->chapter_end)
4093 job->chapter_markers = 0;
4094 if ( job->chapter_markers )
4101 chapters = ghb_settings_get_value(js, "chapter_list");
4102 count = ghb_array_len(chapters);
4103 for(chap = chapter_start; chap <= chapter_end; chap++)
4105 hb_chapter_t * chapter_s;
4111 chapter = ghb_array_get_nth(chapters, chap-1);
4112 name = ghb_value_string(chapter);
4116 name = g_strdup_printf ("Chapter %2d", chap);
4118 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
4119 strncpy(chapter_s->title, name, 1023);
4120 chapter_s->title[1023] = '\0';
4125 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4126 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4127 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4128 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4131 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4132 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4133 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4135 job->deinterlace = (deint != 0) ? 1 : 0;
4137 job->deinterlace = 0;
4138 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4140 gboolean keep_aspect;
4141 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4142 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4143 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
4144 if (job->anamorphic.mode)
4146 job->anamorphic.par_width = title->pixel_aspect_width;
4147 job->anamorphic.par_height = title->pixel_aspect_height;
4148 job->anamorphic.dar_width = 0;
4149 job->anamorphic.dar_height = 0;
4151 if (job->anamorphic.mode == 3 && !keep_aspect)
4153 job->anamorphic.keep_display_aspect = 0;
4154 job->anamorphic.par_width =
4155 ghb_settings_get_int(js, "PicturePARWidth");
4156 job->anamorphic.par_height =
4157 ghb_settings_get_int(js, "PicturePARHeight");
4161 job->anamorphic.keep_display_aspect = 1;
4165 /* Add selected filters */
4166 job->filters = hb_list_init();
4167 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4172 if (detel_opts.map[detel].svalue != NULL)
4173 detel_str = g_strdup(detel_opts.map[detel].svalue);
4176 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4177 hb_filter_detelecine.settings = detel_str;
4178 hb_list_add( job->filters, &hb_filter_detelecine );
4180 if ( decomb_deint && decomb )
4184 if (decomb_opts.map[decomb].svalue != NULL)
4185 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4188 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4189 hb_filter_decomb.settings = decomb_str;
4190 hb_list_add( job->filters, &hb_filter_decomb );
4192 if( job->deinterlace )
4196 if (deint_opts.map[deint].svalue != NULL)
4197 deint_str = g_strdup(deint_opts.map[deint].svalue);
4200 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4201 hb_filter_deinterlace.settings = deint_str;
4202 hb_list_add( job->filters, &hb_filter_deinterlace );
4204 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4207 deblock_str = g_strdup_printf("%d", deblock);
4208 hb_filter_deblock.settings = deblock_str;
4209 hb_list_add( job->filters, &hb_filter_deblock );
4211 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4216 if (denoise_opts.map[denoise].svalue != NULL)
4217 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4220 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4221 hb_filter_denoise.settings = denoise_str;
4222 hb_list_add( job->filters, &hb_filter_denoise );
4224 job->width = ghb_settings_get_int(js, "scale_width");
4225 job->height = ghb_settings_get_int(js, "scale_height");
4227 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4228 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4230 // mp4/theora combination is not supported.
4231 job->vcodec = HB_VCODEC_FFMPEG;
4233 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4235 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4237 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4240 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4241 job->vquality = vquality;
4244 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4246 job->vquality = -1.0;
4247 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4250 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4253 job->vrate = title->rate;
4254 job->vrate_base = title->rate_base;
4259 job->vrate = 27000000;
4260 job->vrate_base = vrate;
4264 const GValue *audio_list;
4268 audio_list = ghb_settings_get_value(js, "audio_list");
4269 count = ghb_array_len(audio_list);
4270 for (ii = 0; ii < count; ii++)
4273 hb_audio_config_t audio;
4274 hb_audio_config_t *taudio;
4276 hb_audio_config_init(&audio);
4277 asettings = ghb_array_get_nth(audio_list, ii);
4278 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4279 audio.out.track = tcount;
4280 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4281 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4282 title->list_audio, audio.in.track );
4283 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4285 if (!(taudio->in.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4288 // AC3/DTS is passthrough only, so input must be AC3/DTS
4289 if (job->mux == HB_MUX_MKV)
4291 audio.out.codec = HB_ACODEC_LAME;
4295 audio.out.codec = HB_ACODEC_FAAC;
4300 audio.out.codec &= taudio->in.codec;
4303 if ((job->mux == HB_MUX_MP4) &&
4304 ((audio.out.codec & HB_ACODEC_LAME) ||
4305 (audio.out.codec & HB_ACODEC_DCA) ||
4306 (audio.out.codec & HB_ACODEC_VORBIS)))
4308 // mp4/mp3|dts|vorbis combination is not supported.
4309 audio.out.codec = HB_ACODEC_FAAC;
4311 audio.out.dynamic_range_compression =
4312 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4313 if (audio.out.dynamic_range_compression < 1.0)
4314 audio.out.dynamic_range_compression = 0.0;
4316 // It would be better if this were done in libhb for us, but its not yet.
4317 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4319 audio.out.mixdown = 0;
4325 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4326 if (audio.out.mixdown == HB_AMIXDOWN_MONO)
4328 else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
4333 // Make sure the mixdown is valid and pick a new one if not.
4334 audio.out.mixdown = ghb_get_best_mix(titleindex,
4335 audio.in.track, audio.out.codec, audio.out.mixdown);
4337 ghb_settings_combo_int(asettings, "AudioBitrate");
4338 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4339 if (srate == 0) // 0 is same as source
4340 audio.out.samplerate = taudio->in.samplerate;
4342 audio.out.samplerate = srate;
4344 audio.out.bitrate = ghb_get_best_audio_bitrate(
4345 audio.out.codec, audio.out.bitrate, channels);
4348 // Add it to the jobs audio list
4349 hb_audio_add( job, &audio );
4352 // I was tempted to move this up with the reset of the video quality
4353 // settings, but I suspect the settings above need to be made
4354 // first in order for hb_calc_bitrate to be accurate.
4355 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4359 size = ghb_settings_get_int(js, "VideoTargetSize");
4360 job->vbitrate = hb_calc_bitrate( job, size );
4361 job->vquality = -1.0;
4364 dest_str = ghb_settings_get_string(js, "destination");
4365 job->file = dest_str;
4367 const GValue *subtitle_list;
4369 gboolean force, burned, def, one_burned = FALSE;
4371 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4372 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4373 count = ghb_array_len(subtitle_list);
4374 for (ii = 0; ii < count; ii++)
4379 ssettings = ghb_array_get_nth(subtitle_list, ii);
4381 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4382 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4383 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4384 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4386 if (source == SRTSUB)
4388 hb_subtitle_config_t sub_config;
4389 gchar *filename, *lang, *code;
4391 filename = ghb_settings_get_string(ssettings, "SrtFile");
4392 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4396 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4397 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4398 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4399 strncpy(sub_config.src_filename, filename, 128);
4400 strncpy(sub_config.src_codeset, code, 40);
4401 sub_config.force = 0;
4402 sub_config.dest = PASSTHRUSUB;
4403 sub_config.default_track = def;
4405 hb_srt_add( job, &sub_config, lang);
4413 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4416 if (!burned && job->mux == HB_MUX_MKV)
4418 job->select_subtitle_config.dest = PASSTHRUSUB;
4420 else if (!burned && job->mux == HB_MUX_MP4)
4422 // Skip any non-burned vobsubs when output is mp4
4427 // Only allow one subtitle to be burned into the video
4430 job->select_subtitle_config.dest = RENDERSUB;
4433 job->select_subtitle_config.force = force;
4434 job->select_subtitle_config.default_track = def;
4435 job->indepth_scan = 1;
4436 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4438 else if (subtitle >= 0)
4440 hb_subtitle_t * subt;
4441 hb_subtitle_config_t sub_config;
4443 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4444 sub_config = subt->config;
4447 if (!burned && job->mux == HB_MUX_MKV &&
4448 subt->format == PICTURESUB)
4450 sub_config.dest = PASSTHRUSUB;
4452 else if (!burned && job->mux == HB_MUX_MP4 &&
4453 subt->format == PICTURESUB)
4455 // Skip any non-burned vobsubs when output is mp4
4458 else if ( burned && subt->format == PICTURESUB )
4460 // Only allow one subtitle to be burned into the video
4465 sub_config.force = force;
4466 sub_config.default_track = def;
4467 hb_subtitle_add( job, &sub_config, subtitle );
4472 // TODO: libhb holds onto a reference to the x264opts and is not
4473 // finished with it until encoding the job is done. But I can't
4474 // find a way to get at the job before it is removed in order to
4475 // free up the memory I am allocating here.
4476 // The short story is THIS LEAKS.
4477 x264opts = ghb_build_x264opts_string(js);
4479 if( *x264opts == '\0' )
4485 if (job->indepth_scan == 1)
4487 // Subtitle scan. Look for subtitle matching audio language
4490 * When subtitle scan is enabled do a fast pre-scan job
4491 * which will determine which subtitles to enable, if any.
4494 job->indepth_scan = 1;
4495 job->x264opts = NULL;
4498 * Add the pre-scan job
4500 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4504 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4505 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4508 * If subtitle_scan is enabled then only turn it on
4509 * for the second pass and then off again for the
4513 job->indepth_scan = 0;
4516 * If turbo options have been selected then append them
4517 * to the x264opts now (size includes one ':' and the '\0')
4519 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4521 gchar *tmp_x264opts;
4525 badapt = ghb_lookup_badapt(x264opts);
4528 extra_opts = g_strdup_printf("%s", turbo_opts);
4532 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4537 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4542 * No x264opts to modify, but apply the turbo options
4543 * anyway as they may be modifying defaults
4545 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4549 job->x264opts = tmp_x264opts;
4553 job->x264opts = x264opts;
4555 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4557 //if (job->x264opts != NULL)
4558 // g_free(job->x264opts);
4562 * On the second pass we turn off subtitle scan so that we
4563 * can actually encode using any subtitles that were auto
4564 * selected in the first pass (using the whacky select-subtitle
4565 * attribute of the job).
4567 job->indepth_scan = 0;
4568 job->x264opts = x264opts;
4569 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4571 //if (job->x264opts != NULL)
4572 // g_free(job->x264opts);
4576 job->x264opts = x264opts;
4577 job->indepth_scan = 0;
4579 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4581 //if (job->x264opts != NULL)
4582 // g_free(job->x264opts);
4585 // clean up audio list
4586 gint num_audio_tracks = hb_list_count(job->list_audio);
4587 for(ii = 0; ii < num_audio_tracks; ii++)
4589 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4590 hb_list_rem(job->list_audio, audio);
4594 // clean up subtitle list
4595 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4596 for(ii = 0; ii < num_subtitle_tracks; ii++)
4598 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4599 hb_list_rem(job->list_subtitle, subtitle);
4603 if (detel_str) g_free(detel_str);
4604 if (decomb_str) g_free(decomb_str);
4605 if (deint_str) g_free(deint_str);
4606 if (deblock_str) g_free(deblock_str);
4607 if (denoise_str) g_free(denoise_str);
4608 if (dest_str) g_free(dest_str);
4612 ghb_add_job(GValue *js, gint unique_id)
4614 // Since I'm doing a scan of the single title I want just prior
4615 // to adding the job, there is only the one title to choose from.
4616 add_job(h_queue, js, unique_id, 0);
4620 ghb_add_live_job(GValue *js, gint unique_id)
4622 // Since I'm doing a scan of the single title I want just prior
4623 // to adding the job, there is only the one title to choose from.
4624 gint titleindex = ghb_settings_combo_int(js, "title");
4625 add_job(h_scan, js, unique_id, titleindex);
4629 ghb_remove_job(gint unique_id)
4634 // Multiples passes all get the same id
4636 // Go backwards through list, so reordering doesn't screw me.
4637 ii = hb_count(h_queue) - 1;
4638 while ((job = hb_job(h_queue, ii--)) != NULL)
4640 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4641 hb_rem(h_queue, job);
4648 hb_start( h_queue );
4658 ghb_start_live_encode()
4664 ghb_stop_live_encode()
4673 hb_get_state2( h_queue, &s );
4675 if( s.state == HB_STATE_PAUSED )
4677 hb_status.queue.state &= ~GHB_STATE_PAUSED;
4678 hb_resume( h_queue );
4682 hb_status.queue.state |= GHB_STATE_PAUSED;
4683 hb_pause( h_queue );
4698 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4701 gint channels = gdk_pixbuf_get_n_channels (pb);
4702 gint stride = gdk_pixbuf_get_rowstride (pb);
4704 for (jj = 0; jj < width; jj++)
4706 dst = pixels + y * stride + (x+jj) * channels;
4707 for (ii = 0; ii < len; ii++)
4728 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4731 gint channels = gdk_pixbuf_get_n_channels (pb);
4732 gint stride = gdk_pixbuf_get_rowstride (pb);
4734 for (jj = 0; jj < width; jj++)
4736 dst = pixels + (y+jj) * stride + x * channels;
4737 for (ii = 0; ii < len; ii++)
4758 gint line_width = 8;
4765 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4770 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4772 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4778 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4780 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4786 ghb_get_preview_image(
4789 signal_user_data_t *ud,
4797 settings = ud->settings;
4798 list = hb_get_titles( h_scan );
4799 if( !hb_list_count( list ) )
4801 /* No valid title, stop right there */
4804 title = hb_list_item( list, titleindex );
4805 if (title == NULL) return NULL;
4806 if (title->job == NULL) return NULL;
4807 set_preview_job_settings(title->job, settings);
4809 // hb_get_preview doesn't compensate for anamorphic, so lets
4810 // calculate scale factors
4811 gint width, height, par_width = 1, par_height = 1;
4812 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4815 hb_set_anamorphic_size( title->job, &width, &height,
4816 &par_width, &par_height );
4819 // Make sure we have a big enough buffer to receive the image from libhb
4820 gint dstWidth = title->job->width;
4821 gint dstHeight= title->job->height;
4823 static guint8 *buffer = NULL;
4824 static gint bufferSize = 0;
4827 newSize = dstWidth * dstHeight * 4;
4828 if( bufferSize < newSize )
4830 bufferSize = newSize;
4831 buffer = (guint8*) g_realloc( buffer, bufferSize );
4833 hb_get_preview( h_scan, title, index, buffer );
4835 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4836 // libhb's format something suitable.
4838 // The image data returned by hb_get_preview is 4 bytes per pixel,
4839 // BGRA format. Alpha is ignored.
4841 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4842 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4844 guint32 *src = (guint32*)buffer;
4845 guint8 *dst = pixels;
4848 gint channels = gdk_pixbuf_get_n_channels (preview);
4849 gint stride = gdk_pixbuf_get_rowstride (preview);
4852 for (ii = 0; ii < dstHeight; ii++)
4855 for (jj = 0; jj < dstWidth; jj++)
4857 tmp[0] = src[0] >> 16;
4858 tmp[1] = src[0] >> 8;
4859 tmp[2] = src[0] >> 0;
4865 gint w = ghb_settings_get_int(settings, "scale_width");
4866 gint h = ghb_settings_get_int(settings, "scale_height");
4867 ghb_par_scale(ud, &w, &h, par_width, par_height);
4869 gint c0, c1, c2, c3;
4870 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4871 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4872 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4873 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4875 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4876 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4878 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4881 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4885 gint orig_w, orig_h;
4888 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4892 ss = gdk_screen_get_default();
4893 s_w = gdk_screen_get_width(ss);
4894 s_h = gdk_screen_get_height(ss);
4898 if (dstWidth > s_w * factor / 100)
4900 dstWidth = s_w * factor / 100;
4901 dstHeight = dstHeight * dstWidth / orig_w;
4903 if (dstHeight > s_h * factor / 100)
4905 dstHeight = s_h * factor / 100;
4906 dstWidth = dstWidth * dstHeight / orig_h;
4908 xscale *= (gdouble)dstWidth / orig_w;
4909 yscale *= (gdouble)dstHeight / orig_h;
4910 w *= (gdouble)dstWidth / orig_w;
4911 h *= (gdouble)dstHeight / orig_h;
4913 GdkPixbuf *scaled_preview;
4914 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4915 if (ghb_settings_get_boolean(settings, "show_crop"))
4922 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4924 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4926 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4928 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4930 g_object_unref (preview);
4931 return scaled_preview;
4935 sanitize_volname(gchar *name)
4960 ghb_dvd_volname(const gchar *device)
4963 name = hb_dvd_name((gchar*)device);
4964 if (name != NULL && name[0] != 0)
4966 name = g_strdup(name);
4967 sanitize_volname(name);