1 /***************************************************************************
4 * Fri Mar 28 10:38:44 2008
5 * Copyright 2008 John Stebbins
6 * <john at stebbins dot name>
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
29 #include <glib/gstdio.h>
30 #include "hb-backend.h"
32 #include "callbacks.h"
33 #include "subtitlehandler.h"
34 #include "x264handler.h"
42 const gchar *shortOpt;
53 static gchar **index_str = NULL;
54 static gint index_str_size = 0;
57 index_str_init(gint max_index)
61 if (max_index+1 > index_str_size)
63 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
64 for (ii = index_str_size; ii <= max_index; ii++)
66 index_str[ii] = g_strdup_printf("%d", ii);
68 index_str_size = max_index + 1;
72 static options_map_t d_par_opts[] =
75 {"Strict", "1", 1, "1"},
76 {"Loose", "2", 2, "2"},
77 {"Custom", "3", 3, "3"},
79 combo_opts_t par_opts =
81 sizeof(d_par_opts)/sizeof(options_map_t),
85 static options_map_t d_alignment_opts[] =
90 {"16", "16", 16, "16"},
92 combo_opts_t alignment_opts =
94 sizeof(d_alignment_opts)/sizeof(options_map_t),
98 static options_map_t d_logging_opts[] =
104 combo_opts_t logging_opts =
106 sizeof(d_logging_opts)/sizeof(options_map_t),
110 static options_map_t d_vqual_granularity_opts[] =
112 {"0.2", "0.2", 0.2, "0.2"},
113 {"0.25", "0.25", 0.25, "0.25"},
114 {"0.5", "0.5", 0.5, "0.5"},
117 combo_opts_t vqual_granularity_opts =
119 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
120 d_vqual_granularity_opts
123 static options_map_t d_container_opts[] =
125 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
126 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
127 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
129 combo_opts_t container_opts =
131 sizeof(d_container_opts)/sizeof(options_map_t),
135 static options_map_t d_detel_opts[] =
137 {"None", "none", 0, ""},
138 {"Custom", "custom", 1, ""},
139 {"Default","default",2, NULL},
141 combo_opts_t detel_opts =
143 sizeof(d_detel_opts)/sizeof(options_map_t),
147 static options_map_t d_decomb_opts[] =
149 {"None", "none", 0, ""},
150 {"Custom", "custom", 1, ""},
151 {"Default","default",2, NULL},
153 combo_opts_t decomb_opts =
155 sizeof(d_decomb_opts)/sizeof(options_map_t),
159 static options_map_t d_deint_opts[] =
161 {"None", "none", 0, ""},
162 {"Custom", "custom", 1, ""},
163 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
164 {"Slow", "slow", 3, "2:-1:-1:0:1"},
165 {"Slower", "slower", 4, "0:-1:-1:0:1"},
167 combo_opts_t deint_opts =
169 sizeof(d_deint_opts)/sizeof(options_map_t),
173 static options_map_t d_denoise_opts[] =
175 {"None", "none", 0, ""},
176 {"Custom", "custom", 1, ""},
177 {"Weak", "weak", 2, "2:1:2:3"},
178 {"Medium", "medium", 3, "3:2:2:3"},
179 {"Strong", "strong", 4, "7:7:5:5"},
181 combo_opts_t denoise_opts =
183 sizeof(d_denoise_opts)/sizeof(options_map_t),
187 static options_map_t d_vcodec_opts[] =
189 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
190 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
191 {"Theora", "theora", HB_VCODEC_THEORA, ""},
193 combo_opts_t vcodec_opts =
195 sizeof(d_vcodec_opts)/sizeof(options_map_t),
199 static options_map_t d_acodec_opts[] =
201 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
202 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
203 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
204 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
205 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
206 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
208 combo_opts_t acodec_opts =
210 sizeof(d_acodec_opts)/sizeof(options_map_t),
214 static options_map_t d_direct_opts[] =
216 {"None", "none", 0, "none"},
217 {"Spatial", "spatial", 1, "spatial"},
218 {"Temporal", "temporal", 2, "temporal"},
219 {"Automatic", "auto", 3, "auto"},
221 combo_opts_t direct_opts =
223 sizeof(d_direct_opts)/sizeof(options_map_t),
227 static options_map_t d_badapt_opts[] =
229 {"Off", "0", 0, "0"},
230 {"Fast", "1", 1, "1"},
231 {"Optimal", "2", 2, "2"},
233 combo_opts_t badapt_opts =
235 sizeof(d_badapt_opts)/sizeof(options_map_t),
239 static options_map_t d_me_opts[] =
241 {"Diamond", "dia", 0, "dia"},
242 {"Hexagon", "hex", 1, "hex"},
243 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
244 {"Exhaustive", "esa", 3, "esa"},
245 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
247 combo_opts_t me_opts =
249 sizeof(d_me_opts)/sizeof(options_map_t),
253 static options_map_t d_subme_opts[] =
265 combo_opts_t subme_opts =
267 sizeof(d_subme_opts)/sizeof(options_map_t),
271 static options_map_t d_analyse_opts[] =
273 {"Some", "some", 0, "some"},
274 {"None", "none", 1, "none"},
275 {"All", "all", 2, "all"},
276 {"Custom", "custom", 3, "all"},
278 combo_opts_t analyse_opts =
280 sizeof(d_analyse_opts)/sizeof(options_map_t),
284 static options_map_t d_trellis_opts[] =
286 {"Disabled", "0", 0, "0"},
287 {"Final Macro Block", "1", 1, "1"},
288 {"Always", "2", 2, "2"},
290 combo_opts_t trellis_opts =
292 sizeof(d_trellis_opts)/sizeof(options_map_t),
296 combo_opts_t subtitle_opts =
302 combo_opts_t title_opts =
308 combo_opts_t audio_track_opts =
320 combo_name_map_t combo_name_map[] =
322 {"PicturePAR", &par_opts},
323 {"PictureModulus", &alignment_opts},
324 {"LoggingLevel", &logging_opts},
325 {"VideoQualityGranularity", &vqual_granularity_opts},
326 {"FileFormat", &container_opts},
327 {"PictureDeinterlace", &deint_opts},
328 {"PictureDecomb", &decomb_opts},
329 {"PictureDetelecine", &detel_opts},
330 {"PictureDenoise", &denoise_opts},
331 {"VideoEncoder", &vcodec_opts},
332 {"AudioEncoder", &acodec_opts},
333 {"x264_direct", &direct_opts},
334 {"x264_b_adapt", &badapt_opts},
335 {"x264_me", &me_opts},
336 {"x264_subme", &subme_opts},
337 {"x264_analyse", &analyse_opts},
338 {"x264_trellis", &trellis_opts},
339 {"SubtitleTrack", &subtitle_opts},
340 {"title", &title_opts},
341 {"AudioTrack", &audio_track_opts},
346 typedef struct iso639_lang_t
348 char * eng_name; /* Description in English */
349 char * native_name; /* Description in native language */
350 char * iso639_1; /* ISO-639-1 (2 characters) code */
351 char * iso639_2; /* ISO-639-2/t (3 character) code */
352 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
356 const iso639_lang_t ghb_language_table[] =
358 { "Any", "", "zz", "und" },
359 { "Afar", "", "aa", "aar" },
360 { "Abkhazian", "", "ab", "abk" },
361 { "Afrikaans", "", "af", "afr" },
362 { "Akan", "", "ak", "aka" },
363 { "Albanian", "", "sq", "sqi", "alb" },
364 { "Amharic", "", "am", "amh" },
365 { "Arabic", "", "ar", "ara" },
366 { "Aragonese", "", "an", "arg" },
367 { "Armenian", "", "hy", "hye", "arm" },
368 { "Assamese", "", "as", "asm" },
369 { "Avaric", "", "av", "ava" },
370 { "Avestan", "", "ae", "ave" },
371 { "Aymara", "", "ay", "aym" },
372 { "Azerbaijani", "", "az", "aze" },
373 { "Bashkir", "", "ba", "bak" },
374 { "Bambara", "", "bm", "bam" },
375 { "Basque", "", "eu", "eus", "baq" },
376 { "Belarusian", "", "be", "bel" },
377 { "Bengali", "", "bn", "ben" },
378 { "Bihari", "", "bh", "bih" },
379 { "Bislama", "", "bi", "bis" },
380 { "Bosnian", "", "bs", "bos" },
381 { "Breton", "", "br", "bre" },
382 { "Bulgarian", "", "bg", "bul" },
383 { "Burmese", "", "my", "mya", "bur" },
384 { "Catalan", "", "ca", "cat" },
385 { "Chamorro", "", "ch", "cha" },
386 { "Chechen", "", "ce", "che" },
387 { "Chinese", "", "zh", "zho", "chi" },
388 { "Church Slavic", "", "cu", "chu" },
389 { "Chuvash", "", "cv", "chv" },
390 { "Cornish", "", "kw", "cor" },
391 { "Corsican", "", "co", "cos" },
392 { "Cree", "", "cr", "cre" },
393 { "Czech", "", "cs", "ces", "cze" },
394 { "Danish", "Dansk", "da", "dan" },
395 { "Divehi", "", "dv", "div" },
396 { "Dutch", "Nederlands", "nl", "nld", "dut" },
397 { "Dzongkha", "", "dz", "dzo" },
398 { "English", "English", "en", "eng" },
399 { "Esperanto", "", "eo", "epo" },
400 { "Estonian", "", "et", "est" },
401 { "Ewe", "", "ee", "ewe" },
402 { "Faroese", "", "fo", "fao" },
403 { "Fijian", "", "fj", "fij" },
404 { "Finnish", "Suomi", "fi", "fin" },
405 { "French", "Francais", "fr", "fra", "fre" },
406 { "Western Frisian", "", "fy", "fry" },
407 { "Fulah", "", "ff", "ful" },
408 { "Georgian", "", "ka", "kat", "geo" },
409 { "German", "Deutsch", "de", "deu", "ger" },
410 { "Gaelic (Scots)", "", "gd", "gla" },
411 { "Irish", "", "ga", "gle" },
412 { "Galician", "", "gl", "glg" },
413 { "Manx", "", "gv", "glv" },
414 { "Greek, Modern", "", "el", "ell", "gre" },
415 { "Guarani", "", "gn", "grn" },
416 { "Gujarati", "", "gu", "guj" },
417 { "Haitian", "", "ht", "hat" },
418 { "Hausa", "", "ha", "hau" },
419 { "Hebrew", "", "he", "heb" },
420 { "Herero", "", "hz", "her" },
421 { "Hindi", "", "hi", "hin" },
422 { "Hiri Motu", "", "ho", "hmo" },
423 { "Hungarian", "Magyar", "hu", "hun" },
424 { "Igbo", "", "ig", "ibo" },
425 { "Icelandic", "Islenska", "is", "isl", "ice" },
426 { "Ido", "", "io", "ido" },
427 { "Sichuan Yi", "", "ii", "iii" },
428 { "Inuktitut", "", "iu", "iku" },
429 { "Interlingue", "", "ie", "ile" },
430 { "Interlingua", "", "ia", "ina" },
431 { "Indonesian", "", "id", "ind" },
432 { "Inupiaq", "", "ik", "ipk" },
433 { "Italian", "Italiano", "it", "ita" },
434 { "Javanese", "", "jv", "jav" },
435 { "Japanese", "", "ja", "jpn" },
436 { "Kalaallisut", "", "kl", "kal" },
437 { "Kannada", "", "kn", "kan" },
438 { "Kashmiri", "", "ks", "kas" },
439 { "Kanuri", "", "kr", "kau" },
440 { "Kazakh", "", "kk", "kaz" },
441 { "Central Khmer", "", "km", "khm" },
442 { "Kikuyu", "", "ki", "kik" },
443 { "Kinyarwanda", "", "rw", "kin" },
444 { "Kirghiz", "", "ky", "kir" },
445 { "Komi", "", "kv", "kom" },
446 { "Kongo", "", "kg", "kon" },
447 { "Korean", "", "ko", "kor" },
448 { "Kuanyama", "", "kj", "kua" },
449 { "Kurdish", "", "ku", "kur" },
450 { "Lao", "", "lo", "lao" },
451 { "Latin", "", "la", "lat" },
452 { "Latvian", "", "lv", "lav" },
453 { "Limburgan", "", "li", "lim" },
454 { "Lingala", "", "ln", "lin" },
455 { "Lithuanian", "", "lt", "lit" },
456 { "Luxembourgish", "", "lb", "ltz" },
457 { "Luba-Katanga", "", "lu", "lub" },
458 { "Ganda", "", "lg", "lug" },
459 { "Macedonian", "", "mk", "mkd", "mac" },
460 { "Marshallese", "", "mh", "mah" },
461 { "Malayalam", "", "ml", "mal" },
462 { "Maori", "", "mi", "mri", "mao" },
463 { "Marathi", "", "mr", "mar" },
464 { "Malay", "", "ms", "msa", "msa" },
465 { "Malagasy", "", "mg", "mlg" },
466 { "Maltese", "", "mt", "mlt" },
467 { "Moldavian", "", "mo", "mol" },
468 { "Mongolian", "", "mn", "mon" },
469 { "Nauru", "", "na", "nau" },
470 { "Navajo", "", "nv", "nav" },
471 { "Ndebele, South", "", "nr", "nbl" },
472 { "Ndebele, North", "", "nd", "nde" },
473 { "Ndonga", "", "ng", "ndo" },
474 { "Nepali", "", "ne", "nep" },
475 { "Norwegian Nynorsk", "", "nn", "nno" },
476 { "Norwegian Bokmål", "", "nb", "nob" },
477 { "Norwegian", "Norsk", "no", "nor" },
478 { "Chichewa; Nyanja", "", "ny", "nya" },
479 { "Occitan", "", "oc", "oci" },
480 { "Ojibwa", "", "oj", "oji" },
481 { "Oriya", "", "or", "ori" },
482 { "Oromo", "", "om", "orm" },
483 { "Ossetian", "", "os", "oss" },
484 { "Panjabi", "", "pa", "pan" },
485 { "Persian", "", "fa", "fas", "per" },
486 { "Pali", "", "pi", "pli" },
487 { "Polish", "", "pl", "pol" },
488 { "Portuguese", "Portugues", "pt", "por" },
489 { "Pushto", "", "ps", "pus" },
490 { "Quechua", "", "qu", "que" },
491 { "Romansh", "", "rm", "roh" },
492 { "Romanian", "", "ro", "ron", "rum" },
493 { "Rundi", "", "rn", "run" },
494 { "Russian", "", "ru", "rus" },
495 { "Sango", "", "sg", "sag" },
496 { "Sanskrit", "", "sa", "san" },
497 { "Serbian", "", "sr", "srp", "scc" },
498 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
499 { "Sinhala", "", "si", "sin" },
500 { "Slovak", "", "sk", "slk", "slo" },
501 { "Slovenian", "", "sl", "slv" },
502 { "Northern Sami", "", "se", "sme" },
503 { "Samoan", "", "sm", "smo" },
504 { "Shona", "", "sn", "sna" },
505 { "Sindhi", "", "sd", "snd" },
506 { "Somali", "", "so", "som" },
507 { "Sotho, Southern", "", "st", "sot" },
508 { "Spanish", "Espanol", "es", "spa" },
509 { "Sardinian", "", "sc", "srd" },
510 { "Swati", "", "ss", "ssw" },
511 { "Sundanese", "", "su", "sun" },
512 { "Swahili", "", "sw", "swa" },
513 { "Swedish", "Svenska", "sv", "swe" },
514 { "Tahitian", "", "ty", "tah" },
515 { "Tamil", "", "ta", "tam" },
516 { "Tatar", "", "tt", "tat" },
517 { "Telugu", "", "te", "tel" },
518 { "Tajik", "", "tg", "tgk" },
519 { "Tagalog", "", "tl", "tgl" },
520 { "Thai", "", "th", "tha" },
521 { "Tibetan", "", "bo", "bod", "tib" },
522 { "Tigrinya", "", "ti", "tir" },
523 { "Tonga", "", "to", "ton" },
524 { "Tswana", "", "tn", "tsn" },
525 { "Tsonga", "", "ts", "tso" },
526 { "Turkmen", "", "tk", "tuk" },
527 { "Turkish", "", "tr", "tur" },
528 { "Twi", "", "tw", "twi" },
529 { "Uighur", "", "ug", "uig" },
530 { "Ukrainian", "", "uk", "ukr" },
531 { "Urdu", "", "ur", "urd" },
532 { "Uzbek", "", "uz", "uzb" },
533 { "Venda", "", "ve", "ven" },
534 { "Vietnamese", "", "vi", "vie" },
535 { "Volapük", "", "vo", "vol" },
536 { "Welsh", "", "cy", "cym", "wel" },
537 { "Walloon", "", "wa", "wln" },
538 { "Wolof", "", "wo", "wol" },
539 { "Xhosa", "", "xh", "xho" },
540 { "Yiddish", "", "yi", "yid" },
541 { "Yoruba", "", "yo", "yor" },
542 { "Zhuang", "", "za", "zha" },
543 { "Zulu", "", "zu", "zul" },
544 {NULL, NULL, NULL, NULL}
546 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
548 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
551 del_tree(const gchar *name, gboolean del_top)
555 if (g_file_test(name, G_FILE_TEST_IS_DIR))
557 GDir *gdir = g_dir_open(name, 0, NULL);
558 file = g_dir_read_name(gdir);
562 path = g_strdup_printf("%s/%s", name, file);
563 del_tree(path, TRUE);
565 file = g_dir_read_name(gdir);
580 return hb_get_version(NULL);
585 signal_user_data_t *ud,
593 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
602 *step = ghb_settings_combo_double(ud->settings,
603 "VideoQualityGranularity");
604 if (*step == 0.2 || *step == 0.5)
606 else if (*step == 0.25)
611 case HB_VCODEC_FFMPEG:
619 case HB_VCODEC_THEORA:
638 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
642 const gchar *result = "";
644 str = ghb_value_string(gval);
645 for (ii = 0; ii < opts->count; ii++)
647 if (strcmp(opts->map[ii].shortOpt, str) == 0)
649 result = opts->map[ii].svalue;
658 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
664 str = ghb_value_string(gval);
665 for (ii = 0; ii < opts->count; ii++)
667 if (strcmp(opts->map[ii].shortOpt, str) == 0)
669 result = opts->map[ii].ivalue;
678 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
684 str = ghb_value_string(gval);
685 for (ii = 0; ii < opts->count; ii++)
687 if (strcmp(opts->map[ii].shortOpt, str) == 0)
689 result = opts->map[ii].ivalue;
698 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
702 const gchar *result = "";
704 str = ghb_value_string(gval);
705 for (ii = 0; ii < opts->count; ii++)
707 if (strcmp(opts->map[ii].shortOpt, str) == 0)
709 result = opts->map[ii].option;
718 lookup_mix_int(const GValue *mix)
725 str = ghb_value_string(mix);
726 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
728 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
730 result = hb_audio_mixdowns[ii].amixdown;
739 lookup_mix_option(const GValue *mix)
743 gchar *result = "None";
746 str = ghb_value_string(mix);
747 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
749 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
751 result = hb_audio_mixdowns[ii].human_readable_name;
760 lookup_video_rate_int(const GValue *vrate)
766 str = ghb_value_string(vrate);
767 for (ii = 0; ii < hb_video_rates_count; ii++)
769 if (strcmp(hb_video_rates[ii].string, str) == 0)
771 result = hb_video_rates[ii].rate;
776 // Default to "same as source"
781 lookup_video_rate_option(const GValue *vrate)
785 const gchar *result = "Same as source";
787 str = ghb_value_string(vrate);
788 for (ii = 0; ii < hb_video_rates_count; ii++)
790 if (strcmp(hb_video_rates[ii].string, str) == 0)
792 result = hb_video_rates[ii].string;
797 // Default to "same as source"
802 lookup_audio_rate_int(const GValue *rate)
808 // Coincidentally, the string "source" will return 0
809 // which is our flag to use "same as source"
810 str = ghb_value_string(rate);
811 for (ii = 0; ii < hb_audio_rates_count; ii++)
813 if (strcmp(hb_audio_rates[ii].string, str) == 0)
815 result = hb_audio_rates[ii].rate;
824 lookup_audio_rate_option(const GValue *rate)
828 const gchar *result = "Same as source";
830 // Coincidentally, the string "source" will return 0
831 // which is our flag to use "same as source"
832 str = ghb_value_string(rate);
833 for (ii = 0; ii < hb_audio_rates_count; ii++)
835 if (strcmp(hb_audio_rates[ii].string, str) == 0)
837 result = hb_audio_rates[ii].string;
846 lookup_audio_bitrate_int(const GValue *rate)
852 // Coincidentally, the string "source" will return 0
853 // which is our flag to use "same as source"
854 str = ghb_value_string(rate);
855 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
857 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
859 result = hb_audio_bitrates[ii].rate;
868 lookup_audio_bitrate_option(const GValue *rate)
872 const gchar *result = "Same as source";
874 // Coincidentally, the string "source" will return 0
875 // which is our flag to use "same as source"
876 str = ghb_value_string(rate);
877 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
879 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
881 result = hb_audio_bitrates[ii].string;
890 lookup_audio_lang_int(const GValue *rate)
896 // Coincidentally, the string "source" will return 0
897 // which is our flag to use "same as source"
898 str = ghb_value_string(rate);
899 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
901 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
912 lookup_audio_lang_option(const GValue *rate)
916 const gchar *result = "Same as source";
918 // Coincidentally, the string "source" will return 0
919 // which is our flag to use "same as source"
920 str = ghb_value_string(rate);
921 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
923 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
925 result = ghb_language_table[ii].eng_name;
934 get_acodec_value(gint val)
936 GValue *value = NULL;
939 for (ii = 0; ii < acodec_opts.count; ii++)
941 if ((int)acodec_opts.map[ii].ivalue == val)
943 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
951 get_amix_value(gint val)
953 GValue *value = NULL;
956 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
958 if (hb_audio_mixdowns[ii].amixdown == val)
960 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
967 // Handle for libhb. Gets set by ghb_backend_init()
968 static hb_handle_t * h_scan = NULL;
969 static hb_handle_t * h_queue = NULL;
971 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
978 hb_get_tempory_directory(h_scan, dir);
979 return g_strdup(dir);
983 ghb_hb_cleanup(gboolean partial)
987 hb_get_tempory_directory(h_scan, dir);
988 del_tree(dir, !partial);
992 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1000 titleindex = ghb_settings_combo_int(ud->settings, "title");
1006 hb_subtitle_t * sub;
1008 if (h_scan == NULL) return VOBSUB;
1009 list = hb_get_titles( h_scan );
1010 if( !hb_list_count( list ) )
1012 /* No valid title, stop right there */
1015 title = hb_list_item( list, titleindex );
1016 if (title == NULL) return VOBSUB; // Bad titleindex
1017 sub = hb_list_item( title->list_subtitle, track);
1025 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1028 const gchar * name = "Unknown";
1041 titleindex = ghb_settings_combo_int(ud->settings, "title");
1047 hb_subtitle_t * sub;
1051 list = hb_get_titles( h_scan );
1052 if( !hb_list_count( list ) )
1055 title = hb_list_item( list, titleindex );
1059 sub = hb_list_item( title->list_subtitle, track);
1062 switch (sub->source)
1083 ghb_get_title_number(gint titleindex)
1088 if (h_scan == NULL) return 1;
1089 list = hb_get_titles( h_scan );
1090 if( !hb_list_count( list ) )
1092 /* No valid title, stop right there */
1095 title = hb_list_item( list, titleindex );
1096 if (title == NULL) return 1; // Bad titleindex
1097 return title->index;
1100 static hb_audio_config_t*
1101 get_hb_audio(gint titleindex, gint track)
1105 hb_audio_config_t *audio = NULL;
1107 if (h_scan == NULL) return NULL;
1108 list = hb_get_titles( h_scan );
1109 if( !hb_list_count( list ) )
1111 /* No valid title, stop right there */
1114 title = hb_list_item( list, titleindex );
1115 if (title == NULL) return NULL; // Bad titleindex
1116 if (!hb_list_count(title->list_audio))
1120 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1125 search_rates(hb_rate_t *rates, gint rate, gint count)
1128 for (ii = 0; ii < count; ii++)
1130 if (rates[ii].rate == rate)
1136 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1138 static GtkListStore*
1139 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1142 GtkListStore *store;
1144 g_debug("get_combo_box_store() %s\n", name);
1145 // First modify the combobox model to allow greying out of options
1146 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1147 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1152 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1154 GtkListStore *store;
1157 store = get_combo_box_store(builder, name);
1158 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1160 gtk_list_store_set(store, &iter,
1167 ghb_grey_combo_options(GtkBuilder *builder)
1170 gint container, track, titleindex, acodec;
1171 hb_audio_config_t *audio = NULL;
1174 widget = GHB_WIDGET (builder, "title");
1175 gval = ghb_widget_value(widget);
1176 titleindex = ghb_lookup_combo_int("title", gval);
1177 ghb_value_free(gval);
1178 widget = GHB_WIDGET (builder, "AudioTrack");
1179 gval = ghb_widget_value(widget);
1180 track = ghb_lookup_combo_int("AudioTrack", gval);
1181 ghb_value_free(gval);
1182 audio = get_hb_audio(titleindex, track);
1183 widget = GHB_WIDGET (builder, "FileFormat");
1184 gval = ghb_widget_value(widget);
1185 container = ghb_lookup_combo_int("FileFormat", gval);
1186 ghb_value_free(gval);
1188 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1189 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1190 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1191 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1193 gboolean allow_dca = TRUE;
1194 allow_dca = (container != HB_MUX_MP4);
1196 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1198 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1200 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1202 if (audio && audio->in.codec != HB_ACODEC_AC3)
1204 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1206 if (audio && audio->in.codec != HB_ACODEC_DCA)
1208 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1210 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1212 widget = GHB_WIDGET (builder, "AudioEncoder");
1213 gval = ghb_widget_value(widget);
1214 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1215 ghb_value_free(gval);
1216 if (acodec != HB_ACODEC_AC3)
1218 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1220 if (container == HB_MUX_MP4)
1222 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1223 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1224 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1226 else if (container == HB_MUX_AVI)
1228 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1229 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1230 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1232 else if (container == HB_MUX_OGM)
1234 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1237 gboolean allow_mono = TRUE;
1238 gboolean allow_stereo = TRUE;
1239 gboolean allow_dolby = TRUE;
1240 gboolean allow_dpl2 = TRUE;
1241 gboolean allow_6ch = TRUE;
1245 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1246 (acodec != HB_ACODEC_LAME);
1247 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1249 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1251 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1252 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1253 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1254 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1256 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1257 (acodec != HB_ACODEC_LAME) &&
1258 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1259 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1261 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1262 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1263 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1264 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1265 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1269 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1271 hb_audio_config_t *audio = NULL;
1272 gboolean allow_mono = TRUE;
1273 gboolean allow_stereo = TRUE;
1274 gboolean allow_dolby = TRUE;
1275 gboolean allow_dpl2 = TRUE;
1276 gboolean allow_6ch = TRUE;
1278 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1280 // Audio codec pass-thru. No mixdown
1283 audio = get_hb_audio(titleindex, track);
1287 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1288 (acodec != HB_ACODEC_LAME);
1289 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1291 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1293 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1294 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1295 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1296 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1298 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1299 (acodec != HB_ACODEC_LAME) &&
1300 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1301 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1303 gboolean greater = FALSE;
1306 // If no mix is specified, select the best available.
1307 mix = HB_AMIXDOWN_6CH;
1309 if (mix == HB_AMIXDOWN_6CH)
1312 if (allow_6ch) return HB_AMIXDOWN_6CH;
1314 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1317 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1319 if (mix == HB_AMIXDOWN_DOLBY || greater)
1322 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1324 if (mix == HB_AMIXDOWN_STEREO || greater)
1327 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1329 if (mix == HB_AMIXDOWN_MONO || greater)
1332 if (allow_mono) return HB_AMIXDOWN_MONO;
1334 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1335 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1336 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1337 if (allow_6ch) return HB_AMIXDOWN_6CH;
1341 // Set up the model for the combo box
1343 init_combo_box(GtkBuilder *builder, const gchar *name)
1346 GtkListStore *store;
1347 GtkCellRenderer *cell;
1349 g_debug("init_combo_box() %s\n", name);
1350 // First modify the combobox model to allow greying out of options
1351 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1355 // 1 - String to display
1356 // 2 - bool indicating whether the entry is selectable (grey or not)
1357 // 3 - String that is used for presets
1358 // 4 - Int value determined by backend
1359 // 5 - String value determined by backend
1360 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1361 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1362 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1364 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1366 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1367 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1368 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1369 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1370 "text", 0, "sensitive", 1, NULL);
1373 { // Combo box entry
1374 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1379 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1382 GtkListStore *store;
1385 g_debug("audio_samplerate_opts_set ()\n");
1386 store = get_combo_box_store(builder, name);
1387 gtk_list_store_clear(store);
1388 // Add an item for "Same As Source"
1389 gtk_list_store_append(store, &iter);
1390 gtk_list_store_set(store, &iter,
1391 0, "Same as source",
1397 for (ii = 0; ii < count; ii++)
1399 gtk_list_store_append(store, &iter);
1400 gtk_list_store_set(store, &iter,
1401 0, rates[ii].string,
1403 2, rates[ii].string,
1404 3, (gdouble)rates[ii].rate,
1405 4, rates[ii].string,
1411 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1414 GtkListStore *store;
1417 g_debug("video_rate_opts_set ()\n");
1418 store = get_combo_box_store(builder, name);
1419 gtk_list_store_clear(store);
1420 // Add an item for "Same As Source"
1421 gtk_list_store_append(store, &iter);
1422 gtk_list_store_set(store, &iter,
1423 0, "Same as source",
1429 for (ii = 0; ii < count; ii++)
1433 if (strcmp(rates[ii].string, "23.976") == 0)
1435 desc = "(NTSC Film)";
1437 else if (strcmp(rates[ii].string, "25") == 0)
1439 desc = "(PAL Film/Video)";
1441 else if (strcmp(rates[ii].string, "29.97") == 0)
1443 desc = "(NTSC Video)";
1445 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1446 gtk_list_store_append(store, &iter);
1447 gtk_list_store_set(store, &iter,
1450 2, rates[ii].string,
1451 3, (gdouble)rates[ii].rate,
1452 4, rates[ii].string,
1459 mix_opts_set(GtkBuilder *builder, const gchar *name)
1462 GtkListStore *store;
1465 g_debug("mix_opts_set ()\n");
1466 store = get_combo_box_store(builder, name);
1467 gtk_list_store_clear(store);
1468 gtk_list_store_append(store, &iter);
1469 gtk_list_store_set(store, &iter,
1476 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1478 gtk_list_store_append(store, &iter);
1479 gtk_list_store_set(store, &iter,
1480 0, hb_audio_mixdowns[ii].human_readable_name,
1482 2, hb_audio_mixdowns[ii].short_name,
1483 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1484 4, hb_audio_mixdowns[ii].internal_name,
1490 language_opts_set(GtkBuilder *builder, const gchar *name)
1493 GtkListStore *store;
1496 g_debug("language_opts_set ()\n");
1497 store = get_combo_box_store(builder, name);
1498 gtk_list_store_clear(store);
1499 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1501 gtk_list_store_append(store, &iter);
1502 gtk_list_store_set(store, &iter,
1503 0, ghb_language_table[ii].eng_name,
1505 2, ghb_language_table[ii].iso639_2,
1507 4, ghb_language_table[ii].iso639_1,
1512 static gchar **titles = NULL;
1515 title_opts_set(GtkBuilder *builder, const gchar *name)
1518 GtkListStore *store;
1519 hb_list_t * list = NULL;
1520 hb_title_t * title = NULL;
1524 g_debug("title_opts_set ()\n");
1525 store = get_combo_box_store(builder, name);
1526 gtk_list_store_clear(store);
1529 list = hb_get_titles( h_scan );
1530 count = hb_list_count( list );
1531 if (count > 100) count = 100;
1533 if (titles) g_strfreev(titles);
1534 if (title_opts.map) g_free(title_opts.map);
1537 title_opts.count = count;
1538 title_opts.map = g_malloc(count*sizeof(options_map_t));
1539 titles = g_malloc((count+1) * sizeof(gchar*));
1543 title_opts.count = 1;
1544 title_opts.map = g_malloc(sizeof(options_map_t));
1549 // No titles. Fill in a default.
1550 gtk_list_store_append(store, &iter);
1551 gtk_list_store_set(store, &iter,
1558 title_opts.map[0].option = "No Titles";
1559 title_opts.map[0].shortOpt = "none";
1560 title_opts.map[0].ivalue = -1;
1561 title_opts.map[0].svalue = "none";
1564 for (ii = 0; ii < count; ii++)
1566 title = (hb_title_t*)hb_list_item(list, ii);
1567 if (title->duration != 0)
1569 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1570 title->index, title->hours, title->minutes, title->seconds);
1574 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1576 gtk_list_store_append(store, &iter);
1577 gtk_list_store_set(store, &iter,
1584 title_opts.map[ii].option = titles[ii];
1585 title_opts.map[ii].shortOpt = titles[ii];
1586 title_opts.map[ii].ivalue = ii;
1587 title_opts.map[ii].svalue = titles[ii];
1593 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1596 gboolean foundit = FALSE;
1598 if (gtk_tree_model_get_iter_first (store, iter))
1602 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1603 if (value == (int)ivalue)
1608 } while (gtk_tree_model_iter_next (store, iter));
1614 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1617 GtkListStore *store;
1618 hb_list_t * list = NULL;
1619 hb_title_t * title = NULL;
1620 hb_audio_config_t * audio;
1624 g_debug("audio_track_opts_set ()\n");
1625 store = get_combo_box_store(builder, name);
1626 gtk_list_store_clear(store);
1629 list = hb_get_titles( h_scan );
1630 title = (hb_title_t*)hb_list_item( list, titleindex );
1633 count = hb_list_count( title->list_audio );
1636 if (count > 100) count = 100;
1637 if (audio_track_opts.map) g_free(audio_track_opts.map);
1640 audio_track_opts.count = count;
1641 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1645 audio_track_opts.count = 1;
1646 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1650 // No audio. set some default
1651 gtk_list_store_append(store, &iter);
1652 gtk_list_store_set(store, &iter,
1659 audio_track_opts.map[0].option = "No Audio";
1660 audio_track_opts.map[0].shortOpt = "none";
1661 audio_track_opts.map[0].ivalue = -1;
1662 audio_track_opts.map[0].svalue = "none";
1665 index_str_init(count-1);
1666 for (ii = 0; ii < count; ii++)
1668 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1669 gtk_list_store_append(store, &iter);
1670 gtk_list_store_set(store, &iter,
1671 0, audio->lang.description,
1677 audio_track_opts.map[ii].option = audio->lang.description,
1678 audio_track_opts.map[ii].shortOpt = index_str[ii];
1679 audio_track_opts.map[ii].ivalue = ii;
1680 audio_track_opts.map[ii].svalue = index_str[ii];
1685 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1688 GtkListStore *store;
1689 hb_list_t * list = NULL;
1690 hb_title_t * title = NULL;
1691 hb_subtitle_t * subtitle;
1693 static char ** options = NULL;
1695 g_debug("subtitle_track_opts_set ()\n");
1696 store = get_combo_box_store(builder, name);
1697 gtk_list_store_clear(store);
1700 list = hb_get_titles( h_scan );
1701 title = (hb_title_t*)hb_list_item( list, titleindex );
1704 count = hb_list_count( title->list_subtitle );
1707 if (count > 100) count = 100;
1708 if (subtitle_opts.map) g_free(subtitle_opts.map);
1711 subtitle_opts.count = count+1;
1712 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1716 subtitle_opts.count = LANG_TABLE_SIZE+1;
1717 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1719 gtk_list_store_append(store, &iter);
1720 gtk_list_store_set(store, &iter,
1721 0, "Foreign Audio Search",
1727 subtitle_opts.map[0].option = "Foreign Audio Search";
1728 subtitle_opts.map[0].shortOpt = "-1";
1729 subtitle_opts.map[0].ivalue = -1;
1730 subtitle_opts.map[0].svalue = "auto";
1733 if (options != NULL)
1734 g_strfreev(options);
1735 options = g_malloc((count+1)*sizeof(gchar*));
1736 index_str_init(count-1);
1737 for (ii = 0; ii < count; ii++)
1739 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1740 // Skip subtitles that must be burned if there is already
1741 // a burned subtitle in the list
1742 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1743 subtitle_opts.map[ii+1].option = options[ii];
1744 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1745 subtitle_opts.map[ii+1].ivalue = ii;
1746 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1747 gtk_list_store_append(store, &iter);
1748 gtk_list_store_set(store, &iter,
1753 4, subtitle->iso639_2,
1756 options[count] = NULL;
1760 index_str_init(LANG_TABLE_SIZE-1);
1761 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1763 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1764 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1765 subtitle_opts.map[ii+1].ivalue = ii;
1766 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1767 gtk_list_store_append(store, &iter);
1768 gtk_list_store_set(store, &iter,
1769 0, ghb_language_table[ii].eng_name,
1773 4, ghb_language_table[ii].iso639_2,
1786 guint64 longest = 0;
1787 gint titleindex = 0;
1789 g_debug("ghb_longest_title ()\n");
1790 if (h_scan == NULL) return 0;
1791 list = hb_get_titles( h_scan );
1792 count = hb_list_count( list );
1793 if (count > 100) count = 100;
1794 for (ii = 0; ii < count; ii++)
1796 title = (hb_title_t*)hb_list_item(list, ii);
1797 if (title->duration > longest)
1800 longest = title->duration;
1807 ghb_find_audio_track(
1811 GHashTable *track_indices)
1815 hb_audio_config_t * audio;
1822 g_debug("find_audio_track ()\n");
1823 if (h_scan == NULL) return -1;
1824 list = hb_get_titles( h_scan );
1825 title = (hb_title_t*)hb_list_item( list, titleindex );
1828 count = hb_list_count( title->list_audio );
1830 if (count > 10) count = 10;
1831 used = g_hash_table_lookup(track_indices, &acodec);
1834 used = g_malloc0(count * sizeof(gboolean));
1835 g_hash_table_insert(track_indices, &acodec, used);
1837 // Try to find an item that matches the preferred language and
1838 // the passthru codec type
1839 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1841 for (ii = 0; ii < count; ii++)
1848 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1849 title->list_audio, ii );
1850 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1851 audio->in.channel_layout);
1852 // Find a track that is not visually impaired or dirctor's
1853 // commentary, and has the highest channel count.
1854 if ((audio->in.codec & acodec) &&
1855 (audio->lang.type < 2) &&
1856 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1857 (strcmp(lang, "und") == 0)))
1859 if (channels > max_chan)
1862 max_chan = channels;
1872 // Try to find an item that matches the preferred language
1873 for (ii = 0; ii < count; ii++)
1877 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1878 title->list_audio, ii );
1879 // Find a track that is not visually impaired or dirctor's commentary
1880 if ((audio->lang.type < 2) &&
1881 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1882 (strcmp(lang, "und") == 0)))
1893 // Try to fine an item that does not match the preferred language and
1894 // matches the passthru codec type
1895 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1897 for (ii = 0; ii < count; ii++)
1904 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1905 title->list_audio, ii );
1906 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1907 audio->in.channel_layout);
1908 // Find a track that is not visually impaired or dirctor's
1909 // commentary, and has the highest channel count.
1910 if ((audio->in.codec & acodec) &&
1911 (audio->lang.type < 2))
1913 if (channels > max_chan)
1916 max_chan = channels;
1926 // Try to fine an item that does not match the preferred language
1927 for (ii = 0; ii < count; ii++)
1931 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1932 title->list_audio, ii );
1933 // Find a track that is not visually impaired or dirctor's commentary
1934 if (audio->lang.type < 2)
1945 // Last ditch, anything goes
1946 for (ii = 0; ii < count; ii++)
1948 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1949 title->list_audio, ii );
1964 ghb_find_pref_subtitle_track(const gchar *lang)
1967 count = subtitle_opts.count;
1968 for (ii = 0; ii < count; ii++)
1970 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
1972 return subtitle_opts.map[ii].ivalue;
1979 ghb_find_subtitle_track(
1982 GHashTable *track_indices)
1986 hb_subtitle_t * subtitle;
1990 g_debug("find_subtitle_track ()\n");
1991 if (strcmp(lang, "auto") == 0)
1993 if (h_scan == NULL) return -1;
1994 list = hb_get_titles( h_scan );
1995 title = (hb_title_t*)hb_list_item( list, titleindex );
1998 count = hb_list_count( title->list_subtitle );
1999 used = g_hash_table_lookup(track_indices, lang);
2002 used = g_malloc0(count * sizeof(gboolean));
2003 g_hash_table_insert(track_indices, g_strdup(lang), used);
2005 // Try to find an item that matches the preferred language
2006 for (ii = 0; ii < count; ii++)
2011 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2012 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2013 (strcmp(lang, "und") == 0))
2024 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2027 GtkListStore *store;
2030 g_debug("generic_opts_set ()\n");
2031 if (name == NULL || opts == NULL) return;
2032 store = get_combo_box_store(builder, name);
2033 gtk_list_store_clear(store);
2034 for (ii = 0; ii < opts->count; ii++)
2036 gtk_list_store_append(store, &iter);
2037 gtk_list_store_set(store, &iter,
2038 0, opts->map[ii].option,
2040 2, opts->map[ii].shortOpt,
2041 3, opts->map[ii].ivalue,
2042 4, opts->map[ii].svalue,
2048 find_combo_table(const gchar *name)
2052 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2054 if (strcmp(name, combo_name_map[ii].name) == 0)
2056 return combo_name_map[ii].opts;
2063 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2067 if (strcmp(name, "AudioBitrate") == 0)
2068 return lookup_audio_bitrate_int(gval);
2069 else if (strcmp(name, "AudioSamplerate") == 0)
2070 return lookup_audio_rate_int(gval);
2071 else if (strcmp(name, "VideoFramerate") == 0)
2072 return lookup_video_rate_int(gval);
2073 else if (strcmp(name, "AudioMixdown") == 0)
2074 return lookup_mix_int(gval);
2075 else if (strcmp(name, "SourceAudioLang") == 0)
2076 return lookup_audio_lang_int(gval);
2079 return lookup_generic_int(find_combo_table(name), gval);
2081 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2086 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2090 if (strcmp(name, "AudioBitrate") == 0)
2091 return lookup_audio_bitrate_int(gval);
2092 else if (strcmp(name, "AudioSamplerate") == 0)
2093 return lookup_audio_rate_int(gval);
2094 else if (strcmp(name, "VideoFramerate") == 0)
2095 return lookup_video_rate_int(gval);
2096 else if (strcmp(name, "AudioMixdown") == 0)
2097 return lookup_mix_int(gval);
2098 else if (strcmp(name, "SourceAudioLang") == 0)
2099 return lookup_audio_lang_int(gval);
2102 return lookup_generic_double(find_combo_table(name), gval);
2104 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2109 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2113 if (strcmp(name, "AudioBitrate") == 0)
2114 return lookup_audio_bitrate_option(gval);
2115 else if (strcmp(name, "AudioSamplerate") == 0)
2116 return lookup_audio_rate_option(gval);
2117 else if (strcmp(name, "VideoFramerate") == 0)
2118 return lookup_video_rate_option(gval);
2119 else if (strcmp(name, "AudioMixdown") == 0)
2120 return lookup_mix_option(gval);
2121 else if (strcmp(name, "SourceAudioLang") == 0)
2122 return lookup_audio_lang_option(gval);
2125 return lookup_generic_option(find_combo_table(name), gval);
2127 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2132 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2136 if (strcmp(name, "AudioBitrate") == 0)
2137 return lookup_audio_bitrate_option(gval);
2138 else if (strcmp(name, "AudioSamplerate") == 0)
2139 return lookup_audio_rate_option(gval);
2140 else if (strcmp(name, "VideoFramerate") == 0)
2141 return lookup_video_rate_option(gval);
2142 else if (strcmp(name, "AudioMixdown") == 0)
2143 return lookup_mix_option(gval);
2144 else if (strcmp(name, "SourceAudioLang") == 0)
2145 return lookup_audio_lang_option(gval);
2148 return lookup_generic_string(find_combo_table(name), gval);
2150 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2155 ghb_update_ui_combo_box(
2156 signal_user_data_t *ud,
2161 GtkComboBox *combo = NULL;
2163 gint handler_id = 0;
2167 g_debug("ghb_update_ui_combo_box() %s\n", name);
2168 // Clearing a combo box causes a rash of "changed" events, even when
2169 // the active item is -1 (inactive). To control things, I'm disabling
2170 // the event till things are settled down.
2171 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2172 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2175 // Valid signal id found. This should always succeed.
2176 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2177 signal_id, 0, 0, 0, 0);
2180 // This should also always succeed
2181 g_signal_handler_block ((gpointer)combo, handler_id);
2187 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2188 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2189 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2190 mix_opts_set(ud->builder, "AudioMixdown");
2191 language_opts_set(ud->builder, "SourceAudioLang");
2192 title_opts_set(ud->builder, "title");
2193 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2194 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2195 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2196 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2197 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2198 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2199 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2200 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2201 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2202 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2203 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2204 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2205 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2206 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2207 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2208 generic_opts_set(ud->builder, "x264_me", &me_opts);
2209 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2210 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2211 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2215 if (strcmp(name, "AudioBitrate") == 0)
2216 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2217 else if (strcmp(name, "AudioSamplerate") == 0)
2218 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2219 else if (strcmp(name, "VideoFramerate") == 0)
2220 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2221 else if (strcmp(name, "AudioMixdown") == 0)
2222 mix_opts_set(ud->builder, "AudioMixdown");
2223 else if (strcmp(name, "SourceAudioLang") == 0)
2224 language_opts_set(ud->builder, "SourceAudioLang");
2225 else if (strcmp(name, "title") == 0)
2226 title_opts_set(ud->builder, "title");
2227 else if (strcmp(name, "SubtitleTrack") == 0)
2228 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2229 else if (strcmp(name, "AudioTrack") == 0)
2230 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2232 generic_opts_set(ud->builder, name, find_combo_table(name));
2236 g_signal_handler_unblock ((gpointer)combo, handler_id);
2241 init_ui_combo_boxes(GtkBuilder *builder)
2245 init_combo_box(builder, "AudioBitrate");
2246 init_combo_box(builder, "AudioSamplerate");
2247 init_combo_box(builder, "VideoFramerate");
2248 init_combo_box(builder, "AudioMixdown");
2249 init_combo_box(builder, "SourceAudioLang");
2250 init_combo_box(builder, "title");
2251 init_combo_box(builder, "AudioTrack");
2252 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2254 init_combo_box(builder, combo_name_map[ii].name);
2258 static const char * turbo_opts =
2259 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2260 "no-fast-pskip=0:8x8dct=0";
2262 // Construct the x264 options string
2263 // The result is allocated, so someone must free it at some point.
2265 ghb_build_x264opts_string(GValue *settings)
2268 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2275 result = g_strdup("");
2281 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2285 hb_chapter_t * chapter;
2288 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2289 *hh = *mm = *ss = 0;
2290 if (h_scan == NULL) return;
2291 list = hb_get_titles( h_scan );
2292 title = (hb_title_t*)hb_list_item( list, ti );
2293 if (title == NULL) return;
2294 count = hb_list_count( title->list_chapter );
2295 if (ii >= count) return;
2296 chapter = hb_list_item(title->list_chapter, ii);
2297 if (chapter == NULL) return;
2298 *hh = chapter->hours;
2299 *mm = chapter->minutes;
2300 *ss = chapter->seconds;
2304 ghb_get_chapters(gint titleindex)
2308 hb_chapter_t * chapter;
2310 GValue *chapters = NULL;
2312 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2313 if (h_scan == NULL) return NULL;
2314 list = hb_get_titles( h_scan );
2315 title = (hb_title_t*)hb_list_item( list, titleindex );
2316 if (title == NULL) return NULL;
2317 count = hb_list_count( title->list_chapter );
2318 chapters = ghb_array_value_new(count);
2319 for (ii = 0; ii < count; ii++)
2321 chapter = hb_list_item(title->list_chapter, ii);
2322 if (chapter == NULL) break;
2323 if (chapter->title == NULL || chapter->title[0] == 0)
2326 str = g_strdup_printf ("Chapter %2d", ii+1);
2327 ghb_array_append(chapters, ghb_string_value_new(str));
2332 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2339 ghb_ac3_in_audio_list(const GValue *audio_list)
2343 count = ghb_array_len(audio_list);
2344 for (ii = 0; ii < count; ii++)
2349 asettings = ghb_array_get_nth(audio_list, ii);
2350 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2351 if (acodec == HB_ACODEC_AC3)
2358 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2361 GtkListStore *store;
2364 g_debug("audio_rate_opts_add ()\n");
2365 store = get_combo_box_store(builder, name);
2366 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2368 str = g_strdup_printf ("%d", rate);
2369 gtk_list_store_append(store, &iter);
2370 gtk_list_store_set(store, &iter,
2382 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2385 GtkListStore *store;
2387 gboolean done = FALSE;
2389 guint last = (guint)last_rate;
2391 g_debug("audio_bitrate_opts_clean ()\n");
2392 store = get_combo_box_store(builder, name);
2393 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2397 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2399 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2401 done = !gtk_list_store_remove(store, &iter);
2403 else if (ivalue > last)
2406 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2407 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2412 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2413 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2420 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2423 GtkListStore *store;
2426 g_debug("audio_bitrate_opts_set ()\n");
2427 store = get_combo_box_store(builder, name);
2428 gtk_list_store_clear(store);
2429 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2431 gtk_list_store_append(store, &iter);
2432 gtk_list_store_set(store, &iter,
2433 0, hb_audio_bitrates[ii].string,
2435 2, hb_audio_bitrates[ii].string,
2436 3, (gdouble)hb_audio_bitrates[ii].rate,
2437 4, hb_audio_bitrates[ii].string,
2443 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2445 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2449 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2451 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2454 static ghb_status_t hb_status;
2457 ghb_combo_init(signal_user_data_t *ud)
2459 // Set up the list model for the combos
2460 init_ui_combo_boxes(ud->builder);
2461 // Populate all the combos
2462 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2466 ghb_backend_init(gint debug)
2469 h_scan = hb_init( debug, 0 );
2470 h_queue = hb_init( debug, 0 );
2481 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2483 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2484 hb_status.scan.state |= GHB_STATE_SCANNING;
2485 // initialize count and cur to something that won't cause FPE
2486 // when computing progress
2487 hb_status.scan.title_count = 1;
2488 hb_status.scan.title_cur = 0;
2492 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2494 g_debug("ghb_backend_queue_scan()");
2495 hb_scan( h_queue, path, titlenum, 10, 0 );
2496 hb_status.queue.state |= GHB_STATE_SCANNING;
2500 ghb_get_scan_state()
2502 return hb_status.scan.state;
2506 ghb_get_queue_state()
2508 return hb_status.queue.state;
2512 ghb_clear_scan_state(gint state)
2514 hb_status.scan.state &= ~state;
2518 ghb_clear_queue_state(gint state)
2520 hb_status.queue.state &= ~state;
2524 ghb_set_scan_state(gint state)
2526 hb_status.scan.state |= state;
2530 ghb_set_queue_state(gint state)
2532 hb_status.queue.state |= state;
2536 ghb_get_status(ghb_status_t *status)
2538 memcpy(status, &hb_status, sizeof(ghb_status_t));
2547 if (h_scan == NULL) return;
2548 hb_get_state( h_scan, &s_scan );
2549 switch( s_scan.state )
2551 #define p s_scan.param.scanning
2552 case HB_STATE_SCANNING:
2554 hb_status.scan.state |= GHB_STATE_SCANNING;
2555 hb_status.scan.title_count = p.title_count;
2556 hb_status.scan.title_cur = p.title_cur;
2560 case HB_STATE_SCANDONE:
2562 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2563 hb_status.scan.state |= GHB_STATE_SCANDONE;
2566 #define p s_scan.param.working
2567 case HB_STATE_WORKING:
2568 hb_status.scan.state |= GHB_STATE_WORKING;
2569 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2570 hb_status.scan.job_cur = p.job_cur;
2571 hb_status.scan.job_count = p.job_count;
2572 hb_status.scan.progress = p.progress;
2573 hb_status.scan.rate_cur = p.rate_cur;
2574 hb_status.scan.rate_avg = p.rate_avg;
2575 hb_status.scan.hours = p.hours;
2576 hb_status.scan.minutes = p.minutes;
2577 hb_status.scan.seconds = p.seconds;
2578 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2582 case HB_STATE_PAUSED:
2583 hb_status.scan.state |= GHB_STATE_PAUSED;
2586 case HB_STATE_MUXING:
2588 hb_status.scan.state |= GHB_STATE_MUXING;
2591 #define p s_scan.param.workdone
2592 case HB_STATE_WORKDONE:
2596 hb_status.scan.state |= GHB_STATE_WORKDONE;
2597 hb_status.scan.state &= ~GHB_STATE_MUXING;
2598 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2599 hb_status.scan.state &= ~GHB_STATE_WORKING;
2603 hb_status.scan.error = GHB_ERROR_NONE;
2605 case HB_ERROR_CANCELED:
2606 hb_status.scan.error = GHB_ERROR_CANCELED;
2609 hb_status.scan.error = GHB_ERROR_FAIL;
2612 // Delete all remaining jobs of this encode.
2613 // An encode can be composed of multiple associated jobs.
2614 // When a job is stopped, libhb removes it from the job list,
2615 // but does not remove other jobs that may be associated with it.
2616 // Associated jobs are taged in the sequence id.
2617 while ((job = hb_job(h_scan, 0)) != NULL)
2618 hb_rem( h_scan, job );
2622 hb_get_state( h_queue, &s_queue );
2623 switch( s_queue.state )
2625 #define p s_queue.param.scanning
2626 case HB_STATE_SCANNING:
2628 hb_status.queue.state |= GHB_STATE_SCANNING;
2629 hb_status.queue.title_count = p.title_count;
2630 hb_status.queue.title_cur = p.title_cur;
2634 case HB_STATE_SCANDONE:
2636 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2637 hb_status.queue.state |= GHB_STATE_SCANDONE;
2640 #define p s_queue.param.working
2641 case HB_STATE_WORKING:
2642 hb_status.queue.state |= GHB_STATE_WORKING;
2643 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2644 hb_status.queue.job_cur = p.job_cur;
2645 hb_status.queue.job_count = p.job_count;
2646 hb_status.queue.progress = p.progress;
2647 hb_status.queue.rate_cur = p.rate_cur;
2648 hb_status.queue.rate_avg = p.rate_avg;
2649 hb_status.queue.hours = p.hours;
2650 hb_status.queue.minutes = p.minutes;
2651 hb_status.queue.seconds = p.seconds;
2652 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2656 case HB_STATE_PAUSED:
2657 hb_status.queue.state |= GHB_STATE_PAUSED;
2660 case HB_STATE_MUXING:
2662 hb_status.queue.state |= GHB_STATE_MUXING;
2665 #define p s_queue.param.workdone
2666 case HB_STATE_WORKDONE:
2670 hb_status.queue.state |= GHB_STATE_WORKDONE;
2671 hb_status.queue.state &= ~GHB_STATE_MUXING;
2672 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2673 hb_status.queue.state &= ~GHB_STATE_WORKING;
2677 hb_status.queue.error = GHB_ERROR_NONE;
2679 case HB_ERROR_CANCELED:
2680 hb_status.queue.error = GHB_ERROR_CANCELED;
2683 hb_status.queue.error = GHB_ERROR_FAIL;
2686 // Delete all remaining jobs of this encode.
2687 // An encode can be composed of multiple associated jobs.
2688 // When a job is stopped, libhb removes it from the job list,
2689 // but does not remove other jobs that may be associated with it.
2690 // Associated jobs are taged in the sequence id.
2691 while ((job = hb_job(h_queue, 0)) != NULL)
2692 hb_rem( h_queue, job );
2699 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2704 if (h_scan == NULL) return FALSE;
2705 list = hb_get_titles( h_scan );
2706 if( !hb_list_count( list ) )
2708 /* No valid title, stop right there */
2712 title = hb_list_item( list, titleindex );
2713 if (title == NULL) return FALSE; // Bad titleindex
2714 tinfo->width = title->width;
2715 tinfo->height = title->height;
2716 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2717 // Don't allow crop to 0
2718 if (title->crop[0] + title->crop[1] >= title->height)
2719 title->crop[0] = title->crop[1] = 0;
2720 if (title->crop[2] + title->crop[3] >= title->width)
2721 title->crop[2] = title->crop[3] = 0;
2722 tinfo->num_chapters = hb_list_count(title->list_chapter);
2723 tinfo->rate_base = title->rate_base;
2724 tinfo->rate = title->rate;
2725 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2726 title->width * title->pixel_aspect_width,
2727 title->height * title->pixel_aspect_height);
2728 tinfo->hours = title->hours;
2729 tinfo->minutes = title->minutes;
2730 tinfo->seconds = title->seconds;
2731 tinfo->duration = title->duration;
2733 tinfo->angle_count = title->angle_count;
2738 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2740 hb_audio_config_t *audio;
2742 audio = get_hb_audio(titleindex, audioindex);
2743 if (audio == NULL) return FALSE; // Bad audioindex
2744 ainfo->codec = audio->in.codec;
2745 ainfo->bitrate = audio->in.bitrate;
2746 ainfo->samplerate = audio->in.samplerate;
2751 ghb_audio_is_passthru(gint acodec)
2753 g_debug("ghb_audio_is_passthru () \n");
2754 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2758 ghb_get_default_acodec()
2760 return HB_ACODEC_FAAC;
2764 picture_settings_deps(signal_user_data_t *ud)
2766 gboolean autoscale, keep_aspect, enable_keep_aspect;
2767 gboolean enable_scale_width, enable_scale_height;
2768 gboolean enable_disp_width, enable_disp_height;
2772 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2775 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2776 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2777 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2779 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2780 if (!enable_keep_aspect)
2782 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2784 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2785 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2787 enable_scale_width = !autoscale && (pic_par != 1);
2788 enable_scale_height = !autoscale && (pic_par != 1);
2789 enable_disp_width = (pic_par == 3) && !keep_aspect;
2790 enable_disp_height = FALSE;
2792 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2793 gtk_widget_set_sensitive(widget, pic_par != 1);
2794 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2795 gtk_widget_set_sensitive(widget, pic_par != 1);
2796 widget = GHB_WIDGET(ud->builder, "scale_width");
2797 gtk_widget_set_sensitive(widget, enable_scale_width);
2798 widget = GHB_WIDGET(ud->builder, "scale_height");
2799 gtk_widget_set_sensitive(widget, enable_scale_height);
2800 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2801 gtk_widget_set_sensitive(widget, enable_disp_width);
2802 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2803 gtk_widget_set_sensitive(widget, enable_disp_height);
2804 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2805 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2806 widget = GHB_WIDGET(ud->builder, "autoscale");
2807 gtk_widget_set_sensitive(widget, pic_par != 1);
2811 ghb_set_scale(signal_user_data_t *ud, gint mode)
2816 gboolean keep_aspect;
2818 gboolean autocrop, autoscale, noscale;
2819 gint crop[4], width, height, par_width, par_height;
2820 gint crop_width, crop_height;
2821 gint aspect_n, aspect_d;
2822 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2823 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2828 gint max_height = 0;
2829 static gboolean busy = FALSE;
2831 g_debug("ghb_set_scale ()\n");
2832 if (h_scan == NULL) return;
2833 list = hb_get_titles( h_scan );
2834 if( !hb_list_count( list ) )
2836 /* No valid title, stop right there */
2841 titleindex = ghb_settings_combo_int(ud->settings, "title");
2842 title = hb_list_item( list, titleindex );
2843 if (title == NULL) return;
2845 if (job == NULL) return;
2847 picture_settings_deps(ud);
2852 // First configure widgets
2853 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2854 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2855 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2856 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2857 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2858 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2859 // alignment constraints rather than scaling to satisfy them.
2860 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2861 // Align dimensions to either 16 or 2 pixels
2862 // The scaler crashes if the dimensions are not divisible by 2
2863 // x264 also will not accept dims that are not multiple of 2
2867 keep_height = FALSE;
2869 // Step needs to be at least 2 because odd widths cause scaler crash
2871 widget = GHB_WIDGET (ud->builder, "scale_width");
2872 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2873 widget = GHB_WIDGET (ud->builder, "scale_height");
2874 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2877 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2878 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2879 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2880 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2881 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2882 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2883 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2884 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2888 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2889 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2890 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2891 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2892 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2893 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2894 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2895 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2897 ghb_title_info_t tinfo;
2898 ghb_get_title_info (&tinfo, titleindex);
2901 crop[0] = tinfo.crop[0];
2902 crop[1] = tinfo.crop[1];
2903 crop[2] = tinfo.crop[2];
2904 crop[3] = tinfo.crop[3];
2905 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2906 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2907 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2908 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2912 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2913 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2914 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2915 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2921 // Adjust the cropping to accomplish the desired width and height
2922 crop_width = tinfo.width - crop[2] - crop[3];
2923 crop_height = tinfo.height - crop[0] - crop[1];
2924 width = MOD_DOWN(crop_width, mod);
2925 height = MOD_DOWN(crop_height, mod);
2927 need1 = (crop_height - height) / 2;
2928 need2 = crop_height - height - need1;
2931 need1 = (crop_width - width) / 2;
2932 need2 = crop_width - width - need1;
2935 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2936 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2937 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2938 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2940 hb_reduce(&aspect_n, &aspect_d,
2941 title->width * title->pixel_aspect_width,
2942 title->height * title->pixel_aspect_height);
2943 crop_width = title->width - crop[2] - crop[3];
2944 crop_height = title->height - crop[0] - crop[1];
2948 height = crop_height;
2952 width = ghb_settings_get_int(ud->settings, "scale_width");
2953 height = ghb_settings_get_int(ud->settings, "scale_height");
2954 max_width = MOD_DOWN(
2955 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
2956 max_height = MOD_DOWN(
2957 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
2959 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2962 width = title->width - crop[2] - crop[3];
2964 height = title->height - crop[0] - crop[1];
2966 width = MOD_ROUND(width, mod);
2967 height = MOD_ROUND(height, mod);
2969 // Adjust dims according to max values
2971 height = MIN(height, max_height);
2973 width = MIN(width, max_width);
2977 job->anamorphic.mode = pic_par;
2978 // The scaler crashes if the dimensions are not divisible by 2
2979 // Align mod 2. And so does something in x264_encoder_headers()
2980 job->anamorphic.modulus = mod;
2981 if (keep_height && pic_par == 2)
2982 width = ((double)height * crop_width / crop_height) + 0.5;
2984 job->height = height;
2986 job->maxWidth = max_width;
2988 job->maxHeight = max_height;
2989 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2990 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2991 if (job->anamorphic.mode == 3 && !keep_aspect)
2993 gint dar_width, dar_height;
2994 if (mode & GHB_PIC_KEEP_PAR)
2996 par_width = ghb_settings_get_int(ud->settings,
2998 par_height = ghb_settings_get_int(ud->settings,
2999 "PicturePARHeight");
3000 dar_width = ((gdouble)width * par_width / par_height) + 0.5;
3001 dar_height = height;
3005 dar_width = ghb_settings_get_int(ud->settings,
3006 "PictureDisplayWidth");
3007 dar_height = ghb_settings_get_int(ud->settings,
3008 "PictureDisplayHeight");
3010 job->anamorphic.dar_width = dar_width;
3011 job->anamorphic.dar_height = dar_height;
3012 job->anamorphic.keep_display_aspect = 0;
3016 job->anamorphic.dar_width = 0;
3017 job->anamorphic.dar_height = 0;
3018 job->anamorphic.keep_display_aspect = 1;
3020 hb_set_anamorphic_size( job, &width, &height,
3021 &par_width, &par_height );
3025 job->anamorphic.mode = pic_par;
3029 gint new_width, new_height;
3031 // Compute pixel aspect ration.
3032 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3033 // Must scale so that par becomes 1:1
3034 // Try to keep largest dimension
3035 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3036 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3038 if (max_width && new_width > max_width)
3040 height = new_height;
3042 else if (max_height && new_height > max_height)
3046 else if (keep_width)
3048 height = new_height;
3050 else if (keep_height)
3054 else if (width > new_width)
3056 height = new_height;
3062 g_debug("new w %d h %d\n", width, height);
3064 width = MOD_ROUND(width, mod);
3065 height = MOD_ROUND(height, mod);
3067 height = MIN(height, max_height);
3069 width = MIN(width, max_width);
3070 par_width = par_height = 1;
3072 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3073 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3075 gint disp_width, dar_width, dar_height;
3078 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3079 hb_reduce(&dar_width, &dar_height, disp_width, height);
3081 gint iaspect = dar_width * 9 / dar_height;
3082 if (dar_width > 2 * dar_height)
3084 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3086 else if (iaspect <= 16 && iaspect >= 15)
3088 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3090 else if (iaspect <= 12 && iaspect >= 11)
3092 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3096 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3098 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3100 ghb_ui_update(ud, "par_width", ghb_int64_value(par_width));
3101 ghb_ui_update(ud, "par_height", ghb_int64_value(par_height));
3102 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3103 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3108 set_preview_job_settings(hb_job_t *job, GValue *settings)
3110 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3111 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3112 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3113 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3115 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3116 job->anamorphic.modulus =
3117 ghb_settings_combo_int(settings, "PictureModulus");
3118 job->width = ghb_settings_get_int(settings, "scale_width");
3119 job->height = ghb_settings_get_int(settings, "scale_height");
3120 if (ghb_settings_get_boolean(settings, "show_crop"))
3122 gdouble xscale = (gdouble)job->width /
3123 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3124 gdouble yscale = (gdouble)job->height /
3125 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3127 job->width += xscale * (job->crop[2] + job->crop[3]);
3128 job->height += yscale * (job->crop[0] + job->crop[1]);
3133 job->anamorphic.modulus = 2;
3136 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3137 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3138 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3140 gboolean keep_aspect;
3141 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3142 if (job->anamorphic.mode == 3 && !keep_aspect)
3144 gint disp_width, disp_height;
3145 disp_width = ghb_settings_get_int(settings, "PictureDisplayWidth");
3146 disp_height = ghb_settings_get_int(settings, "PictureDisplayHeight");
3147 job->anamorphic.dar_width = disp_width;
3148 job->anamorphic.dar_height = disp_height;
3149 job->anamorphic.keep_display_aspect = 0;
3153 job->anamorphic.keep_display_aspect = 1;
3154 job->anamorphic.dar_width = 0;
3155 job->anamorphic.dar_height = 0;
3160 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3167 if (h_scan == NULL) return 1500;
3168 list = hb_get_titles( h_scan );
3169 title = hb_list_item( list, titleindex );
3170 if (title == NULL) return 1500;
3172 if (job == NULL) return 1500;
3173 size = ghb_settings_get_int(settings, "VideoTargetSize");
3174 return hb_calc_bitrate( job, size );
3178 ghb_validate_filter_string(const gchar *str, gint max_fields)
3184 if (str == NULL || *str == 0) return TRUE;
3187 val = g_strtod(str, &end);
3189 { // Found a numeric value
3191 // negative max_fields means infinate
3192 if (max_fields >= 0 && fields > max_fields) return FALSE;
3206 ghb_validate_filters(signal_user_data_t *ud)
3213 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3216 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3217 if (!ghb_validate_filter_string(str, 4))
3219 message = g_strdup_printf(
3220 "Invalid Deinterlace Settings:\n\n%s\n",
3222 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3230 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3233 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3234 if (!ghb_validate_filter_string(str, 6))
3236 message = g_strdup_printf(
3237 "Invalid Detelecine Settings:\n\n%s\n",
3239 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3247 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3250 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3251 if (!ghb_validate_filter_string(str, 7))
3253 message = g_strdup_printf(
3254 "Invalid Decomb Settings:\n\n%s\n",
3256 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3264 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3267 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3268 if (!ghb_validate_filter_string(str, 4))
3270 message = g_strdup_printf(
3271 "Invalid Denoise Settings:\n\n%s\n",
3273 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3284 ghb_validate_video(signal_user_data_t *ud)
3289 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3290 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3291 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3292 (vcodec == HB_VCODEC_THEORA))
3294 // mp4|avi/theora combination is not supported.
3295 message = g_strdup_printf(
3296 "Theora is not supported in the MP4 and AVI containers.\n\n"
3297 "You should choose a different video codec or container.\n"
3298 "If you continue, FFMPEG will be chosen for you.");
3299 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3305 vcodec = HB_VCODEC_FFMPEG;
3306 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3312 ghb_validate_subtitles(signal_user_data_t *ud)
3318 if (h_scan == NULL) return FALSE;
3319 list = hb_get_titles( h_scan );
3320 if( !hb_list_count( list ) )
3322 /* No valid title, stop right there */
3323 g_message("No title found.\n");
3329 titleindex = ghb_settings_combo_int(ud->settings, "title");
3330 title = hb_list_item( list, titleindex );
3331 if (title == NULL) return FALSE;
3332 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3334 const GValue *slist, *settings;
3335 gint count, ii, track, source;
3336 gboolean burned, one_burned = FALSE;
3338 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3339 count = ghb_array_len(slist);
3340 for (ii = 0; ii < count; ii++)
3342 settings = ghb_array_get_nth(slist, ii);
3343 track = ghb_settings_combo_int(settings, "SubtitleTrack");
3344 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3345 source = ghb_subtitle_track_source(ud, track);
3346 if (burned && one_burned)
3348 // MP4 can only handle burned vobsubs. make sure there isn't
3349 // already something burned in the list
3350 message = g_strdup_printf(
3351 "Only one subtitle may be burned into the video.\n\n"
3352 "You should change your subtitle selections.\n"
3353 "If you continue, some subtitles will be lost.");
3354 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3366 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3368 // MP4 can only handle burned vobsubs. make sure there isn't
3369 // already something burned in the list
3370 message = g_strdup_printf(
3371 "Your chosen container does not support soft bitmap subtitles.\n\n"
3372 "You should change your subtitle selections.\n"
3373 "If you continue, some subtitles will be lost.");
3374 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3387 ghb_validate_audio(signal_user_data_t *ud)
3394 if (h_scan == NULL) return FALSE;
3395 list = hb_get_titles( h_scan );
3396 if( !hb_list_count( list ) )
3398 /* No valid title, stop right there */
3399 g_message("No title found.\n");
3405 titleindex = ghb_settings_combo_int(ud->settings, "title");
3406 title = hb_list_item( list, titleindex );
3407 if (title == NULL) return FALSE;
3408 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3410 const GValue *audio_list;
3413 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3414 count = ghb_array_len(audio_list);
3415 for (ii = 0; ii < count; ii++)
3418 hb_audio_config_t *taudio;
3420 asettings = ghb_array_get_nth(audio_list, ii);
3421 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3422 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3423 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3424 title->list_audio, track );
3425 if (!(taudio->in.codec & codec) &&
3426 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3428 // Not supported. AC3 is passthrough only, so input must be AC3
3429 message = g_strdup_printf(
3430 "The source does not support Pass-Thru.\n\n"
3431 "You should choose a different audio codec.\n"
3432 "If you continue, one will be chosen for you.");
3433 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3439 if (mux == HB_MUX_AVI)
3441 codec = HB_ACODEC_LAME;
3445 codec = HB_ACODEC_FAAC;
3447 value = get_acodec_value(codec);
3448 ghb_settings_take_value(asettings, "AudioEncoder", value);
3450 gchar *a_unsup = NULL;
3451 gchar *mux_s = NULL;
3452 if (mux == HB_MUX_MP4)
3455 // mp4/mp3|vorbis combination is not supported.
3456 if (codec == HB_ACODEC_LAME)
3459 codec = HB_ACODEC_FAAC;
3461 if (codec == HB_ACODEC_VORBIS)
3464 codec = HB_ACODEC_FAAC;
3466 if (codec == HB_ACODEC_DCA)
3469 codec = HB_ACODEC_FAAC;
3472 else if (mux == HB_MUX_AVI)
3475 // avi/faac|vorbis combination is not supported.
3476 if (codec == HB_ACODEC_FAAC)
3479 codec = HB_ACODEC_LAME;
3481 if (codec == HB_ACODEC_VORBIS)
3484 codec = HB_ACODEC_LAME;
3487 else if (mux == HB_MUX_OGM)
3490 // avi/faac|vorbis combination is not supported.
3491 if (codec == HB_ACODEC_FAAC)
3494 codec = HB_ACODEC_VORBIS;
3496 if (codec == HB_ACODEC_AC3)
3499 codec = HB_ACODEC_VORBIS;
3501 if (codec == HB_ACODEC_DCA)
3504 codec = HB_ACODEC_VORBIS;
3509 message = g_strdup_printf(
3510 "%s is not supported in the %s container.\n\n"
3511 "You should choose a different audio codec.\n"
3512 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3513 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3519 value = get_acodec_value(codec);
3520 ghb_settings_take_value(asettings, "AudioEncoder", value);
3522 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3523 gboolean allow_mono = TRUE;
3524 gboolean allow_stereo = TRUE;
3525 gboolean allow_dolby = TRUE;
3526 gboolean allow_dpl2 = TRUE;
3527 gboolean allow_6ch = TRUE;
3529 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3530 (codec != HB_ACODEC_LAME);
3531 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3533 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3535 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3536 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3537 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3538 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3540 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3541 (codec != HB_ACODEC_LAME) &&
3542 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3543 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3545 gchar *mix_unsup = NULL;
3546 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3550 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3552 mix_unsup = "stereo";
3554 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3556 mix_unsup = "Dolby";
3558 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3560 mix_unsup = "Dolby Pro Logic II";
3562 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3564 mix_unsup = "6 Channel";
3568 message = g_strdup_printf(
3569 "The source audio does not support %s mixdown.\n\n"
3570 "You should choose a different mixdown.\n"
3571 "If you continue, one will be chosen for you.", mix_unsup);
3572 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3578 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3579 value = get_amix_value(mix);
3580 ghb_settings_take_value(asettings, "AudioMixdown", value);
3587 ghb_validate_vquality(GValue *settings)
3593 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3594 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3596 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3597 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3601 case HB_VCODEC_X264:
3607 case HB_VCODEC_FFMPEG:
3613 case HB_VCODEC_THEORA:
3625 if (vquality < min || vquality > max)
3627 message = g_strdup_printf(
3628 "Interesting video quality choise: %d\n\n"
3629 "Typical values range from %d to %d.\n"
3630 "Are you sure you wish to use this setting?",
3631 (gint)vquality, min, max);
3632 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3633 "Cancel", "Continue"))
3645 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3650 static gchar *x264opts;
3652 gboolean tweaks = FALSE;
3653 gchar *detel_str = NULL;
3654 gchar *decomb_str = NULL;
3655 gchar *deint_str = NULL;
3656 gchar *deblock_str = NULL;
3657 gchar *denoise_str = NULL;
3658 gchar *dest_str = NULL;
3660 g_debug("add_job()\n");
3661 if (h == NULL) return;
3662 list = hb_get_titles( h );
3663 if( !hb_list_count( list ) )
3665 /* No valid title, stop right there */
3669 title = hb_list_item( list, titleindex );
3670 if (title == NULL) return;
3672 /* Set job settings */
3674 if (job == NULL) return;
3676 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3677 if (job->start_at_preview)
3679 job->seek_points = ghb_settings_get_int(js, "preview_count");
3680 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3683 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3684 job->mux = ghb_settings_combo_int(js, "FileFormat");
3685 if (job->mux == HB_MUX_MP4)
3687 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3688 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3692 job->largeFileSize = FALSE;
3693 job->mp4_optimize = FALSE;
3695 if (!job->start_at_preview)
3697 gint chapter_start, chapter_end;
3698 chapter_start = ghb_settings_get_int(js, "start_chapter");
3699 chapter_end = ghb_settings_get_int(js, "end_chapter");
3700 gint num_chapters = hb_list_count(title->list_chapter);
3701 job->chapter_start = MIN( num_chapters, chapter_start );
3702 job->chapter_end = MAX( job->chapter_start, chapter_end );
3704 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3705 if (job->chapter_start == job->chapter_end)
3706 job->chapter_markers = 0;
3707 if ( job->chapter_markers )
3714 chapters = ghb_settings_get_value(js, "chapter_list");
3715 count = ghb_array_len(chapters);
3716 for(chap = chapter_start; chap <= chapter_end; chap++)
3718 hb_chapter_t * chapter_s;
3724 chapter = ghb_array_get_nth(chapters, chap-1);
3725 name = ghb_value_string(chapter);
3729 name = g_strdup_printf ("Chapter %2d", chap);
3731 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3732 strncpy(chapter_s->title, name, 1023);
3733 chapter_s->title[1023] = '\0';
3738 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3739 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3740 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3741 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3744 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3745 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3747 job->deinterlace = (deint != 0) ? 1 : 0;
3749 job->deinterlace = 0;
3750 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3752 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3753 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3755 /* Add selected filters */
3756 job->filters = hb_list_init();
3757 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3762 if (detel_opts.map[detel].svalue != NULL)
3763 detel_str = g_strdup(detel_opts.map[detel].svalue);
3766 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3767 hb_filter_detelecine.settings = detel_str;
3768 hb_list_add( job->filters, &hb_filter_detelecine );
3774 if (decomb_opts.map[decomb].svalue != NULL)
3775 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3778 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3779 hb_filter_decomb.settings = decomb_str;
3780 hb_list_add( job->filters, &hb_filter_decomb );
3782 if( job->deinterlace )
3786 if (deint_opts.map[deint].svalue != NULL)
3787 deint_str = g_strdup(deint_opts.map[deint].svalue);
3790 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3791 hb_filter_deinterlace.settings = deint_str;
3792 hb_list_add( job->filters, &hb_filter_deinterlace );
3794 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3797 deblock_str = g_strdup_printf("%d", deblock);
3798 hb_filter_deblock.settings = deblock_str;
3799 hb_list_add( job->filters, &hb_filter_deblock );
3801 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3806 if (denoise_opts.map[denoise].svalue != NULL)
3807 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3810 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3811 hb_filter_denoise.settings = denoise_str;
3812 hb_list_add( job->filters, &hb_filter_denoise );
3814 job->width = ghb_settings_get_int(js, "scale_width");
3815 job->height = ghb_settings_get_int(js, "scale_height");
3817 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3818 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3819 (job->vcodec == HB_VCODEC_THEORA))
3821 // mp4|avi/theora combination is not supported.
3822 job->vcodec = HB_VCODEC_FFMPEG;
3824 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3826 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3828 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3831 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3832 job->vquality = vquality;
3835 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3837 job->vquality = -1.0;
3838 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3841 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3844 job->vrate = title->rate;
3845 job->vrate_base = title->rate_base;
3850 job->vrate = 27000000;
3851 job->vrate_base = vrate;
3855 // AVI container does not support variable frame rate.
3856 // OGM supports variable frame rate, but bases all timing on
3857 // DTS, which breaks when b-frames are used since it is
3858 // impossible to reconstruct PTS from DTS when the framerate
3860 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3865 const GValue *audio_list;
3869 audio_list = ghb_settings_get_value(js, "audio_list");
3870 count = ghb_array_len(audio_list);
3871 for (ii = 0; ii < count; ii++)
3874 hb_audio_config_t audio;
3875 hb_audio_config_t *taudio;
3877 hb_audio_config_init(&audio);
3878 asettings = ghb_array_get_nth(audio_list, ii);
3879 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3880 audio.out.track = tcount;
3881 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3882 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3883 title->list_audio, audio.in.track );
3884 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3886 if (!(taudio->in.codec & audio.out.codec))
3888 // Not supported. AC3 is passthrough only, so input must be AC3
3889 if (job->mux == HB_MUX_AVI)
3891 audio.out.codec = HB_ACODEC_LAME;
3895 audio.out.codec = HB_ACODEC_FAAC;
3900 audio.out.codec &= taudio->in.codec;
3903 if ((job->mux == HB_MUX_MP4) &&
3904 ((audio.out.codec == HB_ACODEC_LAME) ||
3905 (audio.out.codec == HB_ACODEC_VORBIS)))
3907 // mp4/mp3|vorbis combination is not supported.
3908 audio.out.codec = HB_ACODEC_FAAC;
3910 if ((job->mux == HB_MUX_AVI) &&
3911 ((audio.out.codec == HB_ACODEC_FAAC) ||
3912 (audio.out.codec == HB_ACODEC_VORBIS)))
3914 // avi/faac|vorbis combination is not supported.
3915 audio.out.codec = HB_ACODEC_LAME;
3917 if ((job->mux == HB_MUX_OGM) &&
3918 ((audio.out.codec == HB_ACODEC_FAAC) ||
3919 (audio.out.codec == HB_ACODEC_AC3) ||
3920 (audio.out.codec == HB_ACODEC_DCA)))
3922 // ogm/faac|ac3 combination is not supported.
3923 audio.out.codec = HB_ACODEC_VORBIS;
3925 audio.out.dynamic_range_compression =
3926 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3927 if (audio.out.dynamic_range_compression < 1.0)
3928 audio.out.dynamic_range_compression = 0.0;
3930 // It would be better if this were done in libhb for us, but its not yet.
3931 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3933 audio.out.mixdown = 0;
3937 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3938 // Make sure the mixdown is valid and pick a new one if not.
3939 audio.out.mixdown = ghb_get_best_mix(titleindex,
3940 audio.in.track, audio.out.codec, audio.out.mixdown);
3942 ghb_settings_combo_int(asettings, "AudioBitrate");
3943 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
3944 if (srate == 0) // 0 is same as source
3945 audio.out.samplerate = taudio->in.samplerate;
3947 audio.out.samplerate = srate;
3950 // Add it to the jobs audio list
3951 hb_audio_add( job, &audio );
3954 // I was tempted to move this up with the reset of the video quality
3955 // settings, but I suspect the settings above need to be made
3956 // first in order for hb_calc_bitrate to be accurate.
3957 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3961 size = ghb_settings_get_int(js, "VideoTargetSize");
3962 job->vbitrate = hb_calc_bitrate( job, size );
3963 job->vquality = -1.0;
3966 dest_str = ghb_settings_get_string(js, "destination");
3967 job->file = dest_str;
3968 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3970 const GValue *subtitle_list;
3972 gboolean force, burned, def, one_burned = FALSE;
3974 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
3975 count = ghb_array_len(subtitle_list);
3976 for (ii = 0; ii < count; ii++)
3980 ssettings = ghb_array_get_nth(subtitle_list, ii);
3982 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
3983 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
3984 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
3985 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
3989 if (!burned && job->mux == HB_MUX_MKV)
3991 job->select_subtitle_config.dest = PASSTHRUSUB;
3993 else if (!burned && job->mux == HB_MUX_MP4)
3995 // Skip any non-burned vobsubs when output is mp4
4000 // Only allow one subtitle to be burned into the video
4003 job->select_subtitle_config.dest = RENDERSUB;
4006 job->select_subtitle_config.force = force;
4007 job->select_subtitle_config.default_track = def;
4008 job->indepth_scan = 1;
4010 else if (subtitle >= 0)
4012 hb_subtitle_t * subt;
4013 hb_subtitle_config_t sub_config;
4015 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4016 sub_config = subt->config;
4019 if (!burned && job->mux == HB_MUX_MKV &&
4020 subt->format == PICTURESUB)
4022 sub_config.dest = PASSTHRUSUB;
4024 else if (!burned && job->mux == HB_MUX_MP4 &&
4025 subt->format == PICTURESUB)
4027 // Skip any non-burned vobsubs when output is mp4
4030 else if ( burned && subt->format == PICTURESUB )
4032 // Only allow one subtitle to be burned into the video
4037 sub_config.force = force;
4038 sub_config.default_track = def;
4039 hb_subtitle_add( job, &sub_config, subtitle );
4044 // TODO: libhb holds onto a reference to the x264opts and is not
4045 // finished with it until encoding the job is done. But I can't
4046 // find a way to get at the job before it is removed in order to
4047 // free up the memory I am allocating here.
4048 // The short story is THIS LEAKS.
4049 x264opts = ghb_build_x264opts_string(js);
4051 if( *x264opts == '\0' )
4057 if (job->indepth_scan == 1)
4059 // Subtitle scan. Look for subtitle matching audio language
4062 * When subtitle scan is enabled do a fast pre-scan job
4063 * which will determine which subtitles to enable, if any.
4066 job->indepth_scan = 1;
4067 job->x264opts = NULL;
4070 * Add the pre-scan job
4072 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4076 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4077 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4080 * If subtitle_scan is enabled then only turn it on
4081 * for the second pass and then off again for the
4085 job->indepth_scan = 0;
4088 * If turbo options have been selected then append them
4089 * to the x264opts now (size includes one ':' and the '\0')
4091 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4093 gchar *tmp_x264opts;
4097 badapt = ghb_lookup_badapt(x264opts);
4100 extra_opts = g_strdup_printf("%s", turbo_opts);
4104 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4109 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4114 * No x264opts to modify, but apply the turbo options
4115 * anyway as they may be modifying defaults
4117 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4121 job->x264opts = tmp_x264opts;
4123 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4125 //if (job->x264opts != NULL)
4126 // g_free(job->x264opts);
4130 * On the second pass we turn off subtitle scan so that we
4131 * can actually encode using any subtitles that were auto
4132 * selected in the first pass (using the whacky select-subtitle
4133 * attribute of the job).
4135 job->indepth_scan = 0;
4136 job->x264opts = x264opts;
4137 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4139 //if (job->x264opts != NULL)
4140 // g_free(job->x264opts);
4144 job->x264opts = x264opts;
4145 job->indepth_scan = 0;
4147 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4149 //if (job->x264opts != NULL)
4150 // g_free(job->x264opts);
4153 // clean up audio list
4154 gint num_audio_tracks = hb_list_count(job->list_audio);
4155 for(ii = 0; ii < num_audio_tracks; ii++)
4157 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4158 hb_list_rem(job->list_audio, audio);
4162 // clean up subtitle list
4163 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4164 for(ii = 0; ii < num_subtitle_tracks; ii++)
4166 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4167 hb_list_rem(job->list_subtitle, subtitle);
4171 if (detel_str) g_free(detel_str);
4172 if (decomb_str) g_free(decomb_str);
4173 if (deint_str) g_free(deint_str);
4174 if (deblock_str) g_free(deblock_str);
4175 if (denoise_str) g_free(denoise_str);
4176 if (dest_str) g_free(dest_str);
4180 ghb_add_job(GValue *js, gint unique_id)
4182 // Since I'm doing a scan of the single title I want just prior
4183 // to adding the job, there is only the one title to choose from.
4184 add_job(h_queue, js, unique_id, 0);
4188 ghb_add_live_job(GValue *js, gint unique_id)
4190 // Since I'm doing a scan of the single title I want just prior
4191 // to adding the job, there is only the one title to choose from.
4192 gint titleindex = ghb_settings_combo_int(js, "title");
4193 add_job(h_scan, js, unique_id, titleindex);
4197 ghb_remove_job(gint unique_id)
4202 // Multiples passes all get the same id
4204 // Go backwards through list, so reordering doesn't screw me.
4205 ii = hb_count(h_queue) - 1;
4206 while ((job = hb_job(h_queue, ii--)) != NULL)
4208 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4209 hb_rem(h_queue, job);
4216 hb_start( h_queue );
4226 ghb_start_live_encode()
4232 ghb_stop_live_encode()
4241 hb_get_state2( h_queue, &s );
4243 if( s.state == HB_STATE_PAUSED )
4245 hb_resume( h_queue );
4249 hb_pause( h_queue );
4264 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4267 gint channels = gdk_pixbuf_get_n_channels (pb);
4268 gint stride = gdk_pixbuf_get_rowstride (pb);
4270 for (jj = 0; jj < width; jj++)
4272 dst = pixels + y * stride + (x+jj) * channels;
4273 for (ii = 0; ii < len; ii++)
4294 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4297 gint channels = gdk_pixbuf_get_n_channels (pb);
4298 gint stride = gdk_pixbuf_get_rowstride (pb);
4300 for (jj = 0; jj < width; jj++)
4302 dst = pixels + (y+jj) * stride + x * channels;
4303 for (ii = 0; ii < len; ii++)
4324 gint line_width = 8;
4331 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4336 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4338 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4344 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4346 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4352 ghb_get_preview_image(
4355 signal_user_data_t *ud,
4363 settings = ud->settings;
4364 list = hb_get_titles( h_scan );
4365 if( !hb_list_count( list ) )
4367 /* No valid title, stop right there */
4370 title = hb_list_item( list, titleindex );
4371 if (title == NULL) return NULL;
4372 if (title->job == NULL) return NULL;
4373 set_preview_job_settings(title->job, settings);
4375 // hb_get_preview doesn't compensate for anamorphic, so lets
4376 // calculate scale factors
4377 gint width, height, par_width = 1, par_height = 1;
4378 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4381 hb_set_anamorphic_size( title->job, &width, &height,
4382 &par_width, &par_height );
4385 // Make sure we have a big enough buffer to receive the image from libhb
4386 gint dstWidth = title->job->width;
4387 gint dstHeight= title->job->height;
4389 static guint8 *buffer = NULL;
4390 static gint bufferSize = 0;
4393 newSize = dstWidth * dstHeight * 4;
4394 if( bufferSize < newSize )
4396 bufferSize = newSize;
4397 buffer = (guint8*) g_realloc( buffer, bufferSize );
4399 hb_get_preview( h_scan, title, index, buffer );
4401 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4402 // libhb's format something suitable.
4404 // The image data returned by hb_get_preview is 4 bytes per pixel,
4405 // BGRA format. Alpha is ignored.
4407 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4408 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4410 guint32 *src = (guint32*)buffer;
4411 guint8 *dst = pixels;
4414 gint channels = gdk_pixbuf_get_n_channels (preview);
4415 gint stride = gdk_pixbuf_get_rowstride (preview);
4418 for (ii = 0; ii < dstHeight; ii++)
4421 for (jj = 0; jj < dstWidth; jj++)
4423 tmp[0] = src[0] >> 16;
4424 tmp[1] = src[0] >> 8;
4425 tmp[2] = src[0] >> 0;
4431 gint w = ghb_settings_get_int(settings, "scale_width");
4432 gint h = ghb_settings_get_int(settings, "scale_height");
4433 ghb_par_scale(ud, &w, &h, par_width, par_height);
4435 gint c0, c1, c2, c3;
4436 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4437 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4438 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4439 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4441 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4442 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4444 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4447 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4451 gint orig_w, orig_h;
4454 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4458 ss = gdk_screen_get_default();
4459 s_w = gdk_screen_get_width(ss);
4460 s_h = gdk_screen_get_height(ss);
4464 if (dstWidth > s_w * factor / 100)
4466 dstWidth = s_w * factor / 100;
4467 dstHeight = dstHeight * dstWidth / orig_w;
4469 if (dstHeight > s_h * factor / 100)
4471 dstHeight = s_h * factor / 100;
4472 dstWidth = dstWidth * dstHeight / orig_h;
4474 xscale *= (gdouble)dstWidth / orig_w;
4475 yscale *= (gdouble)dstHeight / orig_h;
4476 w *= (gdouble)dstWidth / orig_w;
4477 h *= (gdouble)dstHeight / orig_h;
4479 GdkPixbuf *scaled_preview;
4480 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4481 if (ghb_settings_get_boolean(settings, "show_crop"))
4488 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4490 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4492 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4494 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4496 g_object_unref (preview);
4497 return scaled_preview;
4501 sanitize_volname(gchar *name)
4526 ghb_dvd_volname(const gchar *device)
4529 name = hb_dvd_name((gchar*)device);
4530 if (name != NULL && name[0] != 0)
4532 name = g_strdup(name);
4533 sanitize_volname(name);