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 {"None", "none", 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 {"None", "none", 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 {"None", "none", 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 {"None", "none", 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 {"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 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "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[] =
304 combo_opts_t subme_opts =
306 sizeof(d_subme_opts)/sizeof(options_map_t),
310 static options_map_t d_analyse_opts[] =
312 {"Some", "some", 0, "some"},
313 {"None", "none", 1, "none"},
314 {"All", "all", 2, "all"},
315 {"Custom", "custom", 3, "all"},
317 combo_opts_t analyse_opts =
319 sizeof(d_analyse_opts)/sizeof(options_map_t),
323 static options_map_t d_trellis_opts[] =
325 {"Disabled", "0", 0, "0"},
326 {"Final Macro Block", "1", 1, "1"},
327 {"Always", "2", 2, "2"},
329 combo_opts_t trellis_opts =
331 sizeof(d_trellis_opts)/sizeof(options_map_t),
335 combo_opts_t subtitle_opts =
341 combo_opts_t title_opts =
347 combo_opts_t audio_track_opts =
359 combo_name_map_t combo_name_map[] =
361 {"WhenComplete", &when_complete_opts},
362 {"PicturePAR", &par_opts},
363 {"PictureModulus", &alignment_opts},
364 {"LoggingLevel", &logging_opts},
365 {"LogLongevity", &log_longevity_opts},
366 {"check_updates", &appcast_update_opts},
367 {"VideoQualityGranularity", &vqual_granularity_opts},
368 {"FileFormat", &container_opts},
369 {"PictureDeinterlace", &deint_opts},
370 {"PictureDecomb", &decomb_opts},
371 {"PictureDetelecine", &detel_opts},
372 {"PictureDenoise", &denoise_opts},
373 {"VideoEncoder", &vcodec_opts},
374 {"AudioEncoder", &acodec_opts},
375 {"x264_direct", &direct_opts},
376 {"x264_b_adapt", &badapt_opts},
377 {"x264_me", &me_opts},
378 {"x264_subme", &subme_opts},
379 {"x264_analyse", &analyse_opts},
380 {"x264_trellis", &trellis_opts},
381 {"SubtitleTrack", &subtitle_opts},
382 {"title", &title_opts},
383 {"AudioTrack", &audio_track_opts},
387 const gchar *srt_codeset_table[] =
426 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
429 typedef struct iso639_lang_t
431 char * eng_name; /* Description in English */
432 char * native_name; /* Description in native language */
433 char * iso639_1; /* ISO-639-1 (2 characters) code */
434 char * iso639_2; /* ISO-639-2/t (3 character) code */
435 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
439 const iso639_lang_t ghb_language_table[] =
441 { "Any", "", "zz", "und" },
442 { "Afar", "", "aa", "aar" },
443 { "Abkhazian", "", "ab", "abk" },
444 { "Afrikaans", "", "af", "afr" },
445 { "Akan", "", "ak", "aka" },
446 { "Albanian", "", "sq", "sqi", "alb" },
447 { "Amharic", "", "am", "amh" },
448 { "Arabic", "", "ar", "ara" },
449 { "Aragonese", "", "an", "arg" },
450 { "Armenian", "", "hy", "hye", "arm" },
451 { "Assamese", "", "as", "asm" },
452 { "Avaric", "", "av", "ava" },
453 { "Avestan", "", "ae", "ave" },
454 { "Aymara", "", "ay", "aym" },
455 { "Azerbaijani", "", "az", "aze" },
456 { "Bashkir", "", "ba", "bak" },
457 { "Bambara", "", "bm", "bam" },
458 { "Basque", "", "eu", "eus", "baq" },
459 { "Belarusian", "", "be", "bel" },
460 { "Bengali", "", "bn", "ben" },
461 { "Bihari", "", "bh", "bih" },
462 { "Bislama", "", "bi", "bis" },
463 { "Bosnian", "", "bs", "bos" },
464 { "Breton", "", "br", "bre" },
465 { "Bulgarian", "", "bg", "bul" },
466 { "Burmese", "", "my", "mya", "bur" },
467 { "Catalan", "", "ca", "cat" },
468 { "Chamorro", "", "ch", "cha" },
469 { "Chechen", "", "ce", "che" },
470 { "Chinese", "", "zh", "zho", "chi" },
471 { "Church Slavic", "", "cu", "chu" },
472 { "Chuvash", "", "cv", "chv" },
473 { "Cornish", "", "kw", "cor" },
474 { "Corsican", "", "co", "cos" },
475 { "Cree", "", "cr", "cre" },
476 { "Czech", "", "cs", "ces", "cze" },
477 { "Danish", "Dansk", "da", "dan" },
478 { "Divehi", "", "dv", "div" },
479 { "Dutch", "Nederlands", "nl", "nld", "dut" },
480 { "Dzongkha", "", "dz", "dzo" },
481 { "English", "English", "en", "eng" },
482 { "Esperanto", "", "eo", "epo" },
483 { "Estonian", "", "et", "est" },
484 { "Ewe", "", "ee", "ewe" },
485 { "Faroese", "", "fo", "fao" },
486 { "Fijian", "", "fj", "fij" },
487 { "Finnish", "Suomi", "fi", "fin" },
488 { "French", "Francais", "fr", "fra", "fre" },
489 { "Western Frisian", "", "fy", "fry" },
490 { "Fulah", "", "ff", "ful" },
491 { "Georgian", "", "ka", "kat", "geo" },
492 { "German", "Deutsch", "de", "deu", "ger" },
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 { "Hungarian", "Magyar", "hu", "hun" },
507 { "Igbo", "", "ig", "ibo" },
508 { "Icelandic", "Islenska", "is", "isl", "ice" },
509 { "Ido", "", "io", "ido" },
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 { "Marshallese", "", "mh", "mah" },
544 { "Malayalam", "", "ml", "mal" },
545 { "Maori", "", "mi", "mri", "mao" },
546 { "Marathi", "", "mr", "mar" },
547 { "Malay", "", "ms", "msa", "msa" },
548 { "Malagasy", "", "mg", "mlg" },
549 { "Maltese", "", "mt", "mlt" },
550 { "Moldavian", "", "mo", "mol" },
551 { "Mongolian", "", "mn", "mon" },
552 { "Nauru", "", "na", "nau" },
553 { "Navajo", "", "nv", "nav" },
554 { "Ndebele, South", "", "nr", "nbl" },
555 { "Ndebele, North", "", "nd", "nde" },
556 { "Ndonga", "", "ng", "ndo" },
557 { "Nepali", "", "ne", "nep" },
558 { "Norwegian Nynorsk", "", "nn", "nno" },
559 { "Norwegian Bokmål", "", "nb", "nob" },
560 { "Norwegian", "Norsk", "no", "nor" },
561 { "Chichewa; Nyanja", "", "ny", "nya" },
562 { "Occitan", "", "oc", "oci" },
563 { "Ojibwa", "", "oj", "oji" },
564 { "Oriya", "", "or", "ori" },
565 { "Oromo", "", "om", "orm" },
566 { "Ossetian", "", "os", "oss" },
567 { "Panjabi", "", "pa", "pan" },
568 { "Persian", "", "fa", "fas", "per" },
569 { "Pali", "", "pi", "pli" },
570 { "Polish", "", "pl", "pol" },
571 { "Portuguese", "Portugues", "pt", "por" },
572 { "Pushto", "", "ps", "pus" },
573 { "Quechua", "", "qu", "que" },
574 { "Romansh", "", "rm", "roh" },
575 { "Romanian", "", "ro", "ron", "rum" },
576 { "Rundi", "", "rn", "run" },
577 { "Russian", "", "ru", "rus" },
578 { "Sango", "", "sg", "sag" },
579 { "Sanskrit", "", "sa", "san" },
580 { "Serbian", "", "sr", "srp", "scc" },
581 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
582 { "Sinhala", "", "si", "sin" },
583 { "Slovak", "", "sk", "slk", "slo" },
584 { "Slovenian", "", "sl", "slv" },
585 { "Northern Sami", "", "se", "sme" },
586 { "Samoan", "", "sm", "smo" },
587 { "Shona", "", "sn", "sna" },
588 { "Sindhi", "", "sd", "snd" },
589 { "Somali", "", "so", "som" },
590 { "Sotho, Southern", "", "st", "sot" },
591 { "Spanish", "Espanol", "es", "spa" },
592 { "Sardinian", "", "sc", "srd" },
593 { "Swati", "", "ss", "ssw" },
594 { "Sundanese", "", "su", "sun" },
595 { "Swahili", "", "sw", "swa" },
596 { "Swedish", "Svenska", "sv", "swe" },
597 { "Tahitian", "", "ty", "tah" },
598 { "Tamil", "", "ta", "tam" },
599 { "Tatar", "", "tt", "tat" },
600 { "Telugu", "", "te", "tel" },
601 { "Tajik", "", "tg", "tgk" },
602 { "Tagalog", "", "tl", "tgl" },
603 { "Thai", "", "th", "tha" },
604 { "Tibetan", "", "bo", "bod", "tib" },
605 { "Tigrinya", "", "ti", "tir" },
606 { "Tonga", "", "to", "ton" },
607 { "Tswana", "", "tn", "tsn" },
608 { "Tsonga", "", "ts", "tso" },
609 { "Turkmen", "", "tk", "tuk" },
610 { "Turkish", "", "tr", "tur" },
611 { "Twi", "", "tw", "twi" },
612 { "Uighur", "", "ug", "uig" },
613 { "Ukrainian", "", "uk", "ukr" },
614 { "Urdu", "", "ur", "urd" },
615 { "Uzbek", "", "uz", "uzb" },
616 { "Venda", "", "ve", "ven" },
617 { "Vietnamese", "", "vi", "vie" },
618 { "Volapük", "", "vo", "vol" },
619 { "Welsh", "", "cy", "cym", "wel" },
620 { "Walloon", "", "wa", "wln" },
621 { "Wolof", "", "wo", "wol" },
622 { "Xhosa", "", "xh", "xho" },
623 { "Yiddish", "", "yi", "yid" },
624 { "Yoruba", "", "yo", "yor" },
625 { "Zhuang", "", "za", "zha" },
626 { "Zulu", "", "zu", "zul" },
627 {NULL, NULL, NULL, NULL}
629 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
631 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
634 del_tree(const gchar *name, gboolean del_top)
638 if (g_file_test(name, G_FILE_TEST_IS_DIR))
640 GDir *gdir = g_dir_open(name, 0, NULL);
641 file = g_dir_read_name(gdir);
645 path = g_strdup_printf("%s/%s", name, file);
646 del_tree(path, TRUE);
648 file = g_dir_read_name(gdir);
663 return hb_get_version(NULL);
668 signal_user_data_t *ud,
676 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
685 *step = ghb_settings_combo_double(ud->settings,
686 "VideoQualityGranularity");
687 if (*step == 0.2 || *step == 0.5)
689 else if (*step == 0.25)
694 case HB_VCODEC_FFMPEG:
702 case HB_VCODEC_THEORA:
721 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
725 const gchar *result = "";
727 str = ghb_value_string(gval);
728 for (ii = 0; ii < opts->count; ii++)
730 if (strcmp(opts->map[ii].shortOpt, str) == 0)
732 result = opts->map[ii].svalue;
741 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
747 str = ghb_value_string(gval);
748 for (ii = 0; ii < opts->count; ii++)
750 if (strcmp(opts->map[ii].shortOpt, str) == 0)
752 result = opts->map[ii].ivalue;
761 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
767 str = ghb_value_string(gval);
768 for (ii = 0; ii < opts->count; ii++)
770 if (strcmp(opts->map[ii].shortOpt, str) == 0)
772 result = opts->map[ii].ivalue;
781 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
785 const gchar *result = "";
787 str = ghb_value_string(gval);
788 for (ii = 0; ii < opts->count; ii++)
790 if (strcmp(opts->map[ii].shortOpt, str) == 0)
792 result = opts->map[ii].option;
801 lookup_mix_int(const GValue *mix)
808 str = ghb_value_string(mix);
809 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
811 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
813 result = hb_audio_mixdowns[ii].amixdown;
822 lookup_mix_option(const GValue *mix)
826 gchar *result = "None";
829 str = ghb_value_string(mix);
830 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
832 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
834 result = hb_audio_mixdowns[ii].human_readable_name;
843 lookup_video_rate_int(const GValue *vrate)
849 str = ghb_value_string(vrate);
850 for (ii = 0; ii < hb_video_rates_count; ii++)
852 if (strcmp(hb_video_rates[ii].string, str) == 0)
854 result = hb_video_rates[ii].rate;
859 // Default to "same as source"
864 lookup_video_rate_option(const GValue *vrate)
868 const gchar *result = "Same as source";
870 str = ghb_value_string(vrate);
871 for (ii = 0; ii < hb_video_rates_count; ii++)
873 if (strcmp(hb_video_rates[ii].string, str) == 0)
875 result = hb_video_rates[ii].string;
880 // Default to "same as source"
885 lookup_audio_rate_int(const GValue *rate)
891 // Coincidentally, the string "source" will return 0
892 // which is our flag to use "same as source"
893 str = ghb_value_string(rate);
894 for (ii = 0; ii < hb_audio_rates_count; ii++)
896 if (strcmp(hb_audio_rates[ii].string, str) == 0)
898 result = hb_audio_rates[ii].rate;
907 lookup_audio_rate_option(const GValue *rate)
911 const gchar *result = "Same as source";
913 // Coincidentally, the string "source" will return 0
914 // which is our flag to use "same as source"
915 str = ghb_value_string(rate);
916 for (ii = 0; ii < hb_audio_rates_count; ii++)
918 if (strcmp(hb_audio_rates[ii].string, str) == 0)
920 result = hb_audio_rates[ii].string;
929 lookup_audio_bitrate_int(const GValue *rate)
935 // Coincidentally, the string "source" will return 0
936 // which is our flag to use "same as source"
937 str = ghb_value_string(rate);
938 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
940 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
942 result = hb_audio_bitrates[ii].rate;
951 lookup_audio_bitrate_option(const GValue *rate)
955 const gchar *result = "Same as source";
957 // Coincidentally, the string "source" will return 0
958 // which is our flag to use "same as source"
959 str = ghb_value_string(rate);
960 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
962 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
964 result = hb_audio_bitrates[ii].string;
973 lookup_audio_lang_int(const GValue *rate)
979 // Coincidentally, the string "source" will return 0
980 // which is our flag to use "same as source"
981 str = ghb_value_string(rate);
982 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
984 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
995 lookup_audio_lang_option(const GValue *rate)
999 const gchar *result = "Same as source";
1001 // Coincidentally, the string "source" will return 0
1002 // which is our flag to use "same as source"
1003 str = ghb_value_string(rate);
1004 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1006 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1008 result = ghb_language_table[ii].eng_name;
1017 get_acodec_value(gint val)
1019 GValue *value = NULL;
1022 for (ii = 0; ii < acodec_opts.count; ii++)
1024 if ((int)acodec_opts.map[ii].ivalue == val)
1026 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1034 get_amix_value(gint val)
1036 GValue *value = NULL;
1039 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1041 if (hb_audio_mixdowns[ii].amixdown == val)
1043 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1050 // Handle for libhb. Gets set by ghb_backend_init()
1051 static hb_handle_t * h_scan = NULL;
1052 static hb_handle_t * h_queue = NULL;
1054 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
1061 hb_get_tempory_directory(h_scan, dir);
1062 return g_strdup(dir);
1066 ghb_hb_cleanup(gboolean partial)
1070 hb_get_tempory_directory(h_scan, dir);
1071 del_tree(dir, !partial);
1075 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1083 titleindex = ghb_settings_combo_int(ud->settings, "title");
1089 hb_subtitle_t * sub;
1091 if (h_scan == NULL) return VOBSUB;
1092 list = hb_get_titles( h_scan );
1093 if( !hb_list_count( list ) )
1095 /* No valid title, stop right there */
1098 title = hb_list_item( list, titleindex );
1099 if (title == NULL) return VOBSUB; // Bad titleindex
1100 sub = hb_list_item( title->list_subtitle, track);
1108 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1111 const gchar * name = "Unknown";
1124 titleindex = ghb_settings_combo_int(ud->settings, "title");
1130 hb_subtitle_t * sub;
1134 list = hb_get_titles( h_scan );
1135 if( !hb_list_count( list ) )
1138 title = hb_list_item( list, titleindex );
1142 sub = hb_list_item( title->list_subtitle, track);
1145 switch (sub->source)
1167 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1171 titleindex = ghb_settings_combo_int(ud->settings, "title");
1175 return ghb_get_user_audio_lang(ud, titleindex, 0);
1181 hb_subtitle_t * sub;
1186 list = hb_get_titles( h_scan );
1187 if( !hb_list_count( list ) )
1189 /* No valid title, stop right there */
1192 title = hb_list_item( list, titleindex );
1193 if (title == NULL) // Bad titleindex
1195 sub = hb_list_item( title->list_subtitle, track);
1197 return g_strdup(sub->iso639_2);
1200 return g_strdup("und");
1204 ghb_get_title_number(gint titleindex)
1209 if (h_scan == NULL) return 1;
1210 list = hb_get_titles( h_scan );
1211 if( !hb_list_count( list ) )
1213 /* No valid title, stop right there */
1216 title = hb_list_item( list, titleindex );
1217 if (title == NULL) return 1; // Bad titleindex
1218 return title->index;
1221 static hb_audio_config_t*
1222 get_hb_audio(gint titleindex, gint track)
1226 hb_audio_config_t *audio = NULL;
1228 if (h_scan == NULL) return NULL;
1229 list = hb_get_titles( h_scan );
1230 if( !hb_list_count( list ) )
1232 /* No valid title, stop right there */
1235 title = hb_list_item( list, titleindex );
1236 if (title == NULL) return NULL; // Bad titleindex
1237 if (!hb_list_count(title->list_audio))
1241 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1246 search_rates(hb_rate_t *rates, gint rate, gint count)
1249 for (ii = 0; ii < count; ii++)
1251 if (rates[ii].rate == rate)
1257 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1259 static GtkListStore*
1260 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1263 GtkListStore *store;
1265 g_debug("get_combo_box_store() %s\n", name);
1266 // First modify the combobox model to allow greying out of options
1267 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1268 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1273 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1275 GtkListStore *store;
1278 store = get_combo_box_store(builder, name);
1279 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1281 gtk_list_store_set(store, &iter,
1288 ghb_grey_combo_options(GtkBuilder *builder)
1291 gint container, track, titleindex, acodec;
1292 hb_audio_config_t *audio = NULL;
1295 widget = GHB_WIDGET (builder, "title");
1296 gval = ghb_widget_value(widget);
1297 titleindex = ghb_lookup_combo_int("title", gval);
1298 ghb_value_free(gval);
1299 widget = GHB_WIDGET (builder, "AudioTrack");
1300 gval = ghb_widget_value(widget);
1301 track = ghb_lookup_combo_int("AudioTrack", gval);
1302 ghb_value_free(gval);
1303 audio = get_hb_audio(titleindex, track);
1304 widget = GHB_WIDGET (builder, "FileFormat");
1305 gval = ghb_widget_value(widget);
1306 container = ghb_lookup_combo_int("FileFormat", gval);
1307 ghb_value_free(gval);
1309 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1310 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1311 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1312 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1314 gboolean allow_dca = TRUE;
1315 allow_dca = (container != HB_MUX_MP4);
1317 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1319 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1321 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1323 if (audio && audio->in.codec != HB_ACODEC_AC3)
1325 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1327 if (audio && audio->in.codec != HB_ACODEC_DCA)
1329 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1331 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1333 widget = GHB_WIDGET (builder, "AudioEncoder");
1334 gval = ghb_widget_value(widget);
1335 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1336 ghb_value_free(gval);
1337 if (acodec != HB_ACODEC_AC3)
1339 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1341 if (container == HB_MUX_MP4)
1343 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1344 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1345 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1347 else if (container == HB_MUX_AVI)
1349 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1350 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1351 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1353 else if (container == HB_MUX_OGM)
1355 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1358 gboolean allow_mono = TRUE;
1359 gboolean allow_stereo = TRUE;
1360 gboolean allow_dolby = TRUE;
1361 gboolean allow_dpl2 = TRUE;
1362 gboolean allow_6ch = TRUE;
1366 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1367 (acodec != HB_ACODEC_LAME);
1368 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1370 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1372 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1373 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1374 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1375 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1377 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1378 (acodec != HB_ACODEC_LAME) &&
1379 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1380 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1382 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1383 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1384 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1385 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1386 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1390 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1392 hb_audio_config_t *audio = NULL;
1393 gboolean allow_mono = TRUE;
1394 gboolean allow_stereo = TRUE;
1395 gboolean allow_dolby = TRUE;
1396 gboolean allow_dpl2 = TRUE;
1397 gboolean allow_6ch = TRUE;
1399 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1401 // Audio codec pass-thru. No mixdown
1404 audio = get_hb_audio(titleindex, track);
1408 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1409 (acodec != HB_ACODEC_LAME);
1410 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1412 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1414 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1415 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1416 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1417 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1419 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1420 (acodec != HB_ACODEC_LAME) &&
1421 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1422 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1424 gboolean greater = FALSE;
1427 // If no mix is specified, select the best available.
1428 mix = HB_AMIXDOWN_6CH;
1430 if (mix == HB_AMIXDOWN_6CH)
1433 if (allow_6ch) return HB_AMIXDOWN_6CH;
1435 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1438 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1440 if (mix == HB_AMIXDOWN_DOLBY || greater)
1443 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1445 if (mix == HB_AMIXDOWN_STEREO || greater)
1448 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1450 if (mix == HB_AMIXDOWN_MONO || greater)
1453 if (allow_mono) return HB_AMIXDOWN_MONO;
1455 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1456 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1457 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1458 if (allow_6ch) return HB_AMIXDOWN_6CH;
1462 // Set up the model for the combo box
1464 init_combo_box(GtkBuilder *builder, const gchar *name)
1467 GtkListStore *store;
1468 GtkCellRenderer *cell;
1470 g_debug("init_combo_box() %s\n", name);
1471 // First modify the combobox model to allow greying out of options
1472 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1476 // 1 - String to display
1477 // 2 - bool indicating whether the entry is selectable (grey or not)
1478 // 3 - String that is used for presets
1479 // 4 - Int value determined by backend
1480 // 5 - String value determined by backend
1481 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1482 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1483 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1485 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1487 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1488 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1489 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1490 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1491 "text", 0, "sensitive", 1, NULL);
1494 { // Combo box entry
1495 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1500 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1503 GtkListStore *store;
1506 g_debug("audio_samplerate_opts_set ()\n");
1507 store = get_combo_box_store(builder, name);
1508 gtk_list_store_clear(store);
1509 // Add an item for "Same As Source"
1510 gtk_list_store_append(store, &iter);
1511 gtk_list_store_set(store, &iter,
1512 0, "Same as source",
1518 for (ii = 0; ii < count; ii++)
1520 gtk_list_store_append(store, &iter);
1521 gtk_list_store_set(store, &iter,
1522 0, rates[ii].string,
1524 2, rates[ii].string,
1525 3, (gdouble)rates[ii].rate,
1526 4, rates[ii].string,
1532 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1535 GtkListStore *store;
1538 g_debug("video_rate_opts_set ()\n");
1539 store = get_combo_box_store(builder, name);
1540 gtk_list_store_clear(store);
1541 // Add an item for "Same As Source"
1542 gtk_list_store_append(store, &iter);
1543 gtk_list_store_set(store, &iter,
1544 0, "Same as source",
1550 for (ii = 0; ii < count; ii++)
1554 if (strcmp(rates[ii].string, "23.976") == 0)
1556 desc = "(NTSC Film)";
1558 else if (strcmp(rates[ii].string, "25") == 0)
1560 desc = "(PAL Film/Video)";
1562 else if (strcmp(rates[ii].string, "29.97") == 0)
1564 desc = "(NTSC Video)";
1566 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1567 gtk_list_store_append(store, &iter);
1568 gtk_list_store_set(store, &iter,
1571 2, rates[ii].string,
1572 3, (gdouble)rates[ii].rate,
1573 4, rates[ii].string,
1580 mix_opts_set(GtkBuilder *builder, const gchar *name)
1583 GtkListStore *store;
1586 g_debug("mix_opts_set ()\n");
1587 store = get_combo_box_store(builder, name);
1588 gtk_list_store_clear(store);
1589 gtk_list_store_append(store, &iter);
1590 gtk_list_store_set(store, &iter,
1597 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1599 gtk_list_store_append(store, &iter);
1600 gtk_list_store_set(store, &iter,
1601 0, hb_audio_mixdowns[ii].human_readable_name,
1603 2, hb_audio_mixdowns[ii].short_name,
1604 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1605 4, hb_audio_mixdowns[ii].internal_name,
1611 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1614 GtkListStore *store;
1617 g_debug("srt_codeset_opts_set ()\n");
1618 store = get_combo_box_store(builder, name);
1619 gtk_list_store_clear(store);
1620 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1622 gtk_list_store_append(store, &iter);
1623 gtk_list_store_set(store, &iter,
1624 0, srt_codeset_table[ii],
1626 2, srt_codeset_table[ii],
1628 4, srt_codeset_table[ii],
1631 GtkComboBoxEntry *cbe;
1633 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1634 //gtk_combo_box_entry_set_text_column(cbe, 0);
1638 language_opts_set(GtkBuilder *builder, const gchar *name)
1641 GtkListStore *store;
1644 g_debug("language_opts_set ()\n");
1645 store = get_combo_box_store(builder, name);
1646 gtk_list_store_clear(store);
1647 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1649 gtk_list_store_append(store, &iter);
1650 gtk_list_store_set(store, &iter,
1651 0, ghb_language_table[ii].eng_name,
1653 2, ghb_language_table[ii].iso639_2,
1655 4, ghb_language_table[ii].iso639_1,
1660 static gchar **titles = NULL;
1663 title_opts_set(GtkBuilder *builder, const gchar *name)
1666 GtkListStore *store;
1667 hb_list_t * list = NULL;
1668 hb_title_t * title = NULL;
1672 g_debug("title_opts_set ()\n");
1673 store = get_combo_box_store(builder, name);
1674 gtk_list_store_clear(store);
1677 list = hb_get_titles( h_scan );
1678 count = hb_list_count( list );
1679 if (count > 100) count = 100;
1681 if (titles) g_strfreev(titles);
1682 if (title_opts.map) g_free(title_opts.map);
1685 title_opts.count = count;
1686 title_opts.map = g_malloc(count*sizeof(options_map_t));
1687 titles = g_malloc((count+1) * sizeof(gchar*));
1691 title_opts.count = 1;
1692 title_opts.map = g_malloc(sizeof(options_map_t));
1697 // No titles. Fill in a default.
1698 gtk_list_store_append(store, &iter);
1699 gtk_list_store_set(store, &iter,
1706 title_opts.map[0].option = "No Titles";
1707 title_opts.map[0].shortOpt = "none";
1708 title_opts.map[0].ivalue = -1;
1709 title_opts.map[0].svalue = "none";
1712 for (ii = 0; ii < count; ii++)
1714 title = (hb_title_t*)hb_list_item(list, ii);
1715 if (title->duration != 0)
1717 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1718 title->index, title->hours, title->minutes, title->seconds);
1722 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1724 gtk_list_store_append(store, &iter);
1725 gtk_list_store_set(store, &iter,
1732 title_opts.map[ii].option = titles[ii];
1733 title_opts.map[ii].shortOpt = titles[ii];
1734 title_opts.map[ii].ivalue = ii;
1735 title_opts.map[ii].svalue = titles[ii];
1741 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1744 gboolean foundit = FALSE;
1746 if (gtk_tree_model_get_iter_first (store, iter))
1750 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1751 if (value == (int)ivalue)
1756 } while (gtk_tree_model_iter_next (store, iter));
1762 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1765 GtkListStore *store;
1766 hb_list_t * list = NULL;
1767 hb_title_t * title = NULL;
1768 hb_audio_config_t * audio;
1772 g_debug("audio_track_opts_set ()\n");
1773 store = get_combo_box_store(builder, name);
1774 gtk_list_store_clear(store);
1777 list = hb_get_titles( h_scan );
1778 title = (hb_title_t*)hb_list_item( list, titleindex );
1781 count = hb_list_count( title->list_audio );
1784 if (count > 100) count = 100;
1785 if (audio_track_opts.map) g_free(audio_track_opts.map);
1788 audio_track_opts.count = count;
1789 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1793 audio_track_opts.count = 1;
1794 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1798 // No audio. set some default
1799 gtk_list_store_append(store, &iter);
1800 gtk_list_store_set(store, &iter,
1807 audio_track_opts.map[0].option = "No Audio";
1808 audio_track_opts.map[0].shortOpt = "none";
1809 audio_track_opts.map[0].ivalue = -1;
1810 audio_track_opts.map[0].svalue = "none";
1813 index_str_init(count-1);
1814 for (ii = 0; ii < count; ii++)
1816 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1817 gtk_list_store_append(store, &iter);
1818 gtk_list_store_set(store, &iter,
1819 0, audio->lang.description,
1825 audio_track_opts.map[ii].option = audio->lang.description,
1826 audio_track_opts.map[ii].shortOpt = index_str[ii];
1827 audio_track_opts.map[ii].ivalue = ii;
1828 audio_track_opts.map[ii].svalue = index_str[ii];
1833 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1836 GtkListStore *store;
1837 hb_list_t * list = NULL;
1838 hb_title_t * title = NULL;
1839 hb_subtitle_t * subtitle;
1841 static char ** options = NULL;
1843 g_debug("subtitle_track_opts_set ()\n");
1844 store = get_combo_box_store(builder, name);
1845 gtk_list_store_clear(store);
1848 list = hb_get_titles( h_scan );
1849 title = (hb_title_t*)hb_list_item( list, titleindex );
1852 count = hb_list_count( title->list_subtitle );
1855 if (count > 100) count = 100;
1856 if (subtitle_opts.map) g_free(subtitle_opts.map);
1859 subtitle_opts.count = count+1;
1860 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1864 subtitle_opts.count = LANG_TABLE_SIZE+1;
1865 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1867 gtk_list_store_append(store, &iter);
1868 gtk_list_store_set(store, &iter,
1869 0, "Foreign Audio Search",
1875 subtitle_opts.map[0].option = "Foreign Audio Search";
1876 subtitle_opts.map[0].shortOpt = "-1";
1877 subtitle_opts.map[0].ivalue = -1;
1878 subtitle_opts.map[0].svalue = "auto";
1881 if (options != NULL)
1882 g_strfreev(options);
1883 options = g_malloc((count+1)*sizeof(gchar*));
1884 index_str_init(count-1);
1885 for (ii = 0; ii < count; ii++)
1887 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1888 // Skip subtitles that must be burned if there is already
1889 // a burned subtitle in the list
1890 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1891 subtitle_opts.map[ii+1].option = options[ii];
1892 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1893 subtitle_opts.map[ii+1].ivalue = ii;
1894 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1895 gtk_list_store_append(store, &iter);
1896 gtk_list_store_set(store, &iter,
1901 4, subtitle->iso639_2,
1904 options[count] = NULL;
1908 index_str_init(LANG_TABLE_SIZE-1);
1909 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1911 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1912 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1913 subtitle_opts.map[ii+1].ivalue = ii;
1914 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1915 gtk_list_store_append(store, &iter);
1916 gtk_list_store_set(store, &iter,
1917 0, ghb_language_table[ii].eng_name,
1921 4, ghb_language_table[ii].iso639_2,
1934 guint64 longest = 0;
1935 gint titleindex = 0;
1937 g_debug("ghb_longest_title ()\n");
1938 if (h_scan == NULL) return 0;
1939 list = hb_get_titles( h_scan );
1940 count = hb_list_count( list );
1941 if (count > 100) count = 100;
1942 for (ii = 0; ii < count; ii++)
1944 title = (hb_title_t*)hb_list_item(list, ii);
1945 if (title->duration > longest)
1948 longest = title->duration;
1955 ghb_get_source_audio_lang(gint titleindex, gint track)
1959 hb_audio_config_t * audio;
1962 g_debug("ghb_lookup_1st_audio_lang ()\n");
1965 list = hb_get_titles( h_scan );
1966 title = (hb_title_t*)hb_list_item( list, titleindex );
1969 if (hb_list_count( title->list_audio ) <= track)
1972 audio = hb_list_audio_config_item(title->list_audio, track);
1976 lang = g_strdup(audio->lang.iso639_2);
1981 ghb_find_audio_track(
1985 GHashTable *track_indices)
1989 hb_audio_config_t * audio;
1996 g_debug("find_audio_track ()\n");
1997 if (h_scan == NULL) return -1;
1998 list = hb_get_titles( h_scan );
1999 title = (hb_title_t*)hb_list_item( list, titleindex );
2002 count = hb_list_count( title->list_audio );
2004 if (count > 10) count = 10;
2005 used = g_hash_table_lookup(track_indices, &acodec);
2008 used = g_malloc0(count * sizeof(gboolean));
2009 g_hash_table_insert(track_indices, &acodec, used);
2011 // Try to find an item that matches the preferred language and
2012 // the passthru codec type
2013 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2015 for (ii = 0; ii < count; ii++)
2022 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2023 title->list_audio, ii );
2024 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2025 audio->in.channel_layout);
2026 // Find a track that is not visually impaired or dirctor's
2027 // commentary, and has the highest channel count.
2028 if ((audio->in.codec & acodec) &&
2029 (audio->lang.type < 2) &&
2030 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2031 (strcmp(lang, "und") == 0)))
2033 if (channels > max_chan)
2036 max_chan = channels;
2046 // Try to find an item that matches the preferred language
2047 for (ii = 0; ii < count; ii++)
2051 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2052 title->list_audio, ii );
2053 // Find a track that is not visually impaired or dirctor's commentary
2054 if ((audio->lang.type < 2) &&
2055 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2056 (strcmp(lang, "und") == 0)))
2067 // Try to fine an item that does not match the preferred language and
2068 // matches the passthru codec type
2069 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2071 for (ii = 0; ii < count; ii++)
2078 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2079 title->list_audio, ii );
2080 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2081 audio->in.channel_layout);
2082 // Find a track that is not visually impaired or dirctor's
2083 // commentary, and has the highest channel count.
2084 if ((audio->in.codec & acodec) &&
2085 (audio->lang.type < 2))
2087 if (channels > max_chan)
2090 max_chan = channels;
2100 // Try to fine an item that does not match the preferred language
2101 for (ii = 0; ii < count; ii++)
2105 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2106 title->list_audio, ii );
2107 // Find a track that is not visually impaired or dirctor's commentary
2108 if (audio->lang.type < 2)
2119 // Last ditch, anything goes
2120 for (ii = 0; ii < count; ii++)
2122 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2123 title->list_audio, ii );
2138 ghb_find_pref_subtitle_track(const gchar *lang)
2141 count = subtitle_opts.count;
2142 for (ii = 0; ii < count; ii++)
2144 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2146 return subtitle_opts.map[ii].ivalue;
2153 ghb_find_cc_track(gint titleindex)
2157 hb_subtitle_t * subtitle;
2160 g_debug("ghb_find_cc_track ()\n");
2161 if (h_scan == NULL) return -2;
2162 list = hb_get_titles( h_scan );
2163 title = (hb_title_t*)hb_list_item( list, titleindex );
2166 count = hb_list_count( title->list_subtitle );
2167 // Try to find an item that matches the preferred language
2168 for (ii = 0; ii < count; ii++)
2170 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2171 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2179 ghb_find_subtitle_track(
2182 GHashTable *track_indices)
2186 hb_subtitle_t * subtitle;
2190 g_debug("find_subtitle_track ()\n");
2191 if (strcmp(lang, "auto") == 0)
2193 if (h_scan == NULL) return -1;
2194 list = hb_get_titles( h_scan );
2195 title = (hb_title_t*)hb_list_item( list, titleindex );
2198 count = hb_list_count( title->list_subtitle );
2199 used = g_hash_table_lookup(track_indices, lang);
2202 used = g_malloc0(count * sizeof(gboolean));
2203 g_hash_table_insert(track_indices, g_strdup(lang), used);
2205 // Try to find an item that matches the preferred language
2206 for (ii = 0; ii < count; ii++)
2211 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2212 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2213 (strcmp(lang, "und") == 0))
2224 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2227 GtkListStore *store;
2230 g_debug("generic_opts_set ()\n");
2231 if (name == NULL || opts == NULL) return;
2232 store = get_combo_box_store(builder, name);
2233 gtk_list_store_clear(store);
2234 for (ii = 0; ii < opts->count; ii++)
2236 gtk_list_store_append(store, &iter);
2237 gtk_list_store_set(store, &iter,
2238 0, opts->map[ii].option,
2240 2, opts->map[ii].shortOpt,
2241 3, opts->map[ii].ivalue,
2242 4, opts->map[ii].svalue,
2248 find_combo_table(const gchar *name)
2252 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2254 if (strcmp(name, combo_name_map[ii].name) == 0)
2256 return combo_name_map[ii].opts;
2263 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2267 if (strcmp(name, "AudioBitrate") == 0)
2268 return lookup_audio_bitrate_int(gval);
2269 else if (strcmp(name, "AudioSamplerate") == 0)
2270 return lookup_audio_rate_int(gval);
2271 else if (strcmp(name, "VideoFramerate") == 0)
2272 return lookup_video_rate_int(gval);
2273 else if (strcmp(name, "AudioMixdown") == 0)
2274 return lookup_mix_int(gval);
2275 else if (strcmp(name, "SrtLanguage") == 0)
2276 return lookup_audio_lang_int(gval);
2277 else if (strcmp(name, "PreferredLanguage") == 0)
2278 return lookup_audio_lang_int(gval);
2281 return lookup_generic_int(find_combo_table(name), gval);
2283 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2288 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2292 if (strcmp(name, "AudioBitrate") == 0)
2293 return lookup_audio_bitrate_int(gval);
2294 else if (strcmp(name, "AudioSamplerate") == 0)
2295 return lookup_audio_rate_int(gval);
2296 else if (strcmp(name, "VideoFramerate") == 0)
2297 return lookup_video_rate_int(gval);
2298 else if (strcmp(name, "AudioMixdown") == 0)
2299 return lookup_mix_int(gval);
2300 else if (strcmp(name, "SrtLanguage") == 0)
2301 return lookup_audio_lang_int(gval);
2302 else if (strcmp(name, "PreferredLanguage") == 0)
2303 return lookup_audio_lang_int(gval);
2306 return lookup_generic_double(find_combo_table(name), gval);
2308 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2313 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2317 if (strcmp(name, "AudioBitrate") == 0)
2318 return lookup_audio_bitrate_option(gval);
2319 else if (strcmp(name, "AudioSamplerate") == 0)
2320 return lookup_audio_rate_option(gval);
2321 else if (strcmp(name, "VideoFramerate") == 0)
2322 return lookup_video_rate_option(gval);
2323 else if (strcmp(name, "AudioMixdown") == 0)
2324 return lookup_mix_option(gval);
2325 else if (strcmp(name, "SrtLanguage") == 0)
2326 return lookup_audio_lang_option(gval);
2327 else if (strcmp(name, "PreferredLanguage") == 0)
2328 return lookup_audio_lang_option(gval);
2331 return lookup_generic_option(find_combo_table(name), gval);
2333 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2338 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2342 if (strcmp(name, "AudioBitrate") == 0)
2343 return lookup_audio_bitrate_option(gval);
2344 else if (strcmp(name, "AudioSamplerate") == 0)
2345 return lookup_audio_rate_option(gval);
2346 else if (strcmp(name, "VideoFramerate") == 0)
2347 return lookup_video_rate_option(gval);
2348 else if (strcmp(name, "AudioMixdown") == 0)
2349 return lookup_mix_option(gval);
2350 else if (strcmp(name, "SrtLanguage") == 0)
2351 return lookup_audio_lang_option(gval);
2352 else if (strcmp(name, "PreferredLanguage") == 0)
2353 return lookup_audio_lang_option(gval);
2356 return lookup_generic_string(find_combo_table(name), gval);
2358 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2363 ghb_update_ui_combo_box(
2364 signal_user_data_t *ud,
2369 GtkComboBox *combo = NULL;
2371 gint handler_id = 0;
2375 g_debug("ghb_update_ui_combo_box() %s\n", name);
2376 // Clearing a combo box causes a rash of "changed" events, even when
2377 // the active item is -1 (inactive). To control things, I'm disabling
2378 // the event till things are settled down.
2379 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2380 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2383 // Valid signal id found. This should always succeed.
2384 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2385 signal_id, 0, 0, 0, 0);
2388 // This should also always succeed
2389 g_signal_handler_block ((gpointer)combo, handler_id);
2395 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2396 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2397 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2398 mix_opts_set(ud->builder, "AudioMixdown");
2399 language_opts_set(ud->builder, "SrtLanguage");
2400 language_opts_set(ud->builder, "PreferredLanguage");
2401 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2402 title_opts_set(ud->builder, "title");
2403 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2404 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2405 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2406 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2407 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2408 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2409 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2410 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2411 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2412 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2413 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2414 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2415 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2416 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2417 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2418 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2419 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2420 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2421 generic_opts_set(ud->builder, "x264_me", &me_opts);
2422 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2423 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2424 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2428 if (strcmp(name, "AudioBitrate") == 0)
2429 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2430 else if (strcmp(name, "AudioSamplerate") == 0)
2431 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2432 else if (strcmp(name, "VideoFramerate") == 0)
2433 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2434 else if (strcmp(name, "AudioMixdown") == 0)
2435 mix_opts_set(ud->builder, "AudioMixdown");
2436 else if (strcmp(name, "SrtLanguage") == 0)
2437 language_opts_set(ud->builder, "SrtLanguage");
2438 else if (strcmp(name, "PreferredLanguage") == 0)
2439 language_opts_set(ud->builder, "PreferredLanguage");
2440 else if (strcmp(name, "SrtCodeset") == 0)
2441 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2442 else if (strcmp(name, "title") == 0)
2443 title_opts_set(ud->builder, "title");
2444 else if (strcmp(name, "SubtitleTrack") == 0)
2445 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2446 else if (strcmp(name, "AudioTrack") == 0)
2447 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2449 generic_opts_set(ud->builder, name, find_combo_table(name));
2453 g_signal_handler_unblock ((gpointer)combo, handler_id);
2458 init_ui_combo_boxes(GtkBuilder *builder)
2462 init_combo_box(builder, "AudioBitrate");
2463 init_combo_box(builder, "AudioSamplerate");
2464 init_combo_box(builder, "VideoFramerate");
2465 init_combo_box(builder, "AudioMixdown");
2466 init_combo_box(builder, "SrtLanguage");
2467 init_combo_box(builder, "PreferredLanguage");
2468 init_combo_box(builder, "SrtCodeset");
2469 init_combo_box(builder, "title");
2470 init_combo_box(builder, "AudioTrack");
2471 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2473 init_combo_box(builder, combo_name_map[ii].name);
2477 static const char * turbo_opts =
2478 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2479 "no-fast-pskip=0:8x8dct=0";
2481 // Construct the x264 options string
2482 // The result is allocated, so someone must free it at some point.
2484 ghb_build_x264opts_string(GValue *settings)
2487 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2494 result = g_strdup("");
2500 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2504 hb_chapter_t * chapter;
2507 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2508 *hh = *mm = *ss = 0;
2509 if (h_scan == NULL) return;
2510 list = hb_get_titles( h_scan );
2511 title = (hb_title_t*)hb_list_item( list, ti );
2512 if (title == NULL) return;
2513 count = hb_list_count( title->list_chapter );
2514 if (ii >= count) return;
2515 chapter = hb_list_item(title->list_chapter, ii);
2516 if (chapter == NULL) return;
2517 *hh = chapter->hours;
2518 *mm = chapter->minutes;
2519 *ss = chapter->seconds;
2523 ghb_get_chapters(gint titleindex)
2527 hb_chapter_t * chapter;
2529 GValue *chapters = NULL;
2531 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2532 if (h_scan == NULL) return NULL;
2533 list = hb_get_titles( h_scan );
2534 title = (hb_title_t*)hb_list_item( list, titleindex );
2535 if (title == NULL) return NULL;
2536 count = hb_list_count( title->list_chapter );
2537 chapters = ghb_array_value_new(count);
2538 for (ii = 0; ii < count; ii++)
2540 chapter = hb_list_item(title->list_chapter, ii);
2541 if (chapter == NULL) break;
2542 if (chapter->title == NULL || chapter->title[0] == 0)
2545 str = g_strdup_printf ("Chapter %2d", ii+1);
2546 ghb_array_append(chapters, ghb_string_value_new(str));
2551 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2558 ghb_ac3_in_audio_list(const GValue *audio_list)
2562 count = ghb_array_len(audio_list);
2563 for (ii = 0; ii < count; ii++)
2568 asettings = ghb_array_get_nth(audio_list, ii);
2569 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2570 if (acodec & HB_ACODEC_AC3)
2577 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2580 GtkListStore *store;
2583 g_debug("audio_rate_opts_add ()\n");
2584 store = get_combo_box_store(builder, name);
2585 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2587 str = g_strdup_printf ("%d", rate);
2588 gtk_list_store_append(store, &iter);
2589 gtk_list_store_set(store, &iter,
2601 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2604 GtkListStore *store;
2606 gboolean done = FALSE;
2608 guint last = (guint)last_rate;
2610 g_debug("audio_bitrate_opts_clean ()\n");
2611 store = get_combo_box_store(builder, name);
2612 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2616 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2618 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2620 done = !gtk_list_store_remove(store, &iter);
2622 else if (ivalue > last)
2625 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2626 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2631 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2632 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2639 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2642 GtkListStore *store;
2645 g_debug("audio_bitrate_opts_set ()\n");
2646 store = get_combo_box_store(builder, name);
2647 gtk_list_store_clear(store);
2648 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2650 gtk_list_store_append(store, &iter);
2651 gtk_list_store_set(store, &iter,
2652 0, hb_audio_bitrates[ii].string,
2654 2, hb_audio_bitrates[ii].string,
2655 3, (gdouble)hb_audio_bitrates[ii].rate,
2656 4, hb_audio_bitrates[ii].string,
2662 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2664 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2668 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2670 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2673 static ghb_status_t hb_status;
2676 ghb_combo_init(signal_user_data_t *ud)
2678 // Set up the list model for the combos
2679 init_ui_combo_boxes(ud->builder);
2680 // Populate all the combos
2681 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2685 ghb_backend_init(gint debug)
2688 h_scan = hb_init( debug, 0 );
2689 h_queue = hb_init( debug, 0 );
2700 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2702 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2703 hb_status.scan.state |= GHB_STATE_SCANNING;
2704 // initialize count and cur to something that won't cause FPE
2705 // when computing progress
2706 hb_status.scan.title_count = 1;
2707 hb_status.scan.title_cur = 0;
2711 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2713 g_debug("ghb_backend_queue_scan()");
2714 hb_scan( h_queue, path, titlenum, 10, 0 );
2715 hb_status.queue.state |= GHB_STATE_SCANNING;
2719 ghb_get_scan_state()
2721 return hb_status.scan.state;
2725 ghb_get_queue_state()
2727 return hb_status.queue.state;
2731 ghb_clear_scan_state(gint state)
2733 hb_status.scan.state &= ~state;
2737 ghb_clear_queue_state(gint state)
2739 hb_status.queue.state &= ~state;
2743 ghb_set_scan_state(gint state)
2745 hb_status.scan.state |= state;
2749 ghb_set_queue_state(gint state)
2751 hb_status.queue.state |= state;
2755 ghb_get_status(ghb_status_t *status)
2757 memcpy(status, &hb_status, sizeof(ghb_status_t));
2766 if (h_scan == NULL) return;
2767 hb_get_state( h_scan, &s_scan );
2768 switch( s_scan.state )
2770 #define p s_scan.param.scanning
2771 case HB_STATE_SCANNING:
2773 hb_status.scan.state |= GHB_STATE_SCANNING;
2774 hb_status.scan.title_count = p.title_count;
2775 hb_status.scan.title_cur = p.title_cur;
2779 case HB_STATE_SCANDONE:
2781 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2782 hb_status.scan.state |= GHB_STATE_SCANDONE;
2785 #define p s_scan.param.working
2786 case HB_STATE_WORKING:
2787 hb_status.scan.state |= GHB_STATE_WORKING;
2788 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2789 hb_status.scan.job_cur = p.job_cur;
2790 hb_status.scan.job_count = p.job_count;
2791 hb_status.scan.progress = p.progress;
2792 hb_status.scan.rate_cur = p.rate_cur;
2793 hb_status.scan.rate_avg = p.rate_avg;
2794 hb_status.scan.hours = p.hours;
2795 hb_status.scan.minutes = p.minutes;
2796 hb_status.scan.seconds = p.seconds;
2797 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2801 case HB_STATE_PAUSED:
2802 hb_status.scan.state |= GHB_STATE_PAUSED;
2805 case HB_STATE_MUXING:
2807 hb_status.scan.state |= GHB_STATE_MUXING;
2810 #define p s_scan.param.workdone
2811 case HB_STATE_WORKDONE:
2815 hb_status.scan.state |= GHB_STATE_WORKDONE;
2816 hb_status.scan.state &= ~GHB_STATE_MUXING;
2817 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2818 hb_status.scan.state &= ~GHB_STATE_WORKING;
2822 hb_status.scan.error = GHB_ERROR_NONE;
2824 case HB_ERROR_CANCELED:
2825 hb_status.scan.error = GHB_ERROR_CANCELED;
2828 hb_status.scan.error = GHB_ERROR_FAIL;
2831 // Delete all remaining jobs of this encode.
2832 // An encode can be composed of multiple associated jobs.
2833 // When a job is stopped, libhb removes it from the job list,
2834 // but does not remove other jobs that may be associated with it.
2835 // Associated jobs are taged in the sequence id.
2836 while ((job = hb_job(h_scan, 0)) != NULL)
2837 hb_rem( h_scan, job );
2841 hb_get_state( h_queue, &s_queue );
2842 switch( s_queue.state )
2844 #define p s_queue.param.scanning
2845 case HB_STATE_SCANNING:
2847 hb_status.queue.state |= GHB_STATE_SCANNING;
2848 hb_status.queue.title_count = p.title_count;
2849 hb_status.queue.title_cur = p.title_cur;
2853 case HB_STATE_SCANDONE:
2855 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2856 hb_status.queue.state |= GHB_STATE_SCANDONE;
2859 #define p s_queue.param.working
2860 case HB_STATE_WORKING:
2861 hb_status.queue.state |= GHB_STATE_WORKING;
2862 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2863 hb_status.queue.job_cur = p.job_cur;
2864 hb_status.queue.job_count = p.job_count;
2865 hb_status.queue.progress = p.progress;
2866 hb_status.queue.rate_cur = p.rate_cur;
2867 hb_status.queue.rate_avg = p.rate_avg;
2868 hb_status.queue.hours = p.hours;
2869 hb_status.queue.minutes = p.minutes;
2870 hb_status.queue.seconds = p.seconds;
2871 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2875 case HB_STATE_PAUSED:
2876 hb_status.queue.state |= GHB_STATE_PAUSED;
2879 case HB_STATE_MUXING:
2881 hb_status.queue.state |= GHB_STATE_MUXING;
2884 #define p s_queue.param.workdone
2885 case HB_STATE_WORKDONE:
2889 hb_status.queue.state |= GHB_STATE_WORKDONE;
2890 hb_status.queue.state &= ~GHB_STATE_MUXING;
2891 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2892 hb_status.queue.state &= ~GHB_STATE_WORKING;
2896 hb_status.queue.error = GHB_ERROR_NONE;
2898 case HB_ERROR_CANCELED:
2899 hb_status.queue.error = GHB_ERROR_CANCELED;
2902 hb_status.queue.error = GHB_ERROR_FAIL;
2905 // Delete all remaining jobs of this encode.
2906 // An encode can be composed of multiple associated jobs.
2907 // When a job is stopped, libhb removes it from the job list,
2908 // but does not remove other jobs that may be associated with it.
2909 // Associated jobs are taged in the sequence id.
2910 while ((job = hb_job(h_queue, 0)) != NULL)
2911 hb_rem( h_queue, job );
2918 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2923 if (h_scan == NULL) return FALSE;
2924 list = hb_get_titles( h_scan );
2925 if( !hb_list_count( list ) )
2927 /* No valid title, stop right there */
2931 title = hb_list_item( list, titleindex );
2932 if (title == NULL) return FALSE; // Bad titleindex
2933 tinfo->width = title->width;
2934 tinfo->height = title->height;
2935 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2936 // Don't allow crop to 0
2937 if (title->crop[0] + title->crop[1] >= title->height)
2938 title->crop[0] = title->crop[1] = 0;
2939 if (title->crop[2] + title->crop[3] >= title->width)
2940 title->crop[2] = title->crop[3] = 0;
2941 tinfo->num_chapters = hb_list_count(title->list_chapter);
2942 tinfo->rate_base = title->rate_base;
2943 tinfo->rate = title->rate;
2944 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2945 title->width * title->pixel_aspect_width,
2946 title->height * title->pixel_aspect_height);
2947 tinfo->hours = title->hours;
2948 tinfo->minutes = title->minutes;
2949 tinfo->seconds = title->seconds;
2950 tinfo->duration = title->duration;
2952 tinfo->angle_count = title->angle_count;
2957 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2959 hb_audio_config_t *audio;
2961 audio = get_hb_audio(titleindex, audioindex);
2962 if (audio == NULL) return FALSE; // Bad audioindex
2963 ainfo->codec = audio->in.codec;
2964 ainfo->bitrate = audio->in.bitrate;
2965 ainfo->samplerate = audio->in.samplerate;
2970 ghb_audio_is_passthru(gint acodec)
2972 g_debug("ghb_audio_is_passthru () \n");
2973 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2977 ghb_get_default_acodec()
2979 return HB_ACODEC_FAAC;
2983 picture_settings_deps(signal_user_data_t *ud)
2985 gboolean autoscale, keep_aspect, enable_keep_aspect;
2986 gboolean enable_scale_width, enable_scale_height;
2987 gboolean enable_disp_width, enable_disp_height, enable_par;
2991 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2994 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2995 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2996 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2998 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2999 if (!enable_keep_aspect)
3001 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3003 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3004 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3006 enable_scale_width = !autoscale && (pic_par != 1);
3007 enable_scale_height = !autoscale && (pic_par != 1);
3008 enable_disp_width = (pic_par == 3) && !keep_aspect;
3009 enable_par = (pic_par == 3) && !keep_aspect;
3010 enable_disp_height = FALSE;
3012 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3013 gtk_widget_set_sensitive(widget, pic_par != 1);
3014 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3015 gtk_widget_set_sensitive(widget, pic_par != 1);
3016 widget = GHB_WIDGET(ud->builder, "scale_width");
3017 gtk_widget_set_sensitive(widget, enable_scale_width);
3018 widget = GHB_WIDGET(ud->builder, "scale_height");
3019 gtk_widget_set_sensitive(widget, enable_scale_height);
3020 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3021 gtk_widget_set_sensitive(widget, enable_disp_width);
3022 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3023 gtk_widget_set_sensitive(widget, enable_disp_height);
3024 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3025 gtk_widget_set_sensitive(widget, enable_par);
3026 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3027 gtk_widget_set_sensitive(widget, enable_par);
3028 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3029 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3030 widget = GHB_WIDGET(ud->builder, "autoscale");
3031 gtk_widget_set_sensitive(widget, pic_par != 1);
3035 ghb_set_scale(signal_user_data_t *ud, gint mode)
3040 gboolean keep_aspect;
3042 gboolean autocrop, autoscale, noscale;
3043 gint crop[4], width, height, par_width, par_height;
3044 gint crop_width, crop_height;
3045 gint aspect_n, aspect_d;
3046 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3047 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3052 gint max_height = 0;
3053 static gboolean busy = FALSE;
3055 g_debug("ghb_set_scale ()\n");
3056 if (h_scan == NULL) return;
3057 list = hb_get_titles( h_scan );
3058 if( !hb_list_count( list ) )
3060 /* No valid title, stop right there */
3065 titleindex = ghb_settings_combo_int(ud->settings, "title");
3066 title = hb_list_item( list, titleindex );
3067 if (title == NULL) return;
3069 if (job == NULL) return;
3071 picture_settings_deps(ud);
3076 // First configure widgets
3077 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3078 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3079 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3080 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3081 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3082 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3083 // alignment constraints rather than scaling to satisfy them.
3084 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3085 // Align dimensions to either 16 or 2 pixels
3086 // The scaler crashes if the dimensions are not divisible by 2
3087 // x264 also will not accept dims that are not multiple of 2
3091 keep_height = FALSE;
3093 // Step needs to be at least 2 because odd widths cause scaler crash
3095 widget = GHB_WIDGET (ud->builder, "scale_width");
3096 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3097 widget = GHB_WIDGET (ud->builder, "scale_height");
3098 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3101 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3102 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3103 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3104 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3105 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3106 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3107 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3108 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3112 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3113 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3114 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3115 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3116 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3117 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3118 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3119 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3121 ghb_title_info_t tinfo;
3122 ghb_get_title_info (&tinfo, titleindex);
3125 crop[0] = tinfo.crop[0];
3126 crop[1] = tinfo.crop[1];
3127 crop[2] = tinfo.crop[2];
3128 crop[3] = tinfo.crop[3];
3129 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3130 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3131 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3132 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3136 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3137 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3138 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3139 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3145 // Adjust the cropping to accomplish the desired width and height
3146 crop_width = tinfo.width - crop[2] - crop[3];
3147 crop_height = tinfo.height - crop[0] - crop[1];
3148 width = MOD_DOWN(crop_width, mod);
3149 height = MOD_DOWN(crop_height, mod);
3151 need1 = (crop_height - height) / 2;
3152 need2 = crop_height - height - need1;
3155 need1 = (crop_width - width) / 2;
3156 need2 = crop_width - width - need1;
3159 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3160 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3161 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3162 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3164 hb_reduce(&aspect_n, &aspect_d,
3165 title->width * title->pixel_aspect_width,
3166 title->height * title->pixel_aspect_height);
3167 crop_width = title->width - crop[2] - crop[3];
3168 crop_height = title->height - crop[0] - crop[1];
3172 height = crop_height;
3176 width = ghb_settings_get_int(ud->settings, "scale_width");
3177 height = ghb_settings_get_int(ud->settings, "scale_height");
3178 max_width = MOD_DOWN(
3179 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3180 max_height = MOD_DOWN(
3181 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3183 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3186 width = title->width - crop[2] - crop[3];
3188 height = title->height - crop[0] - crop[1];
3190 width = MOD_ROUND(width, mod);
3191 height = MOD_ROUND(height, mod);
3193 // Adjust dims according to max values
3195 height = MIN(height, max_height);
3197 width = MIN(width, max_width);
3201 job->anamorphic.mode = pic_par;
3202 // The scaler crashes if the dimensions are not divisible by 2
3203 // Align mod 2. And so does something in x264_encoder_headers()
3204 job->anamorphic.modulus = mod;
3205 job->anamorphic.par_width = title->pixel_aspect_width;
3206 job->anamorphic.par_height = title->pixel_aspect_height;
3207 job->anamorphic.dar_width = 0;
3208 job->anamorphic.dar_height = 0;
3210 if (keep_height && pic_par == 2)
3211 width = ((double)height * crop_width / crop_height) + 0.5;
3213 job->height = height;
3214 job->maxWidth = max_width;
3215 job->maxHeight = max_height;
3216 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3217 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3218 if (job->anamorphic.mode == 3 && !keep_aspect)
3220 job->anamorphic.keep_display_aspect = 0;
3221 if (mode & GHB_PIC_KEEP_PAR)
3223 job->anamorphic.par_width =
3224 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3225 job->anamorphic.par_height =
3226 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3230 job->anamorphic.dar_width =
3231 ghb_settings_get_int(ud->settings,
3232 "PictureDisplayWidth");
3233 job->anamorphic.dar_height = height;
3238 job->anamorphic.keep_display_aspect = 1;
3240 hb_set_anamorphic_size( job, &width, &height,
3241 &par_width, &par_height );
3242 if (job->anamorphic.mode == 3 && !keep_aspect &&
3243 mode & GHB_PIC_KEEP_PAR)
3245 // hb_set_anamorphic_size reduces the par, which we
3246 // don't want in this case because the user is
3247 // explicitely specifying it.
3248 par_width = ghb_settings_get_int(ud->settings,
3250 par_height = ghb_settings_get_int(ud->settings,
3251 "PicturePARHeight");
3256 job->anamorphic.mode = pic_par;
3260 gint new_width, new_height;
3262 // Compute pixel aspect ration.
3263 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3264 // Must scale so that par becomes 1:1
3265 // Try to keep largest dimension
3266 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3267 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3269 if (max_width && new_width > max_width)
3271 height = new_height;
3273 else if (max_height && new_height > max_height)
3277 else if (keep_width)
3279 height = new_height;
3281 else if (keep_height)
3285 else if (width > new_width)
3287 height = new_height;
3293 g_debug("new w %d h %d\n", width, height);
3295 width = MOD_ROUND(width, mod);
3296 height = MOD_ROUND(height, mod);
3298 height = MIN(height, max_height);
3300 width = MIN(width, max_width);
3301 par_width = par_height = 1;
3303 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3304 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3306 gint disp_width, dar_width, dar_height;
3309 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3310 hb_reduce(&dar_width, &dar_height, disp_width, height);
3312 gint iaspect = dar_width * 9 / dar_height;
3313 if (dar_width > 2 * dar_height)
3315 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3317 else if (iaspect <= 16 && iaspect >= 15)
3319 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3321 else if (iaspect <= 12 && iaspect >= 11)
3323 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3327 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3329 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3331 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3332 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3333 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3334 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3339 set_preview_job_settings(hb_job_t *job, GValue *settings)
3341 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3342 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3343 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3344 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3346 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3347 job->anamorphic.modulus =
3348 ghb_settings_combo_int(settings, "PictureModulus");
3349 job->width = ghb_settings_get_int(settings, "scale_width");
3350 job->height = ghb_settings_get_int(settings, "scale_height");
3351 if (ghb_settings_get_boolean(settings, "show_crop"))
3353 gdouble xscale = (gdouble)job->width /
3354 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3355 gdouble yscale = (gdouble)job->height /
3356 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3358 job->width += xscale * (job->crop[2] + job->crop[3]);
3359 job->height += yscale * (job->crop[0] + job->crop[1]);
3364 job->anamorphic.modulus = 2;
3367 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3368 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3369 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3371 gboolean keep_aspect;
3372 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3373 if (job->anamorphic.mode)
3375 job->anamorphic.par_width = job->title->pixel_aspect_width;
3376 job->anamorphic.par_height = job->title->pixel_aspect_height;
3377 job->anamorphic.dar_width = 0;
3378 job->anamorphic.dar_height = 0;
3380 if (job->anamorphic.mode == 3 && !keep_aspect)
3382 job->anamorphic.keep_display_aspect = 0;
3383 job->anamorphic.par_width =
3384 ghb_settings_get_int(settings, "PicturePARWidth");
3385 job->anamorphic.par_height =
3386 ghb_settings_get_int(settings, "PicturePARHeight");
3390 job->anamorphic.keep_display_aspect = 1;
3396 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3403 if (h_scan == NULL) return 1500;
3404 list = hb_get_titles( h_scan );
3405 title = hb_list_item( list, titleindex );
3406 if (title == NULL) return 1500;
3408 if (job == NULL) return 1500;
3409 size = ghb_settings_get_int(settings, "VideoTargetSize");
3410 return hb_calc_bitrate( job, size );
3414 ghb_validate_filter_string(const gchar *str, gint max_fields)
3420 if (str == NULL || *str == 0) return TRUE;
3423 val = g_strtod(str, &end);
3425 { // Found a numeric value
3427 // negative max_fields means infinate
3428 if (max_fields >= 0 && fields > max_fields) return FALSE;
3442 ghb_validate_filters(signal_user_data_t *ud)
3449 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3452 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3453 if (!ghb_validate_filter_string(str, 4))
3455 message = g_strdup_printf(
3456 "Invalid Deinterlace Settings:\n\n%s\n",
3458 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3466 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3469 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3470 if (!ghb_validate_filter_string(str, 6))
3472 message = g_strdup_printf(
3473 "Invalid Detelecine Settings:\n\n%s\n",
3475 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3483 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3486 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3487 if (!ghb_validate_filter_string(str, 15))
3489 message = g_strdup_printf(
3490 "Invalid Decomb Settings:\n\n%s\n",
3492 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3500 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3503 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3504 if (!ghb_validate_filter_string(str, 4))
3506 message = g_strdup_printf(
3507 "Invalid Denoise Settings:\n\n%s\n",
3509 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3520 ghb_validate_video(signal_user_data_t *ud)
3525 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3526 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3527 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3528 (vcodec == HB_VCODEC_THEORA))
3530 // mp4|avi/theora combination is not supported.
3531 message = g_strdup_printf(
3532 "Theora is not supported in the MP4 and AVI containers.\n\n"
3533 "You should choose a different video codec or container.\n"
3534 "If you continue, FFMPEG will be chosen for you.");
3535 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3541 vcodec = HB_VCODEC_FFMPEG;
3542 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3548 ghb_validate_subtitles(signal_user_data_t *ud)
3554 if (h_scan == NULL) return FALSE;
3555 list = hb_get_titles( h_scan );
3556 if( !hb_list_count( list ) )
3558 /* No valid title, stop right there */
3559 g_message("No title found.\n");
3565 titleindex = ghb_settings_combo_int(ud->settings, "title");
3566 title = hb_list_item( list, titleindex );
3567 if (title == NULL) return FALSE;
3568 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3570 const GValue *slist, *settings;
3571 gint count, ii, source;
3572 gboolean burned, one_burned = FALSE;
3574 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3575 count = ghb_array_len(slist);
3576 for (ii = 0; ii < count; ii++)
3578 settings = ghb_array_get_nth(slist, ii);
3579 source = ghb_settings_get_int(settings, "SubtitleSource");
3580 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3581 if (burned && one_burned)
3583 // MP4 can only handle burned vobsubs. make sure there isn't
3584 // already something burned in the list
3585 message = g_strdup_printf(
3586 "Only one subtitle may be burned into the video.\n\n"
3587 "You should change your subtitle selections.\n"
3588 "If you continue, some subtitles will be lost.");
3589 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3601 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3603 // MP4 can only handle burned vobsubs. make sure there isn't
3604 // already something burned in the list
3605 message = g_strdup_printf(
3606 "Your chosen container does not support soft bitmap subtitles.\n\n"
3607 "You should change your subtitle selections.\n"
3608 "If you continue, some subtitles will be lost.");
3609 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3610 "Cancel", "Continue"))
3618 if (source == SRTSUB)
3622 filename = ghb_settings_get_string(settings, "SrtFile");
3623 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3625 message = g_strdup_printf(
3626 "Srt file does not exist or not a regular file.\n\n"
3627 "You should choose a valid file.\n"
3628 "If you continue, this subtitle will be ignored.");
3629 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3630 "Cancel", "Continue"))
3644 ghb_validate_audio(signal_user_data_t *ud)
3651 if (h_scan == NULL) return FALSE;
3652 list = hb_get_titles( h_scan );
3653 if( !hb_list_count( list ) )
3655 /* No valid title, stop right there */
3656 g_message("No title found.\n");
3662 titleindex = ghb_settings_combo_int(ud->settings, "title");
3663 title = hb_list_item( list, titleindex );
3664 if (title == NULL) return FALSE;
3665 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3667 const GValue *audio_list;
3670 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3671 count = ghb_array_len(audio_list);
3672 for (ii = 0; ii < count; ii++)
3675 hb_audio_config_t *taudio;
3677 asettings = ghb_array_get_nth(audio_list, ii);
3678 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3679 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3680 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3681 title->list_audio, track );
3682 if (!(taudio->in.codec & codec) &&
3683 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3685 // Not supported. AC3 is passthrough only, so input must be AC3
3686 message = g_strdup_printf(
3687 "The source does not support Pass-Thru.\n\n"
3688 "You should choose a different audio codec.\n"
3689 "If you continue, one will be chosen for you.");
3690 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3696 if (mux == HB_MUX_AVI)
3698 codec = HB_ACODEC_LAME;
3702 codec = HB_ACODEC_FAAC;
3704 value = get_acodec_value(codec);
3705 ghb_settings_take_value(asettings, "AudioEncoder", value);
3707 gchar *a_unsup = NULL;
3708 gchar *mux_s = NULL;
3709 if (mux == HB_MUX_MP4)
3712 // mp4/mp3|vorbis combination is not supported.
3713 if (codec == HB_ACODEC_LAME)
3716 codec = HB_ACODEC_FAAC;
3718 if (codec == HB_ACODEC_VORBIS)
3721 codec = HB_ACODEC_FAAC;
3723 if (codec == HB_ACODEC_DCA)
3726 codec = HB_ACODEC_FAAC;
3729 else if (mux == HB_MUX_AVI)
3732 // avi/faac|vorbis combination is not supported.
3733 if (codec == HB_ACODEC_FAAC)
3736 codec = HB_ACODEC_LAME;
3738 if (codec == HB_ACODEC_VORBIS)
3741 codec = HB_ACODEC_LAME;
3744 else if (mux == HB_MUX_OGM)
3747 // avi/faac|vorbis combination is not supported.
3748 if (codec == HB_ACODEC_FAAC)
3751 codec = HB_ACODEC_VORBIS;
3753 if (codec == HB_ACODEC_AC3)
3756 codec = HB_ACODEC_VORBIS;
3758 if (codec == HB_ACODEC_DCA)
3761 codec = HB_ACODEC_VORBIS;
3766 message = g_strdup_printf(
3767 "%s is not supported in the %s container.\n\n"
3768 "You should choose a different audio codec.\n"
3769 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3770 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3776 value = get_acodec_value(codec);
3777 ghb_settings_take_value(asettings, "AudioEncoder", value);
3779 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3780 gboolean allow_mono = TRUE;
3781 gboolean allow_stereo = TRUE;
3782 gboolean allow_dolby = TRUE;
3783 gboolean allow_dpl2 = TRUE;
3784 gboolean allow_6ch = TRUE;
3786 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3787 (codec != HB_ACODEC_LAME);
3788 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3790 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3792 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3793 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3794 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3795 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3797 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3798 (codec != HB_ACODEC_LAME) &&
3799 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3800 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3802 gchar *mix_unsup = NULL;
3803 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3807 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3809 mix_unsup = "stereo";
3811 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3813 mix_unsup = "Dolby";
3815 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3817 mix_unsup = "Dolby Pro Logic II";
3819 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3821 mix_unsup = "6 Channel";
3825 message = g_strdup_printf(
3826 "The source audio does not support %s mixdown.\n\n"
3827 "You should choose a different mixdown.\n"
3828 "If you continue, one will be chosen for you.", mix_unsup);
3829 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3835 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3836 value = get_amix_value(mix);
3837 ghb_settings_take_value(asettings, "AudioMixdown", value);
3844 ghb_validate_vquality(GValue *settings)
3850 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3851 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3853 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3854 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3858 case HB_VCODEC_X264:
3864 case HB_VCODEC_FFMPEG:
3870 case HB_VCODEC_THEORA:
3882 if (vquality < min || vquality > max)
3884 message = g_strdup_printf(
3885 "Interesting video quality choise: %d\n\n"
3886 "Typical values range from %d to %d.\n"
3887 "Are you sure you wish to use this setting?",
3888 (gint)vquality, min, max);
3889 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3890 "Cancel", "Continue"))
3902 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3907 static gchar *x264opts;
3909 gboolean tweaks = FALSE;
3910 gchar *detel_str = NULL;
3911 gchar *decomb_str = NULL;
3912 gchar *deint_str = NULL;
3913 gchar *deblock_str = NULL;
3914 gchar *denoise_str = NULL;
3915 gchar *dest_str = NULL;
3917 g_debug("add_job()\n");
3918 if (h == NULL) return;
3919 list = hb_get_titles( h );
3920 if( !hb_list_count( list ) )
3922 /* No valid title, stop right there */
3926 title = hb_list_item( list, titleindex );
3927 if (title == NULL) return;
3929 /* Set job settings */
3931 if (job == NULL) return;
3933 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3934 if (job->start_at_preview)
3936 job->seek_points = ghb_settings_get_int(js, "preview_count");
3937 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3940 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3941 job->mux = ghb_settings_combo_int(js, "FileFormat");
3942 if (job->mux == HB_MUX_MP4)
3944 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3945 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3949 job->largeFileSize = FALSE;
3950 job->mp4_optimize = FALSE;
3952 if (!job->start_at_preview)
3954 gint chapter_start, chapter_end;
3955 chapter_start = ghb_settings_get_int(js, "start_chapter");
3956 chapter_end = ghb_settings_get_int(js, "end_chapter");
3957 gint num_chapters = hb_list_count(title->list_chapter);
3958 job->chapter_start = MIN( num_chapters, chapter_start );
3959 job->chapter_end = MAX( job->chapter_start, chapter_end );
3961 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3962 if (job->chapter_start == job->chapter_end)
3963 job->chapter_markers = 0;
3964 if ( job->chapter_markers )
3971 chapters = ghb_settings_get_value(js, "chapter_list");
3972 count = ghb_array_len(chapters);
3973 for(chap = chapter_start; chap <= chapter_end; chap++)
3975 hb_chapter_t * chapter_s;
3981 chapter = ghb_array_get_nth(chapters, chap-1);
3982 name = ghb_value_string(chapter);
3986 name = g_strdup_printf ("Chapter %2d", chap);
3988 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3989 strncpy(chapter_s->title, name, 1023);
3990 chapter_s->title[1023] = '\0';
3995 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3996 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3997 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3998 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4001 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4002 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4004 job->deinterlace = (deint != 0) ? 1 : 0;
4006 job->deinterlace = 0;
4007 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4009 gboolean keep_aspect;
4010 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4011 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4012 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
4013 if (job->anamorphic.mode)
4015 job->anamorphic.par_width = title->pixel_aspect_width;
4016 job->anamorphic.par_height = title->pixel_aspect_height;
4017 job->anamorphic.dar_width = 0;
4018 job->anamorphic.dar_height = 0;
4020 if (job->anamorphic.mode == 3 && !keep_aspect)
4022 job->anamorphic.keep_display_aspect = 0;
4023 job->anamorphic.par_width =
4024 ghb_settings_get_int(js, "PicturePARWidth");
4025 job->anamorphic.par_height =
4026 ghb_settings_get_int(js, "PicturePARHeight");
4030 job->anamorphic.keep_display_aspect = 1;
4034 /* Add selected filters */
4035 job->filters = hb_list_init();
4036 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4041 if (detel_opts.map[detel].svalue != NULL)
4042 detel_str = g_strdup(detel_opts.map[detel].svalue);
4045 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4046 hb_filter_detelecine.settings = detel_str;
4047 hb_list_add( job->filters, &hb_filter_detelecine );
4053 if (decomb_opts.map[decomb].svalue != NULL)
4054 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4057 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4058 hb_filter_decomb.settings = decomb_str;
4059 hb_list_add( job->filters, &hb_filter_decomb );
4061 if( job->deinterlace )
4065 if (deint_opts.map[deint].svalue != NULL)
4066 deint_str = g_strdup(deint_opts.map[deint].svalue);
4069 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4070 hb_filter_deinterlace.settings = deint_str;
4071 hb_list_add( job->filters, &hb_filter_deinterlace );
4073 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4076 deblock_str = g_strdup_printf("%d", deblock);
4077 hb_filter_deblock.settings = deblock_str;
4078 hb_list_add( job->filters, &hb_filter_deblock );
4080 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4085 if (denoise_opts.map[denoise].svalue != NULL)
4086 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4089 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4090 hb_filter_denoise.settings = denoise_str;
4091 hb_list_add( job->filters, &hb_filter_denoise );
4093 job->width = ghb_settings_get_int(js, "scale_width");
4094 job->height = ghb_settings_get_int(js, "scale_height");
4096 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4097 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
4098 (job->vcodec == HB_VCODEC_THEORA))
4100 // mp4|avi/theora combination is not supported.
4101 job->vcodec = HB_VCODEC_FFMPEG;
4103 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4105 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4107 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4110 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4111 job->vquality = vquality;
4114 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4116 job->vquality = -1.0;
4117 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4120 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4123 job->vrate = title->rate;
4124 job->vrate_base = title->rate_base;
4129 job->vrate = 27000000;
4130 job->vrate_base = vrate;
4134 // AVI container does not support variable frame rate.
4135 // OGM supports variable frame rate, but bases all timing on
4136 // DTS, which breaks when b-frames are used since it is
4137 // impossible to reconstruct PTS from DTS when the framerate
4139 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
4144 const GValue *audio_list;
4148 audio_list = ghb_settings_get_value(js, "audio_list");
4149 count = ghb_array_len(audio_list);
4150 for (ii = 0; ii < count; ii++)
4153 hb_audio_config_t audio;
4154 hb_audio_config_t *taudio;
4156 hb_audio_config_init(&audio);
4157 asettings = ghb_array_get_nth(audio_list, ii);
4158 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4159 audio.out.track = tcount;
4160 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4161 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4162 title->list_audio, audio.in.track );
4163 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4165 if (!(taudio->in.codec & audio.out.codec))
4167 // Not supported. AC3 is passthrough only, so input must be AC3
4168 if (job->mux == HB_MUX_AVI)
4170 audio.out.codec = HB_ACODEC_LAME;
4174 audio.out.codec = HB_ACODEC_FAAC;
4179 audio.out.codec &= taudio->in.codec;
4182 if ((job->mux == HB_MUX_MP4) &&
4183 ((audio.out.codec == HB_ACODEC_LAME) ||
4184 (audio.out.codec == HB_ACODEC_VORBIS)))
4186 // mp4/mp3|vorbis combination is not supported.
4187 audio.out.codec = HB_ACODEC_FAAC;
4189 if ((job->mux == HB_MUX_AVI) &&
4190 ((audio.out.codec == HB_ACODEC_FAAC) ||
4191 (audio.out.codec == HB_ACODEC_VORBIS)))
4193 // avi/faac|vorbis combination is not supported.
4194 audio.out.codec = HB_ACODEC_LAME;
4196 if ((job->mux == HB_MUX_OGM) &&
4197 ((audio.out.codec == HB_ACODEC_FAAC) ||
4198 (audio.out.codec == HB_ACODEC_AC3) ||
4199 (audio.out.codec == HB_ACODEC_DCA)))
4201 // ogm/faac|ac3 combination is not supported.
4202 audio.out.codec = HB_ACODEC_VORBIS;
4204 audio.out.dynamic_range_compression =
4205 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4206 if (audio.out.dynamic_range_compression < 1.0)
4207 audio.out.dynamic_range_compression = 0.0;
4209 // It would be better if this were done in libhb for us, but its not yet.
4210 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
4212 audio.out.mixdown = 0;
4216 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4217 // Make sure the mixdown is valid and pick a new one if not.
4218 audio.out.mixdown = ghb_get_best_mix(titleindex,
4219 audio.in.track, audio.out.codec, audio.out.mixdown);
4221 ghb_settings_combo_int(asettings, "AudioBitrate");
4222 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4223 if (srate == 0) // 0 is same as source
4224 audio.out.samplerate = taudio->in.samplerate;
4226 audio.out.samplerate = srate;
4229 // Add it to the jobs audio list
4230 hb_audio_add( job, &audio );
4233 // I was tempted to move this up with the reset of the video quality
4234 // settings, but I suspect the settings above need to be made
4235 // first in order for hb_calc_bitrate to be accurate.
4236 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4240 size = ghb_settings_get_int(js, "VideoTargetSize");
4241 job->vbitrate = hb_calc_bitrate( job, size );
4242 job->vquality = -1.0;
4245 dest_str = ghb_settings_get_string(js, "destination");
4246 job->file = dest_str;
4247 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
4249 const GValue *subtitle_list;
4251 gboolean force, burned, def, one_burned = FALSE;
4253 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4254 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4255 count = ghb_array_len(subtitle_list);
4256 for (ii = 0; ii < count; ii++)
4261 ssettings = ghb_array_get_nth(subtitle_list, ii);
4263 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4264 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4265 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4266 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4268 if (source == SRTSUB)
4270 hb_subtitle_config_t sub_config;
4271 gchar *filename, *lang, *code;
4273 filename = ghb_settings_get_string(ssettings, "SrtFile");
4274 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4278 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4279 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4280 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4281 strncpy(sub_config.src_filename, filename, 128);
4282 strncpy(sub_config.src_codeset, code, 40);
4283 sub_config.force = 0;
4284 sub_config.dest = PASSTHRUSUB;
4285 sub_config.default_track = def;
4287 hb_srt_add( job, &sub_config, lang);
4295 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4298 if (!burned && job->mux == HB_MUX_MKV)
4300 job->select_subtitle_config.dest = PASSTHRUSUB;
4302 else if (!burned && job->mux == HB_MUX_MP4)
4304 // Skip any non-burned vobsubs when output is mp4
4309 // Only allow one subtitle to be burned into the video
4312 job->select_subtitle_config.dest = RENDERSUB;
4315 job->select_subtitle_config.force = force;
4316 job->select_subtitle_config.default_track = def;
4317 job->indepth_scan = 1;
4318 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4320 else if (subtitle >= 0)
4322 hb_subtitle_t * subt;
4323 hb_subtitle_config_t sub_config;
4325 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4326 sub_config = subt->config;
4329 if (!burned && job->mux == HB_MUX_MKV &&
4330 subt->format == PICTURESUB)
4332 sub_config.dest = PASSTHRUSUB;
4334 else if (!burned && job->mux == HB_MUX_MP4 &&
4335 subt->format == PICTURESUB)
4337 // Skip any non-burned vobsubs when output is mp4
4340 else if ( burned && subt->format == PICTURESUB )
4342 // Only allow one subtitle to be burned into the video
4347 sub_config.force = force;
4348 sub_config.default_track = def;
4349 hb_subtitle_add( job, &sub_config, subtitle );
4354 // TODO: libhb holds onto a reference to the x264opts and is not
4355 // finished with it until encoding the job is done. But I can't
4356 // find a way to get at the job before it is removed in order to
4357 // free up the memory I am allocating here.
4358 // The short story is THIS LEAKS.
4359 x264opts = ghb_build_x264opts_string(js);
4361 if( *x264opts == '\0' )
4367 if (job->indepth_scan == 1)
4369 // Subtitle scan. Look for subtitle matching audio language
4372 * When subtitle scan is enabled do a fast pre-scan job
4373 * which will determine which subtitles to enable, if any.
4376 job->indepth_scan = 1;
4377 job->x264opts = NULL;
4380 * Add the pre-scan job
4382 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4386 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4387 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4390 * If subtitle_scan is enabled then only turn it on
4391 * for the second pass and then off again for the
4395 job->indepth_scan = 0;
4398 * If turbo options have been selected then append them
4399 * to the x264opts now (size includes one ':' and the '\0')
4401 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4403 gchar *tmp_x264opts;
4407 badapt = ghb_lookup_badapt(x264opts);
4410 extra_opts = g_strdup_printf("%s", turbo_opts);
4414 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4419 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4424 * No x264opts to modify, but apply the turbo options
4425 * anyway as they may be modifying defaults
4427 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4431 job->x264opts = tmp_x264opts;
4435 job->x264opts = x264opts;
4437 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4439 //if (job->x264opts != NULL)
4440 // g_free(job->x264opts);
4444 * On the second pass we turn off subtitle scan so that we
4445 * can actually encode using any subtitles that were auto
4446 * selected in the first pass (using the whacky select-subtitle
4447 * attribute of the job).
4449 job->indepth_scan = 0;
4450 job->x264opts = x264opts;
4451 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4453 //if (job->x264opts != NULL)
4454 // g_free(job->x264opts);
4458 job->x264opts = x264opts;
4459 job->indepth_scan = 0;
4461 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4463 //if (job->x264opts != NULL)
4464 // g_free(job->x264opts);
4467 // clean up audio list
4468 gint num_audio_tracks = hb_list_count(job->list_audio);
4469 for(ii = 0; ii < num_audio_tracks; ii++)
4471 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4472 hb_list_rem(job->list_audio, audio);
4476 // clean up subtitle list
4477 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4478 for(ii = 0; ii < num_subtitle_tracks; ii++)
4480 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4481 hb_list_rem(job->list_subtitle, subtitle);
4485 if (detel_str) g_free(detel_str);
4486 if (decomb_str) g_free(decomb_str);
4487 if (deint_str) g_free(deint_str);
4488 if (deblock_str) g_free(deblock_str);
4489 if (denoise_str) g_free(denoise_str);
4490 if (dest_str) g_free(dest_str);
4494 ghb_add_job(GValue *js, gint unique_id)
4496 // Since I'm doing a scan of the single title I want just prior
4497 // to adding the job, there is only the one title to choose from.
4498 add_job(h_queue, js, unique_id, 0);
4502 ghb_add_live_job(GValue *js, gint unique_id)
4504 // Since I'm doing a scan of the single title I want just prior
4505 // to adding the job, there is only the one title to choose from.
4506 gint titleindex = ghb_settings_combo_int(js, "title");
4507 add_job(h_scan, js, unique_id, titleindex);
4511 ghb_remove_job(gint unique_id)
4516 // Multiples passes all get the same id
4518 // Go backwards through list, so reordering doesn't screw me.
4519 ii = hb_count(h_queue) - 1;
4520 while ((job = hb_job(h_queue, ii--)) != NULL)
4522 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4523 hb_rem(h_queue, job);
4530 hb_start( h_queue );
4540 ghb_start_live_encode()
4546 ghb_stop_live_encode()
4555 hb_get_state2( h_queue, &s );
4557 if( s.state == HB_STATE_PAUSED )
4559 hb_status.queue.state &= ~GHB_STATE_PAUSED;
4560 hb_resume( h_queue );
4564 hb_status.queue.state |= GHB_STATE_PAUSED;
4565 hb_pause( h_queue );
4580 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4583 gint channels = gdk_pixbuf_get_n_channels (pb);
4584 gint stride = gdk_pixbuf_get_rowstride (pb);
4586 for (jj = 0; jj < width; jj++)
4588 dst = pixels + y * stride + (x+jj) * channels;
4589 for (ii = 0; ii < len; ii++)
4610 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4613 gint channels = gdk_pixbuf_get_n_channels (pb);
4614 gint stride = gdk_pixbuf_get_rowstride (pb);
4616 for (jj = 0; jj < width; jj++)
4618 dst = pixels + (y+jj) * stride + x * channels;
4619 for (ii = 0; ii < len; ii++)
4640 gint line_width = 8;
4647 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4652 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4654 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4660 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4662 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4668 ghb_get_preview_image(
4671 signal_user_data_t *ud,
4679 settings = ud->settings;
4680 list = hb_get_titles( h_scan );
4681 if( !hb_list_count( list ) )
4683 /* No valid title, stop right there */
4686 title = hb_list_item( list, titleindex );
4687 if (title == NULL) return NULL;
4688 if (title->job == NULL) return NULL;
4689 set_preview_job_settings(title->job, settings);
4691 // hb_get_preview doesn't compensate for anamorphic, so lets
4692 // calculate scale factors
4693 gint width, height, par_width = 1, par_height = 1;
4694 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4697 hb_set_anamorphic_size( title->job, &width, &height,
4698 &par_width, &par_height );
4701 // Make sure we have a big enough buffer to receive the image from libhb
4702 gint dstWidth = title->job->width;
4703 gint dstHeight= title->job->height;
4705 static guint8 *buffer = NULL;
4706 static gint bufferSize = 0;
4709 newSize = dstWidth * dstHeight * 4;
4710 if( bufferSize < newSize )
4712 bufferSize = newSize;
4713 buffer = (guint8*) g_realloc( buffer, bufferSize );
4715 hb_get_preview( h_scan, title, index, buffer );
4717 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4718 // libhb's format something suitable.
4720 // The image data returned by hb_get_preview is 4 bytes per pixel,
4721 // BGRA format. Alpha is ignored.
4723 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4724 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4726 guint32 *src = (guint32*)buffer;
4727 guint8 *dst = pixels;
4730 gint channels = gdk_pixbuf_get_n_channels (preview);
4731 gint stride = gdk_pixbuf_get_rowstride (preview);
4734 for (ii = 0; ii < dstHeight; ii++)
4737 for (jj = 0; jj < dstWidth; jj++)
4739 tmp[0] = src[0] >> 16;
4740 tmp[1] = src[0] >> 8;
4741 tmp[2] = src[0] >> 0;
4747 gint w = ghb_settings_get_int(settings, "scale_width");
4748 gint h = ghb_settings_get_int(settings, "scale_height");
4749 ghb_par_scale(ud, &w, &h, par_width, par_height);
4751 gint c0, c1, c2, c3;
4752 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4753 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4754 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4755 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4757 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4758 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4760 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4763 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4767 gint orig_w, orig_h;
4770 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4774 ss = gdk_screen_get_default();
4775 s_w = gdk_screen_get_width(ss);
4776 s_h = gdk_screen_get_height(ss);
4780 if (dstWidth > s_w * factor / 100)
4782 dstWidth = s_w * factor / 100;
4783 dstHeight = dstHeight * dstWidth / orig_w;
4785 if (dstHeight > s_h * factor / 100)
4787 dstHeight = s_h * factor / 100;
4788 dstWidth = dstWidth * dstHeight / orig_h;
4790 xscale *= (gdouble)dstWidth / orig_w;
4791 yscale *= (gdouble)dstHeight / orig_h;
4792 w *= (gdouble)dstWidth / orig_w;
4793 h *= (gdouble)dstHeight / orig_h;
4795 GdkPixbuf *scaled_preview;
4796 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4797 if (ghb_settings_get_boolean(settings, "show_crop"))
4804 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4806 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4808 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4810 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4812 g_object_unref (preview);
4813 return scaled_preview;
4817 sanitize_volname(gchar *name)
4842 ghb_dvd_volname(const gchar *device)
4845 name = hb_dvd_name((gchar*)device);
4846 if (name != NULL && name[0] != 0)
4848 name = g_strdup(name);
4849 sanitize_volname(name);