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"
40 const gchar *shortOpt;
51 static const gchar *index_str[] =
66 static options_map_t d_container_opts[] =
68 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
69 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
70 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
71 {"AVI", "avi", HB_MUX_AVI, "avi"},
72 {"OGM", "ogm", HB_MUX_OGM, "ogm"},
74 combo_opts_t container_opts =
76 sizeof(d_container_opts)/sizeof(options_map_t),
80 static options_map_t d_deint_opts[] =
82 {"None", "none", 0, ""},
83 {"Fast", "fast", 1, "-1:-1:-1:0:1"},
84 {"Slow", "slow", 2, "2:-1:-1:0:1"},
85 {"Slower", "slower", 3, "0:-1:-1:0:1"},
87 combo_opts_t deint_opts =
89 sizeof(d_deint_opts)/sizeof(options_map_t),
93 static options_map_t d_denoise_opts[] =
95 {"None", "none", 0, ""},
96 {"Weak", "weak", 1, "2:1:2:3"},
97 {"Medium", "medium", 2, "3:2:2:3"},
98 {"Strong", "strong", 3, "7:7:5:5"},
100 combo_opts_t denoise_opts =
102 sizeof(d_denoise_opts)/sizeof(options_map_t),
106 static options_map_t d_vcodec_opts[] =
108 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
109 {"MPEG-4 (XviD)", "xvid", HB_VCODEC_XVID, ""},
110 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
111 {"Theora", "theora", HB_VCODEC_THEORA, ""},
113 combo_opts_t vcodec_opts =
115 sizeof(d_vcodec_opts)/sizeof(options_map_t),
119 static options_map_t d_acodec_opts[] =
121 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
122 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
123 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
124 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
126 combo_opts_t acodec_opts =
128 sizeof(d_acodec_opts)/sizeof(options_map_t),
132 static options_map_t d_direct_opts[] =
134 {"None", "none", 0, "none"},
135 {"Spatial", "spatial", 1, "spatial"},
136 {"Temporal", "temporal", 2, "temporal"},
137 {"Automatic", "auto", 3, "auto"},
139 combo_opts_t direct_opts =
141 sizeof(d_direct_opts)/sizeof(options_map_t),
145 static options_map_t d_me_opts[] =
147 {"Diamond", "dia", 0, "dia"},
148 {"Hexagon", "hex", 1, "hex"},
149 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
150 {"Exhaustive", "esa", 3, "esa"},
152 combo_opts_t me_opts =
154 sizeof(d_me_opts)/sizeof(options_map_t),
158 static options_map_t d_subme_opts[] =
170 combo_opts_t subme_opts =
172 sizeof(d_subme_opts)/sizeof(options_map_t),
176 static options_map_t d_analyse_opts[] =
178 {"Some", "some", 0, "some"},
179 {"None", "none", 1, "none"},
180 {"All", "all", 2, "all"},
181 {"Custom", "custom", 3, "all"},
183 combo_opts_t analyse_opts =
185 sizeof(d_analyse_opts)/sizeof(options_map_t),
189 static options_map_t d_trellis_opts[] =
191 {"Disabled", "0", 0, "0"},
192 {"Final Macro Block", "1", 1, "1"},
193 {"Always", "2", 2, "2"},
195 combo_opts_t trellis_opts =
197 sizeof(d_trellis_opts)/sizeof(options_map_t),
201 combo_opts_t subtitle_opts =
207 combo_opts_t title_opts =
213 combo_opts_t audio_track_opts =
225 combo_name_map_t combo_name_map[] =
227 {"FileFormat", &container_opts},
228 {"PictureDeinterlace", &deint_opts},
229 {"tweak_PictureDeinterlace", &deint_opts},
230 {"PictureDenoise", &denoise_opts},
231 {"tweak_PictureDenoise", &denoise_opts},
232 {"VideoEncoder", &vcodec_opts},
233 {"AudioEncoder", &acodec_opts},
234 {"x264_direct", &direct_opts},
235 {"x264_me", &me_opts},
236 {"x264_subme", &subme_opts},
237 {"x264_analyse", &analyse_opts},
238 {"x264_trellis", &trellis_opts},
239 {"Subtitles", &subtitle_opts},
240 {"title", &title_opts},
241 {"AudioTrack", &audio_track_opts},
246 typedef struct iso639_lang_t
248 char * eng_name; /* Description in English */
249 char * native_name; /* Description in native language */
250 char * iso639_1; /* ISO-639-1 (2 characters) code */
251 char * iso639_2; /* ISO-639-2/t (3 character) code */
252 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
256 const iso639_lang_t ghb_language_table[] =
258 { "Any", "", "zz", "und" },
259 { "Afar", "", "aa", "aar" },
260 { "Abkhazian", "", "ab", "abk" },
261 { "Afrikaans", "", "af", "afr" },
262 { "Akan", "", "ak", "aka" },
263 { "Albanian", "", "sq", "sqi", "alb" },
264 { "Amharic", "", "am", "amh" },
265 { "Arabic", "", "ar", "ara" },
266 { "Aragonese", "", "an", "arg" },
267 { "Armenian", "", "hy", "hye", "arm" },
268 { "Assamese", "", "as", "asm" },
269 { "Avaric", "", "av", "ava" },
270 { "Avestan", "", "ae", "ave" },
271 { "Aymara", "", "ay", "aym" },
272 { "Azerbaijani", "", "az", "aze" },
273 { "Bashkir", "", "ba", "bak" },
274 { "Bambara", "", "bm", "bam" },
275 { "Basque", "", "eu", "eus", "baq" },
276 { "Belarusian", "", "be", "bel" },
277 { "Bengali", "", "bn", "ben" },
278 { "Bihari", "", "bh", "bih" },
279 { "Bislama", "", "bi", "bis" },
280 { "Bosnian", "", "bs", "bos" },
281 { "Breton", "", "br", "bre" },
282 { "Bulgarian", "", "bg", "bul" },
283 { "Burmese", "", "my", "mya", "bur" },
284 { "Catalan", "", "ca", "cat" },
285 { "Chamorro", "", "ch", "cha" },
286 { "Chechen", "", "ce", "che" },
287 { "Chinese", "", "zh", "zho", "chi" },
288 { "Church Slavic", "", "cu", "chu" },
289 { "Chuvash", "", "cv", "chv" },
290 { "Cornish", "", "kw", "cor" },
291 { "Corsican", "", "co", "cos" },
292 { "Cree", "", "cr", "cre" },
293 { "Czech", "", "cs", "ces", "cze" },
294 { "Danish", "Dansk", "da", "dan" },
295 { "Divehi", "", "dv", "div" },
296 { "Dutch", "Nederlands", "nl", "nld", "dut" },
297 { "Dzongkha", "", "dz", "dzo" },
298 { "English", "English", "en", "eng" },
299 { "Esperanto", "", "eo", "epo" },
300 { "Estonian", "", "et", "est" },
301 { "Ewe", "", "ee", "ewe" },
302 { "Faroese", "", "fo", "fao" },
303 { "Fijian", "", "fj", "fij" },
304 { "Finnish", "Suomi", "fi", "fin" },
305 { "French", "Francais", "fr", "fra", "fre" },
306 { "Western Frisian", "", "fy", "fry" },
307 { "Fulah", "", "ff", "ful" },
308 { "Georgian", "", "ka", "kat", "geo" },
309 { "German", "Deutsch", "de", "deu", "ger" },
310 { "Gaelic (Scots)", "", "gd", "gla" },
311 { "Irish", "", "ga", "gle" },
312 { "Galician", "", "gl", "glg" },
313 { "Manx", "", "gv", "glv" },
314 { "Greek, Modern", "", "el", "ell", "gre" },
315 { "Guarani", "", "gn", "grn" },
316 { "Gujarati", "", "gu", "guj" },
317 { "Haitian", "", "ht", "hat" },
318 { "Hausa", "", "ha", "hau" },
319 { "Hebrew", "", "he", "heb" },
320 { "Herero", "", "hz", "her" },
321 { "Hindi", "", "hi", "hin" },
322 { "Hiri Motu", "", "ho", "hmo" },
323 { "Hungarian", "Magyar", "hu", "hun" },
324 { "Igbo", "", "ig", "ibo" },
325 { "Icelandic", "Islenska", "is", "isl", "ice" },
326 { "Ido", "", "io", "ido" },
327 { "Sichuan Yi", "", "ii", "iii" },
328 { "Inuktitut", "", "iu", "iku" },
329 { "Interlingue", "", "ie", "ile" },
330 { "Interlingua", "", "ia", "ina" },
331 { "Indonesian", "", "id", "ind" },
332 { "Inupiaq", "", "ik", "ipk" },
333 { "Italian", "Italiano", "it", "ita" },
334 { "Javanese", "", "jv", "jav" },
335 { "Japanese", "", "ja", "jpn" },
336 { "Kalaallisut", "", "kl", "kal" },
337 { "Kannada", "", "kn", "kan" },
338 { "Kashmiri", "", "ks", "kas" },
339 { "Kanuri", "", "kr", "kau" },
340 { "Kazakh", "", "kk", "kaz" },
341 { "Central Khmer", "", "km", "khm" },
342 { "Kikuyu", "", "ki", "kik" },
343 { "Kinyarwanda", "", "rw", "kin" },
344 { "Kirghiz", "", "ky", "kir" },
345 { "Komi", "", "kv", "kom" },
346 { "Kongo", "", "kg", "kon" },
347 { "Korean", "", "ko", "kor" },
348 { "Kuanyama", "", "kj", "kua" },
349 { "Kurdish", "", "ku", "kur" },
350 { "Lao", "", "lo", "lao" },
351 { "Latin", "", "la", "lat" },
352 { "Latvian", "", "lv", "lav" },
353 { "Limburgan", "", "li", "lim" },
354 { "Lingala", "", "ln", "lin" },
355 { "Lithuanian", "", "lt", "lit" },
356 { "Luxembourgish", "", "lb", "ltz" },
357 { "Luba-Katanga", "", "lu", "lub" },
358 { "Ganda", "", "lg", "lug" },
359 { "Macedonian", "", "mk", "mkd", "mac" },
360 { "Marshallese", "", "mh", "mah" },
361 { "Malayalam", "", "ml", "mal" },
362 { "Maori", "", "mi", "mri", "mao" },
363 { "Marathi", "", "mr", "mar" },
364 { "Malay", "", "ms", "msa", "msa" },
365 { "Malagasy", "", "mg", "mlg" },
366 { "Maltese", "", "mt", "mlt" },
367 { "Moldavian", "", "mo", "mol" },
368 { "Mongolian", "", "mn", "mon" },
369 { "Nauru", "", "na", "nau" },
370 { "Navajo", "", "nv", "nav" },
371 { "Ndebele, South", "", "nr", "nbl" },
372 { "Ndebele, North", "", "nd", "nde" },
373 { "Ndonga", "", "ng", "ndo" },
374 { "Nepali", "", "ne", "nep" },
375 { "Norwegian Nynorsk", "", "nn", "nno" },
376 { "Norwegian Bokmål", "", "nb", "nob" },
377 { "Norwegian", "Norsk", "no", "nor" },
378 { "Chichewa; Nyanja", "", "ny", "nya" },
379 { "Occitan", "", "oc", "oci" },
380 { "Ojibwa", "", "oj", "oji" },
381 { "Oriya", "", "or", "ori" },
382 { "Oromo", "", "om", "orm" },
383 { "Ossetian", "", "os", "oss" },
384 { "Panjabi", "", "pa", "pan" },
385 { "Persian", "", "fa", "fas", "per" },
386 { "Pali", "", "pi", "pli" },
387 { "Polish", "", "pl", "pol" },
388 { "Portuguese", "Portugues", "pt", "por" },
389 { "Pushto", "", "ps", "pus" },
390 { "Quechua", "", "qu", "que" },
391 { "Romansh", "", "rm", "roh" },
392 { "Romanian", "", "ro", "ron", "rum" },
393 { "Rundi", "", "rn", "run" },
394 { "Russian", "", "ru", "rus" },
395 { "Sango", "", "sg", "sag" },
396 { "Sanskrit", "", "sa", "san" },
397 { "Serbian", "", "sr", "srp", "scc" },
398 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
399 { "Sinhala", "", "si", "sin" },
400 { "Slovak", "", "sk", "slk", "slo" },
401 { "Slovenian", "", "sl", "slv" },
402 { "Northern Sami", "", "se", "sme" },
403 { "Samoan", "", "sm", "smo" },
404 { "Shona", "", "sn", "sna" },
405 { "Sindhi", "", "sd", "snd" },
406 { "Somali", "", "so", "som" },
407 { "Sotho, Southern", "", "st", "sot" },
408 { "Spanish", "Espanol", "es", "spa" },
409 { "Sardinian", "", "sc", "srd" },
410 { "Swati", "", "ss", "ssw" },
411 { "Sundanese", "", "su", "sun" },
412 { "Swahili", "", "sw", "swa" },
413 { "Swedish", "Svenska", "sv", "swe" },
414 { "Tahitian", "", "ty", "tah" },
415 { "Tamil", "", "ta", "tam" },
416 { "Tatar", "", "tt", "tat" },
417 { "Telugu", "", "te", "tel" },
418 { "Tajik", "", "tg", "tgk" },
419 { "Tagalog", "", "tl", "tgl" },
420 { "Thai", "", "th", "tha" },
421 { "Tibetan", "", "bo", "bod", "tib" },
422 { "Tigrinya", "", "ti", "tir" },
423 { "Tonga", "", "to", "ton" },
424 { "Tswana", "", "tn", "tsn" },
425 { "Tsonga", "", "ts", "tso" },
426 { "Turkmen", "", "tk", "tuk" },
427 { "Turkish", "", "tr", "tur" },
428 { "Twi", "", "tw", "twi" },
429 { "Uighur", "", "ug", "uig" },
430 { "Ukrainian", "", "uk", "ukr" },
431 { "Urdu", "", "ur", "urd" },
432 { "Uzbek", "", "uz", "uzb" },
433 { "Venda", "", "ve", "ven" },
434 { "Vietnamese", "", "vi", "vie" },
435 { "Volapük", "", "vo", "vol" },
436 { "Welsh", "", "cy", "cym", "wel" },
437 { "Walloon", "", "wa", "wln" },
438 { "Wolof", "", "wo", "wol" },
439 { "Xhosa", "", "xh", "xho" },
440 { "Yiddish", "", "yi", "yid" },
441 { "Yoruba", "", "yo", "yor" },
442 { "Zhuang", "", "za", "zha" },
443 { "Zulu", "", "zu", "zul" },
444 {NULL, NULL, NULL, NULL}
446 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
448 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
451 del_tree(const gchar *name, gboolean del_top)
455 if (g_file_test(name, G_FILE_TEST_IS_DIR))
457 GDir *gdir = g_dir_open(name, 0, NULL);
458 file = g_dir_read_name(gdir);
462 path = g_strdup_printf("%s/%s", name, file);
463 del_tree(path, TRUE);
465 file = g_dir_read_name(gdir);
485 signal_user_data_t *ud,
492 if (ghb_settings_get_boolean(ud->settings, "directqp"))
494 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
495 // Only x264 and ffmpeg currently support direct qp/crf entry
499 if (vcodec == HB_VCODEC_X264)
504 else if (vcodec == HB_VCODEC_FFMPEG)
529 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
535 str = ghb_value_string(gval);
536 for (ii = 0; ii < opts->count; ii++)
538 if (strcmp(opts->map[ii].shortOpt, str) == 0)
540 result = opts->map[ii].ivalue;
549 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
553 const gchar *result = "";
555 str = ghb_value_string(gval);
556 for (ii = 0; ii < opts->count; ii++)
558 if (strcmp(opts->map[ii].shortOpt, str) == 0)
560 result = opts->map[ii].option;
569 lookup_mix_int(const GValue *mix)
576 str = ghb_value_string(mix);
577 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
579 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
581 result = hb_audio_mixdowns[ii].amixdown;
590 lookup_mix_option(const GValue *mix)
594 gchar *result = "None";
597 str = ghb_value_string(mix);
598 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
600 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
602 result = hb_audio_mixdowns[ii].human_readable_name;
611 lookup_video_rate_int(const GValue *vrate)
617 str = ghb_value_string(vrate);
618 for (ii = 0; ii < hb_video_rates_count; ii++)
620 if (strcmp(hb_video_rates[ii].string, str) == 0)
622 result = hb_video_rates[ii].rate;
627 // Default to "same as source"
632 lookup_video_rate_option(const GValue *vrate)
636 const gchar *result = "Same as source";
638 str = ghb_value_string(vrate);
639 for (ii = 0; ii < hb_video_rates_count; ii++)
641 if (strcmp(hb_video_rates[ii].string, str) == 0)
643 result = hb_video_rates[ii].string;
648 // Default to "same as source"
653 lookup_audio_rate_int(const GValue *rate)
659 // Coincidentally, the string "source" will return 0
660 // which is our flag to use "same as source"
661 str = ghb_value_string(rate);
662 for (ii = 0; ii < hb_audio_rates_count; ii++)
664 if (strcmp(hb_audio_rates[ii].string, str) == 0)
666 result = hb_audio_rates[ii].rate;
675 lookup_audio_rate_option(const GValue *rate)
679 const gchar *result = "Same as source";
681 // Coincidentally, the string "source" will return 0
682 // which is our flag to use "same as source"
683 str = ghb_value_string(rate);
684 for (ii = 0; ii < hb_audio_rates_count; ii++)
686 if (strcmp(hb_audio_rates[ii].string, str) == 0)
688 result = hb_audio_rates[ii].string;
697 lookup_audio_bitrate_int(const GValue *rate)
703 // Coincidentally, the string "source" will return 0
704 // which is our flag to use "same as source"
705 str = ghb_value_string(rate);
706 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
708 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
710 result = hb_audio_bitrates[ii].rate;
719 lookup_audio_bitrate_option(const GValue *rate)
723 const gchar *result = "Same as source";
725 // Coincidentally, the string "source" will return 0
726 // which is our flag to use "same as source"
727 str = ghb_value_string(rate);
728 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
730 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
732 result = hb_audio_bitrates[ii].string;
741 lookup_audio_lang_int(const GValue *rate)
747 // Coincidentally, the string "source" will return 0
748 // which is our flag to use "same as source"
749 str = ghb_value_string(rate);
750 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
752 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
763 lookup_audio_lang_option(const GValue *rate)
767 const gchar *result = "Same as source";
769 // Coincidentally, the string "source" will return 0
770 // which is our flag to use "same as source"
771 str = ghb_value_string(rate);
772 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
774 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
776 result = ghb_language_table[ii].eng_name;
785 get_acodec_value(gint val)
787 GValue *value = NULL;
790 for (ii = 0; ii < acodec_opts.count; ii++)
792 if (acodec_opts.map[ii].ivalue == val)
794 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
802 get_abitrate_value(gint val)
804 GValue *value = NULL;
807 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
809 if (hb_audio_bitrates[ii].rate == val)
811 value = ghb_string_value_new(hb_audio_bitrates[ii].string);
819 get_amix_value(gint val)
821 GValue *value = NULL;
824 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
826 if (hb_audio_mixdowns[ii].amixdown == val)
828 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
835 // Handle for libhb. Gets set by ghb_backend_init()
836 static hb_handle_t * h_scan = NULL;
837 static hb_handle_t * h_queue = NULL;
839 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
842 ghb_hb_cleanup(gboolean partial)
846 hb_get_tempory_directory(h_scan, dir);
847 del_tree(dir, !partial);
851 ghb_get_title_number(gint titleindex)
856 if (h_scan == NULL) return 1;
857 list = hb_get_titles( h_scan );
858 if( !hb_list_count( list ) )
860 /* No valid title, stop right there */
863 title = hb_list_item( list, titleindex );
864 if (title == NULL) return 1; // Bad titleindex
868 static hb_audio_config_t*
869 get_hb_audio(gint titleindex, gint track)
873 hb_audio_config_t *audio = NULL;
875 if (h_scan == NULL) return NULL;
876 list = hb_get_titles( h_scan );
877 if( !hb_list_count( list ) )
879 /* No valid title, stop right there */
882 title = hb_list_item( list, titleindex );
883 if (title == NULL) return NULL; // Bad titleindex
884 if (!hb_list_count(title->list_audio))
888 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
893 search_rates(hb_rate_t *rates, gint rate, gint count)
896 for (ii = 0; ii < count; ii++)
898 if (rates[ii].rate == rate)
904 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
907 get_combo_box_store(GtkBuilder *builder, const gchar *name)
912 g_debug("get_combo_box_store() %s\n", name);
913 // First modify the combobox model to allow greying out of options
914 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
915 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
920 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
925 store = get_combo_box_store(builder, name);
926 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
928 gtk_list_store_set(store, &iter,
935 ghb_grey_combo_options(GtkBuilder *builder)
938 gint container, track, titleindex, acodec;
940 hb_audio_config_t *audio = NULL;
943 widget = GHB_WIDGET (builder, "title");
944 gval = ghb_widget_value(widget);
945 titleindex = ghb_lookup_combo_int("title", gval);
946 ghb_value_free(gval);
947 widget = GHB_WIDGET (builder, "AudioTrack");
948 gval = ghb_widget_value(widget);
949 track = ghb_lookup_combo_int("AudioTrack", gval);
950 ghb_value_free(gval);
951 audio = get_hb_audio(titleindex, track);
952 widget = GHB_WIDGET (builder, "FileFormat");
953 gval = ghb_widget_value(widget);
954 container = ghb_lookup_combo_int("FileFormat", gval);
955 ghb_value_free(gval);
956 widget = GHB_WIDGET (builder, "Mp4HttpOptimize");
957 httpopt = ghb_widget_boolean(widget);
959 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
960 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
961 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
962 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
964 gboolean allow_ac3 = TRUE;
966 !(container == HB_MUX_MP4 && httpopt) &&
967 (container != HB_MUX_OGM);
971 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
975 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
977 if (audio && audio->in.codec != HB_ACODEC_AC3)
979 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
981 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
983 widget = GHB_WIDGET (builder, "AudioEncoder");
984 gval = ghb_widget_value(widget);
985 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
986 ghb_value_free(gval);
987 if (acodec != HB_ACODEC_AC3)
989 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
991 if (container == HB_MUX_MP4)
993 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
994 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
995 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
997 else if (container == HB_MUX_AVI)
999 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1000 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1001 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1003 else if (container == HB_MUX_OGM)
1005 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1008 gboolean allow_mono = TRUE;
1009 gboolean allow_stereo = TRUE;
1010 gboolean allow_dolby = TRUE;
1011 gboolean allow_dpl2 = TRUE;
1012 gboolean allow_6ch = TRUE;
1016 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1017 (acodec != HB_ACODEC_LAME);
1018 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1020 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1022 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1023 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1024 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1025 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1027 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1028 (acodec != HB_ACODEC_LAME) &&
1029 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1030 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1032 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1033 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1034 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1035 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1036 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1040 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1042 hb_audio_config_t *audio = NULL;
1043 gboolean allow_mono = TRUE;
1044 gboolean allow_stereo = TRUE;
1045 gboolean allow_dolby = TRUE;
1046 gboolean allow_dpl2 = TRUE;
1047 gboolean allow_6ch = TRUE;
1049 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1051 // Audio codec pass-thru. No mixdown
1054 audio = get_hb_audio(titleindex, track);
1058 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1059 (acodec != HB_ACODEC_LAME);
1060 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1062 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1064 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1065 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1066 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1067 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1069 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1070 (acodec != HB_ACODEC_LAME) &&
1071 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1072 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1074 gboolean greater = FALSE;
1077 // If no mix is specified, select the best available.
1078 mix = HB_AMIXDOWN_6CH;
1080 if (mix == HB_AMIXDOWN_6CH)
1083 if (allow_6ch) return HB_AMIXDOWN_6CH;
1085 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1088 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1090 if (mix == HB_AMIXDOWN_DOLBY || greater)
1093 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1095 if (mix == HB_AMIXDOWN_STEREO || greater)
1098 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1100 if (mix == HB_AMIXDOWN_MONO || greater)
1103 if (allow_mono) return HB_AMIXDOWN_MONO;
1105 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1106 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1107 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1108 if (allow_6ch) return HB_AMIXDOWN_6CH;
1112 // Set up the model for the combo box
1114 init_combo_box(GtkBuilder *builder, const gchar *name)
1117 GtkListStore *store;
1118 GtkCellRenderer *cell;
1120 g_debug("init_combo_box() %s\n", name);
1121 // First modify the combobox model to allow greying out of options
1122 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1124 // 1 - String to display
1125 // 2 - bool indicating whether the entry is selectable (grey or not)
1126 // 3 - String that is used for presets
1127 // 4 - Int value determined by backend
1128 // 5 - String value determined by backend
1129 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1130 G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1131 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1133 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1135 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1136 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1137 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1138 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1139 "text", 0, "sensitive", 1, NULL);
1142 { // Combo box entry
1143 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1148 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1151 GtkListStore *store;
1154 g_debug("audio_samplerate_opts_set ()\n");
1155 store = get_combo_box_store(builder, name);
1156 gtk_list_store_clear(store);
1157 // Add an item for "Same As Source"
1158 gtk_list_store_append(store, &iter);
1159 gtk_list_store_set(store, &iter,
1160 0, "Same as source",
1166 for (ii = 0; ii < count; ii++)
1168 gtk_list_store_append(store, &iter);
1169 gtk_list_store_set(store, &iter,
1170 0, rates[ii].string,
1172 2, rates[ii].string,
1174 4, rates[ii].string,
1180 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1183 GtkListStore *store;
1186 g_debug("video_rate_opts_set ()\n");
1187 store = get_combo_box_store(builder, name);
1188 gtk_list_store_clear(store);
1189 // Add an item for "Same As Source"
1190 gtk_list_store_append(store, &iter);
1191 gtk_list_store_set(store, &iter,
1192 0, "Same as source",
1198 for (ii = 0; ii < count; ii++)
1202 if (strcmp(rates[ii].string, "23.976") == 0)
1204 desc = "(NTSC Film)";
1206 else if (strcmp(rates[ii].string, "25") == 0)
1208 desc = "(PAL Film/Video)";
1210 else if (strcmp(rates[ii].string, "29.97") == 0)
1212 desc = "(NTSC Video)";
1214 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1215 gtk_list_store_append(store, &iter);
1216 gtk_list_store_set(store, &iter,
1219 2, rates[ii].string,
1221 4, rates[ii].string,
1228 mix_opts_set(GtkBuilder *builder, const gchar *name)
1231 GtkListStore *store;
1234 g_debug("mix_opts_set ()\n");
1235 store = get_combo_box_store(builder, name);
1236 gtk_list_store_clear(store);
1237 gtk_list_store_append(store, &iter);
1238 gtk_list_store_set(store, &iter,
1245 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1247 gtk_list_store_append(store, &iter);
1248 gtk_list_store_set(store, &iter,
1249 0, hb_audio_mixdowns[ii].human_readable_name,
1251 2, hb_audio_mixdowns[ii].short_name,
1252 3, hb_audio_mixdowns[ii].amixdown,
1253 4, hb_audio_mixdowns[ii].internal_name,
1259 language_opts_set(GtkBuilder *builder, const gchar *name)
1262 GtkListStore *store;
1265 g_debug("language_opts_set ()\n");
1266 store = get_combo_box_store(builder, name);
1267 gtk_list_store_clear(store);
1268 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1270 gtk_list_store_append(store, &iter);
1271 gtk_list_store_set(store, &iter,
1272 0, ghb_language_table[ii].eng_name,
1274 2, ghb_language_table[ii].iso639_2,
1276 4, ghb_language_table[ii].iso639_1,
1281 static gchar **titles = NULL;
1284 title_opts_set(GtkBuilder *builder, const gchar *name)
1287 GtkListStore *store;
1288 hb_list_t * list = NULL;
1289 hb_title_t * title = NULL;
1293 g_debug("title_opts_set ()\n");
1294 store = get_combo_box_store(builder, name);
1295 gtk_list_store_clear(store);
1298 list = hb_get_titles( h_scan );
1299 count = hb_list_count( list );
1300 if (count > 100) count = 100;
1302 if (titles) g_strfreev(titles);
1303 if (title_opts.map) g_free(title_opts.map);
1306 title_opts.count = count;
1307 title_opts.map = g_malloc(count*sizeof(options_map_t));
1308 titles = g_malloc((count+1) * sizeof(gchar*));
1312 title_opts.count = 1;
1313 title_opts.map = g_malloc(sizeof(options_map_t));
1318 // No titles. Fill in a default.
1319 gtk_list_store_append(store, &iter);
1320 gtk_list_store_set(store, &iter,
1327 title_opts.map[0].option = "No Titles";
1328 title_opts.map[0].shortOpt = "none";
1329 title_opts.map[0].ivalue = -1;
1330 title_opts.map[0].svalue = "none";
1333 for (ii = 0; ii < count; ii++)
1335 title = (hb_title_t*)hb_list_item(list, ii);
1336 if (title->duration != 0)
1338 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1339 title->index, title->hours, title->minutes, title->seconds);
1343 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1345 gtk_list_store_append(store, &iter);
1346 gtk_list_store_set(store, &iter,
1353 title_opts.map[ii].option = titles[ii];
1354 title_opts.map[ii].shortOpt = titles[ii];
1355 title_opts.map[ii].ivalue = ii;
1356 title_opts.map[ii].svalue = titles[ii];
1362 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1365 gboolean foundit = FALSE;
1367 if (gtk_tree_model_get_iter_first (store, iter))
1371 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1372 if (value == ivalue)
1377 } while (gtk_tree_model_iter_next (store, iter));
1383 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1386 GtkListStore *store;
1387 hb_list_t * list = NULL;
1388 hb_title_t * title = NULL;
1389 hb_audio_config_t * audio;
1393 g_debug("audio_track_opts_set ()\n");
1394 store = get_combo_box_store(builder, name);
1395 gtk_list_store_clear(store);
1398 list = hb_get_titles( h_scan );
1399 title = (hb_title_t*)hb_list_item( list, titleindex );
1402 count = hb_list_count( title->list_audio );
1405 if (count > 10) count = 10;
1406 if (audio_track_opts.map) g_free(audio_track_opts.map);
1409 audio_track_opts.count = count;
1410 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1414 audio_track_opts.count = 1;
1415 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1419 // No audio. set some default
1420 gtk_list_store_append(store, &iter);
1421 gtk_list_store_set(store, &iter,
1428 audio_track_opts.map[0].option = "No Audio";
1429 audio_track_opts.map[0].shortOpt = "none";
1430 audio_track_opts.map[0].ivalue = -1;
1431 audio_track_opts.map[0].svalue = "none";
1434 for (ii = 0; ii < count; ii++)
1436 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1437 gtk_list_store_append(store, &iter);
1438 gtk_list_store_set(store, &iter,
1439 0, audio->lang.description,
1445 audio_track_opts.map[ii].option = audio->lang.description,
1446 audio_track_opts.map[ii].shortOpt = index_str[ii];
1447 audio_track_opts.map[ii].ivalue = ii;
1448 audio_track_opts.map[ii].svalue = index_str[ii];
1454 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1457 GtkListStore *store;
1458 hb_list_t * list = NULL;
1459 hb_title_t * title = NULL;
1460 hb_subtitle_t * subtitle;
1464 g_debug("subtitle_opts_set () %s\n", name);
1465 store = get_combo_box_store(builder, name);
1466 gtk_list_store_clear(store);
1469 list = hb_get_titles( h_scan );
1470 title = (hb_title_t*)hb_list_item( list, titleindex );
1473 count = hb_list_count( title->list_subtitle );
1476 if (count > 10) count = 10;
1477 if (subtitle_opts.map) g_free(subtitle_opts.map);
1480 subtitle_opts.count = count+2;
1481 subtitle_opts.map = g_malloc((count+2)*sizeof(options_map_t));
1485 subtitle_opts.count = LANG_TABLE_SIZE+2;
1486 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+2)*sizeof(options_map_t));
1488 // Add options for "none" and "autoselect"
1489 gtk_list_store_append(store, &iter);
1490 gtk_list_store_set(store, &iter,
1497 subtitle_opts.map[0].option = "None";
1498 subtitle_opts.map[0].shortOpt = "none";
1499 subtitle_opts.map[0].ivalue = -2;
1500 subtitle_opts.map[0].svalue = "none";
1501 gtk_list_store_append(store, &iter);
1502 gtk_list_store_set(store, &iter,
1509 subtitle_opts.map[0].option = "Same as audio";
1510 subtitle_opts.map[0].shortOpt = "auto";
1511 subtitle_opts.map[0].ivalue = -1;
1512 subtitle_opts.map[0].svalue = "auto";
1515 for (ii = 0; ii < count; ii++)
1517 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1518 gtk_list_store_append(store, &iter);
1519 gtk_list_store_set(store, &iter,
1522 2, subtitle->iso639_2,
1524 4, subtitle->iso639_2,
1526 subtitle_opts.map[ii+2].option = subtitle->lang;
1527 subtitle_opts.map[ii+2].shortOpt = subtitle->iso639_2;
1528 subtitle_opts.map[ii+2].ivalue = ii;
1529 subtitle_opts.map[ii+2].svalue = subtitle->iso639_2;
1534 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1536 gtk_list_store_append(store, &iter);
1537 gtk_list_store_set(store, &iter,
1538 0, ghb_language_table[ii].eng_name,
1540 2, ghb_language_table[ii].iso639_2,
1542 4, ghb_language_table[ii].iso639_2,
1544 subtitle_opts.map[ii+2].option = ghb_language_table[ii].eng_name;
1545 subtitle_opts.map[ii+2].shortOpt = ghb_language_table[ii].iso639_2;
1546 subtitle_opts.map[ii+2].ivalue = ii;
1547 subtitle_opts.map[ii+2].svalue = ghb_language_table[ii].iso639_2;
1559 guint64 longest = 0;
1560 gint titleindex = 0;
1562 g_debug("ghb_longest_title ()\n");
1563 if (h_scan == NULL) return 0;
1564 list = hb_get_titles( h_scan );
1565 count = hb_list_count( list );
1566 if (count > 100) count = 100;
1567 for (ii = 0; ii < count; ii++)
1569 title = (hb_title_t*)hb_list_item(list, ii);
1570 if (title->duration > longest)
1573 longest = title->duration;
1580 ghb_find_audio_track(gint titleindex, const gchar *lang, gint index)
1584 hb_audio_config_t * audio;
1590 g_debug("find_audio_track ()\n");
1593 list = hb_get_titles( h_scan );
1594 title = (hb_title_t*)hb_list_item( list, titleindex );
1597 count = hb_list_count( title->list_audio );
1600 if (count > 10) count = 10;
1601 for (ii = 0; ii < count; ii++)
1603 audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii );
1604 if ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1605 (strcmp(lang, "und") == 0))
1615 if (match) return track;
1622 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1625 GtkListStore *store;
1628 g_debug("generic_opts_set ()\n");
1629 if (name == NULL || opts == NULL) return;
1630 store = get_combo_box_store(builder, name);
1631 gtk_list_store_clear(store);
1632 for (ii = 0; ii < opts->count; ii++)
1634 gtk_list_store_append(store, &iter);
1635 gtk_list_store_set(store, &iter,
1636 0, opts->map[ii].option,
1638 2, opts->map[ii].shortOpt,
1639 3, opts->map[ii].ivalue,
1640 4, opts->map[ii].svalue,
1646 find_combo_table(const gchar *name)
1650 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1652 if (strcmp(name, combo_name_map[ii].name) == 0)
1654 return combo_name_map[ii].opts;
1661 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
1663 if (strcmp(name, "AudioBitrate") == 0)
1664 return lookup_audio_bitrate_int(gval);
1665 else if (strcmp(name, "AudioSamplerate") == 0)
1666 return lookup_audio_rate_int(gval);
1667 else if (strcmp(name, "VideoFramerate") == 0)
1668 return lookup_video_rate_int(gval);
1669 else if (strcmp(name, "AudioMixdown") == 0)
1670 return lookup_mix_int(gval);
1671 else if (strcmp(name, "SourceAudioLang") == 0)
1672 return lookup_audio_lang_int(gval);
1675 return lookup_generic_int(find_combo_table(name), gval);
1677 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1682 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
1684 if (strcmp(name, "AudioBitrate") == 0)
1685 return lookup_audio_bitrate_option(gval);
1686 else if (strcmp(name, "AudioSamplerate") == 0)
1687 return lookup_audio_rate_option(gval);
1688 else if (strcmp(name, "VideoFramerate") == 0)
1689 return lookup_video_rate_option(gval);
1690 else if (strcmp(name, "AudioMixdown") == 0)
1691 return lookup_mix_option(gval);
1692 else if (strcmp(name, "SourceAudioLang") == 0)
1693 return lookup_audio_lang_option(gval);
1696 return lookup_generic_option(find_combo_table(name), gval);
1698 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
1703 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1705 GtkComboBox *combo = NULL;
1707 gint handler_id = 0;
1709 g_debug("ghb_update_ui_combo_box() %s\n", name);
1712 // Clearing a combo box causes a rash of "changed" events, even when
1713 // the active item is -1 (inactive). To control things, I'm disabling
1714 // the event till things are settled down.
1715 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1716 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1719 // Valid signal id found. This should always succeed.
1720 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1721 signal_id, 0, 0, 0, 0);
1724 // This should also always succeed
1725 g_signal_handler_block ((gpointer)combo, handler_id);
1731 audio_bitrate_opts_set(builder, "AudioBitrate");
1732 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1733 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1734 mix_opts_set(builder, "AudioMixdown");
1735 language_opts_set(builder, "SourceAudioLang");
1736 subtitle_opts_set(builder, "Subtitles", user_data);
1737 title_opts_set(builder, "title");
1738 audio_track_opts_set(builder, "AudioTrack", user_data);
1739 generic_opts_set(builder, "FileFormat", &container_opts);
1740 generic_opts_set(builder, "PictureDeinterlace", &deint_opts);
1741 generic_opts_set(builder, "tweak_PictureDeinterlace", &deint_opts);
1742 generic_opts_set(builder, "PictureDenoise", &denoise_opts);
1743 generic_opts_set(builder, "tweak_PictureDenoise", &denoise_opts);
1744 generic_opts_set(builder, "VideoEncoder", &vcodec_opts);
1745 generic_opts_set(builder, "AudioEncoder", &acodec_opts);
1746 generic_opts_set(builder, "x264_direct", &direct_opts);
1747 generic_opts_set(builder, "x264_me", &me_opts);
1748 generic_opts_set(builder, "x264_subme", &subme_opts);
1749 generic_opts_set(builder, "x264_analyse", &analyse_opts);
1750 generic_opts_set(builder, "x264_trellis", &trellis_opts);
1754 if (strcmp(name, "AudioBitrate") == 0)
1755 audio_bitrate_opts_set(builder, "AudioBitrate");
1756 else if (strcmp(name, "AudioSamplerate") == 0)
1757 audio_samplerate_opts_set(builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
1758 else if (strcmp(name, "VideoFramerate") == 0)
1759 video_rate_opts_set(builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
1760 else if (strcmp(name, "AudioMixdown") == 0)
1761 mix_opts_set(builder, "AudioMixdown");
1762 else if (strcmp(name, "SourceAudioLang") == 0)
1763 language_opts_set(builder, "SourceAudioLang");
1764 else if (strcmp(name, "Subtitles") == 0)
1765 subtitle_opts_set(builder, "Subtitles", user_data);
1766 else if (strcmp(name, "title") == 0)
1767 title_opts_set(builder, "title");
1768 else if (strcmp(name, "AudioTrack") == 0)
1769 audio_track_opts_set(builder, "AudioTrack", user_data);
1771 generic_opts_set(builder, name, find_combo_table(name));
1775 g_signal_handler_unblock ((gpointer)combo, handler_id);
1780 init_ui_combo_boxes(GtkBuilder *builder)
1784 init_combo_box(builder, "AudioBitrate");
1785 init_combo_box(builder, "AudioSamplerate");
1786 init_combo_box(builder, "VideoFramerate");
1787 init_combo_box(builder, "AudioMixdown");
1788 init_combo_box(builder, "SourceAudioLang");
1789 init_combo_box(builder, "Subtitles");
1790 init_combo_box(builder, "title");
1791 init_combo_box(builder, "AudioTrack");
1792 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
1794 init_combo_box(builder, combo_name_map[ii].name);
1798 static const char * turbo_opts =
1799 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
1800 "no-fast-pskip=0:8x8dct=0:weightb=0";
1802 // Construct the x264 options string
1803 // The result is allocated, so someone must free it at some point.
1805 ghb_build_x264opts_string(GValue *settings)
1808 gchar *opts = ghb_settings_get_string(settings, "x264Option");
1815 result = g_strdup("");
1821 ghb_get_chapters(gint titleindex)
1825 hb_chapter_t * chapter;
1827 GValue *chapters = NULL;
1829 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
1830 if (h_scan == NULL) return NULL;
1831 list = hb_get_titles( h_scan );
1832 title = (hb_title_t*)hb_list_item( list, titleindex );
1833 if (title == NULL) return NULL;
1834 count = hb_list_count( title->list_chapter );
1835 chapters = ghb_array_value_new(count);
1836 for (ii = 0; ii < count; ii++)
1838 chapter = hb_list_item(title->list_chapter, ii);
1839 if (chapter == NULL) break;
1840 if (chapter->title == NULL || chapter->title[0] == 0)
1843 str = g_strdup_printf ("Chapter %2d", ii+1);
1844 ghb_array_append(chapters, ghb_string_value_new(str));
1849 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
1856 ghb_ac3_in_audio_list(const GValue *audio_list)
1860 count = ghb_array_len(audio_list);
1861 for (ii = 0; ii < count; ii++)
1866 asettings = ghb_array_get_nth(audio_list, ii);
1867 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
1868 if (acodec == HB_ACODEC_AC3)
1875 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
1878 GtkListStore *store;
1881 g_debug("audio_rate_opts_add ()\n");
1882 store = get_combo_box_store(builder, name);
1883 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
1885 str = g_strdup_printf ("%d", rate);
1886 gtk_list_store_append(store, &iter);
1887 gtk_list_store_set(store, &iter,
1899 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
1902 GtkListStore *store;
1904 gboolean done = FALSE;
1906 guint last = (guint)last_rate;
1908 g_debug("audio_bitrate_opts_clean ()\n");
1909 store = get_combo_box_store(builder, name);
1910 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
1914 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
1916 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
1918 done = !gtk_list_store_remove(store, &iter);
1920 else if (ivalue > last)
1923 gtk_list_store_set(store, &iter, 1, FALSE, -1);
1924 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
1929 gtk_list_store_set(store, &iter, 1, TRUE, -1);
1930 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
1937 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
1940 GtkListStore *store;
1943 g_debug("audio_bitrate_opts_set ()\n");
1944 store = get_combo_box_store(builder, name);
1945 gtk_list_store_clear(store);
1946 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1948 gtk_list_store_append(store, &iter);
1949 gtk_list_store_set(store, &iter,
1950 0, hb_audio_bitrates[ii].string,
1952 2, hb_audio_bitrates[ii].string,
1953 3, hb_audio_bitrates[ii].rate,
1954 4, hb_audio_bitrates[ii].string,
1960 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
1962 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
1966 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
1968 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
1971 static ghb_status_t hb_status;
1974 ghb_backend_init(GtkBuilder *builder, gint debug, gint update)
1977 h_scan = hb_init( debug, update );
1978 h_queue = hb_init( debug, 0 );
1979 // Set up the list model for the combos
1980 init_ui_combo_boxes(builder);
1981 // Populate all the combos
1982 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
1993 ghb_backend_scan(const gchar *path, gint titleindex)
1995 hb_scan( h_scan, path, titleindex );
1996 hb_status.state |= GHB_STATE_SCANNING;
1997 // initialize count and cur to something that won't cause FPE
1998 // when computing progress
1999 hb_status.title_count = 1;
2000 hb_status.title_cur = 0;
2004 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2006 g_debug("ghb_backend_queue_scan()");
2007 hb_scan( h_queue, path, titlenum );
2008 hb_status.queue_state |= GHB_STATE_SCANNING;
2014 return hb_status.state;
2018 ghb_get_queue_state()
2020 return hb_status.queue_state;
2024 ghb_clear_state(gint state)
2026 hb_status.state &= ~state;
2030 ghb_clear_queue_state(gint state)
2032 hb_status.queue_state &= ~state;
2036 ghb_set_state(gint state)
2038 hb_status.state |= state;
2042 ghb_set_queue_state(gint state)
2044 hb_status.queue_state |= state;
2048 ghb_get_status(ghb_status_t *status)
2050 memcpy(status, &hb_status, sizeof(ghb_status_t));
2059 if (h_scan == NULL) return;
2060 hb_get_state( h_scan, &s );
2063 #define p s.param.scanning
2064 case HB_STATE_SCANNING:
2066 hb_status.state |= GHB_STATE_SCANNING;
2067 hb_status.title_count = p.title_count;
2068 hb_status.title_cur = p.title_cur;
2072 case HB_STATE_SCANDONE:
2074 hb_status.state &= ~GHB_STATE_SCANNING;
2075 hb_status.state |= GHB_STATE_SCANDONE;
2079 hb_get_state( h_queue, &s_queue );
2080 switch( s_queue.state )
2082 case HB_STATE_SCANNING:
2084 hb_status.queue_state |= GHB_STATE_SCANNING;
2087 case HB_STATE_SCANDONE:
2089 hb_status.queue_state &= ~GHB_STATE_SCANNING;
2090 hb_status.queue_state |= GHB_STATE_SCANDONE;
2093 #define p s_queue.param.working
2094 case HB_STATE_WORKING:
2095 hb_status.queue_state |= GHB_STATE_WORKING;
2096 hb_status.queue_state &= ~GHB_STATE_PAUSED;
2097 hb_status.job_cur = p.job_cur;
2098 hb_status.job_count = p.job_count;
2099 hb_status.progress = p.progress;
2100 hb_status.rate_cur = p.rate_cur;
2101 hb_status.rate_avg = p.rate_avg;
2102 hb_status.hours = p.hours;
2103 hb_status.minutes = p.minutes;
2104 hb_status.seconds = p.seconds;
2105 hb_status.unique_id = p.sequence_id & 0xFFFFFF;
2109 case HB_STATE_PAUSED:
2110 hb_status.queue_state |= GHB_STATE_PAUSED;
2113 case HB_STATE_MUXING:
2115 hb_status.queue_state |= GHB_STATE_MUXING;
2118 #define p s_queue.param.workdone
2119 case HB_STATE_WORKDONE:
2123 hb_status.queue_state |= GHB_STATE_WORKDONE;
2124 hb_status.queue_state &= ~GHB_STATE_MUXING;
2125 hb_status.queue_state &= ~GHB_STATE_PAUSED;
2126 hb_status.queue_state &= ~GHB_STATE_WORKING;
2130 hb_status.error = GHB_ERROR_NONE;
2131 case HB_ERROR_CANCELED:
2132 hb_status.error = GHB_ERROR_CANCELED;
2134 hb_status.error = GHB_ERROR_FAIL;
2136 hb_status.error = p.error;
2137 // Delete all remaining jobs of this encode.
2138 // An encode can be composed of multiple associated jobs.
2139 // When a job is stopped, libhb removes it from the job list,
2140 // but does not remove other jobs that may be associated with it.
2141 // Associated jobs are taged in the sequence id.
2142 while ((job = hb_job(h_queue, 0)) != NULL)
2143 hb_rem( h_queue, job );
2150 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2155 if (h_scan == NULL) return FALSE;
2156 list = hb_get_titles( h_scan );
2157 if( !hb_list_count( list ) )
2159 /* No valid title, stop right there */
2163 title = hb_list_item( list, titleindex );
2164 if (title == NULL) return FALSE; // Bad titleindex
2165 tinfo->width = title->width;
2166 tinfo->height = title->height;
2167 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2168 // Don't allow crop to 0
2169 if (title->crop[0] + title->crop[1] >= title->height)
2170 title->crop[0] = title->crop[1] = 0;
2171 if (title->crop[2] + title->crop[3] >= title->width)
2172 title->crop[2] = title->crop[3] = 0;
2173 tinfo->num_chapters = hb_list_count(title->list_chapter);
2174 tinfo->rate_base = title->rate_base;
2175 tinfo->rate = title->rate;
2176 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2177 title->width * title->pixel_aspect_width,
2178 title->height * title->pixel_aspect_height);
2179 tinfo->hours = title->hours;
2180 tinfo->minutes = title->minutes;
2181 tinfo->seconds = title->seconds;
2182 tinfo->duration = title->duration;
2187 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2189 hb_audio_config_t *audio;
2191 audio = get_hb_audio(titleindex, audioindex);
2192 if (audio == NULL) return FALSE; // Bad audioindex
2193 ainfo->codec = audio->in.codec;
2194 ainfo->bitrate = audio->in.bitrate;
2195 ainfo->samplerate = audio->in.samplerate;
2200 ghb_audio_is_passthru(gint acodec)
2202 g_debug("ghb_audio_is_passthru () \n");
2203 g_debug("acodec %d\n", acodec);
2204 return (acodec == HB_ACODEC_AC3);
2208 ghb_get_default_acodec()
2210 return HB_ACODEC_FAAC;
2214 ghb_set_scale(signal_user_data_t *ud, gint mode)
2219 gboolean keep_aspect, round_dims, anamorphic;
2220 gboolean autocrop, autoscale, noscale;
2221 gint crop[4], width, height, par_width, par_height;
2222 gint crop_width, crop_height;
2223 gint aspect_n, aspect_d;
2224 gboolean keep_width = (mode == GHB_SCALE_KEEP_WIDTH);
2225 gboolean keep_height = (mode == GHB_SCALE_KEEP_HEIGHT);
2231 gint max_height = 0;
2233 g_debug("ghb_set_scale ()\n");
2235 if (h_scan == NULL) return;
2236 list = hb_get_titles( h_scan );
2237 if( !hb_list_count( list ) )
2239 /* No valid title, stop right there */
2244 titleindex = ghb_settings_combo_int(ud->settings, "title");
2245 title = hb_list_item( list, titleindex );
2246 if (title == NULL) return;
2248 if (job == NULL) return;
2250 // First configure widgets
2251 round_dims = ghb_settings_get_boolean(ud->settings, "ModDimensions");
2252 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
2253 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2254 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2255 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2256 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2257 // alignment constraints rather than scaling to satisfy them.
2258 noscale = ghb_settings_get_boolean(ud->settings, "noscale");
2259 // Align dimensions to either 16 or 2 pixels
2260 // The scaler crashes if the dimensions are not divisible by 2
2261 // x264 also will not accept dims that are not multiple of 2
2262 modshift = round_dims ? 4 : 1;
2263 modround = round_dims ? 8 : 1;
2267 keep_height = FALSE;
2269 if (anamorphic || keep_aspect)
2271 keep_height = FALSE;
2273 // Step needs to be at least 2 because odd widths cause scaler crash
2274 step = round_dims ? 16 : 2;
2275 widget = GHB_WIDGET (ud->builder, "scale_width");
2276 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2277 widget = GHB_WIDGET (ud->builder, "scale_height");
2278 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2281 ghb_title_info_t tinfo;
2283 if (ghb_get_title_info (&tinfo, titleindex))
2285 crop[0] = tinfo.crop[0];
2286 crop[1] = tinfo.crop[1];
2287 crop[2] = tinfo.crop[2];
2288 crop[3] = tinfo.crop[3];
2293 // Adjust the cropping to accomplish the desired width and height
2294 crop_width = tinfo.width - crop[2] - crop[3];
2295 crop_height = tinfo.height - crop[0] - crop[1];
2296 width = (crop_width >> modshift) << modshift;
2297 height = (crop_height >> modshift) << modshift;
2298 need1 = (crop_height - height) / 2;
2299 need2 = crop_height - height - need1;
2302 need1 = (crop_width - width) / 2;
2303 need2 = crop_width - width - need1;
2307 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2308 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2309 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2310 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2313 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2314 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2315 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2316 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2317 hb_reduce(&aspect_n, &aspect_d,
2318 title->width * title->pixel_aspect_width,
2319 title->height * title->pixel_aspect_height);
2320 crop_width = title->width - crop[2] - crop[3];
2321 crop_height = title->height - crop[0] - crop[1];
2325 height = crop_height;
2326 max_width = crop_width;
2327 max_height = crop_height;
2331 width = ghb_settings_get_int(ud->settings, "scale_width");
2332 height = ghb_settings_get_int(ud->settings, "scale_height");
2333 max_width = ghb_settings_get_int(ud->settings, "PictureWidth");
2334 max_height = ghb_settings_get_int(ud->settings, "PictureHeight");
2336 max_width = (max_width >> modshift) << modshift;
2337 max_height = (max_height >> modshift) << modshift;
2338 // Adjust dims according to max values
2341 max_height = crop_height;
2345 max_width = crop_width;
2347 height = MIN(height, max_height);
2348 width = MIN(width, max_width);
2349 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2352 width = title->width - crop[2] - crop[3];
2354 height = title->height - crop[0] - crop[1];
2364 // The scaler crashes if the dimensions are not divisible by 2
2365 // Align mod 2. And so does something in x264_encoder_headers()
2370 job->maxHeight = max_height;
2371 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2372 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2373 hb_set_anamorphic_size( job, &width, &height,
2374 &par_width, &par_height );
2381 gint new_width, new_height;
2383 g_debug("kw %s kh %s\n", keep_width ? "y":"n", keep_height ? "y":"n");
2384 g_debug("w %d h %d\n", width, height);
2385 // Compute pixel aspect ration.
2386 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2387 // Must scale so that par becomes 1:1
2388 // Try to keep largest dimension
2389 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2390 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2391 // Height and width are always multiples of 2, so do the rounding
2392 new_height = ((new_height + 1) >> 1) << 1;
2393 new_width = ((new_width + 1) >> 1) << 1;
2394 g_debug("max w %d, new w %d\n", max_width, new_width);
2395 if (max_width && (new_width > max_width))
2397 height = new_height;
2399 else if (max_height && (new_height > max_height))
2403 else if (keep_width)
2405 height = new_height;
2407 else if (keep_height)
2411 else if (width > new_width)
2413 height = new_height;
2419 g_debug("new w %d h %d\n", width, height);
2421 width = ((width + modround) >> modshift) << modshift;
2422 height = ((height + modround) >> modshift) << modshift;
2424 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2425 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2429 set_preview_job_settings(hb_job_t *job, GValue *settings)
2431 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
2432 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
2433 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
2434 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
2436 gboolean anamorphic, round_dimensions;
2437 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
2438 round_dimensions = ghb_settings_get_boolean(settings, "ModDimensions");
2439 if (round_dimensions && anamorphic)
2442 job->pixel_ratio = 2;
2444 else if (anamorphic)
2447 job->pixel_ratio = 2;
2452 job->pixel_ratio = 0;
2454 job->width = ghb_settings_get_int(settings, "scale_width");
2455 job->height = ghb_settings_get_int(settings, "scale_height");
2456 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
2457 gboolean decomb = ghb_settings_get_boolean(settings, "PictureDecomb");
2458 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2462 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2469 if (h_scan == NULL) return 1500;
2470 list = hb_get_titles( h_scan );
2471 title = hb_list_item( list, titleindex );
2472 if (title == NULL) return 1500;
2474 if (job == NULL) return 1500;
2475 size = ghb_settings_get_int(settings, "VideoTargetSize");
2476 return hb_calc_bitrate( job, size );
2480 ghb_validate_filter_string(const gchar *str, gint max_fields)
2486 if (str == NULL || *str == 0) return TRUE;
2489 val = g_strtod(str, &end);
2491 { // Found a numeric value
2493 // negative max_fields means infinate
2494 if (max_fields >= 0 && fields > max_fields) return FALSE;
2508 ghb_validate_filters(signal_user_data_t *ud)
2516 tweaks = ghb_settings_get_boolean(ud->settings, "allow_tweaks");
2520 str = ghb_settings_get_string(ud->settings, "tweak_PictureDetelecine");
2521 enabled = ghb_settings_get_boolean(ud->settings, "PictureDetelecine");
2522 if (enabled && !ghb_validate_filter_string(str, 6))
2524 message = g_strdup_printf(
2525 "Invalid Detelecine Settings:\n\n%s\n",
2527 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2534 str = ghb_settings_get_string(ud->settings, "tweak_PictureDecomb");
2535 enabled = ghb_settings_get_boolean(ud->settings, "PictureDecomb");
2536 if (enabled && !ghb_validate_filter_string(str, 7))
2538 message = g_strdup_printf(
2539 "Invalid Decomb Settings:\n\n%s\n",
2541 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2548 index = ghb_lookup_combo_int("tweak_PictureDeinterlace",
2549 ghb_settings_get_value(ud->settings, "tweak_PictureDeinterlace"));
2552 str = ghb_settings_get_string(ud->settings, "tweak_PictureDeinterlace");
2553 if (!ghb_validate_filter_string(str, 4))
2555 message = g_strdup_printf(
2556 "Invalid Deinterlace Settings:\n\n%s\n",
2558 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2566 index = ghb_lookup_combo_int("tweak_PictureDenoise",
2567 ghb_settings_get_value(ud->settings, "tweak_PictureDenoise"));
2570 str = ghb_settings_get_string(ud->settings, "tweak_PictureDenoise");
2571 if (!ghb_validate_filter_string(str, 4))
2573 message = g_strdup_printf(
2574 "Invalid Denoise Settings:\n\n%s\n",
2576 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2588 ghb_validate_video(signal_user_data_t *ud)
2593 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2594 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
2595 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
2596 (vcodec == HB_VCODEC_THEORA))
2598 // mp4|avi/theora combination is not supported.
2599 message = g_strdup_printf(
2600 "Theora is not supported in the MP4 and AVI containers.\n\n"
2601 "You should choose a different video codec or container.\n"
2602 "If you continue, XviD will be chosen for you.");
2603 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2609 vcodec = HB_VCODEC_XVID;
2610 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
2616 ghb_validate_container(signal_user_data_t *ud)
2621 container = ghb_settings_combo_int(ud->settings, "FileFormat");
2622 if (container == HB_MUX_MP4)
2624 const GValue *audio_list;
2627 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2628 httpopt = ghb_settings_get_boolean(ud->settings, "Mp4HttpOptimize");
2629 if (httpopt && ghb_ac3_in_audio_list(audio_list))
2631 message = g_strdup_printf(
2632 "AC3 audio in HTTP optimized MP4 is not supported.\n\n"
2633 "You should choose a different audio codec.\n"
2634 "If you continue, FAAC will be chosen for you.");
2635 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2644 count = ghb_array_len(audio_list);
2645 for (ii = 0; ii < count; ii++)
2649 asettings = ghb_array_get_nth(audio_list, ii);
2650 gint acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2651 if (acodec == HB_ACODEC_AC3)
2654 value = get_acodec_value(HB_ACODEC_FAAC);
2655 ghb_settings_take_value(asettings, "AudioEncoder", value);
2656 value = get_abitrate_value(160);
2657 ghb_settings_take_value(asettings, "AudioBitrate", value);
2666 ghb_validate_audio(signal_user_data_t *ud)
2673 if (h_scan == NULL) return FALSE;
2674 list = hb_get_titles( h_scan );
2675 if( !hb_list_count( list ) )
2677 /* No valid title, stop right there */
2678 g_message("No title found.\n");
2684 titleindex = ghb_settings_combo_int(ud->settings, "title");
2685 title = hb_list_item( list, titleindex );
2686 if (title == NULL) return FALSE;
2687 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
2689 const GValue *audio_list;
2692 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2693 count = ghb_array_len(audio_list);
2694 for (ii = 0; ii < count; ii++)
2697 hb_audio_config_t *taudio;
2699 asettings = ghb_array_get_nth(audio_list, ii);
2700 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
2701 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
2702 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
2703 title->list_audio, track );
2704 if ((taudio->in.codec != HB_ACODEC_AC3) && (codec == HB_ACODEC_AC3))
2706 // Not supported. AC3 is passthrough only, so input must be AC3
2707 message = g_strdup_printf(
2708 "The source does not support AC3 Pass-Thru.\n\n"
2709 "You should choose a different audio codec.\n"
2710 "If you continue, one will be chosen for you.");
2711 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2717 if (mux == HB_MUX_AVI)
2719 codec = HB_ACODEC_LAME;
2723 codec = HB_ACODEC_FAAC;
2725 value = get_acodec_value(codec);
2726 ghb_settings_take_value(asettings, "AudioEncoder", value);
2728 gchar *a_unsup = NULL;
2729 gchar *mux_s = NULL;
2730 if (mux == HB_MUX_MP4)
2733 // mp4/mp3|vorbis combination is not supported.
2734 if (codec == HB_ACODEC_LAME)
2737 codec = HB_ACODEC_FAAC;
2739 if (codec == HB_ACODEC_VORBIS)
2742 codec = HB_ACODEC_FAAC;
2745 else if (mux == HB_MUX_AVI)
2748 // avi/faac|vorbis combination is not supported.
2749 if (codec == HB_ACODEC_FAAC)
2752 codec = HB_ACODEC_LAME;
2754 if (codec == HB_ACODEC_VORBIS)
2757 codec = HB_ACODEC_LAME;
2760 else if (mux == HB_MUX_OGM)
2763 // avi/faac|vorbis combination is not supported.
2764 if (codec == HB_ACODEC_FAAC)
2767 codec = HB_ACODEC_VORBIS;
2769 if (codec == HB_ACODEC_AC3)
2772 codec = HB_ACODEC_VORBIS;
2777 message = g_strdup_printf(
2778 "%s is not supported in the %s container.\n\n"
2779 "You should choose a different audio codec.\n"
2780 "If you continue, one will be chosen for you.", a_unsup, mux_s);
2781 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2787 value = get_acodec_value(codec);
2788 ghb_settings_take_value(asettings, "AudioEncoder", value);
2790 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
2791 gboolean allow_mono = TRUE;
2792 gboolean allow_stereo = TRUE;
2793 gboolean allow_dolby = TRUE;
2794 gboolean allow_dpl2 = TRUE;
2795 gboolean allow_6ch = TRUE;
2797 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2798 (codec != HB_ACODEC_LAME);
2799 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2801 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
2803 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
2804 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
2805 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
2806 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
2808 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2809 (codec != HB_ACODEC_LAME) &&
2810 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
2811 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
2813 gchar *mix_unsup = NULL;
2814 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
2818 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
2820 mix_unsup = "stereo";
2822 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
2824 mix_unsup = "Dolby";
2826 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
2828 mix_unsup = "Dolby Pro Logic II";
2830 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
2832 mix_unsup = "6 Channel";
2836 message = g_strdup_printf(
2837 "The source audio does not support %s mixdown.\n\n"
2838 "You should choose a different mixdown.\n"
2839 "If you continue, one will be chosen for you.", mix_unsup);
2840 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2846 mix = ghb_get_best_mix(titleindex, track, codec, mix);
2847 value = get_amix_value(mix);
2848 ghb_settings_take_value(asettings, "AudioMixdown", value);
2855 ghb_validate_vquality(GValue *settings)
2861 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
2862 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
2864 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
2865 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
2867 if (!ghb_settings_get_boolean(settings, "directqp"))
2870 if (vcodec != HB_VCODEC_X264)
2883 if (vcodec == HB_VCODEC_X264)
2888 else if (vcodec == HB_VCODEC_FFMPEG)
2900 if (vquality < min || vquality > max)
2902 message = g_strdup_printf(
2903 "Interesting video quality choise: %d\n\n"
2904 "Typical values range from %d to %d.\n"
2905 "Are you sure you wish to use this setting?",
2906 (gint)vquality, min, max);
2907 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
2908 "Cancel", "Continue"))
2920 ghb_add_job(GValue *js, gint unique_id)
2925 static gchar *x264opts;
2927 gboolean tweaks = FALSE;
2928 gchar *detel_str = NULL;
2929 gchar *decomb_str = NULL;
2930 gchar *deint_str = NULL;
2931 gchar *deblock_str = NULL;
2932 gchar *denoise_str = NULL;
2933 gchar *dest_str = NULL;
2935 g_debug("ghb_add_job()\n");
2936 if (h_queue == NULL) return;
2937 list = hb_get_titles( h_queue );
2938 if( !hb_list_count( list ) )
2940 /* No valid title, stop right there */
2941 g_message("No title found.\n");
2945 // Since I'm doing a scan of the single title I want just prior
2946 // to adding the job, there is only the one title to choose from.
2947 //gint titleindex = ghb_settings_get_int(js, "title");
2948 gint titleindex = 0;
2949 title = hb_list_item( list, titleindex );
2950 if (title == NULL) return;
2952 /* Set job settings */
2954 if (job == NULL) return;
2956 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
2957 job->mux = ghb_settings_combo_int(js, "FileFormat");
2958 if (job->mux == HB_MUX_MP4)
2960 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
2961 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
2965 job->largeFileSize = FALSE;
2966 job->mp4_optimize = FALSE;
2968 gint chapter_start, chapter_end;
2969 chapter_start = ghb_settings_get_int(js, "start_chapter");
2970 chapter_end = ghb_settings_get_int(js, "end_chapter");
2971 gint num_chapters = hb_list_count(title->list_chapter);
2972 job->chapter_start = MIN( num_chapters, chapter_start );
2973 job->chapter_end = MAX( job->chapter_start, chapter_end );
2975 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
2976 if ( job->chapter_markers )
2983 chapters = ghb_settings_get_value(js, "chapter_list");
2984 count = ghb_array_len(chapters);
2985 for(chap = chapter_start; chap <= chapter_end; chap++)
2987 hb_chapter_t * chapter_s;
2993 chapter = ghb_array_get_nth(chapters, chap-1);
2994 name = ghb_value_string(chapter);
2998 name = g_strdup_printf ("Chapter %2d", chap);
3000 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3001 strncpy(chapter_s->title, name, 1023);
3002 chapter_s->title[1023] = '\0';
3006 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3007 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3008 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3009 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3012 gboolean decomb = ghb_settings_get_boolean(js, "PictureDecomb");
3013 gint deint = ghb_settings_combo_int(js,
3014 tweaks ? "tweak_PictureDeinterlace":"PictureDeinterlace");
3016 job->deinterlace = (deint != 0) ? 1 : 0;
3018 job->deinterlace = 0;
3019 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3021 gboolean anamorphic = ghb_settings_get_boolean(js, "anamorphic");
3022 gboolean round_dimensions = ghb_settings_get_boolean(js, "ModDimensions");
3023 if (round_dimensions && anamorphic)
3025 job->pixel_ratio = 2;
3028 else if (anamorphic)
3030 // Huh! I thought I wanted to use pixel_ratio 1 for this case, but
3031 // when its 1, libhb discards the width and height and uses original
3032 // title dims - crop. Thats not what I want.
3033 // Also, x264 requires things to divisible by 2.
3034 job->pixel_ratio = 2;
3039 job->pixel_ratio = 0;
3042 /* Add selected filters */
3043 job->filters = hb_list_init();
3044 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3045 if( vrate == 0 && ghb_settings_get_boolean(js, "PictureDetelecine" ) )
3050 if( ghb_settings_get_boolean(js, "PictureDetelecine" ) )
3052 hb_filter_detelecine.settings = NULL;
3055 detel_str = ghb_settings_get_string(js, "tweak_PictureDetelecine");
3056 if (detel_str && detel_str[0])
3058 hb_filter_detelecine.settings = detel_str;
3061 hb_list_add( job->filters, &hb_filter_detelecine );
3065 // Use default settings
3066 hb_filter_decomb.settings = NULL;
3069 decomb_str = ghb_settings_get_string(js, "tweak_PictureDecomb");
3070 if (decomb_str && decomb_str[0])
3072 hb_filter_decomb.settings = (gchar*)decomb_str;
3075 hb_list_add( job->filters, &hb_filter_decomb );
3077 if( job->deinterlace )
3080 deint_str = g_strdup(deint_opts.map[deint].svalue);
3082 deint_str = ghb_settings_get_string(js,
3083 tweaks ? "tweak_PictureDeinterlace" : "PictureDeinterlace");
3084 hb_filter_deinterlace.settings = deint_str;
3085 hb_list_add( job->filters, &hb_filter_deinterlace );
3087 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3090 deblock_str = g_strdup_printf("%d", deblock);
3091 hb_filter_deblock.settings = deblock_str;
3092 hb_list_add( job->filters, &hb_filter_deblock );
3094 gint denoise = ghb_settings_combo_int(js,
3095 tweaks ? "tweak_PictureDenoise" : "PictureDenoise");
3099 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3101 denoise_str = (gchar*)ghb_settings_get_string(
3102 js, tweaks ? "tweak_PictureDenoise" : "PictureDenoise");
3103 hb_filter_denoise.settings = denoise_str;
3104 hb_list_add( job->filters, &hb_filter_denoise );
3106 job->width = ghb_settings_get_int(js, "scale_width");
3107 job->height = ghb_settings_get_int(js, "scale_height");
3109 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3110 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3111 (job->vcodec == HB_VCODEC_THEORA))
3113 // mp4|avi/theora combination is not supported.
3114 job->vcodec = HB_VCODEC_XVID;
3116 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3118 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3120 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3123 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3124 if (!ghb_settings_get_boolean(js, "directqp"))
3126 if (vquality == 0.0) vquality = 0.01;
3127 if (vquality == 1.0) vquality = 0.0;
3129 job->vquality = vquality;
3132 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3134 job->vquality = -1.0;
3135 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3137 // AVI container does not support variable frame rate.
3138 if (job->mux == HB_MUX_AVI)
3146 job->vrate = title->rate;
3147 job->vrate_base = title->rate_base;
3152 job->vrate = 27000000;
3153 job->vrate_base = vrate;
3156 // First remove any audios that are already in the list
3157 // This happens if you are encoding the same title a second time.
3158 gint num_audio_tracks = hb_list_count(job->list_audio);
3160 for(ii = 0; ii < num_audio_tracks; ii++)
3162 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3163 hb_list_rem(job->list_audio, audio);
3166 const GValue *audio_list;
3170 audio_list = ghb_settings_get_value(js, "audio_list");
3171 count = ghb_array_len(audio_list);
3172 for (ii = 0; ii < count; ii++)
3175 hb_audio_config_t audio;
3176 hb_audio_config_t *taudio;
3178 hb_audio_config_init(&audio);
3179 asettings = ghb_array_get_nth(audio_list, ii);
3180 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3181 audio.out.track = tcount;
3182 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3183 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3184 title->list_audio, audio.in.track );
3185 if ((taudio->in.codec != HB_ACODEC_AC3) && (audio.out.codec == HB_ACODEC_AC3))
3187 // Not supported. AC3 is passthrough only, so input must be AC3
3188 if (job->mux == HB_MUX_AVI)
3190 audio.out.codec = HB_ACODEC_LAME;
3194 audio.out.codec = HB_ACODEC_FAAC;
3197 if ((job->mux == HB_MUX_MP4) &&
3198 ((audio.out.codec == HB_ACODEC_LAME) ||
3199 (audio.out.codec == HB_ACODEC_VORBIS)))
3201 // mp4/mp3|vorbis combination is not supported.
3202 audio.out.codec = HB_ACODEC_FAAC;
3204 if ((job->mux == HB_MUX_AVI) &&
3205 ((audio.out.codec == HB_ACODEC_FAAC) ||
3206 (audio.out.codec == HB_ACODEC_VORBIS)))
3208 // avi/faac|vorbis combination is not supported.
3209 audio.out.codec = HB_ACODEC_LAME;
3211 if ((job->mux == HB_MUX_OGM) &&
3212 ((audio.out.codec == HB_ACODEC_FAAC) ||
3213 (audio.out.codec == HB_ACODEC_AC3)))
3215 // ogm/faac|ac3 combination is not supported.
3216 audio.out.codec = HB_ACODEC_VORBIS;
3218 audio.out.dynamic_range_compression =
3219 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3220 // It would be better if this were done in libhb for us, but its not yet.
3221 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3223 audio.out.mixdown = 0;
3227 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3228 // Make sure the mixdown is valid and pick a new one if not.
3229 audio.out.mixdown = ghb_get_best_mix(titleindex,
3230 audio.in.track, audio.out.codec, audio.out.mixdown);
3232 ghb_settings_combo_int(asettings, "AudioBitrate");
3233 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3234 if (srate == 0) // 0 is same as source
3235 audio.out.samplerate = taudio->in.samplerate;
3237 audio.out.samplerate = srate;
3240 // Add it to the jobs audio list
3241 hb_audio_add( job, &audio );
3244 // I was tempted to move this up with the reset of the video quality
3245 // settings, but I suspect the settings above need to be made
3246 // first in order for hb_calc_bitrate to be accurate.
3247 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3251 size = ghb_settings_get_int(js, "VideoTargetSize");
3252 job->vbitrate = hb_calc_bitrate( job, size );
3253 job->vquality = -1.0;
3256 dest_str = ghb_settings_get_string(js, "destination");
3257 job->file = dest_str;
3258 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3259 // TODO: libhb holds onto a reference to the x264opts and is not
3260 // finished with it until encoding the job is done. But I can't
3261 // find a way to get at the job before it is removed in order to
3262 // free up the memory I am allocating here.
3263 // The short story is THIS LEAKS.
3264 x264opts = ghb_build_x264opts_string(js);
3266 if( x264opts != NULL && *x264opts != '\0' )
3268 job->x264opts = x264opts;
3270 else /*avoids a bus error crash when options aren't specified*/
3272 job->x264opts = NULL;
3275 gchar *slang = ghb_settings_get_string(js, "Subtitles");
3276 subtitle = -2; // default to none
3277 if (strcmp(slang, "auto") == 0)
3284 hb_subtitle_t * subt;
3286 scount = hb_list_count(title->list_subtitle);
3287 for (ii = 0; ii < scount; ii++)
3289 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
3290 if (strcmp(slang, subt->iso639_2) == 0)
3297 gboolean forced_subtitles = ghb_settings_get_boolean(js, "SubtitlesForced");
3298 job->subtitle_force = forced_subtitles;
3300 job->subtitle = subtitle;
3305 // Subtitle scan. Look for subtitle matching audio language
3309 * When subtitle scan is enabled do a fast pre-scan job
3310 * which will determine which subtitles to enable, if any.
3313 job->indepth_scan = 1;
3315 x264opts_tmp = job->x264opts;
3316 job->x264opts = NULL;
3318 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3319 *(job->select_subtitle) = NULL;
3322 * Add the pre-scan job
3324 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3325 hb_add( h_queue, job );
3326 //if (job->x264opts != NULL)
3327 // g_free(job->x264opts);
3329 job->x264opts = x264opts_tmp;
3333 job->select_subtitle = NULL;
3335 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
3336 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3339 * If subtitle_scan is enabled then only turn it on
3340 * for the second pass and then off again for the
3343 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3344 job->select_subtitle = NULL;
3346 job->indepth_scan = 0;
3347 gchar *x264opts2 = NULL;
3350 x264opts2 = g_strdup(x264opts);
3353 * If turbo options have been selected then append them
3354 * to the x264opts now (size includes one ':' and the '\0')
3356 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
3362 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3368 * No x264opts to modify, but apply the turbo options
3369 * anyway as they may be modifying defaults
3371 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3373 x264opts = tmp_x264opts;
3375 job->x264opts = x264opts;
3377 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3378 hb_add( h_queue, job );
3379 //if (job->x264opts != NULL)
3380 // g_free(job->x264opts);
3382 job->select_subtitle = subtitle_tmp;
3385 * On the second pass we turn off subtitle scan so that we
3386 * can actually encode using any subtitles that were auto
3387 * selected in the first pass (using the whacky select-subtitle
3388 * attribute of the job).
3390 job->indepth_scan = 0;
3391 job->x264opts = x264opts2;
3392 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3393 hb_add( h_queue, job );
3394 //if (job->x264opts != NULL)
3395 // g_free(job->x264opts);
3399 job->indepth_scan = 0;
3401 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3402 hb_add( h_queue, job );
3403 //if (job->x264opts != NULL)
3404 // g_free(job->x264opts);
3406 if (detel_str) g_free(detel_str);
3407 if (decomb_str) g_free(decomb_str);
3408 if (deint_str) g_free(deint_str);
3409 if (deblock_str) g_free(deblock_str);
3410 if (denoise_str) g_free(denoise_str);
3411 if (dest_str) g_free(dest_str);
3415 ghb_remove_job(gint unique_id)
3420 // Multiples passes all get the same id
3422 // Go backwards through list, so reordering doesn't screw me.
3423 ii = hb_count(h_queue) - 1;
3424 while ((job = hb_job(h_queue, ii--)) != NULL)
3426 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3427 hb_rem(h_queue, job);
3434 hb_start( h_queue );
3447 hb_get_state2( h_queue, &s );
3449 if( s.state == HB_STATE_PAUSED )
3451 hb_resume( h_queue );
3455 hb_pause( h_queue );
3459 #define RED_HEIGHT 720.0
3460 #define RED_WIDTH 1280.0
3463 ghb_get_preview_image(
3472 list = hb_get_titles( h_scan );
3473 if( !hb_list_count( list ) )
3475 /* No valid title, stop right there */
3478 title = hb_list_item( list, titleindex );
3479 if (title == NULL) return NULL;
3480 if (title->job == NULL) return NULL;
3481 set_preview_job_settings(title->job, settings);
3483 // hb_get_preview can't handle sizes that are larger than the original title
3485 if (title->job->width > title->width)
3486 title->job->width = title->width;
3488 if (title->job->height > title->height)
3489 title->job->height = title->height;
3490 // And also creates artifacts if the width is not a multiple of 8
3491 //title->job->width = ((title->job->width + 4) >> 3) << 3;
3492 // And the height must be a multiple of 2
3493 //title->job->height = ((title->job->height + 1) >> 1) << 1;
3495 // Make sure we have a big enough buffer to receive the image from libhb. libhb
3496 // creates images with a one-pixel border around the original content. Hence we
3497 // add 2 pixels horizontally and vertically to the buffer size.
3498 gint srcWidth = title->width + 2;
3499 gint srcHeight= title->height + 2;
3500 gint dstWidth = title->width;
3501 gint dstHeight= title->height;
3503 gint borderLeft = 1;
3506 // |<---------- title->width ----------->|
3507 // | |<---- title->job->width ---->| |
3509 // .......................................
3510 // ....+-----------------------------+....
3511 // ....| |....<-- gray border
3514 // ....| |<------- image
3520 // ....+-----------------------------+....
3521 // .......................................
3522 dstWidth = title->job->width;
3523 dstHeight = title->job->height;
3524 borderTop = (srcHeight - dstHeight) / 2;
3525 borderLeft = (srcWidth - dstWidth) / 2;
3526 g_debug("boarders removed\n");
3529 g_debug("src %d x %d\n", srcWidth, srcHeight);
3530 g_debug("dst %d x %d\n", dstWidth, dstHeight);
3531 g_debug("job dim %d x %d\n", title->job->width, title->job->height);
3532 g_debug("title crop %d:%d:%d:%d\n",
3537 g_debug("job crop %d:%d:%d:%d\n",
3538 title->job->crop[0],
3539 title->job->crop[1],
3540 title->job->crop[2],
3541 title->job->crop[3]);
3542 static guint8 *buffer = NULL;
3543 static gint bufferSize = 0;
3546 newSize = srcWidth * srcHeight * 4;
3547 if( bufferSize < newSize )
3549 bufferSize = newSize;
3550 buffer = (guint8*) g_realloc( buffer, bufferSize );
3552 hb_get_preview( h_scan, title, index, buffer );
3554 // Create an GdkPixbuf and copy the libhb image into it, converting it from
3555 // libhb's format something suitable. Along the way, we'll strip off the
3556 // border around libhb's image.
3558 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
3559 // Alpha is ignored.
3561 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
3562 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
3564 guint32 *src = (guint32*)buffer;
3565 guint8 *dst = pixels;
3566 src += borderTop * srcWidth; // skip top rows in src to get to first row of dst
3567 src += borderLeft; // skip left pixels in src to get to first pixel of dst
3569 gint channels = gdk_pixbuf_get_n_channels (preview);
3570 gint stride = gdk_pixbuf_get_rowstride (preview);
3572 for (ii = 0; ii < dstHeight; ii++)
3575 for (jj = 0; jj < dstWidth; jj++)
3577 tmp[0] = src[0] >> 16;
3578 tmp[1] = src[0] >> 8;
3579 tmp[2] = src[0] >> 0;
3584 src += (srcWidth - dstWidth); // skip to next row in src
3586 // Got it, but hb_get_preview doesn't compensate for anamorphic, so lets
3588 gint width, height, par_width, par_height;
3589 gboolean anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
3592 hb_set_anamorphic_size( title->job, &width, &height, &par_width, &par_height );
3593 if (par_width > par_height)
3594 dstWidth = dstWidth * par_width / par_height;
3596 dstHeight = dstHeight * par_height / par_width;
3598 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
3600 gdouble factor = 1.0;
3602 if (dstHeight > RED_HEIGHT)
3604 factor = RED_HEIGHT / (gdouble)dstHeight;
3606 if (dstWidth * factor > RED_WIDTH)
3608 factor = RED_WIDTH / (gdouble)dstWidth;
3610 dstHeight = dstHeight * factor + 0.5;
3611 dstWidth = dstWidth * factor + 0.5;
3614 g_debug("scaled %d x %d\n", dstWidth, dstHeight);
3615 GdkPixbuf *scaled_preview;
3616 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
3617 g_object_unref (preview);
3618 return scaled_preview;
3622 sanitize_volname(gchar *name)
3647 ghb_dvd_volname(const gchar *device)
3650 name = hb_dvd_name((gchar*)device);
3653 sanitize_volname(name);
3654 return g_strdup(name);