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"},
139 combo_opts_t acodec_opts =
141 sizeof(d_acodec_opts)/sizeof(options_map_t),
145 static options_map_t d_direct_opts[] =
147 {"None", "none", 0, "none"},
148 {"Spatial", "spatial", 1, "spatial"},
149 {"Temporal", "temporal", 2, "temporal"},
150 {"Automatic", "auto", 3, "auto"},
152 combo_opts_t direct_opts =
154 sizeof(d_direct_opts)/sizeof(options_map_t),
158 static options_map_t d_me_opts[] =
160 {"Diamond", "dia", 0, "dia"},
161 {"Hexagon", "hex", 1, "hex"},
162 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
163 {"Exhaustive", "esa", 3, "esa"},
164 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
166 combo_opts_t me_opts =
168 sizeof(d_me_opts)/sizeof(options_map_t),
172 static options_map_t d_subme_opts[] =
184 combo_opts_t subme_opts =
186 sizeof(d_subme_opts)/sizeof(options_map_t),
190 static options_map_t d_analyse_opts[] =
192 {"Some", "some", 0, "some"},
193 {"None", "none", 1, "none"},
194 {"All", "all", 2, "all"},
195 {"Custom", "custom", 3, "all"},
197 combo_opts_t analyse_opts =
199 sizeof(d_analyse_opts)/sizeof(options_map_t),
203 static options_map_t d_trellis_opts[] =
205 {"Disabled", "0", 0, "0"},
206 {"Final Macro Block", "1", 1, "1"},
207 {"Always", "2", 2, "2"},
209 combo_opts_t trellis_opts =
211 sizeof(d_trellis_opts)/sizeof(options_map_t),
215 combo_opts_t subtitle_opts =
221 combo_opts_t title_opts =
227 combo_opts_t audio_track_opts =
239 combo_name_map_t combo_name_map[] =
241 {"LoggingLevel", &logging_opts},
242 {"FileFormat", &container_opts},
243 {"PictureDeinterlace", &deint_opts},
244 {"tweak_PictureDeinterlace", &deint_opts},
245 {"PictureDenoise", &denoise_opts},
246 {"tweak_PictureDenoise", &denoise_opts},
247 {"VideoEncoder", &vcodec_opts},
248 {"AudioEncoder", &acodec_opts},
249 {"x264_direct", &direct_opts},
250 {"x264_me", &me_opts},
251 {"x264_subme", &subme_opts},
252 {"x264_analyse", &analyse_opts},
253 {"x264_trellis", &trellis_opts},
254 {"Subtitles", &subtitle_opts},
255 {"title", &title_opts},
256 {"AudioTrack", &audio_track_opts},
261 typedef struct iso639_lang_t
263 char * eng_name; /* Description in English */
264 char * native_name; /* Description in native language */
265 char * iso639_1; /* ISO-639-1 (2 characters) code */
266 char * iso639_2; /* ISO-639-2/t (3 character) code */
267 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
271 const iso639_lang_t ghb_language_table[] =
273 { "Any", "", "zz", "und" },
274 { "Afar", "", "aa", "aar" },
275 { "Abkhazian", "", "ab", "abk" },
276 { "Afrikaans", "", "af", "afr" },
277 { "Akan", "", "ak", "aka" },
278 { "Albanian", "", "sq", "sqi", "alb" },
279 { "Amharic", "", "am", "amh" },
280 { "Arabic", "", "ar", "ara" },
281 { "Aragonese", "", "an", "arg" },
282 { "Armenian", "", "hy", "hye", "arm" },
283 { "Assamese", "", "as", "asm" },
284 { "Avaric", "", "av", "ava" },
285 { "Avestan", "", "ae", "ave" },
286 { "Aymara", "", "ay", "aym" },
287 { "Azerbaijani", "", "az", "aze" },
288 { "Bashkir", "", "ba", "bak" },
289 { "Bambara", "", "bm", "bam" },
290 { "Basque", "", "eu", "eus", "baq" },
291 { "Belarusian", "", "be", "bel" },
292 { "Bengali", "", "bn", "ben" },
293 { "Bihari", "", "bh", "bih" },
294 { "Bislama", "", "bi", "bis" },
295 { "Bosnian", "", "bs", "bos" },
296 { "Breton", "", "br", "bre" },
297 { "Bulgarian", "", "bg", "bul" },
298 { "Burmese", "", "my", "mya", "bur" },
299 { "Catalan", "", "ca", "cat" },
300 { "Chamorro", "", "ch", "cha" },
301 { "Chechen", "", "ce", "che" },
302 { "Chinese", "", "zh", "zho", "chi" },
303 { "Church Slavic", "", "cu", "chu" },
304 { "Chuvash", "", "cv", "chv" },
305 { "Cornish", "", "kw", "cor" },
306 { "Corsican", "", "co", "cos" },
307 { "Cree", "", "cr", "cre" },
308 { "Czech", "", "cs", "ces", "cze" },
309 { "Danish", "Dansk", "da", "dan" },
310 { "Divehi", "", "dv", "div" },
311 { "Dutch", "Nederlands", "nl", "nld", "dut" },
312 { "Dzongkha", "", "dz", "dzo" },
313 { "English", "English", "en", "eng" },
314 { "Esperanto", "", "eo", "epo" },
315 { "Estonian", "", "et", "est" },
316 { "Ewe", "", "ee", "ewe" },
317 { "Faroese", "", "fo", "fao" },
318 { "Fijian", "", "fj", "fij" },
319 { "Finnish", "Suomi", "fi", "fin" },
320 { "French", "Francais", "fr", "fra", "fre" },
321 { "Western Frisian", "", "fy", "fry" },
322 { "Fulah", "", "ff", "ful" },
323 { "Georgian", "", "ka", "kat", "geo" },
324 { "German", "Deutsch", "de", "deu", "ger" },
325 { "Gaelic (Scots)", "", "gd", "gla" },
326 { "Irish", "", "ga", "gle" },
327 { "Galician", "", "gl", "glg" },
328 { "Manx", "", "gv", "glv" },
329 { "Greek, Modern", "", "el", "ell", "gre" },
330 { "Guarani", "", "gn", "grn" },
331 { "Gujarati", "", "gu", "guj" },
332 { "Haitian", "", "ht", "hat" },
333 { "Hausa", "", "ha", "hau" },
334 { "Hebrew", "", "he", "heb" },
335 { "Herero", "", "hz", "her" },
336 { "Hindi", "", "hi", "hin" },
337 { "Hiri Motu", "", "ho", "hmo" },
338 { "Hungarian", "Magyar", "hu", "hun" },
339 { "Igbo", "", "ig", "ibo" },
340 { "Icelandic", "Islenska", "is", "isl", "ice" },
341 { "Ido", "", "io", "ido" },
342 { "Sichuan Yi", "", "ii", "iii" },
343 { "Inuktitut", "", "iu", "iku" },
344 { "Interlingue", "", "ie", "ile" },
345 { "Interlingua", "", "ia", "ina" },
346 { "Indonesian", "", "id", "ind" },
347 { "Inupiaq", "", "ik", "ipk" },
348 { "Italian", "Italiano", "it", "ita" },
349 { "Javanese", "", "jv", "jav" },
350 { "Japanese", "", "ja", "jpn" },
351 { "Kalaallisut", "", "kl", "kal" },
352 { "Kannada", "", "kn", "kan" },
353 { "Kashmiri", "", "ks", "kas" },
354 { "Kanuri", "", "kr", "kau" },
355 { "Kazakh", "", "kk", "kaz" },
356 { "Central Khmer", "", "km", "khm" },
357 { "Kikuyu", "", "ki", "kik" },
358 { "Kinyarwanda", "", "rw", "kin" },
359 { "Kirghiz", "", "ky", "kir" },
360 { "Komi", "", "kv", "kom" },
361 { "Kongo", "", "kg", "kon" },
362 { "Korean", "", "ko", "kor" },
363 { "Kuanyama", "", "kj", "kua" },
364 { "Kurdish", "", "ku", "kur" },
365 { "Lao", "", "lo", "lao" },
366 { "Latin", "", "la", "lat" },
367 { "Latvian", "", "lv", "lav" },
368 { "Limburgan", "", "li", "lim" },
369 { "Lingala", "", "ln", "lin" },
370 { "Lithuanian", "", "lt", "lit" },
371 { "Luxembourgish", "", "lb", "ltz" },
372 { "Luba-Katanga", "", "lu", "lub" },
373 { "Ganda", "", "lg", "lug" },
374 { "Macedonian", "", "mk", "mkd", "mac" },
375 { "Marshallese", "", "mh", "mah" },
376 { "Malayalam", "", "ml", "mal" },
377 { "Maori", "", "mi", "mri", "mao" },
378 { "Marathi", "", "mr", "mar" },
379 { "Malay", "", "ms", "msa", "msa" },
380 { "Malagasy", "", "mg", "mlg" },
381 { "Maltese", "", "mt", "mlt" },
382 { "Moldavian", "", "mo", "mol" },
383 { "Mongolian", "", "mn", "mon" },
384 { "Nauru", "", "na", "nau" },
385 { "Navajo", "", "nv", "nav" },
386 { "Ndebele, South", "", "nr", "nbl" },
387 { "Ndebele, North", "", "nd", "nde" },
388 { "Ndonga", "", "ng", "ndo" },
389 { "Nepali", "", "ne", "nep" },
390 { "Norwegian Nynorsk", "", "nn", "nno" },
391 { "Norwegian Bokmål", "", "nb", "nob" },
392 { "Norwegian", "Norsk", "no", "nor" },
393 { "Chichewa; Nyanja", "", "ny", "nya" },
394 { "Occitan", "", "oc", "oci" },
395 { "Ojibwa", "", "oj", "oji" },
396 { "Oriya", "", "or", "ori" },
397 { "Oromo", "", "om", "orm" },
398 { "Ossetian", "", "os", "oss" },
399 { "Panjabi", "", "pa", "pan" },
400 { "Persian", "", "fa", "fas", "per" },
401 { "Pali", "", "pi", "pli" },
402 { "Polish", "", "pl", "pol" },
403 { "Portuguese", "Portugues", "pt", "por" },
404 { "Pushto", "", "ps", "pus" },
405 { "Quechua", "", "qu", "que" },
406 { "Romansh", "", "rm", "roh" },
407 { "Romanian", "", "ro", "ron", "rum" },
408 { "Rundi", "", "rn", "run" },
409 { "Russian", "", "ru", "rus" },
410 { "Sango", "", "sg", "sag" },
411 { "Sanskrit", "", "sa", "san" },
412 { "Serbian", "", "sr", "srp", "scc" },
413 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
414 { "Sinhala", "", "si", "sin" },
415 { "Slovak", "", "sk", "slk", "slo" },
416 { "Slovenian", "", "sl", "slv" },
417 { "Northern Sami", "", "se", "sme" },
418 { "Samoan", "", "sm", "smo" },
419 { "Shona", "", "sn", "sna" },
420 { "Sindhi", "", "sd", "snd" },
421 { "Somali", "", "so", "som" },
422 { "Sotho, Southern", "", "st", "sot" },
423 { "Spanish", "Espanol", "es", "spa" },
424 { "Sardinian", "", "sc", "srd" },
425 { "Swati", "", "ss", "ssw" },
426 { "Sundanese", "", "su", "sun" },
427 { "Swahili", "", "sw", "swa" },
428 { "Swedish", "Svenska", "sv", "swe" },
429 { "Tahitian", "", "ty", "tah" },
430 { "Tamil", "", "ta", "tam" },
431 { "Tatar", "", "tt", "tat" },
432 { "Telugu", "", "te", "tel" },
433 { "Tajik", "", "tg", "tgk" },
434 { "Tagalog", "", "tl", "tgl" },
435 { "Thai", "", "th", "tha" },
436 { "Tibetan", "", "bo", "bod", "tib" },
437 { "Tigrinya", "", "ti", "tir" },
438 { "Tonga", "", "to", "ton" },
439 { "Tswana", "", "tn", "tsn" },
440 { "Tsonga", "", "ts", "tso" },
441 { "Turkmen", "", "tk", "tuk" },
442 { "Turkish", "", "tr", "tur" },
443 { "Twi", "", "tw", "twi" },
444 { "Uighur", "", "ug", "uig" },
445 { "Ukrainian", "", "uk", "ukr" },
446 { "Urdu", "", "ur", "urd" },
447 { "Uzbek", "", "uz", "uzb" },
448 { "Venda", "", "ve", "ven" },
449 { "Vietnamese", "", "vi", "vie" },
450 { "Volapük", "", "vo", "vol" },
451 { "Welsh", "", "cy", "cym", "wel" },
452 { "Walloon", "", "wa", "wln" },
453 { "Wolof", "", "wo", "wol" },
454 { "Xhosa", "", "xh", "xho" },
455 { "Yiddish", "", "yi", "yid" },
456 { "Yoruba", "", "yo", "yor" },
457 { "Zhuang", "", "za", "zha" },
458 { "Zulu", "", "zu", "zul" },
459 {NULL, NULL, NULL, NULL}
461 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
463 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
466 del_tree(const gchar *name, gboolean del_top)
470 if (g_file_test(name, G_FILE_TEST_IS_DIR))
472 GDir *gdir = g_dir_open(name, 0, NULL);
473 file = g_dir_read_name(gdir);
477 path = g_strdup_printf("%s/%s", name, file);
478 del_tree(path, TRUE);
480 file = g_dir_read_name(gdir);
500 signal_user_data_t *ud,
507 if (ghb_settings_get_boolean(ud->settings, "directqp"))
509 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
510 // Only x264 and ffmpeg currently support direct qp/crf entry
514 if (vcodec == HB_VCODEC_X264)
519 else if (vcodec == HB_VCODEC_FFMPEG)
544 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
550 str = ghb_value_string(gval);
551 for (ii = 0; ii < opts->count; ii++)
553 if (strcmp(opts->map[ii].shortOpt, str) == 0)
555 result = opts->map[ii].ivalue;
564 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
568 const gchar *result = "";
570 str = ghb_value_string(gval);
571 for (ii = 0; ii < opts->count; ii++)
573 if (strcmp(opts->map[ii].shortOpt, str) == 0)
575 result = opts->map[ii].option;
584 lookup_mix_int(const GValue *mix)
591 str = ghb_value_string(mix);
592 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
594 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
596 result = hb_audio_mixdowns[ii].amixdown;
605 lookup_mix_option(const GValue *mix)
609 gchar *result = "None";
612 str = ghb_value_string(mix);
613 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
615 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
617 result = hb_audio_mixdowns[ii].human_readable_name;
626 lookup_video_rate_int(const GValue *vrate)
632 str = ghb_value_string(vrate);
633 for (ii = 0; ii < hb_video_rates_count; ii++)
635 if (strcmp(hb_video_rates[ii].string, str) == 0)
637 result = hb_video_rates[ii].rate;
642 // Default to "same as source"
647 lookup_video_rate_option(const GValue *vrate)
651 const gchar *result = "Same as source";
653 str = ghb_value_string(vrate);
654 for (ii = 0; ii < hb_video_rates_count; ii++)
656 if (strcmp(hb_video_rates[ii].string, str) == 0)
658 result = hb_video_rates[ii].string;
663 // Default to "same as source"
668 lookup_audio_rate_int(const GValue *rate)
674 // Coincidentally, the string "source" will return 0
675 // which is our flag to use "same as source"
676 str = ghb_value_string(rate);
677 for (ii = 0; ii < hb_audio_rates_count; ii++)
679 if (strcmp(hb_audio_rates[ii].string, str) == 0)
681 result = hb_audio_rates[ii].rate;
690 lookup_audio_rate_option(const GValue *rate)
694 const gchar *result = "Same as source";
696 // Coincidentally, the string "source" will return 0
697 // which is our flag to use "same as source"
698 str = ghb_value_string(rate);
699 for (ii = 0; ii < hb_audio_rates_count; ii++)
701 if (strcmp(hb_audio_rates[ii].string, str) == 0)
703 result = hb_audio_rates[ii].string;
712 lookup_audio_bitrate_int(const GValue *rate)
718 // Coincidentally, the string "source" will return 0
719 // which is our flag to use "same as source"
720 str = ghb_value_string(rate);
721 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
723 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
725 result = hb_audio_bitrates[ii].rate;
734 lookup_audio_bitrate_option(const GValue *rate)
738 const gchar *result = "Same as source";
740 // Coincidentally, the string "source" will return 0
741 // which is our flag to use "same as source"
742 str = ghb_value_string(rate);
743 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
745 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
747 result = hb_audio_bitrates[ii].string;
756 lookup_audio_lang_int(const GValue *rate)
762 // Coincidentally, the string "source" will return 0
763 // which is our flag to use "same as source"
764 str = ghb_value_string(rate);
765 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
767 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
778 lookup_audio_lang_option(const GValue *rate)
782 const gchar *result = "Same as source";
784 // Coincidentally, the string "source" will return 0
785 // which is our flag to use "same as source"
786 str = ghb_value_string(rate);
787 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
789 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
791 result = ghb_language_table[ii].eng_name;
800 get_acodec_value(gint val)
802 GValue *value = NULL;
805 for (ii = 0; ii < acodec_opts.count; ii++)
807 if (acodec_opts.map[ii].ivalue == val)
809 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
818 get_abitrate_value(gint val)
820 GValue *value = NULL;
823 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
825 if (hb_audio_bitrates[ii].rate == val)
827 value = ghb_string_value_new(hb_audio_bitrates[ii].string);
836 get_amix_value(gint val)
838 GValue *value = NULL;
841 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
843 if (hb_audio_mixdowns[ii].amixdown == val)
845 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
852 // Handle for libhb. Gets set by ghb_backend_init()
853 static hb_handle_t * h_scan = NULL;
854 static hb_handle_t * h_queue = NULL;
856 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
863 hb_get_tempory_directory(h_scan, dir);
864 return g_strdup(dir);
868 ghb_hb_cleanup(gboolean partial)
872 hb_get_tempory_directory(h_scan, dir);
873 del_tree(dir, !partial);
877 ghb_get_title_number(gint titleindex)
882 if (h_scan == NULL) return 1;
883 list = hb_get_titles( h_scan );
884 if( !hb_list_count( list ) )
886 /* No valid title, stop right there */
889 title = hb_list_item( list, titleindex );
890 if (title == NULL) return 1; // Bad titleindex
894 static hb_audio_config_t*
895 get_hb_audio(gint titleindex, gint track)
899 hb_audio_config_t *audio = NULL;
901 if (h_scan == NULL) return NULL;
902 list = hb_get_titles( h_scan );
903 if( !hb_list_count( list ) )
905 /* No valid title, stop right there */
908 title = hb_list_item( list, titleindex );
909 if (title == NULL) return NULL; // Bad titleindex
910 if (!hb_list_count(title->list_audio))
914 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
919 search_rates(hb_rate_t *rates, gint rate, gint count)
922 for (ii = 0; ii < count; ii++)
924 if (rates[ii].rate == rate)
930 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
933 get_combo_box_store(GtkBuilder *builder, const gchar *name)
938 g_debug("get_combo_box_store() %s\n", name);
939 // First modify the combobox model to allow greying out of options
940 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
941 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
946 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
951 store = get_combo_box_store(builder, name);
952 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
954 gtk_list_store_set(store, &iter,
961 ghb_grey_combo_options(GtkBuilder *builder)
964 gint container, track, titleindex, acodec;
965 hb_audio_config_t *audio = NULL;
968 widget = GHB_WIDGET (builder, "title");
969 gval = ghb_widget_value(widget);
970 titleindex = ghb_lookup_combo_int("title", gval);
971 ghb_value_free(gval);
972 widget = GHB_WIDGET (builder, "AudioTrack");
973 gval = ghb_widget_value(widget);
974 track = ghb_lookup_combo_int("AudioTrack", gval);
975 ghb_value_free(gval);
976 audio = get_hb_audio(titleindex, track);
977 widget = GHB_WIDGET (builder, "FileFormat");
978 gval = ghb_widget_value(widget);
979 container = ghb_lookup_combo_int("FileFormat", gval);
980 ghb_value_free(gval);
982 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
983 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
984 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
985 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
987 gboolean allow_ac3 = TRUE;
988 allow_ac3 = (container != HB_MUX_OGM);
992 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
996 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
998 if (audio && audio->in.codec != HB_ACODEC_AC3)
1000 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1002 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1004 widget = GHB_WIDGET (builder, "AudioEncoder");
1005 gval = ghb_widget_value(widget);
1006 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1007 ghb_value_free(gval);
1008 if (acodec != HB_ACODEC_AC3)
1010 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1012 if (container == HB_MUX_MP4)
1014 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1015 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1016 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1018 else if (container == HB_MUX_AVI)
1020 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1021 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1022 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1024 else if (container == HB_MUX_OGM)
1026 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1029 gboolean allow_mono = TRUE;
1030 gboolean allow_stereo = TRUE;
1031 gboolean allow_dolby = TRUE;
1032 gboolean allow_dpl2 = TRUE;
1033 gboolean allow_6ch = TRUE;
1037 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1038 (acodec != HB_ACODEC_LAME);
1039 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1041 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1043 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1044 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1045 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1046 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1048 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1049 (acodec != HB_ACODEC_LAME) &&
1050 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1051 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1053 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1054 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1055 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1056 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1057 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1061 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1063 hb_audio_config_t *audio = NULL;
1064 gboolean allow_mono = TRUE;
1065 gboolean allow_stereo = TRUE;
1066 gboolean allow_dolby = TRUE;
1067 gboolean allow_dpl2 = TRUE;
1068 gboolean allow_6ch = TRUE;
1070 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1072 // Audio codec pass-thru. No mixdown
1075 audio = get_hb_audio(titleindex, track);
1079 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1080 (acodec != HB_ACODEC_LAME);
1081 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1083 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1085 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1086 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1087 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1088 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1090 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1091 (acodec != HB_ACODEC_LAME) &&
1092 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1093 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1095 gboolean greater = FALSE;
1098 // If no mix is specified, select the best available.
1099 mix = HB_AMIXDOWN_6CH;
1101 if (mix == HB_AMIXDOWN_6CH)
1104 if (allow_6ch) return HB_AMIXDOWN_6CH;
1106 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1109 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1111 if (mix == HB_AMIXDOWN_DOLBY || greater)
1114 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1116 if (mix == HB_AMIXDOWN_STEREO || greater)
1119 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1121 if (mix == HB_AMIXDOWN_MONO || greater)
1124 if (allow_mono) return HB_AMIXDOWN_MONO;
1126 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1127 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1128 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1129 if (allow_6ch) return HB_AMIXDOWN_6CH;
1133 // Set up the model for the combo box
1135 init_combo_box(GtkBuilder *builder, const gchar *name)
1138 GtkListStore *store;
1139 GtkCellRenderer *cell;
1141 g_debug("init_combo_box() %s\n", name);
1142 // First modify the combobox model to allow greying out of options
1143 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1145 // 1 - String to display
1146 // 2 - bool indicating whether the entry is selectable (grey or not)
1147 // 3 - String that is used for presets
1148 // 4 - Int value determined by backend
1149 // 5 - String value determined by backend
1150 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1151 G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1152 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1154 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1156 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1157 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1158 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1159 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1160 "text", 0, "sensitive", 1, NULL);
1163 { // Combo box entry
1164 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1169 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1172 GtkListStore *store;
1175 g_debug("audio_samplerate_opts_set ()\n");
1176 store = get_combo_box_store(builder, name);
1177 gtk_list_store_clear(store);
1178 // Add an item for "Same As Source"
1179 gtk_list_store_append(store, &iter);
1180 gtk_list_store_set(store, &iter,
1181 0, "Same as source",
1187 for (ii = 0; ii < count; ii++)
1189 gtk_list_store_append(store, &iter);
1190 gtk_list_store_set(store, &iter,
1191 0, rates[ii].string,
1193 2, rates[ii].string,
1195 4, rates[ii].string,
1201 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1204 GtkListStore *store;
1207 g_debug("video_rate_opts_set ()\n");
1208 store = get_combo_box_store(builder, name);
1209 gtk_list_store_clear(store);
1210 // Add an item for "Same As Source"
1211 gtk_list_store_append(store, &iter);
1212 gtk_list_store_set(store, &iter,
1213 0, "Same as source",
1219 for (ii = 0; ii < count; ii++)
1223 if (strcmp(rates[ii].string, "23.976") == 0)
1225 desc = "(NTSC Film)";
1227 else if (strcmp(rates[ii].string, "25") == 0)
1229 desc = "(PAL Film/Video)";
1231 else if (strcmp(rates[ii].string, "29.97") == 0)
1233 desc = "(NTSC Video)";
1235 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1236 gtk_list_store_append(store, &iter);
1237 gtk_list_store_set(store, &iter,
1240 2, rates[ii].string,
1242 4, rates[ii].string,
1249 mix_opts_set(GtkBuilder *builder, const gchar *name)
1252 GtkListStore *store;
1255 g_debug("mix_opts_set ()\n");
1256 store = get_combo_box_store(builder, name);
1257 gtk_list_store_clear(store);
1258 gtk_list_store_append(store, &iter);
1259 gtk_list_store_set(store, &iter,
1266 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1268 gtk_list_store_append(store, &iter);
1269 gtk_list_store_set(store, &iter,
1270 0, hb_audio_mixdowns[ii].human_readable_name,
1272 2, hb_audio_mixdowns[ii].short_name,
1273 3, hb_audio_mixdowns[ii].amixdown,
1274 4, hb_audio_mixdowns[ii].internal_name,
1280 language_opts_set(GtkBuilder *builder, const gchar *name)
1283 GtkListStore *store;
1286 g_debug("language_opts_set ()\n");
1287 store = get_combo_box_store(builder, name);
1288 gtk_list_store_clear(store);
1289 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1291 gtk_list_store_append(store, &iter);
1292 gtk_list_store_set(store, &iter,
1293 0, ghb_language_table[ii].eng_name,
1295 2, ghb_language_table[ii].iso639_2,
1297 4, ghb_language_table[ii].iso639_1,
1302 static gchar **titles = NULL;
1305 title_opts_set(GtkBuilder *builder, const gchar *name)
1308 GtkListStore *store;
1309 hb_list_t * list = NULL;
1310 hb_title_t * title = NULL;
1314 g_debug("title_opts_set ()\n");
1315 store = get_combo_box_store(builder, name);
1316 gtk_list_store_clear(store);
1319 list = hb_get_titles( h_scan );
1320 count = hb_list_count( list );
1321 if (count > 100) count = 100;
1323 if (titles) g_strfreev(titles);
1324 if (title_opts.map) g_free(title_opts.map);
1327 title_opts.count = count;
1328 title_opts.map = g_malloc(count*sizeof(options_map_t));
1329 titles = g_malloc((count+1) * sizeof(gchar*));
1333 title_opts.count = 1;
1334 title_opts.map = g_malloc(sizeof(options_map_t));
1339 // No titles. Fill in a default.
1340 gtk_list_store_append(store, &iter);
1341 gtk_list_store_set(store, &iter,
1348 title_opts.map[0].option = "No Titles";
1349 title_opts.map[0].shortOpt = "none";
1350 title_opts.map[0].ivalue = -1;
1351 title_opts.map[0].svalue = "none";
1354 for (ii = 0; ii < count; ii++)
1356 title = (hb_title_t*)hb_list_item(list, ii);
1357 if (title->duration != 0)
1359 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1360 title->index, title->hours, title->minutes, title->seconds);
1364 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1366 gtk_list_store_append(store, &iter);
1367 gtk_list_store_set(store, &iter,
1374 title_opts.map[ii].option = titles[ii];
1375 title_opts.map[ii].shortOpt = titles[ii];
1376 title_opts.map[ii].ivalue = ii;
1377 title_opts.map[ii].svalue = titles[ii];
1383 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1386 gboolean foundit = FALSE;
1388 if (gtk_tree_model_get_iter_first (store, iter))
1392 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1393 if (value == ivalue)
1398 } while (gtk_tree_model_iter_next (store, iter));
1404 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1407 GtkListStore *store;
1408 hb_list_t * list = NULL;
1409 hb_title_t * title = NULL;
1410 hb_audio_config_t * audio;
1414 g_debug("audio_track_opts_set ()\n");
1415 store = get_combo_box_store(builder, name);
1416 gtk_list_store_clear(store);
1419 list = hb_get_titles( h_scan );
1420 title = (hb_title_t*)hb_list_item( list, titleindex );
1423 count = hb_list_count( title->list_audio );
1426 if (count > 10) count = 10;
1427 if (audio_track_opts.map) g_free(audio_track_opts.map);
1430 audio_track_opts.count = count;
1431 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1435 audio_track_opts.count = 1;
1436 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1440 // No audio. set some default
1441 gtk_list_store_append(store, &iter);
1442 gtk_list_store_set(store, &iter,
1449 audio_track_opts.map[0].option = "No Audio";
1450 audio_track_opts.map[0].shortOpt = "none";
1451 audio_track_opts.map[0].ivalue = -1;
1452 audio_track_opts.map[0].svalue = "none";
1455 for (ii = 0; ii < count; ii++)
1457 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1458 gtk_list_store_append(store, &iter);
1459 gtk_list_store_set(store, &iter,
1460 0, audio->lang.description,
1466 audio_track_opts.map[ii].option = audio->lang.description,
1467 audio_track_opts.map[ii].shortOpt = index_str[ii];
1468 audio_track_opts.map[ii].ivalue = ii;
1469 audio_track_opts.map[ii].svalue = index_str[ii];
1475 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1478 GtkListStore *store;
1479 hb_list_t * list = NULL;
1480 hb_title_t * title = NULL;
1481 hb_subtitle_t * subtitle;
1485 g_debug("subtitle_opts_set () %s\n", name);
1486 store = get_combo_box_store(builder, name);
1487 gtk_list_store_clear(store);
1490 list = hb_get_titles( h_scan );
1491 title = (hb_title_t*)hb_list_item( list, titleindex );
1494 count = hb_list_count( title->list_subtitle );
1497 if (count > 10) count = 10;
1498 if (subtitle_opts.map) g_free(subtitle_opts.map);
1501 subtitle_opts.count = count+2;
1502 subtitle_opts.map = g_malloc((count+2)*sizeof(options_map_t));
1506 subtitle_opts.count = LANG_TABLE_SIZE+2;
1507 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+2)*sizeof(options_map_t));
1509 // Add options for "none" and "autoselect"
1510 gtk_list_store_append(store, &iter);
1511 gtk_list_store_set(store, &iter,
1518 subtitle_opts.map[0].option = "None";
1519 subtitle_opts.map[0].shortOpt = "none";
1520 subtitle_opts.map[0].ivalue = -2;
1521 subtitle_opts.map[0].svalue = "none";
1522 gtk_list_store_append(store, &iter);
1523 gtk_list_store_set(store, &iter,
1530 subtitle_opts.map[0].option = "Same as audio";
1531 subtitle_opts.map[0].shortOpt = "auto";
1532 subtitle_opts.map[0].ivalue = -1;
1533 subtitle_opts.map[0].svalue = "auto";
1536 for (ii = 0; ii < count; ii++)
1538 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1539 gtk_list_store_append(store, &iter);
1540 gtk_list_store_set(store, &iter,
1543 2, subtitle->iso639_2,
1545 4, subtitle->iso639_2,
1547 subtitle_opts.map[ii+2].option = subtitle->lang;
1548 subtitle_opts.map[ii+2].shortOpt = subtitle->iso639_2;
1549 subtitle_opts.map[ii+2].ivalue = ii;
1550 subtitle_opts.map[ii+2].svalue = subtitle->iso639_2;
1555 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1557 gtk_list_store_append(store, &iter);
1558 gtk_list_store_set(store, &iter,
1559 0, ghb_language_table[ii].eng_name,
1561 2, ghb_language_table[ii].iso639_2,
1563 4, ghb_language_table[ii].iso639_2,
1565 subtitle_opts.map[ii+2].option = ghb_language_table[ii].eng_name;
1566 subtitle_opts.map[ii+2].shortOpt = ghb_language_table[ii].iso639_2;
1567 subtitle_opts.map[ii+2].ivalue = ii;
1568 subtitle_opts.map[ii+2].svalue = ghb_language_table[ii].iso639_2;
1580 guint64 longest = 0;
1581 gint titleindex = 0;
1583 g_debug("ghb_longest_title ()\n");
1584 if (h_scan == NULL) return 0;
1585 list = hb_get_titles( h_scan );
1586 count = hb_list_count( list );
1587 if (count > 100) count = 100;
1588 for (ii = 0; ii < count; ii++)
1590 title = (hb_title_t*)hb_list_item(list, ii);
1591 if (title->duration > longest)
1594 longest = title->duration;
1601 ghb_find_audio_track(gint titleindex, const gchar *lang, gint index)
1605 hb_audio_config_t * audio;
1611 g_debug("find_audio_track ()\n");
1614 list = hb_get_titles( h_scan );
1615 title = (hb_title_t*)hb_list_item( list, titleindex );
1618 count = hb_list_count( title->list_audio );
1621 if (count > 10) count = 10;
1622 for (ii = 0; ii < count; ii++)
1624 audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii );
1625 if ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1626 (strcmp(lang, "und") == 0))
1636 if (match) return track;
1643 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1646 GtkListStore *store;
1649 g_debug("generic_opts_set ()\n");
1650 if (name == NULL || opts == NULL) return;
1651 store = get_combo_box_store(builder, name);
1652 gtk_list_store_clear(store);
1653 for (ii = 0; ii < opts->count; ii++)
1655 gtk_list_store_append(store, &iter);
1656 gtk_list_store_set(store, &iter,
1657 0, opts->map[ii].option,
1659 2, opts->map[ii].shortOpt,
1660 3, opts->map[ii].ivalue,
1661 4, opts->map[ii].svalue,
1667 find_combo_table(const gchar *name)
1671 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1673 if (strcmp(name, combo_name_map[ii].name) == 0)
1675 return combo_name_map[ii].opts;
1682 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
1684 if (strcmp(name, "AudioBitrate") == 0)
1685 return lookup_audio_bitrate_int(gval);
1686 else if (strcmp(name, "AudioSamplerate") == 0)
1687 return lookup_audio_rate_int(gval);
1688 else if (strcmp(name, "VideoFramerate") == 0)
1689 return lookup_video_rate_int(gval);
1690 else if (strcmp(name, "AudioMixdown") == 0)
1691 return lookup_mix_int(gval);
1692 else if (strcmp(name, "SourceAudioLang") == 0)
1693 return lookup_audio_lang_int(gval);
1696 return lookup_generic_int(find_combo_table(name), gval);
1698 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1703 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
1705 if (strcmp(name, "AudioBitrate") == 0)
1706 return lookup_audio_bitrate_option(gval);
1707 else if (strcmp(name, "AudioSamplerate") == 0)
1708 return lookup_audio_rate_option(gval);
1709 else if (strcmp(name, "VideoFramerate") == 0)
1710 return lookup_video_rate_option(gval);
1711 else if (strcmp(name, "AudioMixdown") == 0)
1712 return lookup_mix_option(gval);
1713 else if (strcmp(name, "SourceAudioLang") == 0)
1714 return lookup_audio_lang_option(gval);
1717 return lookup_generic_option(find_combo_table(name), gval);
1719 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1724 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1726 GtkComboBox *combo = NULL;
1728 gint handler_id = 0;
1730 g_debug("ghb_update_ui_combo_box() %s\n", name);
1733 // Clearing a combo box causes a rash of "changed" events, even when
1734 // the active item is -1 (inactive). To control things, I'm disabling
1735 // the event till things are settled down.
1736 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1737 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1740 // Valid signal id found. This should always succeed.
1741 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1742 signal_id, 0, 0, 0, 0);
1745 // This should also always succeed
1746 g_signal_handler_block ((gpointer)combo, handler_id);
1752 audio_bitrate_opts_set(builder, "AudioBitrate");
1753 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1754 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1755 mix_opts_set(builder, "AudioMixdown");
1756 language_opts_set(builder, "SourceAudioLang");
1757 subtitle_opts_set(builder, "Subtitles", user_data);
1758 title_opts_set(builder, "title");
1759 audio_track_opts_set(builder, "AudioTrack", user_data);
1760 generic_opts_set(builder, "LoggingLevel", &logging_opts);
1761 generic_opts_set(builder, "FileFormat", &container_opts);
1762 generic_opts_set(builder, "PictureDeinterlace", &deint_opts);
1763 generic_opts_set(builder, "tweak_PictureDeinterlace", &deint_opts);
1764 generic_opts_set(builder, "PictureDenoise", &denoise_opts);
1765 generic_opts_set(builder, "tweak_PictureDenoise", &denoise_opts);
1766 generic_opts_set(builder, "VideoEncoder", &vcodec_opts);
1767 generic_opts_set(builder, "AudioEncoder", &acodec_opts);
1768 generic_opts_set(builder, "x264_direct", &direct_opts);
1769 generic_opts_set(builder, "x264_me", &me_opts);
1770 generic_opts_set(builder, "x264_subme", &subme_opts);
1771 generic_opts_set(builder, "x264_analyse", &analyse_opts);
1772 generic_opts_set(builder, "x264_trellis", &trellis_opts);
1776 if (strcmp(name, "AudioBitrate") == 0)
1777 audio_bitrate_opts_set(builder, "AudioBitrate");
1778 else if (strcmp(name, "AudioSamplerate") == 0)
1779 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1780 else if (strcmp(name, "VideoFramerate") == 0)
1781 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1782 else if (strcmp(name, "AudioMixdown") == 0)
1783 mix_opts_set(builder, "AudioMixdown");
1784 else if (strcmp(name, "SourceAudioLang") == 0)
1785 language_opts_set(builder, "SourceAudioLang");
1786 else if (strcmp(name, "Subtitles") == 0)
1787 subtitle_opts_set(builder, "Subtitles", user_data);
1788 else if (strcmp(name, "title") == 0)
1789 title_opts_set(builder, "title");
1790 else if (strcmp(name, "AudioTrack") == 0)
1791 audio_track_opts_set(builder, "AudioTrack", user_data);
1793 generic_opts_set(builder, name, find_combo_table(name));
1797 g_signal_handler_unblock ((gpointer)combo, handler_id);
1802 init_ui_combo_boxes(GtkBuilder *builder)
1806 init_combo_box(builder, "AudioBitrate");
1807 init_combo_box(builder, "AudioSamplerate");
1808 init_combo_box(builder, "VideoFramerate");
1809 init_combo_box(builder, "AudioMixdown");
1810 init_combo_box(builder, "SourceAudioLang");
1811 init_combo_box(builder, "Subtitles");
1812 init_combo_box(builder, "title");
1813 init_combo_box(builder, "AudioTrack");
1814 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1816 init_combo_box(builder, combo_name_map[ii].name);
1820 static const char * turbo_opts =
1821 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
1822 "no-fast-pskip=0:8x8dct=0:weightb=0";
1824 // Construct the x264 options string
1825 // The result is allocated, so someone must free it at some point.
1827 ghb_build_x264opts_string(GValue *settings)
1830 gchar *opts = ghb_settings_get_string(settings, "x264Option");
1837 result = g_strdup("");
1843 ghb_get_chapters(gint titleindex)
1847 hb_chapter_t * chapter;
1849 GValue *chapters = NULL;
1851 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
1852 if (h_scan == NULL) return NULL;
1853 list = hb_get_titles( h_scan );
1854 title = (hb_title_t*)hb_list_item( list, titleindex );
1855 if (title == NULL) return NULL;
1856 count = hb_list_count( title->list_chapter );
1857 chapters = ghb_array_value_new(count);
1858 for (ii = 0; ii < count; ii++)
1860 chapter = hb_list_item(title->list_chapter, ii);
1861 if (chapter == NULL) break;
1862 if (chapter->title == NULL || chapter->title[0] == 0)
1865 str = g_strdup_printf ("Chapter %2d", ii+1);
1866 ghb_array_append(chapters, ghb_string_value_new(str));
1871 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
1878 ghb_ac3_in_audio_list(const GValue *audio_list)
1882 count = ghb_array_len(audio_list);
1883 for (ii = 0; ii < count; ii++)
1888 asettings = ghb_array_get_nth(audio_list, ii);
1889 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
1890 if (acodec == HB_ACODEC_AC3)
1897 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
1900 GtkListStore *store;
1903 g_debug("audio_rate_opts_add ()\n");
1904 store = get_combo_box_store(builder, name);
1905 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
1907 str = g_strdup_printf ("%d", rate);
1908 gtk_list_store_append(store, &iter);
1909 gtk_list_store_set(store, &iter,
1921 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
1924 GtkListStore *store;
1926 gboolean done = FALSE;
1928 guint last = (guint)last_rate;
1930 g_debug("audio_bitrate_opts_clean ()\n");
1931 store = get_combo_box_store(builder, name);
1932 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
1936 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
1938 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
1940 done = !gtk_list_store_remove(store, &iter);
1942 else if (ivalue > last)
1945 gtk_list_store_set(store, &iter, 1, FALSE, -1);
1946 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
1951 gtk_list_store_set(store, &iter, 1, TRUE, -1);
1952 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
1959 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
1962 GtkListStore *store;
1965 g_debug("audio_bitrate_opts_set ()\n");
1966 store = get_combo_box_store(builder, name);
1967 gtk_list_store_clear(store);
1968 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1970 gtk_list_store_append(store, &iter);
1971 gtk_list_store_set(store, &iter,
1972 0, hb_audio_bitrates[ii].string,
1974 2, hb_audio_bitrates[ii].string,
1975 3, hb_audio_bitrates[ii].rate,
1976 4, hb_audio_bitrates[ii].string,
1982 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
1984 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
1988 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
1990 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
1993 static ghb_status_t hb_status;
1996 ghb_combo_init(GtkBuilder *builder)
1998 // Set up the list model for the combos
1999 init_ui_combo_boxes(builder);
2000 // Populate all the combos
2001 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
2005 ghb_backend_init(gint debug)
2008 h_scan = hb_init( debug, 0 );
2009 h_queue = hb_init( debug, 0 );
2020 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2022 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2023 hb_status.scan.state |= GHB_STATE_SCANNING;
2024 // initialize count and cur to something that won't cause FPE
2025 // when computing progress
2026 hb_status.scan.title_count = 1;
2027 hb_status.scan.title_cur = 0;
2031 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2033 g_debug("ghb_backend_queue_scan()");
2034 hb_scan( h_queue, path, titlenum, 10, 0 );
2035 hb_status.queue.state |= GHB_STATE_SCANNING;
2039 ghb_get_scan_state()
2041 return hb_status.scan.state;
2045 ghb_get_queue_state()
2047 return hb_status.queue.state;
2051 ghb_clear_scan_state(gint state)
2053 hb_status.scan.state &= ~state;
2057 ghb_clear_queue_state(gint state)
2059 hb_status.queue.state &= ~state;
2063 ghb_set_scan_state(gint state)
2065 hb_status.scan.state |= state;
2069 ghb_set_queue_state(gint state)
2071 hb_status.queue.state |= state;
2075 ghb_get_status(ghb_status_t *status)
2077 memcpy(status, &hb_status, sizeof(ghb_status_t));
2086 if (h_scan == NULL) return;
2087 hb_get_state( h_scan, &s_scan );
2088 switch( s_scan.state )
2090 #define p s_scan.param.scanning
2091 case HB_STATE_SCANNING:
2093 hb_status.scan.state |= GHB_STATE_SCANNING;
2094 hb_status.scan.title_count = p.title_count;
2095 hb_status.scan.title_cur = p.title_cur;
2099 case HB_STATE_SCANDONE:
2101 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2102 hb_status.scan.state |= GHB_STATE_SCANDONE;
2105 #define p s_scan.param.working
2106 case HB_STATE_WORKING:
2107 hb_status.scan.state |= GHB_STATE_WORKING;
2108 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2109 hb_status.scan.job_cur = p.job_cur;
2110 hb_status.scan.job_count = p.job_count;
2111 hb_status.scan.progress = p.progress;
2112 hb_status.scan.rate_cur = p.rate_cur;
2113 hb_status.scan.rate_avg = p.rate_avg;
2114 hb_status.scan.hours = p.hours;
2115 hb_status.scan.minutes = p.minutes;
2116 hb_status.scan.seconds = p.seconds;
2117 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2121 case HB_STATE_PAUSED:
2122 hb_status.scan.state |= GHB_STATE_PAUSED;
2125 case HB_STATE_MUXING:
2127 hb_status.scan.state |= GHB_STATE_MUXING;
2130 #define p s_scan.param.workdone
2131 case HB_STATE_WORKDONE:
2135 hb_status.scan.state |= GHB_STATE_WORKDONE;
2136 hb_status.scan.state &= ~GHB_STATE_MUXING;
2137 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2138 hb_status.scan.state &= ~GHB_STATE_WORKING;
2142 hb_status.scan.error = GHB_ERROR_NONE;
2144 case HB_ERROR_CANCELED:
2145 hb_status.scan.error = GHB_ERROR_CANCELED;
2148 hb_status.scan.error = GHB_ERROR_FAIL;
2151 // Delete all remaining jobs of this encode.
2152 // An encode can be composed of multiple associated jobs.
2153 // When a job is stopped, libhb removes it from the job list,
2154 // but does not remove other jobs that may be associated with it.
2155 // Associated jobs are taged in the sequence id.
2156 while ((job = hb_job(h_scan, 0)) != NULL)
2157 hb_rem( h_scan, job );
2161 hb_get_state( h_queue, &s_queue );
2162 switch( s_queue.state )
2164 #define p s_queue.param.scanning
2165 case HB_STATE_SCANNING:
2167 hb_status.queue.state |= GHB_STATE_SCANNING;
2168 hb_status.queue.title_count = p.title_count;
2169 hb_status.queue.title_cur = p.title_cur;
2173 case HB_STATE_SCANDONE:
2175 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2176 hb_status.queue.state |= GHB_STATE_SCANDONE;
2179 #define p s_queue.param.working
2180 case HB_STATE_WORKING:
2181 hb_status.queue.state |= GHB_STATE_WORKING;
2182 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2183 hb_status.queue.job_cur = p.job_cur;
2184 hb_status.queue.job_count = p.job_count;
2185 hb_status.queue.progress = p.progress;
2186 hb_status.queue.rate_cur = p.rate_cur;
2187 hb_status.queue.rate_avg = p.rate_avg;
2188 hb_status.queue.hours = p.hours;
2189 hb_status.queue.minutes = p.minutes;
2190 hb_status.queue.seconds = p.seconds;
2191 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2195 case HB_STATE_PAUSED:
2196 hb_status.queue.state |= GHB_STATE_PAUSED;
2199 case HB_STATE_MUXING:
2201 hb_status.queue.state |= GHB_STATE_MUXING;
2204 #define p s_queue.param.workdone
2205 case HB_STATE_WORKDONE:
2209 hb_status.queue.state |= GHB_STATE_WORKDONE;
2210 hb_status.queue.state &= ~GHB_STATE_MUXING;
2211 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2212 hb_status.queue.state &= ~GHB_STATE_WORKING;
2216 hb_status.queue.error = GHB_ERROR_NONE;
2218 case HB_ERROR_CANCELED:
2219 hb_status.queue.error = GHB_ERROR_CANCELED;
2222 hb_status.queue.error = GHB_ERROR_FAIL;
2225 // Delete all remaining jobs of this encode.
2226 // An encode can be composed of multiple associated jobs.
2227 // When a job is stopped, libhb removes it from the job list,
2228 // but does not remove other jobs that may be associated with it.
2229 // Associated jobs are taged in the sequence id.
2230 while ((job = hb_job(h_queue, 0)) != NULL)
2231 hb_rem( h_queue, job );
2238 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2243 if (h_scan == NULL) return FALSE;
2244 list = hb_get_titles( h_scan );
2245 if( !hb_list_count( list ) )
2247 /* No valid title, stop right there */
2251 title = hb_list_item( list, titleindex );
2252 if (title == NULL) return FALSE; // Bad titleindex
2253 tinfo->width = title->width;
2254 tinfo->height = title->height;
2255 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2256 // Don't allow crop to 0
2257 if (title->crop[0] + title->crop[1] >= title->height)
2258 title->crop[0] = title->crop[1] = 0;
2259 if (title->crop[2] + title->crop[3] >= title->width)
2260 title->crop[2] = title->crop[3] = 0;
2261 tinfo->num_chapters = hb_list_count(title->list_chapter);
2262 tinfo->rate_base = title->rate_base;
2263 tinfo->rate = title->rate;
2264 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2265 title->width * title->pixel_aspect_width,
2266 title->height * title->pixel_aspect_height);
2267 tinfo->hours = title->hours;
2268 tinfo->minutes = title->minutes;
2269 tinfo->seconds = title->seconds;
2270 tinfo->duration = title->duration;
2275 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2277 hb_audio_config_t *audio;
2279 audio = get_hb_audio(titleindex, audioindex);
2280 if (audio == NULL) return FALSE; // Bad audioindex
2281 ainfo->codec = audio->in.codec;
2282 ainfo->bitrate = audio->in.bitrate;
2283 ainfo->samplerate = audio->in.samplerate;
2288 ghb_audio_is_passthru(gint acodec)
2290 g_debug("ghb_audio_is_passthru () \n");
2291 g_debug("acodec %d\n", acodec);
2292 return (acodec == HB_ACODEC_AC3);
2296 ghb_get_default_acodec()
2298 return HB_ACODEC_FAAC;
2302 ghb_set_scale(signal_user_data_t *ud, gint mode)
2307 gboolean keep_aspect, round_dims, anamorphic;
2308 gboolean autocrop, autoscale, noscale;
2309 gint crop[4], width, height, par_width, par_height;
2310 gint crop_width, crop_height;
2311 gint aspect_n, aspect_d;
2312 gboolean keep_width = (mode == GHB_SCALE_KEEP_WIDTH);
2313 gboolean keep_height = (mode == GHB_SCALE_KEEP_HEIGHT);
2319 gint max_height = 0;
2321 g_debug("ghb_set_scale ()\n");
2323 if (h_scan == NULL) return;
2324 list = hb_get_titles( h_scan );
2325 if( !hb_list_count( list ) )
2327 /* No valid title, stop right there */
2332 titleindex = ghb_settings_combo_int(ud->settings, "title");
2333 title = hb_list_item( list, titleindex );
2334 if (title == NULL) return;
2336 if (job == NULL) return;
2338 // First configure widgets
2339 round_dims = ghb_settings_get_boolean(ud->settings, "ModDimensions");
2340 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
2341 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2342 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2343 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2344 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2345 // alignment constraints rather than scaling to satisfy them.
2346 noscale = ghb_settings_get_boolean(ud->settings, "noscale");
2347 // Align dimensions to either 16 or 2 pixels
2348 // The scaler crashes if the dimensions are not divisible by 2
2349 // x264 also will not accept dims that are not multiple of 2
2350 modshift = round_dims ? 4 : 1;
2351 modround = round_dims ? 8 : 1;
2355 keep_height = FALSE;
2357 if (anamorphic || keep_aspect)
2359 keep_height = FALSE;
2361 // Step needs to be at least 2 because odd widths cause scaler crash
2362 step = round_dims ? 16 : 2;
2363 widget = GHB_WIDGET (ud->builder, "scale_width");
2364 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2365 widget = GHB_WIDGET (ud->builder, "scale_height");
2366 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2369 ghb_title_info_t tinfo;
2371 if (ghb_get_title_info (&tinfo, titleindex))
2373 crop[0] = tinfo.crop[0];
2374 crop[1] = tinfo.crop[1];
2375 crop[2] = tinfo.crop[2];
2376 crop[3] = tinfo.crop[3];
2381 // Adjust the cropping to accomplish the desired width and height
2382 crop_width = tinfo.width - crop[2] - crop[3];
2383 crop_height = tinfo.height - crop[0] - crop[1];
2384 width = (crop_width >> modshift) << modshift;
2385 height = (crop_height >> modshift) << modshift;
2386 need1 = (crop_height - height) / 2;
2387 need2 = crop_height - height - need1;
2390 need1 = (crop_width - width) / 2;
2391 need2 = crop_width - width - need1;
2395 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2396 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2397 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2398 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2401 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2402 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2403 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2404 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2405 hb_reduce(&aspect_n, &aspect_d,
2406 title->width * title->pixel_aspect_width,
2407 title->height * title->pixel_aspect_height);
2408 crop_width = title->width - crop[2] - crop[3];
2409 crop_height = title->height - crop[0] - crop[1];
2413 height = crop_height;
2419 width = ghb_settings_get_int(ud->settings, "scale_width");
2420 height = ghb_settings_get_int(ud->settings, "scale_height");
2421 max_width = ghb_settings_get_int(ud->settings, "PictureWidth");
2422 max_height = ghb_settings_get_int(ud->settings, "PictureHeight");
2424 max_width = (max_width >> modshift) << modshift;
2425 max_height = (max_height >> modshift) << modshift;
2426 // Adjust dims according to max values
2429 max_height = crop_height;
2433 max_width = crop_width;
2435 height = MIN(height, max_height);
2436 width = MIN(width, max_width);
2437 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2440 width = title->width - crop[2] - crop[3];
2442 height = title->height - crop[0] - crop[1];
2452 // The scaler crashes if the dimensions are not divisible by 2
2453 // Align mod 2. And so does something in x264_encoder_headers()
2458 job->maxHeight = max_height;
2459 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2460 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2461 hb_set_anamorphic_size( job, &width, &height,
2462 &par_width, &par_height );
2469 gint new_width, new_height;
2471 g_debug("kw %s kh %s\n", keep_width ? "y":"n", keep_height ? "y":"n");
2472 g_debug("w %d h %d\n", width, height);
2473 // Compute pixel aspect ration.
2474 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2475 // Must scale so that par becomes 1:1
2476 // Try to keep largest dimension
2477 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2478 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2479 // Height and width are always multiples of 2, so do the rounding
2480 new_height = ((new_height + 1) >> 1) << 1;
2481 new_width = ((new_width + 1) >> 1) << 1;
2482 if ((max_width && new_width > max_width) ||
2483 new_width > title->width)
2485 height = new_height;
2487 else if ((max_height && new_height > max_height) ||
2488 new_height > title->height)
2492 else if (keep_width)
2494 height = new_height;
2496 else if (keep_height)
2500 else if (width > new_width)
2502 height = new_height;
2508 g_debug("new w %d h %d\n", width, height);
2510 width = ((width + modround) >> modshift) << modshift;
2511 height = ((height + modround) >> modshift) << modshift;
2513 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2514 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2518 set_preview_job_settings(hb_job_t *job, GValue *settings)
2520 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
2521 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
2522 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
2523 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
2525 gboolean anamorphic, round_dimensions;
2526 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
2527 round_dimensions = ghb_settings_get_boolean(settings, "ModDimensions");
2528 if (round_dimensions && anamorphic)
2531 job->pixel_ratio = 2;
2533 else if (anamorphic)
2536 job->pixel_ratio = 2;
2541 job->pixel_ratio = 0;
2543 job->width = ghb_settings_get_int(settings, "scale_width");
2544 job->height = ghb_settings_get_int(settings, "scale_height");
2545 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
2546 gboolean decomb = ghb_settings_get_boolean(settings, "PictureDecomb");
2547 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2551 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2558 if (h_scan == NULL) return 1500;
2559 list = hb_get_titles( h_scan );
2560 title = hb_list_item( list, titleindex );
2561 if (title == NULL) return 1500;
2563 if (job == NULL) return 1500;
2564 size = ghb_settings_get_int(settings, "VideoTargetSize");
2565 return hb_calc_bitrate( job, size );
2569 ghb_validate_filter_string(const gchar *str, gint max_fields)
2575 if (str == NULL || *str == 0) return TRUE;
2578 val = g_strtod(str, &end);
2580 { // Found a numeric value
2582 // negative max_fields means infinate
2583 if (max_fields >= 0 && fields > max_fields) return FALSE;
2597 ghb_validate_filters(signal_user_data_t *ud)
2605 tweaks = ghb_settings_get_boolean(ud->settings, "allow_tweaks");
2609 str = ghb_settings_get_string(ud->settings, "tweak_PictureDetelecine");
2610 enabled = ghb_settings_get_boolean(ud->settings, "PictureDetelecine");
2611 if (enabled && !ghb_validate_filter_string(str, 6))
2613 message = g_strdup_printf(
2614 "Invalid Detelecine Settings:\n\n%s\n",
2616 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2623 str = ghb_settings_get_string(ud->settings, "tweak_PictureDecomb");
2624 enabled = ghb_settings_get_boolean(ud->settings, "PictureDecomb");
2625 if (enabled && !ghb_validate_filter_string(str, 7))
2627 message = g_strdup_printf(
2628 "Invalid Decomb Settings:\n\n%s\n",
2630 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2637 index = ghb_lookup_combo_int("tweak_PictureDeinterlace",
2638 ghb_settings_get_value(ud->settings, "tweak_PictureDeinterlace"));
2641 str = ghb_settings_get_string(ud->settings, "tweak_PictureDeinterlace");
2642 if (!ghb_validate_filter_string(str, 4))
2644 message = g_strdup_printf(
2645 "Invalid Deinterlace Settings:\n\n%s\n",
2647 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2655 index = ghb_lookup_combo_int("tweak_PictureDenoise",
2656 ghb_settings_get_value(ud->settings, "tweak_PictureDenoise"));
2659 str = ghb_settings_get_string(ud->settings, "tweak_PictureDenoise");
2660 if (!ghb_validate_filter_string(str, 4))
2662 message = g_strdup_printf(
2663 "Invalid Denoise Settings:\n\n%s\n",
2665 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2677 ghb_validate_video(signal_user_data_t *ud)
2682 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2683 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
2684 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
2685 (vcodec == HB_VCODEC_THEORA))
2687 // mp4|avi/theora combination is not supported.
2688 message = g_strdup_printf(
2689 "Theora is not supported in the MP4 and AVI containers.\n\n"
2690 "You should choose a different video codec or container.\n"
2691 "If you continue, XviD will be chosen for you.");
2692 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2698 vcodec = HB_VCODEC_XVID;
2699 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
2705 ghb_validate_audio(signal_user_data_t *ud)
2712 if (h_scan == NULL) return FALSE;
2713 list = hb_get_titles( h_scan );
2714 if( !hb_list_count( list ) )
2716 /* No valid title, stop right there */
2717 g_message("No title found.\n");
2723 titleindex = ghb_settings_combo_int(ud->settings, "title");
2724 title = hb_list_item( list, titleindex );
2725 if (title == NULL) return FALSE;
2726 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2728 const GValue *audio_list;
2731 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2732 count = ghb_array_len(audio_list);
2733 for (ii = 0; ii < count; ii++)
2736 hb_audio_config_t *taudio;
2738 asettings = ghb_array_get_nth(audio_list, ii);
2739 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
2740 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
2741 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
2742 title->list_audio, track );
2743 if ((taudio->in.codec != HB_ACODEC_AC3) && (codec == HB_ACODEC_AC3))
2745 // Not supported. AC3 is passthrough only, so input must be AC3
2746 message = g_strdup_printf(
2747 "The source does not support AC3 Pass-Thru.\n\n"
2748 "You should choose a different audio codec.\n"
2749 "If you continue, one will be chosen for you.");
2750 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2756 if (mux == HB_MUX_AVI)
2758 codec = HB_ACODEC_LAME;
2762 codec = HB_ACODEC_FAAC;
2764 value = get_acodec_value(codec);
2765 ghb_settings_take_value(asettings, "AudioEncoder", value);
2767 gchar *a_unsup = NULL;
2768 gchar *mux_s = NULL;
2769 if (mux == HB_MUX_MP4)
2772 // mp4/mp3|vorbis combination is not supported.
2773 if (codec == HB_ACODEC_LAME)
2776 codec = HB_ACODEC_FAAC;
2778 if (codec == HB_ACODEC_VORBIS)
2781 codec = HB_ACODEC_FAAC;
2784 else if (mux == HB_MUX_AVI)
2787 // avi/faac|vorbis combination is not supported.
2788 if (codec == HB_ACODEC_FAAC)
2791 codec = HB_ACODEC_LAME;
2793 if (codec == HB_ACODEC_VORBIS)
2796 codec = HB_ACODEC_LAME;
2799 else if (mux == HB_MUX_OGM)
2802 // avi/faac|vorbis combination is not supported.
2803 if (codec == HB_ACODEC_FAAC)
2806 codec = HB_ACODEC_VORBIS;
2808 if (codec == HB_ACODEC_AC3)
2811 codec = HB_ACODEC_VORBIS;
2816 message = g_strdup_printf(
2817 "%s is not supported in the %s container.\n\n"
2818 "You should choose a different audio codec.\n"
2819 "If you continue, one will be chosen for you.", a_unsup, mux_s);
2820 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2826 value = get_acodec_value(codec);
2827 ghb_settings_take_value(asettings, "AudioEncoder", value);
2829 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
2830 gboolean allow_mono = TRUE;
2831 gboolean allow_stereo = TRUE;
2832 gboolean allow_dolby = TRUE;
2833 gboolean allow_dpl2 = TRUE;
2834 gboolean allow_6ch = TRUE;
2836 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2837 (codec != HB_ACODEC_LAME);
2838 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2840 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
2842 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
2843 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
2844 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
2845 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
2847 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2848 (codec != HB_ACODEC_LAME) &&
2849 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
2850 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
2852 gchar *mix_unsup = NULL;
2853 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
2857 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
2859 mix_unsup = "stereo";
2861 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
2863 mix_unsup = "Dolby";
2865 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
2867 mix_unsup = "Dolby Pro Logic II";
2869 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
2871 mix_unsup = "6 Channel";
2875 message = g_strdup_printf(
2876 "The source audio does not support %s mixdown.\n\n"
2877 "You should choose a different mixdown.\n"
2878 "If you continue, one will be chosen for you.", mix_unsup);
2879 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2885 mix = ghb_get_best_mix(titleindex, track, codec, mix);
2886 value = get_amix_value(mix);
2887 ghb_settings_take_value(asettings, "AudioMixdown", value);
2894 ghb_validate_vquality(GValue *settings)
2900 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
2901 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
2903 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
2904 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
2906 if (!ghb_settings_get_boolean(settings, "directqp"))
2909 if (vcodec != HB_VCODEC_X264)
2922 if (vcodec == HB_VCODEC_X264)
2927 else if (vcodec == HB_VCODEC_FFMPEG)
2939 if (vquality < min || vquality > max)
2941 message = g_strdup_printf(
2942 "Interesting video quality choise: %d\n\n"
2943 "Typical values range from %d to %d.\n"
2944 "Are you sure you wish to use this setting?",
2945 (gint)vquality, min, max);
2946 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
2947 "Cancel", "Continue"))
2959 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
2964 static gchar *x264opts;
2966 gboolean tweaks = FALSE;
2967 gchar *detel_str = NULL;
2968 gchar *decomb_str = NULL;
2969 gchar *deint_str = NULL;
2970 gchar *deblock_str = NULL;
2971 gchar *denoise_str = NULL;
2972 gchar *dest_str = NULL;
2974 g_debug("add_job()\n");
2975 if (h == NULL) return;
2976 list = hb_get_titles( h );
2977 if( !hb_list_count( list ) )
2979 /* No valid title, stop right there */
2983 title = hb_list_item( list, titleindex );
2984 if (title == NULL) return;
2986 /* Set job settings */
2988 if (job == NULL) return;
2990 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
2991 if (job->start_at_preview)
2993 job->seek_points = ghb_settings_get_int(js, "preview_count");
2994 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
2997 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
2998 job->mux = ghb_settings_combo_int(js, "FileFormat");
2999 if (job->mux == HB_MUX_MP4)
3001 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3002 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3006 job->largeFileSize = FALSE;
3007 job->mp4_optimize = FALSE;
3009 if (!job->start_at_preview)
3011 gint chapter_start, chapter_end;
3012 chapter_start = ghb_settings_get_int(js, "start_chapter");
3013 chapter_end = ghb_settings_get_int(js, "end_chapter");
3014 gint num_chapters = hb_list_count(title->list_chapter);
3015 job->chapter_start = MIN( num_chapters, chapter_start );
3016 job->chapter_end = MAX( job->chapter_start, chapter_end );
3018 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3019 if ( job->chapter_markers )
3026 chapters = ghb_settings_get_value(js, "chapter_list");
3027 count = ghb_array_len(chapters);
3028 for(chap = chapter_start; chap <= chapter_end; chap++)
3030 hb_chapter_t * chapter_s;
3036 chapter = ghb_array_get_nth(chapters, chap-1);
3037 name = ghb_value_string(chapter);
3041 name = g_strdup_printf ("Chapter %2d", chap);
3043 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3044 strncpy(chapter_s->title, name, 1023);
3045 chapter_s->title[1023] = '\0';
3050 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3051 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3052 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3053 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3056 gboolean decomb = ghb_settings_get_boolean(js, "PictureDecomb");
3057 gint deint = ghb_settings_combo_int(js,
3058 tweaks ? "tweak_PictureDeinterlace":"PictureDeinterlace");
3060 job->deinterlace = (deint != 0) ? 1 : 0;
3062 job->deinterlace = 0;
3063 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3065 gboolean anamorphic = ghb_settings_get_boolean(js, "anamorphic");
3066 gboolean round_dimensions = ghb_settings_get_boolean(js, "ModDimensions");
3067 if (round_dimensions && anamorphic)
3069 job->pixel_ratio = 2;
3072 else if (anamorphic)
3074 // Huh! I thought I wanted to use pixel_ratio 1 for this case, but
3075 // when its 1, libhb discards the width and height and uses original
3076 // title dims - crop. Thats not what I want.
3077 // Also, x264 requires things to divisible by 2.
3078 job->pixel_ratio = 2;
3083 job->pixel_ratio = 0;
3086 /* Add selected filters */
3087 job->filters = hb_list_init();
3088 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3089 if( vrate == 0 && ghb_settings_get_boolean(js, "PictureDetelecine" ) )
3094 if( ghb_settings_get_boolean(js, "PictureDetelecine" ) )
3096 hb_filter_detelecine.settings = NULL;
3099 detel_str = ghb_settings_get_string(js, "tweak_PictureDetelecine");
3100 if (detel_str && detel_str[0])
3102 hb_filter_detelecine.settings = detel_str;
3105 hb_list_add( job->filters, &hb_filter_detelecine );
3109 // Use default settings
3110 hb_filter_decomb.settings = NULL;
3113 decomb_str = ghb_settings_get_string(js, "tweak_PictureDecomb");
3114 if (decomb_str && decomb_str[0])
3116 hb_filter_decomb.settings = (gchar*)decomb_str;
3119 hb_list_add( job->filters, &hb_filter_decomb );
3121 if( job->deinterlace )
3124 deint_str = g_strdup(deint_opts.map[deint].svalue);
3126 deint_str = ghb_settings_get_string(js,
3127 tweaks ? "tweak_PictureDeinterlace" : "PictureDeinterlace");
3128 hb_filter_deinterlace.settings = deint_str;
3129 hb_list_add( job->filters, &hb_filter_deinterlace );
3131 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3134 deblock_str = g_strdup_printf("%d", deblock);
3135 hb_filter_deblock.settings = deblock_str;
3136 hb_list_add( job->filters, &hb_filter_deblock );
3138 gint denoise = ghb_settings_combo_int(js,
3139 tweaks ? "tweak_PictureDenoise" : "PictureDenoise");
3143 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3145 denoise_str = (gchar*)ghb_settings_get_string(
3146 js, tweaks ? "tweak_PictureDenoise" : "PictureDenoise");
3147 hb_filter_denoise.settings = denoise_str;
3148 hb_list_add( job->filters, &hb_filter_denoise );
3150 job->width = ghb_settings_get_int(js, "scale_width");
3151 job->height = ghb_settings_get_int(js, "scale_height");
3153 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3154 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3155 (job->vcodec == HB_VCODEC_THEORA))
3157 // mp4|avi/theora combination is not supported.
3158 job->vcodec = HB_VCODEC_XVID;
3160 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3162 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3164 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3167 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3168 if (!ghb_settings_get_boolean(js, "directqp"))
3170 if (vquality == 0.0) vquality = 0.01;
3171 if (vquality == 1.0) vquality = 0.0;
3173 job->vquality = vquality;
3176 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3178 job->vquality = -1.0;
3179 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3181 // AVI container does not support variable frame rate.
3182 if (job->mux == HB_MUX_AVI)
3190 job->vrate = title->rate;
3191 job->vrate_base = title->rate_base;
3196 job->vrate = 27000000;
3197 job->vrate_base = vrate;
3200 // First remove any audios that are already in the list
3201 // This happens if you are encoding the same title a second time.
3202 gint num_audio_tracks = hb_list_count(job->list_audio);
3204 for(ii = 0; ii < num_audio_tracks; ii++)
3206 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3207 hb_list_rem(job->list_audio, audio);
3210 const GValue *audio_list;
3214 audio_list = ghb_settings_get_value(js, "audio_list");
3215 count = ghb_array_len(audio_list);
3216 for (ii = 0; ii < count; ii++)
3219 hb_audio_config_t audio;
3220 hb_audio_config_t *taudio;
3222 hb_audio_config_init(&audio);
3223 asettings = ghb_array_get_nth(audio_list, ii);
3224 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3225 audio.out.track = tcount;
3226 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3227 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3228 title->list_audio, audio.in.track );
3229 if ((taudio->in.codec != HB_ACODEC_AC3) && (audio.out.codec == HB_ACODEC_AC3))
3231 // Not supported. AC3 is passthrough only, so input must be AC3
3232 if (job->mux == HB_MUX_AVI)
3234 audio.out.codec = HB_ACODEC_LAME;
3238 printf("switching to faac\n");
3239 audio.out.codec = HB_ACODEC_FAAC;
3242 if ((job->mux == HB_MUX_MP4) &&
3243 ((audio.out.codec == HB_ACODEC_LAME) ||
3244 (audio.out.codec == HB_ACODEC_VORBIS)))
3246 // mp4/mp3|vorbis combination is not supported.
3247 audio.out.codec = HB_ACODEC_FAAC;
3249 if ((job->mux == HB_MUX_AVI) &&
3250 ((audio.out.codec == HB_ACODEC_FAAC) ||
3251 (audio.out.codec == HB_ACODEC_VORBIS)))
3253 // avi/faac|vorbis combination is not supported.
3254 audio.out.codec = HB_ACODEC_LAME;
3256 if ((job->mux == HB_MUX_OGM) &&
3257 ((audio.out.codec == HB_ACODEC_FAAC) ||
3258 (audio.out.codec == HB_ACODEC_AC3)))
3260 // ogm/faac|ac3 combination is not supported.
3261 audio.out.codec = HB_ACODEC_VORBIS;
3263 audio.out.dynamic_range_compression =
3264 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3265 // It would be better if this were done in libhb for us, but its not yet.
3266 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3268 audio.out.mixdown = 0;
3272 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3273 // Make sure the mixdown is valid and pick a new one if not.
3274 audio.out.mixdown = ghb_get_best_mix(titleindex,
3275 audio.in.track, audio.out.codec, audio.out.mixdown);
3277 ghb_settings_combo_int(asettings, "AudioBitrate");
3278 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3279 if (srate == 0) // 0 is same as source
3280 audio.out.samplerate = taudio->in.samplerate;
3282 audio.out.samplerate = srate;
3285 // Add it to the jobs audio list
3286 hb_audio_add( job, &audio );
3289 // I was tempted to move this up with the reset of the video quality
3290 // settings, but I suspect the settings above need to be made
3291 // first in order for hb_calc_bitrate to be accurate.
3292 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3296 size = ghb_settings_get_int(js, "VideoTargetSize");
3297 job->vbitrate = hb_calc_bitrate( job, size );
3298 job->vquality = -1.0;
3301 dest_str = ghb_settings_get_string(js, "destination");
3302 job->file = dest_str;
3303 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3304 // TODO: libhb holds onto a reference to the x264opts and is not
3305 // finished with it until encoding the job is done. But I can't
3306 // find a way to get at the job before it is removed in order to
3307 // free up the memory I am allocating here.
3308 // The short story is THIS LEAKS.
3309 x264opts = ghb_build_x264opts_string(js);
3311 if( x264opts != NULL && *x264opts != '\0' )
3313 job->x264opts = x264opts;
3315 else /*avoids a bus error crash when options aren't specified*/
3317 job->x264opts = NULL;
3320 gchar *slang = ghb_settings_get_string(js, "Subtitles");
3321 subtitle = -2; // default to none
3322 if (strcmp(slang, "auto") == 0)
3329 hb_subtitle_t * subt;
3331 scount = hb_list_count(title->list_subtitle);
3332 for (ii = 0; ii < scount; ii++)
3334 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
3335 if (strcmp(slang, subt->iso639_2) == 0)
3342 gboolean forced_subtitles = ghb_settings_get_boolean(js, "SubtitlesForced");
3343 job->subtitle_force = forced_subtitles;
3345 job->subtitle = subtitle;
3350 // Subtitle scan. Look for subtitle matching audio language
3354 * When subtitle scan is enabled do a fast pre-scan job
3355 * which will determine which subtitles to enable, if any.
3358 job->indepth_scan = 1;
3360 x264opts_tmp = job->x264opts;
3361 job->x264opts = NULL;
3363 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3364 *(job->select_subtitle) = NULL;
3367 * Add the pre-scan job
3369 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3371 //if (job->x264opts != NULL)
3372 // g_free(job->x264opts);
3374 job->x264opts = x264opts_tmp;
3378 job->select_subtitle = NULL;
3380 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
3381 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3384 * If subtitle_scan is enabled then only turn it on
3385 * for the second pass and then off again for the
3388 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3389 job->select_subtitle = NULL;
3391 job->indepth_scan = 0;
3392 gchar *x264opts2 = NULL;
3395 x264opts2 = g_strdup(x264opts);
3398 * If turbo options have been selected then append them
3399 * to the x264opts now (size includes one ':' and the '\0')
3401 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
3407 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3413 * No x264opts to modify, but apply the turbo options
3414 * anyway as they may be modifying defaults
3416 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3418 x264opts = tmp_x264opts;
3420 job->x264opts = x264opts;
3422 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3424 //if (job->x264opts != NULL)
3425 // g_free(job->x264opts);
3427 job->select_subtitle = subtitle_tmp;
3430 * On the second pass we turn off subtitle scan so that we
3431 * can actually encode using any subtitles that were auto
3432 * selected in the first pass (using the whacky select-subtitle
3433 * attribute of the job).
3435 job->indepth_scan = 0;
3436 job->x264opts = x264opts2;
3437 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3439 //if (job->x264opts != NULL)
3440 // g_free(job->x264opts);
3444 job->indepth_scan = 0;
3446 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3448 //if (job->x264opts != NULL)
3449 // g_free(job->x264opts);
3451 if (detel_str) g_free(detel_str);
3452 if (decomb_str) g_free(decomb_str);
3453 if (deint_str) g_free(deint_str);
3454 if (deblock_str) g_free(deblock_str);
3455 if (denoise_str) g_free(denoise_str);
3456 if (dest_str) g_free(dest_str);
3460 ghb_add_job(GValue *js, gint unique_id)
3462 // Since I'm doing a scan of the single title I want just prior
3463 // to adding the job, there is only the one title to choose from.
3464 add_job(h_queue, js, unique_id, 0);
3468 ghb_add_live_job(GValue *js, gint unique_id)
3470 // Since I'm doing a scan of the single title I want just prior
3471 // to adding the job, there is only the one title to choose from.
3472 gint titleindex = ghb_settings_combo_int(js, "title");
3473 add_job(h_scan, js, unique_id, titleindex);
3477 ghb_remove_job(gint unique_id)
3482 // Multiples passes all get the same id
3484 // Go backwards through list, so reordering doesn't screw me.
3485 ii = hb_count(h_queue) - 1;
3486 while ((job = hb_job(h_queue, ii--)) != NULL)
3488 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3489 hb_rem(h_queue, job);
3496 hb_start( h_queue );
3506 ghb_start_live_encode()
3512 ghb_stop_live_encode()
3521 hb_get_state2( h_queue, &s );
3523 if( s.state == HB_STATE_PAUSED )
3525 hb_resume( h_queue );
3529 hb_pause( h_queue );
3533 #define RED_HEIGHT 720.0
3534 #define RED_WIDTH 1280.0
3537 ghb_get_preview_image(
3540 signal_user_data_t *ud,
3549 settings = ud->settings;
3550 list = hb_get_titles( h_scan );
3551 if( !hb_list_count( list ) )
3553 /* No valid title, stop right there */
3556 title = hb_list_item( list, titleindex );
3557 if (title == NULL) return NULL;
3558 if (title->job == NULL) return NULL;
3559 set_preview_job_settings(title->job, settings);
3561 // hb_get_preview can't handle sizes that are larger than the original title
3563 if (title->job->width > title->width)
3564 title->job->width = title->width;
3566 if (title->job->height > title->height)
3567 title->job->height = title->height;
3568 // And also creates artifacts if the width is not a multiple of 8
3569 //title->job->width = ((title->job->width + 4) >> 3) << 3;
3570 // And the height must be a multiple of 2
3571 //title->job->height = ((title->job->height + 1) >> 1) << 1;
3573 // Make sure we have a big enough buffer to receive the image from libhb. libhb
3574 // creates images with a one-pixel border around the original content. Hence we
3575 // add 2 pixels horizontally and vertically to the buffer size.
3576 gint srcWidth = title->width + 2;
3577 gint srcHeight= title->height + 2;
3578 gint dstWidth = title->width;
3579 gint dstHeight= title->height;
3581 gint borderLeft = 1;
3584 // |<---------- title->width ----------->|
3585 // | |<---- title->job->width ---->| |
3587 // .......................................
3588 // ....+-----------------------------+....
3589 // ....| |....<-- gray border
3592 // ....| |<------- image
3598 // ....+-----------------------------+....
3599 // .......................................
3600 dstWidth = title->job->width;
3601 dstHeight = title->job->height;
3602 borderTop = (srcHeight - dstHeight) / 2;
3603 borderLeft = (srcWidth - dstWidth) / 2;
3604 g_debug("boarders removed\n");
3607 g_debug("src %d x %d\n", srcWidth, srcHeight);
3608 g_debug("dst %d x %d\n", dstWidth, dstHeight);
3609 g_debug("job dim %d x %d\n", title->job->width, title->job->height);
3610 g_debug("title crop %d:%d:%d:%d\n",
3615 g_debug("job crop %d:%d:%d:%d\n",
3616 title->job->crop[0],
3617 title->job->crop[1],
3618 title->job->crop[2],
3619 title->job->crop[3]);
3620 static guint8 *buffer = NULL;
3621 static gint bufferSize = 0;
3624 newSize = srcWidth * srcHeight * 4;
3625 if( bufferSize < newSize )
3627 bufferSize = newSize;
3628 buffer = (guint8*) g_realloc( buffer, bufferSize );
3630 hb_get_preview( h_scan, title, index, buffer );
3632 // Create an GdkPixbuf and copy the libhb image into it, converting it from
3633 // libhb's format something suitable. Along the way, we'll strip off the
3634 // border around libhb's image.
3636 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
3637 // Alpha is ignored.
3639 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
3640 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
3642 guint32 *src = (guint32*)buffer;
3643 guint8 *dst = pixels;
3644 src += borderTop * srcWidth; // skip top rows in src to get to first row of dst
3645 src += borderLeft; // skip left pixels in src to get to first pixel of dst
3647 gint channels = gdk_pixbuf_get_n_channels (preview);
3648 gint stride = gdk_pixbuf_get_rowstride (preview);
3650 for (ii = 0; ii < dstHeight; ii++)
3653 for (jj = 0; jj < dstWidth; jj++)
3655 tmp[0] = src[0] >> 16;
3656 tmp[1] = src[0] >> 8;
3657 tmp[2] = src[0] >> 0;
3662 src += (srcWidth - dstWidth); // skip to next row in src
3664 // Got it, but hb_get_preview doesn't compensate for anamorphic, so lets
3666 gint width, height, par_width, par_height;
3667 gboolean anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
3670 hb_set_anamorphic_size( title->job, &width, &height, &par_width, &par_height );
3671 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
3675 ghb_par_scale(ud, &dstWidth, &dstHeight, 1, 1);
3677 *out_width = dstWidth;
3678 *out_height = dstHeight;
3679 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
3685 ss = gdk_screen_get_default();
3686 s_w = gdk_screen_get_width(ss);
3687 s_h = gdk_screen_get_height(ss);
3688 num = dstWidth * par_width;
3689 den = dstHeight * par_height;
3691 if (dstWidth > s_w * 80 / 100)
3693 dstWidth = s_w * 80 / 100;
3694 dstHeight = dstWidth * den / num;
3696 if (dstHeight > s_h * 80 / 100)
3698 dstHeight = s_h * 80 / 100;
3699 dstWidth = dstHeight * num / den;
3702 g_debug("scaled %d x %d\n", dstWidth, dstHeight);
3703 GdkPixbuf *scaled_preview;
3704 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
3705 g_object_unref (preview);
3706 return scaled_preview;
3710 sanitize_volname(gchar *name)
3735 ghb_dvd_volname(const gchar *device)
3738 name = hb_dvd_name((gchar*)device);
3741 sanitize_volname(name);
3742 return g_strdup(name);