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);
926 get_amix_value(gint val)
928 GValue *value = NULL;
931 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
933 if (hb_audio_mixdowns[ii].amixdown == val)
935 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
942 // Handle for libhb. Gets set by ghb_backend_init()
943 static hb_handle_t * h_scan = NULL;
944 static hb_handle_t * h_queue = NULL;
946 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
953 hb_get_tempory_directory(h_scan, dir);
954 return g_strdup(dir);
958 ghb_hb_cleanup(gboolean partial)
962 hb_get_tempory_directory(h_scan, dir);
963 del_tree(dir, !partial);
967 ghb_get_title_number(gint titleindex)
972 if (h_scan == NULL) return 1;
973 list = hb_get_titles( h_scan );
974 if( !hb_list_count( list ) )
976 /* No valid title, stop right there */
979 title = hb_list_item( list, titleindex );
980 if (title == NULL) return 1; // Bad titleindex
984 static hb_audio_config_t*
985 get_hb_audio(gint titleindex, gint track)
989 hb_audio_config_t *audio = NULL;
991 if (h_scan == NULL) return NULL;
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 NULL; // Bad titleindex
1000 if (!hb_list_count(title->list_audio))
1004 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1009 search_rates(hb_rate_t *rates, gint rate, gint count)
1012 for (ii = 0; ii < count; ii++)
1014 if (rates[ii].rate == rate)
1020 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1022 static GtkListStore*
1023 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1026 GtkListStore *store;
1028 g_debug("get_combo_box_store() %s\n", name);
1029 // First modify the combobox model to allow greying out of options
1030 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1031 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1036 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1038 GtkListStore *store;
1041 store = get_combo_box_store(builder, name);
1042 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1044 gtk_list_store_set(store, &iter,
1051 ghb_grey_combo_options(GtkBuilder *builder)
1054 gint container, track, titleindex, acodec;
1055 hb_audio_config_t *audio = NULL;
1058 widget = GHB_WIDGET (builder, "title");
1059 gval = ghb_widget_value(widget);
1060 titleindex = ghb_lookup_combo_int("title", gval);
1061 ghb_value_free(gval);
1062 widget = GHB_WIDGET (builder, "AudioTrack");
1063 gval = ghb_widget_value(widget);
1064 track = ghb_lookup_combo_int("AudioTrack", gval);
1065 ghb_value_free(gval);
1066 audio = get_hb_audio(titleindex, track);
1067 widget = GHB_WIDGET (builder, "FileFormat");
1068 gval = ghb_widget_value(widget);
1069 container = ghb_lookup_combo_int("FileFormat", gval);
1070 ghb_value_free(gval);
1072 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1073 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1074 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1075 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1077 gboolean allow_dca = TRUE;
1078 allow_dca = (container != HB_MUX_MP4);
1080 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1082 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1084 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1086 if (audio && audio->in.codec != HB_ACODEC_AC3)
1088 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1090 if (audio && audio->in.codec != HB_ACODEC_DCA)
1092 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1094 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1096 widget = GHB_WIDGET (builder, "AudioEncoder");
1097 gval = ghb_widget_value(widget);
1098 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1099 ghb_value_free(gval);
1100 if (acodec != HB_ACODEC_AC3)
1102 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1104 if (container == HB_MUX_MP4)
1106 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1107 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1108 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1110 else if (container == HB_MUX_AVI)
1112 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1113 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1114 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1116 else if (container == HB_MUX_OGM)
1118 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1121 gboolean allow_mono = TRUE;
1122 gboolean allow_stereo = TRUE;
1123 gboolean allow_dolby = TRUE;
1124 gboolean allow_dpl2 = TRUE;
1125 gboolean allow_6ch = TRUE;
1129 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1130 (acodec != HB_ACODEC_LAME);
1131 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1133 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1135 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1136 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1137 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1138 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1140 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1141 (acodec != HB_ACODEC_LAME) &&
1142 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1143 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1145 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1146 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1147 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1148 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1149 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1153 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1155 hb_audio_config_t *audio = NULL;
1156 gboolean allow_mono = TRUE;
1157 gboolean allow_stereo = TRUE;
1158 gboolean allow_dolby = TRUE;
1159 gboolean allow_dpl2 = TRUE;
1160 gboolean allow_6ch = TRUE;
1162 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1164 // Audio codec pass-thru. No mixdown
1167 audio = get_hb_audio(titleindex, track);
1171 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1172 (acodec != HB_ACODEC_LAME);
1173 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1175 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1177 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1178 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1179 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1180 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1182 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1183 (acodec != HB_ACODEC_LAME) &&
1184 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1185 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1187 gboolean greater = FALSE;
1190 // If no mix is specified, select the best available.
1191 mix = HB_AMIXDOWN_6CH;
1193 if (mix == HB_AMIXDOWN_6CH)
1196 if (allow_6ch) return HB_AMIXDOWN_6CH;
1198 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1201 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1203 if (mix == HB_AMIXDOWN_DOLBY || greater)
1206 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1208 if (mix == HB_AMIXDOWN_STEREO || greater)
1211 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1213 if (mix == HB_AMIXDOWN_MONO || greater)
1216 if (allow_mono) return HB_AMIXDOWN_MONO;
1218 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1219 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1220 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1221 if (allow_6ch) return HB_AMIXDOWN_6CH;
1225 // Set up the model for the combo box
1227 init_combo_box(GtkBuilder *builder, const gchar *name)
1230 GtkListStore *store;
1231 GtkCellRenderer *cell;
1233 g_debug("init_combo_box() %s\n", name);
1234 // First modify the combobox model to allow greying out of options
1235 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1237 // 1 - String to display
1238 // 2 - bool indicating whether the entry is selectable (grey or not)
1239 // 3 - String that is used for presets
1240 // 4 - Int value determined by backend
1241 // 5 - String value determined by backend
1242 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1243 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1244 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1246 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1248 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1249 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1250 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1251 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1252 "text", 0, "sensitive", 1, NULL);
1255 { // Combo box entry
1256 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1261 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1264 GtkListStore *store;
1267 g_debug("audio_samplerate_opts_set ()\n");
1268 store = get_combo_box_store(builder, name);
1269 gtk_list_store_clear(store);
1270 // Add an item for "Same As Source"
1271 gtk_list_store_append(store, &iter);
1272 gtk_list_store_set(store, &iter,
1273 0, "Same as source",
1279 for (ii = 0; ii < count; ii++)
1281 gtk_list_store_append(store, &iter);
1282 gtk_list_store_set(store, &iter,
1283 0, rates[ii].string,
1285 2, rates[ii].string,
1286 3, (gdouble)rates[ii].rate,
1287 4, rates[ii].string,
1293 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1296 GtkListStore *store;
1299 g_debug("video_rate_opts_set ()\n");
1300 store = get_combo_box_store(builder, name);
1301 gtk_list_store_clear(store);
1302 // Add an item for "Same As Source"
1303 gtk_list_store_append(store, &iter);
1304 gtk_list_store_set(store, &iter,
1305 0, "Same as source",
1311 for (ii = 0; ii < count; ii++)
1315 if (strcmp(rates[ii].string, "23.976") == 0)
1317 desc = "(NTSC Film)";
1319 else if (strcmp(rates[ii].string, "25") == 0)
1321 desc = "(PAL Film/Video)";
1323 else if (strcmp(rates[ii].string, "29.97") == 0)
1325 desc = "(NTSC Video)";
1327 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1328 gtk_list_store_append(store, &iter);
1329 gtk_list_store_set(store, &iter,
1332 2, rates[ii].string,
1333 3, (gdouble)rates[ii].rate,
1334 4, rates[ii].string,
1341 mix_opts_set(GtkBuilder *builder, const gchar *name)
1344 GtkListStore *store;
1347 g_debug("mix_opts_set ()\n");
1348 store = get_combo_box_store(builder, name);
1349 gtk_list_store_clear(store);
1350 gtk_list_store_append(store, &iter);
1351 gtk_list_store_set(store, &iter,
1358 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1360 gtk_list_store_append(store, &iter);
1361 gtk_list_store_set(store, &iter,
1362 0, hb_audio_mixdowns[ii].human_readable_name,
1364 2, hb_audio_mixdowns[ii].short_name,
1365 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1366 4, hb_audio_mixdowns[ii].internal_name,
1372 language_opts_set(GtkBuilder *builder, const gchar *name)
1375 GtkListStore *store;
1378 g_debug("language_opts_set ()\n");
1379 store = get_combo_box_store(builder, name);
1380 gtk_list_store_clear(store);
1381 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1383 gtk_list_store_append(store, &iter);
1384 gtk_list_store_set(store, &iter,
1385 0, ghb_language_table[ii].eng_name,
1387 2, ghb_language_table[ii].iso639_2,
1389 4, ghb_language_table[ii].iso639_1,
1394 static gchar **titles = NULL;
1397 title_opts_set(GtkBuilder *builder, const gchar *name)
1400 GtkListStore *store;
1401 hb_list_t * list = NULL;
1402 hb_title_t * title = NULL;
1406 g_debug("title_opts_set ()\n");
1407 store = get_combo_box_store(builder, name);
1408 gtk_list_store_clear(store);
1411 list = hb_get_titles( h_scan );
1412 count = hb_list_count( list );
1413 if (count > 100) count = 100;
1415 if (titles) g_strfreev(titles);
1416 if (title_opts.map) g_free(title_opts.map);
1419 title_opts.count = count;
1420 title_opts.map = g_malloc(count*sizeof(options_map_t));
1421 titles = g_malloc((count+1) * sizeof(gchar*));
1425 title_opts.count = 1;
1426 title_opts.map = g_malloc(sizeof(options_map_t));
1431 // No titles. Fill in a default.
1432 gtk_list_store_append(store, &iter);
1433 gtk_list_store_set(store, &iter,
1440 title_opts.map[0].option = "No Titles";
1441 title_opts.map[0].shortOpt = "none";
1442 title_opts.map[0].ivalue = -1;
1443 title_opts.map[0].svalue = "none";
1446 for (ii = 0; ii < count; ii++)
1448 title = (hb_title_t*)hb_list_item(list, ii);
1449 if (title->duration != 0)
1451 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1452 title->index, title->hours, title->minutes, title->seconds);
1456 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1458 gtk_list_store_append(store, &iter);
1459 gtk_list_store_set(store, &iter,
1466 title_opts.map[ii].option = titles[ii];
1467 title_opts.map[ii].shortOpt = titles[ii];
1468 title_opts.map[ii].ivalue = ii;
1469 title_opts.map[ii].svalue = titles[ii];
1475 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1478 gboolean foundit = FALSE;
1480 if (gtk_tree_model_get_iter_first (store, iter))
1484 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1485 if (value == (int)ivalue)
1490 } while (gtk_tree_model_iter_next (store, iter));
1496 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1499 GtkListStore *store;
1500 hb_list_t * list = NULL;
1501 hb_title_t * title = NULL;
1502 hb_audio_config_t * audio;
1506 g_debug("audio_track_opts_set ()\n");
1507 store = get_combo_box_store(builder, name);
1508 gtk_list_store_clear(store);
1511 list = hb_get_titles( h_scan );
1512 title = (hb_title_t*)hb_list_item( list, titleindex );
1515 count = hb_list_count( title->list_audio );
1518 if (count > 100) count = 100;
1519 if (audio_track_opts.map) g_free(audio_track_opts.map);
1522 audio_track_opts.count = count;
1523 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1527 audio_track_opts.count = 1;
1528 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1532 // No audio. set some default
1533 gtk_list_store_append(store, &iter);
1534 gtk_list_store_set(store, &iter,
1541 audio_track_opts.map[0].option = "No Audio";
1542 audio_track_opts.map[0].shortOpt = "none";
1543 audio_track_opts.map[0].ivalue = -1;
1544 audio_track_opts.map[0].svalue = "none";
1547 for (ii = 0; ii < count; ii++)
1549 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1550 gtk_list_store_append(store, &iter);
1551 gtk_list_store_set(store, &iter,
1552 0, audio->lang.description,
1558 audio_track_opts.map[ii].option = audio->lang.description,
1559 audio_track_opts.map[ii].shortOpt = index_str[ii];
1560 audio_track_opts.map[ii].ivalue = ii;
1561 audio_track_opts.map[ii].svalue = index_str[ii];
1567 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1570 GtkListStore *store;
1571 hb_list_t * list = NULL;
1572 hb_title_t * title = NULL;
1573 hb_subtitle_t * subtitle;
1577 g_debug("subtitle_opts_set () %s\n", name);
1578 store = get_combo_box_store(builder, name);
1579 gtk_list_store_clear(store);
1582 list = hb_get_titles( h_scan );
1583 title = (hb_title_t*)hb_list_item( list, titleindex );
1586 count = hb_list_count( title->list_subtitle );
1589 if (count > 100) count = 100;
1590 if (subtitle_opts.map) g_free(subtitle_opts.map);
1593 subtitle_opts.count = count+2;
1594 subtitle_opts.map = g_malloc((count+2)*sizeof(options_map_t));
1598 subtitle_opts.count = LANG_TABLE_SIZE+2;
1599 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+2)*sizeof(options_map_t));
1601 // Add options for "none" and "autoselect"
1602 gtk_list_store_append(store, &iter);
1603 gtk_list_store_set(store, &iter,
1610 subtitle_opts.map[0].option = "None";
1611 subtitle_opts.map[0].shortOpt = "none";
1612 subtitle_opts.map[0].ivalue = -2;
1613 subtitle_opts.map[0].svalue = "none";
1614 gtk_list_store_append(store, &iter);
1615 gtk_list_store_set(store, &iter,
1622 subtitle_opts.map[1].option = "Same as audio";
1623 subtitle_opts.map[1].shortOpt = "auto";
1624 subtitle_opts.map[1].ivalue = -1;
1625 subtitle_opts.map[1].svalue = "auto";
1628 for (ii = 0; ii < count; ii++)
1630 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1631 gtk_list_store_append(store, &iter);
1632 gtk_list_store_set(store, &iter,
1635 2, subtitle->iso639_2,
1637 4, subtitle->iso639_2,
1639 subtitle_opts.map[ii+2].option = subtitle->lang;
1640 subtitle_opts.map[ii+2].shortOpt = subtitle->iso639_2;
1641 subtitle_opts.map[ii+2].ivalue = ii;
1642 subtitle_opts.map[ii+2].svalue = subtitle->iso639_2;
1647 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1649 gtk_list_store_append(store, &iter);
1650 gtk_list_store_set(store, &iter,
1651 0, ghb_language_table[ii].eng_name,
1653 2, ghb_language_table[ii].iso639_2,
1655 4, ghb_language_table[ii].iso639_2,
1657 subtitle_opts.map[ii+2].option = ghb_language_table[ii].eng_name;
1658 subtitle_opts.map[ii+2].shortOpt = ghb_language_table[ii].iso639_2;
1659 subtitle_opts.map[ii+2].ivalue = ii;
1660 subtitle_opts.map[ii+2].svalue = ghb_language_table[ii].iso639_2;
1672 guint64 longest = 0;
1673 gint titleindex = 0;
1675 g_debug("ghb_longest_title ()\n");
1676 if (h_scan == NULL) return 0;
1677 list = hb_get_titles( h_scan );
1678 count = hb_list_count( list );
1679 if (count > 100) count = 100;
1680 for (ii = 0; ii < count; ii++)
1682 title = (hb_title_t*)hb_list_item(list, ii);
1683 if (title->duration > longest)
1686 longest = title->duration;
1693 ghb_find_audio_track(
1697 GHashTable *track_indices)
1701 hb_audio_config_t * audio;
1708 g_debug("find_audio_track ()\n");
1709 if (h_scan == NULL) return -1;
1710 list = hb_get_titles( h_scan );
1711 title = (hb_title_t*)hb_list_item( list, titleindex );
1714 count = hb_list_count( title->list_audio );
1716 if (count > 10) count = 10;
1717 used = g_hash_table_lookup(track_indices, &acodec);
1720 used = g_malloc0(count * sizeof(gboolean));
1721 g_hash_table_insert(track_indices, &acodec, used);
1723 // Try to find an item that matches the preferred language and
1724 // the passthru codec type
1725 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1727 for (ii = 0; ii < count; ii++)
1734 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1735 title->list_audio, ii );
1736 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1737 audio->in.channel_layout);
1738 // Find a track that is not visually impaired or dirctor's
1739 // commentary, and has the highest channel count.
1740 if ((audio->in.codec & acodec) &&
1741 (audio->lang.type < 2) &&
1742 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1743 (strcmp(lang, "und") == 0)))
1745 if (channels > max_chan)
1748 max_chan = channels;
1758 // Try to find an item that matches the preferred language
1759 for (ii = 0; ii < count; ii++)
1763 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1764 title->list_audio, ii );
1765 // Find a track that is not visually impaired or dirctor's commentary
1766 if ((audio->lang.type < 2) &&
1767 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1768 (strcmp(lang, "und") == 0)))
1779 // Try to fine an item that does not match the preferred language and
1780 // matches the passthru codec type
1781 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1783 for (ii = 0; ii < count; ii++)
1790 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1791 title->list_audio, ii );
1792 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1793 audio->in.channel_layout);
1794 // Find a track that is not visually impaired or dirctor's
1795 // commentary, and has the highest channel count.
1796 if ((audio->in.codec & acodec) &&
1797 (audio->lang.type < 2))
1799 if (channels > max_chan)
1802 max_chan = channels;
1812 // Try to fine an item that does not match the preferred language
1813 for (ii = 0; ii < count; ii++)
1817 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1818 title->list_audio, ii );
1819 // Find a track that is not visually impaired or dirctor's commentary
1820 if (audio->lang.type < 2)
1831 // Last ditch, anything goes
1832 for (ii = 0; ii < count; ii++)
1834 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1835 title->list_audio, ii );
1850 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1853 GtkListStore *store;
1856 g_debug("generic_opts_set ()\n");
1857 if (name == NULL || opts == NULL) return;
1858 store = get_combo_box_store(builder, name);
1859 gtk_list_store_clear(store);
1860 for (ii = 0; ii < opts->count; ii++)
1862 gtk_list_store_append(store, &iter);
1863 gtk_list_store_set(store, &iter,
1864 0, opts->map[ii].option,
1866 2, opts->map[ii].shortOpt,
1867 3, opts->map[ii].ivalue,
1868 4, opts->map[ii].svalue,
1874 find_combo_table(const gchar *name)
1878 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1880 if (strcmp(name, combo_name_map[ii].name) == 0)
1882 return combo_name_map[ii].opts;
1889 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
1891 if (strcmp(name, "AudioBitrate") == 0)
1892 return lookup_audio_bitrate_int(gval);
1893 else if (strcmp(name, "AudioSamplerate") == 0)
1894 return lookup_audio_rate_int(gval);
1895 else if (strcmp(name, "VideoFramerate") == 0)
1896 return lookup_video_rate_int(gval);
1897 else if (strcmp(name, "AudioMixdown") == 0)
1898 return lookup_mix_int(gval);
1899 else if (strcmp(name, "SourceAudioLang") == 0)
1900 return lookup_audio_lang_int(gval);
1903 return lookup_generic_int(find_combo_table(name), gval);
1905 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1910 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
1912 if (strcmp(name, "AudioBitrate") == 0)
1913 return lookup_audio_bitrate_int(gval);
1914 else if (strcmp(name, "AudioSamplerate") == 0)
1915 return lookup_audio_rate_int(gval);
1916 else if (strcmp(name, "VideoFramerate") == 0)
1917 return lookup_video_rate_int(gval);
1918 else if (strcmp(name, "AudioMixdown") == 0)
1919 return lookup_mix_int(gval);
1920 else if (strcmp(name, "SourceAudioLang") == 0)
1921 return lookup_audio_lang_int(gval);
1924 return lookup_generic_double(find_combo_table(name), gval);
1926 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
1931 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
1933 if (strcmp(name, "AudioBitrate") == 0)
1934 return lookup_audio_bitrate_option(gval);
1935 else if (strcmp(name, "AudioSamplerate") == 0)
1936 return lookup_audio_rate_option(gval);
1937 else if (strcmp(name, "VideoFramerate") == 0)
1938 return lookup_video_rate_option(gval);
1939 else if (strcmp(name, "AudioMixdown") == 0)
1940 return lookup_mix_option(gval);
1941 else if (strcmp(name, "SourceAudioLang") == 0)
1942 return lookup_audio_lang_option(gval);
1945 return lookup_generic_option(find_combo_table(name), gval);
1947 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1952 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1954 GtkComboBox *combo = NULL;
1956 gint handler_id = 0;
1960 g_debug("ghb_update_ui_combo_box() %s\n", name);
1961 // Clearing a combo box causes a rash of "changed" events, even when
1962 // the active item is -1 (inactive). To control things, I'm disabling
1963 // the event till things are settled down.
1964 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1965 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1968 // Valid signal id found. This should always succeed.
1969 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1970 signal_id, 0, 0, 0, 0);
1973 // This should also always succeed
1974 g_signal_handler_block ((gpointer)combo, handler_id);
1980 audio_bitrate_opts_set(builder, "AudioBitrate");
1981 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1982 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1983 mix_opts_set(builder, "AudioMixdown");
1984 language_opts_set(builder, "SourceAudioLang");
1985 subtitle_opts_set(builder, "Subtitles", user_data);
1986 title_opts_set(builder, "title");
1987 audio_track_opts_set(builder, "AudioTrack", user_data);
1988 generic_opts_set(builder, "VideoQualityGranularity", &vqual_granularity_opts);
1989 generic_opts_set(builder, "PicturePAR", &par_opts);
1990 generic_opts_set(builder, "PictureModulus", &alignment_opts);
1991 generic_opts_set(builder, "LoggingLevel", &logging_opts);
1992 generic_opts_set(builder, "FileFormat", &container_opts);
1993 generic_opts_set(builder, "PictureDeinterlace", &deint_opts);
1994 generic_opts_set(builder, "PictureDetelecine", &detel_opts);
1995 generic_opts_set(builder, "PictureDecomb", &decomb_opts);
1996 generic_opts_set(builder, "PictureDenoise", &denoise_opts);
1997 generic_opts_set(builder, "VideoEncoder", &vcodec_opts);
1998 generic_opts_set(builder, "AudioEncoder", &acodec_opts);
1999 generic_opts_set(builder, "x264_direct", &direct_opts);
2000 generic_opts_set(builder, "x264_b_adapt", &badapt_opts);
2001 generic_opts_set(builder, "x264_me", &me_opts);
2002 generic_opts_set(builder, "x264_subme", &subme_opts);
2003 generic_opts_set(builder, "x264_analyse", &analyse_opts);
2004 generic_opts_set(builder, "x264_trellis", &trellis_opts);
2008 if (strcmp(name, "AudioBitrate") == 0)
2009 audio_bitrate_opts_set(builder, "AudioBitrate");
2010 else if (strcmp(name, "AudioSamplerate") == 0)
2011 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2012 else if (strcmp(name, "VideoFramerate") == 0)
2013 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2014 else if (strcmp(name, "AudioMixdown") == 0)
2015 mix_opts_set(builder, "AudioMixdown");
2016 else if (strcmp(name, "SourceAudioLang") == 0)
2017 language_opts_set(builder, "SourceAudioLang");
2018 else if (strcmp(name, "Subtitles") == 0)
2019 subtitle_opts_set(builder, "Subtitles", user_data);
2020 else if (strcmp(name, "title") == 0)
2021 title_opts_set(builder, "title");
2022 else if (strcmp(name, "AudioTrack") == 0)
2023 audio_track_opts_set(builder, "AudioTrack", user_data);
2025 generic_opts_set(builder, name, find_combo_table(name));
2029 g_signal_handler_unblock ((gpointer)combo, handler_id);
2034 init_ui_combo_boxes(GtkBuilder *builder)
2038 init_combo_box(builder, "AudioBitrate");
2039 init_combo_box(builder, "AudioSamplerate");
2040 init_combo_box(builder, "VideoFramerate");
2041 init_combo_box(builder, "AudioMixdown");
2042 init_combo_box(builder, "SourceAudioLang");
2043 init_combo_box(builder, "Subtitles");
2044 init_combo_box(builder, "title");
2045 init_combo_box(builder, "AudioTrack");
2046 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2048 init_combo_box(builder, combo_name_map[ii].name);
2052 static const char * turbo_opts =
2053 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2054 "no-fast-pskip=0:8x8dct=0:weightb=0";
2056 // Construct the x264 options string
2057 // The result is allocated, so someone must free it at some point.
2059 ghb_build_x264opts_string(GValue *settings)
2062 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2069 result = g_strdup("");
2075 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2079 hb_chapter_t * chapter;
2082 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2083 *hh = *mm = *ss = 0;
2084 if (h_scan == NULL) return;
2085 list = hb_get_titles( h_scan );
2086 title = (hb_title_t*)hb_list_item( list, ti );
2087 if (title == NULL) return;
2088 count = hb_list_count( title->list_chapter );
2089 if (ii >= count) return;
2090 chapter = hb_list_item(title->list_chapter, ii);
2091 if (chapter == NULL) return;
2092 *hh = chapter->hours;
2093 *mm = chapter->minutes;
2094 *ss = chapter->seconds;
2098 ghb_get_chapters(gint titleindex)
2102 hb_chapter_t * chapter;
2104 GValue *chapters = NULL;
2106 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2107 if (h_scan == NULL) return NULL;
2108 list = hb_get_titles( h_scan );
2109 title = (hb_title_t*)hb_list_item( list, titleindex );
2110 if (title == NULL) return NULL;
2111 count = hb_list_count( title->list_chapter );
2112 chapters = ghb_array_value_new(count);
2113 for (ii = 0; ii < count; ii++)
2115 chapter = hb_list_item(title->list_chapter, ii);
2116 if (chapter == NULL) break;
2117 if (chapter->title == NULL || chapter->title[0] == 0)
2120 str = g_strdup_printf ("Chapter %2d", ii+1);
2121 ghb_array_append(chapters, ghb_string_value_new(str));
2126 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2133 ghb_ac3_in_audio_list(const GValue *audio_list)
2137 count = ghb_array_len(audio_list);
2138 for (ii = 0; ii < count; ii++)
2143 asettings = ghb_array_get_nth(audio_list, ii);
2144 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2145 if (acodec == HB_ACODEC_AC3)
2152 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2155 GtkListStore *store;
2158 g_debug("audio_rate_opts_add ()\n");
2159 store = get_combo_box_store(builder, name);
2160 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2162 str = g_strdup_printf ("%d", rate);
2163 gtk_list_store_append(store, &iter);
2164 gtk_list_store_set(store, &iter,
2176 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2179 GtkListStore *store;
2181 gboolean done = FALSE;
2183 guint last = (guint)last_rate;
2185 g_debug("audio_bitrate_opts_clean ()\n");
2186 store = get_combo_box_store(builder, name);
2187 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2191 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2193 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2195 done = !gtk_list_store_remove(store, &iter);
2197 else if (ivalue > last)
2200 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2201 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2206 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2207 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2214 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2217 GtkListStore *store;
2220 g_debug("audio_bitrate_opts_set ()\n");
2221 store = get_combo_box_store(builder, name);
2222 gtk_list_store_clear(store);
2223 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2225 gtk_list_store_append(store, &iter);
2226 gtk_list_store_set(store, &iter,
2227 0, hb_audio_bitrates[ii].string,
2229 2, hb_audio_bitrates[ii].string,
2230 3, (gdouble)hb_audio_bitrates[ii].rate,
2231 4, hb_audio_bitrates[ii].string,
2237 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2239 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2243 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2245 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2248 static ghb_status_t hb_status;
2251 ghb_combo_init(GtkBuilder *builder)
2253 // Set up the list model for the combos
2254 init_ui_combo_boxes(builder);
2255 // Populate all the combos
2256 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
2260 ghb_backend_init(gint debug)
2263 h_scan = hb_init( debug, 0 );
2264 h_queue = hb_init( debug, 0 );
2275 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2277 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2278 hb_status.scan.state |= GHB_STATE_SCANNING;
2279 // initialize count and cur to something that won't cause FPE
2280 // when computing progress
2281 hb_status.scan.title_count = 1;
2282 hb_status.scan.title_cur = 0;
2286 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2288 g_debug("ghb_backend_queue_scan()");
2289 hb_scan( h_queue, path, titlenum, 10, 0 );
2290 hb_status.queue.state |= GHB_STATE_SCANNING;
2294 ghb_get_scan_state()
2296 return hb_status.scan.state;
2300 ghb_get_queue_state()
2302 return hb_status.queue.state;
2306 ghb_clear_scan_state(gint state)
2308 hb_status.scan.state &= ~state;
2312 ghb_clear_queue_state(gint state)
2314 hb_status.queue.state &= ~state;
2318 ghb_set_scan_state(gint state)
2320 hb_status.scan.state |= state;
2324 ghb_set_queue_state(gint state)
2326 hb_status.queue.state |= state;
2330 ghb_get_status(ghb_status_t *status)
2332 memcpy(status, &hb_status, sizeof(ghb_status_t));
2341 if (h_scan == NULL) return;
2342 hb_get_state( h_scan, &s_scan );
2343 switch( s_scan.state )
2345 #define p s_scan.param.scanning
2346 case HB_STATE_SCANNING:
2348 hb_status.scan.state |= GHB_STATE_SCANNING;
2349 hb_status.scan.title_count = p.title_count;
2350 hb_status.scan.title_cur = p.title_cur;
2354 case HB_STATE_SCANDONE:
2356 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2357 hb_status.scan.state |= GHB_STATE_SCANDONE;
2360 #define p s_scan.param.working
2361 case HB_STATE_WORKING:
2362 hb_status.scan.state |= GHB_STATE_WORKING;
2363 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2364 hb_status.scan.job_cur = p.job_cur;
2365 hb_status.scan.job_count = p.job_count;
2366 hb_status.scan.progress = p.progress;
2367 hb_status.scan.rate_cur = p.rate_cur;
2368 hb_status.scan.rate_avg = p.rate_avg;
2369 hb_status.scan.hours = p.hours;
2370 hb_status.scan.minutes = p.minutes;
2371 hb_status.scan.seconds = p.seconds;
2372 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2376 case HB_STATE_PAUSED:
2377 hb_status.scan.state |= GHB_STATE_PAUSED;
2380 case HB_STATE_MUXING:
2382 hb_status.scan.state |= GHB_STATE_MUXING;
2385 #define p s_scan.param.workdone
2386 case HB_STATE_WORKDONE:
2390 hb_status.scan.state |= GHB_STATE_WORKDONE;
2391 hb_status.scan.state &= ~GHB_STATE_MUXING;
2392 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2393 hb_status.scan.state &= ~GHB_STATE_WORKING;
2397 hb_status.scan.error = GHB_ERROR_NONE;
2399 case HB_ERROR_CANCELED:
2400 hb_status.scan.error = GHB_ERROR_CANCELED;
2403 hb_status.scan.error = GHB_ERROR_FAIL;
2406 // Delete all remaining jobs of this encode.
2407 // An encode can be composed of multiple associated jobs.
2408 // When a job is stopped, libhb removes it from the job list,
2409 // but does not remove other jobs that may be associated with it.
2410 // Associated jobs are taged in the sequence id.
2411 while ((job = hb_job(h_scan, 0)) != NULL)
2412 hb_rem( h_scan, job );
2416 hb_get_state( h_queue, &s_queue );
2417 switch( s_queue.state )
2419 #define p s_queue.param.scanning
2420 case HB_STATE_SCANNING:
2422 hb_status.queue.state |= GHB_STATE_SCANNING;
2423 hb_status.queue.title_count = p.title_count;
2424 hb_status.queue.title_cur = p.title_cur;
2428 case HB_STATE_SCANDONE:
2430 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2431 hb_status.queue.state |= GHB_STATE_SCANDONE;
2434 #define p s_queue.param.working
2435 case HB_STATE_WORKING:
2436 hb_status.queue.state |= GHB_STATE_WORKING;
2437 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2438 hb_status.queue.job_cur = p.job_cur;
2439 hb_status.queue.job_count = p.job_count;
2440 hb_status.queue.progress = p.progress;
2441 hb_status.queue.rate_cur = p.rate_cur;
2442 hb_status.queue.rate_avg = p.rate_avg;
2443 hb_status.queue.hours = p.hours;
2444 hb_status.queue.minutes = p.minutes;
2445 hb_status.queue.seconds = p.seconds;
2446 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2450 case HB_STATE_PAUSED:
2451 hb_status.queue.state |= GHB_STATE_PAUSED;
2454 case HB_STATE_MUXING:
2456 hb_status.queue.state |= GHB_STATE_MUXING;
2459 #define p s_queue.param.workdone
2460 case HB_STATE_WORKDONE:
2464 hb_status.queue.state |= GHB_STATE_WORKDONE;
2465 hb_status.queue.state &= ~GHB_STATE_MUXING;
2466 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2467 hb_status.queue.state &= ~GHB_STATE_WORKING;
2471 hb_status.queue.error = GHB_ERROR_NONE;
2473 case HB_ERROR_CANCELED:
2474 hb_status.queue.error = GHB_ERROR_CANCELED;
2477 hb_status.queue.error = GHB_ERROR_FAIL;
2480 // Delete all remaining jobs of this encode.
2481 // An encode can be composed of multiple associated jobs.
2482 // When a job is stopped, libhb removes it from the job list,
2483 // but does not remove other jobs that may be associated with it.
2484 // Associated jobs are taged in the sequence id.
2485 while ((job = hb_job(h_queue, 0)) != NULL)
2486 hb_rem( h_queue, job );
2493 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2498 if (h_scan == NULL) return FALSE;
2499 list = hb_get_titles( h_scan );
2500 if( !hb_list_count( list ) )
2502 /* No valid title, stop right there */
2506 title = hb_list_item( list, titleindex );
2507 if (title == NULL) return FALSE; // Bad titleindex
2508 tinfo->width = title->width;
2509 tinfo->height = title->height;
2510 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2511 // Don't allow crop to 0
2512 if (title->crop[0] + title->crop[1] >= title->height)
2513 title->crop[0] = title->crop[1] = 0;
2514 if (title->crop[2] + title->crop[3] >= title->width)
2515 title->crop[2] = title->crop[3] = 0;
2516 tinfo->num_chapters = hb_list_count(title->list_chapter);
2517 tinfo->rate_base = title->rate_base;
2518 tinfo->rate = title->rate;
2519 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2520 title->width * title->pixel_aspect_width,
2521 title->height * title->pixel_aspect_height);
2522 tinfo->hours = title->hours;
2523 tinfo->minutes = title->minutes;
2524 tinfo->seconds = title->seconds;
2525 tinfo->duration = title->duration;
2527 tinfo->angle_count = title->angle_count;
2532 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2534 hb_audio_config_t *audio;
2536 audio = get_hb_audio(titleindex, audioindex);
2537 if (audio == NULL) return FALSE; // Bad audioindex
2538 ainfo->codec = audio->in.codec;
2539 ainfo->bitrate = audio->in.bitrate;
2540 ainfo->samplerate = audio->in.samplerate;
2545 ghb_audio_is_passthru(gint acodec)
2547 g_debug("ghb_audio_is_passthru () \n");
2548 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2552 ghb_get_default_acodec()
2554 return HB_ACODEC_FAAC;
2558 picture_settings_deps(signal_user_data_t *ud)
2560 gboolean autoscale, keep_aspect, enable_keep_aspect;
2561 gboolean enable_scale_width, enable_scale_height;
2562 gboolean enable_disp_width, enable_disp_height;
2566 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2569 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2570 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2571 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2573 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2574 if (!enable_keep_aspect)
2576 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2578 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2579 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2581 enable_scale_width = !autoscale && (pic_par != 1);
2582 enable_scale_height = !autoscale && (pic_par != 1);
2583 enable_disp_width = (pic_par == 3) && !keep_aspect;
2584 enable_disp_height = FALSE;
2586 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2587 gtk_widget_set_sensitive(widget, pic_par != 1);
2588 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2589 gtk_widget_set_sensitive(widget, pic_par != 1);
2590 widget = GHB_WIDGET(ud->builder, "scale_width");
2591 gtk_widget_set_sensitive(widget, enable_scale_width);
2592 widget = GHB_WIDGET(ud->builder, "scale_height");
2593 gtk_widget_set_sensitive(widget, enable_scale_height);
2594 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2595 gtk_widget_set_sensitive(widget, enable_disp_width);
2596 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2597 gtk_widget_set_sensitive(widget, enable_disp_height);
2598 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2599 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2600 widget = GHB_WIDGET(ud->builder, "autoscale");
2601 gtk_widget_set_sensitive(widget, pic_par != 1);
2605 ghb_set_scale(signal_user_data_t *ud, gint mode)
2610 gboolean keep_aspect;
2612 gboolean autocrop, autoscale, noscale;
2613 gint crop[4], width, height, par_width, par_height;
2614 gint crop_width, crop_height;
2615 gint aspect_n, aspect_d;
2616 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2617 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2622 gint max_height = 0;
2623 static gboolean busy = FALSE;
2625 g_debug("ghb_set_scale ()\n");
2626 if (h_scan == NULL) return;
2627 list = hb_get_titles( h_scan );
2628 if( !hb_list_count( list ) )
2630 /* No valid title, stop right there */
2635 titleindex = ghb_settings_combo_int(ud->settings, "title");
2636 title = hb_list_item( list, titleindex );
2637 if (title == NULL) return;
2639 if (job == NULL) return;
2641 picture_settings_deps(ud);
2646 // First configure widgets
2647 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2648 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2649 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2650 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2651 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2652 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2653 // alignment constraints rather than scaling to satisfy them.
2654 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2655 // Align dimensions to either 16 or 2 pixels
2656 // The scaler crashes if the dimensions are not divisible by 2
2657 // x264 also will not accept dims that are not multiple of 2
2661 keep_height = FALSE;
2663 // Step needs to be at least 2 because odd widths cause scaler crash
2665 widget = GHB_WIDGET (ud->builder, "scale_width");
2666 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2667 widget = GHB_WIDGET (ud->builder, "scale_height");
2668 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2671 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2672 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2673 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2674 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2675 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2676 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2677 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2678 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2682 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2683 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2684 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2685 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2686 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2687 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2688 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2689 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2691 ghb_title_info_t tinfo;
2692 ghb_get_title_info (&tinfo, titleindex);
2695 crop[0] = tinfo.crop[0];
2696 crop[1] = tinfo.crop[1];
2697 crop[2] = tinfo.crop[2];
2698 crop[3] = tinfo.crop[3];
2699 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2700 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2701 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2702 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2706 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2707 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2708 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2709 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2715 // Adjust the cropping to accomplish the desired width and height
2716 crop_width = tinfo.width - crop[2] - crop[3];
2717 crop_height = tinfo.height - crop[0] - crop[1];
2718 width = MOD_DOWN(crop_width, mod);
2719 height = MOD_DOWN(crop_height, mod);
2721 need1 = (crop_height - height) / 2;
2722 need2 = crop_height - height - need1;
2725 need1 = (crop_width - width) / 2;
2726 need2 = crop_width - width - need1;
2729 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2730 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2731 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2732 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2734 hb_reduce(&aspect_n, &aspect_d,
2735 title->width * title->pixel_aspect_width,
2736 title->height * title->pixel_aspect_height);
2737 crop_width = title->width - crop[2] - crop[3];
2738 crop_height = title->height - crop[0] - crop[1];
2742 height = crop_height;
2746 width = ghb_settings_get_int(ud->settings, "scale_width");
2747 height = ghb_settings_get_int(ud->settings, "scale_height");
2748 max_width = MOD_DOWN(
2749 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
2750 max_height = MOD_DOWN(
2751 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
2753 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2756 width = title->width - crop[2] - crop[3];
2758 height = title->height - crop[0] - crop[1];
2760 width = MOD_ROUND(width, mod);
2761 height = MOD_ROUND(height, mod);
2763 // Adjust dims according to max values
2765 height = MIN(height, max_height);
2767 width = MIN(width, max_width);
2771 job->anamorphic.mode = pic_par;
2772 // The scaler crashes if the dimensions are not divisible by 2
2773 // Align mod 2. And so does something in x264_encoder_headers()
2774 job->anamorphic.modulus = mod;
2775 if (keep_height && pic_par == 2)
2776 width = ((double)height * crop_width / crop_height) + 0.5;
2778 job->height = height;
2780 job->maxWidth = max_width;
2782 job->maxHeight = max_height;
2783 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2784 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2785 if (job->anamorphic.mode == 3 && !keep_aspect)
2787 gint dar_width, dar_height;
2788 if (mode & GHB_PIC_KEEP_PAR)
2790 par_width = ghb_settings_get_int(ud->settings,
2792 par_height = ghb_settings_get_int(ud->settings,
2793 "PicturePARHeight");
2794 dar_width = ((gdouble)width * par_width / par_height) + 0.5;
2795 dar_height = height;
2799 dar_width = ghb_settings_get_int(ud->settings,
2800 "PictureDisplayWidth");
2801 dar_height = ghb_settings_get_int(ud->settings,
2802 "PictureDisplayHeight");
2804 job->anamorphic.dar_width = dar_width;
2805 job->anamorphic.dar_height = dar_height;
2809 job->anamorphic.dar_width = 0;
2810 job->anamorphic.dar_height = 0;
2812 hb_set_anamorphic_size( job, &width, &height,
2813 &par_width, &par_height );
2817 job->anamorphic.mode = pic_par;
2821 gint new_width, new_height;
2823 // Compute pixel aspect ration.
2824 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2825 // Must scale so that par becomes 1:1
2826 // Try to keep largest dimension
2827 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2828 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2830 if (max_width && new_width > max_width)
2832 height = new_height;
2834 else if (max_height && new_height > max_height)
2838 else if (keep_width)
2840 height = new_height;
2842 else if (keep_height)
2846 else if (width > new_width)
2848 height = new_height;
2854 g_debug("new w %d h %d\n", width, height);
2856 width = MOD_ROUND(width, mod);
2857 height = MOD_ROUND(height, mod);
2859 height = MIN(height, max_height);
2861 width = MIN(width, max_width);
2862 par_width = par_height = 1;
2864 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2865 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2867 gint disp_width, dar_width, dar_height;
2870 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
2871 hb_reduce(&dar_width, &dar_height, disp_width, height);
2873 gint iaspect = dar_width * 9 / dar_height;
2874 if (dar_width > 2 * dar_height)
2876 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
2878 else if (iaspect <= 16 && iaspect >= 15)
2880 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
2882 else if (iaspect <= 12 && iaspect >= 11)
2884 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
2888 str = g_strdup_printf("%d : %d", dar_width, dar_height);
2890 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
2892 ghb_ui_update(ud, "par_width", ghb_int64_value(par_width));
2893 ghb_ui_update(ud, "par_height", ghb_int64_value(par_height));
2894 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
2895 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
2900 set_preview_job_settings(hb_job_t *job, GValue *settings)
2902 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
2903 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
2904 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
2905 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
2907 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
2908 job->anamorphic.modulus =
2909 ghb_settings_combo_int(settings, "PictureModulus");
2910 job->width = ghb_settings_get_int(settings, "scale_width");
2911 job->height = ghb_settings_get_int(settings, "scale_height");
2912 if (ghb_settings_get_boolean(settings, "show_crop"))
2918 job->width = job->title->width;
2919 job->height = job->title->height;
2920 job->anamorphic.modulus = 2;
2923 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
2924 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
2925 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2927 gboolean keep_aspect;
2928 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
2929 if (job->anamorphic.mode == 3 && !keep_aspect)
2931 gint disp_width, disp_height;
2932 disp_width = ghb_settings_get_int(settings, "PictureDisplayWidth");
2933 disp_height = ghb_settings_get_int(settings, "PictureDisplayHeight");
2934 job->anamorphic.dar_width = disp_width;
2935 job->anamorphic.dar_height = disp_height;
2939 job->anamorphic.dar_width = 0;
2940 job->anamorphic.dar_height = 0;
2945 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2952 if (h_scan == NULL) return 1500;
2953 list = hb_get_titles( h_scan );
2954 title = hb_list_item( list, titleindex );
2955 if (title == NULL) return 1500;
2957 if (job == NULL) return 1500;
2958 size = ghb_settings_get_int(settings, "VideoTargetSize");
2959 return hb_calc_bitrate( job, size );
2963 ghb_validate_filter_string(const gchar *str, gint max_fields)
2969 if (str == NULL || *str == 0) return TRUE;
2972 val = g_strtod(str, &end);
2974 { // Found a numeric value
2976 // negative max_fields means infinate
2977 if (max_fields >= 0 && fields > max_fields) return FALSE;
2991 ghb_validate_filters(signal_user_data_t *ud)
2998 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3001 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3002 if (!ghb_validate_filter_string(str, 4))
3004 message = g_strdup_printf(
3005 "Invalid Deinterlace Settings:\n\n%s\n",
3007 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3015 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3018 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3019 if (!ghb_validate_filter_string(str, 6))
3021 message = g_strdup_printf(
3022 "Invalid Detelecine Settings:\n\n%s\n",
3024 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3032 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3035 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3036 if (!ghb_validate_filter_string(str, 7))
3038 message = g_strdup_printf(
3039 "Invalid Decomb Settings:\n\n%s\n",
3041 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3049 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3052 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3053 if (!ghb_validate_filter_string(str, 4))
3055 message = g_strdup_printf(
3056 "Invalid Denoise Settings:\n\n%s\n",
3058 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3069 ghb_validate_video(signal_user_data_t *ud)
3074 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3075 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3076 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3077 (vcodec == HB_VCODEC_THEORA))
3079 // mp4|avi/theora combination is not supported.
3080 message = g_strdup_printf(
3081 "Theora is not supported in the MP4 and AVI containers.\n\n"
3082 "You should choose a different video codec or container.\n"
3083 "If you continue, XviD will be chosen for you.");
3084 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3090 vcodec = HB_VCODEC_XVID;
3091 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3097 ghb_validate_audio(signal_user_data_t *ud)
3104 if (h_scan == NULL) return FALSE;
3105 list = hb_get_titles( h_scan );
3106 if( !hb_list_count( list ) )
3108 /* No valid title, stop right there */
3109 g_message("No title found.\n");
3115 titleindex = ghb_settings_combo_int(ud->settings, "title");
3116 title = hb_list_item( list, titleindex );
3117 if (title == NULL) return FALSE;
3118 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3120 const GValue *audio_list;
3123 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3124 count = ghb_array_len(audio_list);
3125 for (ii = 0; ii < count; ii++)
3128 hb_audio_config_t *taudio;
3130 asettings = ghb_array_get_nth(audio_list, ii);
3131 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3132 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3133 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3134 title->list_audio, track );
3135 if (!(taudio->in.codec & codec) &&
3136 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3138 // Not supported. AC3 is passthrough only, so input must be AC3
3139 message = g_strdup_printf(
3140 "The source does not support Pass-Thru.\n\n"
3141 "You should choose a different audio codec.\n"
3142 "If you continue, one will be chosen for you.");
3143 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3149 if (mux == HB_MUX_AVI)
3151 codec = HB_ACODEC_LAME;
3155 codec = HB_ACODEC_FAAC;
3157 value = get_acodec_value(codec);
3158 ghb_settings_take_value(asettings, "AudioEncoder", value);
3160 gchar *a_unsup = NULL;
3161 gchar *mux_s = NULL;
3162 if (mux == HB_MUX_MP4)
3165 // mp4/mp3|vorbis combination is not supported.
3166 if (codec == HB_ACODEC_LAME)
3169 codec = HB_ACODEC_FAAC;
3171 if (codec == HB_ACODEC_VORBIS)
3174 codec = HB_ACODEC_FAAC;
3176 if (codec == HB_ACODEC_DCA)
3179 codec = HB_ACODEC_FAAC;
3182 else if (mux == HB_MUX_AVI)
3185 // avi/faac|vorbis combination is not supported.
3186 if (codec == HB_ACODEC_FAAC)
3189 codec = HB_ACODEC_LAME;
3191 if (codec == HB_ACODEC_VORBIS)
3194 codec = HB_ACODEC_LAME;
3197 else if (mux == HB_MUX_OGM)
3200 // avi/faac|vorbis combination is not supported.
3201 if (codec == HB_ACODEC_FAAC)
3204 codec = HB_ACODEC_VORBIS;
3206 if (codec == HB_ACODEC_AC3)
3209 codec = HB_ACODEC_VORBIS;
3211 if (codec == HB_ACODEC_DCA)
3214 codec = HB_ACODEC_VORBIS;
3219 message = g_strdup_printf(
3220 "%s is not supported in the %s container.\n\n"
3221 "You should choose a different audio codec.\n"
3222 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3223 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3229 value = get_acodec_value(codec);
3230 ghb_settings_take_value(asettings, "AudioEncoder", value);
3232 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3233 gboolean allow_mono = TRUE;
3234 gboolean allow_stereo = TRUE;
3235 gboolean allow_dolby = TRUE;
3236 gboolean allow_dpl2 = TRUE;
3237 gboolean allow_6ch = TRUE;
3239 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3240 (codec != HB_ACODEC_LAME);
3241 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3243 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3245 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3246 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3247 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3248 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3250 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3251 (codec != HB_ACODEC_LAME) &&
3252 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3253 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3255 gchar *mix_unsup = NULL;
3256 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3260 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3262 mix_unsup = "stereo";
3264 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3266 mix_unsup = "Dolby";
3268 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3270 mix_unsup = "Dolby Pro Logic II";
3272 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3274 mix_unsup = "6 Channel";
3278 message = g_strdup_printf(
3279 "The source audio does not support %s mixdown.\n\n"
3280 "You should choose a different mixdown.\n"
3281 "If you continue, one will be chosen for you.", mix_unsup);
3282 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3288 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3289 value = get_amix_value(mix);
3290 ghb_settings_take_value(asettings, "AudioMixdown", value);
3297 ghb_validate_vquality(GValue *settings)
3303 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3304 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3306 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3307 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3311 case HB_VCODEC_X264:
3317 case HB_VCODEC_XVID:
3318 case HB_VCODEC_FFMPEG:
3324 case HB_VCODEC_THEORA:
3336 if (vquality < min || vquality > max)
3338 message = g_strdup_printf(
3339 "Interesting video quality choise: %d\n\n"
3340 "Typical values range from %d to %d.\n"
3341 "Are you sure you wish to use this setting?",
3342 (gint)vquality, min, max);
3343 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3344 "Cancel", "Continue"))
3356 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3361 static gchar *x264opts;
3363 gboolean tweaks = FALSE;
3364 gchar *detel_str = NULL;
3365 gchar *decomb_str = NULL;
3366 gchar *deint_str = NULL;
3367 gchar *deblock_str = NULL;
3368 gchar *denoise_str = NULL;
3369 gchar *dest_str = NULL;
3371 g_debug("add_job()\n");
3372 if (h == NULL) return;
3373 list = hb_get_titles( h );
3374 if( !hb_list_count( list ) )
3376 /* No valid title, stop right there */
3380 title = hb_list_item( list, titleindex );
3381 if (title == NULL) return;
3383 /* Set job settings */
3385 if (job == NULL) return;
3387 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3388 if (job->start_at_preview)
3390 job->seek_points = ghb_settings_get_int(js, "preview_count");
3391 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3394 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3395 job->mux = ghb_settings_combo_int(js, "FileFormat");
3396 if (job->mux == HB_MUX_MP4)
3398 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3399 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3403 job->largeFileSize = FALSE;
3404 job->mp4_optimize = FALSE;
3406 if (!job->start_at_preview)
3408 gint chapter_start, chapter_end;
3409 chapter_start = ghb_settings_get_int(js, "start_chapter");
3410 chapter_end = ghb_settings_get_int(js, "end_chapter");
3411 gint num_chapters = hb_list_count(title->list_chapter);
3412 job->chapter_start = MIN( num_chapters, chapter_start );
3413 job->chapter_end = MAX( job->chapter_start, chapter_end );
3415 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3416 if (job->chapter_start == job->chapter_end)
3417 job->chapter_markers = 0;
3418 if ( job->chapter_markers )
3425 chapters = ghb_settings_get_value(js, "chapter_list");
3426 count = ghb_array_len(chapters);
3427 for(chap = chapter_start; chap <= chapter_end; chap++)
3429 hb_chapter_t * chapter_s;
3435 chapter = ghb_array_get_nth(chapters, chap-1);
3436 name = ghb_value_string(chapter);
3440 name = g_strdup_printf ("Chapter %2d", chap);
3442 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3443 strncpy(chapter_s->title, name, 1023);
3444 chapter_s->title[1023] = '\0';
3449 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3450 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3451 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3452 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3455 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3456 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3458 job->deinterlace = (deint != 0) ? 1 : 0;
3460 job->deinterlace = 0;
3461 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3463 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3464 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3466 /* Add selected filters */
3467 job->filters = hb_list_init();
3468 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3473 if (detel_opts.map[detel].svalue != NULL)
3474 detel_str = g_strdup(detel_opts.map[detel].svalue);
3477 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3478 hb_filter_detelecine.settings = detel_str;
3479 hb_list_add( job->filters, &hb_filter_detelecine );
3485 if (decomb_opts.map[decomb].svalue != NULL)
3486 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3489 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3490 hb_filter_decomb.settings = decomb_str;
3491 hb_list_add( job->filters, &hb_filter_decomb );
3493 if( job->deinterlace )
3497 if (deint_opts.map[deint].svalue != NULL)
3498 deint_str = g_strdup(deint_opts.map[deint].svalue);
3501 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3502 hb_filter_deinterlace.settings = deint_str;
3503 hb_list_add( job->filters, &hb_filter_deinterlace );
3505 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3508 deblock_str = g_strdup_printf("%d", deblock);
3509 hb_filter_deblock.settings = deblock_str;
3510 hb_list_add( job->filters, &hb_filter_deblock );
3512 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3517 if (denoise_opts.map[denoise].svalue != NULL)
3518 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3521 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3522 hb_filter_denoise.settings = denoise_str;
3523 hb_list_add( job->filters, &hb_filter_denoise );
3525 job->width = ghb_settings_get_int(js, "scale_width");
3526 job->height = ghb_settings_get_int(js, "scale_height");
3528 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3529 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3530 (job->vcodec == HB_VCODEC_THEORA))
3532 // mp4|avi/theora combination is not supported.
3533 job->vcodec = HB_VCODEC_XVID;
3535 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3537 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3539 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3542 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3543 job->vquality = vquality;
3546 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3548 job->vquality = -1.0;
3549 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3552 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3555 job->vrate = title->rate;
3556 job->vrate_base = title->rate_base;
3561 job->vrate = 27000000;
3562 job->vrate_base = vrate;
3566 // AVI container does not support variable frame rate.
3567 // OGM supports variable frame rate, but bases all timing on
3568 // DTS, which breaks when b-frames are used since it is
3569 // impossible to reconstruct PTS from DTS when the framerate
3571 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3576 // First remove any audios that are already in the list
3577 // This happens if you are encoding the same title a second time.
3578 gint num_audio_tracks = hb_list_count(job->list_audio);
3580 for(ii = 0; ii < num_audio_tracks; ii++)
3582 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3583 hb_list_rem(job->list_audio, audio);
3586 const GValue *audio_list;
3590 audio_list = ghb_settings_get_value(js, "audio_list");
3591 count = ghb_array_len(audio_list);
3592 for (ii = 0; ii < count; ii++)
3595 hb_audio_config_t audio;
3596 hb_audio_config_t *taudio;
3598 hb_audio_config_init(&audio);
3599 asettings = ghb_array_get_nth(audio_list, ii);
3600 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3601 audio.out.track = tcount;
3602 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3603 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3604 title->list_audio, audio.in.track );
3605 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3607 if (!(taudio->in.codec & audio.out.codec))
3609 // Not supported. AC3 is passthrough only, so input must be AC3
3610 if (job->mux == HB_MUX_AVI)
3612 audio.out.codec = HB_ACODEC_LAME;
3616 audio.out.codec = HB_ACODEC_FAAC;
3621 audio.out.codec &= taudio->in.codec;
3624 if ((job->mux == HB_MUX_MP4) &&
3625 ((audio.out.codec == HB_ACODEC_LAME) ||
3626 (audio.out.codec == HB_ACODEC_VORBIS)))
3628 // mp4/mp3|vorbis combination is not supported.
3629 audio.out.codec = HB_ACODEC_FAAC;
3631 if ((job->mux == HB_MUX_AVI) &&
3632 ((audio.out.codec == HB_ACODEC_FAAC) ||
3633 (audio.out.codec == HB_ACODEC_VORBIS)))
3635 // avi/faac|vorbis combination is not supported.
3636 audio.out.codec = HB_ACODEC_LAME;
3638 if ((job->mux == HB_MUX_OGM) &&
3639 ((audio.out.codec == HB_ACODEC_FAAC) ||
3640 (audio.out.codec == HB_ACODEC_AC3) ||
3641 (audio.out.codec == HB_ACODEC_DCA)))
3643 // ogm/faac|ac3 combination is not supported.
3644 audio.out.codec = HB_ACODEC_VORBIS;
3646 audio.out.dynamic_range_compression =
3647 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3648 // It would be better if this were done in libhb for us, but its not yet.
3649 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3651 audio.out.mixdown = 0;
3655 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3656 // Make sure the mixdown is valid and pick a new one if not.
3657 audio.out.mixdown = ghb_get_best_mix(titleindex,
3658 audio.in.track, audio.out.codec, audio.out.mixdown);
3660 ghb_settings_combo_int(asettings, "AudioBitrate");
3661 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3662 if (srate == 0) // 0 is same as source
3663 audio.out.samplerate = taudio->in.samplerate;
3665 audio.out.samplerate = srate;
3668 // Add it to the jobs audio list
3669 hb_audio_add( job, &audio );
3672 // I was tempted to move this up with the reset of the video quality
3673 // settings, but I suspect the settings above need to be made
3674 // first in order for hb_calc_bitrate to be accurate.
3675 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3679 size = ghb_settings_get_int(js, "VideoTargetSize");
3680 job->vbitrate = hb_calc_bitrate( job, size );
3681 job->vquality = -1.0;
3684 dest_str = ghb_settings_get_string(js, "destination");
3685 job->file = dest_str;
3686 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3687 // TODO: libhb holds onto a reference to the x264opts and is not
3688 // finished with it until encoding the job is done. But I can't
3689 // find a way to get at the job before it is removed in order to
3690 // free up the memory I am allocating here.
3691 // The short story is THIS LEAKS.
3692 x264opts = ghb_build_x264opts_string(js);
3694 if( x264opts != NULL && *x264opts != '\0' )
3696 job->x264opts = x264opts;
3698 else /*avoids a bus error crash when options aren't specified*/
3700 job->x264opts = NULL;
3703 subtitle = ghb_settings_get_int(js, "subtitle_index");
3706 job->indepth_scan = 1;
3708 else if (subtitle >= 0)
3710 hb_subtitle_t * subt;
3712 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
3715 hb_list_add(job->list_subtitle, subt);
3718 gboolean forced_subtitles = ghb_settings_get_boolean(js, "SubtitlesForced");
3719 job->subtitle_force = forced_subtitles;
3721 if (job->indepth_scan == 1)
3723 // Subtitle scan. Look for subtitle matching audio language
3727 * When subtitle scan is enabled do a fast pre-scan job
3728 * which will determine which subtitles to enable, if any.
3731 job->indepth_scan = 1;
3733 x264opts_tmp = job->x264opts;
3734 job->x264opts = NULL;
3736 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3737 *(job->select_subtitle) = NULL;
3740 * Add the pre-scan job
3742 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3744 //if (job->x264opts != NULL)
3745 // g_free(job->x264opts);
3747 job->x264opts = x264opts_tmp;
3751 job->select_subtitle = NULL;
3753 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
3754 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3757 * If subtitle_scan is enabled then only turn it on
3758 * for the second pass and then off again for the
3761 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3762 job->select_subtitle = NULL;
3764 job->indepth_scan = 0;
3765 gchar *x264opts2 = NULL;
3768 x264opts2 = g_strdup(x264opts);
3771 * If turbo options have been selected then append them
3772 * to the x264opts now (size includes one ':' and the '\0')
3774 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
3780 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3786 * No x264opts to modify, but apply the turbo options
3787 * anyway as they may be modifying defaults
3789 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3791 x264opts = tmp_x264opts;
3793 job->x264opts = x264opts;
3795 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3797 //if (job->x264opts != NULL)
3798 // g_free(job->x264opts);
3800 job->select_subtitle = subtitle_tmp;
3803 * On the second pass we turn off subtitle scan so that we
3804 * can actually encode using any subtitles that were auto
3805 * selected in the first pass (using the whacky select-subtitle
3806 * attribute of the job).
3808 job->indepth_scan = 0;
3809 job->x264opts = x264opts2;
3810 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3812 //if (job->x264opts != NULL)
3813 // g_free(job->x264opts);
3817 job->indepth_scan = 0;
3819 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3821 //if (job->x264opts != NULL)
3822 // g_free(job->x264opts);
3824 if (detel_str) g_free(detel_str);
3825 if (decomb_str) g_free(decomb_str);
3826 if (deint_str) g_free(deint_str);
3827 if (deblock_str) g_free(deblock_str);
3828 if (denoise_str) g_free(denoise_str);
3829 if (dest_str) g_free(dest_str);
3833 ghb_add_job(GValue *js, gint unique_id)
3835 // Since I'm doing a scan of the single title I want just prior
3836 // to adding the job, there is only the one title to choose from.
3837 add_job(h_queue, js, unique_id, 0);
3841 ghb_add_live_job(GValue *js, gint unique_id)
3843 // Since I'm doing a scan of the single title I want just prior
3844 // to adding the job, there is only the one title to choose from.
3845 gint titleindex = ghb_settings_combo_int(js, "title");
3846 add_job(h_scan, js, unique_id, titleindex);
3850 ghb_remove_job(gint unique_id)
3855 // Multiples passes all get the same id
3857 // Go backwards through list, so reordering doesn't screw me.
3858 ii = hb_count(h_queue) - 1;
3859 while ((job = hb_job(h_queue, ii--)) != NULL)
3861 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3862 hb_rem(h_queue, job);
3869 hb_start( h_queue );
3879 ghb_start_live_encode()
3885 ghb_stop_live_encode()
3894 hb_get_state2( h_queue, &s );
3896 if( s.state == HB_STATE_PAUSED )
3898 hb_resume( h_queue );
3902 hb_pause( h_queue );
3917 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
3920 gint channels = gdk_pixbuf_get_n_channels (pb);
3921 gint stride = gdk_pixbuf_get_rowstride (pb);
3923 for (jj = 0; jj < width; jj++)
3925 dst = pixels + y * stride + (x+jj) * channels;
3926 for (ii = 0; ii < len; ii++)
3947 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
3950 gint channels = gdk_pixbuf_get_n_channels (pb);
3951 gint stride = gdk_pixbuf_get_rowstride (pb);
3953 for (jj = 0; jj < width; jj++)
3955 dst = pixels + (y+jj) * stride + x * channels;
3956 for (ii = 0; ii < len; ii++)
3977 gint line_width = 8;
3984 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
3989 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
3991 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
3997 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
3999 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4005 ghb_get_preview_image(
4008 signal_user_data_t *ud,
4016 settings = ud->settings;
4017 list = hb_get_titles( h_scan );
4018 if( !hb_list_count( list ) )
4020 /* No valid title, stop right there */
4023 title = hb_list_item( list, titleindex );
4024 if (title == NULL) return NULL;
4025 if (title->job == NULL) return NULL;
4026 set_preview_job_settings(title->job, settings);
4028 // hb_get_preview doesn't compensate for anamorphic, so lets
4029 // calculate scale factors
4030 gint width, height, par_width = 1, par_height = 1;
4031 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4034 hb_set_anamorphic_size( title->job, &width, &height,
4035 &par_width, &par_height );
4038 // Make sure we have a big enough buffer to receive the image from libhb
4039 gint dstWidth = title->job->width;
4040 gint dstHeight= title->job->height;
4042 static guint8 *buffer = NULL;
4043 static gint bufferSize = 0;
4046 newSize = dstWidth * dstHeight * 4;
4047 if( bufferSize < newSize )
4049 bufferSize = newSize;
4050 buffer = (guint8*) g_realloc( buffer, bufferSize );
4052 hb_get_preview( h_scan, title, index, buffer );
4054 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4055 // libhb's format something suitable.
4057 // The image data returned by hb_get_preview is 4 bytes per pixel,
4058 // BGRA format. Alpha is ignored.
4060 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4061 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4063 guint32 *src = (guint32*)buffer;
4064 guint8 *dst = pixels;
4067 gint channels = gdk_pixbuf_get_n_channels (preview);
4068 gint stride = gdk_pixbuf_get_rowstride (preview);
4071 for (ii = 0; ii < dstHeight; ii++)
4074 for (jj = 0; jj < dstWidth; jj++)
4076 tmp[0] = src[0] >> 16;
4077 tmp[1] = src[0] >> 8;
4078 tmp[2] = src[0] >> 0;
4084 gint w = ghb_settings_get_int(settings, "scale_width");
4085 gint h = ghb_settings_get_int(settings, "scale_height");
4086 ghb_par_scale(ud, &w, &h, par_width, par_height);
4088 gint c0, c1, c2, c3;
4089 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4090 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4091 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4092 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4094 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4095 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4097 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4100 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4104 gint orig_w, orig_h;
4107 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4111 ss = gdk_screen_get_default();
4112 s_w = gdk_screen_get_width(ss);
4113 s_h = gdk_screen_get_height(ss);
4117 if (dstWidth > s_w * factor / 100)
4119 dstWidth = s_w * factor / 100;
4120 dstHeight = dstHeight * dstWidth / orig_w;
4122 if (dstHeight > s_h * factor / 100)
4124 dstHeight = s_h * factor / 100;
4125 dstWidth = dstWidth * dstHeight / orig_h;
4127 xscale *= (gdouble)dstWidth / orig_w;
4128 yscale *= (gdouble)dstHeight / orig_h;
4129 w *= (gdouble)dstWidth / orig_w;
4130 h *= (gdouble)dstHeight / orig_h;
4132 g_debug("scaled %d x %d", dstWidth, dstHeight);
4133 GdkPixbuf *scaled_preview;
4134 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4135 if (ghb_settings_get_boolean(settings, "show_crop"))
4142 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4144 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4146 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4148 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4150 g_object_unref (preview);
4151 return scaled_preview;
4155 sanitize_volname(gchar *name)
4180 ghb_dvd_volname(const gchar *device)
4183 name = hb_dvd_name((gchar*)device);
4184 if (name != NULL && name[0] != 0)
4186 name = g_strdup(name);
4187 sanitize_volname(name);