1 /***************************************************************************
4 * Fri Mar 28 10:38:44 2008
5 * Copyright 2008 John Stebbins
6 * <john at stebbins dot name>
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
28 #include "hbversion.h"
30 #include <glib/gstdio.h>
31 #include "hb-backend.h"
33 #include "callbacks.h"
41 const gchar *shortOpt;
52 static const gchar *index_str[] =
67 static options_map_t d_logging_opts[] =
73 combo_opts_t logging_opts =
75 sizeof(d_logging_opts)/sizeof(options_map_t),
79 static options_map_t d_container_opts[] =
81 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
82 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
83 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
84 {"AVI", "avi", HB_MUX_AVI, "avi"},
85 {"OGM", "ogm", HB_MUX_OGM, "ogm"},
87 combo_opts_t container_opts =
89 sizeof(d_container_opts)/sizeof(options_map_t),
93 static options_map_t d_deint_opts[] =
95 {"None", "none", 0, ""},
96 {"Fast", "fast", 1, "-1:-1:-1:0:1"},
97 {"Slow", "slow", 2, "2:-1:-1:0:1"},
98 {"Slower", "slower", 3, "0:-1:-1:0:1"},
100 combo_opts_t deint_opts =
102 sizeof(d_deint_opts)/sizeof(options_map_t),
106 static options_map_t d_denoise_opts[] =
108 {"None", "none", 0, ""},
109 {"Weak", "weak", 1, "2:1:2:3"},
110 {"Medium", "medium", 2, "3:2:2:3"},
111 {"Strong", "strong", 3, "7:7:5:5"},
113 combo_opts_t denoise_opts =
115 sizeof(d_denoise_opts)/sizeof(options_map_t),
119 static options_map_t d_vcodec_opts[] =
121 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
122 {"MPEG-4 (XviD)", "xvid", HB_VCODEC_XVID, ""},
123 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
124 {"Theora", "theora", HB_VCODEC_THEORA, ""},
126 combo_opts_t vcodec_opts =
128 sizeof(d_vcodec_opts)/sizeof(options_map_t),
132 static options_map_t d_acodec_opts[] =
134 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
135 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
136 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
137 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
138 // {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
140 combo_opts_t acodec_opts =
142 sizeof(d_acodec_opts)/sizeof(options_map_t),
146 static options_map_t d_direct_opts[] =
148 {"None", "none", 0, "none"},
149 {"Spatial", "spatial", 1, "spatial"},
150 {"Temporal", "temporal", 2, "temporal"},
151 {"Automatic", "auto", 3, "auto"},
153 combo_opts_t direct_opts =
155 sizeof(d_direct_opts)/sizeof(options_map_t),
159 static options_map_t d_me_opts[] =
161 {"Diamond", "dia", 0, "dia"},
162 {"Hexagon", "hex", 1, "hex"},
163 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
164 {"Exhaustive", "esa", 3, "esa"},
165 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
167 combo_opts_t me_opts =
169 sizeof(d_me_opts)/sizeof(options_map_t),
173 static options_map_t d_subme_opts[] =
185 combo_opts_t subme_opts =
187 sizeof(d_subme_opts)/sizeof(options_map_t),
191 static options_map_t d_analyse_opts[] =
193 {"Some", "some", 0, "some"},
194 {"None", "none", 1, "none"},
195 {"All", "all", 2, "all"},
196 {"Custom", "custom", 3, "all"},
198 combo_opts_t analyse_opts =
200 sizeof(d_analyse_opts)/sizeof(options_map_t),
204 static options_map_t d_trellis_opts[] =
206 {"Disabled", "0", 0, "0"},
207 {"Final Macro Block", "1", 1, "1"},
208 {"Always", "2", 2, "2"},
210 combo_opts_t trellis_opts =
212 sizeof(d_trellis_opts)/sizeof(options_map_t),
216 combo_opts_t subtitle_opts =
222 combo_opts_t title_opts =
228 combo_opts_t audio_track_opts =
240 combo_name_map_t combo_name_map[] =
242 {"LoggingLevel", &logging_opts},
243 {"FileFormat", &container_opts},
244 {"PictureDeinterlace", &deint_opts},
245 {"tweak_PictureDeinterlace", &deint_opts},
246 {"PictureDenoise", &denoise_opts},
247 {"tweak_PictureDenoise", &denoise_opts},
248 {"VideoEncoder", &vcodec_opts},
249 {"AudioEncoder", &acodec_opts},
250 {"x264_direct", &direct_opts},
251 {"x264_me", &me_opts},
252 {"x264_subme", &subme_opts},
253 {"x264_analyse", &analyse_opts},
254 {"x264_trellis", &trellis_opts},
255 {"Subtitles", &subtitle_opts},
256 {"title", &title_opts},
257 {"AudioTrack", &audio_track_opts},
262 typedef struct iso639_lang_t
264 char * eng_name; /* Description in English */
265 char * native_name; /* Description in native language */
266 char * iso639_1; /* ISO-639-1 (2 characters) code */
267 char * iso639_2; /* ISO-639-2/t (3 character) code */
268 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
272 const iso639_lang_t ghb_language_table[] =
274 { "Any", "", "zz", "und" },
275 { "Afar", "", "aa", "aar" },
276 { "Abkhazian", "", "ab", "abk" },
277 { "Afrikaans", "", "af", "afr" },
278 { "Akan", "", "ak", "aka" },
279 { "Albanian", "", "sq", "sqi", "alb" },
280 { "Amharic", "", "am", "amh" },
281 { "Arabic", "", "ar", "ara" },
282 { "Aragonese", "", "an", "arg" },
283 { "Armenian", "", "hy", "hye", "arm" },
284 { "Assamese", "", "as", "asm" },
285 { "Avaric", "", "av", "ava" },
286 { "Avestan", "", "ae", "ave" },
287 { "Aymara", "", "ay", "aym" },
288 { "Azerbaijani", "", "az", "aze" },
289 { "Bashkir", "", "ba", "bak" },
290 { "Bambara", "", "bm", "bam" },
291 { "Basque", "", "eu", "eus", "baq" },
292 { "Belarusian", "", "be", "bel" },
293 { "Bengali", "", "bn", "ben" },
294 { "Bihari", "", "bh", "bih" },
295 { "Bislama", "", "bi", "bis" },
296 { "Bosnian", "", "bs", "bos" },
297 { "Breton", "", "br", "bre" },
298 { "Bulgarian", "", "bg", "bul" },
299 { "Burmese", "", "my", "mya", "bur" },
300 { "Catalan", "", "ca", "cat" },
301 { "Chamorro", "", "ch", "cha" },
302 { "Chechen", "", "ce", "che" },
303 { "Chinese", "", "zh", "zho", "chi" },
304 { "Church Slavic", "", "cu", "chu" },
305 { "Chuvash", "", "cv", "chv" },
306 { "Cornish", "", "kw", "cor" },
307 { "Corsican", "", "co", "cos" },
308 { "Cree", "", "cr", "cre" },
309 { "Czech", "", "cs", "ces", "cze" },
310 { "Danish", "Dansk", "da", "dan" },
311 { "Divehi", "", "dv", "div" },
312 { "Dutch", "Nederlands", "nl", "nld", "dut" },
313 { "Dzongkha", "", "dz", "dzo" },
314 { "English", "English", "en", "eng" },
315 { "Esperanto", "", "eo", "epo" },
316 { "Estonian", "", "et", "est" },
317 { "Ewe", "", "ee", "ewe" },
318 { "Faroese", "", "fo", "fao" },
319 { "Fijian", "", "fj", "fij" },
320 { "Finnish", "Suomi", "fi", "fin" },
321 { "French", "Francais", "fr", "fra", "fre" },
322 { "Western Frisian", "", "fy", "fry" },
323 { "Fulah", "", "ff", "ful" },
324 { "Georgian", "", "ka", "kat", "geo" },
325 { "German", "Deutsch", "de", "deu", "ger" },
326 { "Gaelic (Scots)", "", "gd", "gla" },
327 { "Irish", "", "ga", "gle" },
328 { "Galician", "", "gl", "glg" },
329 { "Manx", "", "gv", "glv" },
330 { "Greek, Modern", "", "el", "ell", "gre" },
331 { "Guarani", "", "gn", "grn" },
332 { "Gujarati", "", "gu", "guj" },
333 { "Haitian", "", "ht", "hat" },
334 { "Hausa", "", "ha", "hau" },
335 { "Hebrew", "", "he", "heb" },
336 { "Herero", "", "hz", "her" },
337 { "Hindi", "", "hi", "hin" },
338 { "Hiri Motu", "", "ho", "hmo" },
339 { "Hungarian", "Magyar", "hu", "hun" },
340 { "Igbo", "", "ig", "ibo" },
341 { "Icelandic", "Islenska", "is", "isl", "ice" },
342 { "Ido", "", "io", "ido" },
343 { "Sichuan Yi", "", "ii", "iii" },
344 { "Inuktitut", "", "iu", "iku" },
345 { "Interlingue", "", "ie", "ile" },
346 { "Interlingua", "", "ia", "ina" },
347 { "Indonesian", "", "id", "ind" },
348 { "Inupiaq", "", "ik", "ipk" },
349 { "Italian", "Italiano", "it", "ita" },
350 { "Javanese", "", "jv", "jav" },
351 { "Japanese", "", "ja", "jpn" },
352 { "Kalaallisut", "", "kl", "kal" },
353 { "Kannada", "", "kn", "kan" },
354 { "Kashmiri", "", "ks", "kas" },
355 { "Kanuri", "", "kr", "kau" },
356 { "Kazakh", "", "kk", "kaz" },
357 { "Central Khmer", "", "km", "khm" },
358 { "Kikuyu", "", "ki", "kik" },
359 { "Kinyarwanda", "", "rw", "kin" },
360 { "Kirghiz", "", "ky", "kir" },
361 { "Komi", "", "kv", "kom" },
362 { "Kongo", "", "kg", "kon" },
363 { "Korean", "", "ko", "kor" },
364 { "Kuanyama", "", "kj", "kua" },
365 { "Kurdish", "", "ku", "kur" },
366 { "Lao", "", "lo", "lao" },
367 { "Latin", "", "la", "lat" },
368 { "Latvian", "", "lv", "lav" },
369 { "Limburgan", "", "li", "lim" },
370 { "Lingala", "", "ln", "lin" },
371 { "Lithuanian", "", "lt", "lit" },
372 { "Luxembourgish", "", "lb", "ltz" },
373 { "Luba-Katanga", "", "lu", "lub" },
374 { "Ganda", "", "lg", "lug" },
375 { "Macedonian", "", "mk", "mkd", "mac" },
376 { "Marshallese", "", "mh", "mah" },
377 { "Malayalam", "", "ml", "mal" },
378 { "Maori", "", "mi", "mri", "mao" },
379 { "Marathi", "", "mr", "mar" },
380 { "Malay", "", "ms", "msa", "msa" },
381 { "Malagasy", "", "mg", "mlg" },
382 { "Maltese", "", "mt", "mlt" },
383 { "Moldavian", "", "mo", "mol" },
384 { "Mongolian", "", "mn", "mon" },
385 { "Nauru", "", "na", "nau" },
386 { "Navajo", "", "nv", "nav" },
387 { "Ndebele, South", "", "nr", "nbl" },
388 { "Ndebele, North", "", "nd", "nde" },
389 { "Ndonga", "", "ng", "ndo" },
390 { "Nepali", "", "ne", "nep" },
391 { "Norwegian Nynorsk", "", "nn", "nno" },
392 { "Norwegian Bokmål", "", "nb", "nob" },
393 { "Norwegian", "Norsk", "no", "nor" },
394 { "Chichewa; Nyanja", "", "ny", "nya" },
395 { "Occitan", "", "oc", "oci" },
396 { "Ojibwa", "", "oj", "oji" },
397 { "Oriya", "", "or", "ori" },
398 { "Oromo", "", "om", "orm" },
399 { "Ossetian", "", "os", "oss" },
400 { "Panjabi", "", "pa", "pan" },
401 { "Persian", "", "fa", "fas", "per" },
402 { "Pali", "", "pi", "pli" },
403 { "Polish", "", "pl", "pol" },
404 { "Portuguese", "Portugues", "pt", "por" },
405 { "Pushto", "", "ps", "pus" },
406 { "Quechua", "", "qu", "que" },
407 { "Romansh", "", "rm", "roh" },
408 { "Romanian", "", "ro", "ron", "rum" },
409 { "Rundi", "", "rn", "run" },
410 { "Russian", "", "ru", "rus" },
411 { "Sango", "", "sg", "sag" },
412 { "Sanskrit", "", "sa", "san" },
413 { "Serbian", "", "sr", "srp", "scc" },
414 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
415 { "Sinhala", "", "si", "sin" },
416 { "Slovak", "", "sk", "slk", "slo" },
417 { "Slovenian", "", "sl", "slv" },
418 { "Northern Sami", "", "se", "sme" },
419 { "Samoan", "", "sm", "smo" },
420 { "Shona", "", "sn", "sna" },
421 { "Sindhi", "", "sd", "snd" },
422 { "Somali", "", "so", "som" },
423 { "Sotho, Southern", "", "st", "sot" },
424 { "Spanish", "Espanol", "es", "spa" },
425 { "Sardinian", "", "sc", "srd" },
426 { "Swati", "", "ss", "ssw" },
427 { "Sundanese", "", "su", "sun" },
428 { "Swahili", "", "sw", "swa" },
429 { "Swedish", "Svenska", "sv", "swe" },
430 { "Tahitian", "", "ty", "tah" },
431 { "Tamil", "", "ta", "tam" },
432 { "Tatar", "", "tt", "tat" },
433 { "Telugu", "", "te", "tel" },
434 { "Tajik", "", "tg", "tgk" },
435 { "Tagalog", "", "tl", "tgl" },
436 { "Thai", "", "th", "tha" },
437 { "Tibetan", "", "bo", "bod", "tib" },
438 { "Tigrinya", "", "ti", "tir" },
439 { "Tonga", "", "to", "ton" },
440 { "Tswana", "", "tn", "tsn" },
441 { "Tsonga", "", "ts", "tso" },
442 { "Turkmen", "", "tk", "tuk" },
443 { "Turkish", "", "tr", "tur" },
444 { "Twi", "", "tw", "twi" },
445 { "Uighur", "", "ug", "uig" },
446 { "Ukrainian", "", "uk", "ukr" },
447 { "Urdu", "", "ur", "urd" },
448 { "Uzbek", "", "uz", "uzb" },
449 { "Venda", "", "ve", "ven" },
450 { "Vietnamese", "", "vi", "vie" },
451 { "Volapük", "", "vo", "vol" },
452 { "Welsh", "", "cy", "cym", "wel" },
453 { "Walloon", "", "wa", "wln" },
454 { "Wolof", "", "wo", "wol" },
455 { "Xhosa", "", "xh", "xho" },
456 { "Yiddish", "", "yi", "yid" },
457 { "Yoruba", "", "yo", "yor" },
458 { "Zhuang", "", "za", "zha" },
459 { "Zulu", "", "zu", "zul" },
460 {NULL, NULL, NULL, NULL}
462 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
464 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
467 del_tree(const gchar *name, gboolean del_top)
471 if (g_file_test(name, G_FILE_TEST_IS_DIR))
473 GDir *gdir = g_dir_open(name, 0, NULL);
474 file = g_dir_read_name(gdir);
478 path = g_strdup_printf("%s/%s", name, file);
479 del_tree(path, TRUE);
481 file = g_dir_read_name(gdir);
501 signal_user_data_t *ud,
508 if (ghb_settings_get_boolean(ud->settings, "directqp"))
510 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
511 // Only x264 and ffmpeg currently support direct qp/crf entry
515 if (vcodec == HB_VCODEC_X264)
520 else if (vcodec == HB_VCODEC_FFMPEG)
545 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
551 str = ghb_value_string(gval);
552 for (ii = 0; ii < opts->count; ii++)
554 if (strcmp(opts->map[ii].shortOpt, str) == 0)
556 result = opts->map[ii].ivalue;
565 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
569 const gchar *result = "";
571 str = ghb_value_string(gval);
572 for (ii = 0; ii < opts->count; ii++)
574 if (strcmp(opts->map[ii].shortOpt, str) == 0)
576 result = opts->map[ii].option;
585 lookup_mix_int(const GValue *mix)
592 str = ghb_value_string(mix);
593 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
595 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
597 result = hb_audio_mixdowns[ii].amixdown;
606 lookup_mix_option(const GValue *mix)
610 gchar *result = "None";
613 str = ghb_value_string(mix);
614 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
616 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
618 result = hb_audio_mixdowns[ii].human_readable_name;
627 lookup_video_rate_int(const GValue *vrate)
633 str = ghb_value_string(vrate);
634 for (ii = 0; ii < hb_video_rates_count; ii++)
636 if (strcmp(hb_video_rates[ii].string, str) == 0)
638 result = hb_video_rates[ii].rate;
643 // Default to "same as source"
648 lookup_video_rate_option(const GValue *vrate)
652 const gchar *result = "Same as source";
654 str = ghb_value_string(vrate);
655 for (ii = 0; ii < hb_video_rates_count; ii++)
657 if (strcmp(hb_video_rates[ii].string, str) == 0)
659 result = hb_video_rates[ii].string;
664 // Default to "same as source"
669 lookup_audio_rate_int(const GValue *rate)
675 // Coincidentally, the string "source" will return 0
676 // which is our flag to use "same as source"
677 str = ghb_value_string(rate);
678 for (ii = 0; ii < hb_audio_rates_count; ii++)
680 if (strcmp(hb_audio_rates[ii].string, str) == 0)
682 result = hb_audio_rates[ii].rate;
691 lookup_audio_rate_option(const GValue *rate)
695 const gchar *result = "Same as source";
697 // Coincidentally, the string "source" will return 0
698 // which is our flag to use "same as source"
699 str = ghb_value_string(rate);
700 for (ii = 0; ii < hb_audio_rates_count; ii++)
702 if (strcmp(hb_audio_rates[ii].string, str) == 0)
704 result = hb_audio_rates[ii].string;
713 lookup_audio_bitrate_int(const GValue *rate)
719 // Coincidentally, the string "source" will return 0
720 // which is our flag to use "same as source"
721 str = ghb_value_string(rate);
722 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
724 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
726 result = hb_audio_bitrates[ii].rate;
735 lookup_audio_bitrate_option(const GValue *rate)
739 const gchar *result = "Same as source";
741 // Coincidentally, the string "source" will return 0
742 // which is our flag to use "same as source"
743 str = ghb_value_string(rate);
744 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
746 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
748 result = hb_audio_bitrates[ii].string;
757 lookup_audio_lang_int(const GValue *rate)
763 // Coincidentally, the string "source" will return 0
764 // which is our flag to use "same as source"
765 str = ghb_value_string(rate);
766 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
768 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
779 lookup_audio_lang_option(const GValue *rate)
783 const gchar *result = "Same as source";
785 // Coincidentally, the string "source" will return 0
786 // which is our flag to use "same as source"
787 str = ghb_value_string(rate);
788 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
790 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
792 result = ghb_language_table[ii].eng_name;
801 get_acodec_value(gint val)
803 GValue *value = NULL;
806 for (ii = 0; ii < acodec_opts.count; ii++)
808 if (acodec_opts.map[ii].ivalue == val)
810 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
819 get_abitrate_value(gint val)
821 GValue *value = NULL;
824 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
826 if (hb_audio_bitrates[ii].rate == val)
828 value = ghb_string_value_new(hb_audio_bitrates[ii].string);
837 get_amix_value(gint val)
839 GValue *value = NULL;
842 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
844 if (hb_audio_mixdowns[ii].amixdown == val)
846 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
853 // Handle for libhb. Gets set by ghb_backend_init()
854 static hb_handle_t * h_scan = NULL;
855 static hb_handle_t * h_queue = NULL;
857 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
864 hb_get_tempory_directory(h_scan, dir);
865 return g_strdup(dir);
869 ghb_hb_cleanup(gboolean partial)
873 hb_get_tempory_directory(h_scan, dir);
874 del_tree(dir, !partial);
878 ghb_get_title_number(gint titleindex)
883 if (h_scan == NULL) return 1;
884 list = hb_get_titles( h_scan );
885 if( !hb_list_count( list ) )
887 /* No valid title, stop right there */
890 title = hb_list_item( list, titleindex );
891 if (title == NULL) return 1; // Bad titleindex
895 static hb_audio_config_t*
896 get_hb_audio(gint titleindex, gint track)
900 hb_audio_config_t *audio = NULL;
902 if (h_scan == NULL) return NULL;
903 list = hb_get_titles( h_scan );
904 if( !hb_list_count( list ) )
906 /* No valid title, stop right there */
909 title = hb_list_item( list, titleindex );
910 if (title == NULL) return NULL; // Bad titleindex
911 if (!hb_list_count(title->list_audio))
915 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
920 search_rates(hb_rate_t *rates, gint rate, gint count)
923 for (ii = 0; ii < count; ii++)
925 if (rates[ii].rate == rate)
931 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
934 get_combo_box_store(GtkBuilder *builder, const gchar *name)
939 g_debug("get_combo_box_store() %s\n", name);
940 // First modify the combobox model to allow greying out of options
941 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
942 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
947 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
952 store = get_combo_box_store(builder, name);
953 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
955 gtk_list_store_set(store, &iter,
962 ghb_grey_combo_options(GtkBuilder *builder)
965 gint container, track, titleindex, acodec;
966 hb_audio_config_t *audio = NULL;
969 widget = GHB_WIDGET (builder, "title");
970 gval = ghb_widget_value(widget);
971 titleindex = ghb_lookup_combo_int("title", gval);
972 ghb_value_free(gval);
973 widget = GHB_WIDGET (builder, "AudioTrack");
974 gval = ghb_widget_value(widget);
975 track = ghb_lookup_combo_int("AudioTrack", gval);
976 ghb_value_free(gval);
977 audio = get_hb_audio(titleindex, track);
978 widget = GHB_WIDGET (builder, "FileFormat");
979 gval = ghb_widget_value(widget);
980 container = ghb_lookup_combo_int("FileFormat", gval);
981 ghb_value_free(gval);
983 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
984 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
985 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
986 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
988 gboolean allow_ac3 = TRUE;
989 allow_ac3 = (container != HB_MUX_OGM);
993 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
994 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
998 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
999 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1001 if (audio && audio->in.codec != HB_ACODEC_AC3)
1003 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1005 if (audio && audio->in.codec != HB_ACODEC_DCA)
1007 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1009 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1011 widget = GHB_WIDGET (builder, "AudioEncoder");
1012 gval = ghb_widget_value(widget);
1013 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1014 ghb_value_free(gval);
1015 if (acodec != HB_ACODEC_AC3)
1017 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1019 if (container == HB_MUX_MP4)
1021 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1022 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1023 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1025 else if (container == HB_MUX_AVI)
1027 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1028 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1029 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1031 else if (container == HB_MUX_OGM)
1033 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1036 gboolean allow_mono = TRUE;
1037 gboolean allow_stereo = TRUE;
1038 gboolean allow_dolby = TRUE;
1039 gboolean allow_dpl2 = TRUE;
1040 gboolean allow_6ch = TRUE;
1044 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1045 (acodec != HB_ACODEC_LAME);
1046 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1048 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1050 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1051 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1052 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1053 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1055 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1056 (acodec != HB_ACODEC_LAME) &&
1057 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1058 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1060 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1061 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1062 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1063 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1064 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1068 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1070 hb_audio_config_t *audio = NULL;
1071 gboolean allow_mono = TRUE;
1072 gboolean allow_stereo = TRUE;
1073 gboolean allow_dolby = TRUE;
1074 gboolean allow_dpl2 = TRUE;
1075 gboolean allow_6ch = TRUE;
1077 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1079 // Audio codec pass-thru. No mixdown
1082 audio = get_hb_audio(titleindex, track);
1086 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1087 (acodec != HB_ACODEC_LAME);
1088 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1090 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1092 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1093 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1094 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1095 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1097 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1098 (acodec != HB_ACODEC_LAME) &&
1099 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1100 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1102 gboolean greater = FALSE;
1105 // If no mix is specified, select the best available.
1106 mix = HB_AMIXDOWN_6CH;
1108 if (mix == HB_AMIXDOWN_6CH)
1111 if (allow_6ch) return HB_AMIXDOWN_6CH;
1113 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1116 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1118 if (mix == HB_AMIXDOWN_DOLBY || greater)
1121 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1123 if (mix == HB_AMIXDOWN_STEREO || greater)
1126 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1128 if (mix == HB_AMIXDOWN_MONO || greater)
1131 if (allow_mono) return HB_AMIXDOWN_MONO;
1133 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1134 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1135 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1136 if (allow_6ch) return HB_AMIXDOWN_6CH;
1140 // Set up the model for the combo box
1142 init_combo_box(GtkBuilder *builder, const gchar *name)
1145 GtkListStore *store;
1146 GtkCellRenderer *cell;
1148 g_debug("init_combo_box() %s\n", name);
1149 // First modify the combobox model to allow greying out of options
1150 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1152 // 1 - String to display
1153 // 2 - bool indicating whether the entry is selectable (grey or not)
1154 // 3 - String that is used for presets
1155 // 4 - Int value determined by backend
1156 // 5 - String value determined by backend
1157 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1158 G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1159 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1161 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1163 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1164 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1165 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1166 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1167 "text", 0, "sensitive", 1, NULL);
1170 { // Combo box entry
1171 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1176 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1179 GtkListStore *store;
1182 g_debug("audio_samplerate_opts_set ()\n");
1183 store = get_combo_box_store(builder, name);
1184 gtk_list_store_clear(store);
1185 // Add an item for "Same As Source"
1186 gtk_list_store_append(store, &iter);
1187 gtk_list_store_set(store, &iter,
1188 0, "Same as source",
1194 for (ii = 0; ii < count; ii++)
1196 gtk_list_store_append(store, &iter);
1197 gtk_list_store_set(store, &iter,
1198 0, rates[ii].string,
1200 2, rates[ii].string,
1202 4, rates[ii].string,
1208 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1211 GtkListStore *store;
1214 g_debug("video_rate_opts_set ()\n");
1215 store = get_combo_box_store(builder, name);
1216 gtk_list_store_clear(store);
1217 // Add an item for "Same As Source"
1218 gtk_list_store_append(store, &iter);
1219 gtk_list_store_set(store, &iter,
1220 0, "Same as source",
1226 for (ii = 0; ii < count; ii++)
1230 if (strcmp(rates[ii].string, "23.976") == 0)
1232 desc = "(NTSC Film)";
1234 else if (strcmp(rates[ii].string, "25") == 0)
1236 desc = "(PAL Film/Video)";
1238 else if (strcmp(rates[ii].string, "29.97") == 0)
1240 desc = "(NTSC Video)";
1242 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1243 gtk_list_store_append(store, &iter);
1244 gtk_list_store_set(store, &iter,
1247 2, rates[ii].string,
1249 4, rates[ii].string,
1256 mix_opts_set(GtkBuilder *builder, const gchar *name)
1259 GtkListStore *store;
1262 g_debug("mix_opts_set ()\n");
1263 store = get_combo_box_store(builder, name);
1264 gtk_list_store_clear(store);
1265 gtk_list_store_append(store, &iter);
1266 gtk_list_store_set(store, &iter,
1273 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1275 gtk_list_store_append(store, &iter);
1276 gtk_list_store_set(store, &iter,
1277 0, hb_audio_mixdowns[ii].human_readable_name,
1279 2, hb_audio_mixdowns[ii].short_name,
1280 3, hb_audio_mixdowns[ii].amixdown,
1281 4, hb_audio_mixdowns[ii].internal_name,
1287 language_opts_set(GtkBuilder *builder, const gchar *name)
1290 GtkListStore *store;
1293 g_debug("language_opts_set ()\n");
1294 store = get_combo_box_store(builder, name);
1295 gtk_list_store_clear(store);
1296 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1298 gtk_list_store_append(store, &iter);
1299 gtk_list_store_set(store, &iter,
1300 0, ghb_language_table[ii].eng_name,
1302 2, ghb_language_table[ii].iso639_2,
1304 4, ghb_language_table[ii].iso639_1,
1309 static gchar **titles = NULL;
1312 title_opts_set(GtkBuilder *builder, const gchar *name)
1315 GtkListStore *store;
1316 hb_list_t * list = NULL;
1317 hb_title_t * title = NULL;
1321 g_debug("title_opts_set ()\n");
1322 store = get_combo_box_store(builder, name);
1323 gtk_list_store_clear(store);
1326 list = hb_get_titles( h_scan );
1327 count = hb_list_count( list );
1328 if (count > 100) count = 100;
1330 if (titles) g_strfreev(titles);
1331 if (title_opts.map) g_free(title_opts.map);
1334 title_opts.count = count;
1335 title_opts.map = g_malloc(count*sizeof(options_map_t));
1336 titles = g_malloc((count+1) * sizeof(gchar*));
1340 title_opts.count = 1;
1341 title_opts.map = g_malloc(sizeof(options_map_t));
1346 // No titles. Fill in a default.
1347 gtk_list_store_append(store, &iter);
1348 gtk_list_store_set(store, &iter,
1355 title_opts.map[0].option = "No Titles";
1356 title_opts.map[0].shortOpt = "none";
1357 title_opts.map[0].ivalue = -1;
1358 title_opts.map[0].svalue = "none";
1361 for (ii = 0; ii < count; ii++)
1363 title = (hb_title_t*)hb_list_item(list, ii);
1364 if (title->duration != 0)
1366 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1367 title->index, title->hours, title->minutes, title->seconds);
1371 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1373 gtk_list_store_append(store, &iter);
1374 gtk_list_store_set(store, &iter,
1381 title_opts.map[ii].option = titles[ii];
1382 title_opts.map[ii].shortOpt = titles[ii];
1383 title_opts.map[ii].ivalue = ii;
1384 title_opts.map[ii].svalue = titles[ii];
1390 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1393 gboolean foundit = FALSE;
1395 if (gtk_tree_model_get_iter_first (store, iter))
1399 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1400 if (value == ivalue)
1405 } while (gtk_tree_model_iter_next (store, iter));
1411 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1414 GtkListStore *store;
1415 hb_list_t * list = NULL;
1416 hb_title_t * title = NULL;
1417 hb_audio_config_t * audio;
1421 g_debug("audio_track_opts_set ()\n");
1422 store = get_combo_box_store(builder, name);
1423 gtk_list_store_clear(store);
1426 list = hb_get_titles( h_scan );
1427 title = (hb_title_t*)hb_list_item( list, titleindex );
1430 count = hb_list_count( title->list_audio );
1433 if (count > 10) count = 10;
1434 if (audio_track_opts.map) g_free(audio_track_opts.map);
1437 audio_track_opts.count = count;
1438 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1442 audio_track_opts.count = 1;
1443 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1447 // No audio. set some default
1448 gtk_list_store_append(store, &iter);
1449 gtk_list_store_set(store, &iter,
1456 audio_track_opts.map[0].option = "No Audio";
1457 audio_track_opts.map[0].shortOpt = "none";
1458 audio_track_opts.map[0].ivalue = -1;
1459 audio_track_opts.map[0].svalue = "none";
1462 for (ii = 0; ii < count; ii++)
1464 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1465 gtk_list_store_append(store, &iter);
1466 gtk_list_store_set(store, &iter,
1467 0, audio->lang.description,
1473 audio_track_opts.map[ii].option = audio->lang.description,
1474 audio_track_opts.map[ii].shortOpt = index_str[ii];
1475 audio_track_opts.map[ii].ivalue = ii;
1476 audio_track_opts.map[ii].svalue = index_str[ii];
1482 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1485 GtkListStore *store;
1486 hb_list_t * list = NULL;
1487 hb_title_t * title = NULL;
1488 hb_subtitle_t * subtitle;
1492 g_debug("subtitle_opts_set () %s\n", name);
1493 store = get_combo_box_store(builder, name);
1494 gtk_list_store_clear(store);
1497 list = hb_get_titles( h_scan );
1498 title = (hb_title_t*)hb_list_item( list, titleindex );
1501 count = hb_list_count( title->list_subtitle );
1504 if (count > 10) count = 10;
1505 if (subtitle_opts.map) g_free(subtitle_opts.map);
1508 subtitle_opts.count = count+2;
1509 subtitle_opts.map = g_malloc((count+2)*sizeof(options_map_t));
1513 subtitle_opts.count = LANG_TABLE_SIZE+2;
1514 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+2)*sizeof(options_map_t));
1516 // Add options for "none" and "autoselect"
1517 gtk_list_store_append(store, &iter);
1518 gtk_list_store_set(store, &iter,
1525 subtitle_opts.map[0].option = "None";
1526 subtitle_opts.map[0].shortOpt = "none";
1527 subtitle_opts.map[0].ivalue = -2;
1528 subtitle_opts.map[0].svalue = "none";
1529 gtk_list_store_append(store, &iter);
1530 gtk_list_store_set(store, &iter,
1537 subtitle_opts.map[0].option = "Same as audio";
1538 subtitle_opts.map[0].shortOpt = "auto";
1539 subtitle_opts.map[0].ivalue = -1;
1540 subtitle_opts.map[0].svalue = "auto";
1543 for (ii = 0; ii < count; ii++)
1545 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1546 gtk_list_store_append(store, &iter);
1547 gtk_list_store_set(store, &iter,
1550 2, subtitle->iso639_2,
1552 4, subtitle->iso639_2,
1554 subtitle_opts.map[ii+2].option = subtitle->lang;
1555 subtitle_opts.map[ii+2].shortOpt = subtitle->iso639_2;
1556 subtitle_opts.map[ii+2].ivalue = ii;
1557 subtitle_opts.map[ii+2].svalue = subtitle->iso639_2;
1562 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1564 gtk_list_store_append(store, &iter);
1565 gtk_list_store_set(store, &iter,
1566 0, ghb_language_table[ii].eng_name,
1568 2, ghb_language_table[ii].iso639_2,
1570 4, ghb_language_table[ii].iso639_2,
1572 subtitle_opts.map[ii+2].option = ghb_language_table[ii].eng_name;
1573 subtitle_opts.map[ii+2].shortOpt = ghb_language_table[ii].iso639_2;
1574 subtitle_opts.map[ii+2].ivalue = ii;
1575 subtitle_opts.map[ii+2].svalue = ghb_language_table[ii].iso639_2;
1587 guint64 longest = 0;
1588 gint titleindex = 0;
1590 g_debug("ghb_longest_title ()\n");
1591 if (h_scan == NULL) return 0;
1592 list = hb_get_titles( h_scan );
1593 count = hb_list_count( list );
1594 if (count > 100) count = 100;
1595 for (ii = 0; ii < count; ii++)
1597 title = (hb_title_t*)hb_list_item(list, ii);
1598 if (title->duration > longest)
1601 longest = title->duration;
1608 ghb_find_audio_track(
1612 GHashTable *track_indices)
1616 hb_audio_config_t * audio;
1623 g_debug("find_audio_track ()\n");
1624 if (h_scan == NULL) return -1;
1625 list = hb_get_titles( h_scan );
1626 title = (hb_title_t*)hb_list_item( list, titleindex );
1629 count = hb_list_count( title->list_audio );
1631 if (count > 10) count = 10;
1632 used = g_hash_table_lookup(track_indices, &acodec);
1635 used = g_malloc0(count * sizeof(gboolean));
1636 g_hash_table_insert(track_indices, &acodec, used);
1638 // Try to fine an item that matches the preferred language and
1639 // the passthru codec type
1640 if (acodec == HB_ACODEC_AC3 || acodec == HB_ACODEC_DCA)
1642 for (ii = 0; ii < count; ii++)
1649 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1650 title->list_audio, ii );
1651 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1652 audio->in.channel_layout);
1653 // Find a track that is not visually impaired or dirctor's
1654 // commentary, and has the highest channel count.
1655 if ((audio->in.codec == acodec) &&
1656 (audio->lang.type < 2) &&
1657 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1658 (strcmp(lang, "und") == 0)))
1660 if (channels > max_chan)
1663 max_chan = channels;
1673 // Try to fine an item that matches the preferred language
1674 for (ii = 0; ii < count; ii++)
1678 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1679 title->list_audio, ii );
1680 // Find a track that is not visually impaired or dirctor's commentary
1681 if ((audio->lang.type < 2) &&
1682 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1683 (strcmp(lang, "und") == 0)))
1694 // Try to fine an item that does not match the preferred language and
1695 // matches the passthru codec type
1696 if (acodec == HB_ACODEC_AC3 || acodec == HB_ACODEC_DCA)
1698 for (ii = 0; ii < count; ii++)
1705 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1706 title->list_audio, ii );
1707 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1708 audio->in.channel_layout);
1709 // Find a track that is not visually impaired or dirctor's
1710 // commentary, and has the highest channel count.
1711 if ((audio->in.codec == acodec) &&
1712 (audio->lang.type < 2))
1714 if (channels > max_chan)
1717 max_chan = channels;
1727 // Try to fine an item that does not match the preferred language
1728 for (ii = 0; ii < count; ii++)
1732 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1733 title->list_audio, ii );
1734 // Find a track that is not visually impaired or dirctor's commentary
1735 if (audio->lang.type < 2)
1746 // Last ditch, anything goes
1747 for (ii = 0; ii < count; ii++)
1749 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1750 title->list_audio, ii );
1765 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1768 GtkListStore *store;
1771 g_debug("generic_opts_set ()\n");
1772 if (name == NULL || opts == NULL) return;
1773 store = get_combo_box_store(builder, name);
1774 gtk_list_store_clear(store);
1775 for (ii = 0; ii < opts->count; ii++)
1777 gtk_list_store_append(store, &iter);
1778 gtk_list_store_set(store, &iter,
1779 0, opts->map[ii].option,
1781 2, opts->map[ii].shortOpt,
1782 3, opts->map[ii].ivalue,
1783 4, opts->map[ii].svalue,
1789 find_combo_table(const gchar *name)
1793 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1795 if (strcmp(name, combo_name_map[ii].name) == 0)
1797 return combo_name_map[ii].opts;
1804 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
1806 if (strcmp(name, "AudioBitrate") == 0)
1807 return lookup_audio_bitrate_int(gval);
1808 else if (strcmp(name, "AudioSamplerate") == 0)
1809 return lookup_audio_rate_int(gval);
1810 else if (strcmp(name, "VideoFramerate") == 0)
1811 return lookup_video_rate_int(gval);
1812 else if (strcmp(name, "AudioMixdown") == 0)
1813 return lookup_mix_int(gval);
1814 else if (strcmp(name, "SourceAudioLang") == 0)
1815 return lookup_audio_lang_int(gval);
1818 return lookup_generic_int(find_combo_table(name), gval);
1820 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1825 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
1827 if (strcmp(name, "AudioBitrate") == 0)
1828 return lookup_audio_bitrate_option(gval);
1829 else if (strcmp(name, "AudioSamplerate") == 0)
1830 return lookup_audio_rate_option(gval);
1831 else if (strcmp(name, "VideoFramerate") == 0)
1832 return lookup_video_rate_option(gval);
1833 else if (strcmp(name, "AudioMixdown") == 0)
1834 return lookup_mix_option(gval);
1835 else if (strcmp(name, "SourceAudioLang") == 0)
1836 return lookup_audio_lang_option(gval);
1839 return lookup_generic_option(find_combo_table(name), gval);
1841 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1846 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1848 GtkComboBox *combo = NULL;
1850 gint handler_id = 0;
1852 g_debug("ghb_update_ui_combo_box() %s\n", name);
1855 // Clearing a combo box causes a rash of "changed" events, even when
1856 // the active item is -1 (inactive). To control things, I'm disabling
1857 // the event till things are settled down.
1858 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1859 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1862 // Valid signal id found. This should always succeed.
1863 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1864 signal_id, 0, 0, 0, 0);
1867 // This should also always succeed
1868 g_signal_handler_block ((gpointer)combo, handler_id);
1874 audio_bitrate_opts_set(builder, "AudioBitrate");
1875 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1876 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1877 mix_opts_set(builder, "AudioMixdown");
1878 language_opts_set(builder, "SourceAudioLang");
1879 subtitle_opts_set(builder, "Subtitles", user_data);
1880 title_opts_set(builder, "title");
1881 audio_track_opts_set(builder, "AudioTrack", user_data);
1882 generic_opts_set(builder, "LoggingLevel", &logging_opts);
1883 generic_opts_set(builder, "FileFormat", &container_opts);
1884 generic_opts_set(builder, "PictureDeinterlace", &deint_opts);
1885 generic_opts_set(builder, "tweak_PictureDeinterlace", &deint_opts);
1886 generic_opts_set(builder, "PictureDenoise", &denoise_opts);
1887 generic_opts_set(builder, "tweak_PictureDenoise", &denoise_opts);
1888 generic_opts_set(builder, "VideoEncoder", &vcodec_opts);
1889 generic_opts_set(builder, "AudioEncoder", &acodec_opts);
1890 generic_opts_set(builder, "x264_direct", &direct_opts);
1891 generic_opts_set(builder, "x264_me", &me_opts);
1892 generic_opts_set(builder, "x264_subme", &subme_opts);
1893 generic_opts_set(builder, "x264_analyse", &analyse_opts);
1894 generic_opts_set(builder, "x264_trellis", &trellis_opts);
1898 if (strcmp(name, "AudioBitrate") == 0)
1899 audio_bitrate_opts_set(builder, "AudioBitrate");
1900 else if (strcmp(name, "AudioSamplerate") == 0)
1901 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1902 else if (strcmp(name, "VideoFramerate") == 0)
1903 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1904 else if (strcmp(name, "AudioMixdown") == 0)
1905 mix_opts_set(builder, "AudioMixdown");
1906 else if (strcmp(name, "SourceAudioLang") == 0)
1907 language_opts_set(builder, "SourceAudioLang");
1908 else if (strcmp(name, "Subtitles") == 0)
1909 subtitle_opts_set(builder, "Subtitles", user_data);
1910 else if (strcmp(name, "title") == 0)
1911 title_opts_set(builder, "title");
1912 else if (strcmp(name, "AudioTrack") == 0)
1913 audio_track_opts_set(builder, "AudioTrack", user_data);
1915 generic_opts_set(builder, name, find_combo_table(name));
1919 g_signal_handler_unblock ((gpointer)combo, handler_id);
1924 init_ui_combo_boxes(GtkBuilder *builder)
1928 init_combo_box(builder, "AudioBitrate");
1929 init_combo_box(builder, "AudioSamplerate");
1930 init_combo_box(builder, "VideoFramerate");
1931 init_combo_box(builder, "AudioMixdown");
1932 init_combo_box(builder, "SourceAudioLang");
1933 init_combo_box(builder, "Subtitles");
1934 init_combo_box(builder, "title");
1935 init_combo_box(builder, "AudioTrack");
1936 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1938 init_combo_box(builder, combo_name_map[ii].name);
1942 static const char * turbo_opts =
1943 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
1944 "no-fast-pskip=0:8x8dct=0:weightb=0";
1946 // Construct the x264 options string
1947 // The result is allocated, so someone must free it at some point.
1949 ghb_build_x264opts_string(GValue *settings)
1952 gchar *opts = ghb_settings_get_string(settings, "x264Option");
1959 result = g_strdup("");
1965 ghb_get_chapters(gint titleindex)
1969 hb_chapter_t * chapter;
1971 GValue *chapters = NULL;
1973 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
1974 if (h_scan == NULL) return NULL;
1975 list = hb_get_titles( h_scan );
1976 title = (hb_title_t*)hb_list_item( list, titleindex );
1977 if (title == NULL) return NULL;
1978 count = hb_list_count( title->list_chapter );
1979 chapters = ghb_array_value_new(count);
1980 for (ii = 0; ii < count; ii++)
1982 chapter = hb_list_item(title->list_chapter, ii);
1983 if (chapter == NULL) break;
1984 if (chapter->title == NULL || chapter->title[0] == 0)
1987 str = g_strdup_printf ("Chapter %2d", ii+1);
1988 ghb_array_append(chapters, ghb_string_value_new(str));
1993 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2000 ghb_ac3_in_audio_list(const GValue *audio_list)
2004 count = ghb_array_len(audio_list);
2005 for (ii = 0; ii < count; ii++)
2010 asettings = ghb_array_get_nth(audio_list, ii);
2011 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2012 if (acodec == HB_ACODEC_AC3)
2019 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2022 GtkListStore *store;
2025 g_debug("audio_rate_opts_add ()\n");
2026 store = get_combo_box_store(builder, name);
2027 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2029 str = g_strdup_printf ("%d", rate);
2030 gtk_list_store_append(store, &iter);
2031 gtk_list_store_set(store, &iter,
2043 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2046 GtkListStore *store;
2048 gboolean done = FALSE;
2050 guint last = (guint)last_rate;
2052 g_debug("audio_bitrate_opts_clean ()\n");
2053 store = get_combo_box_store(builder, name);
2054 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2058 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2060 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2062 done = !gtk_list_store_remove(store, &iter);
2064 else if (ivalue > last)
2067 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2068 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2073 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2074 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2081 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2084 GtkListStore *store;
2087 g_debug("audio_bitrate_opts_set ()\n");
2088 store = get_combo_box_store(builder, name);
2089 gtk_list_store_clear(store);
2090 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2092 gtk_list_store_append(store, &iter);
2093 gtk_list_store_set(store, &iter,
2094 0, hb_audio_bitrates[ii].string,
2096 2, hb_audio_bitrates[ii].string,
2097 3, hb_audio_bitrates[ii].rate,
2098 4, hb_audio_bitrates[ii].string,
2104 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2106 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2110 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2112 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2115 static ghb_status_t hb_status;
2118 ghb_combo_init(GtkBuilder *builder)
2120 // Set up the list model for the combos
2121 init_ui_combo_boxes(builder);
2122 // Populate all the combos
2123 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
2127 ghb_backend_init(gint debug)
2130 h_scan = hb_init( debug, 0 );
2131 h_queue = hb_init( debug, 0 );
2142 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2144 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2145 hb_status.scan.state |= GHB_STATE_SCANNING;
2146 // initialize count and cur to something that won't cause FPE
2147 // when computing progress
2148 hb_status.scan.title_count = 1;
2149 hb_status.scan.title_cur = 0;
2153 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2155 g_debug("ghb_backend_queue_scan()");
2156 hb_scan( h_queue, path, titlenum, 10, 0 );
2157 hb_status.queue.state |= GHB_STATE_SCANNING;
2161 ghb_get_scan_state()
2163 return hb_status.scan.state;
2167 ghb_get_queue_state()
2169 return hb_status.queue.state;
2173 ghb_clear_scan_state(gint state)
2175 hb_status.scan.state &= ~state;
2179 ghb_clear_queue_state(gint state)
2181 hb_status.queue.state &= ~state;
2185 ghb_set_scan_state(gint state)
2187 hb_status.scan.state |= state;
2191 ghb_set_queue_state(gint state)
2193 hb_status.queue.state |= state;
2197 ghb_get_status(ghb_status_t *status)
2199 memcpy(status, &hb_status, sizeof(ghb_status_t));
2208 if (h_scan == NULL) return;
2209 hb_get_state( h_scan, &s_scan );
2210 switch( s_scan.state )
2212 #define p s_scan.param.scanning
2213 case HB_STATE_SCANNING:
2215 hb_status.scan.state |= GHB_STATE_SCANNING;
2216 hb_status.scan.title_count = p.title_count;
2217 hb_status.scan.title_cur = p.title_cur;
2221 case HB_STATE_SCANDONE:
2223 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2224 hb_status.scan.state |= GHB_STATE_SCANDONE;
2227 #define p s_scan.param.working
2228 case HB_STATE_WORKING:
2229 hb_status.scan.state |= GHB_STATE_WORKING;
2230 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2231 hb_status.scan.job_cur = p.job_cur;
2232 hb_status.scan.job_count = p.job_count;
2233 hb_status.scan.progress = p.progress;
2234 hb_status.scan.rate_cur = p.rate_cur;
2235 hb_status.scan.rate_avg = p.rate_avg;
2236 hb_status.scan.hours = p.hours;
2237 hb_status.scan.minutes = p.minutes;
2238 hb_status.scan.seconds = p.seconds;
2239 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2243 case HB_STATE_PAUSED:
2244 hb_status.scan.state |= GHB_STATE_PAUSED;
2247 case HB_STATE_MUXING:
2249 hb_status.scan.state |= GHB_STATE_MUXING;
2252 #define p s_scan.param.workdone
2253 case HB_STATE_WORKDONE:
2257 hb_status.scan.state |= GHB_STATE_WORKDONE;
2258 hb_status.scan.state &= ~GHB_STATE_MUXING;
2259 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2260 hb_status.scan.state &= ~GHB_STATE_WORKING;
2264 hb_status.scan.error = GHB_ERROR_NONE;
2266 case HB_ERROR_CANCELED:
2267 hb_status.scan.error = GHB_ERROR_CANCELED;
2270 hb_status.scan.error = GHB_ERROR_FAIL;
2273 // Delete all remaining jobs of this encode.
2274 // An encode can be composed of multiple associated jobs.
2275 // When a job is stopped, libhb removes it from the job list,
2276 // but does not remove other jobs that may be associated with it.
2277 // Associated jobs are taged in the sequence id.
2278 while ((job = hb_job(h_scan, 0)) != NULL)
2279 hb_rem( h_scan, job );
2283 hb_get_state( h_queue, &s_queue );
2284 switch( s_queue.state )
2286 #define p s_queue.param.scanning
2287 case HB_STATE_SCANNING:
2289 hb_status.queue.state |= GHB_STATE_SCANNING;
2290 hb_status.queue.title_count = p.title_count;
2291 hb_status.queue.title_cur = p.title_cur;
2295 case HB_STATE_SCANDONE:
2297 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2298 hb_status.queue.state |= GHB_STATE_SCANDONE;
2301 #define p s_queue.param.working
2302 case HB_STATE_WORKING:
2303 hb_status.queue.state |= GHB_STATE_WORKING;
2304 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2305 hb_status.queue.job_cur = p.job_cur;
2306 hb_status.queue.job_count = p.job_count;
2307 hb_status.queue.progress = p.progress;
2308 hb_status.queue.rate_cur = p.rate_cur;
2309 hb_status.queue.rate_avg = p.rate_avg;
2310 hb_status.queue.hours = p.hours;
2311 hb_status.queue.minutes = p.minutes;
2312 hb_status.queue.seconds = p.seconds;
2313 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2317 case HB_STATE_PAUSED:
2318 hb_status.queue.state |= GHB_STATE_PAUSED;
2321 case HB_STATE_MUXING:
2323 hb_status.queue.state |= GHB_STATE_MUXING;
2326 #define p s_queue.param.workdone
2327 case HB_STATE_WORKDONE:
2331 hb_status.queue.state |= GHB_STATE_WORKDONE;
2332 hb_status.queue.state &= ~GHB_STATE_MUXING;
2333 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2334 hb_status.queue.state &= ~GHB_STATE_WORKING;
2338 hb_status.queue.error = GHB_ERROR_NONE;
2340 case HB_ERROR_CANCELED:
2341 hb_status.queue.error = GHB_ERROR_CANCELED;
2344 hb_status.queue.error = GHB_ERROR_FAIL;
2347 // Delete all remaining jobs of this encode.
2348 // An encode can be composed of multiple associated jobs.
2349 // When a job is stopped, libhb removes it from the job list,
2350 // but does not remove other jobs that may be associated with it.
2351 // Associated jobs are taged in the sequence id.
2352 while ((job = hb_job(h_queue, 0)) != NULL)
2353 hb_rem( h_queue, job );
2360 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2365 if (h_scan == NULL) return FALSE;
2366 list = hb_get_titles( h_scan );
2367 if( !hb_list_count( list ) )
2369 /* No valid title, stop right there */
2373 title = hb_list_item( list, titleindex );
2374 if (title == NULL) return FALSE; // Bad titleindex
2375 tinfo->width = title->width;
2376 tinfo->height = title->height;
2377 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2378 // Don't allow crop to 0
2379 if (title->crop[0] + title->crop[1] >= title->height)
2380 title->crop[0] = title->crop[1] = 0;
2381 if (title->crop[2] + title->crop[3] >= title->width)
2382 title->crop[2] = title->crop[3] = 0;
2383 tinfo->num_chapters = hb_list_count(title->list_chapter);
2384 tinfo->rate_base = title->rate_base;
2385 tinfo->rate = title->rate;
2386 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2387 title->width * title->pixel_aspect_width,
2388 title->height * title->pixel_aspect_height);
2389 tinfo->hours = title->hours;
2390 tinfo->minutes = title->minutes;
2391 tinfo->seconds = title->seconds;
2392 tinfo->duration = title->duration;
2397 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2399 hb_audio_config_t *audio;
2401 audio = get_hb_audio(titleindex, audioindex);
2402 if (audio == NULL) return FALSE; // Bad audioindex
2403 ainfo->codec = audio->in.codec;
2404 ainfo->bitrate = audio->in.bitrate;
2405 ainfo->samplerate = audio->in.samplerate;
2410 ghb_audio_is_passthru(gint acodec)
2412 g_debug("ghb_audio_is_passthru () \n");
2413 return (acodec == HB_ACODEC_AC3) || (acodec == HB_ACODEC_DCA);
2417 ghb_get_default_acodec()
2419 return HB_ACODEC_FAAC;
2423 ghb_set_scale(signal_user_data_t *ud, gint mode)
2428 gboolean keep_aspect, round_dims, anamorphic;
2429 gboolean autocrop, autoscale, noscale;
2430 gint crop[4], width, height, par_width, par_height;
2431 gint crop_width, crop_height;
2432 gint aspect_n, aspect_d;
2433 gboolean keep_width = (mode == GHB_SCALE_KEEP_WIDTH);
2434 gboolean keep_height = (mode == GHB_SCALE_KEEP_HEIGHT);
2440 gint max_height = 0;
2442 g_debug("ghb_set_scale ()\n");
2444 if (h_scan == NULL) return;
2445 list = hb_get_titles( h_scan );
2446 if( !hb_list_count( list ) )
2448 /* No valid title, stop right there */
2453 titleindex = ghb_settings_combo_int(ud->settings, "title");
2454 title = hb_list_item( list, titleindex );
2455 if (title == NULL) return;
2457 if (job == NULL) return;
2459 // First configure widgets
2460 round_dims = ghb_settings_get_boolean(ud->settings, "ModDimensions");
2461 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
2462 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2463 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2464 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2465 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2466 // alignment constraints rather than scaling to satisfy them.
2467 noscale = ghb_settings_get_boolean(ud->settings, "noscale");
2468 // Align dimensions to either 16 or 2 pixels
2469 // The scaler crashes if the dimensions are not divisible by 2
2470 // x264 also will not accept dims that are not multiple of 2
2471 modshift = round_dims ? 4 : 1;
2472 modround = round_dims ? 8 : 1;
2476 keep_height = FALSE;
2480 keep_height = FALSE;
2482 // Step needs to be at least 2 because odd widths cause scaler crash
2483 step = round_dims ? 16 : 2;
2484 widget = GHB_WIDGET (ud->builder, "scale_width");
2485 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2486 widget = GHB_WIDGET (ud->builder, "scale_height");
2487 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2490 ghb_title_info_t tinfo;
2492 if (ghb_get_title_info (&tinfo, titleindex))
2494 crop[0] = tinfo.crop[0];
2495 crop[1] = tinfo.crop[1];
2496 crop[2] = tinfo.crop[2];
2497 crop[3] = tinfo.crop[3];
2502 // Adjust the cropping to accomplish the desired width and height
2503 crop_width = tinfo.width - crop[2] - crop[3];
2504 crop_height = tinfo.height - crop[0] - crop[1];
2505 width = (crop_width >> modshift) << modshift;
2506 height = (crop_height >> modshift) << modshift;
2507 need1 = (crop_height - height) / 2;
2508 need2 = crop_height - height - need1;
2511 need1 = (crop_width - width) / 2;
2512 need2 = crop_width - width - need1;
2516 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2517 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2518 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2519 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2522 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2523 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2524 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2525 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2526 hb_reduce(&aspect_n, &aspect_d,
2527 title->width * title->pixel_aspect_width,
2528 title->height * title->pixel_aspect_height);
2529 crop_width = title->width - crop[2] - crop[3];
2530 crop_height = title->height - crop[0] - crop[1];
2534 height = crop_height;
2540 width = ghb_settings_get_int(ud->settings, "scale_width");
2541 height = ghb_settings_get_int(ud->settings, "scale_height");
2542 max_width = ghb_settings_get_int(ud->settings, "PictureWidth");
2543 max_height = ghb_settings_get_int(ud->settings, "PictureHeight");
2545 max_width = (max_width >> modshift) << modshift;
2546 max_height = (max_height >> modshift) << modshift;
2547 // Adjust dims according to max values
2550 max_height = crop_height;
2554 max_width = crop_width;
2556 height = MIN(height, max_height);
2557 width = MIN(width, max_width);
2558 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2561 width = title->width - crop[2] - crop[3];
2563 height = title->height - crop[0] - crop[1];
2567 job->anamorphic.mode = autoscale ? 2 : 3;
2568 // The scaler crashes if the dimensions are not divisible by 2
2569 // Align mod 2. And so does something in x264_encoder_headers()
2570 job->anamorphic.modulus = round_dims ? 16 : 2;
2572 job->height = height;
2574 job->maxHeight = max_height;
2575 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2576 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2577 hb_set_anamorphic_size( job, &width, &height,
2578 &par_width, &par_height );
2582 job->anamorphic.mode = 0;
2586 gint new_width, new_height;
2588 g_debug("kw %s kh %s\n", keep_width ? "y":"n", keep_height ? "y":"n");
2589 g_debug("w %d h %d\n", width, height);
2590 // Compute pixel aspect ration.
2591 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2592 // Must scale so that par becomes 1:1
2593 // Try to keep largest dimension
2594 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2595 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2596 // Height and width are always multiples of 2, so do the rounding
2597 new_height = ((new_height + 1) >> 1) << 1;
2598 new_width = ((new_width + 1) >> 1) << 1;
2599 if ((max_width && new_width > max_width) ||
2600 new_width > title->width)
2602 height = new_height;
2604 else if ((max_height && new_height > max_height) ||
2605 new_height > title->height)
2609 else if (keep_width)
2611 height = new_height;
2613 else if (keep_height)
2617 else if (width > new_width)
2619 height = new_height;
2625 g_debug("new w %d h %d\n", width, height);
2627 width = ((width + modround) >> modshift) << modshift;
2628 height = ((height + modround) >> modshift) << modshift;
2630 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2631 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2635 set_preview_job_settings(hb_job_t *job, GValue *settings)
2637 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
2638 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
2639 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
2640 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
2642 gboolean anamorphic, round_dimensions, autoscale;
2643 autoscale = ghb_settings_get_boolean(settings, "autoscale");
2644 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
2645 round_dimensions = ghb_settings_get_boolean(settings, "ModDimensions");
2648 job->anamorphic.modulus = round_dimensions ? 16 : 2;
2649 job->anamorphic.mode = autoscale ? 2 : 3;
2653 job->anamorphic.modulus = 2;
2654 job->anamorphic.mode = 0;
2656 job->width = ghb_settings_get_int(settings, "scale_width");
2657 job->height = ghb_settings_get_int(settings, "scale_height");
2658 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
2659 gboolean decomb = ghb_settings_get_boolean(settings, "PictureDecomb");
2660 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2664 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2671 if (h_scan == NULL) return 1500;
2672 list = hb_get_titles( h_scan );
2673 title = hb_list_item( list, titleindex );
2674 if (title == NULL) return 1500;
2676 if (job == NULL) return 1500;
2677 size = ghb_settings_get_int(settings, "VideoTargetSize");
2678 return hb_calc_bitrate( job, size );
2682 ghb_validate_filter_string(const gchar *str, gint max_fields)
2688 if (str == NULL || *str == 0) return TRUE;
2691 val = g_strtod(str, &end);
2693 { // Found a numeric value
2695 // negative max_fields means infinate
2696 if (max_fields >= 0 && fields > max_fields) return FALSE;
2710 ghb_validate_filters(signal_user_data_t *ud)
2718 tweaks = ghb_settings_get_boolean(ud->settings, "allow_tweaks");
2722 str = ghb_settings_get_string(ud->settings, "tweak_PictureDetelecine");
2723 enabled = ghb_settings_get_boolean(ud->settings, "PictureDetelecine");
2724 if (enabled && !ghb_validate_filter_string(str, 6))
2726 message = g_strdup_printf(
2727 "Invalid Detelecine Settings:\n\n%s\n",
2729 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2736 str = ghb_settings_get_string(ud->settings, "tweak_PictureDecomb");
2737 enabled = ghb_settings_get_boolean(ud->settings, "PictureDecomb");
2738 if (enabled && !ghb_validate_filter_string(str, 7))
2740 message = g_strdup_printf(
2741 "Invalid Decomb Settings:\n\n%s\n",
2743 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2750 index = ghb_lookup_combo_int("tweak_PictureDeinterlace",
2751 ghb_settings_get_value(ud->settings, "tweak_PictureDeinterlace"));
2754 str = ghb_settings_get_string(ud->settings, "tweak_PictureDeinterlace");
2755 if (!ghb_validate_filter_string(str, 4))
2757 message = g_strdup_printf(
2758 "Invalid Deinterlace Settings:\n\n%s\n",
2760 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2768 index = ghb_lookup_combo_int("tweak_PictureDenoise",
2769 ghb_settings_get_value(ud->settings, "tweak_PictureDenoise"));
2772 str = ghb_settings_get_string(ud->settings, "tweak_PictureDenoise");
2773 if (!ghb_validate_filter_string(str, 4))
2775 message = g_strdup_printf(
2776 "Invalid Denoise Settings:\n\n%s\n",
2778 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2790 ghb_validate_video(signal_user_data_t *ud)
2795 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2796 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
2797 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
2798 (vcodec == HB_VCODEC_THEORA))
2800 // mp4|avi/theora combination is not supported.
2801 message = g_strdup_printf(
2802 "Theora is not supported in the MP4 and AVI containers.\n\n"
2803 "You should choose a different video codec or container.\n"
2804 "If you continue, XviD will be chosen for you.");
2805 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2811 vcodec = HB_VCODEC_XVID;
2812 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
2818 ghb_validate_audio(signal_user_data_t *ud)
2825 if (h_scan == NULL) return FALSE;
2826 list = hb_get_titles( h_scan );
2827 if( !hb_list_count( list ) )
2829 /* No valid title, stop right there */
2830 g_message("No title found.\n");
2836 titleindex = ghb_settings_combo_int(ud->settings, "title");
2837 title = hb_list_item( list, titleindex );
2838 if (title == NULL) return FALSE;
2839 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2841 const GValue *audio_list;
2844 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2845 count = ghb_array_len(audio_list);
2846 for (ii = 0; ii < count; ii++)
2849 hb_audio_config_t *taudio;
2851 asettings = ghb_array_get_nth(audio_list, ii);
2852 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
2853 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
2854 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
2855 title->list_audio, track );
2856 if ((taudio->in.codec != HB_ACODEC_AC3 && codec == HB_ACODEC_AC3) ||
2857 (taudio->in.codec != HB_ACODEC_DCA && codec == HB_ACODEC_DCA))
2859 // Not supported. AC3 is passthrough only, so input must be AC3
2861 str = (codec == HB_ACODEC_AC3) ? "AC-3" : "DTS";
2862 message = g_strdup_printf(
2863 "The source does not support %s Pass-Thru.\n\n"
2864 "You should choose a different audio codec.\n"
2865 "If you continue, one will be chosen for you.", str);
2866 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2872 if (mux == HB_MUX_AVI)
2874 codec = HB_ACODEC_LAME;
2878 codec = HB_ACODEC_FAAC;
2880 value = get_acodec_value(codec);
2881 ghb_settings_take_value(asettings, "AudioEncoder", value);
2883 gchar *a_unsup = NULL;
2884 gchar *mux_s = NULL;
2885 if (mux == HB_MUX_MP4)
2888 // mp4/mp3|vorbis combination is not supported.
2889 if (codec == HB_ACODEC_LAME)
2892 codec = HB_ACODEC_FAAC;
2894 if (codec == HB_ACODEC_VORBIS)
2897 codec = HB_ACODEC_FAAC;
2900 else if (mux == HB_MUX_AVI)
2903 // avi/faac|vorbis combination is not supported.
2904 if (codec == HB_ACODEC_FAAC)
2907 codec = HB_ACODEC_LAME;
2909 if (codec == HB_ACODEC_VORBIS)
2912 codec = HB_ACODEC_LAME;
2915 else if (mux == HB_MUX_OGM)
2918 // avi/faac|vorbis combination is not supported.
2919 if (codec == HB_ACODEC_FAAC)
2922 codec = HB_ACODEC_VORBIS;
2924 if (codec == HB_ACODEC_AC3)
2927 codec = HB_ACODEC_VORBIS;
2929 if (codec == HB_ACODEC_DCA)
2932 codec = HB_ACODEC_VORBIS;
2937 message = g_strdup_printf(
2938 "%s is not supported in the %s container.\n\n"
2939 "You should choose a different audio codec.\n"
2940 "If you continue, one will be chosen for you.", a_unsup, mux_s);
2941 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2947 value = get_acodec_value(codec);
2948 ghb_settings_take_value(asettings, "AudioEncoder", value);
2950 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
2951 gboolean allow_mono = TRUE;
2952 gboolean allow_stereo = TRUE;
2953 gboolean allow_dolby = TRUE;
2954 gboolean allow_dpl2 = TRUE;
2955 gboolean allow_6ch = TRUE;
2957 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2958 (codec != HB_ACODEC_LAME);
2959 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2961 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
2963 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
2964 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
2965 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
2966 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
2968 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2969 (codec != HB_ACODEC_LAME) &&
2970 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
2971 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
2973 gchar *mix_unsup = NULL;
2974 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
2978 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
2980 mix_unsup = "stereo";
2982 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
2984 mix_unsup = "Dolby";
2986 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
2988 mix_unsup = "Dolby Pro Logic II";
2990 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
2992 mix_unsup = "6 Channel";
2996 message = g_strdup_printf(
2997 "The source audio does not support %s mixdown.\n\n"
2998 "You should choose a different mixdown.\n"
2999 "If you continue, one will be chosen for you.", mix_unsup);
3000 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3006 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3007 value = get_amix_value(mix);
3008 ghb_settings_take_value(asettings, "AudioMixdown", value);
3015 ghb_validate_vquality(GValue *settings)
3021 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3022 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3024 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3025 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3027 if (!ghb_settings_get_boolean(settings, "directqp"))
3030 if (vcodec != HB_VCODEC_X264)
3043 if (vcodec == HB_VCODEC_X264)
3048 else if (vcodec == HB_VCODEC_FFMPEG)
3060 if (vquality < min || vquality > max)
3062 message = g_strdup_printf(
3063 "Interesting video quality choise: %d\n\n"
3064 "Typical values range from %d to %d.\n"
3065 "Are you sure you wish to use this setting?",
3066 (gint)vquality, min, max);
3067 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3068 "Cancel", "Continue"))
3080 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3085 static gchar *x264opts;
3087 gboolean tweaks = FALSE;
3088 gchar *detel_str = NULL;
3089 gchar *decomb_str = NULL;
3090 gchar *deint_str = NULL;
3091 gchar *deblock_str = NULL;
3092 gchar *denoise_str = NULL;
3093 gchar *dest_str = NULL;
3095 g_debug("add_job()\n");
3096 if (h == NULL) return;
3097 list = hb_get_titles( h );
3098 if( !hb_list_count( list ) )
3100 /* No valid title, stop right there */
3104 title = hb_list_item( list, titleindex );
3105 if (title == NULL) return;
3107 /* Set job settings */
3109 if (job == NULL) return;
3111 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3112 if (job->start_at_preview)
3114 job->seek_points = ghb_settings_get_int(js, "preview_count");
3115 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3118 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3119 job->mux = ghb_settings_combo_int(js, "FileFormat");
3120 if (job->mux == HB_MUX_MP4)
3122 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3123 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3127 job->largeFileSize = FALSE;
3128 job->mp4_optimize = FALSE;
3130 if (!job->start_at_preview)
3132 gint chapter_start, chapter_end;
3133 chapter_start = ghb_settings_get_int(js, "start_chapter");
3134 chapter_end = ghb_settings_get_int(js, "end_chapter");
3135 gint num_chapters = hb_list_count(title->list_chapter);
3136 job->chapter_start = MIN( num_chapters, chapter_start );
3137 job->chapter_end = MAX( job->chapter_start, chapter_end );
3139 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3140 if ( job->chapter_markers )
3147 chapters = ghb_settings_get_value(js, "chapter_list");
3148 count = ghb_array_len(chapters);
3149 for(chap = chapter_start; chap <= chapter_end; chap++)
3151 hb_chapter_t * chapter_s;
3157 chapter = ghb_array_get_nth(chapters, chap-1);
3158 name = ghb_value_string(chapter);
3162 name = g_strdup_printf ("Chapter %2d", chap);
3164 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3165 strncpy(chapter_s->title, name, 1023);
3166 chapter_s->title[1023] = '\0';
3171 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3172 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3173 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3174 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3177 gboolean decomb = ghb_settings_get_boolean(js, "PictureDecomb");
3178 gint deint = ghb_settings_combo_int(js,
3179 tweaks ? "tweak_PictureDeinterlace":"PictureDeinterlace");
3181 job->deinterlace = (deint != 0) ? 1 : 0;
3183 job->deinterlace = 0;
3184 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3186 gboolean autoscale = ghb_settings_get_boolean(js, "autoscale");
3187 gboolean anamorphic = ghb_settings_get_boolean(js, "anamorphic");
3188 gboolean round_dimensions = ghb_settings_get_boolean(js, "ModDimensions");
3191 job->anamorphic.mode = autoscale ? 2 : 3;
3192 // Also, x264 requires things to be divisible by 2.
3193 job->anamorphic.modulus = round_dimensions ? 16 : 2;
3197 job->anamorphic.mode = 0;
3198 job->anamorphic.modulus = 2;
3200 /* Add selected filters */
3201 job->filters = hb_list_init();
3202 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3203 if( vrate == 0 && ghb_settings_get_boolean(js, "PictureDetelecine" ) )
3208 if( ghb_settings_get_boolean(js, "PictureDetelecine" ) )
3210 hb_filter_detelecine.settings = NULL;
3213 detel_str = ghb_settings_get_string(js, "tweak_PictureDetelecine");
3214 if (detel_str && detel_str[0])
3216 hb_filter_detelecine.settings = detel_str;
3219 hb_list_add( job->filters, &hb_filter_detelecine );
3223 // Use default settings
3224 hb_filter_decomb.settings = NULL;
3227 decomb_str = ghb_settings_get_string(js, "tweak_PictureDecomb");
3228 if (decomb_str && decomb_str[0])
3230 hb_filter_decomb.settings = (gchar*)decomb_str;
3233 hb_list_add( job->filters, &hb_filter_decomb );
3235 if( job->deinterlace )
3238 deint_str = g_strdup(deint_opts.map[deint].svalue);
3240 deint_str = ghb_settings_get_string(js,
3241 tweaks ? "tweak_PictureDeinterlace" : "PictureDeinterlace");
3242 hb_filter_deinterlace.settings = deint_str;
3243 hb_list_add( job->filters, &hb_filter_deinterlace );
3245 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3248 deblock_str = g_strdup_printf("%d", deblock);
3249 hb_filter_deblock.settings = deblock_str;
3250 hb_list_add( job->filters, &hb_filter_deblock );
3252 gint denoise = ghb_settings_combo_int(js,
3253 tweaks ? "tweak_PictureDenoise" : "PictureDenoise");
3257 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3259 denoise_str = (gchar*)ghb_settings_get_string(
3260 js, tweaks ? "tweak_PictureDenoise" : "PictureDenoise");
3261 hb_filter_denoise.settings = denoise_str;
3262 hb_list_add( job->filters, &hb_filter_denoise );
3264 job->width = ghb_settings_get_int(js, "scale_width");
3265 job->height = ghb_settings_get_int(js, "scale_height");
3267 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3268 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3269 (job->vcodec == HB_VCODEC_THEORA))
3271 // mp4|avi/theora combination is not supported.
3272 job->vcodec = HB_VCODEC_XVID;
3274 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3276 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3278 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3281 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3282 if (!ghb_settings_get_boolean(js, "directqp"))
3284 if (vquality == 0.0) vquality = 0.01;
3285 if (vquality == 1.0) vquality = 0.0;
3287 job->vquality = vquality;
3290 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3292 job->vquality = -1.0;
3293 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3295 // AVI container does not support variable frame rate.
3296 if (job->mux == HB_MUX_AVI)
3304 job->vrate = title->rate;
3305 job->vrate_base = title->rate_base;
3310 job->vrate = 27000000;
3311 job->vrate_base = vrate;
3314 // First remove any audios that are already in the list
3315 // This happens if you are encoding the same title a second time.
3316 gint num_audio_tracks = hb_list_count(job->list_audio);
3318 for(ii = 0; ii < num_audio_tracks; ii++)
3320 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3321 hb_list_rem(job->list_audio, audio);
3324 const GValue *audio_list;
3328 audio_list = ghb_settings_get_value(js, "audio_list");
3329 count = ghb_array_len(audio_list);
3330 for (ii = 0; ii < count; ii++)
3333 hb_audio_config_t audio;
3334 hb_audio_config_t *taudio;
3336 hb_audio_config_init(&audio);
3337 asettings = ghb_array_get_nth(audio_list, ii);
3338 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3339 audio.out.track = tcount;
3340 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3341 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3342 title->list_audio, audio.in.track );
3343 if ((taudio->in.codec != HB_ACODEC_AC3 &&
3344 audio.out.codec == HB_ACODEC_AC3) ||
3345 (taudio->in.codec != HB_ACODEC_DCA &&
3346 audio.out.codec == HB_ACODEC_DCA))
3348 // Not supported. AC3 is passthrough only, so input must be AC3
3349 if (job->mux == HB_MUX_AVI)
3351 audio.out.codec = HB_ACODEC_LAME;
3355 printf("switching to faac\n");
3356 audio.out.codec = HB_ACODEC_FAAC;
3359 if ((job->mux == HB_MUX_MP4) &&
3360 ((audio.out.codec == HB_ACODEC_LAME) ||
3361 (audio.out.codec == HB_ACODEC_VORBIS)))
3363 // mp4/mp3|vorbis combination is not supported.
3364 audio.out.codec = HB_ACODEC_FAAC;
3366 if ((job->mux == HB_MUX_AVI) &&
3367 ((audio.out.codec == HB_ACODEC_FAAC) ||
3368 (audio.out.codec == HB_ACODEC_VORBIS)))
3370 // avi/faac|vorbis combination is not supported.
3371 audio.out.codec = HB_ACODEC_LAME;
3373 if ((job->mux == HB_MUX_OGM) &&
3374 ((audio.out.codec == HB_ACODEC_FAAC) ||
3375 (audio.out.codec == HB_ACODEC_AC3) ||
3376 (audio.out.codec == HB_ACODEC_DCA)))
3378 // ogm/faac|ac3 combination is not supported.
3379 audio.out.codec = HB_ACODEC_VORBIS;
3381 audio.out.dynamic_range_compression =
3382 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3383 // It would be better if this were done in libhb for us, but its not yet.
3384 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3386 audio.out.mixdown = 0;
3390 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3391 // Make sure the mixdown is valid and pick a new one if not.
3392 audio.out.mixdown = ghb_get_best_mix(titleindex,
3393 audio.in.track, audio.out.codec, audio.out.mixdown);
3395 ghb_settings_combo_int(asettings, "AudioBitrate");
3396 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3397 if (srate == 0) // 0 is same as source
3398 audio.out.samplerate = taudio->in.samplerate;
3400 audio.out.samplerate = srate;
3403 // Add it to the jobs audio list
3404 hb_audio_add( job, &audio );
3407 // I was tempted to move this up with the reset of the video quality
3408 // settings, but I suspect the settings above need to be made
3409 // first in order for hb_calc_bitrate to be accurate.
3410 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3414 size = ghb_settings_get_int(js, "VideoTargetSize");
3415 job->vbitrate = hb_calc_bitrate( job, size );
3416 job->vquality = -1.0;
3419 dest_str = ghb_settings_get_string(js, "destination");
3420 job->file = dest_str;
3421 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3422 // TODO: libhb holds onto a reference to the x264opts and is not
3423 // finished with it until encoding the job is done. But I can't
3424 // find a way to get at the job before it is removed in order to
3425 // free up the memory I am allocating here.
3426 // The short story is THIS LEAKS.
3427 x264opts = ghb_build_x264opts_string(js);
3429 if( x264opts != NULL && *x264opts != '\0' )
3431 job->x264opts = x264opts;
3433 else /*avoids a bus error crash when options aren't specified*/
3435 job->x264opts = NULL;
3438 gchar *slang = ghb_settings_get_string(js, "Subtitles");
3439 subtitle = -2; // default to none
3440 if (strcmp(slang, "auto") == 0)
3447 hb_subtitle_t * subt;
3449 scount = hb_list_count(title->list_subtitle);
3450 for (ii = 0; ii < scount; ii++)
3452 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
3453 if (strcmp(slang, subt->iso639_2) == 0)
3460 gboolean forced_subtitles = ghb_settings_get_boolean(js, "SubtitlesForced");
3461 job->subtitle_force = forced_subtitles;
3463 job->subtitle = subtitle;
3468 // Subtitle scan. Look for subtitle matching audio language
3472 * When subtitle scan is enabled do a fast pre-scan job
3473 * which will determine which subtitles to enable, if any.
3476 job->indepth_scan = 1;
3478 x264opts_tmp = job->x264opts;
3479 job->x264opts = NULL;
3481 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3482 *(job->select_subtitle) = NULL;
3485 * Add the pre-scan job
3487 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3489 //if (job->x264opts != NULL)
3490 // g_free(job->x264opts);
3492 job->x264opts = x264opts_tmp;
3496 job->select_subtitle = NULL;
3498 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
3499 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3502 * If subtitle_scan is enabled then only turn it on
3503 * for the second pass and then off again for the
3506 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3507 job->select_subtitle = NULL;
3509 job->indepth_scan = 0;
3510 gchar *x264opts2 = NULL;
3513 x264opts2 = g_strdup(x264opts);
3516 * If turbo options have been selected then append them
3517 * to the x264opts now (size includes one ':' and the '\0')
3519 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
3525 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3531 * No x264opts to modify, but apply the turbo options
3532 * anyway as they may be modifying defaults
3534 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3536 x264opts = tmp_x264opts;
3538 job->x264opts = x264opts;
3540 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3542 //if (job->x264opts != NULL)
3543 // g_free(job->x264opts);
3545 job->select_subtitle = subtitle_tmp;
3548 * On the second pass we turn off subtitle scan so that we
3549 * can actually encode using any subtitles that were auto
3550 * selected in the first pass (using the whacky select-subtitle
3551 * attribute of the job).
3553 job->indepth_scan = 0;
3554 job->x264opts = x264opts2;
3555 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3557 //if (job->x264opts != NULL)
3558 // g_free(job->x264opts);
3562 job->indepth_scan = 0;
3564 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3566 //if (job->x264opts != NULL)
3567 // g_free(job->x264opts);
3569 if (detel_str) g_free(detel_str);
3570 if (decomb_str) g_free(decomb_str);
3571 if (deint_str) g_free(deint_str);
3572 if (deblock_str) g_free(deblock_str);
3573 if (denoise_str) g_free(denoise_str);
3574 if (dest_str) g_free(dest_str);
3578 ghb_add_job(GValue *js, gint unique_id)
3580 // Since I'm doing a scan of the single title I want just prior
3581 // to adding the job, there is only the one title to choose from.
3582 add_job(h_queue, js, unique_id, 0);
3586 ghb_add_live_job(GValue *js, gint unique_id)
3588 // Since I'm doing a scan of the single title I want just prior
3589 // to adding the job, there is only the one title to choose from.
3590 gint titleindex = ghb_settings_combo_int(js, "title");
3591 add_job(h_scan, js, unique_id, titleindex);
3595 ghb_remove_job(gint unique_id)
3600 // Multiples passes all get the same id
3602 // Go backwards through list, so reordering doesn't screw me.
3603 ii = hb_count(h_queue) - 1;
3604 while ((job = hb_job(h_queue, ii--)) != NULL)
3606 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3607 hb_rem(h_queue, job);
3614 hb_start( h_queue );
3624 ghb_start_live_encode()
3630 ghb_stop_live_encode()
3639 hb_get_state2( h_queue, &s );
3641 if( s.state == HB_STATE_PAUSED )
3643 hb_resume( h_queue );
3647 hb_pause( h_queue );
3651 #define RED_HEIGHT 720.0
3652 #define RED_WIDTH 1280.0
3655 ghb_get_preview_image(
3658 signal_user_data_t *ud,
3667 settings = ud->settings;
3668 list = hb_get_titles( h_scan );
3669 if( !hb_list_count( list ) )
3671 /* No valid title, stop right there */
3674 title = hb_list_item( list, titleindex );
3675 if (title == NULL) return NULL;
3676 if (title->job == NULL) return NULL;
3677 set_preview_job_settings(title->job, settings);
3679 // hb_get_preview can't handle sizes that are larger than the original title
3681 if (title->job->width > title->width)
3682 title->job->width = title->width;
3684 if (title->job->height > title->height)
3685 title->job->height = title->height;
3686 // And also creates artifacts if the width is not a multiple of 8
3687 //title->job->width = ((title->job->width + 4) >> 3) << 3;
3688 // And the height must be a multiple of 2
3689 //title->job->height = ((title->job->height + 1) >> 1) << 1;
3691 // Make sure we have a big enough buffer to receive the image from libhb. libhb
3692 // creates images with a one-pixel border around the original content. Hence we
3693 // add 2 pixels horizontally and vertically to the buffer size.
3694 gint srcWidth = title->width + 2;
3695 gint srcHeight= title->height + 2;
3696 gint dstWidth = title->width;
3697 gint dstHeight= title->height;
3699 gint borderLeft = 1;
3702 // |<---------- title->width ----------->|
3703 // | |<---- title->job->width ---->| |
3705 // .......................................
3706 // ....+-----------------------------+....
3707 // ....| |....<-- gray border
3710 // ....| |<------- image
3716 // ....+-----------------------------+....
3717 // .......................................
3718 dstWidth = title->job->width;
3719 dstHeight = title->job->height;
3720 borderTop = (srcHeight - dstHeight) / 2;
3721 borderLeft = (srcWidth - dstWidth) / 2;
3722 g_debug("boarders removed\n");
3725 g_debug("src %d x %d\n", srcWidth, srcHeight);
3726 g_debug("dst %d x %d\n", dstWidth, dstHeight);
3727 g_debug("job dim %d x %d\n", title->job->width, title->job->height);
3728 g_debug("title crop %d:%d:%d:%d\n",
3733 g_debug("job crop %d:%d:%d:%d\n",
3734 title->job->crop[0],
3735 title->job->crop[1],
3736 title->job->crop[2],
3737 title->job->crop[3]);
3738 static guint8 *buffer = NULL;
3739 static gint bufferSize = 0;
3742 newSize = srcWidth * srcHeight * 4;
3743 if( bufferSize < newSize )
3745 bufferSize = newSize;
3746 buffer = (guint8*) g_realloc( buffer, bufferSize );
3748 hb_get_preview( h_scan, title, index, buffer );
3750 // Create an GdkPixbuf and copy the libhb image into it, converting it from
3751 // libhb's format something suitable. Along the way, we'll strip off the
3752 // border around libhb's image.
3754 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
3755 // Alpha is ignored.
3757 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
3758 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
3760 guint32 *src = (guint32*)buffer;
3761 guint8 *dst = pixels;
3762 src += borderTop * srcWidth; // skip top rows in src to get to first row of dst
3763 src += borderLeft; // skip left pixels in src to get to first pixel of dst
3765 gint channels = gdk_pixbuf_get_n_channels (preview);
3766 gint stride = gdk_pixbuf_get_rowstride (preview);
3768 for (ii = 0; ii < dstHeight; ii++)
3771 for (jj = 0; jj < dstWidth; jj++)
3773 tmp[0] = src[0] >> 16;
3774 tmp[1] = src[0] >> 8;
3775 tmp[2] = src[0] >> 0;
3780 src += (srcWidth - dstWidth); // skip to next row in src
3782 // Got it, but hb_get_preview doesn't compensate for anamorphic, so lets
3784 gint width, height, par_width, par_height;
3785 gboolean anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
3788 hb_set_anamorphic_size( title->job, &width, &height, &par_width, &par_height );
3789 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
3793 ghb_par_scale(ud, &dstWidth, &dstHeight, 1, 1);
3795 *out_width = dstWidth;
3796 *out_height = dstHeight;
3797 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
3803 ss = gdk_screen_get_default();
3804 s_w = gdk_screen_get_width(ss);
3805 s_h = gdk_screen_get_height(ss);
3806 num = dstWidth * par_width;
3807 den = dstHeight * par_height;
3809 if (dstWidth > s_w * 80 / 100)
3811 dstWidth = s_w * 80 / 100;
3812 dstHeight = dstWidth * den / num;
3814 if (dstHeight > s_h * 80 / 100)
3816 dstHeight = s_h * 80 / 100;
3817 dstWidth = dstHeight * num / den;
3820 g_debug("scaled %d x %d\n", dstWidth, dstHeight);
3821 GdkPixbuf *scaled_preview;
3822 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
3823 g_object_unref (preview);
3824 return scaled_preview;
3828 sanitize_volname(gchar *name)
3853 ghb_dvd_volname(const gchar *device)
3856 name = hb_dvd_name((gchar*)device);
3859 sanitize_volname(name);
3860 return g_strdup(name);