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
28 #include "hbversion.h"
30 #include <glib/gstdio.h>
31 #include "hb-backend.h"
33 #include "callbacks.h"
41 const gchar *shortOpt;
52 static const gchar *index_str[] =
67 static options_map_t d_logging_opts[] =
73 combo_opts_t logging_opts =
75 sizeof(d_logging_opts)/sizeof(options_map_t),
79 static options_map_t d_vqual_granularity_opts[] =
81 {"0.2", "0.2", 0.2, "0.2"},
82 {"0.25", "0.25", 0.25, "0.25"},
83 {"0.5", "0.5", 0.5, "0.5"},
86 combo_opts_t vqual_granularity_opts =
88 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
89 d_vqual_granularity_opts
92 static options_map_t d_container_opts[] =
94 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
95 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
96 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
97 {"AVI", "avi", HB_MUX_AVI, "avi"},
98 {"OGM", "ogm", HB_MUX_OGM, "ogm"},
100 combo_opts_t container_opts =
102 sizeof(d_container_opts)/sizeof(options_map_t),
106 static options_map_t d_detel_opts[] =
108 {"None", "none", 0, ""},
109 {"Custom", "custom", 1, ""},
110 {"Default","default",2, NULL},
112 combo_opts_t detel_opts =
114 sizeof(d_detel_opts)/sizeof(options_map_t),
118 static options_map_t d_decomb_opts[] =
120 {"None", "none", 0, ""},
121 {"Custom", "custom", 1, ""},
122 {"Default","default",2, NULL},
124 combo_opts_t decomb_opts =
126 sizeof(d_decomb_opts)/sizeof(options_map_t),
130 static options_map_t d_deint_opts[] =
132 {"None", "none", 0, ""},
133 {"Custom", "custom", 1, ""},
134 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
135 {"Slow", "slow", 3, "2:-1:-1:0:1"},
136 {"Slower", "slower", 4, "0:-1:-1:0:1"},
138 combo_opts_t deint_opts =
140 sizeof(d_deint_opts)/sizeof(options_map_t),
144 static options_map_t d_denoise_opts[] =
146 {"None", "none", 0, ""},
147 {"Custom", "custom", 1, ""},
148 {"Weak", "weak", 2, "2:1:2:3"},
149 {"Medium", "medium", 3, "3:2:2:3"},
150 {"Strong", "strong", 4, "7:7:5:5"},
152 combo_opts_t denoise_opts =
154 sizeof(d_denoise_opts)/sizeof(options_map_t),
158 static options_map_t d_vcodec_opts[] =
160 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
161 {"MPEG-4 (XviD)", "xvid", HB_VCODEC_XVID, ""},
162 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
163 {"Theora", "theora", HB_VCODEC_THEORA, ""},
165 combo_opts_t vcodec_opts =
167 sizeof(d_vcodec_opts)/sizeof(options_map_t),
171 static options_map_t d_acodec_opts[] =
173 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
174 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
175 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
176 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
177 // {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
179 combo_opts_t acodec_opts =
181 sizeof(d_acodec_opts)/sizeof(options_map_t),
185 static options_map_t d_direct_opts[] =
187 {"None", "none", 0, "none"},
188 {"Spatial", "spatial", 1, "spatial"},
189 {"Temporal", "temporal", 2, "temporal"},
190 {"Automatic", "auto", 3, "auto"},
192 combo_opts_t direct_opts =
194 sizeof(d_direct_opts)/sizeof(options_map_t),
198 static options_map_t d_badapt_opts[] =
200 {"Off", "0", 0, "0"},
201 {"Faster", "1", 1, "1"},
202 {"More Effecient", "2", 2, "2"},
204 combo_opts_t badapt_opts =
206 sizeof(d_badapt_opts)/sizeof(options_map_t),
210 static options_map_t d_me_opts[] =
212 {"Diamond", "dia", 0, "dia"},
213 {"Hexagon", "hex", 1, "hex"},
214 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
215 {"Exhaustive", "esa", 3, "esa"},
216 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
218 combo_opts_t me_opts =
220 sizeof(d_me_opts)/sizeof(options_map_t),
224 static options_map_t d_subme_opts[] =
236 combo_opts_t subme_opts =
238 sizeof(d_subme_opts)/sizeof(options_map_t),
242 static options_map_t d_analyse_opts[] =
244 {"Some", "some", 0, "some"},
245 {"None", "none", 1, "none"},
246 {"All", "all", 2, "all"},
247 {"Custom", "custom", 3, "all"},
249 combo_opts_t analyse_opts =
251 sizeof(d_analyse_opts)/sizeof(options_map_t),
255 static options_map_t d_trellis_opts[] =
257 {"Disabled", "0", 0, "0"},
258 {"Final Macro Block", "1", 1, "1"},
259 {"Always", "2", 2, "2"},
261 combo_opts_t trellis_opts =
263 sizeof(d_trellis_opts)/sizeof(options_map_t),
267 combo_opts_t subtitle_opts =
273 combo_opts_t title_opts =
279 combo_opts_t audio_track_opts =
291 combo_name_map_t combo_name_map[] =
293 {"LoggingLevel", &logging_opts},
294 {"VideoQualityGranularity", &vqual_granularity_opts},
295 {"FileFormat", &container_opts},
296 {"PictureDeinterlace", &deint_opts},
297 {"PictureDecomb", &decomb_opts},
298 {"PictureDetelecine", &detel_opts},
299 {"PictureDenoise", &denoise_opts},
300 {"VideoEncoder", &vcodec_opts},
301 {"AudioEncoder", &acodec_opts},
302 {"x264_direct", &direct_opts},
303 {"x264_b_adapt", &badapt_opts},
304 {"x264_me", &me_opts},
305 {"x264_subme", &subme_opts},
306 {"x264_analyse", &analyse_opts},
307 {"x264_trellis", &trellis_opts},
308 {"Subtitles", &subtitle_opts},
309 {"title", &title_opts},
310 {"AudioTrack", &audio_track_opts},
315 typedef struct iso639_lang_t
317 char * eng_name; /* Description in English */
318 char * native_name; /* Description in native language */
319 char * iso639_1; /* ISO-639-1 (2 characters) code */
320 char * iso639_2; /* ISO-639-2/t (3 character) code */
321 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
325 const iso639_lang_t ghb_language_table[] =
327 { "Any", "", "zz", "und" },
328 { "Afar", "", "aa", "aar" },
329 { "Abkhazian", "", "ab", "abk" },
330 { "Afrikaans", "", "af", "afr" },
331 { "Akan", "", "ak", "aka" },
332 { "Albanian", "", "sq", "sqi", "alb" },
333 { "Amharic", "", "am", "amh" },
334 { "Arabic", "", "ar", "ara" },
335 { "Aragonese", "", "an", "arg" },
336 { "Armenian", "", "hy", "hye", "arm" },
337 { "Assamese", "", "as", "asm" },
338 { "Avaric", "", "av", "ava" },
339 { "Avestan", "", "ae", "ave" },
340 { "Aymara", "", "ay", "aym" },
341 { "Azerbaijani", "", "az", "aze" },
342 { "Bashkir", "", "ba", "bak" },
343 { "Bambara", "", "bm", "bam" },
344 { "Basque", "", "eu", "eus", "baq" },
345 { "Belarusian", "", "be", "bel" },
346 { "Bengali", "", "bn", "ben" },
347 { "Bihari", "", "bh", "bih" },
348 { "Bislama", "", "bi", "bis" },
349 { "Bosnian", "", "bs", "bos" },
350 { "Breton", "", "br", "bre" },
351 { "Bulgarian", "", "bg", "bul" },
352 { "Burmese", "", "my", "mya", "bur" },
353 { "Catalan", "", "ca", "cat" },
354 { "Chamorro", "", "ch", "cha" },
355 { "Chechen", "", "ce", "che" },
356 { "Chinese", "", "zh", "zho", "chi" },
357 { "Church Slavic", "", "cu", "chu" },
358 { "Chuvash", "", "cv", "chv" },
359 { "Cornish", "", "kw", "cor" },
360 { "Corsican", "", "co", "cos" },
361 { "Cree", "", "cr", "cre" },
362 { "Czech", "", "cs", "ces", "cze" },
363 { "Danish", "Dansk", "da", "dan" },
364 { "Divehi", "", "dv", "div" },
365 { "Dutch", "Nederlands", "nl", "nld", "dut" },
366 { "Dzongkha", "", "dz", "dzo" },
367 { "English", "English", "en", "eng" },
368 { "Esperanto", "", "eo", "epo" },
369 { "Estonian", "", "et", "est" },
370 { "Ewe", "", "ee", "ewe" },
371 { "Faroese", "", "fo", "fao" },
372 { "Fijian", "", "fj", "fij" },
373 { "Finnish", "Suomi", "fi", "fin" },
374 { "French", "Francais", "fr", "fra", "fre" },
375 { "Western Frisian", "", "fy", "fry" },
376 { "Fulah", "", "ff", "ful" },
377 { "Georgian", "", "ka", "kat", "geo" },
378 { "German", "Deutsch", "de", "deu", "ger" },
379 { "Gaelic (Scots)", "", "gd", "gla" },
380 { "Irish", "", "ga", "gle" },
381 { "Galician", "", "gl", "glg" },
382 { "Manx", "", "gv", "glv" },
383 { "Greek, Modern", "", "el", "ell", "gre" },
384 { "Guarani", "", "gn", "grn" },
385 { "Gujarati", "", "gu", "guj" },
386 { "Haitian", "", "ht", "hat" },
387 { "Hausa", "", "ha", "hau" },
388 { "Hebrew", "", "he", "heb" },
389 { "Herero", "", "hz", "her" },
390 { "Hindi", "", "hi", "hin" },
391 { "Hiri Motu", "", "ho", "hmo" },
392 { "Hungarian", "Magyar", "hu", "hun" },
393 { "Igbo", "", "ig", "ibo" },
394 { "Icelandic", "Islenska", "is", "isl", "ice" },
395 { "Ido", "", "io", "ido" },
396 { "Sichuan Yi", "", "ii", "iii" },
397 { "Inuktitut", "", "iu", "iku" },
398 { "Interlingue", "", "ie", "ile" },
399 { "Interlingua", "", "ia", "ina" },
400 { "Indonesian", "", "id", "ind" },
401 { "Inupiaq", "", "ik", "ipk" },
402 { "Italian", "Italiano", "it", "ita" },
403 { "Javanese", "", "jv", "jav" },
404 { "Japanese", "", "ja", "jpn" },
405 { "Kalaallisut", "", "kl", "kal" },
406 { "Kannada", "", "kn", "kan" },
407 { "Kashmiri", "", "ks", "kas" },
408 { "Kanuri", "", "kr", "kau" },
409 { "Kazakh", "", "kk", "kaz" },
410 { "Central Khmer", "", "km", "khm" },
411 { "Kikuyu", "", "ki", "kik" },
412 { "Kinyarwanda", "", "rw", "kin" },
413 { "Kirghiz", "", "ky", "kir" },
414 { "Komi", "", "kv", "kom" },
415 { "Kongo", "", "kg", "kon" },
416 { "Korean", "", "ko", "kor" },
417 { "Kuanyama", "", "kj", "kua" },
418 { "Kurdish", "", "ku", "kur" },
419 { "Lao", "", "lo", "lao" },
420 { "Latin", "", "la", "lat" },
421 { "Latvian", "", "lv", "lav" },
422 { "Limburgan", "", "li", "lim" },
423 { "Lingala", "", "ln", "lin" },
424 { "Lithuanian", "", "lt", "lit" },
425 { "Luxembourgish", "", "lb", "ltz" },
426 { "Luba-Katanga", "", "lu", "lub" },
427 { "Ganda", "", "lg", "lug" },
428 { "Macedonian", "", "mk", "mkd", "mac" },
429 { "Marshallese", "", "mh", "mah" },
430 { "Malayalam", "", "ml", "mal" },
431 { "Maori", "", "mi", "mri", "mao" },
432 { "Marathi", "", "mr", "mar" },
433 { "Malay", "", "ms", "msa", "msa" },
434 { "Malagasy", "", "mg", "mlg" },
435 { "Maltese", "", "mt", "mlt" },
436 { "Moldavian", "", "mo", "mol" },
437 { "Mongolian", "", "mn", "mon" },
438 { "Nauru", "", "na", "nau" },
439 { "Navajo", "", "nv", "nav" },
440 { "Ndebele, South", "", "nr", "nbl" },
441 { "Ndebele, North", "", "nd", "nde" },
442 { "Ndonga", "", "ng", "ndo" },
443 { "Nepali", "", "ne", "nep" },
444 { "Norwegian Nynorsk", "", "nn", "nno" },
445 { "Norwegian Bokmål", "", "nb", "nob" },
446 { "Norwegian", "Norsk", "no", "nor" },
447 { "Chichewa; Nyanja", "", "ny", "nya" },
448 { "Occitan", "", "oc", "oci" },
449 { "Ojibwa", "", "oj", "oji" },
450 { "Oriya", "", "or", "ori" },
451 { "Oromo", "", "om", "orm" },
452 { "Ossetian", "", "os", "oss" },
453 { "Panjabi", "", "pa", "pan" },
454 { "Persian", "", "fa", "fas", "per" },
455 { "Pali", "", "pi", "pli" },
456 { "Polish", "", "pl", "pol" },
457 { "Portuguese", "Portugues", "pt", "por" },
458 { "Pushto", "", "ps", "pus" },
459 { "Quechua", "", "qu", "que" },
460 { "Romansh", "", "rm", "roh" },
461 { "Romanian", "", "ro", "ron", "rum" },
462 { "Rundi", "", "rn", "run" },
463 { "Russian", "", "ru", "rus" },
464 { "Sango", "", "sg", "sag" },
465 { "Sanskrit", "", "sa", "san" },
466 { "Serbian", "", "sr", "srp", "scc" },
467 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
468 { "Sinhala", "", "si", "sin" },
469 { "Slovak", "", "sk", "slk", "slo" },
470 { "Slovenian", "", "sl", "slv" },
471 { "Northern Sami", "", "se", "sme" },
472 { "Samoan", "", "sm", "smo" },
473 { "Shona", "", "sn", "sna" },
474 { "Sindhi", "", "sd", "snd" },
475 { "Somali", "", "so", "som" },
476 { "Sotho, Southern", "", "st", "sot" },
477 { "Spanish", "Espanol", "es", "spa" },
478 { "Sardinian", "", "sc", "srd" },
479 { "Swati", "", "ss", "ssw" },
480 { "Sundanese", "", "su", "sun" },
481 { "Swahili", "", "sw", "swa" },
482 { "Swedish", "Svenska", "sv", "swe" },
483 { "Tahitian", "", "ty", "tah" },
484 { "Tamil", "", "ta", "tam" },
485 { "Tatar", "", "tt", "tat" },
486 { "Telugu", "", "te", "tel" },
487 { "Tajik", "", "tg", "tgk" },
488 { "Tagalog", "", "tl", "tgl" },
489 { "Thai", "", "th", "tha" },
490 { "Tibetan", "", "bo", "bod", "tib" },
491 { "Tigrinya", "", "ti", "tir" },
492 { "Tonga", "", "to", "ton" },
493 { "Tswana", "", "tn", "tsn" },
494 { "Tsonga", "", "ts", "tso" },
495 { "Turkmen", "", "tk", "tuk" },
496 { "Turkish", "", "tr", "tur" },
497 { "Twi", "", "tw", "twi" },
498 { "Uighur", "", "ug", "uig" },
499 { "Ukrainian", "", "uk", "ukr" },
500 { "Urdu", "", "ur", "urd" },
501 { "Uzbek", "", "uz", "uzb" },
502 { "Venda", "", "ve", "ven" },
503 { "Vietnamese", "", "vi", "vie" },
504 { "Volapük", "", "vo", "vol" },
505 { "Welsh", "", "cy", "cym", "wel" },
506 { "Walloon", "", "wa", "wln" },
507 { "Wolof", "", "wo", "wol" },
508 { "Xhosa", "", "xh", "xho" },
509 { "Yiddish", "", "yi", "yid" },
510 { "Yoruba", "", "yo", "yor" },
511 { "Zhuang", "", "za", "zha" },
512 { "Zulu", "", "zu", "zul" },
513 {NULL, NULL, NULL, NULL}
515 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
517 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
520 del_tree(const gchar *name, gboolean del_top)
524 if (g_file_test(name, G_FILE_TEST_IS_DIR))
526 GDir *gdir = g_dir_open(name, 0, NULL);
527 file = g_dir_read_name(gdir);
531 path = g_strdup_printf("%s/%s", name, file);
532 del_tree(path, TRUE);
534 file = g_dir_read_name(gdir);
554 signal_user_data_t *ud,
562 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
571 *step = ghb_settings_combo_double(ud->settings,
572 "VideoQualityGranularity");
573 if (*step == 0.2 || *step == 0.5)
575 else if (*step == 0.25)
581 case HB_VCODEC_FFMPEG:
589 case HB_VCODEC_THEORA:
608 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
614 str = ghb_value_string(gval);
615 for (ii = 0; ii < opts->count; ii++)
617 if (strcmp(opts->map[ii].shortOpt, str) == 0)
619 result = opts->map[ii].ivalue;
628 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
634 str = ghb_value_string(gval);
635 for (ii = 0; ii < opts->count; ii++)
637 if (strcmp(opts->map[ii].shortOpt, str) == 0)
639 result = opts->map[ii].ivalue;
648 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
652 const gchar *result = "";
654 str = ghb_value_string(gval);
655 for (ii = 0; ii < opts->count; ii++)
657 if (strcmp(opts->map[ii].shortOpt, str) == 0)
659 result = opts->map[ii].option;
668 lookup_mix_int(const GValue *mix)
675 str = ghb_value_string(mix);
676 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
678 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
680 result = hb_audio_mixdowns[ii].amixdown;
689 lookup_mix_option(const GValue *mix)
693 gchar *result = "None";
696 str = ghb_value_string(mix);
697 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
699 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
701 result = hb_audio_mixdowns[ii].human_readable_name;
710 lookup_video_rate_int(const GValue *vrate)
716 str = ghb_value_string(vrate);
717 for (ii = 0; ii < hb_video_rates_count; ii++)
719 if (strcmp(hb_video_rates[ii].string, str) == 0)
721 result = hb_video_rates[ii].rate;
726 // Default to "same as source"
731 lookup_video_rate_option(const GValue *vrate)
735 const gchar *result = "Same as source";
737 str = ghb_value_string(vrate);
738 for (ii = 0; ii < hb_video_rates_count; ii++)
740 if (strcmp(hb_video_rates[ii].string, str) == 0)
742 result = hb_video_rates[ii].string;
747 // Default to "same as source"
752 lookup_audio_rate_int(const GValue *rate)
758 // Coincidentally, the string "source" will return 0
759 // which is our flag to use "same as source"
760 str = ghb_value_string(rate);
761 for (ii = 0; ii < hb_audio_rates_count; ii++)
763 if (strcmp(hb_audio_rates[ii].string, str) == 0)
765 result = hb_audio_rates[ii].rate;
774 lookup_audio_rate_option(const GValue *rate)
778 const gchar *result = "Same as source";
780 // Coincidentally, the string "source" will return 0
781 // which is our flag to use "same as source"
782 str = ghb_value_string(rate);
783 for (ii = 0; ii < hb_audio_rates_count; ii++)
785 if (strcmp(hb_audio_rates[ii].string, str) == 0)
787 result = hb_audio_rates[ii].string;
796 lookup_audio_bitrate_int(const GValue *rate)
802 // Coincidentally, the string "source" will return 0
803 // which is our flag to use "same as source"
804 str = ghb_value_string(rate);
805 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
807 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
809 result = hb_audio_bitrates[ii].rate;
818 lookup_audio_bitrate_option(const GValue *rate)
822 const gchar *result = "Same as source";
824 // Coincidentally, the string "source" will return 0
825 // which is our flag to use "same as source"
826 str = ghb_value_string(rate);
827 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
829 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
831 result = hb_audio_bitrates[ii].string;
840 lookup_audio_lang_int(const GValue *rate)
846 // Coincidentally, the string "source" will return 0
847 // which is our flag to use "same as source"
848 str = ghb_value_string(rate);
849 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
851 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
862 lookup_audio_lang_option(const GValue *rate)
866 const gchar *result = "Same as source";
868 // Coincidentally, the string "source" will return 0
869 // which is our flag to use "same as source"
870 str = ghb_value_string(rate);
871 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
873 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
875 result = ghb_language_table[ii].eng_name;
884 get_acodec_value(gint val)
886 GValue *value = NULL;
889 for (ii = 0; ii < acodec_opts.count; ii++)
891 if ((int)acodec_opts.map[ii].ivalue == val)
893 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
902 get_abitrate_value(gint val)
904 GValue *value = NULL;
907 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
909 if (hb_audio_bitrates[ii].rate == val)
911 value = ghb_string_value_new(hb_audio_bitrates[ii].string);
920 get_amix_value(gint val)
922 GValue *value = NULL;
925 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
927 if (hb_audio_mixdowns[ii].amixdown == val)
929 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
936 // Handle for libhb. Gets set by ghb_backend_init()
937 static hb_handle_t * h_scan = NULL;
938 static hb_handle_t * h_queue = NULL;
940 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
947 hb_get_tempory_directory(h_scan, dir);
948 return g_strdup(dir);
952 ghb_hb_cleanup(gboolean partial)
956 hb_get_tempory_directory(h_scan, dir);
957 del_tree(dir, !partial);
961 ghb_get_title_number(gint titleindex)
966 if (h_scan == NULL) return 1;
967 list = hb_get_titles( h_scan );
968 if( !hb_list_count( list ) )
970 /* No valid title, stop right there */
973 title = hb_list_item( list, titleindex );
974 if (title == NULL) return 1; // Bad titleindex
978 static hb_audio_config_t*
979 get_hb_audio(gint titleindex, gint track)
983 hb_audio_config_t *audio = NULL;
985 if (h_scan == NULL) return NULL;
986 list = hb_get_titles( h_scan );
987 if( !hb_list_count( list ) )
989 /* No valid title, stop right there */
992 title = hb_list_item( list, titleindex );
993 if (title == NULL) return NULL; // Bad titleindex
994 if (!hb_list_count(title->list_audio))
998 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1003 search_rates(hb_rate_t *rates, gint rate, gint count)
1006 for (ii = 0; ii < count; ii++)
1008 if (rates[ii].rate == rate)
1014 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1016 static GtkListStore*
1017 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1020 GtkListStore *store;
1022 g_debug("get_combo_box_store() %s\n", name);
1023 // First modify the combobox model to allow greying out of options
1024 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1025 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1030 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1032 GtkListStore *store;
1035 store = get_combo_box_store(builder, name);
1036 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1038 gtk_list_store_set(store, &iter,
1045 ghb_grey_combo_options(GtkBuilder *builder)
1048 gint container, track, titleindex, acodec;
1049 hb_audio_config_t *audio = NULL;
1052 widget = GHB_WIDGET (builder, "title");
1053 gval = ghb_widget_value(widget);
1054 titleindex = ghb_lookup_combo_int("title", gval);
1055 ghb_value_free(gval);
1056 widget = GHB_WIDGET (builder, "AudioTrack");
1057 gval = ghb_widget_value(widget);
1058 track = ghb_lookup_combo_int("AudioTrack", gval);
1059 ghb_value_free(gval);
1060 audio = get_hb_audio(titleindex, track);
1061 widget = GHB_WIDGET (builder, "FileFormat");
1062 gval = ghb_widget_value(widget);
1063 container = ghb_lookup_combo_int("FileFormat", gval);
1064 ghb_value_free(gval);
1066 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1067 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1068 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1069 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1071 gboolean allow_ac3 = TRUE;
1072 allow_ac3 = (container != HB_MUX_OGM);
1076 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1077 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1081 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1082 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1084 if (audio && audio->in.codec != HB_ACODEC_AC3)
1086 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1088 if (audio && audio->in.codec != HB_ACODEC_DCA)
1090 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1092 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1094 widget = GHB_WIDGET (builder, "AudioEncoder");
1095 gval = ghb_widget_value(widget);
1096 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1097 ghb_value_free(gval);
1098 if (acodec != HB_ACODEC_AC3)
1100 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1102 if (container == HB_MUX_MP4)
1104 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1105 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1106 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1108 else if (container == HB_MUX_AVI)
1110 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1111 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1112 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1114 else if (container == HB_MUX_OGM)
1116 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1119 gboolean allow_mono = TRUE;
1120 gboolean allow_stereo = TRUE;
1121 gboolean allow_dolby = TRUE;
1122 gboolean allow_dpl2 = TRUE;
1123 gboolean allow_6ch = TRUE;
1127 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1128 (acodec != HB_ACODEC_LAME);
1129 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1131 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1133 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1134 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1135 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1136 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1138 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1139 (acodec != HB_ACODEC_LAME) &&
1140 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1141 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1143 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1144 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1145 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1146 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1147 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1151 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1153 hb_audio_config_t *audio = NULL;
1154 gboolean allow_mono = TRUE;
1155 gboolean allow_stereo = TRUE;
1156 gboolean allow_dolby = TRUE;
1157 gboolean allow_dpl2 = TRUE;
1158 gboolean allow_6ch = TRUE;
1160 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1162 // Audio codec pass-thru. No mixdown
1165 audio = get_hb_audio(titleindex, track);
1169 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1170 (acodec != HB_ACODEC_LAME);
1171 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1173 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1175 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1176 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1177 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1178 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1180 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1181 (acodec != HB_ACODEC_LAME) &&
1182 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1183 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1185 gboolean greater = FALSE;
1188 // If no mix is specified, select the best available.
1189 mix = HB_AMIXDOWN_6CH;
1191 if (mix == HB_AMIXDOWN_6CH)
1194 if (allow_6ch) return HB_AMIXDOWN_6CH;
1196 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1199 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1201 if (mix == HB_AMIXDOWN_DOLBY || greater)
1204 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1206 if (mix == HB_AMIXDOWN_STEREO || greater)
1209 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1211 if (mix == HB_AMIXDOWN_MONO || greater)
1214 if (allow_mono) return HB_AMIXDOWN_MONO;
1216 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1217 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1218 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1219 if (allow_6ch) return HB_AMIXDOWN_6CH;
1223 // Set up the model for the combo box
1225 init_combo_box(GtkBuilder *builder, const gchar *name)
1228 GtkListStore *store;
1229 GtkCellRenderer *cell;
1231 g_debug("init_combo_box() %s\n", name);
1232 // First modify the combobox model to allow greying out of options
1233 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1235 // 1 - String to display
1236 // 2 - bool indicating whether the entry is selectable (grey or not)
1237 // 3 - String that is used for presets
1238 // 4 - Int value determined by backend
1239 // 5 - String value determined by backend
1240 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1241 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1242 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1244 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1246 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1247 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1248 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1249 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1250 "text", 0, "sensitive", 1, NULL);
1253 { // Combo box entry
1254 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1259 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1262 GtkListStore *store;
1265 g_debug("audio_samplerate_opts_set ()\n");
1266 store = get_combo_box_store(builder, name);
1267 gtk_list_store_clear(store);
1268 // Add an item for "Same As Source"
1269 gtk_list_store_append(store, &iter);
1270 gtk_list_store_set(store, &iter,
1271 0, "Same as source",
1277 for (ii = 0; ii < count; ii++)
1279 gtk_list_store_append(store, &iter);
1280 gtk_list_store_set(store, &iter,
1281 0, rates[ii].string,
1283 2, rates[ii].string,
1284 3, (gdouble)rates[ii].rate,
1285 4, rates[ii].string,
1291 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1294 GtkListStore *store;
1297 g_debug("video_rate_opts_set ()\n");
1298 store = get_combo_box_store(builder, name);
1299 gtk_list_store_clear(store);
1300 // Add an item for "Same As Source"
1301 gtk_list_store_append(store, &iter);
1302 gtk_list_store_set(store, &iter,
1303 0, "Same as source",
1309 for (ii = 0; ii < count; ii++)
1313 if (strcmp(rates[ii].string, "23.976") == 0)
1315 desc = "(NTSC Film)";
1317 else if (strcmp(rates[ii].string, "25") == 0)
1319 desc = "(PAL Film/Video)";
1321 else if (strcmp(rates[ii].string, "29.97") == 0)
1323 desc = "(NTSC Video)";
1325 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1326 gtk_list_store_append(store, &iter);
1327 gtk_list_store_set(store, &iter,
1330 2, rates[ii].string,
1331 3, (gdouble)rates[ii].rate,
1332 4, rates[ii].string,
1339 mix_opts_set(GtkBuilder *builder, const gchar *name)
1342 GtkListStore *store;
1345 g_debug("mix_opts_set ()\n");
1346 store = get_combo_box_store(builder, name);
1347 gtk_list_store_clear(store);
1348 gtk_list_store_append(store, &iter);
1349 gtk_list_store_set(store, &iter,
1356 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1358 gtk_list_store_append(store, &iter);
1359 gtk_list_store_set(store, &iter,
1360 0, hb_audio_mixdowns[ii].human_readable_name,
1362 2, hb_audio_mixdowns[ii].short_name,
1363 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1364 4, hb_audio_mixdowns[ii].internal_name,
1370 language_opts_set(GtkBuilder *builder, const gchar *name)
1373 GtkListStore *store;
1376 g_debug("language_opts_set ()\n");
1377 store = get_combo_box_store(builder, name);
1378 gtk_list_store_clear(store);
1379 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1381 gtk_list_store_append(store, &iter);
1382 gtk_list_store_set(store, &iter,
1383 0, ghb_language_table[ii].eng_name,
1385 2, ghb_language_table[ii].iso639_2,
1387 4, ghb_language_table[ii].iso639_1,
1392 static gchar **titles = NULL;
1395 title_opts_set(GtkBuilder *builder, const gchar *name)
1398 GtkListStore *store;
1399 hb_list_t * list = NULL;
1400 hb_title_t * title = NULL;
1404 g_debug("title_opts_set ()\n");
1405 store = get_combo_box_store(builder, name);
1406 gtk_list_store_clear(store);
1409 list = hb_get_titles( h_scan );
1410 count = hb_list_count( list );
1411 if (count > 100) count = 100;
1413 if (titles) g_strfreev(titles);
1414 if (title_opts.map) g_free(title_opts.map);
1417 title_opts.count = count;
1418 title_opts.map = g_malloc(count*sizeof(options_map_t));
1419 titles = g_malloc((count+1) * sizeof(gchar*));
1423 title_opts.count = 1;
1424 title_opts.map = g_malloc(sizeof(options_map_t));
1429 // No titles. Fill in a default.
1430 gtk_list_store_append(store, &iter);
1431 gtk_list_store_set(store, &iter,
1438 title_opts.map[0].option = "No Titles";
1439 title_opts.map[0].shortOpt = "none";
1440 title_opts.map[0].ivalue = -1;
1441 title_opts.map[0].svalue = "none";
1444 for (ii = 0; ii < count; ii++)
1446 title = (hb_title_t*)hb_list_item(list, ii);
1447 if (title->duration != 0)
1449 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1450 title->index, title->hours, title->minutes, title->seconds);
1454 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1456 gtk_list_store_append(store, &iter);
1457 gtk_list_store_set(store, &iter,
1464 title_opts.map[ii].option = titles[ii];
1465 title_opts.map[ii].shortOpt = titles[ii];
1466 title_opts.map[ii].ivalue = ii;
1467 title_opts.map[ii].svalue = titles[ii];
1473 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1476 gboolean foundit = FALSE;
1478 if (gtk_tree_model_get_iter_first (store, iter))
1482 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1483 if (value == (int)ivalue)
1488 } while (gtk_tree_model_iter_next (store, iter));
1494 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1497 GtkListStore *store;
1498 hb_list_t * list = NULL;
1499 hb_title_t * title = NULL;
1500 hb_audio_config_t * audio;
1504 g_debug("audio_track_opts_set ()\n");
1505 store = get_combo_box_store(builder, name);
1506 gtk_list_store_clear(store);
1509 list = hb_get_titles( h_scan );
1510 title = (hb_title_t*)hb_list_item( list, titleindex );
1513 count = hb_list_count( title->list_audio );
1516 if (count > 100) count = 100;
1517 if (audio_track_opts.map) g_free(audio_track_opts.map);
1520 audio_track_opts.count = count;
1521 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1525 audio_track_opts.count = 1;
1526 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1530 // No audio. set some default
1531 gtk_list_store_append(store, &iter);
1532 gtk_list_store_set(store, &iter,
1539 audio_track_opts.map[0].option = "No Audio";
1540 audio_track_opts.map[0].shortOpt = "none";
1541 audio_track_opts.map[0].ivalue = -1;
1542 audio_track_opts.map[0].svalue = "none";
1545 for (ii = 0; ii < count; ii++)
1547 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1548 gtk_list_store_append(store, &iter);
1549 gtk_list_store_set(store, &iter,
1550 0, audio->lang.description,
1556 audio_track_opts.map[ii].option = audio->lang.description,
1557 audio_track_opts.map[ii].shortOpt = index_str[ii];
1558 audio_track_opts.map[ii].ivalue = ii;
1559 audio_track_opts.map[ii].svalue = index_str[ii];
1565 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1568 GtkListStore *store;
1569 hb_list_t * list = NULL;
1570 hb_title_t * title = NULL;
1571 hb_subtitle_t * subtitle;
1575 g_debug("subtitle_opts_set () %s\n", name);
1576 store = get_combo_box_store(builder, name);
1577 gtk_list_store_clear(store);
1580 list = hb_get_titles( h_scan );
1581 title = (hb_title_t*)hb_list_item( list, titleindex );
1584 count = hb_list_count( title->list_subtitle );
1587 if (count > 100) count = 100;
1588 if (subtitle_opts.map) g_free(subtitle_opts.map);
1591 subtitle_opts.count = count+2;
1592 subtitle_opts.map = g_malloc((count+2)*sizeof(options_map_t));
1596 subtitle_opts.count = LANG_TABLE_SIZE+2;
1597 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+2)*sizeof(options_map_t));
1599 // Add options for "none" and "autoselect"
1600 gtk_list_store_append(store, &iter);
1601 gtk_list_store_set(store, &iter,
1608 subtitle_opts.map[0].option = "None";
1609 subtitle_opts.map[0].shortOpt = "none";
1610 subtitle_opts.map[0].ivalue = -2;
1611 subtitle_opts.map[0].svalue = "none";
1612 gtk_list_store_append(store, &iter);
1613 gtk_list_store_set(store, &iter,
1620 subtitle_opts.map[0].option = "Same as audio";
1621 subtitle_opts.map[0].shortOpt = "auto";
1622 subtitle_opts.map[0].ivalue = -1;
1623 subtitle_opts.map[0].svalue = "auto";
1626 for (ii = 0; ii < count; ii++)
1628 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1629 gtk_list_store_append(store, &iter);
1630 gtk_list_store_set(store, &iter,
1633 2, subtitle->iso639_2,
1635 4, subtitle->iso639_2,
1637 subtitle_opts.map[ii+2].option = subtitle->lang;
1638 subtitle_opts.map[ii+2].shortOpt = subtitle->iso639_2;
1639 subtitle_opts.map[ii+2].ivalue = ii;
1640 subtitle_opts.map[ii+2].svalue = subtitle->iso639_2;
1645 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1647 gtk_list_store_append(store, &iter);
1648 gtk_list_store_set(store, &iter,
1649 0, ghb_language_table[ii].eng_name,
1651 2, ghb_language_table[ii].iso639_2,
1653 4, ghb_language_table[ii].iso639_2,
1655 subtitle_opts.map[ii+2].option = ghb_language_table[ii].eng_name;
1656 subtitle_opts.map[ii+2].shortOpt = ghb_language_table[ii].iso639_2;
1657 subtitle_opts.map[ii+2].ivalue = ii;
1658 subtitle_opts.map[ii+2].svalue = ghb_language_table[ii].iso639_2;
1670 guint64 longest = 0;
1671 gint titleindex = 0;
1673 g_debug("ghb_longest_title ()\n");
1674 if (h_scan == NULL) return 0;
1675 list = hb_get_titles( h_scan );
1676 count = hb_list_count( list );
1677 if (count > 100) count = 100;
1678 for (ii = 0; ii < count; ii++)
1680 title = (hb_title_t*)hb_list_item(list, ii);
1681 if (title->duration > longest)
1684 longest = title->duration;
1691 ghb_find_audio_track(
1695 GHashTable *track_indices)
1699 hb_audio_config_t * audio;
1706 g_debug("find_audio_track ()\n");
1707 if (h_scan == NULL) return -1;
1708 list = hb_get_titles( h_scan );
1709 title = (hb_title_t*)hb_list_item( list, titleindex );
1712 count = hb_list_count( title->list_audio );
1714 if (count > 10) count = 10;
1715 used = g_hash_table_lookup(track_indices, &acodec);
1718 used = g_malloc0(count * sizeof(gboolean));
1719 g_hash_table_insert(track_indices, &acodec, used);
1721 // Try to fine an item that matches the preferred language and
1722 // the passthru codec type
1723 if (acodec == HB_ACODEC_AC3 || acodec == HB_ACODEC_DCA)
1725 for (ii = 0; ii < count; ii++)
1732 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1733 title->list_audio, ii );
1734 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1735 audio->in.channel_layout);
1736 // Find a track that is not visually impaired or dirctor's
1737 // commentary, and has the highest channel count.
1738 if ((audio->in.codec == acodec) &&
1739 (audio->lang.type < 2) &&
1740 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1741 (strcmp(lang, "und") == 0)))
1743 if (channels > max_chan)
1746 max_chan = channels;
1756 // Try to fine an item that matches the preferred language
1757 for (ii = 0; ii < count; ii++)
1761 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1762 title->list_audio, ii );
1763 // Find a track that is not visually impaired or dirctor's commentary
1764 if ((audio->lang.type < 2) &&
1765 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1766 (strcmp(lang, "und") == 0)))
1777 // Try to fine an item that does not match the preferred language and
1778 // matches the passthru codec type
1779 if (acodec == HB_ACODEC_AC3 || acodec == HB_ACODEC_DCA)
1781 for (ii = 0; ii < count; ii++)
1788 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1789 title->list_audio, ii );
1790 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1791 audio->in.channel_layout);
1792 // Find a track that is not visually impaired or dirctor's
1793 // commentary, and has the highest channel count.
1794 if ((audio->in.codec == acodec) &&
1795 (audio->lang.type < 2))
1797 if (channels > max_chan)
1800 max_chan = channels;
1810 // Try to fine an item that does not match the preferred language
1811 for (ii = 0; ii < count; ii++)
1815 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1816 title->list_audio, ii );
1817 // Find a track that is not visually impaired or dirctor's commentary
1818 if (audio->lang.type < 2)
1829 // Last ditch, anything goes
1830 for (ii = 0; ii < count; ii++)
1832 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1833 title->list_audio, ii );
1848 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1851 GtkListStore *store;
1854 g_debug("generic_opts_set ()\n");
1855 if (name == NULL || opts == NULL) return;
1856 store = get_combo_box_store(builder, name);
1857 gtk_list_store_clear(store);
1858 for (ii = 0; ii < opts->count; ii++)
1860 gtk_list_store_append(store, &iter);
1861 gtk_list_store_set(store, &iter,
1862 0, opts->map[ii].option,
1864 2, opts->map[ii].shortOpt,
1865 3, opts->map[ii].ivalue,
1866 4, opts->map[ii].svalue,
1872 find_combo_table(const gchar *name)
1876 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1878 if (strcmp(name, combo_name_map[ii].name) == 0)
1880 return combo_name_map[ii].opts;
1887 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
1889 if (strcmp(name, "AudioBitrate") == 0)
1890 return lookup_audio_bitrate_int(gval);
1891 else if (strcmp(name, "AudioSamplerate") == 0)
1892 return lookup_audio_rate_int(gval);
1893 else if (strcmp(name, "VideoFramerate") == 0)
1894 return lookup_video_rate_int(gval);
1895 else if (strcmp(name, "AudioMixdown") == 0)
1896 return lookup_mix_int(gval);
1897 else if (strcmp(name, "SourceAudioLang") == 0)
1898 return lookup_audio_lang_int(gval);
1901 return lookup_generic_int(find_combo_table(name), gval);
1903 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1908 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
1910 if (strcmp(name, "AudioBitrate") == 0)
1911 return lookup_audio_bitrate_int(gval);
1912 else if (strcmp(name, "AudioSamplerate") == 0)
1913 return lookup_audio_rate_int(gval);
1914 else if (strcmp(name, "VideoFramerate") == 0)
1915 return lookup_video_rate_int(gval);
1916 else if (strcmp(name, "AudioMixdown") == 0)
1917 return lookup_mix_int(gval);
1918 else if (strcmp(name, "SourceAudioLang") == 0)
1919 return lookup_audio_lang_int(gval);
1922 return lookup_generic_double(find_combo_table(name), gval);
1924 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
1929 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
1931 if (strcmp(name, "AudioBitrate") == 0)
1932 return lookup_audio_bitrate_option(gval);
1933 else if (strcmp(name, "AudioSamplerate") == 0)
1934 return lookup_audio_rate_option(gval);
1935 else if (strcmp(name, "VideoFramerate") == 0)
1936 return lookup_video_rate_option(gval);
1937 else if (strcmp(name, "AudioMixdown") == 0)
1938 return lookup_mix_option(gval);
1939 else if (strcmp(name, "SourceAudioLang") == 0)
1940 return lookup_audio_lang_option(gval);
1943 return lookup_generic_option(find_combo_table(name), gval);
1945 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1950 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1952 GtkComboBox *combo = NULL;
1954 gint handler_id = 0;
1956 g_debug("ghb_update_ui_combo_box() %s\n", name);
1959 // Clearing a combo box causes a rash of "changed" events, even when
1960 // the active item is -1 (inactive). To control things, I'm disabling
1961 // the event till things are settled down.
1962 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1963 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1966 // Valid signal id found. This should always succeed.
1967 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1968 signal_id, 0, 0, 0, 0);
1971 // This should also always succeed
1972 g_signal_handler_block ((gpointer)combo, handler_id);
1978 audio_bitrate_opts_set(builder, "AudioBitrate");
1979 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1980 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1981 mix_opts_set(builder, "AudioMixdown");
1982 language_opts_set(builder, "SourceAudioLang");
1983 subtitle_opts_set(builder, "Subtitles", user_data);
1984 title_opts_set(builder, "title");
1985 audio_track_opts_set(builder, "AudioTrack", user_data);
1986 generic_opts_set(builder, "VideoQualityGranularity", &vqual_granularity_opts);
1987 generic_opts_set(builder, "LoggingLevel", &logging_opts);
1988 generic_opts_set(builder, "FileFormat", &container_opts);
1989 generic_opts_set(builder, "PictureDeinterlace", &deint_opts);
1990 generic_opts_set(builder, "PictureDetelecine", &detel_opts);
1991 generic_opts_set(builder, "PictureDecomb", &decomb_opts);
1992 generic_opts_set(builder, "PictureDenoise", &denoise_opts);
1993 generic_opts_set(builder, "VideoEncoder", &vcodec_opts);
1994 generic_opts_set(builder, "AudioEncoder", &acodec_opts);
1995 generic_opts_set(builder, "x264_direct", &direct_opts);
1996 generic_opts_set(builder, "x264_b_adapt", &badapt_opts);
1997 generic_opts_set(builder, "x264_me", &me_opts);
1998 generic_opts_set(builder, "x264_subme", &subme_opts);
1999 generic_opts_set(builder, "x264_analyse", &analyse_opts);
2000 generic_opts_set(builder, "x264_trellis", &trellis_opts);
2004 if (strcmp(name, "AudioBitrate") == 0)
2005 audio_bitrate_opts_set(builder, "AudioBitrate");
2006 else if (strcmp(name, "AudioSamplerate") == 0)
2007 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2008 else if (strcmp(name, "VideoFramerate") == 0)
2009 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2010 else if (strcmp(name, "AudioMixdown") == 0)
2011 mix_opts_set(builder, "AudioMixdown");
2012 else if (strcmp(name, "SourceAudioLang") == 0)
2013 language_opts_set(builder, "SourceAudioLang");
2014 else if (strcmp(name, "Subtitles") == 0)
2015 subtitle_opts_set(builder, "Subtitles", user_data);
2016 else if (strcmp(name, "title") == 0)
2017 title_opts_set(builder, "title");
2018 else if (strcmp(name, "AudioTrack") == 0)
2019 audio_track_opts_set(builder, "AudioTrack", user_data);
2021 generic_opts_set(builder, name, find_combo_table(name));
2025 g_signal_handler_unblock ((gpointer)combo, handler_id);
2030 init_ui_combo_boxes(GtkBuilder *builder)
2034 init_combo_box(builder, "AudioBitrate");
2035 init_combo_box(builder, "AudioSamplerate");
2036 init_combo_box(builder, "VideoFramerate");
2037 init_combo_box(builder, "AudioMixdown");
2038 init_combo_box(builder, "SourceAudioLang");
2039 init_combo_box(builder, "Subtitles");
2040 init_combo_box(builder, "title");
2041 init_combo_box(builder, "AudioTrack");
2042 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2044 init_combo_box(builder, combo_name_map[ii].name);
2048 static const char * turbo_opts =
2049 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2050 "no-fast-pskip=0:8x8dct=0:weightb=0";
2052 // Construct the x264 options string
2053 // The result is allocated, so someone must free it at some point.
2055 ghb_build_x264opts_string(GValue *settings)
2058 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2065 result = g_strdup("");
2071 ghb_get_chapters(gint titleindex)
2075 hb_chapter_t * chapter;
2077 GValue *chapters = NULL;
2079 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2080 if (h_scan == NULL) return NULL;
2081 list = hb_get_titles( h_scan );
2082 title = (hb_title_t*)hb_list_item( list, titleindex );
2083 if (title == NULL) return NULL;
2084 count = hb_list_count( title->list_chapter );
2085 chapters = ghb_array_value_new(count);
2086 for (ii = 0; ii < count; ii++)
2088 chapter = hb_list_item(title->list_chapter, ii);
2089 if (chapter == NULL) break;
2090 if (chapter->title == NULL || chapter->title[0] == 0)
2093 str = g_strdup_printf ("Chapter %2d", ii+1);
2094 ghb_array_append(chapters, ghb_string_value_new(str));
2099 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2106 ghb_ac3_in_audio_list(const GValue *audio_list)
2110 count = ghb_array_len(audio_list);
2111 for (ii = 0; ii < count; ii++)
2116 asettings = ghb_array_get_nth(audio_list, ii);
2117 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2118 if (acodec == HB_ACODEC_AC3)
2125 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2128 GtkListStore *store;
2131 g_debug("audio_rate_opts_add ()\n");
2132 store = get_combo_box_store(builder, name);
2133 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2135 str = g_strdup_printf ("%d", rate);
2136 gtk_list_store_append(store, &iter);
2137 gtk_list_store_set(store, &iter,
2149 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2152 GtkListStore *store;
2154 gboolean done = FALSE;
2156 guint last = (guint)last_rate;
2158 g_debug("audio_bitrate_opts_clean ()\n");
2159 store = get_combo_box_store(builder, name);
2160 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2164 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2166 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2168 done = !gtk_list_store_remove(store, &iter);
2170 else if (ivalue > last)
2173 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2174 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2179 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2180 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2187 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2190 GtkListStore *store;
2193 g_debug("audio_bitrate_opts_set ()\n");
2194 store = get_combo_box_store(builder, name);
2195 gtk_list_store_clear(store);
2196 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2198 gtk_list_store_append(store, &iter);
2199 gtk_list_store_set(store, &iter,
2200 0, hb_audio_bitrates[ii].string,
2202 2, hb_audio_bitrates[ii].string,
2203 3, (gdouble)hb_audio_bitrates[ii].rate,
2204 4, hb_audio_bitrates[ii].string,
2210 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2212 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2216 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2218 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2221 static ghb_status_t hb_status;
2224 ghb_combo_init(GtkBuilder *builder)
2226 // Set up the list model for the combos
2227 init_ui_combo_boxes(builder);
2228 // Populate all the combos
2229 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
2233 ghb_backend_init(gint debug)
2236 h_scan = hb_init( debug, 0 );
2237 h_queue = hb_init( debug, 0 );
2248 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2250 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2251 hb_status.scan.state |= GHB_STATE_SCANNING;
2252 // initialize count and cur to something that won't cause FPE
2253 // when computing progress
2254 hb_status.scan.title_count = 1;
2255 hb_status.scan.title_cur = 0;
2259 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2261 g_debug("ghb_backend_queue_scan()");
2262 hb_scan( h_queue, path, titlenum, 10, 0 );
2263 hb_status.queue.state |= GHB_STATE_SCANNING;
2267 ghb_get_scan_state()
2269 return hb_status.scan.state;
2273 ghb_get_queue_state()
2275 return hb_status.queue.state;
2279 ghb_clear_scan_state(gint state)
2281 hb_status.scan.state &= ~state;
2285 ghb_clear_queue_state(gint state)
2287 hb_status.queue.state &= ~state;
2291 ghb_set_scan_state(gint state)
2293 hb_status.scan.state |= state;
2297 ghb_set_queue_state(gint state)
2299 hb_status.queue.state |= state;
2303 ghb_get_status(ghb_status_t *status)
2305 memcpy(status, &hb_status, sizeof(ghb_status_t));
2314 if (h_scan == NULL) return;
2315 hb_get_state( h_scan, &s_scan );
2316 switch( s_scan.state )
2318 #define p s_scan.param.scanning
2319 case HB_STATE_SCANNING:
2321 hb_status.scan.state |= GHB_STATE_SCANNING;
2322 hb_status.scan.title_count = p.title_count;
2323 hb_status.scan.title_cur = p.title_cur;
2327 case HB_STATE_SCANDONE:
2329 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2330 hb_status.scan.state |= GHB_STATE_SCANDONE;
2333 #define p s_scan.param.working
2334 case HB_STATE_WORKING:
2335 hb_status.scan.state |= GHB_STATE_WORKING;
2336 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2337 hb_status.scan.job_cur = p.job_cur;
2338 hb_status.scan.job_count = p.job_count;
2339 hb_status.scan.progress = p.progress;
2340 hb_status.scan.rate_cur = p.rate_cur;
2341 hb_status.scan.rate_avg = p.rate_avg;
2342 hb_status.scan.hours = p.hours;
2343 hb_status.scan.minutes = p.minutes;
2344 hb_status.scan.seconds = p.seconds;
2345 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2349 case HB_STATE_PAUSED:
2350 hb_status.scan.state |= GHB_STATE_PAUSED;
2353 case HB_STATE_MUXING:
2355 hb_status.scan.state |= GHB_STATE_MUXING;
2358 #define p s_scan.param.workdone
2359 case HB_STATE_WORKDONE:
2363 hb_status.scan.state |= GHB_STATE_WORKDONE;
2364 hb_status.scan.state &= ~GHB_STATE_MUXING;
2365 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2366 hb_status.scan.state &= ~GHB_STATE_WORKING;
2370 hb_status.scan.error = GHB_ERROR_NONE;
2372 case HB_ERROR_CANCELED:
2373 hb_status.scan.error = GHB_ERROR_CANCELED;
2376 hb_status.scan.error = GHB_ERROR_FAIL;
2379 // Delete all remaining jobs of this encode.
2380 // An encode can be composed of multiple associated jobs.
2381 // When a job is stopped, libhb removes it from the job list,
2382 // but does not remove other jobs that may be associated with it.
2383 // Associated jobs are taged in the sequence id.
2384 while ((job = hb_job(h_scan, 0)) != NULL)
2385 hb_rem( h_scan, job );
2389 hb_get_state( h_queue, &s_queue );
2390 switch( s_queue.state )
2392 #define p s_queue.param.scanning
2393 case HB_STATE_SCANNING:
2395 hb_status.queue.state |= GHB_STATE_SCANNING;
2396 hb_status.queue.title_count = p.title_count;
2397 hb_status.queue.title_cur = p.title_cur;
2401 case HB_STATE_SCANDONE:
2403 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2404 hb_status.queue.state |= GHB_STATE_SCANDONE;
2407 #define p s_queue.param.working
2408 case HB_STATE_WORKING:
2409 hb_status.queue.state |= GHB_STATE_WORKING;
2410 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2411 hb_status.queue.job_cur = p.job_cur;
2412 hb_status.queue.job_count = p.job_count;
2413 hb_status.queue.progress = p.progress;
2414 hb_status.queue.rate_cur = p.rate_cur;
2415 hb_status.queue.rate_avg = p.rate_avg;
2416 hb_status.queue.hours = p.hours;
2417 hb_status.queue.minutes = p.minutes;
2418 hb_status.queue.seconds = p.seconds;
2419 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2423 case HB_STATE_PAUSED:
2424 hb_status.queue.state |= GHB_STATE_PAUSED;
2427 case HB_STATE_MUXING:
2429 hb_status.queue.state |= GHB_STATE_MUXING;
2432 #define p s_queue.param.workdone
2433 case HB_STATE_WORKDONE:
2437 hb_status.queue.state |= GHB_STATE_WORKDONE;
2438 hb_status.queue.state &= ~GHB_STATE_MUXING;
2439 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2440 hb_status.queue.state &= ~GHB_STATE_WORKING;
2444 hb_status.queue.error = GHB_ERROR_NONE;
2446 case HB_ERROR_CANCELED:
2447 hb_status.queue.error = GHB_ERROR_CANCELED;
2450 hb_status.queue.error = GHB_ERROR_FAIL;
2453 // Delete all remaining jobs of this encode.
2454 // An encode can be composed of multiple associated jobs.
2455 // When a job is stopped, libhb removes it from the job list,
2456 // but does not remove other jobs that may be associated with it.
2457 // Associated jobs are taged in the sequence id.
2458 while ((job = hb_job(h_queue, 0)) != NULL)
2459 hb_rem( h_queue, job );
2466 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2471 if (h_scan == NULL) return FALSE;
2472 list = hb_get_titles( h_scan );
2473 if( !hb_list_count( list ) )
2475 /* No valid title, stop right there */
2479 title = hb_list_item( list, titleindex );
2480 if (title == NULL) return FALSE; // Bad titleindex
2481 tinfo->width = title->width;
2482 tinfo->height = title->height;
2483 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2484 // Don't allow crop to 0
2485 if (title->crop[0] + title->crop[1] >= title->height)
2486 title->crop[0] = title->crop[1] = 0;
2487 if (title->crop[2] + title->crop[3] >= title->width)
2488 title->crop[2] = title->crop[3] = 0;
2489 tinfo->num_chapters = hb_list_count(title->list_chapter);
2490 tinfo->rate_base = title->rate_base;
2491 tinfo->rate = title->rate;
2492 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2493 title->width * title->pixel_aspect_width,
2494 title->height * title->pixel_aspect_height);
2495 tinfo->hours = title->hours;
2496 tinfo->minutes = title->minutes;
2497 tinfo->seconds = title->seconds;
2498 tinfo->duration = title->duration;
2503 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2505 hb_audio_config_t *audio;
2507 audio = get_hb_audio(titleindex, audioindex);
2508 if (audio == NULL) return FALSE; // Bad audioindex
2509 ainfo->codec = audio->in.codec;
2510 ainfo->bitrate = audio->in.bitrate;
2511 ainfo->samplerate = audio->in.samplerate;
2516 ghb_audio_is_passthru(gint acodec)
2518 g_debug("ghb_audio_is_passthru () \n");
2519 return (acodec == HB_ACODEC_AC3) || (acodec == HB_ACODEC_DCA);
2523 ghb_get_default_acodec()
2525 return HB_ACODEC_FAAC;
2529 ghb_set_scale(signal_user_data_t *ud, gint mode)
2534 gboolean keep_aspect, round_dims, anamorphic;
2535 gboolean autocrop, autoscale, noscale;
2536 gint crop[4], width, height, par_width, par_height;
2537 gint crop_width, crop_height;
2538 gint aspect_n, aspect_d;
2539 gboolean keep_width = (mode == GHB_SCALE_KEEP_WIDTH);
2540 gboolean keep_height = (mode == GHB_SCALE_KEEP_HEIGHT);
2546 gint max_height = 0;
2548 g_debug("ghb_set_scale ()\n");
2550 if (h_scan == NULL) return;
2551 list = hb_get_titles( h_scan );
2552 if( !hb_list_count( list ) )
2554 /* No valid title, stop right there */
2559 titleindex = ghb_settings_combo_int(ud->settings, "title");
2560 title = hb_list_item( list, titleindex );
2561 if (title == NULL) return;
2563 if (job == NULL) return;
2565 // First configure widgets
2566 round_dims = ghb_settings_get_boolean(ud->settings, "ModDimensions");
2567 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
2568 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2569 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2570 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2571 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2572 // alignment constraints rather than scaling to satisfy them.
2573 noscale = ghb_settings_get_boolean(ud->settings, "noscale");
2574 // Align dimensions to either 16 or 2 pixels
2575 // The scaler crashes if the dimensions are not divisible by 2
2576 // x264 also will not accept dims that are not multiple of 2
2577 modshift = round_dims ? 4 : 1;
2578 modround = round_dims ? 8 : 1;
2582 keep_height = FALSE;
2586 keep_height = FALSE;
2588 // Step needs to be at least 2 because odd widths cause scaler crash
2589 step = round_dims ? 16 : 2;
2590 widget = GHB_WIDGET (ud->builder, "scale_width");
2591 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2592 widget = GHB_WIDGET (ud->builder, "scale_height");
2593 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2596 ghb_title_info_t tinfo;
2598 if (ghb_get_title_info (&tinfo, titleindex))
2600 crop[0] = tinfo.crop[0];
2601 crop[1] = tinfo.crop[1];
2602 crop[2] = tinfo.crop[2];
2603 crop[3] = tinfo.crop[3];
2608 // Adjust the cropping to accomplish the desired width and height
2609 crop_width = tinfo.width - crop[2] - crop[3];
2610 crop_height = tinfo.height - crop[0] - crop[1];
2611 width = (crop_width >> modshift) << modshift;
2612 height = (crop_height >> modshift) << modshift;
2613 need1 = (crop_height - height) / 2;
2614 need2 = crop_height - height - need1;
2617 need1 = (crop_width - width) / 2;
2618 need2 = crop_width - width - need1;
2622 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2623 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2624 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2625 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2628 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2629 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2630 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2631 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2632 hb_reduce(&aspect_n, &aspect_d,
2633 title->width * title->pixel_aspect_width,
2634 title->height * title->pixel_aspect_height);
2635 crop_width = title->width - crop[2] - crop[3];
2636 crop_height = title->height - crop[0] - crop[1];
2640 height = crop_height;
2646 width = ghb_settings_get_int(ud->settings, "scale_width");
2647 height = ghb_settings_get_int(ud->settings, "scale_height");
2648 max_width = ghb_settings_get_int(ud->settings, "PictureWidth");
2649 max_height = ghb_settings_get_int(ud->settings, "PictureHeight");
2651 max_width = (max_width >> modshift) << modshift;
2652 max_height = (max_height >> modshift) << modshift;
2653 // Adjust dims according to max values
2656 max_height = crop_height;
2660 max_width = crop_width;
2662 height = MIN(height, max_height);
2663 width = MIN(width, max_width);
2664 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2667 width = title->width - crop[2] - crop[3];
2669 height = title->height - crop[0] - crop[1];
2673 job->anamorphic.mode = autoscale ? 2 : 3;
2674 // The scaler crashes if the dimensions are not divisible by 2
2675 // Align mod 2. And so does something in x264_encoder_headers()
2676 job->anamorphic.modulus = round_dims ? 16 : 2;
2678 job->height = height;
2680 job->maxHeight = max_height;
2681 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2682 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2683 hb_set_anamorphic_size( job, &width, &height,
2684 &par_width, &par_height );
2688 job->anamorphic.mode = 0;
2692 gint new_width, new_height;
2694 g_debug("kw %s kh %s\n", keep_width ? "y":"n", keep_height ? "y":"n");
2695 g_debug("w %d h %d\n", width, height);
2696 // Compute pixel aspect ration.
2697 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2698 // Must scale so that par becomes 1:1
2699 // Try to keep largest dimension
2700 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2701 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2702 // Height and width are always multiples of 2, so do the rounding
2703 new_height = ((new_height + 1) >> 1) << 1;
2704 new_width = ((new_width + 1) >> 1) << 1;
2705 if ((max_width && new_width > max_width) ||
2706 new_width > title->width)
2708 height = new_height;
2710 else if ((max_height && new_height > max_height) ||
2711 new_height > title->height)
2715 else if (keep_width)
2717 height = new_height;
2719 else if (keep_height)
2723 else if (width > new_width)
2725 height = new_height;
2731 g_debug("new w %d h %d\n", width, height);
2733 width = ((width + modround) >> modshift) << modshift;
2734 height = ((height + modround) >> modshift) << modshift;
2736 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2737 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2741 set_preview_job_settings(hb_job_t *job, GValue *settings)
2743 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
2744 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
2745 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
2746 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
2748 gboolean anamorphic, round_dimensions, autoscale;
2749 autoscale = ghb_settings_get_boolean(settings, "autoscale");
2750 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
2751 round_dimensions = ghb_settings_get_boolean(settings, "ModDimensions");
2754 job->anamorphic.modulus = round_dimensions ? 16 : 2;
2755 job->anamorphic.mode = autoscale ? 2 : 3;
2759 job->anamorphic.modulus = 2;
2760 job->anamorphic.mode = 0;
2762 job->width = ghb_settings_get_int(settings, "scale_width");
2763 job->height = ghb_settings_get_int(settings, "scale_height");
2764 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
2765 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
2766 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2770 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2777 if (h_scan == NULL) return 1500;
2778 list = hb_get_titles( h_scan );
2779 title = hb_list_item( list, titleindex );
2780 if (title == NULL) return 1500;
2782 if (job == NULL) return 1500;
2783 size = ghb_settings_get_int(settings, "VideoTargetSize");
2784 return hb_calc_bitrate( job, size );
2788 ghb_validate_filter_string(const gchar *str, gint max_fields)
2794 if (str == NULL || *str == 0) return TRUE;
2797 val = g_strtod(str, &end);
2799 { // Found a numeric value
2801 // negative max_fields means infinate
2802 if (max_fields >= 0 && fields > max_fields) return FALSE;
2816 ghb_validate_filters(signal_user_data_t *ud)
2823 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
2826 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
2827 if (!ghb_validate_filter_string(str, 4))
2829 message = g_strdup_printf(
2830 "Invalid Deinterlace Settings:\n\n%s\n",
2832 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2840 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
2843 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
2844 if (!ghb_validate_filter_string(str, 6))
2846 message = g_strdup_printf(
2847 "Invalid Detelecine Settings:\n\n%s\n",
2849 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2857 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
2860 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
2861 if (!ghb_validate_filter_string(str, 7))
2863 message = g_strdup_printf(
2864 "Invalid Decomb Settings:\n\n%s\n",
2866 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2874 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
2877 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
2878 if (!ghb_validate_filter_string(str, 4))
2880 message = g_strdup_printf(
2881 "Invalid Denoise Settings:\n\n%s\n",
2883 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2894 ghb_validate_video(signal_user_data_t *ud)
2899 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2900 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
2901 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
2902 (vcodec == HB_VCODEC_THEORA))
2904 // mp4|avi/theora combination is not supported.
2905 message = g_strdup_printf(
2906 "Theora is not supported in the MP4 and AVI containers.\n\n"
2907 "You should choose a different video codec or container.\n"
2908 "If you continue, XviD will be chosen for you.");
2909 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2915 vcodec = HB_VCODEC_XVID;
2916 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
2922 ghb_validate_audio(signal_user_data_t *ud)
2929 if (h_scan == NULL) return FALSE;
2930 list = hb_get_titles( h_scan );
2931 if( !hb_list_count( list ) )
2933 /* No valid title, stop right there */
2934 g_message("No title found.\n");
2940 titleindex = ghb_settings_combo_int(ud->settings, "title");
2941 title = hb_list_item( list, titleindex );
2942 if (title == NULL) return FALSE;
2943 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2945 const GValue *audio_list;
2948 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2949 count = ghb_array_len(audio_list);
2950 for (ii = 0; ii < count; ii++)
2953 hb_audio_config_t *taudio;
2955 asettings = ghb_array_get_nth(audio_list, ii);
2956 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
2957 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
2958 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
2959 title->list_audio, track );
2960 if ((taudio->in.codec != HB_ACODEC_AC3 && codec == HB_ACODEC_AC3) ||
2961 (taudio->in.codec != HB_ACODEC_DCA && codec == HB_ACODEC_DCA))
2963 // Not supported. AC3 is passthrough only, so input must be AC3
2965 str = (codec == HB_ACODEC_AC3) ? "AC-3" : "DTS";
2966 message = g_strdup_printf(
2967 "The source does not support %s Pass-Thru.\n\n"
2968 "You should choose a different audio codec.\n"
2969 "If you continue, one will be chosen for you.", str);
2970 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2976 if (mux == HB_MUX_AVI)
2978 codec = HB_ACODEC_LAME;
2982 codec = HB_ACODEC_FAAC;
2984 value = get_acodec_value(codec);
2985 ghb_settings_take_value(asettings, "AudioEncoder", value);
2987 gchar *a_unsup = NULL;
2988 gchar *mux_s = NULL;
2989 if (mux == HB_MUX_MP4)
2992 // mp4/mp3|vorbis combination is not supported.
2993 if (codec == HB_ACODEC_LAME)
2996 codec = HB_ACODEC_FAAC;
2998 if (codec == HB_ACODEC_VORBIS)
3001 codec = HB_ACODEC_FAAC;
3004 else if (mux == HB_MUX_AVI)
3007 // avi/faac|vorbis combination is not supported.
3008 if (codec == HB_ACODEC_FAAC)
3011 codec = HB_ACODEC_LAME;
3013 if (codec == HB_ACODEC_VORBIS)
3016 codec = HB_ACODEC_LAME;
3019 else if (mux == HB_MUX_OGM)
3022 // avi/faac|vorbis combination is not supported.
3023 if (codec == HB_ACODEC_FAAC)
3026 codec = HB_ACODEC_VORBIS;
3028 if (codec == HB_ACODEC_AC3)
3031 codec = HB_ACODEC_VORBIS;
3033 if (codec == HB_ACODEC_DCA)
3036 codec = HB_ACODEC_VORBIS;
3041 message = g_strdup_printf(
3042 "%s is not supported in the %s container.\n\n"
3043 "You should choose a different audio codec.\n"
3044 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3045 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3051 value = get_acodec_value(codec);
3052 ghb_settings_take_value(asettings, "AudioEncoder", value);
3054 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3055 gboolean allow_mono = TRUE;
3056 gboolean allow_stereo = TRUE;
3057 gboolean allow_dolby = TRUE;
3058 gboolean allow_dpl2 = TRUE;
3059 gboolean allow_6ch = TRUE;
3061 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3062 (codec != HB_ACODEC_LAME);
3063 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3065 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3067 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3068 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3069 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3070 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3072 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3073 (codec != HB_ACODEC_LAME) &&
3074 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3075 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3077 gchar *mix_unsup = NULL;
3078 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3082 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3084 mix_unsup = "stereo";
3086 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3088 mix_unsup = "Dolby";
3090 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3092 mix_unsup = "Dolby Pro Logic II";
3094 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3096 mix_unsup = "6 Channel";
3100 message = g_strdup_printf(
3101 "The source audio does not support %s mixdown.\n\n"
3102 "You should choose a different mixdown.\n"
3103 "If you continue, one will be chosen for you.", mix_unsup);
3104 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3110 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3111 value = get_amix_value(mix);
3112 ghb_settings_take_value(asettings, "AudioMixdown", value);
3119 ghb_validate_vquality(GValue *settings)
3125 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3126 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3128 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3129 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3133 case HB_VCODEC_X264:
3139 case HB_VCODEC_XVID:
3140 case HB_VCODEC_FFMPEG:
3146 case HB_VCODEC_THEORA:
3158 if (vquality < min || vquality > max)
3160 message = g_strdup_printf(
3161 "Interesting video quality choise: %d\n\n"
3162 "Typical values range from %d to %d.\n"
3163 "Are you sure you wish to use this setting?",
3164 (gint)vquality, min, max);
3165 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3166 "Cancel", "Continue"))
3178 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3183 static gchar *x264opts;
3185 gboolean tweaks = FALSE;
3186 gchar *detel_str = NULL;
3187 gchar *decomb_str = NULL;
3188 gchar *deint_str = NULL;
3189 gchar *deblock_str = NULL;
3190 gchar *denoise_str = NULL;
3191 gchar *dest_str = NULL;
3193 g_debug("add_job()\n");
3194 if (h == NULL) return;
3195 list = hb_get_titles( h );
3196 if( !hb_list_count( list ) )
3198 /* No valid title, stop right there */
3202 title = hb_list_item( list, titleindex );
3203 if (title == NULL) return;
3205 /* Set job settings */
3207 if (job == NULL) return;
3209 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3210 if (job->start_at_preview)
3212 job->seek_points = ghb_settings_get_int(js, "preview_count");
3213 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3216 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3217 job->mux = ghb_settings_combo_int(js, "FileFormat");
3218 if (job->mux == HB_MUX_MP4)
3220 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3221 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3225 job->largeFileSize = FALSE;
3226 job->mp4_optimize = FALSE;
3228 if (!job->start_at_preview)
3230 gint chapter_start, chapter_end;
3231 chapter_start = ghb_settings_get_int(js, "start_chapter");
3232 chapter_end = ghb_settings_get_int(js, "end_chapter");
3233 gint num_chapters = hb_list_count(title->list_chapter);
3234 job->chapter_start = MIN( num_chapters, chapter_start );
3235 job->chapter_end = MAX( job->chapter_start, chapter_end );
3237 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3238 if ( job->chapter_markers )
3245 chapters = ghb_settings_get_value(js, "chapter_list");
3246 count = ghb_array_len(chapters);
3247 for(chap = chapter_start; chap <= chapter_end; chap++)
3249 hb_chapter_t * chapter_s;
3255 chapter = ghb_array_get_nth(chapters, chap-1);
3256 name = ghb_value_string(chapter);
3260 name = g_strdup_printf ("Chapter %2d", chap);
3262 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3263 strncpy(chapter_s->title, name, 1023);
3264 chapter_s->title[1023] = '\0';
3269 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3270 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3271 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3272 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3275 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3276 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3278 job->deinterlace = (deint != 0) ? 1 : 0;
3280 job->deinterlace = 0;
3281 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3283 gboolean autoscale = ghb_settings_get_boolean(js, "autoscale");
3284 gboolean anamorphic = ghb_settings_get_boolean(js, "anamorphic");
3285 gboolean round_dimensions = ghb_settings_get_boolean(js, "ModDimensions");
3288 job->anamorphic.mode = autoscale ? 2 : 3;
3289 // Also, x264 requires things to be divisible by 2.
3290 job->anamorphic.modulus = round_dimensions ? 16 : 2;
3294 job->anamorphic.mode = 0;
3295 job->anamorphic.modulus = 2;
3297 /* Add selected filters */
3298 job->filters = hb_list_init();
3299 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3300 if( vrate == 0 && ghb_settings_combo_int(js, "PictureDetelecine" ) )
3305 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3310 if (detel_opts.map[detel].svalue != NULL)
3311 detel_str = g_strdup(detel_opts.map[detel].svalue);
3314 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3315 hb_filter_detelecine.settings = detel_str;
3316 hb_list_add( job->filters, &hb_filter_detelecine );
3322 if (decomb_opts.map[decomb].svalue != NULL)
3323 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3326 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3327 hb_filter_decomb.settings = decomb_str;
3328 hb_list_add( job->filters, &hb_filter_decomb );
3330 if( job->deinterlace )
3334 if (deint_opts.map[deint].svalue != NULL)
3335 deint_str = g_strdup(deint_opts.map[deint].svalue);
3338 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3339 hb_filter_deinterlace.settings = deint_str;
3340 hb_list_add( job->filters, &hb_filter_deinterlace );
3342 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3345 deblock_str = g_strdup_printf("%d", deblock);
3346 hb_filter_deblock.settings = deblock_str;
3347 hb_list_add( job->filters, &hb_filter_deblock );
3349 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3354 if (denoise_opts.map[denoise].svalue != NULL)
3355 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3358 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3359 hb_filter_denoise.settings = denoise_str;
3360 hb_list_add( job->filters, &hb_filter_denoise );
3362 job->width = ghb_settings_get_int(js, "scale_width");
3363 job->height = ghb_settings_get_int(js, "scale_height");
3365 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3366 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3367 (job->vcodec == HB_VCODEC_THEORA))
3369 // mp4|avi/theora combination is not supported.
3370 job->vcodec = HB_VCODEC_XVID;
3372 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3374 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3376 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3379 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3380 job->vquality = vquality;
3383 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3385 job->vquality = -1.0;
3386 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3388 // AVI container does not support variable frame rate.
3389 if (job->mux == HB_MUX_AVI)
3397 job->vrate = title->rate;
3398 job->vrate_base = title->rate_base;
3403 job->vrate = 27000000;
3404 job->vrate_base = vrate;
3407 // First remove any audios that are already in the list
3408 // This happens if you are encoding the same title a second time.
3409 gint num_audio_tracks = hb_list_count(job->list_audio);
3411 for(ii = 0; ii < num_audio_tracks; ii++)
3413 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3414 hb_list_rem(job->list_audio, audio);
3417 const GValue *audio_list;
3421 audio_list = ghb_settings_get_value(js, "audio_list");
3422 count = ghb_array_len(audio_list);
3423 for (ii = 0; ii < count; ii++)
3426 hb_audio_config_t audio;
3427 hb_audio_config_t *taudio;
3429 hb_audio_config_init(&audio);
3430 asettings = ghb_array_get_nth(audio_list, ii);
3431 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3432 audio.out.track = tcount;
3433 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3434 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3435 title->list_audio, audio.in.track );
3436 if ((taudio->in.codec != HB_ACODEC_AC3 &&
3437 audio.out.codec == HB_ACODEC_AC3) ||
3438 (taudio->in.codec != HB_ACODEC_DCA &&
3439 audio.out.codec == HB_ACODEC_DCA))
3441 // Not supported. AC3 is passthrough only, so input must be AC3
3442 if (job->mux == HB_MUX_AVI)
3444 audio.out.codec = HB_ACODEC_LAME;
3448 audio.out.codec = HB_ACODEC_FAAC;
3451 if ((job->mux == HB_MUX_MP4) &&
3452 ((audio.out.codec == HB_ACODEC_LAME) ||
3453 (audio.out.codec == HB_ACODEC_VORBIS)))
3455 // mp4/mp3|vorbis combination is not supported.
3456 audio.out.codec = HB_ACODEC_FAAC;
3458 if ((job->mux == HB_MUX_AVI) &&
3459 ((audio.out.codec == HB_ACODEC_FAAC) ||
3460 (audio.out.codec == HB_ACODEC_VORBIS)))
3462 // avi/faac|vorbis combination is not supported.
3463 audio.out.codec = HB_ACODEC_LAME;
3465 if ((job->mux == HB_MUX_OGM) &&
3466 ((audio.out.codec == HB_ACODEC_FAAC) ||
3467 (audio.out.codec == HB_ACODEC_AC3) ||
3468 (audio.out.codec == HB_ACODEC_DCA)))
3470 // ogm/faac|ac3 combination is not supported.
3471 audio.out.codec = HB_ACODEC_VORBIS;
3473 audio.out.dynamic_range_compression =
3474 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3475 // It would be better if this were done in libhb for us, but its not yet.
3476 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3478 audio.out.mixdown = 0;
3482 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3483 // Make sure the mixdown is valid and pick a new one if not.
3484 audio.out.mixdown = ghb_get_best_mix(titleindex,
3485 audio.in.track, audio.out.codec, audio.out.mixdown);
3487 ghb_settings_combo_int(asettings, "AudioBitrate");
3488 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3489 if (srate == 0) // 0 is same as source
3490 audio.out.samplerate = taudio->in.samplerate;
3492 audio.out.samplerate = srate;
3495 // Add it to the jobs audio list
3496 hb_audio_add( job, &audio );
3499 // I was tempted to move this up with the reset of the video quality
3500 // settings, but I suspect the settings above need to be made
3501 // first in order for hb_calc_bitrate to be accurate.
3502 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3506 size = ghb_settings_get_int(js, "VideoTargetSize");
3507 job->vbitrate = hb_calc_bitrate( job, size );
3508 job->vquality = -1.0;
3511 dest_str = ghb_settings_get_string(js, "destination");
3512 job->file = dest_str;
3513 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3514 // TODO: libhb holds onto a reference to the x264opts and is not
3515 // finished with it until encoding the job is done. But I can't
3516 // find a way to get at the job before it is removed in order to
3517 // free up the memory I am allocating here.
3518 // The short story is THIS LEAKS.
3519 x264opts = ghb_build_x264opts_string(js);
3521 if( x264opts != NULL && *x264opts != '\0' )
3523 job->x264opts = x264opts;
3525 else /*avoids a bus error crash when options aren't specified*/
3527 job->x264opts = NULL;
3530 gchar *slang = ghb_settings_get_string(js, "Subtitles");
3531 subtitle = -2; // default to none
3532 if (strcmp(slang, "auto") == 0)
3539 hb_subtitle_t * subt;
3541 scount = hb_list_count(title->list_subtitle);
3542 for (ii = 0; ii < scount; ii++)
3544 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
3545 if (strcmp(slang, subt->iso639_2) == 0)
3552 gboolean forced_subtitles = ghb_settings_get_boolean(js, "SubtitlesForced");
3553 job->subtitle_force = forced_subtitles;
3555 job->subtitle = subtitle;
3560 // Subtitle scan. Look for subtitle matching audio language
3564 * When subtitle scan is enabled do a fast pre-scan job
3565 * which will determine which subtitles to enable, if any.
3568 job->indepth_scan = 1;
3570 x264opts_tmp = job->x264opts;
3571 job->x264opts = NULL;
3573 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3574 *(job->select_subtitle) = NULL;
3577 * Add the pre-scan job
3579 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3581 //if (job->x264opts != NULL)
3582 // g_free(job->x264opts);
3584 job->x264opts = x264opts_tmp;
3588 job->select_subtitle = NULL;
3590 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
3591 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3594 * If subtitle_scan is enabled then only turn it on
3595 * for the second pass and then off again for the
3598 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3599 job->select_subtitle = NULL;
3601 job->indepth_scan = 0;
3602 gchar *x264opts2 = NULL;
3605 x264opts2 = g_strdup(x264opts);
3608 * If turbo options have been selected then append them
3609 * to the x264opts now (size includes one ':' and the '\0')
3611 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
3617 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3623 * No x264opts to modify, but apply the turbo options
3624 * anyway as they may be modifying defaults
3626 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3628 x264opts = tmp_x264opts;
3630 job->x264opts = x264opts;
3632 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3634 //if (job->x264opts != NULL)
3635 // g_free(job->x264opts);
3637 job->select_subtitle = subtitle_tmp;
3640 * On the second pass we turn off subtitle scan so that we
3641 * can actually encode using any subtitles that were auto
3642 * selected in the first pass (using the whacky select-subtitle
3643 * attribute of the job).
3645 job->indepth_scan = 0;
3646 job->x264opts = x264opts2;
3647 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3649 //if (job->x264opts != NULL)
3650 // g_free(job->x264opts);
3654 job->indepth_scan = 0;
3656 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3658 //if (job->x264opts != NULL)
3659 // g_free(job->x264opts);
3661 if (detel_str) g_free(detel_str);
3662 if (decomb_str) g_free(decomb_str);
3663 if (deint_str) g_free(deint_str);
3664 if (deblock_str) g_free(deblock_str);
3665 if (denoise_str) g_free(denoise_str);
3666 if (dest_str) g_free(dest_str);
3670 ghb_add_job(GValue *js, gint unique_id)
3672 // Since I'm doing a scan of the single title I want just prior
3673 // to adding the job, there is only the one title to choose from.
3674 add_job(h_queue, js, unique_id, 0);
3678 ghb_add_live_job(GValue *js, gint unique_id)
3680 // Since I'm doing a scan of the single title I want just prior
3681 // to adding the job, there is only the one title to choose from.
3682 gint titleindex = ghb_settings_combo_int(js, "title");
3683 add_job(h_scan, js, unique_id, titleindex);
3687 ghb_remove_job(gint unique_id)
3692 // Multiples passes all get the same id
3694 // Go backwards through list, so reordering doesn't screw me.
3695 ii = hb_count(h_queue) - 1;
3696 while ((job = hb_job(h_queue, ii--)) != NULL)
3698 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3699 hb_rem(h_queue, job);
3706 hb_start( h_queue );
3716 ghb_start_live_encode()
3722 ghb_stop_live_encode()
3731 hb_get_state2( h_queue, &s );
3733 if( s.state == HB_STATE_PAUSED )
3735 hb_resume( h_queue );
3739 hb_pause( h_queue );
3743 #define RED_HEIGHT 720.0
3744 #define RED_WIDTH 1280.0
3747 ghb_get_preview_image(
3750 signal_user_data_t *ud,
3759 settings = ud->settings;
3760 list = hb_get_titles( h_scan );
3761 if( !hb_list_count( list ) )
3763 /* No valid title, stop right there */
3766 title = hb_list_item( list, titleindex );
3767 if (title == NULL) return NULL;
3768 if (title->job == NULL) return NULL;
3769 set_preview_job_settings(title->job, settings);
3771 // hb_get_preview can't handle sizes that are larger than the original title
3773 if (title->job->width > title->width)
3774 title->job->width = title->width;
3776 if (title->job->height > title->height)
3777 title->job->height = title->height;
3778 // And also creates artifacts if the width is not a multiple of 8
3779 //title->job->width = ((title->job->width + 4) >> 3) << 3;
3780 // And the height must be a multiple of 2
3781 //title->job->height = ((title->job->height + 1) >> 1) << 1;
3783 // Make sure we have a big enough buffer to receive the image from libhb. libhb
3784 // creates images with a one-pixel border around the original content. Hence we
3785 // add 2 pixels horizontally and vertically to the buffer size.
3786 gint srcWidth = title->width + 2;
3787 gint srcHeight= title->height + 2;
3788 gint dstWidth = title->width;
3789 gint dstHeight= title->height;
3791 gint borderLeft = 1;
3794 // |<---------- title->width ----------->|
3795 // | |<---- title->job->width ---->| |
3797 // .......................................
3798 // ....+-----------------------------+....
3799 // ....| |....<-- gray border
3802 // ....| |<------- image
3808 // ....+-----------------------------+....
3809 // .......................................
3810 dstWidth = title->job->width;
3811 dstHeight = title->job->height;
3812 borderTop = (srcHeight - dstHeight) / 2;
3813 borderLeft = (srcWidth - dstWidth) / 2;
3814 g_debug("boarders removed\n");
3817 g_debug("src %d x %d\n", srcWidth, srcHeight);
3818 g_debug("dst %d x %d\n", dstWidth, dstHeight);
3819 g_debug("job dim %d x %d\n", title->job->width, title->job->height);
3820 g_debug("title crop %d:%d:%d:%d\n",
3825 g_debug("job crop %d:%d:%d:%d\n",
3826 title->job->crop[0],
3827 title->job->crop[1],
3828 title->job->crop[2],
3829 title->job->crop[3]);
3830 static guint8 *buffer = NULL;
3831 static gint bufferSize = 0;
3834 newSize = srcWidth * srcHeight * 4;
3835 if( bufferSize < newSize )
3837 bufferSize = newSize;
3838 buffer = (guint8*) g_realloc( buffer, bufferSize );
3840 hb_get_preview( h_scan, title, index, buffer );
3842 // Create an GdkPixbuf and copy the libhb image into it, converting it from
3843 // libhb's format something suitable. Along the way, we'll strip off the
3844 // border around libhb's image.
3846 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
3847 // Alpha is ignored.
3849 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
3850 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
3852 guint32 *src = (guint32*)buffer;
3853 guint8 *dst = pixels;
3854 src += borderTop * srcWidth; // skip top rows in src to get to first row of dst
3855 src += borderLeft; // skip left pixels in src to get to first pixel of dst
3857 gint channels = gdk_pixbuf_get_n_channels (preview);
3858 gint stride = gdk_pixbuf_get_rowstride (preview);
3860 for (ii = 0; ii < dstHeight; ii++)
3863 for (jj = 0; jj < dstWidth; jj++)
3865 tmp[0] = src[0] >> 16;
3866 tmp[1] = src[0] >> 8;
3867 tmp[2] = src[0] >> 0;
3872 src += (srcWidth - dstWidth); // skip to next row in src
3874 // Got it, but hb_get_preview doesn't compensate for anamorphic, so lets
3876 gint width, height, par_width, par_height;
3877 gboolean anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
3880 hb_set_anamorphic_size( title->job, &width, &height, &par_width, &par_height );
3881 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
3885 ghb_par_scale(ud, &dstWidth, &dstHeight, 1, 1);
3887 *out_width = dstWidth;
3888 *out_height = dstHeight;
3889 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
3895 ss = gdk_screen_get_default();
3896 s_w = gdk_screen_get_width(ss);
3897 s_h = gdk_screen_get_height(ss);
3898 num = dstWidth * par_width;
3899 den = dstHeight * par_height;
3901 if (dstWidth > s_w * 80 / 100)
3903 dstWidth = s_w * 80 / 100;
3904 dstHeight = dstWidth * den / num;
3906 if (dstHeight > s_h * 80 / 100)
3908 dstHeight = s_h * 80 / 100;
3909 dstWidth = dstHeight * num / den;
3912 g_debug("scaled %d x %d\n", dstWidth, dstHeight);
3913 GdkPixbuf *scaled_preview;
3914 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
3915 g_object_unref (preview);
3916 return scaled_preview;
3920 sanitize_volname(gchar *name)
3945 ghb_dvd_volname(const gchar *device)
3948 name = hb_dvd_name((gchar*)device);
3951 sanitize_volname(name);
3952 return g_strdup(name);