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"
40 const gchar *shortOpt;
51 static const gchar *index_str[] =
66 static options_map_t d_par_opts[] =
69 {"Strict", "1", 1, "1"},
70 {"Loose", "2", 2, "2"},
71 {"Custom", "3", 3, "3"},
73 combo_opts_t par_opts =
75 sizeof(d_par_opts)/sizeof(options_map_t),
79 static options_map_t d_alignment_opts[] =
84 {"16", "16", 16, "16"},
86 combo_opts_t alignment_opts =
88 sizeof(d_alignment_opts)/sizeof(options_map_t),
92 static options_map_t d_logging_opts[] =
98 combo_opts_t logging_opts =
100 sizeof(d_logging_opts)/sizeof(options_map_t),
104 static options_map_t d_vqual_granularity_opts[] =
106 {"0.2", "0.2", 0.2, "0.2"},
107 {"0.25", "0.25", 0.25, "0.25"},
108 {"0.5", "0.5", 0.5, "0.5"},
111 combo_opts_t vqual_granularity_opts =
113 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
114 d_vqual_granularity_opts
117 static options_map_t d_container_opts[] =
119 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
120 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
121 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
123 combo_opts_t container_opts =
125 sizeof(d_container_opts)/sizeof(options_map_t),
129 static options_map_t d_detel_opts[] =
131 {"None", "none", 0, ""},
132 {"Custom", "custom", 1, ""},
133 {"Default","default",2, NULL},
135 combo_opts_t detel_opts =
137 sizeof(d_detel_opts)/sizeof(options_map_t),
141 static options_map_t d_decomb_opts[] =
143 {"None", "none", 0, ""},
144 {"Custom", "custom", 1, ""},
145 {"Default","default",2, NULL},
147 combo_opts_t decomb_opts =
149 sizeof(d_decomb_opts)/sizeof(options_map_t),
153 static options_map_t d_deint_opts[] =
155 {"None", "none", 0, ""},
156 {"Custom", "custom", 1, ""},
157 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
158 {"Slow", "slow", 3, "2:-1:-1:0:1"},
159 {"Slower", "slower", 4, "0:-1:-1:0:1"},
161 combo_opts_t deint_opts =
163 sizeof(d_deint_opts)/sizeof(options_map_t),
167 static options_map_t d_denoise_opts[] =
169 {"None", "none", 0, ""},
170 {"Custom", "custom", 1, ""},
171 {"Weak", "weak", 2, "2:1:2:3"},
172 {"Medium", "medium", 3, "3:2:2:3"},
173 {"Strong", "strong", 4, "7:7:5:5"},
175 combo_opts_t denoise_opts =
177 sizeof(d_denoise_opts)/sizeof(options_map_t),
181 static options_map_t d_vcodec_opts[] =
183 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
184 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
185 {"Theora", "theora", HB_VCODEC_THEORA, ""},
187 combo_opts_t vcodec_opts =
189 sizeof(d_vcodec_opts)/sizeof(options_map_t),
193 static options_map_t d_acodec_opts[] =
195 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
196 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
197 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
198 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
199 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
200 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
202 combo_opts_t acodec_opts =
204 sizeof(d_acodec_opts)/sizeof(options_map_t),
208 static options_map_t d_direct_opts[] =
210 {"None", "none", 0, "none"},
211 {"Spatial", "spatial", 1, "spatial"},
212 {"Temporal", "temporal", 2, "temporal"},
213 {"Automatic", "auto", 3, "auto"},
215 combo_opts_t direct_opts =
217 sizeof(d_direct_opts)/sizeof(options_map_t),
221 static options_map_t d_badapt_opts[] =
223 {"Off", "0", 0, "0"},
224 {"Fast", "1", 1, "1"},
225 {"Optimal", "2", 2, "2"},
227 combo_opts_t badapt_opts =
229 sizeof(d_badapt_opts)/sizeof(options_map_t),
233 static options_map_t d_me_opts[] =
235 {"Diamond", "dia", 0, "dia"},
236 {"Hexagon", "hex", 1, "hex"},
237 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
238 {"Exhaustive", "esa", 3, "esa"},
239 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
241 combo_opts_t me_opts =
243 sizeof(d_me_opts)/sizeof(options_map_t),
247 static options_map_t d_subme_opts[] =
259 combo_opts_t subme_opts =
261 sizeof(d_subme_opts)/sizeof(options_map_t),
265 static options_map_t d_analyse_opts[] =
267 {"Some", "some", 0, "some"},
268 {"None", "none", 1, "none"},
269 {"All", "all", 2, "all"},
270 {"Custom", "custom", 3, "all"},
272 combo_opts_t analyse_opts =
274 sizeof(d_analyse_opts)/sizeof(options_map_t),
278 static options_map_t d_trellis_opts[] =
280 {"Disabled", "0", 0, "0"},
281 {"Final Macro Block", "1", 1, "1"},
282 {"Always", "2", 2, "2"},
284 combo_opts_t trellis_opts =
286 sizeof(d_trellis_opts)/sizeof(options_map_t),
290 combo_opts_t subtitle_opts =
296 combo_opts_t title_opts =
302 combo_opts_t audio_track_opts =
314 combo_name_map_t combo_name_map[] =
316 {"PicturePAR", &par_opts},
317 {"PictureModulus", &alignment_opts},
318 {"LoggingLevel", &logging_opts},
319 {"VideoQualityGranularity", &vqual_granularity_opts},
320 {"FileFormat", &container_opts},
321 {"PictureDeinterlace", &deint_opts},
322 {"PictureDecomb", &decomb_opts},
323 {"PictureDetelecine", &detel_opts},
324 {"PictureDenoise", &denoise_opts},
325 {"VideoEncoder", &vcodec_opts},
326 {"AudioEncoder", &acodec_opts},
327 {"x264_direct", &direct_opts},
328 {"x264_b_adapt", &badapt_opts},
329 {"x264_me", &me_opts},
330 {"x264_subme", &subme_opts},
331 {"x264_analyse", &analyse_opts},
332 {"x264_trellis", &trellis_opts},
333 {"Subtitles", &subtitle_opts},
334 {"title", &title_opts},
335 {"AudioTrack", &audio_track_opts},
340 typedef struct iso639_lang_t
342 char * eng_name; /* Description in English */
343 char * native_name; /* Description in native language */
344 char * iso639_1; /* ISO-639-1 (2 characters) code */
345 char * iso639_2; /* ISO-639-2/t (3 character) code */
346 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
350 const iso639_lang_t ghb_language_table[] =
352 { "Any", "", "zz", "und" },
353 { "Afar", "", "aa", "aar" },
354 { "Abkhazian", "", "ab", "abk" },
355 { "Afrikaans", "", "af", "afr" },
356 { "Akan", "", "ak", "aka" },
357 { "Albanian", "", "sq", "sqi", "alb" },
358 { "Amharic", "", "am", "amh" },
359 { "Arabic", "", "ar", "ara" },
360 { "Aragonese", "", "an", "arg" },
361 { "Armenian", "", "hy", "hye", "arm" },
362 { "Assamese", "", "as", "asm" },
363 { "Avaric", "", "av", "ava" },
364 { "Avestan", "", "ae", "ave" },
365 { "Aymara", "", "ay", "aym" },
366 { "Azerbaijani", "", "az", "aze" },
367 { "Bashkir", "", "ba", "bak" },
368 { "Bambara", "", "bm", "bam" },
369 { "Basque", "", "eu", "eus", "baq" },
370 { "Belarusian", "", "be", "bel" },
371 { "Bengali", "", "bn", "ben" },
372 { "Bihari", "", "bh", "bih" },
373 { "Bislama", "", "bi", "bis" },
374 { "Bosnian", "", "bs", "bos" },
375 { "Breton", "", "br", "bre" },
376 { "Bulgarian", "", "bg", "bul" },
377 { "Burmese", "", "my", "mya", "bur" },
378 { "Catalan", "", "ca", "cat" },
379 { "Chamorro", "", "ch", "cha" },
380 { "Chechen", "", "ce", "che" },
381 { "Chinese", "", "zh", "zho", "chi" },
382 { "Church Slavic", "", "cu", "chu" },
383 { "Chuvash", "", "cv", "chv" },
384 { "Cornish", "", "kw", "cor" },
385 { "Corsican", "", "co", "cos" },
386 { "Cree", "", "cr", "cre" },
387 { "Czech", "", "cs", "ces", "cze" },
388 { "Danish", "Dansk", "da", "dan" },
389 { "Divehi", "", "dv", "div" },
390 { "Dutch", "Nederlands", "nl", "nld", "dut" },
391 { "Dzongkha", "", "dz", "dzo" },
392 { "English", "English", "en", "eng" },
393 { "Esperanto", "", "eo", "epo" },
394 { "Estonian", "", "et", "est" },
395 { "Ewe", "", "ee", "ewe" },
396 { "Faroese", "", "fo", "fao" },
397 { "Fijian", "", "fj", "fij" },
398 { "Finnish", "Suomi", "fi", "fin" },
399 { "French", "Francais", "fr", "fra", "fre" },
400 { "Western Frisian", "", "fy", "fry" },
401 { "Fulah", "", "ff", "ful" },
402 { "Georgian", "", "ka", "kat", "geo" },
403 { "German", "Deutsch", "de", "deu", "ger" },
404 { "Gaelic (Scots)", "", "gd", "gla" },
405 { "Irish", "", "ga", "gle" },
406 { "Galician", "", "gl", "glg" },
407 { "Manx", "", "gv", "glv" },
408 { "Greek, Modern", "", "el", "ell", "gre" },
409 { "Guarani", "", "gn", "grn" },
410 { "Gujarati", "", "gu", "guj" },
411 { "Haitian", "", "ht", "hat" },
412 { "Hausa", "", "ha", "hau" },
413 { "Hebrew", "", "he", "heb" },
414 { "Herero", "", "hz", "her" },
415 { "Hindi", "", "hi", "hin" },
416 { "Hiri Motu", "", "ho", "hmo" },
417 { "Hungarian", "Magyar", "hu", "hun" },
418 { "Igbo", "", "ig", "ibo" },
419 { "Icelandic", "Islenska", "is", "isl", "ice" },
420 { "Ido", "", "io", "ido" },
421 { "Sichuan Yi", "", "ii", "iii" },
422 { "Inuktitut", "", "iu", "iku" },
423 { "Interlingue", "", "ie", "ile" },
424 { "Interlingua", "", "ia", "ina" },
425 { "Indonesian", "", "id", "ind" },
426 { "Inupiaq", "", "ik", "ipk" },
427 { "Italian", "Italiano", "it", "ita" },
428 { "Javanese", "", "jv", "jav" },
429 { "Japanese", "", "ja", "jpn" },
430 { "Kalaallisut", "", "kl", "kal" },
431 { "Kannada", "", "kn", "kan" },
432 { "Kashmiri", "", "ks", "kas" },
433 { "Kanuri", "", "kr", "kau" },
434 { "Kazakh", "", "kk", "kaz" },
435 { "Central Khmer", "", "km", "khm" },
436 { "Kikuyu", "", "ki", "kik" },
437 { "Kinyarwanda", "", "rw", "kin" },
438 { "Kirghiz", "", "ky", "kir" },
439 { "Komi", "", "kv", "kom" },
440 { "Kongo", "", "kg", "kon" },
441 { "Korean", "", "ko", "kor" },
442 { "Kuanyama", "", "kj", "kua" },
443 { "Kurdish", "", "ku", "kur" },
444 { "Lao", "", "lo", "lao" },
445 { "Latin", "", "la", "lat" },
446 { "Latvian", "", "lv", "lav" },
447 { "Limburgan", "", "li", "lim" },
448 { "Lingala", "", "ln", "lin" },
449 { "Lithuanian", "", "lt", "lit" },
450 { "Luxembourgish", "", "lb", "ltz" },
451 { "Luba-Katanga", "", "lu", "lub" },
452 { "Ganda", "", "lg", "lug" },
453 { "Macedonian", "", "mk", "mkd", "mac" },
454 { "Marshallese", "", "mh", "mah" },
455 { "Malayalam", "", "ml", "mal" },
456 { "Maori", "", "mi", "mri", "mao" },
457 { "Marathi", "", "mr", "mar" },
458 { "Malay", "", "ms", "msa", "msa" },
459 { "Malagasy", "", "mg", "mlg" },
460 { "Maltese", "", "mt", "mlt" },
461 { "Moldavian", "", "mo", "mol" },
462 { "Mongolian", "", "mn", "mon" },
463 { "Nauru", "", "na", "nau" },
464 { "Navajo", "", "nv", "nav" },
465 { "Ndebele, South", "", "nr", "nbl" },
466 { "Ndebele, North", "", "nd", "nde" },
467 { "Ndonga", "", "ng", "ndo" },
468 { "Nepali", "", "ne", "nep" },
469 { "Norwegian Nynorsk", "", "nn", "nno" },
470 { "Norwegian Bokmål", "", "nb", "nob" },
471 { "Norwegian", "Norsk", "no", "nor" },
472 { "Chichewa; Nyanja", "", "ny", "nya" },
473 { "Occitan", "", "oc", "oci" },
474 { "Ojibwa", "", "oj", "oji" },
475 { "Oriya", "", "or", "ori" },
476 { "Oromo", "", "om", "orm" },
477 { "Ossetian", "", "os", "oss" },
478 { "Panjabi", "", "pa", "pan" },
479 { "Persian", "", "fa", "fas", "per" },
480 { "Pali", "", "pi", "pli" },
481 { "Polish", "", "pl", "pol" },
482 { "Portuguese", "Portugues", "pt", "por" },
483 { "Pushto", "", "ps", "pus" },
484 { "Quechua", "", "qu", "que" },
485 { "Romansh", "", "rm", "roh" },
486 { "Romanian", "", "ro", "ron", "rum" },
487 { "Rundi", "", "rn", "run" },
488 { "Russian", "", "ru", "rus" },
489 { "Sango", "", "sg", "sag" },
490 { "Sanskrit", "", "sa", "san" },
491 { "Serbian", "", "sr", "srp", "scc" },
492 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
493 { "Sinhala", "", "si", "sin" },
494 { "Slovak", "", "sk", "slk", "slo" },
495 { "Slovenian", "", "sl", "slv" },
496 { "Northern Sami", "", "se", "sme" },
497 { "Samoan", "", "sm", "smo" },
498 { "Shona", "", "sn", "sna" },
499 { "Sindhi", "", "sd", "snd" },
500 { "Somali", "", "so", "som" },
501 { "Sotho, Southern", "", "st", "sot" },
502 { "Spanish", "Espanol", "es", "spa" },
503 { "Sardinian", "", "sc", "srd" },
504 { "Swati", "", "ss", "ssw" },
505 { "Sundanese", "", "su", "sun" },
506 { "Swahili", "", "sw", "swa" },
507 { "Swedish", "Svenska", "sv", "swe" },
508 { "Tahitian", "", "ty", "tah" },
509 { "Tamil", "", "ta", "tam" },
510 { "Tatar", "", "tt", "tat" },
511 { "Telugu", "", "te", "tel" },
512 { "Tajik", "", "tg", "tgk" },
513 { "Tagalog", "", "tl", "tgl" },
514 { "Thai", "", "th", "tha" },
515 { "Tibetan", "", "bo", "bod", "tib" },
516 { "Tigrinya", "", "ti", "tir" },
517 { "Tonga", "", "to", "ton" },
518 { "Tswana", "", "tn", "tsn" },
519 { "Tsonga", "", "ts", "tso" },
520 { "Turkmen", "", "tk", "tuk" },
521 { "Turkish", "", "tr", "tur" },
522 { "Twi", "", "tw", "twi" },
523 { "Uighur", "", "ug", "uig" },
524 { "Ukrainian", "", "uk", "ukr" },
525 { "Urdu", "", "ur", "urd" },
526 { "Uzbek", "", "uz", "uzb" },
527 { "Venda", "", "ve", "ven" },
528 { "Vietnamese", "", "vi", "vie" },
529 { "Volapük", "", "vo", "vol" },
530 { "Welsh", "", "cy", "cym", "wel" },
531 { "Walloon", "", "wa", "wln" },
532 { "Wolof", "", "wo", "wol" },
533 { "Xhosa", "", "xh", "xho" },
534 { "Yiddish", "", "yi", "yid" },
535 { "Yoruba", "", "yo", "yor" },
536 { "Zhuang", "", "za", "zha" },
537 { "Zulu", "", "zu", "zul" },
538 {NULL, NULL, NULL, NULL}
540 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
542 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
545 del_tree(const gchar *name, gboolean del_top)
549 if (g_file_test(name, G_FILE_TEST_IS_DIR))
551 GDir *gdir = g_dir_open(name, 0, NULL);
552 file = g_dir_read_name(gdir);
556 path = g_strdup_printf("%s/%s", name, file);
557 del_tree(path, TRUE);
559 file = g_dir_read_name(gdir);
574 return hb_get_version(NULL);
579 signal_user_data_t *ud,
587 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
596 *step = ghb_settings_combo_double(ud->settings,
597 "VideoQualityGranularity");
598 if (*step == 0.2 || *step == 0.5)
600 else if (*step == 0.25)
606 case HB_VCODEC_FFMPEG:
614 case HB_VCODEC_THEORA:
633 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
639 str = ghb_value_string(gval);
640 for (ii = 0; ii < opts->count; ii++)
642 if (strcmp(opts->map[ii].shortOpt, str) == 0)
644 result = opts->map[ii].ivalue;
653 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
659 str = ghb_value_string(gval);
660 for (ii = 0; ii < opts->count; ii++)
662 if (strcmp(opts->map[ii].shortOpt, str) == 0)
664 result = opts->map[ii].ivalue;
673 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
677 const gchar *result = "";
679 str = ghb_value_string(gval);
680 for (ii = 0; ii < opts->count; ii++)
682 if (strcmp(opts->map[ii].shortOpt, str) == 0)
684 result = opts->map[ii].option;
693 lookup_mix_int(const GValue *mix)
700 str = ghb_value_string(mix);
701 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
703 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
705 result = hb_audio_mixdowns[ii].amixdown;
714 lookup_mix_option(const GValue *mix)
718 gchar *result = "None";
721 str = ghb_value_string(mix);
722 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
724 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
726 result = hb_audio_mixdowns[ii].human_readable_name;
735 lookup_video_rate_int(const GValue *vrate)
741 str = ghb_value_string(vrate);
742 for (ii = 0; ii < hb_video_rates_count; ii++)
744 if (strcmp(hb_video_rates[ii].string, str) == 0)
746 result = hb_video_rates[ii].rate;
751 // Default to "same as source"
756 lookup_video_rate_option(const GValue *vrate)
760 const gchar *result = "Same as source";
762 str = ghb_value_string(vrate);
763 for (ii = 0; ii < hb_video_rates_count; ii++)
765 if (strcmp(hb_video_rates[ii].string, str) == 0)
767 result = hb_video_rates[ii].string;
772 // Default to "same as source"
777 lookup_audio_rate_int(const GValue *rate)
783 // Coincidentally, the string "source" will return 0
784 // which is our flag to use "same as source"
785 str = ghb_value_string(rate);
786 for (ii = 0; ii < hb_audio_rates_count; ii++)
788 if (strcmp(hb_audio_rates[ii].string, str) == 0)
790 result = hb_audio_rates[ii].rate;
799 lookup_audio_rate_option(const GValue *rate)
803 const gchar *result = "Same as source";
805 // Coincidentally, the string "source" will return 0
806 // which is our flag to use "same as source"
807 str = ghb_value_string(rate);
808 for (ii = 0; ii < hb_audio_rates_count; ii++)
810 if (strcmp(hb_audio_rates[ii].string, str) == 0)
812 result = hb_audio_rates[ii].string;
821 lookup_audio_bitrate_int(const GValue *rate)
827 // Coincidentally, the string "source" will return 0
828 // which is our flag to use "same as source"
829 str = ghb_value_string(rate);
830 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
832 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
834 result = hb_audio_bitrates[ii].rate;
843 lookup_audio_bitrate_option(const GValue *rate)
847 const gchar *result = "Same as source";
849 // Coincidentally, the string "source" will return 0
850 // which is our flag to use "same as source"
851 str = ghb_value_string(rate);
852 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
854 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
856 result = hb_audio_bitrates[ii].string;
865 lookup_audio_lang_int(const GValue *rate)
871 // Coincidentally, the string "source" will return 0
872 // which is our flag to use "same as source"
873 str = ghb_value_string(rate);
874 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
876 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
887 lookup_audio_lang_option(const GValue *rate)
891 const gchar *result = "Same as source";
893 // Coincidentally, the string "source" will return 0
894 // which is our flag to use "same as source"
895 str = ghb_value_string(rate);
896 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
898 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
900 result = ghb_language_table[ii].eng_name;
909 get_acodec_value(gint val)
911 GValue *value = NULL;
914 for (ii = 0; ii < acodec_opts.count; ii++)
916 if ((int)acodec_opts.map[ii].ivalue == val)
918 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
927 get_abitrate_value(gint val)
929 GValue *value = NULL;
932 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
934 if (hb_audio_bitrates[ii].rate == val)
936 value = ghb_string_value_new(hb_audio_bitrates[ii].string);
945 get_amix_value(gint val)
947 GValue *value = NULL;
950 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
952 if (hb_audio_mixdowns[ii].amixdown == val)
954 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
961 // Handle for libhb. Gets set by ghb_backend_init()
962 static hb_handle_t * h_scan = NULL;
963 static hb_handle_t * h_queue = NULL;
965 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
972 hb_get_tempory_directory(h_scan, dir);
973 return g_strdup(dir);
977 ghb_hb_cleanup(gboolean partial)
981 hb_get_tempory_directory(h_scan, dir);
982 del_tree(dir, !partial);
986 ghb_get_title_number(gint titleindex)
991 if (h_scan == NULL) return 1;
992 list = hb_get_titles( h_scan );
993 if( !hb_list_count( list ) )
995 /* No valid title, stop right there */
998 title = hb_list_item( list, titleindex );
999 if (title == NULL) return 1; // Bad titleindex
1000 return title->index;
1003 static hb_audio_config_t*
1004 get_hb_audio(gint titleindex, gint track)
1008 hb_audio_config_t *audio = NULL;
1010 if (h_scan == NULL) return NULL;
1011 list = hb_get_titles( h_scan );
1012 if( !hb_list_count( list ) )
1014 /* No valid title, stop right there */
1017 title = hb_list_item( list, titleindex );
1018 if (title == NULL) return NULL; // Bad titleindex
1019 if (!hb_list_count(title->list_audio))
1023 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1028 search_rates(hb_rate_t *rates, gint rate, gint count)
1031 for (ii = 0; ii < count; ii++)
1033 if (rates[ii].rate == rate)
1039 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1041 static GtkListStore*
1042 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1045 GtkListStore *store;
1047 g_debug("get_combo_box_store() %s\n", name);
1048 // First modify the combobox model to allow greying out of options
1049 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1050 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1055 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1057 GtkListStore *store;
1060 store = get_combo_box_store(builder, name);
1061 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1063 gtk_list_store_set(store, &iter,
1070 ghb_grey_combo_options(GtkBuilder *builder)
1073 gint container, track, titleindex, acodec;
1074 hb_audio_config_t *audio = NULL;
1077 widget = GHB_WIDGET (builder, "title");
1078 gval = ghb_widget_value(widget);
1079 titleindex = ghb_lookup_combo_int("title", gval);
1080 ghb_value_free(gval);
1081 widget = GHB_WIDGET (builder, "AudioTrack");
1082 gval = ghb_widget_value(widget);
1083 track = ghb_lookup_combo_int("AudioTrack", gval);
1084 ghb_value_free(gval);
1085 audio = get_hb_audio(titleindex, track);
1086 widget = GHB_WIDGET (builder, "FileFormat");
1087 gval = ghb_widget_value(widget);
1088 container = ghb_lookup_combo_int("FileFormat", gval);
1089 ghb_value_free(gval);
1091 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1092 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1093 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1094 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1096 gboolean allow_dca = TRUE;
1097 allow_dca = (container != HB_MUX_MP4);
1099 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1101 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1103 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1105 if (audio && audio->in.codec != HB_ACODEC_AC3)
1107 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1109 if (audio && audio->in.codec != HB_ACODEC_DCA)
1111 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1113 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1115 widget = GHB_WIDGET (builder, "AudioEncoder");
1116 gval = ghb_widget_value(widget);
1117 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1118 ghb_value_free(gval);
1119 if (acodec != HB_ACODEC_AC3)
1121 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1123 if (container == HB_MUX_MP4)
1125 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1126 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1127 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1129 else if (container == HB_MUX_AVI)
1131 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1132 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1133 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1135 else if (container == HB_MUX_OGM)
1137 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1140 gboolean allow_mono = TRUE;
1141 gboolean allow_stereo = TRUE;
1142 gboolean allow_dolby = TRUE;
1143 gboolean allow_dpl2 = TRUE;
1144 gboolean allow_6ch = TRUE;
1148 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1149 (acodec != HB_ACODEC_LAME);
1150 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1152 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1154 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1155 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1156 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1157 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1159 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1160 (acodec != HB_ACODEC_LAME) &&
1161 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1162 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1164 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1165 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1166 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1167 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1168 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1172 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1174 hb_audio_config_t *audio = NULL;
1175 gboolean allow_mono = TRUE;
1176 gboolean allow_stereo = TRUE;
1177 gboolean allow_dolby = TRUE;
1178 gboolean allow_dpl2 = TRUE;
1179 gboolean allow_6ch = TRUE;
1181 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1183 // Audio codec pass-thru. No mixdown
1186 audio = get_hb_audio(titleindex, track);
1190 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1191 (acodec != HB_ACODEC_LAME);
1192 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1194 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1196 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1197 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1198 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1199 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1201 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1202 (acodec != HB_ACODEC_LAME) &&
1203 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1204 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1206 gboolean greater = FALSE;
1209 // If no mix is specified, select the best available.
1210 mix = HB_AMIXDOWN_6CH;
1212 if (mix == HB_AMIXDOWN_6CH)
1215 if (allow_6ch) return HB_AMIXDOWN_6CH;
1217 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1220 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1222 if (mix == HB_AMIXDOWN_DOLBY || greater)
1225 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1227 if (mix == HB_AMIXDOWN_STEREO || greater)
1230 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1232 if (mix == HB_AMIXDOWN_MONO || greater)
1235 if (allow_mono) return HB_AMIXDOWN_MONO;
1237 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1238 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1239 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1240 if (allow_6ch) return HB_AMIXDOWN_6CH;
1244 // Set up the model for the combo box
1246 init_combo_box(GtkBuilder *builder, const gchar *name)
1249 GtkListStore *store;
1250 GtkCellRenderer *cell;
1252 g_debug("init_combo_box() %s\n", name);
1253 // First modify the combobox model to allow greying out of options
1254 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1256 // 1 - String to display
1257 // 2 - bool indicating whether the entry is selectable (grey or not)
1258 // 3 - String that is used for presets
1259 // 4 - Int value determined by backend
1260 // 5 - String value determined by backend
1261 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1262 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1263 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1265 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1267 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1268 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1269 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1270 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1271 "text", 0, "sensitive", 1, NULL);
1274 { // Combo box entry
1275 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1280 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1283 GtkListStore *store;
1286 g_debug("audio_samplerate_opts_set ()\n");
1287 store = get_combo_box_store(builder, name);
1288 gtk_list_store_clear(store);
1289 // Add an item for "Same As Source"
1290 gtk_list_store_append(store, &iter);
1291 gtk_list_store_set(store, &iter,
1292 0, "Same as source",
1298 for (ii = 0; ii < count; ii++)
1300 gtk_list_store_append(store, &iter);
1301 gtk_list_store_set(store, &iter,
1302 0, rates[ii].string,
1304 2, rates[ii].string,
1305 3, (gdouble)rates[ii].rate,
1306 4, rates[ii].string,
1312 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1315 GtkListStore *store;
1318 g_debug("video_rate_opts_set ()\n");
1319 store = get_combo_box_store(builder, name);
1320 gtk_list_store_clear(store);
1321 // Add an item for "Same As Source"
1322 gtk_list_store_append(store, &iter);
1323 gtk_list_store_set(store, &iter,
1324 0, "Same as source",
1330 for (ii = 0; ii < count; ii++)
1334 if (strcmp(rates[ii].string, "23.976") == 0)
1336 desc = "(NTSC Film)";
1338 else if (strcmp(rates[ii].string, "25") == 0)
1340 desc = "(PAL Film/Video)";
1342 else if (strcmp(rates[ii].string, "29.97") == 0)
1344 desc = "(NTSC Video)";
1346 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1347 gtk_list_store_append(store, &iter);
1348 gtk_list_store_set(store, &iter,
1351 2, rates[ii].string,
1352 3, (gdouble)rates[ii].rate,
1353 4, rates[ii].string,
1360 mix_opts_set(GtkBuilder *builder, const gchar *name)
1363 GtkListStore *store;
1366 g_debug("mix_opts_set ()\n");
1367 store = get_combo_box_store(builder, name);
1368 gtk_list_store_clear(store);
1369 gtk_list_store_append(store, &iter);
1370 gtk_list_store_set(store, &iter,
1377 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1379 gtk_list_store_append(store, &iter);
1380 gtk_list_store_set(store, &iter,
1381 0, hb_audio_mixdowns[ii].human_readable_name,
1383 2, hb_audio_mixdowns[ii].short_name,
1384 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1385 4, hb_audio_mixdowns[ii].internal_name,
1391 language_opts_set(GtkBuilder *builder, const gchar *name)
1394 GtkListStore *store;
1397 g_debug("language_opts_set ()\n");
1398 store = get_combo_box_store(builder, name);
1399 gtk_list_store_clear(store);
1400 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1402 gtk_list_store_append(store, &iter);
1403 gtk_list_store_set(store, &iter,
1404 0, ghb_language_table[ii].eng_name,
1406 2, ghb_language_table[ii].iso639_2,
1408 4, ghb_language_table[ii].iso639_1,
1413 static gchar **titles = NULL;
1416 title_opts_set(GtkBuilder *builder, const gchar *name)
1419 GtkListStore *store;
1420 hb_list_t * list = NULL;
1421 hb_title_t * title = NULL;
1425 g_debug("title_opts_set ()\n");
1426 store = get_combo_box_store(builder, name);
1427 gtk_list_store_clear(store);
1430 list = hb_get_titles( h_scan );
1431 count = hb_list_count( list );
1432 if (count > 100) count = 100;
1434 if (titles) g_strfreev(titles);
1435 if (title_opts.map) g_free(title_opts.map);
1438 title_opts.count = count;
1439 title_opts.map = g_malloc(count*sizeof(options_map_t));
1440 titles = g_malloc((count+1) * sizeof(gchar*));
1444 title_opts.count = 1;
1445 title_opts.map = g_malloc(sizeof(options_map_t));
1450 // No titles. Fill in a default.
1451 gtk_list_store_append(store, &iter);
1452 gtk_list_store_set(store, &iter,
1459 title_opts.map[0].option = "No Titles";
1460 title_opts.map[0].shortOpt = "none";
1461 title_opts.map[0].ivalue = -1;
1462 title_opts.map[0].svalue = "none";
1465 for (ii = 0; ii < count; ii++)
1467 title = (hb_title_t*)hb_list_item(list, ii);
1468 if (title->duration != 0)
1470 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1471 title->index, title->hours, title->minutes, title->seconds);
1475 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1477 gtk_list_store_append(store, &iter);
1478 gtk_list_store_set(store, &iter,
1485 title_opts.map[ii].option = titles[ii];
1486 title_opts.map[ii].shortOpt = titles[ii];
1487 title_opts.map[ii].ivalue = ii;
1488 title_opts.map[ii].svalue = titles[ii];
1494 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1497 gboolean foundit = FALSE;
1499 if (gtk_tree_model_get_iter_first (store, iter))
1503 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1504 if (value == (int)ivalue)
1509 } while (gtk_tree_model_iter_next (store, iter));
1515 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1518 GtkListStore *store;
1519 hb_list_t * list = NULL;
1520 hb_title_t * title = NULL;
1521 hb_audio_config_t * audio;
1525 g_debug("audio_track_opts_set ()\n");
1526 store = get_combo_box_store(builder, name);
1527 gtk_list_store_clear(store);
1530 list = hb_get_titles( h_scan );
1531 title = (hb_title_t*)hb_list_item( list, titleindex );
1534 count = hb_list_count( title->list_audio );
1537 if (count > 100) count = 100;
1538 if (audio_track_opts.map) g_free(audio_track_opts.map);
1541 audio_track_opts.count = count;
1542 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1546 audio_track_opts.count = 1;
1547 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1551 // No audio. set some default
1552 gtk_list_store_append(store, &iter);
1553 gtk_list_store_set(store, &iter,
1560 audio_track_opts.map[0].option = "No Audio";
1561 audio_track_opts.map[0].shortOpt = "none";
1562 audio_track_opts.map[0].ivalue = -1;
1563 audio_track_opts.map[0].svalue = "none";
1566 for (ii = 0; ii < count; ii++)
1568 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1569 gtk_list_store_append(store, &iter);
1570 gtk_list_store_set(store, &iter,
1571 0, audio->lang.description,
1577 audio_track_opts.map[ii].option = audio->lang.description,
1578 audio_track_opts.map[ii].shortOpt = index_str[ii];
1579 audio_track_opts.map[ii].ivalue = ii;
1580 audio_track_opts.map[ii].svalue = index_str[ii];
1586 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1589 GtkListStore *store;
1590 hb_list_t * list = NULL;
1591 hb_title_t * title = NULL;
1592 hb_subtitle_t * subtitle;
1596 g_debug("subtitle_opts_set () %s\n", name);
1597 store = get_combo_box_store(builder, name);
1598 gtk_list_store_clear(store);
1601 list = hb_get_titles( h_scan );
1602 title = (hb_title_t*)hb_list_item( list, titleindex );
1605 count = hb_list_count( title->list_subtitle );
1608 if (count > 100) count = 100;
1609 if (subtitle_opts.map) g_free(subtitle_opts.map);
1612 subtitle_opts.count = count+2;
1613 subtitle_opts.map = g_malloc((count+2)*sizeof(options_map_t));
1617 subtitle_opts.count = LANG_TABLE_SIZE+2;
1618 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+2)*sizeof(options_map_t));
1620 // Add options for "none" and "autoselect"
1621 gtk_list_store_append(store, &iter);
1622 gtk_list_store_set(store, &iter,
1629 subtitle_opts.map[0].option = "None";
1630 subtitle_opts.map[0].shortOpt = "none";
1631 subtitle_opts.map[0].ivalue = -2;
1632 subtitle_opts.map[0].svalue = "none";
1633 gtk_list_store_append(store, &iter);
1634 gtk_list_store_set(store, &iter,
1641 subtitle_opts.map[0].option = "Same as audio";
1642 subtitle_opts.map[0].shortOpt = "auto";
1643 subtitle_opts.map[0].ivalue = -1;
1644 subtitle_opts.map[0].svalue = "auto";
1647 for (ii = 0; ii < count; ii++)
1649 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1650 gtk_list_store_append(store, &iter);
1651 gtk_list_store_set(store, &iter,
1654 2, subtitle->iso639_2,
1656 4, subtitle->iso639_2,
1658 subtitle_opts.map[ii+2].option = subtitle->lang;
1659 subtitle_opts.map[ii+2].shortOpt = subtitle->iso639_2;
1660 subtitle_opts.map[ii+2].ivalue = ii;
1661 subtitle_opts.map[ii+2].svalue = subtitle->iso639_2;
1666 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1668 gtk_list_store_append(store, &iter);
1669 gtk_list_store_set(store, &iter,
1670 0, ghb_language_table[ii].eng_name,
1672 2, ghb_language_table[ii].iso639_2,
1674 4, ghb_language_table[ii].iso639_2,
1676 subtitle_opts.map[ii+2].option = ghb_language_table[ii].eng_name;
1677 subtitle_opts.map[ii+2].shortOpt = ghb_language_table[ii].iso639_2;
1678 subtitle_opts.map[ii+2].ivalue = ii;
1679 subtitle_opts.map[ii+2].svalue = ghb_language_table[ii].iso639_2;
1691 guint64 longest = 0;
1692 gint titleindex = 0;
1694 g_debug("ghb_longest_title ()\n");
1695 if (h_scan == NULL) return 0;
1696 list = hb_get_titles( h_scan );
1697 count = hb_list_count( list );
1698 if (count > 100) count = 100;
1699 for (ii = 0; ii < count; ii++)
1701 title = (hb_title_t*)hb_list_item(list, ii);
1702 if (title->duration > longest)
1705 longest = title->duration;
1712 ghb_find_audio_track(
1716 GHashTable *track_indices)
1720 hb_audio_config_t * audio;
1727 g_debug("find_audio_track ()\n");
1728 if (h_scan == NULL) return -1;
1729 list = hb_get_titles( h_scan );
1730 title = (hb_title_t*)hb_list_item( list, titleindex );
1733 count = hb_list_count( title->list_audio );
1735 if (count > 10) count = 10;
1736 used = g_hash_table_lookup(track_indices, &acodec);
1739 used = g_malloc0(count * sizeof(gboolean));
1740 g_hash_table_insert(track_indices, &acodec, used);
1742 // Try to find an item that matches the preferred language and
1743 // the passthru codec type
1744 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1746 for (ii = 0; ii < count; ii++)
1753 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1754 title->list_audio, ii );
1755 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1756 audio->in.channel_layout);
1757 // Find a track that is not visually impaired or dirctor's
1758 // commentary, and has the highest channel count.
1759 if ((audio->in.codec & acodec) &&
1760 (audio->lang.type < 2) &&
1761 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1762 (strcmp(lang, "und") == 0)))
1764 if (channels > max_chan)
1767 max_chan = channels;
1777 // Try to find an item that matches the preferred language
1778 for (ii = 0; ii < count; ii++)
1782 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1783 title->list_audio, ii );
1784 // Find a track that is not visually impaired or dirctor's commentary
1785 if ((audio->lang.type < 2) &&
1786 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1787 (strcmp(lang, "und") == 0)))
1798 // Try to fine an item that does not match the preferred language and
1799 // matches the passthru codec type
1800 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1802 for (ii = 0; ii < count; ii++)
1809 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1810 title->list_audio, ii );
1811 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1812 audio->in.channel_layout);
1813 // Find a track that is not visually impaired or dirctor's
1814 // commentary, and has the highest channel count.
1815 if ((audio->in.codec & acodec) &&
1816 (audio->lang.type < 2))
1818 if (channels > max_chan)
1821 max_chan = channels;
1831 // Try to fine an item that does not match the preferred language
1832 for (ii = 0; ii < count; ii++)
1836 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1837 title->list_audio, ii );
1838 // Find a track that is not visually impaired or dirctor's commentary
1839 if (audio->lang.type < 2)
1850 // Last ditch, anything goes
1851 for (ii = 0; ii < count; ii++)
1853 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1854 title->list_audio, ii );
1869 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1872 GtkListStore *store;
1875 g_debug("generic_opts_set ()\n");
1876 if (name == NULL || opts == NULL) return;
1877 store = get_combo_box_store(builder, name);
1878 gtk_list_store_clear(store);
1879 for (ii = 0; ii < opts->count; ii++)
1881 gtk_list_store_append(store, &iter);
1882 gtk_list_store_set(store, &iter,
1883 0, opts->map[ii].option,
1885 2, opts->map[ii].shortOpt,
1886 3, opts->map[ii].ivalue,
1887 4, opts->map[ii].svalue,
1893 find_combo_table(const gchar *name)
1897 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1899 if (strcmp(name, combo_name_map[ii].name) == 0)
1901 return combo_name_map[ii].opts;
1908 ghb_lookup_combo_int(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_int(find_combo_table(name), gval);
1924 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1929 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
1931 if (strcmp(name, "AudioBitrate") == 0)
1932 return lookup_audio_bitrate_int(gval);
1933 else if (strcmp(name, "AudioSamplerate") == 0)
1934 return lookup_audio_rate_int(gval);
1935 else if (strcmp(name, "VideoFramerate") == 0)
1936 return lookup_video_rate_int(gval);
1937 else if (strcmp(name, "AudioMixdown") == 0)
1938 return lookup_mix_int(gval);
1939 else if (strcmp(name, "SourceAudioLang") == 0)
1940 return lookup_audio_lang_int(gval);
1943 return lookup_generic_double(find_combo_table(name), gval);
1945 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
1950 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
1952 if (strcmp(name, "AudioBitrate") == 0)
1953 return lookup_audio_bitrate_option(gval);
1954 else if (strcmp(name, "AudioSamplerate") == 0)
1955 return lookup_audio_rate_option(gval);
1956 else if (strcmp(name, "VideoFramerate") == 0)
1957 return lookup_video_rate_option(gval);
1958 else if (strcmp(name, "AudioMixdown") == 0)
1959 return lookup_mix_option(gval);
1960 else if (strcmp(name, "SourceAudioLang") == 0)
1961 return lookup_audio_lang_option(gval);
1964 return lookup_generic_option(find_combo_table(name), gval);
1966 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1971 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1973 GtkComboBox *combo = NULL;
1975 gint handler_id = 0;
1979 g_debug("ghb_update_ui_combo_box() %s\n", name);
1980 // Clearing a combo box causes a rash of "changed" events, even when
1981 // the active item is -1 (inactive). To control things, I'm disabling
1982 // the event till things are settled down.
1983 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1984 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1987 // Valid signal id found. This should always succeed.
1988 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1989 signal_id, 0, 0, 0, 0);
1992 // This should also always succeed
1993 g_signal_handler_block ((gpointer)combo, handler_id);
1999 audio_bitrate_opts_set(builder, "AudioBitrate");
2000 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2001 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2002 mix_opts_set(builder, "AudioMixdown");
2003 language_opts_set(builder, "SourceAudioLang");
2004 subtitle_opts_set(builder, "Subtitles", user_data);
2005 title_opts_set(builder, "title");
2006 audio_track_opts_set(builder, "AudioTrack", user_data);
2007 generic_opts_set(builder, "VideoQualityGranularity", &vqual_granularity_opts);
2008 generic_opts_set(builder, "PicturePAR", &par_opts);
2009 generic_opts_set(builder, "PictureModulus", &alignment_opts);
2010 generic_opts_set(builder, "LoggingLevel", &logging_opts);
2011 generic_opts_set(builder, "FileFormat", &container_opts);
2012 generic_opts_set(builder, "PictureDeinterlace", &deint_opts);
2013 generic_opts_set(builder, "PictureDetelecine", &detel_opts);
2014 generic_opts_set(builder, "PictureDecomb", &decomb_opts);
2015 generic_opts_set(builder, "PictureDenoise", &denoise_opts);
2016 generic_opts_set(builder, "VideoEncoder", &vcodec_opts);
2017 generic_opts_set(builder, "AudioEncoder", &acodec_opts);
2018 generic_opts_set(builder, "x264_direct", &direct_opts);
2019 generic_opts_set(builder, "x264_b_adapt", &badapt_opts);
2020 generic_opts_set(builder, "x264_me", &me_opts);
2021 generic_opts_set(builder, "x264_subme", &subme_opts);
2022 generic_opts_set(builder, "x264_analyse", &analyse_opts);
2023 generic_opts_set(builder, "x264_trellis", &trellis_opts);
2027 if (strcmp(name, "AudioBitrate") == 0)
2028 audio_bitrate_opts_set(builder, "AudioBitrate");
2029 else if (strcmp(name, "AudioSamplerate") == 0)
2030 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2031 else if (strcmp(name, "VideoFramerate") == 0)
2032 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2033 else if (strcmp(name, "AudioMixdown") == 0)
2034 mix_opts_set(builder, "AudioMixdown");
2035 else if (strcmp(name, "SourceAudioLang") == 0)
2036 language_opts_set(builder, "SourceAudioLang");
2037 else if (strcmp(name, "Subtitles") == 0)
2038 subtitle_opts_set(builder, "Subtitles", user_data);
2039 else if (strcmp(name, "title") == 0)
2040 title_opts_set(builder, "title");
2041 else if (strcmp(name, "AudioTrack") == 0)
2042 audio_track_opts_set(builder, "AudioTrack", user_data);
2044 generic_opts_set(builder, name, find_combo_table(name));
2048 g_signal_handler_unblock ((gpointer)combo, handler_id);
2053 init_ui_combo_boxes(GtkBuilder *builder)
2057 init_combo_box(builder, "AudioBitrate");
2058 init_combo_box(builder, "AudioSamplerate");
2059 init_combo_box(builder, "VideoFramerate");
2060 init_combo_box(builder, "AudioMixdown");
2061 init_combo_box(builder, "SourceAudioLang");
2062 init_combo_box(builder, "Subtitles");
2063 init_combo_box(builder, "title");
2064 init_combo_box(builder, "AudioTrack");
2065 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2067 init_combo_box(builder, combo_name_map[ii].name);
2071 static const char * turbo_opts =
2072 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2073 "no-fast-pskip=0:8x8dct=0:weightb=0";
2075 // Construct the x264 options string
2076 // The result is allocated, so someone must free it at some point.
2078 ghb_build_x264opts_string(GValue *settings)
2081 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2088 result = g_strdup("");
2094 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2098 hb_chapter_t * chapter;
2101 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2102 *hh = *mm = *ss = 0;
2103 if (h_scan == NULL) return;
2104 list = hb_get_titles( h_scan );
2105 title = (hb_title_t*)hb_list_item( list, ti );
2106 if (title == NULL) return;
2107 count = hb_list_count( title->list_chapter );
2108 if (ii >= count) return;
2109 chapter = hb_list_item(title->list_chapter, ii);
2110 if (chapter == NULL) return;
2111 *hh = chapter->hours;
2112 *mm = chapter->minutes;
2113 *ss = chapter->seconds;
2117 ghb_get_chapters(gint titleindex)
2121 hb_chapter_t * chapter;
2123 GValue *chapters = NULL;
2125 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2126 if (h_scan == NULL) return NULL;
2127 list = hb_get_titles( h_scan );
2128 title = (hb_title_t*)hb_list_item( list, titleindex );
2129 if (title == NULL) return NULL;
2130 count = hb_list_count( title->list_chapter );
2131 chapters = ghb_array_value_new(count);
2132 for (ii = 0; ii < count; ii++)
2134 chapter = hb_list_item(title->list_chapter, ii);
2135 if (chapter == NULL) break;
2136 if (chapter->title == NULL || chapter->title[0] == 0)
2139 str = g_strdup_printf ("Chapter %2d", ii+1);
2140 ghb_array_append(chapters, ghb_string_value_new(str));
2145 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2152 ghb_ac3_in_audio_list(const GValue *audio_list)
2156 count = ghb_array_len(audio_list);
2157 for (ii = 0; ii < count; ii++)
2162 asettings = ghb_array_get_nth(audio_list, ii);
2163 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2164 if (acodec == HB_ACODEC_AC3)
2171 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2174 GtkListStore *store;
2177 g_debug("audio_rate_opts_add ()\n");
2178 store = get_combo_box_store(builder, name);
2179 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2181 str = g_strdup_printf ("%d", rate);
2182 gtk_list_store_append(store, &iter);
2183 gtk_list_store_set(store, &iter,
2195 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2198 GtkListStore *store;
2200 gboolean done = FALSE;
2202 guint last = (guint)last_rate;
2204 g_debug("audio_bitrate_opts_clean ()\n");
2205 store = get_combo_box_store(builder, name);
2206 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2210 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2212 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2214 done = !gtk_list_store_remove(store, &iter);
2216 else if (ivalue > last)
2219 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2220 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2225 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2226 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2233 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2236 GtkListStore *store;
2239 g_debug("audio_bitrate_opts_set ()\n");
2240 store = get_combo_box_store(builder, name);
2241 gtk_list_store_clear(store);
2242 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2244 gtk_list_store_append(store, &iter);
2245 gtk_list_store_set(store, &iter,
2246 0, hb_audio_bitrates[ii].string,
2248 2, hb_audio_bitrates[ii].string,
2249 3, (gdouble)hb_audio_bitrates[ii].rate,
2250 4, hb_audio_bitrates[ii].string,
2256 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2258 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2262 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2264 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2267 static ghb_status_t hb_status;
2270 ghb_combo_init(GtkBuilder *builder)
2272 // Set up the list model for the combos
2273 init_ui_combo_boxes(builder);
2274 // Populate all the combos
2275 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
2279 ghb_backend_init(gint debug)
2282 h_scan = hb_init( debug, 0 );
2283 h_queue = hb_init( debug, 0 );
2294 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2296 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2297 hb_status.scan.state |= GHB_STATE_SCANNING;
2298 // initialize count and cur to something that won't cause FPE
2299 // when computing progress
2300 hb_status.scan.title_count = 1;
2301 hb_status.scan.title_cur = 0;
2305 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2307 g_debug("ghb_backend_queue_scan()");
2308 hb_scan( h_queue, path, titlenum, 10, 0 );
2309 hb_status.queue.state |= GHB_STATE_SCANNING;
2313 ghb_get_scan_state()
2315 return hb_status.scan.state;
2319 ghb_get_queue_state()
2321 return hb_status.queue.state;
2325 ghb_clear_scan_state(gint state)
2327 hb_status.scan.state &= ~state;
2331 ghb_clear_queue_state(gint state)
2333 hb_status.queue.state &= ~state;
2337 ghb_set_scan_state(gint state)
2339 hb_status.scan.state |= state;
2343 ghb_set_queue_state(gint state)
2345 hb_status.queue.state |= state;
2349 ghb_get_status(ghb_status_t *status)
2351 memcpy(status, &hb_status, sizeof(ghb_status_t));
2360 if (h_scan == NULL) return;
2361 hb_get_state( h_scan, &s_scan );
2362 switch( s_scan.state )
2364 #define p s_scan.param.scanning
2365 case HB_STATE_SCANNING:
2367 hb_status.scan.state |= GHB_STATE_SCANNING;
2368 hb_status.scan.title_count = p.title_count;
2369 hb_status.scan.title_cur = p.title_cur;
2373 case HB_STATE_SCANDONE:
2375 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2376 hb_status.scan.state |= GHB_STATE_SCANDONE;
2379 #define p s_scan.param.working
2380 case HB_STATE_WORKING:
2381 hb_status.scan.state |= GHB_STATE_WORKING;
2382 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2383 hb_status.scan.job_cur = p.job_cur;
2384 hb_status.scan.job_count = p.job_count;
2385 hb_status.scan.progress = p.progress;
2386 hb_status.scan.rate_cur = p.rate_cur;
2387 hb_status.scan.rate_avg = p.rate_avg;
2388 hb_status.scan.hours = p.hours;
2389 hb_status.scan.minutes = p.minutes;
2390 hb_status.scan.seconds = p.seconds;
2391 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2395 case HB_STATE_PAUSED:
2396 hb_status.scan.state |= GHB_STATE_PAUSED;
2399 case HB_STATE_MUXING:
2401 hb_status.scan.state |= GHB_STATE_MUXING;
2404 #define p s_scan.param.workdone
2405 case HB_STATE_WORKDONE:
2409 hb_status.scan.state |= GHB_STATE_WORKDONE;
2410 hb_status.scan.state &= ~GHB_STATE_MUXING;
2411 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2412 hb_status.scan.state &= ~GHB_STATE_WORKING;
2416 hb_status.scan.error = GHB_ERROR_NONE;
2418 case HB_ERROR_CANCELED:
2419 hb_status.scan.error = GHB_ERROR_CANCELED;
2422 hb_status.scan.error = GHB_ERROR_FAIL;
2425 // Delete all remaining jobs of this encode.
2426 // An encode can be composed of multiple associated jobs.
2427 // When a job is stopped, libhb removes it from the job list,
2428 // but does not remove other jobs that may be associated with it.
2429 // Associated jobs are taged in the sequence id.
2430 while ((job = hb_job(h_scan, 0)) != NULL)
2431 hb_rem( h_scan, job );
2435 hb_get_state( h_queue, &s_queue );
2436 switch( s_queue.state )
2438 #define p s_queue.param.scanning
2439 case HB_STATE_SCANNING:
2441 hb_status.queue.state |= GHB_STATE_SCANNING;
2442 hb_status.queue.title_count = p.title_count;
2443 hb_status.queue.title_cur = p.title_cur;
2447 case HB_STATE_SCANDONE:
2449 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2450 hb_status.queue.state |= GHB_STATE_SCANDONE;
2453 #define p s_queue.param.working
2454 case HB_STATE_WORKING:
2455 hb_status.queue.state |= GHB_STATE_WORKING;
2456 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2457 hb_status.queue.job_cur = p.job_cur;
2458 hb_status.queue.job_count = p.job_count;
2459 hb_status.queue.progress = p.progress;
2460 hb_status.queue.rate_cur = p.rate_cur;
2461 hb_status.queue.rate_avg = p.rate_avg;
2462 hb_status.queue.hours = p.hours;
2463 hb_status.queue.minutes = p.minutes;
2464 hb_status.queue.seconds = p.seconds;
2465 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2469 case HB_STATE_PAUSED:
2470 hb_status.queue.state |= GHB_STATE_PAUSED;
2473 case HB_STATE_MUXING:
2475 hb_status.queue.state |= GHB_STATE_MUXING;
2478 #define p s_queue.param.workdone
2479 case HB_STATE_WORKDONE:
2483 hb_status.queue.state |= GHB_STATE_WORKDONE;
2484 hb_status.queue.state &= ~GHB_STATE_MUXING;
2485 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2486 hb_status.queue.state &= ~GHB_STATE_WORKING;
2490 hb_status.queue.error = GHB_ERROR_NONE;
2492 case HB_ERROR_CANCELED:
2493 hb_status.queue.error = GHB_ERROR_CANCELED;
2496 hb_status.queue.error = GHB_ERROR_FAIL;
2499 // Delete all remaining jobs of this encode.
2500 // An encode can be composed of multiple associated jobs.
2501 // When a job is stopped, libhb removes it from the job list,
2502 // but does not remove other jobs that may be associated with it.
2503 // Associated jobs are taged in the sequence id.
2504 while ((job = hb_job(h_queue, 0)) != NULL)
2505 hb_rem( h_queue, job );
2512 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2517 if (h_scan == NULL) return FALSE;
2518 list = hb_get_titles( h_scan );
2519 if( !hb_list_count( list ) )
2521 /* No valid title, stop right there */
2525 title = hb_list_item( list, titleindex );
2526 if (title == NULL) return FALSE; // Bad titleindex
2527 tinfo->width = title->width;
2528 tinfo->height = title->height;
2529 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2530 // Don't allow crop to 0
2531 if (title->crop[0] + title->crop[1] >= title->height)
2532 title->crop[0] = title->crop[1] = 0;
2533 if (title->crop[2] + title->crop[3] >= title->width)
2534 title->crop[2] = title->crop[3] = 0;
2535 tinfo->num_chapters = hb_list_count(title->list_chapter);
2536 tinfo->rate_base = title->rate_base;
2537 tinfo->rate = title->rate;
2538 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2539 title->width * title->pixel_aspect_width,
2540 title->height * title->pixel_aspect_height);
2541 tinfo->hours = title->hours;
2542 tinfo->minutes = title->minutes;
2543 tinfo->seconds = title->seconds;
2544 tinfo->duration = title->duration;
2546 tinfo->angle_count = title->angle_count;
2551 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2553 hb_audio_config_t *audio;
2555 audio = get_hb_audio(titleindex, audioindex);
2556 if (audio == NULL) return FALSE; // Bad audioindex
2557 ainfo->codec = audio->in.codec;
2558 ainfo->bitrate = audio->in.bitrate;
2559 ainfo->samplerate = audio->in.samplerate;
2564 ghb_audio_is_passthru(gint acodec)
2566 g_debug("ghb_audio_is_passthru () \n");
2567 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2571 ghb_get_default_acodec()
2573 return HB_ACODEC_FAAC;
2577 picture_settings_deps(signal_user_data_t *ud)
2579 gboolean autoscale, keep_aspect, enable_keep_aspect;
2580 gboolean enable_scale_width, enable_scale_height;
2581 gboolean enable_disp_width, enable_disp_height;
2585 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2588 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2589 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2590 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2592 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2593 if (!enable_keep_aspect)
2595 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2597 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2598 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2600 enable_scale_width = !autoscale && (pic_par != 1);
2601 enable_scale_height = !autoscale && (pic_par != 1);
2602 enable_disp_width = (pic_par == 3) && !keep_aspect;
2603 enable_disp_height = FALSE;
2605 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2606 gtk_widget_set_sensitive(widget, pic_par != 1);
2607 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2608 gtk_widget_set_sensitive(widget, pic_par != 1);
2609 widget = GHB_WIDGET(ud->builder, "scale_width");
2610 gtk_widget_set_sensitive(widget, enable_scale_width);
2611 widget = GHB_WIDGET(ud->builder, "scale_height");
2612 gtk_widget_set_sensitive(widget, enable_scale_height);
2613 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2614 gtk_widget_set_sensitive(widget, enable_disp_width);
2615 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2616 gtk_widget_set_sensitive(widget, enable_disp_height);
2617 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2618 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2619 widget = GHB_WIDGET(ud->builder, "autoscale");
2620 gtk_widget_set_sensitive(widget, pic_par != 1);
2624 ghb_set_scale(signal_user_data_t *ud, gint mode)
2629 gboolean keep_aspect;
2631 gboolean autocrop, autoscale, noscale;
2632 gint crop[4], width, height, par_width, par_height;
2633 gint crop_width, crop_height;
2634 gint aspect_n, aspect_d;
2635 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2636 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2641 gint max_height = 0;
2642 static gboolean busy = FALSE;
2644 g_debug("ghb_set_scale ()\n");
2645 if (h_scan == NULL) return;
2646 list = hb_get_titles( h_scan );
2647 if( !hb_list_count( list ) )
2649 /* No valid title, stop right there */
2654 titleindex = ghb_settings_combo_int(ud->settings, "title");
2655 title = hb_list_item( list, titleindex );
2656 if (title == NULL) return;
2658 if (job == NULL) return;
2660 picture_settings_deps(ud);
2665 // First configure widgets
2666 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2667 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2668 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2669 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2670 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2671 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2672 // alignment constraints rather than scaling to satisfy them.
2673 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2674 // Align dimensions to either 16 or 2 pixels
2675 // The scaler crashes if the dimensions are not divisible by 2
2676 // x264 also will not accept dims that are not multiple of 2
2680 keep_height = FALSE;
2682 // Step needs to be at least 2 because odd widths cause scaler crash
2684 widget = GHB_WIDGET (ud->builder, "scale_width");
2685 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2686 widget = GHB_WIDGET (ud->builder, "scale_height");
2687 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2690 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2691 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2692 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2693 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2694 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2695 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2696 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2697 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2701 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2702 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2703 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2704 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2705 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2706 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2707 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2708 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2710 ghb_title_info_t tinfo;
2711 ghb_get_title_info (&tinfo, titleindex);
2714 crop[0] = tinfo.crop[0];
2715 crop[1] = tinfo.crop[1];
2716 crop[2] = tinfo.crop[2];
2717 crop[3] = tinfo.crop[3];
2718 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2719 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2720 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2721 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2725 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2726 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2727 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2728 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2734 // Adjust the cropping to accomplish the desired width and height
2735 crop_width = tinfo.width - crop[2] - crop[3];
2736 crop_height = tinfo.height - crop[0] - crop[1];
2737 width = MOD_DOWN(crop_width, mod);
2738 height = MOD_DOWN(crop_height, mod);
2740 need1 = (crop_height - height) / 2;
2741 need2 = crop_height - height - need1;
2744 need1 = (crop_width - width) / 2;
2745 need2 = crop_width - width - need1;
2748 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2749 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2750 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2751 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2753 hb_reduce(&aspect_n, &aspect_d,
2754 title->width * title->pixel_aspect_width,
2755 title->height * title->pixel_aspect_height);
2756 crop_width = title->width - crop[2] - crop[3];
2757 crop_height = title->height - crop[0] - crop[1];
2761 height = crop_height;
2765 width = ghb_settings_get_int(ud->settings, "scale_width");
2766 height = ghb_settings_get_int(ud->settings, "scale_height");
2767 max_width = MOD_DOWN(
2768 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
2769 max_height = MOD_DOWN(
2770 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
2772 // Adjust dims according to max values
2775 max_height = MOD_DOWN(crop_height, mod);
2779 max_width = MOD_DOWN(crop_width, mod);
2782 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2785 width = title->width - crop[2] - crop[3];
2787 height = title->height - crop[0] - crop[1];
2789 width = MOD_ROUND(width, mod);
2790 height = MOD_ROUND(height, mod);
2792 height = MIN(height, max_height);
2794 width = MIN(width, max_width);
2798 job->anamorphic.mode = pic_par;
2799 // The scaler crashes if the dimensions are not divisible by 2
2800 // Align mod 2. And so does something in x264_encoder_headers()
2801 job->anamorphic.modulus = mod;
2802 if (keep_height && pic_par == 2)
2803 width = ((double)height * crop_width / crop_height) + 0.5;
2805 job->height = height;
2807 job->maxWidth = max_width;
2809 job->maxHeight = max_height;
2810 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2811 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2812 if (job->anamorphic.mode == 3 && !keep_aspect)
2814 gint dar_width, dar_height;
2815 if (mode & GHB_PIC_KEEP_PAR)
2817 par_width = ghb_settings_get_int(ud->settings,
2819 par_height = ghb_settings_get_int(ud->settings,
2820 "PicturePARHeight");
2821 dar_width = ((gdouble)width * par_width / par_height) + 0.5;
2822 dar_height = height;
2826 dar_width = ghb_settings_get_int(ud->settings,
2827 "PictureDisplayWidth");
2828 dar_height = ghb_settings_get_int(ud->settings,
2829 "PictureDisplayHeight");
2831 job->anamorphic.dar_width = dar_width;
2832 job->anamorphic.dar_height = dar_height;
2836 job->anamorphic.dar_width = 0;
2837 job->anamorphic.dar_height = 0;
2839 hb_set_anamorphic_size( job, &width, &height,
2840 &par_width, &par_height );
2844 job->anamorphic.mode = pic_par;
2848 gint new_width, new_height;
2850 // Compute pixel aspect ration.
2851 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2852 // Must scale so that par becomes 1:1
2853 // Try to keep largest dimension
2854 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2855 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2857 if (max_width && new_width > max_width)
2859 height = new_height;
2861 else if (max_height && new_height > max_height)
2865 else if (keep_width)
2867 height = new_height;
2869 else if (keep_height)
2873 else if (width > new_width)
2875 height = new_height;
2881 g_debug("new w %d h %d\n", width, height);
2883 width = MOD_ROUND(width, mod);
2884 height = MOD_ROUND(height, mod);
2886 height = MIN(height, max_height);
2888 width = MIN(width, max_width);
2889 par_width = par_height = 1;
2891 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2892 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2894 gint disp_width, dar_width, dar_height;
2897 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
2898 hb_reduce(&dar_width, &dar_height, disp_width, height);
2900 gint iaspect = dar_width * 9 / dar_height;
2901 if (dar_width > 2 * dar_height)
2903 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
2905 else if (iaspect <= 16 && iaspect >= 15)
2907 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
2909 else if (iaspect <= 12 && iaspect >= 11)
2911 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
2915 str = g_strdup_printf("%d : %d", dar_width, dar_height);
2917 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
2919 ghb_ui_update(ud, "par_width", ghb_int64_value(par_width));
2920 ghb_ui_update(ud, "par_height", ghb_int64_value(par_height));
2921 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
2922 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
2927 set_preview_job_settings(hb_job_t *job, GValue *settings)
2929 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
2930 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
2931 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
2932 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
2934 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
2935 job->anamorphic.modulus =
2936 ghb_settings_combo_int(settings, "PictureModulus");
2937 job->width = ghb_settings_get_int(settings, "scale_width");
2938 job->height = ghb_settings_get_int(settings, "scale_height");
2940 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
2941 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
2942 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2944 gboolean keep_aspect;
2945 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
2946 if (job->anamorphic.mode == 3 && !keep_aspect)
2948 gint disp_width, disp_height;
2949 disp_width = ghb_settings_get_int(settings, "PictureDisplayWidth");
2950 disp_height = ghb_settings_get_int(settings, "PictureDisplayHeight");
2951 job->anamorphic.dar_width = disp_width;
2952 job->anamorphic.dar_height = disp_height;
2956 job->anamorphic.dar_width = 0;
2957 job->anamorphic.dar_height = 0;
2962 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2969 if (h_scan == NULL) return 1500;
2970 list = hb_get_titles( h_scan );
2971 title = hb_list_item( list, titleindex );
2972 if (title == NULL) return 1500;
2974 if (job == NULL) return 1500;
2975 size = ghb_settings_get_int(settings, "VideoTargetSize");
2976 return hb_calc_bitrate( job, size );
2980 ghb_validate_filter_string(const gchar *str, gint max_fields)
2986 if (str == NULL || *str == 0) return TRUE;
2989 val = g_strtod(str, &end);
2991 { // Found a numeric value
2993 // negative max_fields means infinate
2994 if (max_fields >= 0 && fields > max_fields) return FALSE;
3008 ghb_validate_filters(signal_user_data_t *ud)
3015 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3018 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3019 if (!ghb_validate_filter_string(str, 4))
3021 message = g_strdup_printf(
3022 "Invalid Deinterlace Settings:\n\n%s\n",
3024 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3032 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3035 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3036 if (!ghb_validate_filter_string(str, 6))
3038 message = g_strdup_printf(
3039 "Invalid Detelecine Settings:\n\n%s\n",
3041 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3049 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3052 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3053 if (!ghb_validate_filter_string(str, 7))
3055 message = g_strdup_printf(
3056 "Invalid Decomb Settings:\n\n%s\n",
3058 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3066 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3069 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3070 if (!ghb_validate_filter_string(str, 4))
3072 message = g_strdup_printf(
3073 "Invalid Denoise Settings:\n\n%s\n",
3075 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3086 ghb_validate_video(signal_user_data_t *ud)
3091 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3092 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3093 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3094 (vcodec == HB_VCODEC_THEORA))
3096 // mp4|avi/theora combination is not supported.
3097 message = g_strdup_printf(
3098 "Theora is not supported in the MP4 and AVI containers.\n\n"
3099 "You should choose a different video codec or container.\n"
3100 "If you continue, XviD will be chosen for you.");
3101 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3107 vcodec = HB_VCODEC_XVID;
3108 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3114 ghb_validate_audio(signal_user_data_t *ud)
3121 if (h_scan == NULL) return FALSE;
3122 list = hb_get_titles( h_scan );
3123 if( !hb_list_count( list ) )
3125 /* No valid title, stop right there */
3126 g_message("No title found.\n");
3132 titleindex = ghb_settings_combo_int(ud->settings, "title");
3133 title = hb_list_item( list, titleindex );
3134 if (title == NULL) return FALSE;
3135 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3137 const GValue *audio_list;
3140 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3141 count = ghb_array_len(audio_list);
3142 for (ii = 0; ii < count; ii++)
3145 hb_audio_config_t *taudio;
3147 asettings = ghb_array_get_nth(audio_list, ii);
3148 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3149 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3150 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3151 title->list_audio, track );
3152 if (!(taudio->in.codec & codec) &&
3153 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3155 // Not supported. AC3 is passthrough only, so input must be AC3
3156 message = g_strdup_printf(
3157 "The source does not support Pass-Thru.\n\n"
3158 "You should choose a different audio codec.\n"
3159 "If you continue, one will be chosen for you.");
3160 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3166 if (mux == HB_MUX_AVI)
3168 codec = HB_ACODEC_LAME;
3172 codec = HB_ACODEC_FAAC;
3174 value = get_acodec_value(codec);
3175 ghb_settings_take_value(asettings, "AudioEncoder", value);
3177 gchar *a_unsup = NULL;
3178 gchar *mux_s = NULL;
3179 if (mux == HB_MUX_MP4)
3182 // mp4/mp3|vorbis combination is not supported.
3183 if (codec == HB_ACODEC_LAME)
3186 codec = HB_ACODEC_FAAC;
3188 if (codec == HB_ACODEC_VORBIS)
3191 codec = HB_ACODEC_FAAC;
3193 if (codec == HB_ACODEC_DCA)
3196 codec = HB_ACODEC_FAAC;
3199 else if (mux == HB_MUX_AVI)
3202 // avi/faac|vorbis combination is not supported.
3203 if (codec == HB_ACODEC_FAAC)
3206 codec = HB_ACODEC_LAME;
3208 if (codec == HB_ACODEC_VORBIS)
3211 codec = HB_ACODEC_LAME;
3214 else if (mux == HB_MUX_OGM)
3217 // avi/faac|vorbis combination is not supported.
3218 if (codec == HB_ACODEC_FAAC)
3221 codec = HB_ACODEC_VORBIS;
3223 if (codec == HB_ACODEC_AC3)
3226 codec = HB_ACODEC_VORBIS;
3228 if (codec == HB_ACODEC_DCA)
3231 codec = HB_ACODEC_VORBIS;
3236 message = g_strdup_printf(
3237 "%s is not supported in the %s container.\n\n"
3238 "You should choose a different audio codec.\n"
3239 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3240 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3246 value = get_acodec_value(codec);
3247 ghb_settings_take_value(asettings, "AudioEncoder", value);
3249 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3250 gboolean allow_mono = TRUE;
3251 gboolean allow_stereo = TRUE;
3252 gboolean allow_dolby = TRUE;
3253 gboolean allow_dpl2 = TRUE;
3254 gboolean allow_6ch = TRUE;
3256 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3257 (codec != HB_ACODEC_LAME);
3258 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3260 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3262 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3263 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3264 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3265 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3267 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3268 (codec != HB_ACODEC_LAME) &&
3269 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3270 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3272 gchar *mix_unsup = NULL;
3273 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3277 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3279 mix_unsup = "stereo";
3281 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3283 mix_unsup = "Dolby";
3285 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3287 mix_unsup = "Dolby Pro Logic II";
3289 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3291 mix_unsup = "6 Channel";
3295 message = g_strdup_printf(
3296 "The source audio does not support %s mixdown.\n\n"
3297 "You should choose a different mixdown.\n"
3298 "If you continue, one will be chosen for you.", mix_unsup);
3299 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3305 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3306 value = get_amix_value(mix);
3307 ghb_settings_take_value(asettings, "AudioMixdown", value);
3314 ghb_validate_vquality(GValue *settings)
3320 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3321 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3323 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3324 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3328 case HB_VCODEC_X264:
3334 case HB_VCODEC_XVID:
3335 case HB_VCODEC_FFMPEG:
3341 case HB_VCODEC_THEORA:
3353 if (vquality < min || vquality > max)
3355 message = g_strdup_printf(
3356 "Interesting video quality choise: %d\n\n"
3357 "Typical values range from %d to %d.\n"
3358 "Are you sure you wish to use this setting?",
3359 (gint)vquality, min, max);
3360 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3361 "Cancel", "Continue"))
3373 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3378 static gchar *x264opts;
3380 gboolean tweaks = FALSE;
3381 gchar *detel_str = NULL;
3382 gchar *decomb_str = NULL;
3383 gchar *deint_str = NULL;
3384 gchar *deblock_str = NULL;
3385 gchar *denoise_str = NULL;
3386 gchar *dest_str = NULL;
3388 g_debug("add_job()\n");
3389 if (h == NULL) return;
3390 list = hb_get_titles( h );
3391 if( !hb_list_count( list ) )
3393 /* No valid title, stop right there */
3397 title = hb_list_item( list, titleindex );
3398 if (title == NULL) return;
3400 /* Set job settings */
3402 if (job == NULL) return;
3404 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3405 if (job->start_at_preview)
3407 job->seek_points = ghb_settings_get_int(js, "preview_count");
3408 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3411 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3412 job->mux = ghb_settings_combo_int(js, "FileFormat");
3413 if (job->mux == HB_MUX_MP4)
3415 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3416 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3420 job->largeFileSize = FALSE;
3421 job->mp4_optimize = FALSE;
3423 if (!job->start_at_preview)
3425 gint chapter_start, chapter_end;
3426 chapter_start = ghb_settings_get_int(js, "start_chapter");
3427 chapter_end = ghb_settings_get_int(js, "end_chapter");
3428 gint num_chapters = hb_list_count(title->list_chapter);
3429 job->chapter_start = MIN( num_chapters, chapter_start );
3430 job->chapter_end = MAX( job->chapter_start, chapter_end );
3432 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3433 if ( job->chapter_markers )
3440 chapters = ghb_settings_get_value(js, "chapter_list");
3441 count = ghb_array_len(chapters);
3442 for(chap = chapter_start; chap <= chapter_end; chap++)
3444 hb_chapter_t * chapter_s;
3450 chapter = ghb_array_get_nth(chapters, chap-1);
3451 name = ghb_value_string(chapter);
3455 name = g_strdup_printf ("Chapter %2d", chap);
3457 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3458 strncpy(chapter_s->title, name, 1023);
3459 chapter_s->title[1023] = '\0';
3464 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3465 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3466 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3467 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3470 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3471 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3473 job->deinterlace = (deint != 0) ? 1 : 0;
3475 job->deinterlace = 0;
3476 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3478 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3479 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3481 /* Add selected filters */
3482 job->filters = hb_list_init();
3483 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3488 if (detel_opts.map[detel].svalue != NULL)
3489 detel_str = g_strdup(detel_opts.map[detel].svalue);
3492 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3493 hb_filter_detelecine.settings = detel_str;
3494 hb_list_add( job->filters, &hb_filter_detelecine );
3500 if (decomb_opts.map[decomb].svalue != NULL)
3501 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3504 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3505 hb_filter_decomb.settings = decomb_str;
3506 hb_list_add( job->filters, &hb_filter_decomb );
3508 if( job->deinterlace )
3512 if (deint_opts.map[deint].svalue != NULL)
3513 deint_str = g_strdup(deint_opts.map[deint].svalue);
3516 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3517 hb_filter_deinterlace.settings = deint_str;
3518 hb_list_add( job->filters, &hb_filter_deinterlace );
3520 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3523 deblock_str = g_strdup_printf("%d", deblock);
3524 hb_filter_deblock.settings = deblock_str;
3525 hb_list_add( job->filters, &hb_filter_deblock );
3527 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3532 if (denoise_opts.map[denoise].svalue != NULL)
3533 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3536 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3537 hb_filter_denoise.settings = denoise_str;
3538 hb_list_add( job->filters, &hb_filter_denoise );
3540 job->width = ghb_settings_get_int(js, "scale_width");
3541 job->height = ghb_settings_get_int(js, "scale_height");
3543 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3544 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3545 (job->vcodec == HB_VCODEC_THEORA))
3547 // mp4|avi/theora combination is not supported.
3548 job->vcodec = HB_VCODEC_XVID;
3550 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3552 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3554 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3557 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3558 job->vquality = vquality;
3561 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3563 job->vquality = -1.0;
3564 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3567 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3570 job->vrate = title->rate;
3571 job->vrate_base = title->rate_base;
3576 job->vrate = 27000000;
3577 job->vrate_base = vrate;
3581 // AVI container does not support variable frame rate.
3582 // OGM supports variable frame rate, but bases all timing on
3583 // DTS, which breaks when b-frames are used since it is
3584 // impossible to reconstruct PTS from DTS when the framerate
3586 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3591 // First remove any audios that are already in the list
3592 // This happens if you are encoding the same title a second time.
3593 gint num_audio_tracks = hb_list_count(job->list_audio);
3595 for(ii = 0; ii < num_audio_tracks; ii++)
3597 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3598 hb_list_rem(job->list_audio, audio);
3601 const GValue *audio_list;
3605 audio_list = ghb_settings_get_value(js, "audio_list");
3606 count = ghb_array_len(audio_list);
3607 for (ii = 0; ii < count; ii++)
3610 hb_audio_config_t audio;
3611 hb_audio_config_t *taudio;
3613 hb_audio_config_init(&audio);
3614 asettings = ghb_array_get_nth(audio_list, ii);
3615 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3616 audio.out.track = tcount;
3617 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3618 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3619 title->list_audio, audio.in.track );
3620 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3622 if (!(taudio->in.codec & audio.out.codec))
3624 // Not supported. AC3 is passthrough only, so input must be AC3
3625 if (job->mux == HB_MUX_AVI)
3627 audio.out.codec = HB_ACODEC_LAME;
3631 audio.out.codec = HB_ACODEC_FAAC;
3636 audio.out.codec &= taudio->in.codec;
3639 if ((job->mux == HB_MUX_MP4) &&
3640 ((audio.out.codec == HB_ACODEC_LAME) ||
3641 (audio.out.codec == HB_ACODEC_VORBIS)))
3643 // mp4/mp3|vorbis combination is not supported.
3644 audio.out.codec = HB_ACODEC_FAAC;
3646 if ((job->mux == HB_MUX_AVI) &&
3647 ((audio.out.codec == HB_ACODEC_FAAC) ||
3648 (audio.out.codec == HB_ACODEC_VORBIS)))
3650 // avi/faac|vorbis combination is not supported.
3651 audio.out.codec = HB_ACODEC_LAME;
3653 if ((job->mux == HB_MUX_OGM) &&
3654 ((audio.out.codec == HB_ACODEC_FAAC) ||
3655 (audio.out.codec == HB_ACODEC_AC3) ||
3656 (audio.out.codec == HB_ACODEC_DCA)))
3658 // ogm/faac|ac3 combination is not supported.
3659 audio.out.codec = HB_ACODEC_VORBIS;
3661 audio.out.dynamic_range_compression =
3662 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3663 // It would be better if this were done in libhb for us, but its not yet.
3664 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3666 audio.out.mixdown = 0;
3670 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3671 // Make sure the mixdown is valid and pick a new one if not.
3672 audio.out.mixdown = ghb_get_best_mix(titleindex,
3673 audio.in.track, audio.out.codec, audio.out.mixdown);
3675 ghb_settings_combo_int(asettings, "AudioBitrate");
3676 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3677 if (srate == 0) // 0 is same as source
3678 audio.out.samplerate = taudio->in.samplerate;
3680 audio.out.samplerate = srate;
3683 // Add it to the jobs audio list
3684 hb_audio_add( job, &audio );
3687 // I was tempted to move this up with the reset of the video quality
3688 // settings, but I suspect the settings above need to be made
3689 // first in order for hb_calc_bitrate to be accurate.
3690 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3694 size = ghb_settings_get_int(js, "VideoTargetSize");
3695 job->vbitrate = hb_calc_bitrate( job, size );
3696 job->vquality = -1.0;
3699 dest_str = ghb_settings_get_string(js, "destination");
3700 job->file = dest_str;
3701 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3702 // TODO: libhb holds onto a reference to the x264opts and is not
3703 // finished with it until encoding the job is done. But I can't
3704 // find a way to get at the job before it is removed in order to
3705 // free up the memory I am allocating here.
3706 // The short story is THIS LEAKS.
3707 x264opts = ghb_build_x264opts_string(js);
3709 if( x264opts != NULL && *x264opts != '\0' )
3711 job->x264opts = x264opts;
3713 else /*avoids a bus error crash when options aren't specified*/
3715 job->x264opts = NULL;
3718 gchar *slang = ghb_settings_get_string(js, "Subtitles");
3719 subtitle = -2; // default to none
3720 if (strcmp(slang, "auto") == 0)
3727 hb_subtitle_t * subt;
3729 scount = hb_list_count(title->list_subtitle);
3730 for (ii = 0; ii < scount; ii++)
3732 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
3733 if (strcmp(slang, subt->iso639_2) == 0)
3740 gboolean forced_subtitles = ghb_settings_get_boolean(js, "SubtitlesForced");
3741 job->subtitle_force = forced_subtitles;
3743 job->subtitle = subtitle;
3748 // Subtitle scan. Look for subtitle matching audio language
3752 * When subtitle scan is enabled do a fast pre-scan job
3753 * which will determine which subtitles to enable, if any.
3756 job->indepth_scan = 1;
3758 x264opts_tmp = job->x264opts;
3759 job->x264opts = NULL;
3761 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3762 *(job->select_subtitle) = NULL;
3765 * Add the pre-scan job
3767 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3769 //if (job->x264opts != NULL)
3770 // g_free(job->x264opts);
3772 job->x264opts = x264opts_tmp;
3776 job->select_subtitle = NULL;
3778 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
3779 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3782 * If subtitle_scan is enabled then only turn it on
3783 * for the second pass and then off again for the
3786 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3787 job->select_subtitle = NULL;
3789 job->indepth_scan = 0;
3790 gchar *x264opts2 = NULL;
3793 x264opts2 = g_strdup(x264opts);
3796 * If turbo options have been selected then append them
3797 * to the x264opts now (size includes one ':' and the '\0')
3799 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
3805 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3811 * No x264opts to modify, but apply the turbo options
3812 * anyway as they may be modifying defaults
3814 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3816 x264opts = tmp_x264opts;
3818 job->x264opts = x264opts;
3820 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3822 //if (job->x264opts != NULL)
3823 // g_free(job->x264opts);
3825 job->select_subtitle = subtitle_tmp;
3828 * On the second pass we turn off subtitle scan so that we
3829 * can actually encode using any subtitles that were auto
3830 * selected in the first pass (using the whacky select-subtitle
3831 * attribute of the job).
3833 job->indepth_scan = 0;
3834 job->x264opts = x264opts2;
3835 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3837 //if (job->x264opts != NULL)
3838 // g_free(job->x264opts);
3842 job->indepth_scan = 0;
3844 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3846 //if (job->x264opts != NULL)
3847 // g_free(job->x264opts);
3849 if (detel_str) g_free(detel_str);
3850 if (decomb_str) g_free(decomb_str);
3851 if (deint_str) g_free(deint_str);
3852 if (deblock_str) g_free(deblock_str);
3853 if (denoise_str) g_free(denoise_str);
3854 if (dest_str) g_free(dest_str);
3858 ghb_add_job(GValue *js, gint unique_id)
3860 // Since I'm doing a scan of the single title I want just prior
3861 // to adding the job, there is only the one title to choose from.
3862 add_job(h_queue, js, unique_id, 0);
3866 ghb_add_live_job(GValue *js, gint unique_id)
3868 // Since I'm doing a scan of the single title I want just prior
3869 // to adding the job, there is only the one title to choose from.
3870 gint titleindex = ghb_settings_combo_int(js, "title");
3871 add_job(h_scan, js, unique_id, titleindex);
3875 ghb_remove_job(gint unique_id)
3880 // Multiples passes all get the same id
3882 // Go backwards through list, so reordering doesn't screw me.
3883 ii = hb_count(h_queue) - 1;
3884 while ((job = hb_job(h_queue, ii--)) != NULL)
3886 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3887 hb_rem(h_queue, job);
3894 hb_start( h_queue );
3904 ghb_start_live_encode()
3910 ghb_stop_live_encode()
3919 hb_get_state2( h_queue, &s );
3921 if( s.state == HB_STATE_PAUSED )
3923 hb_resume( h_queue );
3927 hb_pause( h_queue );
3931 #define RED_HEIGHT 720.0
3932 #define RED_WIDTH 1280.0
3935 ghb_get_preview_image(
3938 signal_user_data_t *ud,
3947 settings = ud->settings;
3948 list = hb_get_titles( h_scan );
3949 if( !hb_list_count( list ) )
3951 /* No valid title, stop right there */
3954 title = hb_list_item( list, titleindex );
3955 if (title == NULL) return NULL;
3956 if (title->job == NULL) return NULL;
3957 set_preview_job_settings(title->job, settings);
3959 // hb_get_preview can't handle sizes that are larger than the original title
3961 if (title->job->width > title->width)
3962 title->job->width = title->width;
3964 if (title->job->height > title->height)
3965 title->job->height = title->height;
3967 // hb_get_preview doesn't compensate for anamorphic, so lets
3968 // calculate scale factors
3969 gint width, height, par_width = 1, par_height = 1;
3970 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
3973 hb_set_anamorphic_size( title->job, &width, &height,
3974 &par_width, &par_height );
3977 // And also creates artifacts if the width is not a multiple of 8
3978 //title->job->width = ((title->job->width + 4) >> 3) << 3;
3979 // And the height must be a multiple of 2
3980 //title->job->height = ((title->job->height + 1) >> 1) << 1;
3982 // Make sure we have a big enough buffer to receive the image from libhb. libhb
3983 // creates images with a one-pixel border around the original content. Hence we
3984 // add 2 pixels horizontally and vertically to the buffer size.
3985 gint srcWidth = title->width + 2;
3986 gint srcHeight= title->height + 2;
3987 gint dstWidth = title->width;
3988 gint dstHeight= title->height;
3990 gint borderLeft = 1;
3993 // |<---------- title->width ----------->|
3994 // | |<---- title->job->width ---->| |
3996 // .......................................
3997 // ....+-----------------------------+....
3998 // ....| |....<-- gray border
4001 // ....| |<------- image
4007 // ....+-----------------------------+....
4008 // .......................................
4009 dstWidth = title->job->width;
4010 dstHeight = title->job->height;
4011 borderTop = (srcHeight - dstHeight) / 2;
4012 borderLeft = (srcWidth - dstWidth) / 2;
4013 g_debug("boarders removed\n");
4016 g_debug("src %d x %d\n", srcWidth, srcHeight);
4017 g_debug("dst %d x %d\n", dstWidth, dstHeight);
4018 g_debug("job dim %d x %d\n", title->job->width, title->job->height);
4019 g_debug("title crop %d:%d:%d:%d\n",
4024 g_debug("job crop %d:%d:%d:%d\n",
4025 title->job->crop[0],
4026 title->job->crop[1],
4027 title->job->crop[2],
4028 title->job->crop[3]);
4029 static guint8 *buffer = NULL;
4030 static gint bufferSize = 0;
4033 newSize = srcWidth * srcHeight * 4;
4034 if( bufferSize < newSize )
4036 bufferSize = newSize;
4037 buffer = (guint8*) g_realloc( buffer, bufferSize );
4039 hb_get_preview( h_scan, title, index, buffer );
4041 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4042 // libhb's format something suitable. Along the way, we'll strip off the
4043 // border around libhb's image.
4045 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
4046 // Alpha is ignored.
4048 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4049 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4051 guint32 *src = (guint32*)buffer;
4052 guint8 *dst = pixels;
4053 src += borderTop * srcWidth; // skip top rows in src to get to first row of dst
4054 src += borderLeft; // skip left pixels in src to get to first pixel of dst
4056 gint channels = gdk_pixbuf_get_n_channels (preview);
4057 gint stride = gdk_pixbuf_get_rowstride (preview);
4059 for (ii = 0; ii < dstHeight; ii++)
4062 for (jj = 0; jj < dstWidth; jj++)
4064 tmp[0] = src[0] >> 16;
4065 tmp[1] = src[0] >> 8;
4066 tmp[2] = src[0] >> 0;
4071 src += (srcWidth - dstWidth); // skip to next row in src
4073 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4074 *out_width = dstWidth;
4075 *out_height = dstHeight;
4076 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4080 gint orig_w, orig_h;
4083 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4087 ss = gdk_screen_get_default();
4088 s_w = gdk_screen_get_width(ss);
4089 s_h = gdk_screen_get_height(ss);
4093 if (dstWidth > s_w * factor / 100)
4095 dstWidth = s_w * factor / 100;
4096 dstHeight = dstHeight * dstWidth / orig_w;
4098 if (dstHeight > s_h * factor / 100)
4100 dstHeight = s_h * factor / 100;
4101 dstWidth = dstWidth * dstHeight / orig_h;
4104 g_debug("scaled %d x %d\n", dstWidth, dstHeight);
4105 GdkPixbuf *scaled_preview;
4106 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4107 g_object_unref (preview);
4108 return scaled_preview;
4112 sanitize_volname(gchar *name)
4137 ghb_dvd_volname(const gchar *device)
4140 name = hb_dvd_name((gchar*)device);
4143 sanitize_volname(name);
4144 return g_strdup(name);