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_appcast_update_opts[] =
125 {"Never", "never", 0, "never"},
126 {"Daily", "daily", 1, "daily"},
127 {"Weekly", "weekly", 2, "weekly"},
128 {"Monthly", "monthly", 3, "monthly"},
130 combo_opts_t appcast_update_opts =
132 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
133 d_appcast_update_opts
136 static options_map_t d_vqual_granularity_opts[] =
138 {"0.2", "0.2", 0.2, "0.2"},
139 {"0.25", "0.25", 0.25, "0.25"},
140 {"0.5", "0.5", 0.5, "0.5"},
143 combo_opts_t vqual_granularity_opts =
145 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
146 d_vqual_granularity_opts
149 static options_map_t d_container_opts[] =
151 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
152 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
154 combo_opts_t container_opts =
156 sizeof(d_container_opts)/sizeof(options_map_t),
160 static options_map_t d_detel_opts[] =
162 {"None", "none", 0, ""},
163 {"Custom", "custom", 1, ""},
164 {"Default","default",2, NULL},
166 combo_opts_t detel_opts =
168 sizeof(d_detel_opts)/sizeof(options_map_t),
172 static options_map_t d_decomb_opts[] =
174 {"None", "none", 0, ""},
175 {"Custom", "custom", 1, ""},
176 {"Default","default",2, NULL},
178 combo_opts_t decomb_opts =
180 sizeof(d_decomb_opts)/sizeof(options_map_t),
184 static options_map_t d_deint_opts[] =
186 {"None", "none", 0, ""},
187 {"Custom", "custom", 1, ""},
188 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
189 {"Slow", "slow", 3, "2:-1:-1:0:1"},
190 {"Slower", "slower", 4, "0:-1:-1:0:1"},
192 combo_opts_t deint_opts =
194 sizeof(d_deint_opts)/sizeof(options_map_t),
198 static options_map_t d_denoise_opts[] =
200 {"None", "none", 0, ""},
201 {"Custom", "custom", 1, ""},
202 {"Weak", "weak", 2, "2:1:2:3"},
203 {"Medium", "medium", 3, "3:2:2:3"},
204 {"Strong", "strong", 4, "7:7:5:5"},
206 combo_opts_t denoise_opts =
208 sizeof(d_denoise_opts)/sizeof(options_map_t),
212 static options_map_t d_vcodec_opts[] =
214 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
215 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
216 {"Theora", "theora", HB_VCODEC_THEORA, ""},
218 combo_opts_t vcodec_opts =
220 sizeof(d_vcodec_opts)/sizeof(options_map_t),
224 static options_map_t d_acodec_opts[] =
226 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
227 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
228 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
229 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
230 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
231 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
233 combo_opts_t acodec_opts =
235 sizeof(d_acodec_opts)/sizeof(options_map_t),
239 static options_map_t d_direct_opts[] =
241 {"None", "none", 0, "none"},
242 {"Spatial", "spatial", 1, "spatial"},
243 {"Temporal", "temporal", 2, "temporal"},
244 {"Automatic", "auto", 3, "auto"},
246 combo_opts_t direct_opts =
248 sizeof(d_direct_opts)/sizeof(options_map_t),
252 static options_map_t d_badapt_opts[] =
254 {"Off", "0", 0, "0"},
255 {"Fast", "1", 1, "1"},
256 {"Optimal", "2", 2, "2"},
258 combo_opts_t badapt_opts =
260 sizeof(d_badapt_opts)/sizeof(options_map_t),
264 static options_map_t d_me_opts[] =
266 {"Diamond", "dia", 0, "dia"},
267 {"Hexagon", "hex", 1, "hex"},
268 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
269 {"Exhaustive", "esa", 3, "esa"},
270 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
272 combo_opts_t me_opts =
274 sizeof(d_me_opts)/sizeof(options_map_t),
278 static options_map_t d_subme_opts[] =
290 combo_opts_t subme_opts =
292 sizeof(d_subme_opts)/sizeof(options_map_t),
296 static options_map_t d_analyse_opts[] =
298 {"Some", "some", 0, "some"},
299 {"None", "none", 1, "none"},
300 {"All", "all", 2, "all"},
301 {"Custom", "custom", 3, "all"},
303 combo_opts_t analyse_opts =
305 sizeof(d_analyse_opts)/sizeof(options_map_t),
309 static options_map_t d_trellis_opts[] =
311 {"Disabled", "0", 0, "0"},
312 {"Final Macro Block", "1", 1, "1"},
313 {"Always", "2", 2, "2"},
315 combo_opts_t trellis_opts =
317 sizeof(d_trellis_opts)/sizeof(options_map_t),
321 combo_opts_t subtitle_opts =
327 combo_opts_t title_opts =
333 combo_opts_t audio_track_opts =
345 combo_name_map_t combo_name_map[] =
347 {"WhenComplete", &when_complete_opts},
348 {"PicturePAR", &par_opts},
349 {"PictureModulus", &alignment_opts},
350 {"LoggingLevel", &logging_opts},
351 {"check_updates", &appcast_update_opts},
352 {"VideoQualityGranularity", &vqual_granularity_opts},
353 {"FileFormat", &container_opts},
354 {"PictureDeinterlace", &deint_opts},
355 {"PictureDecomb", &decomb_opts},
356 {"PictureDetelecine", &detel_opts},
357 {"PictureDenoise", &denoise_opts},
358 {"VideoEncoder", &vcodec_opts},
359 {"AudioEncoder", &acodec_opts},
360 {"x264_direct", &direct_opts},
361 {"x264_b_adapt", &badapt_opts},
362 {"x264_me", &me_opts},
363 {"x264_subme", &subme_opts},
364 {"x264_analyse", &analyse_opts},
365 {"x264_trellis", &trellis_opts},
366 {"SubtitleTrack", &subtitle_opts},
367 {"title", &title_opts},
368 {"AudioTrack", &audio_track_opts},
373 typedef struct iso639_lang_t
375 char * eng_name; /* Description in English */
376 char * native_name; /* Description in native language */
377 char * iso639_1; /* ISO-639-1 (2 characters) code */
378 char * iso639_2; /* ISO-639-2/t (3 character) code */
379 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
383 const iso639_lang_t ghb_language_table[] =
385 { "Any", "", "zz", "und" },
386 { "Afar", "", "aa", "aar" },
387 { "Abkhazian", "", "ab", "abk" },
388 { "Afrikaans", "", "af", "afr" },
389 { "Akan", "", "ak", "aka" },
390 { "Albanian", "", "sq", "sqi", "alb" },
391 { "Amharic", "", "am", "amh" },
392 { "Arabic", "", "ar", "ara" },
393 { "Aragonese", "", "an", "arg" },
394 { "Armenian", "", "hy", "hye", "arm" },
395 { "Assamese", "", "as", "asm" },
396 { "Avaric", "", "av", "ava" },
397 { "Avestan", "", "ae", "ave" },
398 { "Aymara", "", "ay", "aym" },
399 { "Azerbaijani", "", "az", "aze" },
400 { "Bashkir", "", "ba", "bak" },
401 { "Bambara", "", "bm", "bam" },
402 { "Basque", "", "eu", "eus", "baq" },
403 { "Belarusian", "", "be", "bel" },
404 { "Bengali", "", "bn", "ben" },
405 { "Bihari", "", "bh", "bih" },
406 { "Bislama", "", "bi", "bis" },
407 { "Bosnian", "", "bs", "bos" },
408 { "Breton", "", "br", "bre" },
409 { "Bulgarian", "", "bg", "bul" },
410 { "Burmese", "", "my", "mya", "bur" },
411 { "Catalan", "", "ca", "cat" },
412 { "Chamorro", "", "ch", "cha" },
413 { "Chechen", "", "ce", "che" },
414 { "Chinese", "", "zh", "zho", "chi" },
415 { "Church Slavic", "", "cu", "chu" },
416 { "Chuvash", "", "cv", "chv" },
417 { "Cornish", "", "kw", "cor" },
418 { "Corsican", "", "co", "cos" },
419 { "Cree", "", "cr", "cre" },
420 { "Czech", "", "cs", "ces", "cze" },
421 { "Danish", "Dansk", "da", "dan" },
422 { "Divehi", "", "dv", "div" },
423 { "Dutch", "Nederlands", "nl", "nld", "dut" },
424 { "Dzongkha", "", "dz", "dzo" },
425 { "English", "English", "en", "eng" },
426 { "Esperanto", "", "eo", "epo" },
427 { "Estonian", "", "et", "est" },
428 { "Ewe", "", "ee", "ewe" },
429 { "Faroese", "", "fo", "fao" },
430 { "Fijian", "", "fj", "fij" },
431 { "Finnish", "Suomi", "fi", "fin" },
432 { "French", "Francais", "fr", "fra", "fre" },
433 { "Western Frisian", "", "fy", "fry" },
434 { "Fulah", "", "ff", "ful" },
435 { "Georgian", "", "ka", "kat", "geo" },
436 { "German", "Deutsch", "de", "deu", "ger" },
437 { "Gaelic (Scots)", "", "gd", "gla" },
438 { "Irish", "", "ga", "gle" },
439 { "Galician", "", "gl", "glg" },
440 { "Manx", "", "gv", "glv" },
441 { "Greek, Modern", "", "el", "ell", "gre" },
442 { "Guarani", "", "gn", "grn" },
443 { "Gujarati", "", "gu", "guj" },
444 { "Haitian", "", "ht", "hat" },
445 { "Hausa", "", "ha", "hau" },
446 { "Hebrew", "", "he", "heb" },
447 { "Herero", "", "hz", "her" },
448 { "Hindi", "", "hi", "hin" },
449 { "Hiri Motu", "", "ho", "hmo" },
450 { "Hungarian", "Magyar", "hu", "hun" },
451 { "Igbo", "", "ig", "ibo" },
452 { "Icelandic", "Islenska", "is", "isl", "ice" },
453 { "Ido", "", "io", "ido" },
454 { "Sichuan Yi", "", "ii", "iii" },
455 { "Inuktitut", "", "iu", "iku" },
456 { "Interlingue", "", "ie", "ile" },
457 { "Interlingua", "", "ia", "ina" },
458 { "Indonesian", "", "id", "ind" },
459 { "Inupiaq", "", "ik", "ipk" },
460 { "Italian", "Italiano", "it", "ita" },
461 { "Javanese", "", "jv", "jav" },
462 { "Japanese", "", "ja", "jpn" },
463 { "Kalaallisut", "", "kl", "kal" },
464 { "Kannada", "", "kn", "kan" },
465 { "Kashmiri", "", "ks", "kas" },
466 { "Kanuri", "", "kr", "kau" },
467 { "Kazakh", "", "kk", "kaz" },
468 { "Central Khmer", "", "km", "khm" },
469 { "Kikuyu", "", "ki", "kik" },
470 { "Kinyarwanda", "", "rw", "kin" },
471 { "Kirghiz", "", "ky", "kir" },
472 { "Komi", "", "kv", "kom" },
473 { "Kongo", "", "kg", "kon" },
474 { "Korean", "", "ko", "kor" },
475 { "Kuanyama", "", "kj", "kua" },
476 { "Kurdish", "", "ku", "kur" },
477 { "Lao", "", "lo", "lao" },
478 { "Latin", "", "la", "lat" },
479 { "Latvian", "", "lv", "lav" },
480 { "Limburgan", "", "li", "lim" },
481 { "Lingala", "", "ln", "lin" },
482 { "Lithuanian", "", "lt", "lit" },
483 { "Luxembourgish", "", "lb", "ltz" },
484 { "Luba-Katanga", "", "lu", "lub" },
485 { "Ganda", "", "lg", "lug" },
486 { "Macedonian", "", "mk", "mkd", "mac" },
487 { "Marshallese", "", "mh", "mah" },
488 { "Malayalam", "", "ml", "mal" },
489 { "Maori", "", "mi", "mri", "mao" },
490 { "Marathi", "", "mr", "mar" },
491 { "Malay", "", "ms", "msa", "msa" },
492 { "Malagasy", "", "mg", "mlg" },
493 { "Maltese", "", "mt", "mlt" },
494 { "Moldavian", "", "mo", "mol" },
495 { "Mongolian", "", "mn", "mon" },
496 { "Nauru", "", "na", "nau" },
497 { "Navajo", "", "nv", "nav" },
498 { "Ndebele, South", "", "nr", "nbl" },
499 { "Ndebele, North", "", "nd", "nde" },
500 { "Ndonga", "", "ng", "ndo" },
501 { "Nepali", "", "ne", "nep" },
502 { "Norwegian Nynorsk", "", "nn", "nno" },
503 { "Norwegian Bokmål", "", "nb", "nob" },
504 { "Norwegian", "Norsk", "no", "nor" },
505 { "Chichewa; Nyanja", "", "ny", "nya" },
506 { "Occitan", "", "oc", "oci" },
507 { "Ojibwa", "", "oj", "oji" },
508 { "Oriya", "", "or", "ori" },
509 { "Oromo", "", "om", "orm" },
510 { "Ossetian", "", "os", "oss" },
511 { "Panjabi", "", "pa", "pan" },
512 { "Persian", "", "fa", "fas", "per" },
513 { "Pali", "", "pi", "pli" },
514 { "Polish", "", "pl", "pol" },
515 { "Portuguese", "Portugues", "pt", "por" },
516 { "Pushto", "", "ps", "pus" },
517 { "Quechua", "", "qu", "que" },
518 { "Romansh", "", "rm", "roh" },
519 { "Romanian", "", "ro", "ron", "rum" },
520 { "Rundi", "", "rn", "run" },
521 { "Russian", "", "ru", "rus" },
522 { "Sango", "", "sg", "sag" },
523 { "Sanskrit", "", "sa", "san" },
524 { "Serbian", "", "sr", "srp", "scc" },
525 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
526 { "Sinhala", "", "si", "sin" },
527 { "Slovak", "", "sk", "slk", "slo" },
528 { "Slovenian", "", "sl", "slv" },
529 { "Northern Sami", "", "se", "sme" },
530 { "Samoan", "", "sm", "smo" },
531 { "Shona", "", "sn", "sna" },
532 { "Sindhi", "", "sd", "snd" },
533 { "Somali", "", "so", "som" },
534 { "Sotho, Southern", "", "st", "sot" },
535 { "Spanish", "Espanol", "es", "spa" },
536 { "Sardinian", "", "sc", "srd" },
537 { "Swati", "", "ss", "ssw" },
538 { "Sundanese", "", "su", "sun" },
539 { "Swahili", "", "sw", "swa" },
540 { "Swedish", "Svenska", "sv", "swe" },
541 { "Tahitian", "", "ty", "tah" },
542 { "Tamil", "", "ta", "tam" },
543 { "Tatar", "", "tt", "tat" },
544 { "Telugu", "", "te", "tel" },
545 { "Tajik", "", "tg", "tgk" },
546 { "Tagalog", "", "tl", "tgl" },
547 { "Thai", "", "th", "tha" },
548 { "Tibetan", "", "bo", "bod", "tib" },
549 { "Tigrinya", "", "ti", "tir" },
550 { "Tonga", "", "to", "ton" },
551 { "Tswana", "", "tn", "tsn" },
552 { "Tsonga", "", "ts", "tso" },
553 { "Turkmen", "", "tk", "tuk" },
554 { "Turkish", "", "tr", "tur" },
555 { "Twi", "", "tw", "twi" },
556 { "Uighur", "", "ug", "uig" },
557 { "Ukrainian", "", "uk", "ukr" },
558 { "Urdu", "", "ur", "urd" },
559 { "Uzbek", "", "uz", "uzb" },
560 { "Venda", "", "ve", "ven" },
561 { "Vietnamese", "", "vi", "vie" },
562 { "Volapük", "", "vo", "vol" },
563 { "Welsh", "", "cy", "cym", "wel" },
564 { "Walloon", "", "wa", "wln" },
565 { "Wolof", "", "wo", "wol" },
566 { "Xhosa", "", "xh", "xho" },
567 { "Yiddish", "", "yi", "yid" },
568 { "Yoruba", "", "yo", "yor" },
569 { "Zhuang", "", "za", "zha" },
570 { "Zulu", "", "zu", "zul" },
571 {NULL, NULL, NULL, NULL}
573 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
575 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
578 del_tree(const gchar *name, gboolean del_top)
582 if (g_file_test(name, G_FILE_TEST_IS_DIR))
584 GDir *gdir = g_dir_open(name, 0, NULL);
585 file = g_dir_read_name(gdir);
589 path = g_strdup_printf("%s/%s", name, file);
590 del_tree(path, TRUE);
592 file = g_dir_read_name(gdir);
607 return hb_get_version(NULL);
612 signal_user_data_t *ud,
620 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
629 *step = ghb_settings_combo_double(ud->settings,
630 "VideoQualityGranularity");
631 if (*step == 0.2 || *step == 0.5)
633 else if (*step == 0.25)
638 case HB_VCODEC_FFMPEG:
646 case HB_VCODEC_THEORA:
665 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
669 const gchar *result = "";
671 str = ghb_value_string(gval);
672 for (ii = 0; ii < opts->count; ii++)
674 if (strcmp(opts->map[ii].shortOpt, str) == 0)
676 result = opts->map[ii].svalue;
685 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
691 str = ghb_value_string(gval);
692 for (ii = 0; ii < opts->count; ii++)
694 if (strcmp(opts->map[ii].shortOpt, str) == 0)
696 result = opts->map[ii].ivalue;
705 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
711 str = ghb_value_string(gval);
712 for (ii = 0; ii < opts->count; ii++)
714 if (strcmp(opts->map[ii].shortOpt, str) == 0)
716 result = opts->map[ii].ivalue;
725 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
729 const gchar *result = "";
731 str = ghb_value_string(gval);
732 for (ii = 0; ii < opts->count; ii++)
734 if (strcmp(opts->map[ii].shortOpt, str) == 0)
736 result = opts->map[ii].option;
745 lookup_mix_int(const GValue *mix)
752 str = ghb_value_string(mix);
753 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
755 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
757 result = hb_audio_mixdowns[ii].amixdown;
766 lookup_mix_option(const GValue *mix)
770 gchar *result = "None";
773 str = ghb_value_string(mix);
774 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
776 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
778 result = hb_audio_mixdowns[ii].human_readable_name;
787 lookup_video_rate_int(const GValue *vrate)
793 str = ghb_value_string(vrate);
794 for (ii = 0; ii < hb_video_rates_count; ii++)
796 if (strcmp(hb_video_rates[ii].string, str) == 0)
798 result = hb_video_rates[ii].rate;
803 // Default to "same as source"
808 lookup_video_rate_option(const GValue *vrate)
812 const gchar *result = "Same as source";
814 str = ghb_value_string(vrate);
815 for (ii = 0; ii < hb_video_rates_count; ii++)
817 if (strcmp(hb_video_rates[ii].string, str) == 0)
819 result = hb_video_rates[ii].string;
824 // Default to "same as source"
829 lookup_audio_rate_int(const GValue *rate)
835 // Coincidentally, the string "source" will return 0
836 // which is our flag to use "same as source"
837 str = ghb_value_string(rate);
838 for (ii = 0; ii < hb_audio_rates_count; ii++)
840 if (strcmp(hb_audio_rates[ii].string, str) == 0)
842 result = hb_audio_rates[ii].rate;
851 lookup_audio_rate_option(const GValue *rate)
855 const gchar *result = "Same as source";
857 // Coincidentally, the string "source" will return 0
858 // which is our flag to use "same as source"
859 str = ghb_value_string(rate);
860 for (ii = 0; ii < hb_audio_rates_count; ii++)
862 if (strcmp(hb_audio_rates[ii].string, str) == 0)
864 result = hb_audio_rates[ii].string;
873 lookup_audio_bitrate_int(const GValue *rate)
879 // Coincidentally, the string "source" will return 0
880 // which is our flag to use "same as source"
881 str = ghb_value_string(rate);
882 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
884 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
886 result = hb_audio_bitrates[ii].rate;
895 lookup_audio_bitrate_option(const GValue *rate)
899 const gchar *result = "Same as source";
901 // Coincidentally, the string "source" will return 0
902 // which is our flag to use "same as source"
903 str = ghb_value_string(rate);
904 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
906 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
908 result = hb_audio_bitrates[ii].string;
917 lookup_audio_lang_int(const GValue *rate)
923 // Coincidentally, the string "source" will return 0
924 // which is our flag to use "same as source"
925 str = ghb_value_string(rate);
926 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
928 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
939 lookup_audio_lang_option(const GValue *rate)
943 const gchar *result = "Same as source";
945 // Coincidentally, the string "source" will return 0
946 // which is our flag to use "same as source"
947 str = ghb_value_string(rate);
948 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
950 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
952 result = ghb_language_table[ii].eng_name;
961 get_acodec_value(gint val)
963 GValue *value = NULL;
966 for (ii = 0; ii < acodec_opts.count; ii++)
968 if ((int)acodec_opts.map[ii].ivalue == val)
970 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
978 get_amix_value(gint val)
980 GValue *value = NULL;
983 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
985 if (hb_audio_mixdowns[ii].amixdown == val)
987 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
994 // Handle for libhb. Gets set by ghb_backend_init()
995 static hb_handle_t * h_scan = NULL;
996 static hb_handle_t * h_queue = NULL;
998 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
1005 hb_get_tempory_directory(h_scan, dir);
1006 return g_strdup(dir);
1010 ghb_hb_cleanup(gboolean partial)
1014 hb_get_tempory_directory(h_scan, dir);
1015 del_tree(dir, !partial);
1019 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1027 titleindex = ghb_settings_combo_int(ud->settings, "title");
1033 hb_subtitle_t * sub;
1035 if (h_scan == NULL) return VOBSUB;
1036 list = hb_get_titles( h_scan );
1037 if( !hb_list_count( list ) )
1039 /* No valid title, stop right there */
1042 title = hb_list_item( list, titleindex );
1043 if (title == NULL) return VOBSUB; // Bad titleindex
1044 sub = hb_list_item( title->list_subtitle, track);
1052 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1055 const gchar * name = "Unknown";
1068 titleindex = ghb_settings_combo_int(ud->settings, "title");
1074 hb_subtitle_t * sub;
1078 list = hb_get_titles( h_scan );
1079 if( !hb_list_count( list ) )
1082 title = hb_list_item( list, titleindex );
1086 sub = hb_list_item( title->list_subtitle, track);
1089 switch (sub->source)
1110 ghb_get_title_number(gint titleindex)
1115 if (h_scan == NULL) return 1;
1116 list = hb_get_titles( h_scan );
1117 if( !hb_list_count( list ) )
1119 /* No valid title, stop right there */
1122 title = hb_list_item( list, titleindex );
1123 if (title == NULL) return 1; // Bad titleindex
1124 return title->index;
1127 static hb_audio_config_t*
1128 get_hb_audio(gint titleindex, gint track)
1132 hb_audio_config_t *audio = NULL;
1134 if (h_scan == NULL) return NULL;
1135 list = hb_get_titles( h_scan );
1136 if( !hb_list_count( list ) )
1138 /* No valid title, stop right there */
1141 title = hb_list_item( list, titleindex );
1142 if (title == NULL) return NULL; // Bad titleindex
1143 if (!hb_list_count(title->list_audio))
1147 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1152 search_rates(hb_rate_t *rates, gint rate, gint count)
1155 for (ii = 0; ii < count; ii++)
1157 if (rates[ii].rate == rate)
1163 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1165 static GtkListStore*
1166 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1169 GtkListStore *store;
1171 g_debug("get_combo_box_store() %s\n", name);
1172 // First modify the combobox model to allow greying out of options
1173 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1174 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1179 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1181 GtkListStore *store;
1184 store = get_combo_box_store(builder, name);
1185 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1187 gtk_list_store_set(store, &iter,
1194 ghb_grey_combo_options(GtkBuilder *builder)
1197 gint container, track, titleindex, acodec;
1198 hb_audio_config_t *audio = NULL;
1201 widget = GHB_WIDGET (builder, "title");
1202 gval = ghb_widget_value(widget);
1203 titleindex = ghb_lookup_combo_int("title", gval);
1204 ghb_value_free(gval);
1205 widget = GHB_WIDGET (builder, "AudioTrack");
1206 gval = ghb_widget_value(widget);
1207 track = ghb_lookup_combo_int("AudioTrack", gval);
1208 ghb_value_free(gval);
1209 audio = get_hb_audio(titleindex, track);
1210 widget = GHB_WIDGET (builder, "FileFormat");
1211 gval = ghb_widget_value(widget);
1212 container = ghb_lookup_combo_int("FileFormat", gval);
1213 ghb_value_free(gval);
1215 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1216 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1217 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1218 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1220 gboolean allow_dca = TRUE;
1221 allow_dca = (container != HB_MUX_MP4);
1223 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1225 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1227 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1229 if (audio && audio->in.codec != HB_ACODEC_AC3)
1231 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1233 if (audio && audio->in.codec != HB_ACODEC_DCA)
1235 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1237 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1239 widget = GHB_WIDGET (builder, "AudioEncoder");
1240 gval = ghb_widget_value(widget);
1241 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1242 ghb_value_free(gval);
1243 if (acodec != HB_ACODEC_AC3)
1245 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1247 if (container == HB_MUX_MP4)
1249 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1250 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1251 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1253 else if (container == HB_MUX_AVI)
1255 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1256 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1257 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1259 else if (container == HB_MUX_OGM)
1261 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1264 gboolean allow_mono = TRUE;
1265 gboolean allow_stereo = TRUE;
1266 gboolean allow_dolby = TRUE;
1267 gboolean allow_dpl2 = TRUE;
1268 gboolean allow_6ch = TRUE;
1272 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1273 (acodec != HB_ACODEC_LAME);
1274 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1276 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1278 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1279 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1280 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1281 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1283 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1284 (acodec != HB_ACODEC_LAME) &&
1285 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1286 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1288 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1289 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1290 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1291 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1292 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1296 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1298 hb_audio_config_t *audio = NULL;
1299 gboolean allow_mono = TRUE;
1300 gboolean allow_stereo = TRUE;
1301 gboolean allow_dolby = TRUE;
1302 gboolean allow_dpl2 = TRUE;
1303 gboolean allow_6ch = TRUE;
1305 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1307 // Audio codec pass-thru. No mixdown
1310 audio = get_hb_audio(titleindex, track);
1314 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1315 (acodec != HB_ACODEC_LAME);
1316 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1318 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1320 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1321 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1322 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1323 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1325 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1326 (acodec != HB_ACODEC_LAME) &&
1327 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1328 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1330 gboolean greater = FALSE;
1333 // If no mix is specified, select the best available.
1334 mix = HB_AMIXDOWN_6CH;
1336 if (mix == HB_AMIXDOWN_6CH)
1339 if (allow_6ch) return HB_AMIXDOWN_6CH;
1341 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1344 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1346 if (mix == HB_AMIXDOWN_DOLBY || greater)
1349 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1351 if (mix == HB_AMIXDOWN_STEREO || greater)
1354 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1356 if (mix == HB_AMIXDOWN_MONO || greater)
1359 if (allow_mono) return HB_AMIXDOWN_MONO;
1361 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1362 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1363 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1364 if (allow_6ch) return HB_AMIXDOWN_6CH;
1368 // Set up the model for the combo box
1370 init_combo_box(GtkBuilder *builder, const gchar *name)
1373 GtkListStore *store;
1374 GtkCellRenderer *cell;
1376 g_debug("init_combo_box() %s\n", name);
1377 // First modify the combobox model to allow greying out of options
1378 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1382 // 1 - String to display
1383 // 2 - bool indicating whether the entry is selectable (grey or not)
1384 // 3 - String that is used for presets
1385 // 4 - Int value determined by backend
1386 // 5 - String value determined by backend
1387 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1388 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1389 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1391 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1393 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1394 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1395 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1396 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1397 "text", 0, "sensitive", 1, NULL);
1400 { // Combo box entry
1401 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1406 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1409 GtkListStore *store;
1412 g_debug("audio_samplerate_opts_set ()\n");
1413 store = get_combo_box_store(builder, name);
1414 gtk_list_store_clear(store);
1415 // Add an item for "Same As Source"
1416 gtk_list_store_append(store, &iter);
1417 gtk_list_store_set(store, &iter,
1418 0, "Same as source",
1424 for (ii = 0; ii < count; ii++)
1426 gtk_list_store_append(store, &iter);
1427 gtk_list_store_set(store, &iter,
1428 0, rates[ii].string,
1430 2, rates[ii].string,
1431 3, (gdouble)rates[ii].rate,
1432 4, rates[ii].string,
1438 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1441 GtkListStore *store;
1444 g_debug("video_rate_opts_set ()\n");
1445 store = get_combo_box_store(builder, name);
1446 gtk_list_store_clear(store);
1447 // Add an item for "Same As Source"
1448 gtk_list_store_append(store, &iter);
1449 gtk_list_store_set(store, &iter,
1450 0, "Same as source",
1456 for (ii = 0; ii < count; ii++)
1460 if (strcmp(rates[ii].string, "23.976") == 0)
1462 desc = "(NTSC Film)";
1464 else if (strcmp(rates[ii].string, "25") == 0)
1466 desc = "(PAL Film/Video)";
1468 else if (strcmp(rates[ii].string, "29.97") == 0)
1470 desc = "(NTSC Video)";
1472 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1473 gtk_list_store_append(store, &iter);
1474 gtk_list_store_set(store, &iter,
1477 2, rates[ii].string,
1478 3, (gdouble)rates[ii].rate,
1479 4, rates[ii].string,
1486 mix_opts_set(GtkBuilder *builder, const gchar *name)
1489 GtkListStore *store;
1492 g_debug("mix_opts_set ()\n");
1493 store = get_combo_box_store(builder, name);
1494 gtk_list_store_clear(store);
1495 gtk_list_store_append(store, &iter);
1496 gtk_list_store_set(store, &iter,
1503 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1505 gtk_list_store_append(store, &iter);
1506 gtk_list_store_set(store, &iter,
1507 0, hb_audio_mixdowns[ii].human_readable_name,
1509 2, hb_audio_mixdowns[ii].short_name,
1510 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1511 4, hb_audio_mixdowns[ii].internal_name,
1517 language_opts_set(GtkBuilder *builder, const gchar *name)
1520 GtkListStore *store;
1523 g_debug("language_opts_set ()\n");
1524 store = get_combo_box_store(builder, name);
1525 gtk_list_store_clear(store);
1526 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1528 gtk_list_store_append(store, &iter);
1529 gtk_list_store_set(store, &iter,
1530 0, ghb_language_table[ii].eng_name,
1532 2, ghb_language_table[ii].iso639_2,
1534 4, ghb_language_table[ii].iso639_1,
1539 static gchar **titles = NULL;
1542 title_opts_set(GtkBuilder *builder, const gchar *name)
1545 GtkListStore *store;
1546 hb_list_t * list = NULL;
1547 hb_title_t * title = NULL;
1551 g_debug("title_opts_set ()\n");
1552 store = get_combo_box_store(builder, name);
1553 gtk_list_store_clear(store);
1556 list = hb_get_titles( h_scan );
1557 count = hb_list_count( list );
1558 if (count > 100) count = 100;
1560 if (titles) g_strfreev(titles);
1561 if (title_opts.map) g_free(title_opts.map);
1564 title_opts.count = count;
1565 title_opts.map = g_malloc(count*sizeof(options_map_t));
1566 titles = g_malloc((count+1) * sizeof(gchar*));
1570 title_opts.count = 1;
1571 title_opts.map = g_malloc(sizeof(options_map_t));
1576 // No titles. Fill in a default.
1577 gtk_list_store_append(store, &iter);
1578 gtk_list_store_set(store, &iter,
1585 title_opts.map[0].option = "No Titles";
1586 title_opts.map[0].shortOpt = "none";
1587 title_opts.map[0].ivalue = -1;
1588 title_opts.map[0].svalue = "none";
1591 for (ii = 0; ii < count; ii++)
1593 title = (hb_title_t*)hb_list_item(list, ii);
1594 if (title->duration != 0)
1596 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1597 title->index, title->hours, title->minutes, title->seconds);
1601 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1603 gtk_list_store_append(store, &iter);
1604 gtk_list_store_set(store, &iter,
1611 title_opts.map[ii].option = titles[ii];
1612 title_opts.map[ii].shortOpt = titles[ii];
1613 title_opts.map[ii].ivalue = ii;
1614 title_opts.map[ii].svalue = titles[ii];
1620 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1623 gboolean foundit = FALSE;
1625 if (gtk_tree_model_get_iter_first (store, iter))
1629 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1630 if (value == (int)ivalue)
1635 } while (gtk_tree_model_iter_next (store, iter));
1641 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1644 GtkListStore *store;
1645 hb_list_t * list = NULL;
1646 hb_title_t * title = NULL;
1647 hb_audio_config_t * audio;
1651 g_debug("audio_track_opts_set ()\n");
1652 store = get_combo_box_store(builder, name);
1653 gtk_list_store_clear(store);
1656 list = hb_get_titles( h_scan );
1657 title = (hb_title_t*)hb_list_item( list, titleindex );
1660 count = hb_list_count( title->list_audio );
1663 if (count > 100) count = 100;
1664 if (audio_track_opts.map) g_free(audio_track_opts.map);
1667 audio_track_opts.count = count;
1668 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1672 audio_track_opts.count = 1;
1673 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1677 // No audio. set some default
1678 gtk_list_store_append(store, &iter);
1679 gtk_list_store_set(store, &iter,
1686 audio_track_opts.map[0].option = "No Audio";
1687 audio_track_opts.map[0].shortOpt = "none";
1688 audio_track_opts.map[0].ivalue = -1;
1689 audio_track_opts.map[0].svalue = "none";
1692 index_str_init(count-1);
1693 for (ii = 0; ii < count; ii++)
1695 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1696 gtk_list_store_append(store, &iter);
1697 gtk_list_store_set(store, &iter,
1698 0, audio->lang.description,
1704 audio_track_opts.map[ii].option = audio->lang.description,
1705 audio_track_opts.map[ii].shortOpt = index_str[ii];
1706 audio_track_opts.map[ii].ivalue = ii;
1707 audio_track_opts.map[ii].svalue = index_str[ii];
1712 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1715 GtkListStore *store;
1716 hb_list_t * list = NULL;
1717 hb_title_t * title = NULL;
1718 hb_subtitle_t * subtitle;
1720 static char ** options = NULL;
1722 g_debug("subtitle_track_opts_set ()\n");
1723 store = get_combo_box_store(builder, name);
1724 gtk_list_store_clear(store);
1727 list = hb_get_titles( h_scan );
1728 title = (hb_title_t*)hb_list_item( list, titleindex );
1731 count = hb_list_count( title->list_subtitle );
1734 if (count > 100) count = 100;
1735 if (subtitle_opts.map) g_free(subtitle_opts.map);
1738 subtitle_opts.count = count+1;
1739 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1743 subtitle_opts.count = LANG_TABLE_SIZE+1;
1744 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1746 gtk_list_store_append(store, &iter);
1747 gtk_list_store_set(store, &iter,
1748 0, "Foreign Audio Search",
1754 subtitle_opts.map[0].option = "Foreign Audio Search";
1755 subtitle_opts.map[0].shortOpt = "-1";
1756 subtitle_opts.map[0].ivalue = -1;
1757 subtitle_opts.map[0].svalue = "auto";
1760 if (options != NULL)
1761 g_strfreev(options);
1762 options = g_malloc((count+1)*sizeof(gchar*));
1763 index_str_init(count-1);
1764 for (ii = 0; ii < count; ii++)
1766 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1767 // Skip subtitles that must be burned if there is already
1768 // a burned subtitle in the list
1769 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1770 subtitle_opts.map[ii+1].option = options[ii];
1771 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1772 subtitle_opts.map[ii+1].ivalue = ii;
1773 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1774 gtk_list_store_append(store, &iter);
1775 gtk_list_store_set(store, &iter,
1780 4, subtitle->iso639_2,
1783 options[count] = NULL;
1787 index_str_init(LANG_TABLE_SIZE-1);
1788 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1790 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1791 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1792 subtitle_opts.map[ii+1].ivalue = ii;
1793 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1794 gtk_list_store_append(store, &iter);
1795 gtk_list_store_set(store, &iter,
1796 0, ghb_language_table[ii].eng_name,
1800 4, ghb_language_table[ii].iso639_2,
1813 guint64 longest = 0;
1814 gint titleindex = 0;
1816 g_debug("ghb_longest_title ()\n");
1817 if (h_scan == NULL) return 0;
1818 list = hb_get_titles( h_scan );
1819 count = hb_list_count( list );
1820 if (count > 100) count = 100;
1821 for (ii = 0; ii < count; ii++)
1823 title = (hb_title_t*)hb_list_item(list, ii);
1824 if (title->duration > longest)
1827 longest = title->duration;
1834 ghb_get_source_audio_lang(gint titleindex, gint track)
1838 hb_audio_config_t * audio;
1841 g_debug("ghb_lookup_1st_audio_lang ()\n");
1844 list = hb_get_titles( h_scan );
1845 title = (hb_title_t*)hb_list_item( list, titleindex );
1848 if (hb_list_count( title->list_audio ) <= track)
1851 audio = hb_list_audio_config_item(title->list_audio, track);
1855 lang = g_strdup(audio->lang.iso639_2);
1860 ghb_find_audio_track(
1864 GHashTable *track_indices)
1868 hb_audio_config_t * audio;
1875 g_debug("find_audio_track ()\n");
1876 if (h_scan == NULL) return -1;
1877 list = hb_get_titles( h_scan );
1878 title = (hb_title_t*)hb_list_item( list, titleindex );
1881 count = hb_list_count( title->list_audio );
1883 if (count > 10) count = 10;
1884 used = g_hash_table_lookup(track_indices, &acodec);
1887 used = g_malloc0(count * sizeof(gboolean));
1888 g_hash_table_insert(track_indices, &acodec, used);
1890 // Try to find an item that matches the preferred language and
1891 // the passthru codec type
1892 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1894 for (ii = 0; ii < count; ii++)
1901 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1902 title->list_audio, ii );
1903 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1904 audio->in.channel_layout);
1905 // Find a track that is not visually impaired or dirctor's
1906 // commentary, and has the highest channel count.
1907 if ((audio->in.codec & acodec) &&
1908 (audio->lang.type < 2) &&
1909 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1910 (strcmp(lang, "und") == 0)))
1912 if (channels > max_chan)
1915 max_chan = channels;
1925 // Try to find an item that matches the preferred language
1926 for (ii = 0; ii < count; ii++)
1930 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1931 title->list_audio, ii );
1932 // Find a track that is not visually impaired or dirctor's commentary
1933 if ((audio->lang.type < 2) &&
1934 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1935 (strcmp(lang, "und") == 0)))
1946 // Try to fine an item that does not match the preferred language and
1947 // matches the passthru codec type
1948 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1950 for (ii = 0; ii < count; ii++)
1957 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1958 title->list_audio, ii );
1959 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1960 audio->in.channel_layout);
1961 // Find a track that is not visually impaired or dirctor's
1962 // commentary, and has the highest channel count.
1963 if ((audio->in.codec & acodec) &&
1964 (audio->lang.type < 2))
1966 if (channels > max_chan)
1969 max_chan = channels;
1979 // Try to fine an item that does not match the preferred language
1980 for (ii = 0; ii < count; ii++)
1984 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1985 title->list_audio, ii );
1986 // Find a track that is not visually impaired or dirctor's commentary
1987 if (audio->lang.type < 2)
1998 // Last ditch, anything goes
1999 for (ii = 0; ii < count; ii++)
2001 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2002 title->list_audio, ii );
2017 ghb_find_pref_subtitle_track(const gchar *lang)
2020 count = subtitle_opts.count;
2021 for (ii = 0; ii < count; ii++)
2023 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2025 return subtitle_opts.map[ii].ivalue;
2032 ghb_find_subtitle_track(
2035 GHashTable *track_indices)
2039 hb_subtitle_t * subtitle;
2043 g_debug("find_subtitle_track ()\n");
2044 if (strcmp(lang, "auto") == 0)
2046 if (h_scan == NULL) return -1;
2047 list = hb_get_titles( h_scan );
2048 title = (hb_title_t*)hb_list_item( list, titleindex );
2051 count = hb_list_count( title->list_subtitle );
2052 used = g_hash_table_lookup(track_indices, lang);
2055 used = g_malloc0(count * sizeof(gboolean));
2056 g_hash_table_insert(track_indices, g_strdup(lang), used);
2058 // Try to find an item that matches the preferred language
2059 for (ii = 0; ii < count; ii++)
2064 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2065 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2066 (strcmp(lang, "und") == 0))
2077 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2080 GtkListStore *store;
2083 g_debug("generic_opts_set ()\n");
2084 if (name == NULL || opts == NULL) return;
2085 store = get_combo_box_store(builder, name);
2086 gtk_list_store_clear(store);
2087 for (ii = 0; ii < opts->count; ii++)
2089 gtk_list_store_append(store, &iter);
2090 gtk_list_store_set(store, &iter,
2091 0, opts->map[ii].option,
2093 2, opts->map[ii].shortOpt,
2094 3, opts->map[ii].ivalue,
2095 4, opts->map[ii].svalue,
2101 find_combo_table(const gchar *name)
2105 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2107 if (strcmp(name, combo_name_map[ii].name) == 0)
2109 return combo_name_map[ii].opts;
2116 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2120 if (strcmp(name, "AudioBitrate") == 0)
2121 return lookup_audio_bitrate_int(gval);
2122 else if (strcmp(name, "AudioSamplerate") == 0)
2123 return lookup_audio_rate_int(gval);
2124 else if (strcmp(name, "VideoFramerate") == 0)
2125 return lookup_video_rate_int(gval);
2126 else if (strcmp(name, "AudioMixdown") == 0)
2127 return lookup_mix_int(gval);
2128 else if (strcmp(name, "PreferredLanguage") == 0)
2129 return lookup_audio_lang_int(gval);
2132 return lookup_generic_int(find_combo_table(name), gval);
2134 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2139 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2143 if (strcmp(name, "AudioBitrate") == 0)
2144 return lookup_audio_bitrate_int(gval);
2145 else if (strcmp(name, "AudioSamplerate") == 0)
2146 return lookup_audio_rate_int(gval);
2147 else if (strcmp(name, "VideoFramerate") == 0)
2148 return lookup_video_rate_int(gval);
2149 else if (strcmp(name, "AudioMixdown") == 0)
2150 return lookup_mix_int(gval);
2151 else if (strcmp(name, "PreferredLanguage") == 0)
2152 return lookup_audio_lang_int(gval);
2155 return lookup_generic_double(find_combo_table(name), gval);
2157 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2162 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2166 if (strcmp(name, "AudioBitrate") == 0)
2167 return lookup_audio_bitrate_option(gval);
2168 else if (strcmp(name, "AudioSamplerate") == 0)
2169 return lookup_audio_rate_option(gval);
2170 else if (strcmp(name, "VideoFramerate") == 0)
2171 return lookup_video_rate_option(gval);
2172 else if (strcmp(name, "AudioMixdown") == 0)
2173 return lookup_mix_option(gval);
2174 else if (strcmp(name, "PreferredLanguage") == 0)
2175 return lookup_audio_lang_option(gval);
2178 return lookup_generic_option(find_combo_table(name), gval);
2180 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2185 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2189 if (strcmp(name, "AudioBitrate") == 0)
2190 return lookup_audio_bitrate_option(gval);
2191 else if (strcmp(name, "AudioSamplerate") == 0)
2192 return lookup_audio_rate_option(gval);
2193 else if (strcmp(name, "VideoFramerate") == 0)
2194 return lookup_video_rate_option(gval);
2195 else if (strcmp(name, "AudioMixdown") == 0)
2196 return lookup_mix_option(gval);
2197 else if (strcmp(name, "PreferredLanguage") == 0)
2198 return lookup_audio_lang_option(gval);
2201 return lookup_generic_string(find_combo_table(name), gval);
2203 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2208 ghb_update_ui_combo_box(
2209 signal_user_data_t *ud,
2214 GtkComboBox *combo = NULL;
2216 gint handler_id = 0;
2220 g_debug("ghb_update_ui_combo_box() %s\n", name);
2221 // Clearing a combo box causes a rash of "changed" events, even when
2222 // the active item is -1 (inactive). To control things, I'm disabling
2223 // the event till things are settled down.
2224 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2225 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2228 // Valid signal id found. This should always succeed.
2229 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2230 signal_id, 0, 0, 0, 0);
2233 // This should also always succeed
2234 g_signal_handler_block ((gpointer)combo, handler_id);
2240 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2241 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2242 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2243 mix_opts_set(ud->builder, "AudioMixdown");
2244 language_opts_set(ud->builder, "PreferredLanguage");
2245 title_opts_set(ud->builder, "title");
2246 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2247 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2248 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2249 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2250 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2251 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2252 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2253 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2254 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2255 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2256 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2257 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2258 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2259 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2260 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2261 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2262 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2263 generic_opts_set(ud->builder, "x264_me", &me_opts);
2264 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2265 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2266 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2270 if (strcmp(name, "AudioBitrate") == 0)
2271 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2272 else if (strcmp(name, "AudioSamplerate") == 0)
2273 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2274 else if (strcmp(name, "VideoFramerate") == 0)
2275 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2276 else if (strcmp(name, "AudioMixdown") == 0)
2277 mix_opts_set(ud->builder, "AudioMixdown");
2278 else if (strcmp(name, "PreferredLanguage") == 0)
2279 language_opts_set(ud->builder, "PreferredLanguage");
2280 else if (strcmp(name, "title") == 0)
2281 title_opts_set(ud->builder, "title");
2282 else if (strcmp(name, "SubtitleTrack") == 0)
2283 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2284 else if (strcmp(name, "AudioTrack") == 0)
2285 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2287 generic_opts_set(ud->builder, name, find_combo_table(name));
2291 g_signal_handler_unblock ((gpointer)combo, handler_id);
2296 init_ui_combo_boxes(GtkBuilder *builder)
2300 init_combo_box(builder, "AudioBitrate");
2301 init_combo_box(builder, "AudioSamplerate");
2302 init_combo_box(builder, "VideoFramerate");
2303 init_combo_box(builder, "AudioMixdown");
2304 init_combo_box(builder, "PreferredLanguage");
2305 init_combo_box(builder, "title");
2306 init_combo_box(builder, "AudioTrack");
2307 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2309 init_combo_box(builder, combo_name_map[ii].name);
2313 static const char * turbo_opts =
2314 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2315 "no-fast-pskip=0:8x8dct=0";
2317 // Construct the x264 options string
2318 // The result is allocated, so someone must free it at some point.
2320 ghb_build_x264opts_string(GValue *settings)
2323 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2330 result = g_strdup("");
2336 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2340 hb_chapter_t * chapter;
2343 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2344 *hh = *mm = *ss = 0;
2345 if (h_scan == NULL) return;
2346 list = hb_get_titles( h_scan );
2347 title = (hb_title_t*)hb_list_item( list, ti );
2348 if (title == NULL) return;
2349 count = hb_list_count( title->list_chapter );
2350 if (ii >= count) return;
2351 chapter = hb_list_item(title->list_chapter, ii);
2352 if (chapter == NULL) return;
2353 *hh = chapter->hours;
2354 *mm = chapter->minutes;
2355 *ss = chapter->seconds;
2359 ghb_get_chapters(gint titleindex)
2363 hb_chapter_t * chapter;
2365 GValue *chapters = NULL;
2367 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2368 if (h_scan == NULL) return NULL;
2369 list = hb_get_titles( h_scan );
2370 title = (hb_title_t*)hb_list_item( list, titleindex );
2371 if (title == NULL) return NULL;
2372 count = hb_list_count( title->list_chapter );
2373 chapters = ghb_array_value_new(count);
2374 for (ii = 0; ii < count; ii++)
2376 chapter = hb_list_item(title->list_chapter, ii);
2377 if (chapter == NULL) break;
2378 if (chapter->title == NULL || chapter->title[0] == 0)
2381 str = g_strdup_printf ("Chapter %2d", ii+1);
2382 ghb_array_append(chapters, ghb_string_value_new(str));
2387 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2394 ghb_ac3_in_audio_list(const GValue *audio_list)
2398 count = ghb_array_len(audio_list);
2399 for (ii = 0; ii < count; ii++)
2404 asettings = ghb_array_get_nth(audio_list, ii);
2405 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2406 if (acodec & HB_ACODEC_AC3)
2413 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2416 GtkListStore *store;
2419 g_debug("audio_rate_opts_add ()\n");
2420 store = get_combo_box_store(builder, name);
2421 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2423 str = g_strdup_printf ("%d", rate);
2424 gtk_list_store_append(store, &iter);
2425 gtk_list_store_set(store, &iter,
2437 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2440 GtkListStore *store;
2442 gboolean done = FALSE;
2444 guint last = (guint)last_rate;
2446 g_debug("audio_bitrate_opts_clean ()\n");
2447 store = get_combo_box_store(builder, name);
2448 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2452 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2454 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2456 done = !gtk_list_store_remove(store, &iter);
2458 else if (ivalue > last)
2461 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2462 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2467 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2468 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2475 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2478 GtkListStore *store;
2481 g_debug("audio_bitrate_opts_set ()\n");
2482 store = get_combo_box_store(builder, name);
2483 gtk_list_store_clear(store);
2484 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2486 gtk_list_store_append(store, &iter);
2487 gtk_list_store_set(store, &iter,
2488 0, hb_audio_bitrates[ii].string,
2490 2, hb_audio_bitrates[ii].string,
2491 3, (gdouble)hb_audio_bitrates[ii].rate,
2492 4, hb_audio_bitrates[ii].string,
2498 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2500 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2504 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2506 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2509 static ghb_status_t hb_status;
2512 ghb_combo_init(signal_user_data_t *ud)
2514 // Set up the list model for the combos
2515 init_ui_combo_boxes(ud->builder);
2516 // Populate all the combos
2517 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2521 ghb_backend_init(gint debug)
2524 h_scan = hb_init( debug, 0 );
2525 h_queue = hb_init( debug, 0 );
2536 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2538 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2539 hb_status.scan.state |= GHB_STATE_SCANNING;
2540 // initialize count and cur to something that won't cause FPE
2541 // when computing progress
2542 hb_status.scan.title_count = 1;
2543 hb_status.scan.title_cur = 0;
2547 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2549 g_debug("ghb_backend_queue_scan()");
2550 hb_scan( h_queue, path, titlenum, 10, 0 );
2551 hb_status.queue.state |= GHB_STATE_SCANNING;
2555 ghb_get_scan_state()
2557 return hb_status.scan.state;
2561 ghb_get_queue_state()
2563 return hb_status.queue.state;
2567 ghb_clear_scan_state(gint state)
2569 hb_status.scan.state &= ~state;
2573 ghb_clear_queue_state(gint state)
2575 hb_status.queue.state &= ~state;
2579 ghb_set_scan_state(gint state)
2581 hb_status.scan.state |= state;
2585 ghb_set_queue_state(gint state)
2587 hb_status.queue.state |= state;
2591 ghb_get_status(ghb_status_t *status)
2593 memcpy(status, &hb_status, sizeof(ghb_status_t));
2602 if (h_scan == NULL) return;
2603 hb_get_state( h_scan, &s_scan );
2604 switch( s_scan.state )
2606 #define p s_scan.param.scanning
2607 case HB_STATE_SCANNING:
2609 hb_status.scan.state |= GHB_STATE_SCANNING;
2610 hb_status.scan.title_count = p.title_count;
2611 hb_status.scan.title_cur = p.title_cur;
2615 case HB_STATE_SCANDONE:
2617 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2618 hb_status.scan.state |= GHB_STATE_SCANDONE;
2621 #define p s_scan.param.working
2622 case HB_STATE_WORKING:
2623 hb_status.scan.state |= GHB_STATE_WORKING;
2624 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2625 hb_status.scan.job_cur = p.job_cur;
2626 hb_status.scan.job_count = p.job_count;
2627 hb_status.scan.progress = p.progress;
2628 hb_status.scan.rate_cur = p.rate_cur;
2629 hb_status.scan.rate_avg = p.rate_avg;
2630 hb_status.scan.hours = p.hours;
2631 hb_status.scan.minutes = p.minutes;
2632 hb_status.scan.seconds = p.seconds;
2633 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2637 case HB_STATE_PAUSED:
2638 hb_status.scan.state |= GHB_STATE_PAUSED;
2641 case HB_STATE_MUXING:
2643 hb_status.scan.state |= GHB_STATE_MUXING;
2646 #define p s_scan.param.workdone
2647 case HB_STATE_WORKDONE:
2651 hb_status.scan.state |= GHB_STATE_WORKDONE;
2652 hb_status.scan.state &= ~GHB_STATE_MUXING;
2653 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2654 hb_status.scan.state &= ~GHB_STATE_WORKING;
2658 hb_status.scan.error = GHB_ERROR_NONE;
2660 case HB_ERROR_CANCELED:
2661 hb_status.scan.error = GHB_ERROR_CANCELED;
2664 hb_status.scan.error = GHB_ERROR_FAIL;
2667 // Delete all remaining jobs of this encode.
2668 // An encode can be composed of multiple associated jobs.
2669 // When a job is stopped, libhb removes it from the job list,
2670 // but does not remove other jobs that may be associated with it.
2671 // Associated jobs are taged in the sequence id.
2672 while ((job = hb_job(h_scan, 0)) != NULL)
2673 hb_rem( h_scan, job );
2677 hb_get_state( h_queue, &s_queue );
2678 switch( s_queue.state )
2680 #define p s_queue.param.scanning
2681 case HB_STATE_SCANNING:
2683 hb_status.queue.state |= GHB_STATE_SCANNING;
2684 hb_status.queue.title_count = p.title_count;
2685 hb_status.queue.title_cur = p.title_cur;
2689 case HB_STATE_SCANDONE:
2691 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2692 hb_status.queue.state |= GHB_STATE_SCANDONE;
2695 #define p s_queue.param.working
2696 case HB_STATE_WORKING:
2697 hb_status.queue.state |= GHB_STATE_WORKING;
2698 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2699 hb_status.queue.job_cur = p.job_cur;
2700 hb_status.queue.job_count = p.job_count;
2701 hb_status.queue.progress = p.progress;
2702 hb_status.queue.rate_cur = p.rate_cur;
2703 hb_status.queue.rate_avg = p.rate_avg;
2704 hb_status.queue.hours = p.hours;
2705 hb_status.queue.minutes = p.minutes;
2706 hb_status.queue.seconds = p.seconds;
2707 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2711 case HB_STATE_PAUSED:
2712 hb_status.queue.state |= GHB_STATE_PAUSED;
2715 case HB_STATE_MUXING:
2717 hb_status.queue.state |= GHB_STATE_MUXING;
2720 #define p s_queue.param.workdone
2721 case HB_STATE_WORKDONE:
2725 hb_status.queue.state |= GHB_STATE_WORKDONE;
2726 hb_status.queue.state &= ~GHB_STATE_MUXING;
2727 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2728 hb_status.queue.state &= ~GHB_STATE_WORKING;
2732 hb_status.queue.error = GHB_ERROR_NONE;
2734 case HB_ERROR_CANCELED:
2735 hb_status.queue.error = GHB_ERROR_CANCELED;
2738 hb_status.queue.error = GHB_ERROR_FAIL;
2741 // Delete all remaining jobs of this encode.
2742 // An encode can be composed of multiple associated jobs.
2743 // When a job is stopped, libhb removes it from the job list,
2744 // but does not remove other jobs that may be associated with it.
2745 // Associated jobs are taged in the sequence id.
2746 while ((job = hb_job(h_queue, 0)) != NULL)
2747 hb_rem( h_queue, job );
2754 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2759 if (h_scan == NULL) return FALSE;
2760 list = hb_get_titles( h_scan );
2761 if( !hb_list_count( list ) )
2763 /* No valid title, stop right there */
2767 title = hb_list_item( list, titleindex );
2768 if (title == NULL) return FALSE; // Bad titleindex
2769 tinfo->width = title->width;
2770 tinfo->height = title->height;
2771 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2772 // Don't allow crop to 0
2773 if (title->crop[0] + title->crop[1] >= title->height)
2774 title->crop[0] = title->crop[1] = 0;
2775 if (title->crop[2] + title->crop[3] >= title->width)
2776 title->crop[2] = title->crop[3] = 0;
2777 tinfo->num_chapters = hb_list_count(title->list_chapter);
2778 tinfo->rate_base = title->rate_base;
2779 tinfo->rate = title->rate;
2780 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2781 title->width * title->pixel_aspect_width,
2782 title->height * title->pixel_aspect_height);
2783 tinfo->hours = title->hours;
2784 tinfo->minutes = title->minutes;
2785 tinfo->seconds = title->seconds;
2786 tinfo->duration = title->duration;
2788 tinfo->angle_count = title->angle_count;
2793 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2795 hb_audio_config_t *audio;
2797 audio = get_hb_audio(titleindex, audioindex);
2798 if (audio == NULL) return FALSE; // Bad audioindex
2799 ainfo->codec = audio->in.codec;
2800 ainfo->bitrate = audio->in.bitrate;
2801 ainfo->samplerate = audio->in.samplerate;
2806 ghb_audio_is_passthru(gint acodec)
2808 g_debug("ghb_audio_is_passthru () \n");
2809 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2813 ghb_get_default_acodec()
2815 return HB_ACODEC_FAAC;
2819 picture_settings_deps(signal_user_data_t *ud)
2821 gboolean autoscale, keep_aspect, enable_keep_aspect;
2822 gboolean enable_scale_width, enable_scale_height;
2823 gboolean enable_disp_width, enable_disp_height, enable_par;
2827 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2830 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2831 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2832 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2834 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2835 if (!enable_keep_aspect)
2837 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2839 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2840 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2842 enable_scale_width = !autoscale && (pic_par != 1);
2843 enable_scale_height = !autoscale && (pic_par != 1);
2844 enable_disp_width = (pic_par == 3) && !keep_aspect;
2845 enable_par = (pic_par == 3) && !keep_aspect;
2846 enable_disp_height = FALSE;
2848 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2849 gtk_widget_set_sensitive(widget, pic_par != 1);
2850 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2851 gtk_widget_set_sensitive(widget, pic_par != 1);
2852 widget = GHB_WIDGET(ud->builder, "scale_width");
2853 gtk_widget_set_sensitive(widget, enable_scale_width);
2854 widget = GHB_WIDGET(ud->builder, "scale_height");
2855 gtk_widget_set_sensitive(widget, enable_scale_height);
2856 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2857 gtk_widget_set_sensitive(widget, enable_disp_width);
2858 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2859 gtk_widget_set_sensitive(widget, enable_disp_height);
2860 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
2861 gtk_widget_set_sensitive(widget, enable_par);
2862 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
2863 gtk_widget_set_sensitive(widget, enable_par);
2864 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2865 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2866 widget = GHB_WIDGET(ud->builder, "autoscale");
2867 gtk_widget_set_sensitive(widget, pic_par != 1);
2871 ghb_set_scale(signal_user_data_t *ud, gint mode)
2876 gboolean keep_aspect;
2878 gboolean autocrop, autoscale, noscale;
2879 gint crop[4], width, height, par_width, par_height;
2880 gint crop_width, crop_height;
2881 gint aspect_n, aspect_d;
2882 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2883 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2888 gint max_height = 0;
2889 static gboolean busy = FALSE;
2891 g_debug("ghb_set_scale ()\n");
2892 if (h_scan == NULL) return;
2893 list = hb_get_titles( h_scan );
2894 if( !hb_list_count( list ) )
2896 /* No valid title, stop right there */
2901 titleindex = ghb_settings_combo_int(ud->settings, "title");
2902 title = hb_list_item( list, titleindex );
2903 if (title == NULL) return;
2905 if (job == NULL) return;
2907 picture_settings_deps(ud);
2912 // First configure widgets
2913 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2914 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2915 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2916 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2917 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2918 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2919 // alignment constraints rather than scaling to satisfy them.
2920 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2921 // Align dimensions to either 16 or 2 pixels
2922 // The scaler crashes if the dimensions are not divisible by 2
2923 // x264 also will not accept dims that are not multiple of 2
2927 keep_height = FALSE;
2929 // Step needs to be at least 2 because odd widths cause scaler crash
2931 widget = GHB_WIDGET (ud->builder, "scale_width");
2932 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2933 widget = GHB_WIDGET (ud->builder, "scale_height");
2934 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2937 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2938 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2939 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2940 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2941 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2942 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2943 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2944 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2948 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2949 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2950 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2951 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2952 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2953 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2954 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2955 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2957 ghb_title_info_t tinfo;
2958 ghb_get_title_info (&tinfo, titleindex);
2961 crop[0] = tinfo.crop[0];
2962 crop[1] = tinfo.crop[1];
2963 crop[2] = tinfo.crop[2];
2964 crop[3] = tinfo.crop[3];
2965 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2966 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2967 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2968 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2972 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2973 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2974 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2975 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2981 // Adjust the cropping to accomplish the desired width and height
2982 crop_width = tinfo.width - crop[2] - crop[3];
2983 crop_height = tinfo.height - crop[0] - crop[1];
2984 width = MOD_DOWN(crop_width, mod);
2985 height = MOD_DOWN(crop_height, mod);
2987 need1 = (crop_height - height) / 2;
2988 need2 = crop_height - height - need1;
2991 need1 = (crop_width - width) / 2;
2992 need2 = crop_width - width - need1;
2995 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2996 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2997 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2998 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3000 hb_reduce(&aspect_n, &aspect_d,
3001 title->width * title->pixel_aspect_width,
3002 title->height * title->pixel_aspect_height);
3003 crop_width = title->width - crop[2] - crop[3];
3004 crop_height = title->height - crop[0] - crop[1];
3008 height = crop_height;
3012 width = ghb_settings_get_int(ud->settings, "scale_width");
3013 height = ghb_settings_get_int(ud->settings, "scale_height");
3014 max_width = MOD_DOWN(
3015 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3016 max_height = MOD_DOWN(
3017 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3019 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3022 width = title->width - crop[2] - crop[3];
3024 height = title->height - crop[0] - crop[1];
3026 width = MOD_ROUND(width, mod);
3027 height = MOD_ROUND(height, mod);
3029 // Adjust dims according to max values
3031 height = MIN(height, max_height);
3033 width = MIN(width, max_width);
3037 job->anamorphic.mode = pic_par;
3038 // The scaler crashes if the dimensions are not divisible by 2
3039 // Align mod 2. And so does something in x264_encoder_headers()
3040 job->anamorphic.modulus = mod;
3041 job->anamorphic.par_width = title->pixel_aspect_width;
3042 job->anamorphic.par_height = title->pixel_aspect_height;
3043 job->anamorphic.dar_width = 0;
3044 job->anamorphic.dar_height = 0;
3046 if (keep_height && pic_par == 2)
3047 width = ((double)height * crop_width / crop_height) + 0.5;
3049 job->height = height;
3051 job->maxWidth = max_width;
3053 job->maxHeight = max_height;
3054 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3055 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3056 if (job->anamorphic.mode == 3 && !keep_aspect)
3058 job->anamorphic.keep_display_aspect = 0;
3059 if (mode & GHB_PIC_KEEP_PAR)
3061 job->anamorphic.par_width =
3062 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3063 job->anamorphic.par_height =
3064 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3068 job->anamorphic.dar_width =
3069 ghb_settings_get_int(ud->settings,
3070 "PictureDisplayWidth");
3071 job->anamorphic.dar_height =
3072 ghb_settings_get_int(ud->settings,
3073 "PictureDisplayHeight");
3078 job->anamorphic.keep_display_aspect = 1;
3080 hb_set_anamorphic_size( job, &width, &height,
3081 &par_width, &par_height );
3082 if (job->anamorphic.mode == 3 && !keep_aspect &&
3083 mode & GHB_PIC_KEEP_PAR)
3085 // hb_set_anamorphic_size reduces the par, which we
3086 // don't want in this case because the user is
3087 // explicitely specifying it.
3088 par_width = ghb_settings_get_int(ud->settings,
3090 par_height = ghb_settings_get_int(ud->settings,
3091 "PicturePARHeight");
3096 job->anamorphic.mode = pic_par;
3100 gint new_width, new_height;
3102 // Compute pixel aspect ration.
3103 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3104 // Must scale so that par becomes 1:1
3105 // Try to keep largest dimension
3106 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3107 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3109 if (max_width && new_width > max_width)
3111 height = new_height;
3113 else if (max_height && new_height > max_height)
3117 else if (keep_width)
3119 height = new_height;
3121 else if (keep_height)
3125 else if (width > new_width)
3127 height = new_height;
3133 g_debug("new w %d h %d\n", width, height);
3135 width = MOD_ROUND(width, mod);
3136 height = MOD_ROUND(height, mod);
3138 height = MIN(height, max_height);
3140 width = MIN(width, max_width);
3141 par_width = par_height = 1;
3143 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3144 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3146 gint disp_width, dar_width, dar_height;
3149 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3150 hb_reduce(&dar_width, &dar_height, disp_width, height);
3152 gint iaspect = dar_width * 9 / dar_height;
3153 if (dar_width > 2 * dar_height)
3155 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3157 else if (iaspect <= 16 && iaspect >= 15)
3159 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3161 else if (iaspect <= 12 && iaspect >= 11)
3163 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3167 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3169 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3171 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3172 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3173 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3174 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3179 set_preview_job_settings(hb_job_t *job, GValue *settings)
3181 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3182 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3183 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3184 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3186 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3187 job->anamorphic.modulus =
3188 ghb_settings_combo_int(settings, "PictureModulus");
3189 job->width = ghb_settings_get_int(settings, "scale_width");
3190 job->height = ghb_settings_get_int(settings, "scale_height");
3191 if (ghb_settings_get_boolean(settings, "show_crop"))
3193 gdouble xscale = (gdouble)job->width /
3194 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3195 gdouble yscale = (gdouble)job->height /
3196 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3198 job->width += xscale * (job->crop[2] + job->crop[3]);
3199 job->height += yscale * (job->crop[0] + job->crop[1]);
3204 job->anamorphic.modulus = 2;
3207 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3208 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3209 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3211 gboolean keep_aspect;
3212 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3213 if (job->anamorphic.mode)
3215 job->anamorphic.par_width = job->title->pixel_aspect_width;
3216 job->anamorphic.par_height = job->title->pixel_aspect_height;
3217 job->anamorphic.dar_width = 0;
3218 job->anamorphic.dar_height = 0;
3220 if (job->anamorphic.mode == 3 && !keep_aspect)
3222 job->anamorphic.keep_display_aspect = 0;
3223 job->anamorphic.par_width =
3224 ghb_settings_get_int(settings, "PicturePARWidth");
3225 job->anamorphic.par_height =
3226 ghb_settings_get_int(settings, "PicturePARHeight");
3230 job->anamorphic.keep_display_aspect = 1;
3236 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3243 if (h_scan == NULL) return 1500;
3244 list = hb_get_titles( h_scan );
3245 title = hb_list_item( list, titleindex );
3246 if (title == NULL) return 1500;
3248 if (job == NULL) return 1500;
3249 size = ghb_settings_get_int(settings, "VideoTargetSize");
3250 return hb_calc_bitrate( job, size );
3254 ghb_validate_filter_string(const gchar *str, gint max_fields)
3260 if (str == NULL || *str == 0) return TRUE;
3263 val = g_strtod(str, &end);
3265 { // Found a numeric value
3267 // negative max_fields means infinate
3268 if (max_fields >= 0 && fields > max_fields) return FALSE;
3282 ghb_validate_filters(signal_user_data_t *ud)
3289 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3292 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3293 if (!ghb_validate_filter_string(str, 4))
3295 message = g_strdup_printf(
3296 "Invalid Deinterlace Settings:\n\n%s\n",
3298 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3306 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3309 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3310 if (!ghb_validate_filter_string(str, 6))
3312 message = g_strdup_printf(
3313 "Invalid Detelecine Settings:\n\n%s\n",
3315 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3323 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3326 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3327 if (!ghb_validate_filter_string(str, 7))
3329 message = g_strdup_printf(
3330 "Invalid Decomb Settings:\n\n%s\n",
3332 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3340 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3343 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3344 if (!ghb_validate_filter_string(str, 4))
3346 message = g_strdup_printf(
3347 "Invalid Denoise Settings:\n\n%s\n",
3349 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3360 ghb_validate_video(signal_user_data_t *ud)
3365 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3366 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3367 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3368 (vcodec == HB_VCODEC_THEORA))
3370 // mp4|avi/theora combination is not supported.
3371 message = g_strdup_printf(
3372 "Theora is not supported in the MP4 and AVI containers.\n\n"
3373 "You should choose a different video codec or container.\n"
3374 "If you continue, FFMPEG will be chosen for you.");
3375 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3381 vcodec = HB_VCODEC_FFMPEG;
3382 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3388 ghb_validate_subtitles(signal_user_data_t *ud)
3394 if (h_scan == NULL) return FALSE;
3395 list = hb_get_titles( h_scan );
3396 if( !hb_list_count( list ) )
3398 /* No valid title, stop right there */
3399 g_message("No title found.\n");
3405 titleindex = ghb_settings_combo_int(ud->settings, "title");
3406 title = hb_list_item( list, titleindex );
3407 if (title == NULL) return FALSE;
3408 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3410 const GValue *slist, *settings;
3411 gint count, ii, track, source;
3412 gboolean burned, one_burned = FALSE;
3414 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3415 count = ghb_array_len(slist);
3416 for (ii = 0; ii < count; ii++)
3418 settings = ghb_array_get_nth(slist, ii);
3419 track = ghb_settings_combo_int(settings, "SubtitleTrack");
3420 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3421 source = ghb_subtitle_track_source(ud, track);
3422 if (burned && one_burned)
3424 // MP4 can only handle burned vobsubs. make sure there isn't
3425 // already something burned in the list
3426 message = g_strdup_printf(
3427 "Only one subtitle may be burned into the video.\n\n"
3428 "You should change your subtitle selections.\n"
3429 "If you continue, some subtitles will be lost.");
3430 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3442 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3444 // MP4 can only handle burned vobsubs. make sure there isn't
3445 // already something burned in the list
3446 message = g_strdup_printf(
3447 "Your chosen container does not support soft bitmap subtitles.\n\n"
3448 "You should change your subtitle selections.\n"
3449 "If you continue, some subtitles will be lost.");
3450 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3463 ghb_validate_audio(signal_user_data_t *ud)
3470 if (h_scan == NULL) return FALSE;
3471 list = hb_get_titles( h_scan );
3472 if( !hb_list_count( list ) )
3474 /* No valid title, stop right there */
3475 g_message("No title found.\n");
3481 titleindex = ghb_settings_combo_int(ud->settings, "title");
3482 title = hb_list_item( list, titleindex );
3483 if (title == NULL) return FALSE;
3484 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3486 const GValue *audio_list;
3489 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3490 count = ghb_array_len(audio_list);
3491 for (ii = 0; ii < count; ii++)
3494 hb_audio_config_t *taudio;
3496 asettings = ghb_array_get_nth(audio_list, ii);
3497 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3498 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3499 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3500 title->list_audio, track );
3501 if (!(taudio->in.codec & codec) &&
3502 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3504 // Not supported. AC3 is passthrough only, so input must be AC3
3505 message = g_strdup_printf(
3506 "The source does not support Pass-Thru.\n\n"
3507 "You should choose a different audio codec.\n"
3508 "If you continue, one will be chosen for you.");
3509 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3515 if (mux == HB_MUX_AVI)
3517 codec = HB_ACODEC_LAME;
3521 codec = HB_ACODEC_FAAC;
3523 value = get_acodec_value(codec);
3524 ghb_settings_take_value(asettings, "AudioEncoder", value);
3526 gchar *a_unsup = NULL;
3527 gchar *mux_s = NULL;
3528 if (mux == HB_MUX_MP4)
3531 // mp4/mp3|vorbis combination is not supported.
3532 if (codec == HB_ACODEC_LAME)
3535 codec = HB_ACODEC_FAAC;
3537 if (codec == HB_ACODEC_VORBIS)
3540 codec = HB_ACODEC_FAAC;
3542 if (codec == HB_ACODEC_DCA)
3545 codec = HB_ACODEC_FAAC;
3548 else if (mux == HB_MUX_AVI)
3551 // avi/faac|vorbis combination is not supported.
3552 if (codec == HB_ACODEC_FAAC)
3555 codec = HB_ACODEC_LAME;
3557 if (codec == HB_ACODEC_VORBIS)
3560 codec = HB_ACODEC_LAME;
3563 else if (mux == HB_MUX_OGM)
3566 // avi/faac|vorbis combination is not supported.
3567 if (codec == HB_ACODEC_FAAC)
3570 codec = HB_ACODEC_VORBIS;
3572 if (codec == HB_ACODEC_AC3)
3575 codec = HB_ACODEC_VORBIS;
3577 if (codec == HB_ACODEC_DCA)
3580 codec = HB_ACODEC_VORBIS;
3585 message = g_strdup_printf(
3586 "%s is not supported in the %s container.\n\n"
3587 "You should choose a different audio codec.\n"
3588 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3589 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3595 value = get_acodec_value(codec);
3596 ghb_settings_take_value(asettings, "AudioEncoder", value);
3598 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3599 gboolean allow_mono = TRUE;
3600 gboolean allow_stereo = TRUE;
3601 gboolean allow_dolby = TRUE;
3602 gboolean allow_dpl2 = TRUE;
3603 gboolean allow_6ch = TRUE;
3605 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3606 (codec != HB_ACODEC_LAME);
3607 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3609 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3611 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3612 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3613 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3614 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3616 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3617 (codec != HB_ACODEC_LAME) &&
3618 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3619 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3621 gchar *mix_unsup = NULL;
3622 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3626 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3628 mix_unsup = "stereo";
3630 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3632 mix_unsup = "Dolby";
3634 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3636 mix_unsup = "Dolby Pro Logic II";
3638 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3640 mix_unsup = "6 Channel";
3644 message = g_strdup_printf(
3645 "The source audio does not support %s mixdown.\n\n"
3646 "You should choose a different mixdown.\n"
3647 "If you continue, one will be chosen for you.", mix_unsup);
3648 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3654 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3655 value = get_amix_value(mix);
3656 ghb_settings_take_value(asettings, "AudioMixdown", value);
3663 ghb_validate_vquality(GValue *settings)
3669 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3670 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3672 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3673 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3677 case HB_VCODEC_X264:
3683 case HB_VCODEC_FFMPEG:
3689 case HB_VCODEC_THEORA:
3701 if (vquality < min || vquality > max)
3703 message = g_strdup_printf(
3704 "Interesting video quality choise: %d\n\n"
3705 "Typical values range from %d to %d.\n"
3706 "Are you sure you wish to use this setting?",
3707 (gint)vquality, min, max);
3708 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3709 "Cancel", "Continue"))
3721 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3726 static gchar *x264opts;
3728 gboolean tweaks = FALSE;
3729 gchar *detel_str = NULL;
3730 gchar *decomb_str = NULL;
3731 gchar *deint_str = NULL;
3732 gchar *deblock_str = NULL;
3733 gchar *denoise_str = NULL;
3734 gchar *dest_str = NULL;
3736 g_debug("add_job()\n");
3737 if (h == NULL) return;
3738 list = hb_get_titles( h );
3739 if( !hb_list_count( list ) )
3741 /* No valid title, stop right there */
3745 title = hb_list_item( list, titleindex );
3746 if (title == NULL) return;
3748 /* Set job settings */
3750 if (job == NULL) return;
3752 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3753 if (job->start_at_preview)
3755 job->seek_points = ghb_settings_get_int(js, "preview_count");
3756 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3759 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3760 job->mux = ghb_settings_combo_int(js, "FileFormat");
3761 if (job->mux == HB_MUX_MP4)
3763 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3764 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3768 job->largeFileSize = FALSE;
3769 job->mp4_optimize = FALSE;
3771 if (!job->start_at_preview)
3773 gint chapter_start, chapter_end;
3774 chapter_start = ghb_settings_get_int(js, "start_chapter");
3775 chapter_end = ghb_settings_get_int(js, "end_chapter");
3776 gint num_chapters = hb_list_count(title->list_chapter);
3777 job->chapter_start = MIN( num_chapters, chapter_start );
3778 job->chapter_end = MAX( job->chapter_start, chapter_end );
3780 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3781 if (job->chapter_start == job->chapter_end)
3782 job->chapter_markers = 0;
3783 if ( job->chapter_markers )
3790 chapters = ghb_settings_get_value(js, "chapter_list");
3791 count = ghb_array_len(chapters);
3792 for(chap = chapter_start; chap <= chapter_end; chap++)
3794 hb_chapter_t * chapter_s;
3800 chapter = ghb_array_get_nth(chapters, chap-1);
3801 name = ghb_value_string(chapter);
3805 name = g_strdup_printf ("Chapter %2d", chap);
3807 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3808 strncpy(chapter_s->title, name, 1023);
3809 chapter_s->title[1023] = '\0';
3814 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3815 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3816 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3817 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3820 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3821 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3823 job->deinterlace = (deint != 0) ? 1 : 0;
3825 job->deinterlace = 0;
3826 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3828 gboolean keep_aspect;
3829 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
3830 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3831 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3832 if (job->anamorphic.mode)
3834 job->anamorphic.par_width = title->pixel_aspect_width;
3835 job->anamorphic.par_height = title->pixel_aspect_height;
3836 job->anamorphic.dar_width = 0;
3837 job->anamorphic.dar_height = 0;
3839 if (job->anamorphic.mode == 3 && !keep_aspect)
3841 job->anamorphic.keep_display_aspect = 0;
3842 job->anamorphic.par_width =
3843 ghb_settings_get_int(js, "PicturePARWidth");
3844 job->anamorphic.par_height =
3845 ghb_settings_get_int(js, "PicturePARHeight");
3849 job->anamorphic.keep_display_aspect = 1;
3853 /* Add selected filters */
3854 job->filters = hb_list_init();
3855 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3860 if (detel_opts.map[detel].svalue != NULL)
3861 detel_str = g_strdup(detel_opts.map[detel].svalue);
3864 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3865 hb_filter_detelecine.settings = detel_str;
3866 hb_list_add( job->filters, &hb_filter_detelecine );
3872 if (decomb_opts.map[decomb].svalue != NULL)
3873 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3876 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3877 hb_filter_decomb.settings = decomb_str;
3878 hb_list_add( job->filters, &hb_filter_decomb );
3880 if( job->deinterlace )
3884 if (deint_opts.map[deint].svalue != NULL)
3885 deint_str = g_strdup(deint_opts.map[deint].svalue);
3888 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3889 hb_filter_deinterlace.settings = deint_str;
3890 hb_list_add( job->filters, &hb_filter_deinterlace );
3892 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3895 deblock_str = g_strdup_printf("%d", deblock);
3896 hb_filter_deblock.settings = deblock_str;
3897 hb_list_add( job->filters, &hb_filter_deblock );
3899 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3904 if (denoise_opts.map[denoise].svalue != NULL)
3905 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3908 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3909 hb_filter_denoise.settings = denoise_str;
3910 hb_list_add( job->filters, &hb_filter_denoise );
3912 job->width = ghb_settings_get_int(js, "scale_width");
3913 job->height = ghb_settings_get_int(js, "scale_height");
3915 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3916 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3917 (job->vcodec == HB_VCODEC_THEORA))
3919 // mp4|avi/theora combination is not supported.
3920 job->vcodec = HB_VCODEC_FFMPEG;
3922 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3924 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3926 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3929 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3930 job->vquality = vquality;
3933 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3935 job->vquality = -1.0;
3936 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3939 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3942 job->vrate = title->rate;
3943 job->vrate_base = title->rate_base;
3948 job->vrate = 27000000;
3949 job->vrate_base = vrate;
3953 // AVI container does not support variable frame rate.
3954 // OGM supports variable frame rate, but bases all timing on
3955 // DTS, which breaks when b-frames are used since it is
3956 // impossible to reconstruct PTS from DTS when the framerate
3958 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3963 const GValue *audio_list;
3967 audio_list = ghb_settings_get_value(js, "audio_list");
3968 count = ghb_array_len(audio_list);
3969 for (ii = 0; ii < count; ii++)
3972 hb_audio_config_t audio;
3973 hb_audio_config_t *taudio;
3975 hb_audio_config_init(&audio);
3976 asettings = ghb_array_get_nth(audio_list, ii);
3977 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3978 audio.out.track = tcount;
3979 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3980 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3981 title->list_audio, audio.in.track );
3982 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3984 if (!(taudio->in.codec & audio.out.codec))
3986 // Not supported. AC3 is passthrough only, so input must be AC3
3987 if (job->mux == HB_MUX_AVI)
3989 audio.out.codec = HB_ACODEC_LAME;
3993 audio.out.codec = HB_ACODEC_FAAC;
3998 audio.out.codec &= taudio->in.codec;
4001 if ((job->mux == HB_MUX_MP4) &&
4002 ((audio.out.codec == HB_ACODEC_LAME) ||
4003 (audio.out.codec == HB_ACODEC_VORBIS)))
4005 // mp4/mp3|vorbis combination is not supported.
4006 audio.out.codec = HB_ACODEC_FAAC;
4008 if ((job->mux == HB_MUX_AVI) &&
4009 ((audio.out.codec == HB_ACODEC_FAAC) ||
4010 (audio.out.codec == HB_ACODEC_VORBIS)))
4012 // avi/faac|vorbis combination is not supported.
4013 audio.out.codec = HB_ACODEC_LAME;
4015 if ((job->mux == HB_MUX_OGM) &&
4016 ((audio.out.codec == HB_ACODEC_FAAC) ||
4017 (audio.out.codec == HB_ACODEC_AC3) ||
4018 (audio.out.codec == HB_ACODEC_DCA)))
4020 // ogm/faac|ac3 combination is not supported.
4021 audio.out.codec = HB_ACODEC_VORBIS;
4023 audio.out.dynamic_range_compression =
4024 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4025 if (audio.out.dynamic_range_compression < 1.0)
4026 audio.out.dynamic_range_compression = 0.0;
4028 // It would be better if this were done in libhb for us, but its not yet.
4029 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
4031 audio.out.mixdown = 0;
4035 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4036 // Make sure the mixdown is valid and pick a new one if not.
4037 audio.out.mixdown = ghb_get_best_mix(titleindex,
4038 audio.in.track, audio.out.codec, audio.out.mixdown);
4040 ghb_settings_combo_int(asettings, "AudioBitrate");
4041 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4042 if (srate == 0) // 0 is same as source
4043 audio.out.samplerate = taudio->in.samplerate;
4045 audio.out.samplerate = srate;
4048 // Add it to the jobs audio list
4049 hb_audio_add( job, &audio );
4052 // I was tempted to move this up with the reset of the video quality
4053 // settings, but I suspect the settings above need to be made
4054 // first in order for hb_calc_bitrate to be accurate.
4055 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4059 size = ghb_settings_get_int(js, "VideoTargetSize");
4060 job->vbitrate = hb_calc_bitrate( job, size );
4061 job->vquality = -1.0;
4064 dest_str = ghb_settings_get_string(js, "destination");
4065 job->file = dest_str;
4066 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
4068 const GValue *subtitle_list;
4070 gboolean force, burned, def, one_burned = FALSE;
4072 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4073 count = ghb_array_len(subtitle_list);
4074 for (ii = 0; ii < count; ii++)
4078 ssettings = ghb_array_get_nth(subtitle_list, ii);
4080 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4081 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4082 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4083 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4087 if (!burned && job->mux == HB_MUX_MKV)
4089 job->select_subtitle_config.dest = PASSTHRUSUB;
4091 else if (!burned && job->mux == HB_MUX_MP4)
4093 // Skip any non-burned vobsubs when output is mp4
4098 // Only allow one subtitle to be burned into the video
4101 job->select_subtitle_config.dest = RENDERSUB;
4104 job->select_subtitle_config.force = force;
4105 job->select_subtitle_config.default_track = def;
4106 job->indepth_scan = 1;
4108 else if (subtitle >= 0)
4110 hb_subtitle_t * subt;
4111 hb_subtitle_config_t sub_config;
4113 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4114 sub_config = subt->config;
4117 if (!burned && job->mux == HB_MUX_MKV &&
4118 subt->format == PICTURESUB)
4120 sub_config.dest = PASSTHRUSUB;
4122 else if (!burned && job->mux == HB_MUX_MP4 &&
4123 subt->format == PICTURESUB)
4125 // Skip any non-burned vobsubs when output is mp4
4128 else if ( burned && subt->format == PICTURESUB )
4130 // Only allow one subtitle to be burned into the video
4135 sub_config.force = force;
4136 sub_config.default_track = def;
4137 hb_subtitle_add( job, &sub_config, subtitle );
4142 // TODO: libhb holds onto a reference to the x264opts and is not
4143 // finished with it until encoding the job is done. But I can't
4144 // find a way to get at the job before it is removed in order to
4145 // free up the memory I am allocating here.
4146 // The short story is THIS LEAKS.
4147 x264opts = ghb_build_x264opts_string(js);
4149 if( *x264opts == '\0' )
4155 if (job->indepth_scan == 1)
4157 // Subtitle scan. Look for subtitle matching audio language
4160 * When subtitle scan is enabled do a fast pre-scan job
4161 * which will determine which subtitles to enable, if any.
4164 job->indepth_scan = 1;
4165 job->x264opts = NULL;
4168 * Add the pre-scan job
4170 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4174 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4175 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4178 * If subtitle_scan is enabled then only turn it on
4179 * for the second pass and then off again for the
4183 job->indepth_scan = 0;
4186 * If turbo options have been selected then append them
4187 * to the x264opts now (size includes one ':' and the '\0')
4189 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4191 gchar *tmp_x264opts;
4195 badapt = ghb_lookup_badapt(x264opts);
4198 extra_opts = g_strdup_printf("%s", turbo_opts);
4202 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4207 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4212 * No x264opts to modify, but apply the turbo options
4213 * anyway as they may be modifying defaults
4215 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4219 job->x264opts = tmp_x264opts;
4223 job->x264opts = x264opts;
4225 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4227 //if (job->x264opts != NULL)
4228 // g_free(job->x264opts);
4232 * On the second pass we turn off subtitle scan so that we
4233 * can actually encode using any subtitles that were auto
4234 * selected in the first pass (using the whacky select-subtitle
4235 * attribute of the job).
4237 job->indepth_scan = 0;
4238 job->x264opts = x264opts;
4239 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4241 //if (job->x264opts != NULL)
4242 // g_free(job->x264opts);
4246 job->x264opts = x264opts;
4247 job->indepth_scan = 0;
4249 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4251 //if (job->x264opts != NULL)
4252 // g_free(job->x264opts);
4255 // clean up audio list
4256 gint num_audio_tracks = hb_list_count(job->list_audio);
4257 for(ii = 0; ii < num_audio_tracks; ii++)
4259 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4260 hb_list_rem(job->list_audio, audio);
4264 // clean up subtitle list
4265 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4266 for(ii = 0; ii < num_subtitle_tracks; ii++)
4268 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4269 hb_list_rem(job->list_subtitle, subtitle);
4273 if (detel_str) g_free(detel_str);
4274 if (decomb_str) g_free(decomb_str);
4275 if (deint_str) g_free(deint_str);
4276 if (deblock_str) g_free(deblock_str);
4277 if (denoise_str) g_free(denoise_str);
4278 if (dest_str) g_free(dest_str);
4282 ghb_add_job(GValue *js, gint unique_id)
4284 // Since I'm doing a scan of the single title I want just prior
4285 // to adding the job, there is only the one title to choose from.
4286 add_job(h_queue, js, unique_id, 0);
4290 ghb_add_live_job(GValue *js, gint unique_id)
4292 // Since I'm doing a scan of the single title I want just prior
4293 // to adding the job, there is only the one title to choose from.
4294 gint titleindex = ghb_settings_combo_int(js, "title");
4295 add_job(h_scan, js, unique_id, titleindex);
4299 ghb_remove_job(gint unique_id)
4304 // Multiples passes all get the same id
4306 // Go backwards through list, so reordering doesn't screw me.
4307 ii = hb_count(h_queue) - 1;
4308 while ((job = hb_job(h_queue, ii--)) != NULL)
4310 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4311 hb_rem(h_queue, job);
4318 hb_start( h_queue );
4328 ghb_start_live_encode()
4334 ghb_stop_live_encode()
4343 hb_get_state2( h_queue, &s );
4345 if( s.state == HB_STATE_PAUSED )
4347 hb_resume( h_queue );
4351 hb_pause( h_queue );
4366 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4369 gint channels = gdk_pixbuf_get_n_channels (pb);
4370 gint stride = gdk_pixbuf_get_rowstride (pb);
4372 for (jj = 0; jj < width; jj++)
4374 dst = pixels + y * stride + (x+jj) * channels;
4375 for (ii = 0; ii < len; ii++)
4396 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4399 gint channels = gdk_pixbuf_get_n_channels (pb);
4400 gint stride = gdk_pixbuf_get_rowstride (pb);
4402 for (jj = 0; jj < width; jj++)
4404 dst = pixels + (y+jj) * stride + x * channels;
4405 for (ii = 0; ii < len; ii++)
4426 gint line_width = 8;
4433 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4438 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4440 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4446 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4448 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4454 ghb_get_preview_image(
4457 signal_user_data_t *ud,
4465 settings = ud->settings;
4466 list = hb_get_titles( h_scan );
4467 if( !hb_list_count( list ) )
4469 /* No valid title, stop right there */
4472 title = hb_list_item( list, titleindex );
4473 if (title == NULL) return NULL;
4474 if (title->job == NULL) return NULL;
4475 set_preview_job_settings(title->job, settings);
4477 // hb_get_preview doesn't compensate for anamorphic, so lets
4478 // calculate scale factors
4479 gint width, height, par_width = 1, par_height = 1;
4480 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4483 hb_set_anamorphic_size( title->job, &width, &height,
4484 &par_width, &par_height );
4487 // Make sure we have a big enough buffer to receive the image from libhb
4488 gint dstWidth = title->job->width;
4489 gint dstHeight= title->job->height;
4491 static guint8 *buffer = NULL;
4492 static gint bufferSize = 0;
4495 newSize = dstWidth * dstHeight * 4;
4496 if( bufferSize < newSize )
4498 bufferSize = newSize;
4499 buffer = (guint8*) g_realloc( buffer, bufferSize );
4501 hb_get_preview( h_scan, title, index, buffer );
4503 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4504 // libhb's format something suitable.
4506 // The image data returned by hb_get_preview is 4 bytes per pixel,
4507 // BGRA format. Alpha is ignored.
4509 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4510 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4512 guint32 *src = (guint32*)buffer;
4513 guint8 *dst = pixels;
4516 gint channels = gdk_pixbuf_get_n_channels (preview);
4517 gint stride = gdk_pixbuf_get_rowstride (preview);
4520 for (ii = 0; ii < dstHeight; ii++)
4523 for (jj = 0; jj < dstWidth; jj++)
4525 tmp[0] = src[0] >> 16;
4526 tmp[1] = src[0] >> 8;
4527 tmp[2] = src[0] >> 0;
4533 gint w = ghb_settings_get_int(settings, "scale_width");
4534 gint h = ghb_settings_get_int(settings, "scale_height");
4535 ghb_par_scale(ud, &w, &h, par_width, par_height);
4537 gint c0, c1, c2, c3;
4538 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4539 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4540 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4541 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4543 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4544 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4546 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4549 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4553 gint orig_w, orig_h;
4556 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4560 ss = gdk_screen_get_default();
4561 s_w = gdk_screen_get_width(ss);
4562 s_h = gdk_screen_get_height(ss);
4566 if (dstWidth > s_w * factor / 100)
4568 dstWidth = s_w * factor / 100;
4569 dstHeight = dstHeight * dstWidth / orig_w;
4571 if (dstHeight > s_h * factor / 100)
4573 dstHeight = s_h * factor / 100;
4574 dstWidth = dstWidth * dstHeight / orig_h;
4576 xscale *= (gdouble)dstWidth / orig_w;
4577 yscale *= (gdouble)dstHeight / orig_h;
4578 w *= (gdouble)dstWidth / orig_w;
4579 h *= (gdouble)dstHeight / orig_h;
4581 GdkPixbuf *scaled_preview;
4582 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4583 if (ghb_settings_get_boolean(settings, "show_crop"))
4590 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4592 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4594 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4596 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4598 g_object_unref (preview);
4599 return scaled_preview;
4603 sanitize_volname(gchar *name)
4628 ghb_dvd_volname(const gchar *device)
4631 name = hb_dvd_name((gchar*)device);
4632 if (name != NULL && name[0] != 0)
4634 name = g_strdup(name);
4635 sanitize_volname(name);