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 "x264handler.h"
42 const gchar *shortOpt;
53 static gchar **index_str = NULL;
54 static gint index_str_size = 0;
57 index_str_init(gint max_index)
61 if (max_index+1 > index_str_size)
63 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
64 for (ii = index_str_size; ii <= max_index; ii++)
66 index_str[ii] = g_strdup_printf("%d", ii);
68 index_str_size = max_index + 1;
72 static options_map_t d_when_complete_opts[] =
74 {"Do Nothing", "nothing", 0, "0"},
75 {"Show Notification", "notify", 1, "1"},
76 {"Put Computer To Sleep", "sleep", 2, "2"},
77 {"Shutdown Computer", "shutdown", 3, "3"},
79 combo_opts_t when_complete_opts =
81 sizeof(d_when_complete_opts)/sizeof(options_map_t),
85 static options_map_t d_par_opts[] =
88 {"Strict", "1", 1, "1"},
89 {"Loose", "2", 2, "2"},
90 {"Custom", "3", 3, "3"},
92 combo_opts_t par_opts =
94 sizeof(d_par_opts)/sizeof(options_map_t),
98 static options_map_t d_alignment_opts[] =
103 {"16", "16", 16, "16"},
105 combo_opts_t alignment_opts =
107 sizeof(d_alignment_opts)/sizeof(options_map_t),
111 static options_map_t d_logging_opts[] =
117 combo_opts_t logging_opts =
119 sizeof(d_logging_opts)/sizeof(options_map_t),
123 static options_map_t d_log_longevity_opts[] =
125 {"Week", "week", 7, "7"},
126 {"Month", "month", 30, "30"},
127 {"Year", "year", 365, "365"},
128 {"Immortal", "immortal", 366, "366"},
130 combo_opts_t log_longevity_opts =
132 sizeof(d_log_longevity_opts)/sizeof(options_map_t),
136 static options_map_t d_appcast_update_opts[] =
138 {"Never", "never", 0, "never"},
139 {"Daily", "daily", 1, "daily"},
140 {"Weekly", "weekly", 2, "weekly"},
141 {"Monthly", "monthly", 3, "monthly"},
143 combo_opts_t appcast_update_opts =
145 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
146 d_appcast_update_opts
149 static options_map_t d_vqual_granularity_opts[] =
151 {"0.2", "0.2", 0.2, "0.2"},
152 {"0.25", "0.25", 0.25, "0.25"},
153 {"0.5", "0.5", 0.5, "0.5"},
156 combo_opts_t vqual_granularity_opts =
158 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
159 d_vqual_granularity_opts
162 static options_map_t d_container_opts[] =
164 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
165 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
167 combo_opts_t container_opts =
169 sizeof(d_container_opts)/sizeof(options_map_t),
173 static options_map_t d_detel_opts[] =
175 {"None", "none", 0, ""},
176 {"Custom", "custom", 1, ""},
177 {"Default","default",2, NULL},
179 combo_opts_t detel_opts =
181 sizeof(d_detel_opts)/sizeof(options_map_t),
185 static options_map_t d_decomb_opts[] =
187 {"None", "none", 0, ""},
188 {"Custom", "custom", 1, ""},
189 {"Default","default",2, NULL},
191 combo_opts_t decomb_opts =
193 sizeof(d_decomb_opts)/sizeof(options_map_t),
197 static options_map_t d_deint_opts[] =
199 {"None", "none", 0, ""},
200 {"Custom", "custom", 1, ""},
201 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
202 {"Slow", "slow", 3, "2:-1:-1:0:1"},
203 {"Slower", "slower", 4, "0:-1:-1:0:1"},
205 combo_opts_t deint_opts =
207 sizeof(d_deint_opts)/sizeof(options_map_t),
211 static options_map_t d_denoise_opts[] =
213 {"None", "none", 0, ""},
214 {"Custom", "custom", 1, ""},
215 {"Weak", "weak", 2, "2:1:2:3"},
216 {"Medium", "medium", 3, "3:2:2:3"},
217 {"Strong", "strong", 4, "7:7:5:5"},
219 combo_opts_t denoise_opts =
221 sizeof(d_denoise_opts)/sizeof(options_map_t),
225 static options_map_t d_vcodec_opts[] =
227 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
228 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
229 {"Theora", "theora", HB_VCODEC_THEORA, ""},
231 combo_opts_t vcodec_opts =
233 sizeof(d_vcodec_opts)/sizeof(options_map_t),
237 static options_map_t d_acodec_opts[] =
239 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
240 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
241 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
242 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
243 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
244 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
246 combo_opts_t acodec_opts =
248 sizeof(d_acodec_opts)/sizeof(options_map_t),
252 static options_map_t d_direct_opts[] =
254 {"None", "none", 0, "none"},
255 {"Spatial", "spatial", 1, "spatial"},
256 {"Temporal", "temporal", 2, "temporal"},
257 {"Automatic", "auto", 3, "auto"},
259 combo_opts_t direct_opts =
261 sizeof(d_direct_opts)/sizeof(options_map_t),
265 static options_map_t d_badapt_opts[] =
267 {"Off", "0", 0, "0"},
268 {"Fast", "1", 1, "1"},
269 {"Optimal", "2", 2, "2"},
271 combo_opts_t badapt_opts =
273 sizeof(d_badapt_opts)/sizeof(options_map_t),
277 static options_map_t d_me_opts[] =
279 {"Diamond", "dia", 0, "dia"},
280 {"Hexagon", "hex", 1, "hex"},
281 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
282 {"Exhaustive", "esa", 3, "esa"},
283 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
285 combo_opts_t me_opts =
287 sizeof(d_me_opts)/sizeof(options_map_t),
291 static options_map_t d_subme_opts[] =
303 combo_opts_t subme_opts =
305 sizeof(d_subme_opts)/sizeof(options_map_t),
309 static options_map_t d_analyse_opts[] =
311 {"Some", "some", 0, "some"},
312 {"None", "none", 1, "none"},
313 {"All", "all", 2, "all"},
314 {"Custom", "custom", 3, "all"},
316 combo_opts_t analyse_opts =
318 sizeof(d_analyse_opts)/sizeof(options_map_t),
322 static options_map_t d_trellis_opts[] =
324 {"Disabled", "0", 0, "0"},
325 {"Final Macro Block", "1", 1, "1"},
326 {"Always", "2", 2, "2"},
328 combo_opts_t trellis_opts =
330 sizeof(d_trellis_opts)/sizeof(options_map_t),
334 combo_opts_t subtitle_opts =
340 combo_opts_t title_opts =
346 combo_opts_t audio_track_opts =
358 combo_name_map_t combo_name_map[] =
360 {"WhenComplete", &when_complete_opts},
361 {"PicturePAR", &par_opts},
362 {"PictureModulus", &alignment_opts},
363 {"LoggingLevel", &logging_opts},
364 {"LogLongevity", &log_longevity_opts},
365 {"check_updates", &appcast_update_opts},
366 {"VideoQualityGranularity", &vqual_granularity_opts},
367 {"FileFormat", &container_opts},
368 {"PictureDeinterlace", &deint_opts},
369 {"PictureDecomb", &decomb_opts},
370 {"PictureDetelecine", &detel_opts},
371 {"PictureDenoise", &denoise_opts},
372 {"VideoEncoder", &vcodec_opts},
373 {"AudioEncoder", &acodec_opts},
374 {"x264_direct", &direct_opts},
375 {"x264_b_adapt", &badapt_opts},
376 {"x264_me", &me_opts},
377 {"x264_subme", &subme_opts},
378 {"x264_analyse", &analyse_opts},
379 {"x264_trellis", &trellis_opts},
380 {"SubtitleTrack", &subtitle_opts},
381 {"title", &title_opts},
382 {"AudioTrack", &audio_track_opts},
386 const gchar *srt_codeset_table[] =
421 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
424 typedef struct iso639_lang_t
426 char * eng_name; /* Description in English */
427 char * native_name; /* Description in native language */
428 char * iso639_1; /* ISO-639-1 (2 characters) code */
429 char * iso639_2; /* ISO-639-2/t (3 character) code */
430 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
434 const iso639_lang_t ghb_language_table[] =
436 { "Any", "", "zz", "und" },
437 { "Afar", "", "aa", "aar" },
438 { "Abkhazian", "", "ab", "abk" },
439 { "Afrikaans", "", "af", "afr" },
440 { "Akan", "", "ak", "aka" },
441 { "Albanian", "", "sq", "sqi", "alb" },
442 { "Amharic", "", "am", "amh" },
443 { "Arabic", "", "ar", "ara" },
444 { "Aragonese", "", "an", "arg" },
445 { "Armenian", "", "hy", "hye", "arm" },
446 { "Assamese", "", "as", "asm" },
447 { "Avaric", "", "av", "ava" },
448 { "Avestan", "", "ae", "ave" },
449 { "Aymara", "", "ay", "aym" },
450 { "Azerbaijani", "", "az", "aze" },
451 { "Bashkir", "", "ba", "bak" },
452 { "Bambara", "", "bm", "bam" },
453 { "Basque", "", "eu", "eus", "baq" },
454 { "Belarusian", "", "be", "bel" },
455 { "Bengali", "", "bn", "ben" },
456 { "Bihari", "", "bh", "bih" },
457 { "Bislama", "", "bi", "bis" },
458 { "Bosnian", "", "bs", "bos" },
459 { "Breton", "", "br", "bre" },
460 { "Bulgarian", "", "bg", "bul" },
461 { "Burmese", "", "my", "mya", "bur" },
462 { "Catalan", "", "ca", "cat" },
463 { "Chamorro", "", "ch", "cha" },
464 { "Chechen", "", "ce", "che" },
465 { "Chinese", "", "zh", "zho", "chi" },
466 { "Church Slavic", "", "cu", "chu" },
467 { "Chuvash", "", "cv", "chv" },
468 { "Cornish", "", "kw", "cor" },
469 { "Corsican", "", "co", "cos" },
470 { "Cree", "", "cr", "cre" },
471 { "Czech", "", "cs", "ces", "cze" },
472 { "Danish", "Dansk", "da", "dan" },
473 { "Divehi", "", "dv", "div" },
474 { "Dutch", "Nederlands", "nl", "nld", "dut" },
475 { "Dzongkha", "", "dz", "dzo" },
476 { "English", "English", "en", "eng" },
477 { "Esperanto", "", "eo", "epo" },
478 { "Estonian", "", "et", "est" },
479 { "Ewe", "", "ee", "ewe" },
480 { "Faroese", "", "fo", "fao" },
481 { "Fijian", "", "fj", "fij" },
482 { "Finnish", "Suomi", "fi", "fin" },
483 { "French", "Francais", "fr", "fra", "fre" },
484 { "Western Frisian", "", "fy", "fry" },
485 { "Fulah", "", "ff", "ful" },
486 { "Georgian", "", "ka", "kat", "geo" },
487 { "German", "Deutsch", "de", "deu", "ger" },
488 { "Gaelic (Scots)", "", "gd", "gla" },
489 { "Irish", "", "ga", "gle" },
490 { "Galician", "", "gl", "glg" },
491 { "Manx", "", "gv", "glv" },
492 { "Greek, Modern", "", "el", "ell", "gre" },
493 { "Guarani", "", "gn", "grn" },
494 { "Gujarati", "", "gu", "guj" },
495 { "Haitian", "", "ht", "hat" },
496 { "Hausa", "", "ha", "hau" },
497 { "Hebrew", "", "he", "heb" },
498 { "Herero", "", "hz", "her" },
499 { "Hindi", "", "hi", "hin" },
500 { "Hiri Motu", "", "ho", "hmo" },
501 { "Hungarian", "Magyar", "hu", "hun" },
502 { "Igbo", "", "ig", "ibo" },
503 { "Icelandic", "Islenska", "is", "isl", "ice" },
504 { "Ido", "", "io", "ido" },
505 { "Sichuan Yi", "", "ii", "iii" },
506 { "Inuktitut", "", "iu", "iku" },
507 { "Interlingue", "", "ie", "ile" },
508 { "Interlingua", "", "ia", "ina" },
509 { "Indonesian", "", "id", "ind" },
510 { "Inupiaq", "", "ik", "ipk" },
511 { "Italian", "Italiano", "it", "ita" },
512 { "Javanese", "", "jv", "jav" },
513 { "Japanese", "", "ja", "jpn" },
514 { "Kalaallisut", "", "kl", "kal" },
515 { "Kannada", "", "kn", "kan" },
516 { "Kashmiri", "", "ks", "kas" },
517 { "Kanuri", "", "kr", "kau" },
518 { "Kazakh", "", "kk", "kaz" },
519 { "Central Khmer", "", "km", "khm" },
520 { "Kikuyu", "", "ki", "kik" },
521 { "Kinyarwanda", "", "rw", "kin" },
522 { "Kirghiz", "", "ky", "kir" },
523 { "Komi", "", "kv", "kom" },
524 { "Kongo", "", "kg", "kon" },
525 { "Korean", "", "ko", "kor" },
526 { "Kuanyama", "", "kj", "kua" },
527 { "Kurdish", "", "ku", "kur" },
528 { "Lao", "", "lo", "lao" },
529 { "Latin", "", "la", "lat" },
530 { "Latvian", "", "lv", "lav" },
531 { "Limburgan", "", "li", "lim" },
532 { "Lingala", "", "ln", "lin" },
533 { "Lithuanian", "", "lt", "lit" },
534 { "Luxembourgish", "", "lb", "ltz" },
535 { "Luba-Katanga", "", "lu", "lub" },
536 { "Ganda", "", "lg", "lug" },
537 { "Macedonian", "", "mk", "mkd", "mac" },
538 { "Marshallese", "", "mh", "mah" },
539 { "Malayalam", "", "ml", "mal" },
540 { "Maori", "", "mi", "mri", "mao" },
541 { "Marathi", "", "mr", "mar" },
542 { "Malay", "", "ms", "msa", "msa" },
543 { "Malagasy", "", "mg", "mlg" },
544 { "Maltese", "", "mt", "mlt" },
545 { "Moldavian", "", "mo", "mol" },
546 { "Mongolian", "", "mn", "mon" },
547 { "Nauru", "", "na", "nau" },
548 { "Navajo", "", "nv", "nav" },
549 { "Ndebele, South", "", "nr", "nbl" },
550 { "Ndebele, North", "", "nd", "nde" },
551 { "Ndonga", "", "ng", "ndo" },
552 { "Nepali", "", "ne", "nep" },
553 { "Norwegian Nynorsk", "", "nn", "nno" },
554 { "Norwegian Bokmål", "", "nb", "nob" },
555 { "Norwegian", "Norsk", "no", "nor" },
556 { "Chichewa; Nyanja", "", "ny", "nya" },
557 { "Occitan", "", "oc", "oci" },
558 { "Ojibwa", "", "oj", "oji" },
559 { "Oriya", "", "or", "ori" },
560 { "Oromo", "", "om", "orm" },
561 { "Ossetian", "", "os", "oss" },
562 { "Panjabi", "", "pa", "pan" },
563 { "Persian", "", "fa", "fas", "per" },
564 { "Pali", "", "pi", "pli" },
565 { "Polish", "", "pl", "pol" },
566 { "Portuguese", "Portugues", "pt", "por" },
567 { "Pushto", "", "ps", "pus" },
568 { "Quechua", "", "qu", "que" },
569 { "Romansh", "", "rm", "roh" },
570 { "Romanian", "", "ro", "ron", "rum" },
571 { "Rundi", "", "rn", "run" },
572 { "Russian", "", "ru", "rus" },
573 { "Sango", "", "sg", "sag" },
574 { "Sanskrit", "", "sa", "san" },
575 { "Serbian", "", "sr", "srp", "scc" },
576 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
577 { "Sinhala", "", "si", "sin" },
578 { "Slovak", "", "sk", "slk", "slo" },
579 { "Slovenian", "", "sl", "slv" },
580 { "Northern Sami", "", "se", "sme" },
581 { "Samoan", "", "sm", "smo" },
582 { "Shona", "", "sn", "sna" },
583 { "Sindhi", "", "sd", "snd" },
584 { "Somali", "", "so", "som" },
585 { "Sotho, Southern", "", "st", "sot" },
586 { "Spanish", "Espanol", "es", "spa" },
587 { "Sardinian", "", "sc", "srd" },
588 { "Swati", "", "ss", "ssw" },
589 { "Sundanese", "", "su", "sun" },
590 { "Swahili", "", "sw", "swa" },
591 { "Swedish", "Svenska", "sv", "swe" },
592 { "Tahitian", "", "ty", "tah" },
593 { "Tamil", "", "ta", "tam" },
594 { "Tatar", "", "tt", "tat" },
595 { "Telugu", "", "te", "tel" },
596 { "Tajik", "", "tg", "tgk" },
597 { "Tagalog", "", "tl", "tgl" },
598 { "Thai", "", "th", "tha" },
599 { "Tibetan", "", "bo", "bod", "tib" },
600 { "Tigrinya", "", "ti", "tir" },
601 { "Tonga", "", "to", "ton" },
602 { "Tswana", "", "tn", "tsn" },
603 { "Tsonga", "", "ts", "tso" },
604 { "Turkmen", "", "tk", "tuk" },
605 { "Turkish", "", "tr", "tur" },
606 { "Twi", "", "tw", "twi" },
607 { "Uighur", "", "ug", "uig" },
608 { "Ukrainian", "", "uk", "ukr" },
609 { "Urdu", "", "ur", "urd" },
610 { "Uzbek", "", "uz", "uzb" },
611 { "Venda", "", "ve", "ven" },
612 { "Vietnamese", "", "vi", "vie" },
613 { "Volapük", "", "vo", "vol" },
614 { "Welsh", "", "cy", "cym", "wel" },
615 { "Walloon", "", "wa", "wln" },
616 { "Wolof", "", "wo", "wol" },
617 { "Xhosa", "", "xh", "xho" },
618 { "Yiddish", "", "yi", "yid" },
619 { "Yoruba", "", "yo", "yor" },
620 { "Zhuang", "", "za", "zha" },
621 { "Zulu", "", "zu", "zul" },
622 {NULL, NULL, NULL, NULL}
624 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
626 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
629 del_tree(const gchar *name, gboolean del_top)
633 if (g_file_test(name, G_FILE_TEST_IS_DIR))
635 GDir *gdir = g_dir_open(name, 0, NULL);
636 file = g_dir_read_name(gdir);
640 path = g_strdup_printf("%s/%s", name, file);
641 del_tree(path, TRUE);
643 file = g_dir_read_name(gdir);
658 return hb_get_version(NULL);
663 signal_user_data_t *ud,
671 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
680 *step = ghb_settings_combo_double(ud->settings,
681 "VideoQualityGranularity");
682 if (*step == 0.2 || *step == 0.5)
684 else if (*step == 0.25)
689 case HB_VCODEC_FFMPEG:
697 case HB_VCODEC_THEORA:
716 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
720 const gchar *result = "";
722 str = ghb_value_string(gval);
723 for (ii = 0; ii < opts->count; ii++)
725 if (strcmp(opts->map[ii].shortOpt, str) == 0)
727 result = opts->map[ii].svalue;
736 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
742 str = ghb_value_string(gval);
743 for (ii = 0; ii < opts->count; ii++)
745 if (strcmp(opts->map[ii].shortOpt, str) == 0)
747 result = opts->map[ii].ivalue;
756 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
762 str = ghb_value_string(gval);
763 for (ii = 0; ii < opts->count; ii++)
765 if (strcmp(opts->map[ii].shortOpt, str) == 0)
767 result = opts->map[ii].ivalue;
776 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
780 const gchar *result = "";
782 str = ghb_value_string(gval);
783 for (ii = 0; ii < opts->count; ii++)
785 if (strcmp(opts->map[ii].shortOpt, str) == 0)
787 result = opts->map[ii].option;
796 lookup_mix_int(const GValue *mix)
803 str = ghb_value_string(mix);
804 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
806 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
808 result = hb_audio_mixdowns[ii].amixdown;
817 lookup_mix_option(const GValue *mix)
821 gchar *result = "None";
824 str = ghb_value_string(mix);
825 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
827 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
829 result = hb_audio_mixdowns[ii].human_readable_name;
838 lookup_video_rate_int(const GValue *vrate)
844 str = ghb_value_string(vrate);
845 for (ii = 0; ii < hb_video_rates_count; ii++)
847 if (strcmp(hb_video_rates[ii].string, str) == 0)
849 result = hb_video_rates[ii].rate;
854 // Default to "same as source"
859 lookup_video_rate_option(const GValue *vrate)
863 const gchar *result = "Same as source";
865 str = ghb_value_string(vrate);
866 for (ii = 0; ii < hb_video_rates_count; ii++)
868 if (strcmp(hb_video_rates[ii].string, str) == 0)
870 result = hb_video_rates[ii].string;
875 // Default to "same as source"
880 lookup_audio_rate_int(const GValue *rate)
886 // Coincidentally, the string "source" will return 0
887 // which is our flag to use "same as source"
888 str = ghb_value_string(rate);
889 for (ii = 0; ii < hb_audio_rates_count; ii++)
891 if (strcmp(hb_audio_rates[ii].string, str) == 0)
893 result = hb_audio_rates[ii].rate;
902 lookup_audio_rate_option(const GValue *rate)
906 const gchar *result = "Same as source";
908 // Coincidentally, the string "source" will return 0
909 // which is our flag to use "same as source"
910 str = ghb_value_string(rate);
911 for (ii = 0; ii < hb_audio_rates_count; ii++)
913 if (strcmp(hb_audio_rates[ii].string, str) == 0)
915 result = hb_audio_rates[ii].string;
924 lookup_audio_bitrate_int(const GValue *rate)
930 // Coincidentally, the string "source" will return 0
931 // which is our flag to use "same as source"
932 str = ghb_value_string(rate);
933 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
935 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
937 result = hb_audio_bitrates[ii].rate;
946 lookup_audio_bitrate_option(const GValue *rate)
950 const gchar *result = "Same as source";
952 // Coincidentally, the string "source" will return 0
953 // which is our flag to use "same as source"
954 str = ghb_value_string(rate);
955 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
957 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
959 result = hb_audio_bitrates[ii].string;
968 lookup_audio_lang_int(const GValue *rate)
974 // Coincidentally, the string "source" will return 0
975 // which is our flag to use "same as source"
976 str = ghb_value_string(rate);
977 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
979 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
990 lookup_audio_lang_option(const GValue *rate)
994 const gchar *result = "Same as source";
996 // Coincidentally, the string "source" will return 0
997 // which is our flag to use "same as source"
998 str = ghb_value_string(rate);
999 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1001 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1003 result = ghb_language_table[ii].eng_name;
1012 get_acodec_value(gint val)
1014 GValue *value = NULL;
1017 for (ii = 0; ii < acodec_opts.count; ii++)
1019 if ((int)acodec_opts.map[ii].ivalue == val)
1021 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1029 get_amix_value(gint val)
1031 GValue *value = NULL;
1034 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1036 if (hb_audio_mixdowns[ii].amixdown == val)
1038 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1045 // Handle for libhb. Gets set by ghb_backend_init()
1046 static hb_handle_t * h_scan = NULL;
1047 static hb_handle_t * h_queue = NULL;
1049 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
1056 hb_get_tempory_directory(h_scan, dir);
1057 return g_strdup(dir);
1061 ghb_hb_cleanup(gboolean partial)
1065 hb_get_tempory_directory(h_scan, dir);
1066 del_tree(dir, !partial);
1070 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1078 titleindex = ghb_settings_combo_int(ud->settings, "title");
1084 hb_subtitle_t * sub;
1086 if (h_scan == NULL) return VOBSUB;
1087 list = hb_get_titles( h_scan );
1088 if( !hb_list_count( list ) )
1090 /* No valid title, stop right there */
1093 title = hb_list_item( list, titleindex );
1094 if (title == NULL) return VOBSUB; // Bad titleindex
1095 sub = hb_list_item( title->list_subtitle, track);
1103 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1106 const gchar * name = "Unknown";
1119 titleindex = ghb_settings_combo_int(ud->settings, "title");
1125 hb_subtitle_t * sub;
1129 list = hb_get_titles( h_scan );
1130 if( !hb_list_count( list ) )
1133 title = hb_list_item( list, titleindex );
1137 sub = hb_list_item( title->list_subtitle, track);
1140 switch (sub->source)
1163 ghb_get_title_number(gint titleindex)
1168 if (h_scan == NULL) return 1;
1169 list = hb_get_titles( h_scan );
1170 if( !hb_list_count( list ) )
1172 /* No valid title, stop right there */
1175 title = hb_list_item( list, titleindex );
1176 if (title == NULL) return 1; // Bad titleindex
1177 return title->index;
1180 static hb_audio_config_t*
1181 get_hb_audio(gint titleindex, gint track)
1185 hb_audio_config_t *audio = NULL;
1187 if (h_scan == NULL) return NULL;
1188 list = hb_get_titles( h_scan );
1189 if( !hb_list_count( list ) )
1191 /* No valid title, stop right there */
1194 title = hb_list_item( list, titleindex );
1195 if (title == NULL) return NULL; // Bad titleindex
1196 if (!hb_list_count(title->list_audio))
1200 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1205 search_rates(hb_rate_t *rates, gint rate, gint count)
1208 for (ii = 0; ii < count; ii++)
1210 if (rates[ii].rate == rate)
1216 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1218 static GtkListStore*
1219 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1222 GtkListStore *store;
1224 g_debug("get_combo_box_store() %s\n", name);
1225 // First modify the combobox model to allow greying out of options
1226 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1227 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1232 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1234 GtkListStore *store;
1237 store = get_combo_box_store(builder, name);
1238 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1240 gtk_list_store_set(store, &iter,
1247 ghb_grey_combo_options(GtkBuilder *builder)
1250 gint container, track, titleindex, acodec;
1251 hb_audio_config_t *audio = NULL;
1254 widget = GHB_WIDGET (builder, "title");
1255 gval = ghb_widget_value(widget);
1256 titleindex = ghb_lookup_combo_int("title", gval);
1257 ghb_value_free(gval);
1258 widget = GHB_WIDGET (builder, "AudioTrack");
1259 gval = ghb_widget_value(widget);
1260 track = ghb_lookup_combo_int("AudioTrack", gval);
1261 ghb_value_free(gval);
1262 audio = get_hb_audio(titleindex, track);
1263 widget = GHB_WIDGET (builder, "FileFormat");
1264 gval = ghb_widget_value(widget);
1265 container = ghb_lookup_combo_int("FileFormat", gval);
1266 ghb_value_free(gval);
1268 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1269 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1270 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1271 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1273 gboolean allow_dca = TRUE;
1274 allow_dca = (container != HB_MUX_MP4);
1276 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1278 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1280 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1282 if (audio && audio->in.codec != HB_ACODEC_AC3)
1284 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1286 if (audio && audio->in.codec != HB_ACODEC_DCA)
1288 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1290 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1292 widget = GHB_WIDGET (builder, "AudioEncoder");
1293 gval = ghb_widget_value(widget);
1294 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1295 ghb_value_free(gval);
1296 if (acodec != HB_ACODEC_AC3)
1298 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1300 if (container == HB_MUX_MP4)
1302 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1303 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1304 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1306 else if (container == HB_MUX_AVI)
1308 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1309 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1310 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1312 else if (container == HB_MUX_OGM)
1314 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1317 gboolean allow_mono = TRUE;
1318 gboolean allow_stereo = TRUE;
1319 gboolean allow_dolby = TRUE;
1320 gboolean allow_dpl2 = TRUE;
1321 gboolean allow_6ch = TRUE;
1325 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1326 (acodec != HB_ACODEC_LAME);
1327 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1329 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1331 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1332 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1333 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1334 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1336 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1337 (acodec != HB_ACODEC_LAME) &&
1338 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1339 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1341 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1342 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1343 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1344 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1345 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1349 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1351 hb_audio_config_t *audio = NULL;
1352 gboolean allow_mono = TRUE;
1353 gboolean allow_stereo = TRUE;
1354 gboolean allow_dolby = TRUE;
1355 gboolean allow_dpl2 = TRUE;
1356 gboolean allow_6ch = TRUE;
1358 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1360 // Audio codec pass-thru. No mixdown
1363 audio = get_hb_audio(titleindex, track);
1367 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1368 (acodec != HB_ACODEC_LAME);
1369 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1371 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1373 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1374 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1375 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1376 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1378 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1379 (acodec != HB_ACODEC_LAME) &&
1380 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1381 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1383 gboolean greater = FALSE;
1386 // If no mix is specified, select the best available.
1387 mix = HB_AMIXDOWN_6CH;
1389 if (mix == HB_AMIXDOWN_6CH)
1392 if (allow_6ch) return HB_AMIXDOWN_6CH;
1394 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1397 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1399 if (mix == HB_AMIXDOWN_DOLBY || greater)
1402 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1404 if (mix == HB_AMIXDOWN_STEREO || greater)
1407 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1409 if (mix == HB_AMIXDOWN_MONO || greater)
1412 if (allow_mono) return HB_AMIXDOWN_MONO;
1414 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1415 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1416 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1417 if (allow_6ch) return HB_AMIXDOWN_6CH;
1421 // Set up the model for the combo box
1423 init_combo_box(GtkBuilder *builder, const gchar *name)
1426 GtkListStore *store;
1427 GtkCellRenderer *cell;
1429 g_debug("init_combo_box() %s\n", name);
1430 // First modify the combobox model to allow greying out of options
1431 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1435 // 1 - String to display
1436 // 2 - bool indicating whether the entry is selectable (grey or not)
1437 // 3 - String that is used for presets
1438 // 4 - Int value determined by backend
1439 // 5 - String value determined by backend
1440 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1441 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1442 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1444 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1446 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1447 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1448 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1449 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1450 "text", 0, "sensitive", 1, NULL);
1453 { // Combo box entry
1454 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1459 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1462 GtkListStore *store;
1465 g_debug("audio_samplerate_opts_set ()\n");
1466 store = get_combo_box_store(builder, name);
1467 gtk_list_store_clear(store);
1468 // Add an item for "Same As Source"
1469 gtk_list_store_append(store, &iter);
1470 gtk_list_store_set(store, &iter,
1471 0, "Same as source",
1477 for (ii = 0; ii < count; ii++)
1479 gtk_list_store_append(store, &iter);
1480 gtk_list_store_set(store, &iter,
1481 0, rates[ii].string,
1483 2, rates[ii].string,
1484 3, (gdouble)rates[ii].rate,
1485 4, rates[ii].string,
1491 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1494 GtkListStore *store;
1497 g_debug("video_rate_opts_set ()\n");
1498 store = get_combo_box_store(builder, name);
1499 gtk_list_store_clear(store);
1500 // Add an item for "Same As Source"
1501 gtk_list_store_append(store, &iter);
1502 gtk_list_store_set(store, &iter,
1503 0, "Same as source",
1509 for (ii = 0; ii < count; ii++)
1513 if (strcmp(rates[ii].string, "23.976") == 0)
1515 desc = "(NTSC Film)";
1517 else if (strcmp(rates[ii].string, "25") == 0)
1519 desc = "(PAL Film/Video)";
1521 else if (strcmp(rates[ii].string, "29.97") == 0)
1523 desc = "(NTSC Video)";
1525 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1526 gtk_list_store_append(store, &iter);
1527 gtk_list_store_set(store, &iter,
1530 2, rates[ii].string,
1531 3, (gdouble)rates[ii].rate,
1532 4, rates[ii].string,
1539 mix_opts_set(GtkBuilder *builder, const gchar *name)
1542 GtkListStore *store;
1545 g_debug("mix_opts_set ()\n");
1546 store = get_combo_box_store(builder, name);
1547 gtk_list_store_clear(store);
1548 gtk_list_store_append(store, &iter);
1549 gtk_list_store_set(store, &iter,
1556 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1558 gtk_list_store_append(store, &iter);
1559 gtk_list_store_set(store, &iter,
1560 0, hb_audio_mixdowns[ii].human_readable_name,
1562 2, hb_audio_mixdowns[ii].short_name,
1563 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1564 4, hb_audio_mixdowns[ii].internal_name,
1570 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1573 GtkListStore *store;
1576 g_debug("srt_codeset_opts_set ()\n");
1577 store = get_combo_box_store(builder, name);
1578 gtk_list_store_clear(store);
1579 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1581 gtk_list_store_append(store, &iter);
1582 gtk_list_store_set(store, &iter,
1583 0, srt_codeset_table[ii],
1585 2, srt_codeset_table[ii],
1587 4, srt_codeset_table[ii],
1590 GtkComboBoxEntry *cbe;
1592 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1593 //gtk_combo_box_entry_set_text_column(cbe, 0);
1597 language_opts_set(GtkBuilder *builder, const gchar *name)
1600 GtkListStore *store;
1603 g_debug("language_opts_set ()\n");
1604 store = get_combo_box_store(builder, name);
1605 gtk_list_store_clear(store);
1606 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1608 gtk_list_store_append(store, &iter);
1609 gtk_list_store_set(store, &iter,
1610 0, ghb_language_table[ii].eng_name,
1612 2, ghb_language_table[ii].iso639_2,
1614 4, ghb_language_table[ii].iso639_1,
1619 static gchar **titles = NULL;
1622 title_opts_set(GtkBuilder *builder, const gchar *name)
1625 GtkListStore *store;
1626 hb_list_t * list = NULL;
1627 hb_title_t * title = NULL;
1631 g_debug("title_opts_set ()\n");
1632 store = get_combo_box_store(builder, name);
1633 gtk_list_store_clear(store);
1636 list = hb_get_titles( h_scan );
1637 count = hb_list_count( list );
1638 if (count > 100) count = 100;
1640 if (titles) g_strfreev(titles);
1641 if (title_opts.map) g_free(title_opts.map);
1644 title_opts.count = count;
1645 title_opts.map = g_malloc(count*sizeof(options_map_t));
1646 titles = g_malloc((count+1) * sizeof(gchar*));
1650 title_opts.count = 1;
1651 title_opts.map = g_malloc(sizeof(options_map_t));
1656 // No titles. Fill in a default.
1657 gtk_list_store_append(store, &iter);
1658 gtk_list_store_set(store, &iter,
1665 title_opts.map[0].option = "No Titles";
1666 title_opts.map[0].shortOpt = "none";
1667 title_opts.map[0].ivalue = -1;
1668 title_opts.map[0].svalue = "none";
1671 for (ii = 0; ii < count; ii++)
1673 title = (hb_title_t*)hb_list_item(list, ii);
1674 if (title->duration != 0)
1676 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1677 title->index, title->hours, title->minutes, title->seconds);
1681 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1683 gtk_list_store_append(store, &iter);
1684 gtk_list_store_set(store, &iter,
1691 title_opts.map[ii].option = titles[ii];
1692 title_opts.map[ii].shortOpt = titles[ii];
1693 title_opts.map[ii].ivalue = ii;
1694 title_opts.map[ii].svalue = titles[ii];
1700 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1703 gboolean foundit = FALSE;
1705 if (gtk_tree_model_get_iter_first (store, iter))
1709 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1710 if (value == (int)ivalue)
1715 } while (gtk_tree_model_iter_next (store, iter));
1721 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1724 GtkListStore *store;
1725 hb_list_t * list = NULL;
1726 hb_title_t * title = NULL;
1727 hb_audio_config_t * audio;
1731 g_debug("audio_track_opts_set ()\n");
1732 store = get_combo_box_store(builder, name);
1733 gtk_list_store_clear(store);
1736 list = hb_get_titles( h_scan );
1737 title = (hb_title_t*)hb_list_item( list, titleindex );
1740 count = hb_list_count( title->list_audio );
1743 if (count > 100) count = 100;
1744 if (audio_track_opts.map) g_free(audio_track_opts.map);
1747 audio_track_opts.count = count;
1748 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1752 audio_track_opts.count = 1;
1753 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1757 // No audio. set some default
1758 gtk_list_store_append(store, &iter);
1759 gtk_list_store_set(store, &iter,
1766 audio_track_opts.map[0].option = "No Audio";
1767 audio_track_opts.map[0].shortOpt = "none";
1768 audio_track_opts.map[0].ivalue = -1;
1769 audio_track_opts.map[0].svalue = "none";
1772 index_str_init(count-1);
1773 for (ii = 0; ii < count; ii++)
1775 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1776 gtk_list_store_append(store, &iter);
1777 gtk_list_store_set(store, &iter,
1778 0, audio->lang.description,
1784 audio_track_opts.map[ii].option = audio->lang.description,
1785 audio_track_opts.map[ii].shortOpt = index_str[ii];
1786 audio_track_opts.map[ii].ivalue = ii;
1787 audio_track_opts.map[ii].svalue = index_str[ii];
1792 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1795 GtkListStore *store;
1796 hb_list_t * list = NULL;
1797 hb_title_t * title = NULL;
1798 hb_subtitle_t * subtitle;
1800 static char ** options = NULL;
1802 g_debug("subtitle_track_opts_set ()\n");
1803 store = get_combo_box_store(builder, name);
1804 gtk_list_store_clear(store);
1807 list = hb_get_titles( h_scan );
1808 title = (hb_title_t*)hb_list_item( list, titleindex );
1811 count = hb_list_count( title->list_subtitle );
1814 if (count > 100) count = 100;
1815 if (subtitle_opts.map) g_free(subtitle_opts.map);
1818 subtitle_opts.count = count+1;
1819 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1823 subtitle_opts.count = LANG_TABLE_SIZE+1;
1824 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1826 gtk_list_store_append(store, &iter);
1827 gtk_list_store_set(store, &iter,
1828 0, "Foreign Audio Search",
1834 subtitle_opts.map[0].option = "Foreign Audio Search";
1835 subtitle_opts.map[0].shortOpt = "-1";
1836 subtitle_opts.map[0].ivalue = -1;
1837 subtitle_opts.map[0].svalue = "auto";
1840 if (options != NULL)
1841 g_strfreev(options);
1842 options = g_malloc((count+1)*sizeof(gchar*));
1843 index_str_init(count-1);
1844 for (ii = 0; ii < count; ii++)
1846 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1847 // Skip subtitles that must be burned if there is already
1848 // a burned subtitle in the list
1849 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1850 subtitle_opts.map[ii+1].option = options[ii];
1851 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1852 subtitle_opts.map[ii+1].ivalue = ii;
1853 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1854 gtk_list_store_append(store, &iter);
1855 gtk_list_store_set(store, &iter,
1860 4, subtitle->iso639_2,
1863 options[count] = NULL;
1867 index_str_init(LANG_TABLE_SIZE-1);
1868 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1870 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1871 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1872 subtitle_opts.map[ii+1].ivalue = ii;
1873 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1874 gtk_list_store_append(store, &iter);
1875 gtk_list_store_set(store, &iter,
1876 0, ghb_language_table[ii].eng_name,
1880 4, ghb_language_table[ii].iso639_2,
1893 guint64 longest = 0;
1894 gint titleindex = 0;
1896 g_debug("ghb_longest_title ()\n");
1897 if (h_scan == NULL) return 0;
1898 list = hb_get_titles( h_scan );
1899 count = hb_list_count( list );
1900 if (count > 100) count = 100;
1901 for (ii = 0; ii < count; ii++)
1903 title = (hb_title_t*)hb_list_item(list, ii);
1904 if (title->duration > longest)
1907 longest = title->duration;
1914 ghb_get_source_audio_lang(gint titleindex, gint track)
1918 hb_audio_config_t * audio;
1921 g_debug("ghb_lookup_1st_audio_lang ()\n");
1924 list = hb_get_titles( h_scan );
1925 title = (hb_title_t*)hb_list_item( list, titleindex );
1928 if (hb_list_count( title->list_audio ) <= track)
1931 audio = hb_list_audio_config_item(title->list_audio, track);
1935 lang = g_strdup(audio->lang.iso639_2);
1940 ghb_find_audio_track(
1944 GHashTable *track_indices)
1948 hb_audio_config_t * audio;
1955 g_debug("find_audio_track ()\n");
1956 if (h_scan == NULL) return -1;
1957 list = hb_get_titles( h_scan );
1958 title = (hb_title_t*)hb_list_item( list, titleindex );
1961 count = hb_list_count( title->list_audio );
1963 if (count > 10) count = 10;
1964 used = g_hash_table_lookup(track_indices, &acodec);
1967 used = g_malloc0(count * sizeof(gboolean));
1968 g_hash_table_insert(track_indices, &acodec, used);
1970 // Try to find an item that matches the preferred language and
1971 // the passthru codec type
1972 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1974 for (ii = 0; ii < count; ii++)
1981 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1982 title->list_audio, ii );
1983 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1984 audio->in.channel_layout);
1985 // Find a track that is not visually impaired or dirctor's
1986 // commentary, and has the highest channel count.
1987 if ((audio->in.codec & acodec) &&
1988 (audio->lang.type < 2) &&
1989 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1990 (strcmp(lang, "und") == 0)))
1992 if (channels > max_chan)
1995 max_chan = channels;
2005 // Try to find an item that matches the preferred language
2006 for (ii = 0; ii < count; ii++)
2010 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2011 title->list_audio, ii );
2012 // Find a track that is not visually impaired or dirctor's commentary
2013 if ((audio->lang.type < 2) &&
2014 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2015 (strcmp(lang, "und") == 0)))
2026 // Try to fine an item that does not match the preferred language and
2027 // matches the passthru codec type
2028 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2030 for (ii = 0; ii < count; ii++)
2037 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2038 title->list_audio, ii );
2039 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2040 audio->in.channel_layout);
2041 // Find a track that is not visually impaired or dirctor's
2042 // commentary, and has the highest channel count.
2043 if ((audio->in.codec & acodec) &&
2044 (audio->lang.type < 2))
2046 if (channels > max_chan)
2049 max_chan = channels;
2059 // Try to fine an item that does not match the preferred language
2060 for (ii = 0; ii < count; ii++)
2064 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2065 title->list_audio, ii );
2066 // Find a track that is not visually impaired or dirctor's commentary
2067 if (audio->lang.type < 2)
2078 // Last ditch, anything goes
2079 for (ii = 0; ii < count; ii++)
2081 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2082 title->list_audio, ii );
2097 ghb_find_pref_subtitle_track(const gchar *lang)
2100 count = subtitle_opts.count;
2101 for (ii = 0; ii < count; ii++)
2103 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2105 return subtitle_opts.map[ii].ivalue;
2112 ghb_find_subtitle_track(
2115 GHashTable *track_indices)
2119 hb_subtitle_t * subtitle;
2123 g_debug("find_subtitle_track ()\n");
2124 if (strcmp(lang, "auto") == 0)
2126 if (h_scan == NULL) return -1;
2127 list = hb_get_titles( h_scan );
2128 title = (hb_title_t*)hb_list_item( list, titleindex );
2131 count = hb_list_count( title->list_subtitle );
2132 used = g_hash_table_lookup(track_indices, lang);
2135 used = g_malloc0(count * sizeof(gboolean));
2136 g_hash_table_insert(track_indices, g_strdup(lang), used);
2138 // Try to find an item that matches the preferred language
2139 for (ii = 0; ii < count; ii++)
2144 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2145 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2146 (strcmp(lang, "und") == 0))
2157 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2160 GtkListStore *store;
2163 g_debug("generic_opts_set ()\n");
2164 if (name == NULL || opts == NULL) return;
2165 store = get_combo_box_store(builder, name);
2166 gtk_list_store_clear(store);
2167 for (ii = 0; ii < opts->count; ii++)
2169 gtk_list_store_append(store, &iter);
2170 gtk_list_store_set(store, &iter,
2171 0, opts->map[ii].option,
2173 2, opts->map[ii].shortOpt,
2174 3, opts->map[ii].ivalue,
2175 4, opts->map[ii].svalue,
2181 find_combo_table(const gchar *name)
2185 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2187 if (strcmp(name, combo_name_map[ii].name) == 0)
2189 return combo_name_map[ii].opts;
2196 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2200 if (strcmp(name, "AudioBitrate") == 0)
2201 return lookup_audio_bitrate_int(gval);
2202 else if (strcmp(name, "AudioSamplerate") == 0)
2203 return lookup_audio_rate_int(gval);
2204 else if (strcmp(name, "VideoFramerate") == 0)
2205 return lookup_video_rate_int(gval);
2206 else if (strcmp(name, "AudioMixdown") == 0)
2207 return lookup_mix_int(gval);
2208 else if (strcmp(name, "SrtLanguage") == 0)
2209 return lookup_audio_lang_int(gval);
2210 else if (strcmp(name, "PreferredLanguage") == 0)
2211 return lookup_audio_lang_int(gval);
2214 return lookup_generic_int(find_combo_table(name), gval);
2216 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2221 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2225 if (strcmp(name, "AudioBitrate") == 0)
2226 return lookup_audio_bitrate_int(gval);
2227 else if (strcmp(name, "AudioSamplerate") == 0)
2228 return lookup_audio_rate_int(gval);
2229 else if (strcmp(name, "VideoFramerate") == 0)
2230 return lookup_video_rate_int(gval);
2231 else if (strcmp(name, "AudioMixdown") == 0)
2232 return lookup_mix_int(gval);
2233 else if (strcmp(name, "SrtLanguage") == 0)
2234 return lookup_audio_lang_int(gval);
2235 else if (strcmp(name, "PreferredLanguage") == 0)
2236 return lookup_audio_lang_int(gval);
2239 return lookup_generic_double(find_combo_table(name), gval);
2241 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2246 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2250 if (strcmp(name, "AudioBitrate") == 0)
2251 return lookup_audio_bitrate_option(gval);
2252 else if (strcmp(name, "AudioSamplerate") == 0)
2253 return lookup_audio_rate_option(gval);
2254 else if (strcmp(name, "VideoFramerate") == 0)
2255 return lookup_video_rate_option(gval);
2256 else if (strcmp(name, "AudioMixdown") == 0)
2257 return lookup_mix_option(gval);
2258 else if (strcmp(name, "SrtLanguage") == 0)
2259 return lookup_audio_lang_option(gval);
2260 else if (strcmp(name, "PreferredLanguage") == 0)
2261 return lookup_audio_lang_option(gval);
2264 return lookup_generic_option(find_combo_table(name), gval);
2266 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2271 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2275 if (strcmp(name, "AudioBitrate") == 0)
2276 return lookup_audio_bitrate_option(gval);
2277 else if (strcmp(name, "AudioSamplerate") == 0)
2278 return lookup_audio_rate_option(gval);
2279 else if (strcmp(name, "VideoFramerate") == 0)
2280 return lookup_video_rate_option(gval);
2281 else if (strcmp(name, "AudioMixdown") == 0)
2282 return lookup_mix_option(gval);
2283 else if (strcmp(name, "SrtLanguage") == 0)
2284 return lookup_audio_lang_option(gval);
2285 else if (strcmp(name, "PreferredLanguage") == 0)
2286 return lookup_audio_lang_option(gval);
2289 return lookup_generic_string(find_combo_table(name), gval);
2291 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2296 ghb_update_ui_combo_box(
2297 signal_user_data_t *ud,
2302 GtkComboBox *combo = NULL;
2304 gint handler_id = 0;
2308 g_debug("ghb_update_ui_combo_box() %s\n", name);
2309 // Clearing a combo box causes a rash of "changed" events, even when
2310 // the active item is -1 (inactive). To control things, I'm disabling
2311 // the event till things are settled down.
2312 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2313 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2316 // Valid signal id found. This should always succeed.
2317 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2318 signal_id, 0, 0, 0, 0);
2321 // This should also always succeed
2322 g_signal_handler_block ((gpointer)combo, handler_id);
2328 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2329 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2330 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2331 mix_opts_set(ud->builder, "AudioMixdown");
2332 language_opts_set(ud->builder, "SrtLanguage");
2333 language_opts_set(ud->builder, "PreferredLanguage");
2334 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2335 title_opts_set(ud->builder, "title");
2336 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2337 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2338 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2339 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2340 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2341 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2342 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2343 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2344 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2345 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2346 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2347 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2348 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2349 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2350 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2351 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2352 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2353 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2354 generic_opts_set(ud->builder, "x264_me", &me_opts);
2355 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2356 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2357 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2361 if (strcmp(name, "AudioBitrate") == 0)
2362 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2363 else if (strcmp(name, "AudioSamplerate") == 0)
2364 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2365 else if (strcmp(name, "VideoFramerate") == 0)
2366 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2367 else if (strcmp(name, "AudioMixdown") == 0)
2368 mix_opts_set(ud->builder, "AudioMixdown");
2369 else if (strcmp(name, "SrtLanguage") == 0)
2370 language_opts_set(ud->builder, "SrtLanguage");
2371 else if (strcmp(name, "PreferredLanguage") == 0)
2372 language_opts_set(ud->builder, "PreferredLanguage");
2373 else if (strcmp(name, "SrtCodeset") == 0)
2374 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2375 else if (strcmp(name, "title") == 0)
2376 title_opts_set(ud->builder, "title");
2377 else if (strcmp(name, "SubtitleTrack") == 0)
2378 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2379 else if (strcmp(name, "AudioTrack") == 0)
2380 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2382 generic_opts_set(ud->builder, name, find_combo_table(name));
2386 g_signal_handler_unblock ((gpointer)combo, handler_id);
2391 init_ui_combo_boxes(GtkBuilder *builder)
2395 init_combo_box(builder, "AudioBitrate");
2396 init_combo_box(builder, "AudioSamplerate");
2397 init_combo_box(builder, "VideoFramerate");
2398 init_combo_box(builder, "AudioMixdown");
2399 init_combo_box(builder, "SrtLanguage");
2400 init_combo_box(builder, "PreferredLanguage");
2401 init_combo_box(builder, "SrtCodeset");
2402 init_combo_box(builder, "title");
2403 init_combo_box(builder, "AudioTrack");
2404 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2406 init_combo_box(builder, combo_name_map[ii].name);
2410 static const char * turbo_opts =
2411 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2412 "no-fast-pskip=0:8x8dct=0";
2414 // Construct the x264 options string
2415 // The result is allocated, so someone must free it at some point.
2417 ghb_build_x264opts_string(GValue *settings)
2420 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2427 result = g_strdup("");
2433 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2437 hb_chapter_t * chapter;
2440 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2441 *hh = *mm = *ss = 0;
2442 if (h_scan == NULL) return;
2443 list = hb_get_titles( h_scan );
2444 title = (hb_title_t*)hb_list_item( list, ti );
2445 if (title == NULL) return;
2446 count = hb_list_count( title->list_chapter );
2447 if (ii >= count) return;
2448 chapter = hb_list_item(title->list_chapter, ii);
2449 if (chapter == NULL) return;
2450 *hh = chapter->hours;
2451 *mm = chapter->minutes;
2452 *ss = chapter->seconds;
2456 ghb_get_chapters(gint titleindex)
2460 hb_chapter_t * chapter;
2462 GValue *chapters = NULL;
2464 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2465 if (h_scan == NULL) return NULL;
2466 list = hb_get_titles( h_scan );
2467 title = (hb_title_t*)hb_list_item( list, titleindex );
2468 if (title == NULL) return NULL;
2469 count = hb_list_count( title->list_chapter );
2470 chapters = ghb_array_value_new(count);
2471 for (ii = 0; ii < count; ii++)
2473 chapter = hb_list_item(title->list_chapter, ii);
2474 if (chapter == NULL) break;
2475 if (chapter->title == NULL || chapter->title[0] == 0)
2478 str = g_strdup_printf ("Chapter %2d", ii+1);
2479 ghb_array_append(chapters, ghb_string_value_new(str));
2484 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2491 ghb_ac3_in_audio_list(const GValue *audio_list)
2495 count = ghb_array_len(audio_list);
2496 for (ii = 0; ii < count; ii++)
2501 asettings = ghb_array_get_nth(audio_list, ii);
2502 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2503 if (acodec & HB_ACODEC_AC3)
2510 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2513 GtkListStore *store;
2516 g_debug("audio_rate_opts_add ()\n");
2517 store = get_combo_box_store(builder, name);
2518 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2520 str = g_strdup_printf ("%d", rate);
2521 gtk_list_store_append(store, &iter);
2522 gtk_list_store_set(store, &iter,
2534 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2537 GtkListStore *store;
2539 gboolean done = FALSE;
2541 guint last = (guint)last_rate;
2543 g_debug("audio_bitrate_opts_clean ()\n");
2544 store = get_combo_box_store(builder, name);
2545 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2549 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2551 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2553 done = !gtk_list_store_remove(store, &iter);
2555 else if (ivalue > last)
2558 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2559 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2564 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2565 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2572 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2575 GtkListStore *store;
2578 g_debug("audio_bitrate_opts_set ()\n");
2579 store = get_combo_box_store(builder, name);
2580 gtk_list_store_clear(store);
2581 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2583 gtk_list_store_append(store, &iter);
2584 gtk_list_store_set(store, &iter,
2585 0, hb_audio_bitrates[ii].string,
2587 2, hb_audio_bitrates[ii].string,
2588 3, (gdouble)hb_audio_bitrates[ii].rate,
2589 4, hb_audio_bitrates[ii].string,
2595 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2597 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2601 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2603 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2606 static ghb_status_t hb_status;
2609 ghb_combo_init(signal_user_data_t *ud)
2611 // Set up the list model for the combos
2612 init_ui_combo_boxes(ud->builder);
2613 // Populate all the combos
2614 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2618 ghb_backend_init(gint debug)
2621 h_scan = hb_init( debug, 0 );
2622 h_queue = hb_init( debug, 0 );
2633 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2635 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2636 hb_status.scan.state |= GHB_STATE_SCANNING;
2637 // initialize count and cur to something that won't cause FPE
2638 // when computing progress
2639 hb_status.scan.title_count = 1;
2640 hb_status.scan.title_cur = 0;
2644 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2646 g_debug("ghb_backend_queue_scan()");
2647 hb_scan( h_queue, path, titlenum, 10, 0 );
2648 hb_status.queue.state |= GHB_STATE_SCANNING;
2652 ghb_get_scan_state()
2654 return hb_status.scan.state;
2658 ghb_get_queue_state()
2660 return hb_status.queue.state;
2664 ghb_clear_scan_state(gint state)
2666 hb_status.scan.state &= ~state;
2670 ghb_clear_queue_state(gint state)
2672 hb_status.queue.state &= ~state;
2676 ghb_set_scan_state(gint state)
2678 hb_status.scan.state |= state;
2682 ghb_set_queue_state(gint state)
2684 hb_status.queue.state |= state;
2688 ghb_get_status(ghb_status_t *status)
2690 memcpy(status, &hb_status, sizeof(ghb_status_t));
2699 if (h_scan == NULL) return;
2700 hb_get_state( h_scan, &s_scan );
2701 switch( s_scan.state )
2703 #define p s_scan.param.scanning
2704 case HB_STATE_SCANNING:
2706 hb_status.scan.state |= GHB_STATE_SCANNING;
2707 hb_status.scan.title_count = p.title_count;
2708 hb_status.scan.title_cur = p.title_cur;
2712 case HB_STATE_SCANDONE:
2714 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2715 hb_status.scan.state |= GHB_STATE_SCANDONE;
2718 #define p s_scan.param.working
2719 case HB_STATE_WORKING:
2720 hb_status.scan.state |= GHB_STATE_WORKING;
2721 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2722 hb_status.scan.job_cur = p.job_cur;
2723 hb_status.scan.job_count = p.job_count;
2724 hb_status.scan.progress = p.progress;
2725 hb_status.scan.rate_cur = p.rate_cur;
2726 hb_status.scan.rate_avg = p.rate_avg;
2727 hb_status.scan.hours = p.hours;
2728 hb_status.scan.minutes = p.minutes;
2729 hb_status.scan.seconds = p.seconds;
2730 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2734 case HB_STATE_PAUSED:
2735 hb_status.scan.state |= GHB_STATE_PAUSED;
2738 case HB_STATE_MUXING:
2740 hb_status.scan.state |= GHB_STATE_MUXING;
2743 #define p s_scan.param.workdone
2744 case HB_STATE_WORKDONE:
2748 hb_status.scan.state |= GHB_STATE_WORKDONE;
2749 hb_status.scan.state &= ~GHB_STATE_MUXING;
2750 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2751 hb_status.scan.state &= ~GHB_STATE_WORKING;
2755 hb_status.scan.error = GHB_ERROR_NONE;
2757 case HB_ERROR_CANCELED:
2758 hb_status.scan.error = GHB_ERROR_CANCELED;
2761 hb_status.scan.error = GHB_ERROR_FAIL;
2764 // Delete all remaining jobs of this encode.
2765 // An encode can be composed of multiple associated jobs.
2766 // When a job is stopped, libhb removes it from the job list,
2767 // but does not remove other jobs that may be associated with it.
2768 // Associated jobs are taged in the sequence id.
2769 while ((job = hb_job(h_scan, 0)) != NULL)
2770 hb_rem( h_scan, job );
2774 hb_get_state( h_queue, &s_queue );
2775 switch( s_queue.state )
2777 #define p s_queue.param.scanning
2778 case HB_STATE_SCANNING:
2780 hb_status.queue.state |= GHB_STATE_SCANNING;
2781 hb_status.queue.title_count = p.title_count;
2782 hb_status.queue.title_cur = p.title_cur;
2786 case HB_STATE_SCANDONE:
2788 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2789 hb_status.queue.state |= GHB_STATE_SCANDONE;
2792 #define p s_queue.param.working
2793 case HB_STATE_WORKING:
2794 hb_status.queue.state |= GHB_STATE_WORKING;
2795 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2796 hb_status.queue.job_cur = p.job_cur;
2797 hb_status.queue.job_count = p.job_count;
2798 hb_status.queue.progress = p.progress;
2799 hb_status.queue.rate_cur = p.rate_cur;
2800 hb_status.queue.rate_avg = p.rate_avg;
2801 hb_status.queue.hours = p.hours;
2802 hb_status.queue.minutes = p.minutes;
2803 hb_status.queue.seconds = p.seconds;
2804 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2808 case HB_STATE_PAUSED:
2809 hb_status.queue.state |= GHB_STATE_PAUSED;
2812 case HB_STATE_MUXING:
2814 hb_status.queue.state |= GHB_STATE_MUXING;
2817 #define p s_queue.param.workdone
2818 case HB_STATE_WORKDONE:
2822 hb_status.queue.state |= GHB_STATE_WORKDONE;
2823 hb_status.queue.state &= ~GHB_STATE_MUXING;
2824 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2825 hb_status.queue.state &= ~GHB_STATE_WORKING;
2829 hb_status.queue.error = GHB_ERROR_NONE;
2831 case HB_ERROR_CANCELED:
2832 hb_status.queue.error = GHB_ERROR_CANCELED;
2835 hb_status.queue.error = GHB_ERROR_FAIL;
2838 // Delete all remaining jobs of this encode.
2839 // An encode can be composed of multiple associated jobs.
2840 // When a job is stopped, libhb removes it from the job list,
2841 // but does not remove other jobs that may be associated with it.
2842 // Associated jobs are taged in the sequence id.
2843 while ((job = hb_job(h_queue, 0)) != NULL)
2844 hb_rem( h_queue, job );
2851 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2856 if (h_scan == NULL) return FALSE;
2857 list = hb_get_titles( h_scan );
2858 if( !hb_list_count( list ) )
2860 /* No valid title, stop right there */
2864 title = hb_list_item( list, titleindex );
2865 if (title == NULL) return FALSE; // Bad titleindex
2866 tinfo->width = title->width;
2867 tinfo->height = title->height;
2868 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2869 // Don't allow crop to 0
2870 if (title->crop[0] + title->crop[1] >= title->height)
2871 title->crop[0] = title->crop[1] = 0;
2872 if (title->crop[2] + title->crop[3] >= title->width)
2873 title->crop[2] = title->crop[3] = 0;
2874 tinfo->num_chapters = hb_list_count(title->list_chapter);
2875 tinfo->rate_base = title->rate_base;
2876 tinfo->rate = title->rate;
2877 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2878 title->width * title->pixel_aspect_width,
2879 title->height * title->pixel_aspect_height);
2880 tinfo->hours = title->hours;
2881 tinfo->minutes = title->minutes;
2882 tinfo->seconds = title->seconds;
2883 tinfo->duration = title->duration;
2885 tinfo->angle_count = title->angle_count;
2890 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2892 hb_audio_config_t *audio;
2894 audio = get_hb_audio(titleindex, audioindex);
2895 if (audio == NULL) return FALSE; // Bad audioindex
2896 ainfo->codec = audio->in.codec;
2897 ainfo->bitrate = audio->in.bitrate;
2898 ainfo->samplerate = audio->in.samplerate;
2903 ghb_audio_is_passthru(gint acodec)
2905 g_debug("ghb_audio_is_passthru () \n");
2906 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2910 ghb_get_default_acodec()
2912 return HB_ACODEC_FAAC;
2916 picture_settings_deps(signal_user_data_t *ud)
2918 gboolean autoscale, keep_aspect, enable_keep_aspect;
2919 gboolean enable_scale_width, enable_scale_height;
2920 gboolean enable_disp_width, enable_disp_height, enable_par;
2924 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2927 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2928 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2929 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2931 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2932 if (!enable_keep_aspect)
2934 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2936 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2937 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2939 enable_scale_width = !autoscale && (pic_par != 1);
2940 enable_scale_height = !autoscale && (pic_par != 1);
2941 enable_disp_width = (pic_par == 3) && !keep_aspect;
2942 enable_par = (pic_par == 3) && !keep_aspect;
2943 enable_disp_height = FALSE;
2945 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2946 gtk_widget_set_sensitive(widget, pic_par != 1);
2947 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2948 gtk_widget_set_sensitive(widget, pic_par != 1);
2949 widget = GHB_WIDGET(ud->builder, "scale_width");
2950 gtk_widget_set_sensitive(widget, enable_scale_width);
2951 widget = GHB_WIDGET(ud->builder, "scale_height");
2952 gtk_widget_set_sensitive(widget, enable_scale_height);
2953 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2954 gtk_widget_set_sensitive(widget, enable_disp_width);
2955 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2956 gtk_widget_set_sensitive(widget, enable_disp_height);
2957 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
2958 gtk_widget_set_sensitive(widget, enable_par);
2959 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
2960 gtk_widget_set_sensitive(widget, enable_par);
2961 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2962 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2963 widget = GHB_WIDGET(ud->builder, "autoscale");
2964 gtk_widget_set_sensitive(widget, pic_par != 1);
2968 ghb_set_scale(signal_user_data_t *ud, gint mode)
2973 gboolean keep_aspect;
2975 gboolean autocrop, autoscale, noscale;
2976 gint crop[4], width, height, par_width, par_height;
2977 gint crop_width, crop_height;
2978 gint aspect_n, aspect_d;
2979 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2980 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2985 gint max_height = 0;
2986 static gboolean busy = FALSE;
2988 g_debug("ghb_set_scale ()\n");
2989 if (h_scan == NULL) return;
2990 list = hb_get_titles( h_scan );
2991 if( !hb_list_count( list ) )
2993 /* No valid title, stop right there */
2998 titleindex = ghb_settings_combo_int(ud->settings, "title");
2999 title = hb_list_item( list, titleindex );
3000 if (title == NULL) return;
3002 if (job == NULL) return;
3004 picture_settings_deps(ud);
3009 // First configure widgets
3010 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3011 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3012 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3013 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3014 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3015 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3016 // alignment constraints rather than scaling to satisfy them.
3017 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3018 // Align dimensions to either 16 or 2 pixels
3019 // The scaler crashes if the dimensions are not divisible by 2
3020 // x264 also will not accept dims that are not multiple of 2
3024 keep_height = FALSE;
3026 // Step needs to be at least 2 because odd widths cause scaler crash
3028 widget = GHB_WIDGET (ud->builder, "scale_width");
3029 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3030 widget = GHB_WIDGET (ud->builder, "scale_height");
3031 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3034 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3035 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3036 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3037 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3038 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3039 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3040 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3041 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3045 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3046 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3047 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3048 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3049 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3050 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3051 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3052 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3054 ghb_title_info_t tinfo;
3055 ghb_get_title_info (&tinfo, titleindex);
3058 crop[0] = tinfo.crop[0];
3059 crop[1] = tinfo.crop[1];
3060 crop[2] = tinfo.crop[2];
3061 crop[3] = tinfo.crop[3];
3062 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3063 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3064 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3065 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3069 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3070 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3071 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3072 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3078 // Adjust the cropping to accomplish the desired width and height
3079 crop_width = tinfo.width - crop[2] - crop[3];
3080 crop_height = tinfo.height - crop[0] - crop[1];
3081 width = MOD_DOWN(crop_width, mod);
3082 height = MOD_DOWN(crop_height, mod);
3084 need1 = (crop_height - height) / 2;
3085 need2 = crop_height - height - need1;
3088 need1 = (crop_width - width) / 2;
3089 need2 = crop_width - width - need1;
3092 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3093 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3094 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3095 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3097 hb_reduce(&aspect_n, &aspect_d,
3098 title->width * title->pixel_aspect_width,
3099 title->height * title->pixel_aspect_height);
3100 crop_width = title->width - crop[2] - crop[3];
3101 crop_height = title->height - crop[0] - crop[1];
3105 height = crop_height;
3109 width = ghb_settings_get_int(ud->settings, "scale_width");
3110 height = ghb_settings_get_int(ud->settings, "scale_height");
3111 max_width = MOD_DOWN(
3112 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3113 max_height = MOD_DOWN(
3114 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3116 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3119 width = title->width - crop[2] - crop[3];
3121 height = title->height - crop[0] - crop[1];
3123 width = MOD_ROUND(width, mod);
3124 height = MOD_ROUND(height, mod);
3126 // Adjust dims according to max values
3128 height = MIN(height, max_height);
3130 width = MIN(width, max_width);
3134 job->anamorphic.mode = pic_par;
3135 // The scaler crashes if the dimensions are not divisible by 2
3136 // Align mod 2. And so does something in x264_encoder_headers()
3137 job->anamorphic.modulus = mod;
3138 job->anamorphic.par_width = title->pixel_aspect_width;
3139 job->anamorphic.par_height = title->pixel_aspect_height;
3140 job->anamorphic.dar_width = 0;
3141 job->anamorphic.dar_height = 0;
3143 if (keep_height && pic_par == 2)
3144 width = ((double)height * crop_width / crop_height) + 0.5;
3146 job->height = height;
3148 job->maxWidth = max_width;
3150 job->maxHeight = max_height;
3151 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3152 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3153 if (job->anamorphic.mode == 3 && !keep_aspect)
3155 job->anamorphic.keep_display_aspect = 0;
3156 if (mode & GHB_PIC_KEEP_PAR)
3158 job->anamorphic.par_width =
3159 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3160 job->anamorphic.par_height =
3161 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3165 job->anamorphic.dar_width =
3166 ghb_settings_get_int(ud->settings,
3167 "PictureDisplayWidth");
3168 job->anamorphic.dar_height =
3169 ghb_settings_get_int(ud->settings,
3170 "PictureDisplayHeight");
3175 job->anamorphic.keep_display_aspect = 1;
3177 hb_set_anamorphic_size( job, &width, &height,
3178 &par_width, &par_height );
3179 if (job->anamorphic.mode == 3 && !keep_aspect &&
3180 mode & GHB_PIC_KEEP_PAR)
3182 // hb_set_anamorphic_size reduces the par, which we
3183 // don't want in this case because the user is
3184 // explicitely specifying it.
3185 par_width = ghb_settings_get_int(ud->settings,
3187 par_height = ghb_settings_get_int(ud->settings,
3188 "PicturePARHeight");
3193 job->anamorphic.mode = pic_par;
3197 gint new_width, new_height;
3199 // Compute pixel aspect ration.
3200 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3201 // Must scale so that par becomes 1:1
3202 // Try to keep largest dimension
3203 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3204 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3206 if (max_width && new_width > max_width)
3208 height = new_height;
3210 else if (max_height && new_height > max_height)
3214 else if (keep_width)
3216 height = new_height;
3218 else if (keep_height)
3222 else if (width > new_width)
3224 height = new_height;
3230 g_debug("new w %d h %d\n", width, height);
3232 width = MOD_ROUND(width, mod);
3233 height = MOD_ROUND(height, mod);
3235 height = MIN(height, max_height);
3237 width = MIN(width, max_width);
3238 par_width = par_height = 1;
3240 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3241 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3243 gint disp_width, dar_width, dar_height;
3246 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3247 hb_reduce(&dar_width, &dar_height, disp_width, height);
3249 gint iaspect = dar_width * 9 / dar_height;
3250 if (dar_width > 2 * dar_height)
3252 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3254 else if (iaspect <= 16 && iaspect >= 15)
3256 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3258 else if (iaspect <= 12 && iaspect >= 11)
3260 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3264 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3266 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3268 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3269 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3270 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3271 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3276 set_preview_job_settings(hb_job_t *job, GValue *settings)
3278 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3279 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3280 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3281 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3283 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3284 job->anamorphic.modulus =
3285 ghb_settings_combo_int(settings, "PictureModulus");
3286 job->width = ghb_settings_get_int(settings, "scale_width");
3287 job->height = ghb_settings_get_int(settings, "scale_height");
3288 if (ghb_settings_get_boolean(settings, "show_crop"))
3290 gdouble xscale = (gdouble)job->width /
3291 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3292 gdouble yscale = (gdouble)job->height /
3293 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3295 job->width += xscale * (job->crop[2] + job->crop[3]);
3296 job->height += yscale * (job->crop[0] + job->crop[1]);
3301 job->anamorphic.modulus = 2;
3304 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3305 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3306 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3308 gboolean keep_aspect;
3309 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3310 if (job->anamorphic.mode)
3312 job->anamorphic.par_width = job->title->pixel_aspect_width;
3313 job->anamorphic.par_height = job->title->pixel_aspect_height;
3314 job->anamorphic.dar_width = 0;
3315 job->anamorphic.dar_height = 0;
3317 if (job->anamorphic.mode == 3 && !keep_aspect)
3319 job->anamorphic.keep_display_aspect = 0;
3320 job->anamorphic.par_width =
3321 ghb_settings_get_int(settings, "PicturePARWidth");
3322 job->anamorphic.par_height =
3323 ghb_settings_get_int(settings, "PicturePARHeight");
3327 job->anamorphic.keep_display_aspect = 1;
3333 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3340 if (h_scan == NULL) return 1500;
3341 list = hb_get_titles( h_scan );
3342 title = hb_list_item( list, titleindex );
3343 if (title == NULL) return 1500;
3345 if (job == NULL) return 1500;
3346 size = ghb_settings_get_int(settings, "VideoTargetSize");
3347 return hb_calc_bitrate( job, size );
3351 ghb_validate_filter_string(const gchar *str, gint max_fields)
3357 if (str == NULL || *str == 0) return TRUE;
3360 val = g_strtod(str, &end);
3362 { // Found a numeric value
3364 // negative max_fields means infinate
3365 if (max_fields >= 0 && fields > max_fields) return FALSE;
3379 ghb_validate_filters(signal_user_data_t *ud)
3386 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3389 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3390 if (!ghb_validate_filter_string(str, 4))
3392 message = g_strdup_printf(
3393 "Invalid Deinterlace Settings:\n\n%s\n",
3395 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3403 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3406 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3407 if (!ghb_validate_filter_string(str, 6))
3409 message = g_strdup_printf(
3410 "Invalid Detelecine Settings:\n\n%s\n",
3412 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3420 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3423 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3424 if (!ghb_validate_filter_string(str, 7))
3426 message = g_strdup_printf(
3427 "Invalid Decomb Settings:\n\n%s\n",
3429 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3437 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3440 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3441 if (!ghb_validate_filter_string(str, 4))
3443 message = g_strdup_printf(
3444 "Invalid Denoise Settings:\n\n%s\n",
3446 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3457 ghb_validate_video(signal_user_data_t *ud)
3462 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3463 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3464 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3465 (vcodec == HB_VCODEC_THEORA))
3467 // mp4|avi/theora combination is not supported.
3468 message = g_strdup_printf(
3469 "Theora is not supported in the MP4 and AVI containers.\n\n"
3470 "You should choose a different video codec or container.\n"
3471 "If you continue, FFMPEG will be chosen for you.");
3472 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3478 vcodec = HB_VCODEC_FFMPEG;
3479 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3485 ghb_validate_subtitles(signal_user_data_t *ud)
3491 if (h_scan == NULL) return FALSE;
3492 list = hb_get_titles( h_scan );
3493 if( !hb_list_count( list ) )
3495 /* No valid title, stop right there */
3496 g_message("No title found.\n");
3502 titleindex = ghb_settings_combo_int(ud->settings, "title");
3503 title = hb_list_item( list, titleindex );
3504 if (title == NULL) return FALSE;
3505 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3507 const GValue *slist, *settings;
3508 gint count, ii, source;
3509 gboolean burned, one_burned = FALSE;
3511 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3512 count = ghb_array_len(slist);
3513 for (ii = 0; ii < count; ii++)
3515 settings = ghb_array_get_nth(slist, ii);
3516 source = ghb_settings_get_int(settings, "SubtitleSource");
3517 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3518 if (burned && one_burned)
3520 // MP4 can only handle burned vobsubs. make sure there isn't
3521 // already something burned in the list
3522 message = g_strdup_printf(
3523 "Only one subtitle may be burned into the video.\n\n"
3524 "You should change your subtitle selections.\n"
3525 "If you continue, some subtitles will be lost.");
3526 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3538 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3540 // MP4 can only handle burned vobsubs. make sure there isn't
3541 // already something burned in the list
3542 message = g_strdup_printf(
3543 "Your chosen container does not support soft bitmap subtitles.\n\n"
3544 "You should change your subtitle selections.\n"
3545 "If you continue, some subtitles will be lost.");
3546 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3547 "Cancel", "Continue"))
3555 if (source == SRTSUB)
3559 filename = ghb_settings_get_string(settings, "SrtFile");
3560 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3562 message = g_strdup_printf(
3563 "Srt file does not exist or not a regular file.\n\n"
3564 "You should choose a valid file.\n"
3565 "If you continue, this subtitle will be ignored.");
3566 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3567 "Cancel", "Continue"))
3581 ghb_validate_audio(signal_user_data_t *ud)
3588 if (h_scan == NULL) return FALSE;
3589 list = hb_get_titles( h_scan );
3590 if( !hb_list_count( list ) )
3592 /* No valid title, stop right there */
3593 g_message("No title found.\n");
3599 titleindex = ghb_settings_combo_int(ud->settings, "title");
3600 title = hb_list_item( list, titleindex );
3601 if (title == NULL) return FALSE;
3602 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3604 const GValue *audio_list;
3607 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3608 count = ghb_array_len(audio_list);
3609 for (ii = 0; ii < count; ii++)
3612 hb_audio_config_t *taudio;
3614 asettings = ghb_array_get_nth(audio_list, ii);
3615 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3616 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3617 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3618 title->list_audio, track );
3619 if (!(taudio->in.codec & codec) &&
3620 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3622 // Not supported. AC3 is passthrough only, so input must be AC3
3623 message = g_strdup_printf(
3624 "The source does not support Pass-Thru.\n\n"
3625 "You should choose a different audio codec.\n"
3626 "If you continue, one will be chosen for you.");
3627 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3633 if (mux == HB_MUX_AVI)
3635 codec = HB_ACODEC_LAME;
3639 codec = HB_ACODEC_FAAC;
3641 value = get_acodec_value(codec);
3642 ghb_settings_take_value(asettings, "AudioEncoder", value);
3644 gchar *a_unsup = NULL;
3645 gchar *mux_s = NULL;
3646 if (mux == HB_MUX_MP4)
3649 // mp4/mp3|vorbis combination is not supported.
3650 if (codec == HB_ACODEC_LAME)
3653 codec = HB_ACODEC_FAAC;
3655 if (codec == HB_ACODEC_VORBIS)
3658 codec = HB_ACODEC_FAAC;
3660 if (codec == HB_ACODEC_DCA)
3663 codec = HB_ACODEC_FAAC;
3666 else if (mux == HB_MUX_AVI)
3669 // avi/faac|vorbis combination is not supported.
3670 if (codec == HB_ACODEC_FAAC)
3673 codec = HB_ACODEC_LAME;
3675 if (codec == HB_ACODEC_VORBIS)
3678 codec = HB_ACODEC_LAME;
3681 else if (mux == HB_MUX_OGM)
3684 // avi/faac|vorbis combination is not supported.
3685 if (codec == HB_ACODEC_FAAC)
3688 codec = HB_ACODEC_VORBIS;
3690 if (codec == HB_ACODEC_AC3)
3693 codec = HB_ACODEC_VORBIS;
3695 if (codec == HB_ACODEC_DCA)
3698 codec = HB_ACODEC_VORBIS;
3703 message = g_strdup_printf(
3704 "%s is not supported in the %s container.\n\n"
3705 "You should choose a different audio codec.\n"
3706 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3707 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3713 value = get_acodec_value(codec);
3714 ghb_settings_take_value(asettings, "AudioEncoder", value);
3716 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3717 gboolean allow_mono = TRUE;
3718 gboolean allow_stereo = TRUE;
3719 gboolean allow_dolby = TRUE;
3720 gboolean allow_dpl2 = TRUE;
3721 gboolean allow_6ch = TRUE;
3723 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3724 (codec != HB_ACODEC_LAME);
3725 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3727 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3729 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3730 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3731 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3732 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3734 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3735 (codec != HB_ACODEC_LAME) &&
3736 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3737 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3739 gchar *mix_unsup = NULL;
3740 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3744 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3746 mix_unsup = "stereo";
3748 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3750 mix_unsup = "Dolby";
3752 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3754 mix_unsup = "Dolby Pro Logic II";
3756 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3758 mix_unsup = "6 Channel";
3762 message = g_strdup_printf(
3763 "The source audio does not support %s mixdown.\n\n"
3764 "You should choose a different mixdown.\n"
3765 "If you continue, one will be chosen for you.", mix_unsup);
3766 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3772 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3773 value = get_amix_value(mix);
3774 ghb_settings_take_value(asettings, "AudioMixdown", value);
3781 ghb_validate_vquality(GValue *settings)
3787 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3788 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3790 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3791 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3795 case HB_VCODEC_X264:
3801 case HB_VCODEC_FFMPEG:
3807 case HB_VCODEC_THEORA:
3819 if (vquality < min || vquality > max)
3821 message = g_strdup_printf(
3822 "Interesting video quality choise: %d\n\n"
3823 "Typical values range from %d to %d.\n"
3824 "Are you sure you wish to use this setting?",
3825 (gint)vquality, min, max);
3826 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3827 "Cancel", "Continue"))
3839 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3844 static gchar *x264opts;
3846 gboolean tweaks = FALSE;
3847 gchar *detel_str = NULL;
3848 gchar *decomb_str = NULL;
3849 gchar *deint_str = NULL;
3850 gchar *deblock_str = NULL;
3851 gchar *denoise_str = NULL;
3852 gchar *dest_str = NULL;
3854 g_debug("add_job()\n");
3855 if (h == NULL) return;
3856 list = hb_get_titles( h );
3857 if( !hb_list_count( list ) )
3859 /* No valid title, stop right there */
3863 title = hb_list_item( list, titleindex );
3864 if (title == NULL) return;
3866 /* Set job settings */
3868 if (job == NULL) return;
3870 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3871 if (job->start_at_preview)
3873 job->seek_points = ghb_settings_get_int(js, "preview_count");
3874 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3877 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3878 job->mux = ghb_settings_combo_int(js, "FileFormat");
3879 if (job->mux == HB_MUX_MP4)
3881 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3882 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3886 job->largeFileSize = FALSE;
3887 job->mp4_optimize = FALSE;
3889 if (!job->start_at_preview)
3891 gint chapter_start, chapter_end;
3892 chapter_start = ghb_settings_get_int(js, "start_chapter");
3893 chapter_end = ghb_settings_get_int(js, "end_chapter");
3894 gint num_chapters = hb_list_count(title->list_chapter);
3895 job->chapter_start = MIN( num_chapters, chapter_start );
3896 job->chapter_end = MAX( job->chapter_start, chapter_end );
3898 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3899 if (job->chapter_start == job->chapter_end)
3900 job->chapter_markers = 0;
3901 if ( job->chapter_markers )
3908 chapters = ghb_settings_get_value(js, "chapter_list");
3909 count = ghb_array_len(chapters);
3910 for(chap = chapter_start; chap <= chapter_end; chap++)
3912 hb_chapter_t * chapter_s;
3918 chapter = ghb_array_get_nth(chapters, chap-1);
3919 name = ghb_value_string(chapter);
3923 name = g_strdup_printf ("Chapter %2d", chap);
3925 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3926 strncpy(chapter_s->title, name, 1023);
3927 chapter_s->title[1023] = '\0';
3932 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3933 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3934 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3935 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3938 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3939 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3941 job->deinterlace = (deint != 0) ? 1 : 0;
3943 job->deinterlace = 0;
3944 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3946 gboolean keep_aspect;
3947 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
3948 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3949 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3950 if (job->anamorphic.mode)
3952 job->anamorphic.par_width = title->pixel_aspect_width;
3953 job->anamorphic.par_height = title->pixel_aspect_height;
3954 job->anamorphic.dar_width = 0;
3955 job->anamorphic.dar_height = 0;
3957 if (job->anamorphic.mode == 3 && !keep_aspect)
3959 job->anamorphic.keep_display_aspect = 0;
3960 job->anamorphic.par_width =
3961 ghb_settings_get_int(js, "PicturePARWidth");
3962 job->anamorphic.par_height =
3963 ghb_settings_get_int(js, "PicturePARHeight");
3967 job->anamorphic.keep_display_aspect = 1;
3971 /* Add selected filters */
3972 job->filters = hb_list_init();
3973 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3978 if (detel_opts.map[detel].svalue != NULL)
3979 detel_str = g_strdup(detel_opts.map[detel].svalue);
3982 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3983 hb_filter_detelecine.settings = detel_str;
3984 hb_list_add( job->filters, &hb_filter_detelecine );
3990 if (decomb_opts.map[decomb].svalue != NULL)
3991 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3994 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3995 hb_filter_decomb.settings = decomb_str;
3996 hb_list_add( job->filters, &hb_filter_decomb );
3998 if( job->deinterlace )
4002 if (deint_opts.map[deint].svalue != NULL)
4003 deint_str = g_strdup(deint_opts.map[deint].svalue);
4006 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4007 hb_filter_deinterlace.settings = deint_str;
4008 hb_list_add( job->filters, &hb_filter_deinterlace );
4010 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4013 deblock_str = g_strdup_printf("%d", deblock);
4014 hb_filter_deblock.settings = deblock_str;
4015 hb_list_add( job->filters, &hb_filter_deblock );
4017 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4022 if (denoise_opts.map[denoise].svalue != NULL)
4023 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4026 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4027 hb_filter_denoise.settings = denoise_str;
4028 hb_list_add( job->filters, &hb_filter_denoise );
4030 job->width = ghb_settings_get_int(js, "scale_width");
4031 job->height = ghb_settings_get_int(js, "scale_height");
4033 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4034 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
4035 (job->vcodec == HB_VCODEC_THEORA))
4037 // mp4|avi/theora combination is not supported.
4038 job->vcodec = HB_VCODEC_FFMPEG;
4040 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4042 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4044 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4047 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4048 job->vquality = vquality;
4051 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4053 job->vquality = -1.0;
4054 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4057 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4060 job->vrate = title->rate;
4061 job->vrate_base = title->rate_base;
4066 job->vrate = 27000000;
4067 job->vrate_base = vrate;
4071 // AVI container does not support variable frame rate.
4072 // OGM supports variable frame rate, but bases all timing on
4073 // DTS, which breaks when b-frames are used since it is
4074 // impossible to reconstruct PTS from DTS when the framerate
4076 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
4081 const GValue *audio_list;
4085 audio_list = ghb_settings_get_value(js, "audio_list");
4086 count = ghb_array_len(audio_list);
4087 for (ii = 0; ii < count; ii++)
4090 hb_audio_config_t audio;
4091 hb_audio_config_t *taudio;
4093 hb_audio_config_init(&audio);
4094 asettings = ghb_array_get_nth(audio_list, ii);
4095 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4096 audio.out.track = tcount;
4097 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4098 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4099 title->list_audio, audio.in.track );
4100 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4102 if (!(taudio->in.codec & audio.out.codec))
4104 // Not supported. AC3 is passthrough only, so input must be AC3
4105 if (job->mux == HB_MUX_AVI)
4107 audio.out.codec = HB_ACODEC_LAME;
4111 audio.out.codec = HB_ACODEC_FAAC;
4116 audio.out.codec &= taudio->in.codec;
4119 if ((job->mux == HB_MUX_MP4) &&
4120 ((audio.out.codec == HB_ACODEC_LAME) ||
4121 (audio.out.codec == HB_ACODEC_VORBIS)))
4123 // mp4/mp3|vorbis combination is not supported.
4124 audio.out.codec = HB_ACODEC_FAAC;
4126 if ((job->mux == HB_MUX_AVI) &&
4127 ((audio.out.codec == HB_ACODEC_FAAC) ||
4128 (audio.out.codec == HB_ACODEC_VORBIS)))
4130 // avi/faac|vorbis combination is not supported.
4131 audio.out.codec = HB_ACODEC_LAME;
4133 if ((job->mux == HB_MUX_OGM) &&
4134 ((audio.out.codec == HB_ACODEC_FAAC) ||
4135 (audio.out.codec == HB_ACODEC_AC3) ||
4136 (audio.out.codec == HB_ACODEC_DCA)))
4138 // ogm/faac|ac3 combination is not supported.
4139 audio.out.codec = HB_ACODEC_VORBIS;
4141 audio.out.dynamic_range_compression =
4142 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4143 if (audio.out.dynamic_range_compression < 1.0)
4144 audio.out.dynamic_range_compression = 0.0;
4146 // It would be better if this were done in libhb for us, but its not yet.
4147 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
4149 audio.out.mixdown = 0;
4153 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4154 // Make sure the mixdown is valid and pick a new one if not.
4155 audio.out.mixdown = ghb_get_best_mix(titleindex,
4156 audio.in.track, audio.out.codec, audio.out.mixdown);
4158 ghb_settings_combo_int(asettings, "AudioBitrate");
4159 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4160 if (srate == 0) // 0 is same as source
4161 audio.out.samplerate = taudio->in.samplerate;
4163 audio.out.samplerate = srate;
4166 // Add it to the jobs audio list
4167 hb_audio_add( job, &audio );
4170 // I was tempted to move this up with the reset of the video quality
4171 // settings, but I suspect the settings above need to be made
4172 // first in order for hb_calc_bitrate to be accurate.
4173 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4177 size = ghb_settings_get_int(js, "VideoTargetSize");
4178 job->vbitrate = hb_calc_bitrate( job, size );
4179 job->vquality = -1.0;
4182 dest_str = ghb_settings_get_string(js, "destination");
4183 job->file = dest_str;
4184 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
4186 const GValue *subtitle_list;
4188 gboolean force, burned, def, one_burned = FALSE;
4190 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4191 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4192 count = ghb_array_len(subtitle_list);
4193 for (ii = 0; ii < count; ii++)
4198 ssettings = ghb_array_get_nth(subtitle_list, ii);
4200 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4201 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4202 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4203 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4205 if (source == SRTSUB)
4207 hb_subtitle_config_t sub_config;
4208 gchar *filename, *lang, *code;
4210 filename = ghb_settings_get_string(ssettings, "SrtFile");
4211 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4215 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4216 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4217 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4218 strncpy(sub_config.src_filename, filename, 128);
4219 strncpy(sub_config.src_codeset, code, 40);
4220 sub_config.force = 0;
4221 sub_config.dest = PASSTHRUSUB;
4222 sub_config.default_track = def;
4224 hb_srt_add( job, &sub_config, lang);
4232 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4235 if (!burned && job->mux == HB_MUX_MKV)
4237 job->select_subtitle_config.dest = PASSTHRUSUB;
4239 else if (!burned && job->mux == HB_MUX_MP4)
4241 // Skip any non-burned vobsubs when output is mp4
4246 // Only allow one subtitle to be burned into the video
4249 job->select_subtitle_config.dest = RENDERSUB;
4252 job->select_subtitle_config.force = force;
4253 job->select_subtitle_config.default_track = def;
4254 job->indepth_scan = 1;
4255 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4257 else if (subtitle >= 0)
4259 hb_subtitle_t * subt;
4260 hb_subtitle_config_t sub_config;
4262 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4263 sub_config = subt->config;
4266 if (!burned && job->mux == HB_MUX_MKV &&
4267 subt->format == PICTURESUB)
4269 sub_config.dest = PASSTHRUSUB;
4271 else if (!burned && job->mux == HB_MUX_MP4 &&
4272 subt->format == PICTURESUB)
4274 // Skip any non-burned vobsubs when output is mp4
4277 else if ( burned && subt->format == PICTURESUB )
4279 // Only allow one subtitle to be burned into the video
4284 sub_config.force = force;
4285 sub_config.default_track = def;
4286 hb_subtitle_add( job, &sub_config, subtitle );
4291 // TODO: libhb holds onto a reference to the x264opts and is not
4292 // finished with it until encoding the job is done. But I can't
4293 // find a way to get at the job before it is removed in order to
4294 // free up the memory I am allocating here.
4295 // The short story is THIS LEAKS.
4296 x264opts = ghb_build_x264opts_string(js);
4298 if( *x264opts == '\0' )
4304 if (job->indepth_scan == 1)
4306 // Subtitle scan. Look for subtitle matching audio language
4309 * When subtitle scan is enabled do a fast pre-scan job
4310 * which will determine which subtitles to enable, if any.
4313 job->indepth_scan = 1;
4314 job->x264opts = NULL;
4317 * Add the pre-scan job
4319 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4323 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4324 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4327 * If subtitle_scan is enabled then only turn it on
4328 * for the second pass and then off again for the
4332 job->indepth_scan = 0;
4335 * If turbo options have been selected then append them
4336 * to the x264opts now (size includes one ':' and the '\0')
4338 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4340 gchar *tmp_x264opts;
4344 badapt = ghb_lookup_badapt(x264opts);
4347 extra_opts = g_strdup_printf("%s", turbo_opts);
4351 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4356 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4361 * No x264opts to modify, but apply the turbo options
4362 * anyway as they may be modifying defaults
4364 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4368 job->x264opts = tmp_x264opts;
4372 job->x264opts = x264opts;
4374 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4376 //if (job->x264opts != NULL)
4377 // g_free(job->x264opts);
4381 * On the second pass we turn off subtitle scan so that we
4382 * can actually encode using any subtitles that were auto
4383 * selected in the first pass (using the whacky select-subtitle
4384 * attribute of the job).
4386 job->indepth_scan = 0;
4387 job->x264opts = x264opts;
4388 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4390 //if (job->x264opts != NULL)
4391 // g_free(job->x264opts);
4395 job->x264opts = x264opts;
4396 job->indepth_scan = 0;
4398 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4400 //if (job->x264opts != NULL)
4401 // g_free(job->x264opts);
4404 // clean up audio list
4405 gint num_audio_tracks = hb_list_count(job->list_audio);
4406 for(ii = 0; ii < num_audio_tracks; ii++)
4408 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4409 hb_list_rem(job->list_audio, audio);
4413 // clean up subtitle list
4414 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4415 for(ii = 0; ii < num_subtitle_tracks; ii++)
4417 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4418 hb_list_rem(job->list_subtitle, subtitle);
4422 if (detel_str) g_free(detel_str);
4423 if (decomb_str) g_free(decomb_str);
4424 if (deint_str) g_free(deint_str);
4425 if (deblock_str) g_free(deblock_str);
4426 if (denoise_str) g_free(denoise_str);
4427 if (dest_str) g_free(dest_str);
4431 ghb_add_job(GValue *js, gint unique_id)
4433 // Since I'm doing a scan of the single title I want just prior
4434 // to adding the job, there is only the one title to choose from.
4435 add_job(h_queue, js, unique_id, 0);
4439 ghb_add_live_job(GValue *js, gint unique_id)
4441 // Since I'm doing a scan of the single title I want just prior
4442 // to adding the job, there is only the one title to choose from.
4443 gint titleindex = ghb_settings_combo_int(js, "title");
4444 add_job(h_scan, js, unique_id, titleindex);
4448 ghb_remove_job(gint unique_id)
4453 // Multiples passes all get the same id
4455 // Go backwards through list, so reordering doesn't screw me.
4456 ii = hb_count(h_queue) - 1;
4457 while ((job = hb_job(h_queue, ii--)) != NULL)
4459 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4460 hb_rem(h_queue, job);
4467 hb_start( h_queue );
4477 ghb_start_live_encode()
4483 ghb_stop_live_encode()
4492 hb_get_state2( h_queue, &s );
4494 if( s.state == HB_STATE_PAUSED )
4496 hb_resume( h_queue );
4500 hb_pause( h_queue );
4515 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4518 gint channels = gdk_pixbuf_get_n_channels (pb);
4519 gint stride = gdk_pixbuf_get_rowstride (pb);
4521 for (jj = 0; jj < width; jj++)
4523 dst = pixels + y * stride + (x+jj) * channels;
4524 for (ii = 0; ii < len; ii++)
4545 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4548 gint channels = gdk_pixbuf_get_n_channels (pb);
4549 gint stride = gdk_pixbuf_get_rowstride (pb);
4551 for (jj = 0; jj < width; jj++)
4553 dst = pixels + (y+jj) * stride + x * channels;
4554 for (ii = 0; ii < len; ii++)
4575 gint line_width = 8;
4582 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4587 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4589 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4595 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4597 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4603 ghb_get_preview_image(
4606 signal_user_data_t *ud,
4614 settings = ud->settings;
4615 list = hb_get_titles( h_scan );
4616 if( !hb_list_count( list ) )
4618 /* No valid title, stop right there */
4621 title = hb_list_item( list, titleindex );
4622 if (title == NULL) return NULL;
4623 if (title->job == NULL) return NULL;
4624 set_preview_job_settings(title->job, settings);
4626 // hb_get_preview doesn't compensate for anamorphic, so lets
4627 // calculate scale factors
4628 gint width, height, par_width = 1, par_height = 1;
4629 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4632 hb_set_anamorphic_size( title->job, &width, &height,
4633 &par_width, &par_height );
4636 // Make sure we have a big enough buffer to receive the image from libhb
4637 gint dstWidth = title->job->width;
4638 gint dstHeight= title->job->height;
4640 static guint8 *buffer = NULL;
4641 static gint bufferSize = 0;
4644 newSize = dstWidth * dstHeight * 4;
4645 if( bufferSize < newSize )
4647 bufferSize = newSize;
4648 buffer = (guint8*) g_realloc( buffer, bufferSize );
4650 hb_get_preview( h_scan, title, index, buffer );
4652 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4653 // libhb's format something suitable.
4655 // The image data returned by hb_get_preview is 4 bytes per pixel,
4656 // BGRA format. Alpha is ignored.
4658 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4659 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4661 guint32 *src = (guint32*)buffer;
4662 guint8 *dst = pixels;
4665 gint channels = gdk_pixbuf_get_n_channels (preview);
4666 gint stride = gdk_pixbuf_get_rowstride (preview);
4669 for (ii = 0; ii < dstHeight; ii++)
4672 for (jj = 0; jj < dstWidth; jj++)
4674 tmp[0] = src[0] >> 16;
4675 tmp[1] = src[0] >> 8;
4676 tmp[2] = src[0] >> 0;
4682 gint w = ghb_settings_get_int(settings, "scale_width");
4683 gint h = ghb_settings_get_int(settings, "scale_height");
4684 ghb_par_scale(ud, &w, &h, par_width, par_height);
4686 gint c0, c1, c2, c3;
4687 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4688 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4689 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4690 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4692 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4693 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4695 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4698 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4702 gint orig_w, orig_h;
4705 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4709 ss = gdk_screen_get_default();
4710 s_w = gdk_screen_get_width(ss);
4711 s_h = gdk_screen_get_height(ss);
4715 if (dstWidth > s_w * factor / 100)
4717 dstWidth = s_w * factor / 100;
4718 dstHeight = dstHeight * dstWidth / orig_w;
4720 if (dstHeight > s_h * factor / 100)
4722 dstHeight = s_h * factor / 100;
4723 dstWidth = dstWidth * dstHeight / orig_h;
4725 xscale *= (gdouble)dstWidth / orig_w;
4726 yscale *= (gdouble)dstHeight / orig_h;
4727 w *= (gdouble)dstWidth / orig_w;
4728 h *= (gdouble)dstHeight / orig_h;
4730 GdkPixbuf *scaled_preview;
4731 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4732 if (ghb_settings_get_boolean(settings, "show_crop"))
4739 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4741 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4743 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4745 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4747 g_object_unref (preview);
4748 return scaled_preview;
4752 sanitize_volname(gchar *name)
4777 ghb_dvd_volname(const gchar *device)
4780 name = hb_dvd_name((gchar*)device);
4781 if (name != NULL && name[0] != 0)
4783 name = g_strdup(name);
4784 sanitize_volname(name);