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_appcast_update_opts[] =
112 {"Never", "never", 0, "never"},
113 {"Daily", "daily", 1, "daily"},
114 {"Weekly", "weekly", 2, "weekly"},
115 {"Monthly", "monthly", 3, "monthly"},
117 combo_opts_t appcast_update_opts =
119 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
120 d_appcast_update_opts
123 static options_map_t d_vqual_granularity_opts[] =
125 {"0.2", "0.2", 0.2, "0.2"},
126 {"0.25", "0.25", 0.25, "0.25"},
127 {"0.5", "0.5", 0.5, "0.5"},
130 combo_opts_t vqual_granularity_opts =
132 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
133 d_vqual_granularity_opts
136 static options_map_t d_container_opts[] =
138 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
139 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
141 combo_opts_t container_opts =
143 sizeof(d_container_opts)/sizeof(options_map_t),
147 static options_map_t d_detel_opts[] =
149 {"None", "none", 0, ""},
150 {"Custom", "custom", 1, ""},
151 {"Default","default",2, NULL},
153 combo_opts_t detel_opts =
155 sizeof(d_detel_opts)/sizeof(options_map_t),
159 static options_map_t d_decomb_opts[] =
161 {"None", "none", 0, ""},
162 {"Custom", "custom", 1, ""},
163 {"Default","default",2, NULL},
165 combo_opts_t decomb_opts =
167 sizeof(d_decomb_opts)/sizeof(options_map_t),
171 static options_map_t d_deint_opts[] =
173 {"None", "none", 0, ""},
174 {"Custom", "custom", 1, ""},
175 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
176 {"Slow", "slow", 3, "2:-1:-1:0:1"},
177 {"Slower", "slower", 4, "0:-1:-1:0:1"},
179 combo_opts_t deint_opts =
181 sizeof(d_deint_opts)/sizeof(options_map_t),
185 static options_map_t d_denoise_opts[] =
187 {"None", "none", 0, ""},
188 {"Custom", "custom", 1, ""},
189 {"Weak", "weak", 2, "2:1:2:3"},
190 {"Medium", "medium", 3, "3:2:2:3"},
191 {"Strong", "strong", 4, "7:7:5:5"},
193 combo_opts_t denoise_opts =
195 sizeof(d_denoise_opts)/sizeof(options_map_t),
199 static options_map_t d_vcodec_opts[] =
201 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
202 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
203 {"Theora", "theora", HB_VCODEC_THEORA, ""},
205 combo_opts_t vcodec_opts =
207 sizeof(d_vcodec_opts)/sizeof(options_map_t),
211 static options_map_t d_acodec_opts[] =
213 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
214 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
215 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
216 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
217 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
218 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
220 combo_opts_t acodec_opts =
222 sizeof(d_acodec_opts)/sizeof(options_map_t),
226 static options_map_t d_direct_opts[] =
228 {"None", "none", 0, "none"},
229 {"Spatial", "spatial", 1, "spatial"},
230 {"Temporal", "temporal", 2, "temporal"},
231 {"Automatic", "auto", 3, "auto"},
233 combo_opts_t direct_opts =
235 sizeof(d_direct_opts)/sizeof(options_map_t),
239 static options_map_t d_badapt_opts[] =
241 {"Off", "0", 0, "0"},
242 {"Fast", "1", 1, "1"},
243 {"Optimal", "2", 2, "2"},
245 combo_opts_t badapt_opts =
247 sizeof(d_badapt_opts)/sizeof(options_map_t),
251 static options_map_t d_me_opts[] =
253 {"Diamond", "dia", 0, "dia"},
254 {"Hexagon", "hex", 1, "hex"},
255 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
256 {"Exhaustive", "esa", 3, "esa"},
257 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
259 combo_opts_t me_opts =
261 sizeof(d_me_opts)/sizeof(options_map_t),
265 static options_map_t d_subme_opts[] =
277 combo_opts_t subme_opts =
279 sizeof(d_subme_opts)/sizeof(options_map_t),
283 static options_map_t d_analyse_opts[] =
285 {"Some", "some", 0, "some"},
286 {"None", "none", 1, "none"},
287 {"All", "all", 2, "all"},
288 {"Custom", "custom", 3, "all"},
290 combo_opts_t analyse_opts =
292 sizeof(d_analyse_opts)/sizeof(options_map_t),
296 static options_map_t d_trellis_opts[] =
298 {"Disabled", "0", 0, "0"},
299 {"Final Macro Block", "1", 1, "1"},
300 {"Always", "2", 2, "2"},
302 combo_opts_t trellis_opts =
304 sizeof(d_trellis_opts)/sizeof(options_map_t),
308 combo_opts_t subtitle_opts =
314 combo_opts_t title_opts =
320 combo_opts_t audio_track_opts =
332 combo_name_map_t combo_name_map[] =
334 {"PicturePAR", &par_opts},
335 {"PictureModulus", &alignment_opts},
336 {"LoggingLevel", &logging_opts},
337 {"check_updates", &appcast_update_opts},
338 {"VideoQualityGranularity", &vqual_granularity_opts},
339 {"FileFormat", &container_opts},
340 {"PictureDeinterlace", &deint_opts},
341 {"PictureDecomb", &decomb_opts},
342 {"PictureDetelecine", &detel_opts},
343 {"PictureDenoise", &denoise_opts},
344 {"VideoEncoder", &vcodec_opts},
345 {"AudioEncoder", &acodec_opts},
346 {"x264_direct", &direct_opts},
347 {"x264_b_adapt", &badapt_opts},
348 {"x264_me", &me_opts},
349 {"x264_subme", &subme_opts},
350 {"x264_analyse", &analyse_opts},
351 {"x264_trellis", &trellis_opts},
352 {"SubtitleTrack", &subtitle_opts},
353 {"title", &title_opts},
354 {"AudioTrack", &audio_track_opts},
359 typedef struct iso639_lang_t
361 char * eng_name; /* Description in English */
362 char * native_name; /* Description in native language */
363 char * iso639_1; /* ISO-639-1 (2 characters) code */
364 char * iso639_2; /* ISO-639-2/t (3 character) code */
365 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
369 const iso639_lang_t ghb_language_table[] =
371 { "Any", "", "zz", "und" },
372 { "Afar", "", "aa", "aar" },
373 { "Abkhazian", "", "ab", "abk" },
374 { "Afrikaans", "", "af", "afr" },
375 { "Akan", "", "ak", "aka" },
376 { "Albanian", "", "sq", "sqi", "alb" },
377 { "Amharic", "", "am", "amh" },
378 { "Arabic", "", "ar", "ara" },
379 { "Aragonese", "", "an", "arg" },
380 { "Armenian", "", "hy", "hye", "arm" },
381 { "Assamese", "", "as", "asm" },
382 { "Avaric", "", "av", "ava" },
383 { "Avestan", "", "ae", "ave" },
384 { "Aymara", "", "ay", "aym" },
385 { "Azerbaijani", "", "az", "aze" },
386 { "Bashkir", "", "ba", "bak" },
387 { "Bambara", "", "bm", "bam" },
388 { "Basque", "", "eu", "eus", "baq" },
389 { "Belarusian", "", "be", "bel" },
390 { "Bengali", "", "bn", "ben" },
391 { "Bihari", "", "bh", "bih" },
392 { "Bislama", "", "bi", "bis" },
393 { "Bosnian", "", "bs", "bos" },
394 { "Breton", "", "br", "bre" },
395 { "Bulgarian", "", "bg", "bul" },
396 { "Burmese", "", "my", "mya", "bur" },
397 { "Catalan", "", "ca", "cat" },
398 { "Chamorro", "", "ch", "cha" },
399 { "Chechen", "", "ce", "che" },
400 { "Chinese", "", "zh", "zho", "chi" },
401 { "Church Slavic", "", "cu", "chu" },
402 { "Chuvash", "", "cv", "chv" },
403 { "Cornish", "", "kw", "cor" },
404 { "Corsican", "", "co", "cos" },
405 { "Cree", "", "cr", "cre" },
406 { "Czech", "", "cs", "ces", "cze" },
407 { "Danish", "Dansk", "da", "dan" },
408 { "Divehi", "", "dv", "div" },
409 { "Dutch", "Nederlands", "nl", "nld", "dut" },
410 { "Dzongkha", "", "dz", "dzo" },
411 { "English", "English", "en", "eng" },
412 { "Esperanto", "", "eo", "epo" },
413 { "Estonian", "", "et", "est" },
414 { "Ewe", "", "ee", "ewe" },
415 { "Faroese", "", "fo", "fao" },
416 { "Fijian", "", "fj", "fij" },
417 { "Finnish", "Suomi", "fi", "fin" },
418 { "French", "Francais", "fr", "fra", "fre" },
419 { "Western Frisian", "", "fy", "fry" },
420 { "Fulah", "", "ff", "ful" },
421 { "Georgian", "", "ka", "kat", "geo" },
422 { "German", "Deutsch", "de", "deu", "ger" },
423 { "Gaelic (Scots)", "", "gd", "gla" },
424 { "Irish", "", "ga", "gle" },
425 { "Galician", "", "gl", "glg" },
426 { "Manx", "", "gv", "glv" },
427 { "Greek, Modern", "", "el", "ell", "gre" },
428 { "Guarani", "", "gn", "grn" },
429 { "Gujarati", "", "gu", "guj" },
430 { "Haitian", "", "ht", "hat" },
431 { "Hausa", "", "ha", "hau" },
432 { "Hebrew", "", "he", "heb" },
433 { "Herero", "", "hz", "her" },
434 { "Hindi", "", "hi", "hin" },
435 { "Hiri Motu", "", "ho", "hmo" },
436 { "Hungarian", "Magyar", "hu", "hun" },
437 { "Igbo", "", "ig", "ibo" },
438 { "Icelandic", "Islenska", "is", "isl", "ice" },
439 { "Ido", "", "io", "ido" },
440 { "Sichuan Yi", "", "ii", "iii" },
441 { "Inuktitut", "", "iu", "iku" },
442 { "Interlingue", "", "ie", "ile" },
443 { "Interlingua", "", "ia", "ina" },
444 { "Indonesian", "", "id", "ind" },
445 { "Inupiaq", "", "ik", "ipk" },
446 { "Italian", "Italiano", "it", "ita" },
447 { "Javanese", "", "jv", "jav" },
448 { "Japanese", "", "ja", "jpn" },
449 { "Kalaallisut", "", "kl", "kal" },
450 { "Kannada", "", "kn", "kan" },
451 { "Kashmiri", "", "ks", "kas" },
452 { "Kanuri", "", "kr", "kau" },
453 { "Kazakh", "", "kk", "kaz" },
454 { "Central Khmer", "", "km", "khm" },
455 { "Kikuyu", "", "ki", "kik" },
456 { "Kinyarwanda", "", "rw", "kin" },
457 { "Kirghiz", "", "ky", "kir" },
458 { "Komi", "", "kv", "kom" },
459 { "Kongo", "", "kg", "kon" },
460 { "Korean", "", "ko", "kor" },
461 { "Kuanyama", "", "kj", "kua" },
462 { "Kurdish", "", "ku", "kur" },
463 { "Lao", "", "lo", "lao" },
464 { "Latin", "", "la", "lat" },
465 { "Latvian", "", "lv", "lav" },
466 { "Limburgan", "", "li", "lim" },
467 { "Lingala", "", "ln", "lin" },
468 { "Lithuanian", "", "lt", "lit" },
469 { "Luxembourgish", "", "lb", "ltz" },
470 { "Luba-Katanga", "", "lu", "lub" },
471 { "Ganda", "", "lg", "lug" },
472 { "Macedonian", "", "mk", "mkd", "mac" },
473 { "Marshallese", "", "mh", "mah" },
474 { "Malayalam", "", "ml", "mal" },
475 { "Maori", "", "mi", "mri", "mao" },
476 { "Marathi", "", "mr", "mar" },
477 { "Malay", "", "ms", "msa", "msa" },
478 { "Malagasy", "", "mg", "mlg" },
479 { "Maltese", "", "mt", "mlt" },
480 { "Moldavian", "", "mo", "mol" },
481 { "Mongolian", "", "mn", "mon" },
482 { "Nauru", "", "na", "nau" },
483 { "Navajo", "", "nv", "nav" },
484 { "Ndebele, South", "", "nr", "nbl" },
485 { "Ndebele, North", "", "nd", "nde" },
486 { "Ndonga", "", "ng", "ndo" },
487 { "Nepali", "", "ne", "nep" },
488 { "Norwegian Nynorsk", "", "nn", "nno" },
489 { "Norwegian Bokmål", "", "nb", "nob" },
490 { "Norwegian", "Norsk", "no", "nor" },
491 { "Chichewa; Nyanja", "", "ny", "nya" },
492 { "Occitan", "", "oc", "oci" },
493 { "Ojibwa", "", "oj", "oji" },
494 { "Oriya", "", "or", "ori" },
495 { "Oromo", "", "om", "orm" },
496 { "Ossetian", "", "os", "oss" },
497 { "Panjabi", "", "pa", "pan" },
498 { "Persian", "", "fa", "fas", "per" },
499 { "Pali", "", "pi", "pli" },
500 { "Polish", "", "pl", "pol" },
501 { "Portuguese", "Portugues", "pt", "por" },
502 { "Pushto", "", "ps", "pus" },
503 { "Quechua", "", "qu", "que" },
504 { "Romansh", "", "rm", "roh" },
505 { "Romanian", "", "ro", "ron", "rum" },
506 { "Rundi", "", "rn", "run" },
507 { "Russian", "", "ru", "rus" },
508 { "Sango", "", "sg", "sag" },
509 { "Sanskrit", "", "sa", "san" },
510 { "Serbian", "", "sr", "srp", "scc" },
511 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
512 { "Sinhala", "", "si", "sin" },
513 { "Slovak", "", "sk", "slk", "slo" },
514 { "Slovenian", "", "sl", "slv" },
515 { "Northern Sami", "", "se", "sme" },
516 { "Samoan", "", "sm", "smo" },
517 { "Shona", "", "sn", "sna" },
518 { "Sindhi", "", "sd", "snd" },
519 { "Somali", "", "so", "som" },
520 { "Sotho, Southern", "", "st", "sot" },
521 { "Spanish", "Espanol", "es", "spa" },
522 { "Sardinian", "", "sc", "srd" },
523 { "Swati", "", "ss", "ssw" },
524 { "Sundanese", "", "su", "sun" },
525 { "Swahili", "", "sw", "swa" },
526 { "Swedish", "Svenska", "sv", "swe" },
527 { "Tahitian", "", "ty", "tah" },
528 { "Tamil", "", "ta", "tam" },
529 { "Tatar", "", "tt", "tat" },
530 { "Telugu", "", "te", "tel" },
531 { "Tajik", "", "tg", "tgk" },
532 { "Tagalog", "", "tl", "tgl" },
533 { "Thai", "", "th", "tha" },
534 { "Tibetan", "", "bo", "bod", "tib" },
535 { "Tigrinya", "", "ti", "tir" },
536 { "Tonga", "", "to", "ton" },
537 { "Tswana", "", "tn", "tsn" },
538 { "Tsonga", "", "ts", "tso" },
539 { "Turkmen", "", "tk", "tuk" },
540 { "Turkish", "", "tr", "tur" },
541 { "Twi", "", "tw", "twi" },
542 { "Uighur", "", "ug", "uig" },
543 { "Ukrainian", "", "uk", "ukr" },
544 { "Urdu", "", "ur", "urd" },
545 { "Uzbek", "", "uz", "uzb" },
546 { "Venda", "", "ve", "ven" },
547 { "Vietnamese", "", "vi", "vie" },
548 { "Volapük", "", "vo", "vol" },
549 { "Welsh", "", "cy", "cym", "wel" },
550 { "Walloon", "", "wa", "wln" },
551 { "Wolof", "", "wo", "wol" },
552 { "Xhosa", "", "xh", "xho" },
553 { "Yiddish", "", "yi", "yid" },
554 { "Yoruba", "", "yo", "yor" },
555 { "Zhuang", "", "za", "zha" },
556 { "Zulu", "", "zu", "zul" },
557 {NULL, NULL, NULL, NULL}
559 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
561 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
564 del_tree(const gchar *name, gboolean del_top)
568 if (g_file_test(name, G_FILE_TEST_IS_DIR))
570 GDir *gdir = g_dir_open(name, 0, NULL);
571 file = g_dir_read_name(gdir);
575 path = g_strdup_printf("%s/%s", name, file);
576 del_tree(path, TRUE);
578 file = g_dir_read_name(gdir);
593 return hb_get_version(NULL);
598 signal_user_data_t *ud,
606 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
615 *step = ghb_settings_combo_double(ud->settings,
616 "VideoQualityGranularity");
617 if (*step == 0.2 || *step == 0.5)
619 else if (*step == 0.25)
624 case HB_VCODEC_FFMPEG:
632 case HB_VCODEC_THEORA:
651 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
655 const gchar *result = "";
657 str = ghb_value_string(gval);
658 for (ii = 0; ii < opts->count; ii++)
660 if (strcmp(opts->map[ii].shortOpt, str) == 0)
662 result = opts->map[ii].svalue;
671 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
677 str = ghb_value_string(gval);
678 for (ii = 0; ii < opts->count; ii++)
680 if (strcmp(opts->map[ii].shortOpt, str) == 0)
682 result = opts->map[ii].ivalue;
691 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
697 str = ghb_value_string(gval);
698 for (ii = 0; ii < opts->count; ii++)
700 if (strcmp(opts->map[ii].shortOpt, str) == 0)
702 result = opts->map[ii].ivalue;
711 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
715 const gchar *result = "";
717 str = ghb_value_string(gval);
718 for (ii = 0; ii < opts->count; ii++)
720 if (strcmp(opts->map[ii].shortOpt, str) == 0)
722 result = opts->map[ii].option;
731 lookup_mix_int(const GValue *mix)
738 str = ghb_value_string(mix);
739 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
741 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
743 result = hb_audio_mixdowns[ii].amixdown;
752 lookup_mix_option(const GValue *mix)
756 gchar *result = "None";
759 str = ghb_value_string(mix);
760 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
762 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
764 result = hb_audio_mixdowns[ii].human_readable_name;
773 lookup_video_rate_int(const GValue *vrate)
779 str = ghb_value_string(vrate);
780 for (ii = 0; ii < hb_video_rates_count; ii++)
782 if (strcmp(hb_video_rates[ii].string, str) == 0)
784 result = hb_video_rates[ii].rate;
789 // Default to "same as source"
794 lookup_video_rate_option(const GValue *vrate)
798 const gchar *result = "Same as source";
800 str = ghb_value_string(vrate);
801 for (ii = 0; ii < hb_video_rates_count; ii++)
803 if (strcmp(hb_video_rates[ii].string, str) == 0)
805 result = hb_video_rates[ii].string;
810 // Default to "same as source"
815 lookup_audio_rate_int(const GValue *rate)
821 // Coincidentally, the string "source" will return 0
822 // which is our flag to use "same as source"
823 str = ghb_value_string(rate);
824 for (ii = 0; ii < hb_audio_rates_count; ii++)
826 if (strcmp(hb_audio_rates[ii].string, str) == 0)
828 result = hb_audio_rates[ii].rate;
837 lookup_audio_rate_option(const GValue *rate)
841 const gchar *result = "Same as source";
843 // Coincidentally, the string "source" will return 0
844 // which is our flag to use "same as source"
845 str = ghb_value_string(rate);
846 for (ii = 0; ii < hb_audio_rates_count; ii++)
848 if (strcmp(hb_audio_rates[ii].string, str) == 0)
850 result = hb_audio_rates[ii].string;
859 lookup_audio_bitrate_int(const GValue *rate)
865 // Coincidentally, the string "source" will return 0
866 // which is our flag to use "same as source"
867 str = ghb_value_string(rate);
868 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
870 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
872 result = hb_audio_bitrates[ii].rate;
881 lookup_audio_bitrate_option(const GValue *rate)
885 const gchar *result = "Same as source";
887 // Coincidentally, the string "source" will return 0
888 // which is our flag to use "same as source"
889 str = ghb_value_string(rate);
890 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
892 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
894 result = hb_audio_bitrates[ii].string;
903 lookup_audio_lang_int(const GValue *rate)
909 // Coincidentally, the string "source" will return 0
910 // which is our flag to use "same as source"
911 str = ghb_value_string(rate);
912 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
914 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
925 lookup_audio_lang_option(const GValue *rate)
929 const gchar *result = "Same as source";
931 // Coincidentally, the string "source" will return 0
932 // which is our flag to use "same as source"
933 str = ghb_value_string(rate);
934 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
936 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
938 result = ghb_language_table[ii].eng_name;
947 get_acodec_value(gint val)
949 GValue *value = NULL;
952 for (ii = 0; ii < acodec_opts.count; ii++)
954 if ((int)acodec_opts.map[ii].ivalue == val)
956 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
964 get_amix_value(gint val)
966 GValue *value = NULL;
969 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
971 if (hb_audio_mixdowns[ii].amixdown == val)
973 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
980 // Handle for libhb. Gets set by ghb_backend_init()
981 static hb_handle_t * h_scan = NULL;
982 static hb_handle_t * h_queue = NULL;
984 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
991 hb_get_tempory_directory(h_scan, dir);
992 return g_strdup(dir);
996 ghb_hb_cleanup(gboolean partial)
1000 hb_get_tempory_directory(h_scan, dir);
1001 del_tree(dir, !partial);
1005 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1013 titleindex = ghb_settings_combo_int(ud->settings, "title");
1019 hb_subtitle_t * sub;
1021 if (h_scan == NULL) return VOBSUB;
1022 list = hb_get_titles( h_scan );
1023 if( !hb_list_count( list ) )
1025 /* No valid title, stop right there */
1028 title = hb_list_item( list, titleindex );
1029 if (title == NULL) return VOBSUB; // Bad titleindex
1030 sub = hb_list_item( title->list_subtitle, track);
1038 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1041 const gchar * name = "Unknown";
1054 titleindex = ghb_settings_combo_int(ud->settings, "title");
1060 hb_subtitle_t * sub;
1064 list = hb_get_titles( h_scan );
1065 if( !hb_list_count( list ) )
1068 title = hb_list_item( list, titleindex );
1072 sub = hb_list_item( title->list_subtitle, track);
1075 switch (sub->source)
1096 ghb_get_title_number(gint titleindex)
1101 if (h_scan == NULL) return 1;
1102 list = hb_get_titles( h_scan );
1103 if( !hb_list_count( list ) )
1105 /* No valid title, stop right there */
1108 title = hb_list_item( list, titleindex );
1109 if (title == NULL) return 1; // Bad titleindex
1110 return title->index;
1113 static hb_audio_config_t*
1114 get_hb_audio(gint titleindex, gint track)
1118 hb_audio_config_t *audio = NULL;
1120 if (h_scan == NULL) return NULL;
1121 list = hb_get_titles( h_scan );
1122 if( !hb_list_count( list ) )
1124 /* No valid title, stop right there */
1127 title = hb_list_item( list, titleindex );
1128 if (title == NULL) return NULL; // Bad titleindex
1129 if (!hb_list_count(title->list_audio))
1133 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1138 search_rates(hb_rate_t *rates, gint rate, gint count)
1141 for (ii = 0; ii < count; ii++)
1143 if (rates[ii].rate == rate)
1149 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1151 static GtkListStore*
1152 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1155 GtkListStore *store;
1157 g_debug("get_combo_box_store() %s\n", name);
1158 // First modify the combobox model to allow greying out of options
1159 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1160 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1165 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1167 GtkListStore *store;
1170 store = get_combo_box_store(builder, name);
1171 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1173 gtk_list_store_set(store, &iter,
1180 ghb_grey_combo_options(GtkBuilder *builder)
1183 gint container, track, titleindex, acodec;
1184 hb_audio_config_t *audio = NULL;
1187 widget = GHB_WIDGET (builder, "title");
1188 gval = ghb_widget_value(widget);
1189 titleindex = ghb_lookup_combo_int("title", gval);
1190 ghb_value_free(gval);
1191 widget = GHB_WIDGET (builder, "AudioTrack");
1192 gval = ghb_widget_value(widget);
1193 track = ghb_lookup_combo_int("AudioTrack", gval);
1194 ghb_value_free(gval);
1195 audio = get_hb_audio(titleindex, track);
1196 widget = GHB_WIDGET (builder, "FileFormat");
1197 gval = ghb_widget_value(widget);
1198 container = ghb_lookup_combo_int("FileFormat", gval);
1199 ghb_value_free(gval);
1201 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1202 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1203 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1204 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1206 gboolean allow_dca = TRUE;
1207 allow_dca = (container != HB_MUX_MP4);
1209 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1211 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1213 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1215 if (audio && audio->in.codec != HB_ACODEC_AC3)
1217 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1219 if (audio && audio->in.codec != HB_ACODEC_DCA)
1221 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1223 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1225 widget = GHB_WIDGET (builder, "AudioEncoder");
1226 gval = ghb_widget_value(widget);
1227 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1228 ghb_value_free(gval);
1229 if (acodec != HB_ACODEC_AC3)
1231 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1233 if (container == HB_MUX_MP4)
1235 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1236 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1237 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1239 else if (container == HB_MUX_AVI)
1241 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1242 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1243 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1245 else if (container == HB_MUX_OGM)
1247 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1250 gboolean allow_mono = TRUE;
1251 gboolean allow_stereo = TRUE;
1252 gboolean allow_dolby = TRUE;
1253 gboolean allow_dpl2 = TRUE;
1254 gboolean allow_6ch = TRUE;
1258 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1259 (acodec != HB_ACODEC_LAME);
1260 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1262 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1264 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1265 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1266 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1267 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1269 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1270 (acodec != HB_ACODEC_LAME) &&
1271 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1272 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1274 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1275 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1276 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1277 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1278 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1282 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1284 hb_audio_config_t *audio = NULL;
1285 gboolean allow_mono = TRUE;
1286 gboolean allow_stereo = TRUE;
1287 gboolean allow_dolby = TRUE;
1288 gboolean allow_dpl2 = TRUE;
1289 gboolean allow_6ch = TRUE;
1291 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1293 // Audio codec pass-thru. No mixdown
1296 audio = get_hb_audio(titleindex, track);
1300 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1301 (acodec != HB_ACODEC_LAME);
1302 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1304 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1306 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1307 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1308 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1309 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1311 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1312 (acodec != HB_ACODEC_LAME) &&
1313 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1314 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1316 gboolean greater = FALSE;
1319 // If no mix is specified, select the best available.
1320 mix = HB_AMIXDOWN_6CH;
1322 if (mix == HB_AMIXDOWN_6CH)
1325 if (allow_6ch) return HB_AMIXDOWN_6CH;
1327 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1330 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1332 if (mix == HB_AMIXDOWN_DOLBY || greater)
1335 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1337 if (mix == HB_AMIXDOWN_STEREO || greater)
1340 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1342 if (mix == HB_AMIXDOWN_MONO || greater)
1345 if (allow_mono) return HB_AMIXDOWN_MONO;
1347 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1348 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1349 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1350 if (allow_6ch) return HB_AMIXDOWN_6CH;
1354 // Set up the model for the combo box
1356 init_combo_box(GtkBuilder *builder, const gchar *name)
1359 GtkListStore *store;
1360 GtkCellRenderer *cell;
1362 g_debug("init_combo_box() %s\n", name);
1363 // First modify the combobox model to allow greying out of options
1364 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1368 // 1 - String to display
1369 // 2 - bool indicating whether the entry is selectable (grey or not)
1370 // 3 - String that is used for presets
1371 // 4 - Int value determined by backend
1372 // 5 - String value determined by backend
1373 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1374 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1375 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1377 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1379 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1380 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1381 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1382 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1383 "text", 0, "sensitive", 1, NULL);
1386 { // Combo box entry
1387 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1392 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1395 GtkListStore *store;
1398 g_debug("audio_samplerate_opts_set ()\n");
1399 store = get_combo_box_store(builder, name);
1400 gtk_list_store_clear(store);
1401 // Add an item for "Same As Source"
1402 gtk_list_store_append(store, &iter);
1403 gtk_list_store_set(store, &iter,
1404 0, "Same as source",
1410 for (ii = 0; ii < count; ii++)
1412 gtk_list_store_append(store, &iter);
1413 gtk_list_store_set(store, &iter,
1414 0, rates[ii].string,
1416 2, rates[ii].string,
1417 3, (gdouble)rates[ii].rate,
1418 4, rates[ii].string,
1424 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1427 GtkListStore *store;
1430 g_debug("video_rate_opts_set ()\n");
1431 store = get_combo_box_store(builder, name);
1432 gtk_list_store_clear(store);
1433 // Add an item for "Same As Source"
1434 gtk_list_store_append(store, &iter);
1435 gtk_list_store_set(store, &iter,
1436 0, "Same as source",
1442 for (ii = 0; ii < count; ii++)
1446 if (strcmp(rates[ii].string, "23.976") == 0)
1448 desc = "(NTSC Film)";
1450 else if (strcmp(rates[ii].string, "25") == 0)
1452 desc = "(PAL Film/Video)";
1454 else if (strcmp(rates[ii].string, "29.97") == 0)
1456 desc = "(NTSC Video)";
1458 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1459 gtk_list_store_append(store, &iter);
1460 gtk_list_store_set(store, &iter,
1463 2, rates[ii].string,
1464 3, (gdouble)rates[ii].rate,
1465 4, rates[ii].string,
1472 mix_opts_set(GtkBuilder *builder, const gchar *name)
1475 GtkListStore *store;
1478 g_debug("mix_opts_set ()\n");
1479 store = get_combo_box_store(builder, name);
1480 gtk_list_store_clear(store);
1481 gtk_list_store_append(store, &iter);
1482 gtk_list_store_set(store, &iter,
1489 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1491 gtk_list_store_append(store, &iter);
1492 gtk_list_store_set(store, &iter,
1493 0, hb_audio_mixdowns[ii].human_readable_name,
1495 2, hb_audio_mixdowns[ii].short_name,
1496 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1497 4, hb_audio_mixdowns[ii].internal_name,
1503 language_opts_set(GtkBuilder *builder, const gchar *name)
1506 GtkListStore *store;
1509 g_debug("language_opts_set ()\n");
1510 store = get_combo_box_store(builder, name);
1511 gtk_list_store_clear(store);
1512 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1514 gtk_list_store_append(store, &iter);
1515 gtk_list_store_set(store, &iter,
1516 0, ghb_language_table[ii].eng_name,
1518 2, ghb_language_table[ii].iso639_2,
1520 4, ghb_language_table[ii].iso639_1,
1525 static gchar **titles = NULL;
1528 title_opts_set(GtkBuilder *builder, const gchar *name)
1531 GtkListStore *store;
1532 hb_list_t * list = NULL;
1533 hb_title_t * title = NULL;
1537 g_debug("title_opts_set ()\n");
1538 store = get_combo_box_store(builder, name);
1539 gtk_list_store_clear(store);
1542 list = hb_get_titles( h_scan );
1543 count = hb_list_count( list );
1544 if (count > 100) count = 100;
1546 if (titles) g_strfreev(titles);
1547 if (title_opts.map) g_free(title_opts.map);
1550 title_opts.count = count;
1551 title_opts.map = g_malloc(count*sizeof(options_map_t));
1552 titles = g_malloc((count+1) * sizeof(gchar*));
1556 title_opts.count = 1;
1557 title_opts.map = g_malloc(sizeof(options_map_t));
1562 // No titles. Fill in a default.
1563 gtk_list_store_append(store, &iter);
1564 gtk_list_store_set(store, &iter,
1571 title_opts.map[0].option = "No Titles";
1572 title_opts.map[0].shortOpt = "none";
1573 title_opts.map[0].ivalue = -1;
1574 title_opts.map[0].svalue = "none";
1577 for (ii = 0; ii < count; ii++)
1579 title = (hb_title_t*)hb_list_item(list, ii);
1580 if (title->duration != 0)
1582 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1583 title->index, title->hours, title->minutes, title->seconds);
1587 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1589 gtk_list_store_append(store, &iter);
1590 gtk_list_store_set(store, &iter,
1597 title_opts.map[ii].option = titles[ii];
1598 title_opts.map[ii].shortOpt = titles[ii];
1599 title_opts.map[ii].ivalue = ii;
1600 title_opts.map[ii].svalue = titles[ii];
1606 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1609 gboolean foundit = FALSE;
1611 if (gtk_tree_model_get_iter_first (store, iter))
1615 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1616 if (value == (int)ivalue)
1621 } while (gtk_tree_model_iter_next (store, iter));
1627 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1630 GtkListStore *store;
1631 hb_list_t * list = NULL;
1632 hb_title_t * title = NULL;
1633 hb_audio_config_t * audio;
1637 g_debug("audio_track_opts_set ()\n");
1638 store = get_combo_box_store(builder, name);
1639 gtk_list_store_clear(store);
1642 list = hb_get_titles( h_scan );
1643 title = (hb_title_t*)hb_list_item( list, titleindex );
1646 count = hb_list_count( title->list_audio );
1649 if (count > 100) count = 100;
1650 if (audio_track_opts.map) g_free(audio_track_opts.map);
1653 audio_track_opts.count = count;
1654 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1658 audio_track_opts.count = 1;
1659 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1663 // No audio. set some default
1664 gtk_list_store_append(store, &iter);
1665 gtk_list_store_set(store, &iter,
1672 audio_track_opts.map[0].option = "No Audio";
1673 audio_track_opts.map[0].shortOpt = "none";
1674 audio_track_opts.map[0].ivalue = -1;
1675 audio_track_opts.map[0].svalue = "none";
1678 index_str_init(count-1);
1679 for (ii = 0; ii < count; ii++)
1681 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1682 gtk_list_store_append(store, &iter);
1683 gtk_list_store_set(store, &iter,
1684 0, audio->lang.description,
1690 audio_track_opts.map[ii].option = audio->lang.description,
1691 audio_track_opts.map[ii].shortOpt = index_str[ii];
1692 audio_track_opts.map[ii].ivalue = ii;
1693 audio_track_opts.map[ii].svalue = index_str[ii];
1698 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1701 GtkListStore *store;
1702 hb_list_t * list = NULL;
1703 hb_title_t * title = NULL;
1704 hb_subtitle_t * subtitle;
1706 static char ** options = NULL;
1708 g_debug("subtitle_track_opts_set ()\n");
1709 store = get_combo_box_store(builder, name);
1710 gtk_list_store_clear(store);
1713 list = hb_get_titles( h_scan );
1714 title = (hb_title_t*)hb_list_item( list, titleindex );
1717 count = hb_list_count( title->list_subtitle );
1720 if (count > 100) count = 100;
1721 if (subtitle_opts.map) g_free(subtitle_opts.map);
1724 subtitle_opts.count = count+1;
1725 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1729 subtitle_opts.count = LANG_TABLE_SIZE+1;
1730 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1732 gtk_list_store_append(store, &iter);
1733 gtk_list_store_set(store, &iter,
1734 0, "Foreign Audio Search",
1740 subtitle_opts.map[0].option = "Foreign Audio Search";
1741 subtitle_opts.map[0].shortOpt = "-1";
1742 subtitle_opts.map[0].ivalue = -1;
1743 subtitle_opts.map[0].svalue = "auto";
1746 if (options != NULL)
1747 g_strfreev(options);
1748 options = g_malloc((count+1)*sizeof(gchar*));
1749 index_str_init(count-1);
1750 for (ii = 0; ii < count; ii++)
1752 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1753 // Skip subtitles that must be burned if there is already
1754 // a burned subtitle in the list
1755 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1756 subtitle_opts.map[ii+1].option = options[ii];
1757 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1758 subtitle_opts.map[ii+1].ivalue = ii;
1759 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1760 gtk_list_store_append(store, &iter);
1761 gtk_list_store_set(store, &iter,
1766 4, subtitle->iso639_2,
1769 options[count] = NULL;
1773 index_str_init(LANG_TABLE_SIZE-1);
1774 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1776 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1777 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1778 subtitle_opts.map[ii+1].ivalue = ii;
1779 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1780 gtk_list_store_append(store, &iter);
1781 gtk_list_store_set(store, &iter,
1782 0, ghb_language_table[ii].eng_name,
1786 4, ghb_language_table[ii].iso639_2,
1799 guint64 longest = 0;
1800 gint titleindex = 0;
1802 g_debug("ghb_longest_title ()\n");
1803 if (h_scan == NULL) return 0;
1804 list = hb_get_titles( h_scan );
1805 count = hb_list_count( list );
1806 if (count > 100) count = 100;
1807 for (ii = 0; ii < count; ii++)
1809 title = (hb_title_t*)hb_list_item(list, ii);
1810 if (title->duration > longest)
1813 longest = title->duration;
1820 ghb_get_source_audio_lang(gint titleindex, gint track)
1824 hb_audio_config_t * audio;
1827 g_debug("ghb_lookup_1st_audio_lang ()\n");
1830 list = hb_get_titles( h_scan );
1831 title = (hb_title_t*)hb_list_item( list, titleindex );
1834 if (hb_list_count( title->list_audio ) <= track)
1837 audio = hb_list_audio_config_item(title->list_audio, track);
1841 lang = g_strdup(audio->lang.iso639_2);
1846 ghb_find_audio_track(
1850 GHashTable *track_indices)
1854 hb_audio_config_t * audio;
1861 g_debug("find_audio_track ()\n");
1862 if (h_scan == NULL) return -1;
1863 list = hb_get_titles( h_scan );
1864 title = (hb_title_t*)hb_list_item( list, titleindex );
1867 count = hb_list_count( title->list_audio );
1869 if (count > 10) count = 10;
1870 used = g_hash_table_lookup(track_indices, &acodec);
1873 used = g_malloc0(count * sizeof(gboolean));
1874 g_hash_table_insert(track_indices, &acodec, used);
1876 // Try to find an item that matches the preferred language and
1877 // the passthru codec type
1878 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1880 for (ii = 0; ii < count; ii++)
1887 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1888 title->list_audio, ii );
1889 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1890 audio->in.channel_layout);
1891 // Find a track that is not visually impaired or dirctor's
1892 // commentary, and has the highest channel count.
1893 if ((audio->in.codec & acodec) &&
1894 (audio->lang.type < 2) &&
1895 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1896 (strcmp(lang, "und") == 0)))
1898 if (channels > max_chan)
1901 max_chan = channels;
1911 // Try to find an item that matches the preferred language
1912 for (ii = 0; ii < count; ii++)
1916 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1917 title->list_audio, ii );
1918 // Find a track that is not visually impaired or dirctor's commentary
1919 if ((audio->lang.type < 2) &&
1920 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1921 (strcmp(lang, "und") == 0)))
1932 // Try to fine an item that does not match the preferred language and
1933 // matches the passthru codec type
1934 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1936 for (ii = 0; ii < count; ii++)
1943 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1944 title->list_audio, ii );
1945 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1946 audio->in.channel_layout);
1947 // Find a track that is not visually impaired or dirctor's
1948 // commentary, and has the highest channel count.
1949 if ((audio->in.codec & acodec) &&
1950 (audio->lang.type < 2))
1952 if (channels > max_chan)
1955 max_chan = channels;
1965 // Try to fine an item that does not match the preferred language
1966 for (ii = 0; ii < count; ii++)
1970 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1971 title->list_audio, ii );
1972 // Find a track that is not visually impaired or dirctor's commentary
1973 if (audio->lang.type < 2)
1984 // Last ditch, anything goes
1985 for (ii = 0; ii < count; ii++)
1987 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1988 title->list_audio, ii );
2003 ghb_find_pref_subtitle_track(const gchar *lang)
2006 count = subtitle_opts.count;
2007 for (ii = 0; ii < count; ii++)
2009 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2011 return subtitle_opts.map[ii].ivalue;
2018 ghb_find_subtitle_track(
2021 GHashTable *track_indices)
2025 hb_subtitle_t * subtitle;
2029 g_debug("find_subtitle_track ()\n");
2030 if (strcmp(lang, "auto") == 0)
2032 if (h_scan == NULL) return -1;
2033 list = hb_get_titles( h_scan );
2034 title = (hb_title_t*)hb_list_item( list, titleindex );
2037 count = hb_list_count( title->list_subtitle );
2038 used = g_hash_table_lookup(track_indices, lang);
2041 used = g_malloc0(count * sizeof(gboolean));
2042 g_hash_table_insert(track_indices, g_strdup(lang), used);
2044 // Try to find an item that matches the preferred language
2045 for (ii = 0; ii < count; ii++)
2050 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2051 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2052 (strcmp(lang, "und") == 0))
2063 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2066 GtkListStore *store;
2069 g_debug("generic_opts_set ()\n");
2070 if (name == NULL || opts == NULL) return;
2071 store = get_combo_box_store(builder, name);
2072 gtk_list_store_clear(store);
2073 for (ii = 0; ii < opts->count; ii++)
2075 gtk_list_store_append(store, &iter);
2076 gtk_list_store_set(store, &iter,
2077 0, opts->map[ii].option,
2079 2, opts->map[ii].shortOpt,
2080 3, opts->map[ii].ivalue,
2081 4, opts->map[ii].svalue,
2087 find_combo_table(const gchar *name)
2091 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2093 if (strcmp(name, combo_name_map[ii].name) == 0)
2095 return combo_name_map[ii].opts;
2102 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2106 if (strcmp(name, "AudioBitrate") == 0)
2107 return lookup_audio_bitrate_int(gval);
2108 else if (strcmp(name, "AudioSamplerate") == 0)
2109 return lookup_audio_rate_int(gval);
2110 else if (strcmp(name, "VideoFramerate") == 0)
2111 return lookup_video_rate_int(gval);
2112 else if (strcmp(name, "AudioMixdown") == 0)
2113 return lookup_mix_int(gval);
2114 else if (strcmp(name, "PreferredLanguage") == 0)
2115 return lookup_audio_lang_int(gval);
2118 return lookup_generic_int(find_combo_table(name), gval);
2120 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2125 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2129 if (strcmp(name, "AudioBitrate") == 0)
2130 return lookup_audio_bitrate_int(gval);
2131 else if (strcmp(name, "AudioSamplerate") == 0)
2132 return lookup_audio_rate_int(gval);
2133 else if (strcmp(name, "VideoFramerate") == 0)
2134 return lookup_video_rate_int(gval);
2135 else if (strcmp(name, "AudioMixdown") == 0)
2136 return lookup_mix_int(gval);
2137 else if (strcmp(name, "PreferredLanguage") == 0)
2138 return lookup_audio_lang_int(gval);
2141 return lookup_generic_double(find_combo_table(name), gval);
2143 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2148 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2152 if (strcmp(name, "AudioBitrate") == 0)
2153 return lookup_audio_bitrate_option(gval);
2154 else if (strcmp(name, "AudioSamplerate") == 0)
2155 return lookup_audio_rate_option(gval);
2156 else if (strcmp(name, "VideoFramerate") == 0)
2157 return lookup_video_rate_option(gval);
2158 else if (strcmp(name, "AudioMixdown") == 0)
2159 return lookup_mix_option(gval);
2160 else if (strcmp(name, "PreferredLanguage") == 0)
2161 return lookup_audio_lang_option(gval);
2164 return lookup_generic_option(find_combo_table(name), gval);
2166 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2171 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2175 if (strcmp(name, "AudioBitrate") == 0)
2176 return lookup_audio_bitrate_option(gval);
2177 else if (strcmp(name, "AudioSamplerate") == 0)
2178 return lookup_audio_rate_option(gval);
2179 else if (strcmp(name, "VideoFramerate") == 0)
2180 return lookup_video_rate_option(gval);
2181 else if (strcmp(name, "AudioMixdown") == 0)
2182 return lookup_mix_option(gval);
2183 else if (strcmp(name, "PreferredLanguage") == 0)
2184 return lookup_audio_lang_option(gval);
2187 return lookup_generic_string(find_combo_table(name), gval);
2189 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2194 ghb_update_ui_combo_box(
2195 signal_user_data_t *ud,
2200 GtkComboBox *combo = NULL;
2202 gint handler_id = 0;
2206 g_debug("ghb_update_ui_combo_box() %s\n", name);
2207 // Clearing a combo box causes a rash of "changed" events, even when
2208 // the active item is -1 (inactive). To control things, I'm disabling
2209 // the event till things are settled down.
2210 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2211 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2214 // Valid signal id found. This should always succeed.
2215 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2216 signal_id, 0, 0, 0, 0);
2219 // This should also always succeed
2220 g_signal_handler_block ((gpointer)combo, handler_id);
2226 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2227 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2228 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2229 mix_opts_set(ud->builder, "AudioMixdown");
2230 language_opts_set(ud->builder, "PreferredLanguage");
2231 title_opts_set(ud->builder, "title");
2232 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2233 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2234 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2235 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2236 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2237 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2238 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2239 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2240 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2241 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2242 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2243 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2244 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2245 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2246 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2247 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2248 generic_opts_set(ud->builder, "x264_me", &me_opts);
2249 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2250 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2251 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2255 if (strcmp(name, "AudioBitrate") == 0)
2256 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2257 else if (strcmp(name, "AudioSamplerate") == 0)
2258 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2259 else if (strcmp(name, "VideoFramerate") == 0)
2260 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2261 else if (strcmp(name, "AudioMixdown") == 0)
2262 mix_opts_set(ud->builder, "AudioMixdown");
2263 else if (strcmp(name, "PreferredLanguage") == 0)
2264 language_opts_set(ud->builder, "PreferredLanguage");
2265 else if (strcmp(name, "title") == 0)
2266 title_opts_set(ud->builder, "title");
2267 else if (strcmp(name, "SubtitleTrack") == 0)
2268 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2269 else if (strcmp(name, "AudioTrack") == 0)
2270 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2272 generic_opts_set(ud->builder, name, find_combo_table(name));
2276 g_signal_handler_unblock ((gpointer)combo, handler_id);
2281 init_ui_combo_boxes(GtkBuilder *builder)
2285 init_combo_box(builder, "AudioBitrate");
2286 init_combo_box(builder, "AudioSamplerate");
2287 init_combo_box(builder, "VideoFramerate");
2288 init_combo_box(builder, "AudioMixdown");
2289 init_combo_box(builder, "PreferredLanguage");
2290 init_combo_box(builder, "title");
2291 init_combo_box(builder, "AudioTrack");
2292 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2294 init_combo_box(builder, combo_name_map[ii].name);
2298 static const char * turbo_opts =
2299 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2300 "no-fast-pskip=0:8x8dct=0";
2302 // Construct the x264 options string
2303 // The result is allocated, so someone must free it at some point.
2305 ghb_build_x264opts_string(GValue *settings)
2308 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2315 result = g_strdup("");
2321 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2325 hb_chapter_t * chapter;
2328 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2329 *hh = *mm = *ss = 0;
2330 if (h_scan == NULL) return;
2331 list = hb_get_titles( h_scan );
2332 title = (hb_title_t*)hb_list_item( list, ti );
2333 if (title == NULL) return;
2334 count = hb_list_count( title->list_chapter );
2335 if (ii >= count) return;
2336 chapter = hb_list_item(title->list_chapter, ii);
2337 if (chapter == NULL) return;
2338 *hh = chapter->hours;
2339 *mm = chapter->minutes;
2340 *ss = chapter->seconds;
2344 ghb_get_chapters(gint titleindex)
2348 hb_chapter_t * chapter;
2350 GValue *chapters = NULL;
2352 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2353 if (h_scan == NULL) return NULL;
2354 list = hb_get_titles( h_scan );
2355 title = (hb_title_t*)hb_list_item( list, titleindex );
2356 if (title == NULL) return NULL;
2357 count = hb_list_count( title->list_chapter );
2358 chapters = ghb_array_value_new(count);
2359 for (ii = 0; ii < count; ii++)
2361 chapter = hb_list_item(title->list_chapter, ii);
2362 if (chapter == NULL) break;
2363 if (chapter->title == NULL || chapter->title[0] == 0)
2366 str = g_strdup_printf ("Chapter %2d", ii+1);
2367 ghb_array_append(chapters, ghb_string_value_new(str));
2372 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2379 ghb_ac3_in_audio_list(const GValue *audio_list)
2383 count = ghb_array_len(audio_list);
2384 for (ii = 0; ii < count; ii++)
2389 asettings = ghb_array_get_nth(audio_list, ii);
2390 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2391 if (acodec & HB_ACODEC_AC3)
2398 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2401 GtkListStore *store;
2404 g_debug("audio_rate_opts_add ()\n");
2405 store = get_combo_box_store(builder, name);
2406 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2408 str = g_strdup_printf ("%d", rate);
2409 gtk_list_store_append(store, &iter);
2410 gtk_list_store_set(store, &iter,
2422 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2425 GtkListStore *store;
2427 gboolean done = FALSE;
2429 guint last = (guint)last_rate;
2431 g_debug("audio_bitrate_opts_clean ()\n");
2432 store = get_combo_box_store(builder, name);
2433 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2437 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2439 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2441 done = !gtk_list_store_remove(store, &iter);
2443 else if (ivalue > last)
2446 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2447 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2452 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2453 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2460 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2463 GtkListStore *store;
2466 g_debug("audio_bitrate_opts_set ()\n");
2467 store = get_combo_box_store(builder, name);
2468 gtk_list_store_clear(store);
2469 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2471 gtk_list_store_append(store, &iter);
2472 gtk_list_store_set(store, &iter,
2473 0, hb_audio_bitrates[ii].string,
2475 2, hb_audio_bitrates[ii].string,
2476 3, (gdouble)hb_audio_bitrates[ii].rate,
2477 4, hb_audio_bitrates[ii].string,
2483 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2485 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2489 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2491 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2494 static ghb_status_t hb_status;
2497 ghb_combo_init(signal_user_data_t *ud)
2499 // Set up the list model for the combos
2500 init_ui_combo_boxes(ud->builder);
2501 // Populate all the combos
2502 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2506 ghb_backend_init(gint debug)
2509 h_scan = hb_init( debug, 0 );
2510 h_queue = hb_init( debug, 0 );
2521 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2523 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2524 hb_status.scan.state |= GHB_STATE_SCANNING;
2525 // initialize count and cur to something that won't cause FPE
2526 // when computing progress
2527 hb_status.scan.title_count = 1;
2528 hb_status.scan.title_cur = 0;
2532 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2534 g_debug("ghb_backend_queue_scan()");
2535 hb_scan( h_queue, path, titlenum, 10, 0 );
2536 hb_status.queue.state |= GHB_STATE_SCANNING;
2540 ghb_get_scan_state()
2542 return hb_status.scan.state;
2546 ghb_get_queue_state()
2548 return hb_status.queue.state;
2552 ghb_clear_scan_state(gint state)
2554 hb_status.scan.state &= ~state;
2558 ghb_clear_queue_state(gint state)
2560 hb_status.queue.state &= ~state;
2564 ghb_set_scan_state(gint state)
2566 hb_status.scan.state |= state;
2570 ghb_set_queue_state(gint state)
2572 hb_status.queue.state |= state;
2576 ghb_get_status(ghb_status_t *status)
2578 memcpy(status, &hb_status, sizeof(ghb_status_t));
2587 if (h_scan == NULL) return;
2588 hb_get_state( h_scan, &s_scan );
2589 switch( s_scan.state )
2591 #define p s_scan.param.scanning
2592 case HB_STATE_SCANNING:
2594 hb_status.scan.state |= GHB_STATE_SCANNING;
2595 hb_status.scan.title_count = p.title_count;
2596 hb_status.scan.title_cur = p.title_cur;
2600 case HB_STATE_SCANDONE:
2602 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2603 hb_status.scan.state |= GHB_STATE_SCANDONE;
2606 #define p s_scan.param.working
2607 case HB_STATE_WORKING:
2608 hb_status.scan.state |= GHB_STATE_WORKING;
2609 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2610 hb_status.scan.job_cur = p.job_cur;
2611 hb_status.scan.job_count = p.job_count;
2612 hb_status.scan.progress = p.progress;
2613 hb_status.scan.rate_cur = p.rate_cur;
2614 hb_status.scan.rate_avg = p.rate_avg;
2615 hb_status.scan.hours = p.hours;
2616 hb_status.scan.minutes = p.minutes;
2617 hb_status.scan.seconds = p.seconds;
2618 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2622 case HB_STATE_PAUSED:
2623 hb_status.scan.state |= GHB_STATE_PAUSED;
2626 case HB_STATE_MUXING:
2628 hb_status.scan.state |= GHB_STATE_MUXING;
2631 #define p s_scan.param.workdone
2632 case HB_STATE_WORKDONE:
2636 hb_status.scan.state |= GHB_STATE_WORKDONE;
2637 hb_status.scan.state &= ~GHB_STATE_MUXING;
2638 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2639 hb_status.scan.state &= ~GHB_STATE_WORKING;
2643 hb_status.scan.error = GHB_ERROR_NONE;
2645 case HB_ERROR_CANCELED:
2646 hb_status.scan.error = GHB_ERROR_CANCELED;
2649 hb_status.scan.error = GHB_ERROR_FAIL;
2652 // Delete all remaining jobs of this encode.
2653 // An encode can be composed of multiple associated jobs.
2654 // When a job is stopped, libhb removes it from the job list,
2655 // but does not remove other jobs that may be associated with it.
2656 // Associated jobs are taged in the sequence id.
2657 while ((job = hb_job(h_scan, 0)) != NULL)
2658 hb_rem( h_scan, job );
2662 hb_get_state( h_queue, &s_queue );
2663 switch( s_queue.state )
2665 #define p s_queue.param.scanning
2666 case HB_STATE_SCANNING:
2668 hb_status.queue.state |= GHB_STATE_SCANNING;
2669 hb_status.queue.title_count = p.title_count;
2670 hb_status.queue.title_cur = p.title_cur;
2674 case HB_STATE_SCANDONE:
2676 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2677 hb_status.queue.state |= GHB_STATE_SCANDONE;
2680 #define p s_queue.param.working
2681 case HB_STATE_WORKING:
2682 hb_status.queue.state |= GHB_STATE_WORKING;
2683 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2684 hb_status.queue.job_cur = p.job_cur;
2685 hb_status.queue.job_count = p.job_count;
2686 hb_status.queue.progress = p.progress;
2687 hb_status.queue.rate_cur = p.rate_cur;
2688 hb_status.queue.rate_avg = p.rate_avg;
2689 hb_status.queue.hours = p.hours;
2690 hb_status.queue.minutes = p.minutes;
2691 hb_status.queue.seconds = p.seconds;
2692 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2696 case HB_STATE_PAUSED:
2697 hb_status.queue.state |= GHB_STATE_PAUSED;
2700 case HB_STATE_MUXING:
2702 hb_status.queue.state |= GHB_STATE_MUXING;
2705 #define p s_queue.param.workdone
2706 case HB_STATE_WORKDONE:
2710 hb_status.queue.state |= GHB_STATE_WORKDONE;
2711 hb_status.queue.state &= ~GHB_STATE_MUXING;
2712 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2713 hb_status.queue.state &= ~GHB_STATE_WORKING;
2717 hb_status.queue.error = GHB_ERROR_NONE;
2719 case HB_ERROR_CANCELED:
2720 hb_status.queue.error = GHB_ERROR_CANCELED;
2723 hb_status.queue.error = GHB_ERROR_FAIL;
2726 // Delete all remaining jobs of this encode.
2727 // An encode can be composed of multiple associated jobs.
2728 // When a job is stopped, libhb removes it from the job list,
2729 // but does not remove other jobs that may be associated with it.
2730 // Associated jobs are taged in the sequence id.
2731 while ((job = hb_job(h_queue, 0)) != NULL)
2732 hb_rem( h_queue, job );
2739 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2744 if (h_scan == NULL) return FALSE;
2745 list = hb_get_titles( h_scan );
2746 if( !hb_list_count( list ) )
2748 /* No valid title, stop right there */
2752 title = hb_list_item( list, titleindex );
2753 if (title == NULL) return FALSE; // Bad titleindex
2754 tinfo->width = title->width;
2755 tinfo->height = title->height;
2756 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2757 // Don't allow crop to 0
2758 if (title->crop[0] + title->crop[1] >= title->height)
2759 title->crop[0] = title->crop[1] = 0;
2760 if (title->crop[2] + title->crop[3] >= title->width)
2761 title->crop[2] = title->crop[3] = 0;
2762 tinfo->num_chapters = hb_list_count(title->list_chapter);
2763 tinfo->rate_base = title->rate_base;
2764 tinfo->rate = title->rate;
2765 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2766 title->width * title->pixel_aspect_width,
2767 title->height * title->pixel_aspect_height);
2768 tinfo->hours = title->hours;
2769 tinfo->minutes = title->minutes;
2770 tinfo->seconds = title->seconds;
2771 tinfo->duration = title->duration;
2773 tinfo->angle_count = title->angle_count;
2778 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2780 hb_audio_config_t *audio;
2782 audio = get_hb_audio(titleindex, audioindex);
2783 if (audio == NULL) return FALSE; // Bad audioindex
2784 ainfo->codec = audio->in.codec;
2785 ainfo->bitrate = audio->in.bitrate;
2786 ainfo->samplerate = audio->in.samplerate;
2791 ghb_audio_is_passthru(gint acodec)
2793 g_debug("ghb_audio_is_passthru () \n");
2794 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2798 ghb_get_default_acodec()
2800 return HB_ACODEC_FAAC;
2804 picture_settings_deps(signal_user_data_t *ud)
2806 gboolean autoscale, keep_aspect, enable_keep_aspect;
2807 gboolean enable_scale_width, enable_scale_height;
2808 gboolean enable_disp_width, enable_disp_height, enable_par;
2812 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2815 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2816 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2817 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2819 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2820 if (!enable_keep_aspect)
2822 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2824 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2825 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2827 enable_scale_width = !autoscale && (pic_par != 1);
2828 enable_scale_height = !autoscale && (pic_par != 1);
2829 enable_disp_width = (pic_par == 3) && !keep_aspect;
2830 enable_par = (pic_par == 3) && !keep_aspect;
2831 enable_disp_height = FALSE;
2833 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2834 gtk_widget_set_sensitive(widget, pic_par != 1);
2835 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2836 gtk_widget_set_sensitive(widget, pic_par != 1);
2837 widget = GHB_WIDGET(ud->builder, "scale_width");
2838 gtk_widget_set_sensitive(widget, enable_scale_width);
2839 widget = GHB_WIDGET(ud->builder, "scale_height");
2840 gtk_widget_set_sensitive(widget, enable_scale_height);
2841 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2842 gtk_widget_set_sensitive(widget, enable_disp_width);
2843 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2844 gtk_widget_set_sensitive(widget, enable_disp_height);
2845 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
2846 gtk_widget_set_sensitive(widget, enable_par);
2847 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
2848 gtk_widget_set_sensitive(widget, enable_par);
2849 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2850 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2851 widget = GHB_WIDGET(ud->builder, "autoscale");
2852 gtk_widget_set_sensitive(widget, pic_par != 1);
2856 ghb_set_scale(signal_user_data_t *ud, gint mode)
2861 gboolean keep_aspect;
2863 gboolean autocrop, autoscale, noscale;
2864 gint crop[4], width, height, par_width, par_height;
2865 gint crop_width, crop_height;
2866 gint aspect_n, aspect_d;
2867 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2868 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2873 gint max_height = 0;
2874 static gboolean busy = FALSE;
2876 g_debug("ghb_set_scale ()\n");
2877 if (h_scan == NULL) return;
2878 list = hb_get_titles( h_scan );
2879 if( !hb_list_count( list ) )
2881 /* No valid title, stop right there */
2886 titleindex = ghb_settings_combo_int(ud->settings, "title");
2887 title = hb_list_item( list, titleindex );
2888 if (title == NULL) return;
2890 if (job == NULL) return;
2892 picture_settings_deps(ud);
2897 // First configure widgets
2898 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2899 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2900 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2901 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2902 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2903 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2904 // alignment constraints rather than scaling to satisfy them.
2905 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2906 // Align dimensions to either 16 or 2 pixels
2907 // The scaler crashes if the dimensions are not divisible by 2
2908 // x264 also will not accept dims that are not multiple of 2
2912 keep_height = FALSE;
2914 // Step needs to be at least 2 because odd widths cause scaler crash
2916 widget = GHB_WIDGET (ud->builder, "scale_width");
2917 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2918 widget = GHB_WIDGET (ud->builder, "scale_height");
2919 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2922 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2923 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2924 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2925 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2926 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2927 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2928 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2929 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2933 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2934 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2935 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2936 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2937 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2938 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2939 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2940 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2942 ghb_title_info_t tinfo;
2943 ghb_get_title_info (&tinfo, titleindex);
2946 crop[0] = tinfo.crop[0];
2947 crop[1] = tinfo.crop[1];
2948 crop[2] = tinfo.crop[2];
2949 crop[3] = tinfo.crop[3];
2950 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2951 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2952 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2953 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2957 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2958 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2959 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2960 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2966 // Adjust the cropping to accomplish the desired width and height
2967 crop_width = tinfo.width - crop[2] - crop[3];
2968 crop_height = tinfo.height - crop[0] - crop[1];
2969 width = MOD_DOWN(crop_width, mod);
2970 height = MOD_DOWN(crop_height, mod);
2972 need1 = (crop_height - height) / 2;
2973 need2 = crop_height - height - need1;
2976 need1 = (crop_width - width) / 2;
2977 need2 = crop_width - width - need1;
2980 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2981 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2982 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2983 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2985 hb_reduce(&aspect_n, &aspect_d,
2986 title->width * title->pixel_aspect_width,
2987 title->height * title->pixel_aspect_height);
2988 crop_width = title->width - crop[2] - crop[3];
2989 crop_height = title->height - crop[0] - crop[1];
2993 height = crop_height;
2997 width = ghb_settings_get_int(ud->settings, "scale_width");
2998 height = ghb_settings_get_int(ud->settings, "scale_height");
2999 max_width = MOD_DOWN(
3000 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3001 max_height = MOD_DOWN(
3002 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3004 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3007 width = title->width - crop[2] - crop[3];
3009 height = title->height - crop[0] - crop[1];
3011 width = MOD_ROUND(width, mod);
3012 height = MOD_ROUND(height, mod);
3014 // Adjust dims according to max values
3016 height = MIN(height, max_height);
3018 width = MIN(width, max_width);
3022 job->anamorphic.mode = pic_par;
3023 // The scaler crashes if the dimensions are not divisible by 2
3024 // Align mod 2. And so does something in x264_encoder_headers()
3025 job->anamorphic.modulus = mod;
3026 job->anamorphic.par_width = title->pixel_aspect_width;
3027 job->anamorphic.par_height = title->pixel_aspect_height;
3028 job->anamorphic.dar_width = 0;
3029 job->anamorphic.dar_height = 0;
3031 if (keep_height && pic_par == 2)
3032 width = ((double)height * crop_width / crop_height) + 0.5;
3034 job->height = height;
3036 job->maxWidth = max_width;
3038 job->maxHeight = max_height;
3039 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3040 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3041 if (job->anamorphic.mode == 3 && !keep_aspect)
3043 job->anamorphic.keep_display_aspect = 0;
3044 if (mode & GHB_PIC_KEEP_PAR)
3046 job->anamorphic.par_width =
3047 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3048 job->anamorphic.par_height =
3049 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3053 job->anamorphic.dar_width =
3054 ghb_settings_get_int(ud->settings,
3055 "PictureDisplayWidth");
3056 job->anamorphic.dar_height =
3057 ghb_settings_get_int(ud->settings,
3058 "PictureDisplayHeight");
3063 job->anamorphic.keep_display_aspect = 1;
3065 hb_set_anamorphic_size( job, &width, &height,
3066 &par_width, &par_height );
3067 if (job->anamorphic.mode == 3 && !keep_aspect &&
3068 mode & GHB_PIC_KEEP_PAR)
3070 // hb_set_anamorphic_size reduces the par, which we
3071 // don't want in this case because the user is
3072 // explicitely specifying it.
3073 par_width = ghb_settings_get_int(ud->settings,
3075 par_height = ghb_settings_get_int(ud->settings,
3076 "PicturePARHeight");
3081 job->anamorphic.mode = pic_par;
3085 gint new_width, new_height;
3087 // Compute pixel aspect ration.
3088 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3089 // Must scale so that par becomes 1:1
3090 // Try to keep largest dimension
3091 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3092 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3094 if (max_width && new_width > max_width)
3096 height = new_height;
3098 else if (max_height && new_height > max_height)
3102 else if (keep_width)
3104 height = new_height;
3106 else if (keep_height)
3110 else if (width > new_width)
3112 height = new_height;
3118 g_debug("new w %d h %d\n", width, height);
3120 width = MOD_ROUND(width, mod);
3121 height = MOD_ROUND(height, mod);
3123 height = MIN(height, max_height);
3125 width = MIN(width, max_width);
3126 par_width = par_height = 1;
3128 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3129 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3131 gint disp_width, dar_width, dar_height;
3134 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3135 hb_reduce(&dar_width, &dar_height, disp_width, height);
3137 gint iaspect = dar_width * 9 / dar_height;
3138 if (dar_width > 2 * dar_height)
3140 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3142 else if (iaspect <= 16 && iaspect >= 15)
3144 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3146 else if (iaspect <= 12 && iaspect >= 11)
3148 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3152 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3154 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3156 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3157 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3158 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3159 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3164 set_preview_job_settings(hb_job_t *job, GValue *settings)
3166 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3167 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3168 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3169 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3171 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3172 job->anamorphic.modulus =
3173 ghb_settings_combo_int(settings, "PictureModulus");
3174 job->width = ghb_settings_get_int(settings, "scale_width");
3175 job->height = ghb_settings_get_int(settings, "scale_height");
3176 if (ghb_settings_get_boolean(settings, "show_crop"))
3178 gdouble xscale = (gdouble)job->width /
3179 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3180 gdouble yscale = (gdouble)job->height /
3181 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3183 job->width += xscale * (job->crop[2] + job->crop[3]);
3184 job->height += yscale * (job->crop[0] + job->crop[1]);
3189 job->anamorphic.modulus = 2;
3192 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3193 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3194 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3196 gboolean keep_aspect;
3197 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3198 if (job->anamorphic.mode)
3200 job->anamorphic.par_width = job->title->pixel_aspect_width;
3201 job->anamorphic.par_height = job->title->pixel_aspect_height;
3202 job->anamorphic.dar_width = 0;
3203 job->anamorphic.dar_height = 0;
3205 if (job->anamorphic.mode == 3 && !keep_aspect)
3207 job->anamorphic.keep_display_aspect = 0;
3208 job->anamorphic.par_width =
3209 ghb_settings_get_int(settings, "PicturePARWidth");
3210 job->anamorphic.par_height =
3211 ghb_settings_get_int(settings, "PicturePARHeight");
3215 job->anamorphic.keep_display_aspect = 1;
3221 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3228 if (h_scan == NULL) return 1500;
3229 list = hb_get_titles( h_scan );
3230 title = hb_list_item( list, titleindex );
3231 if (title == NULL) return 1500;
3233 if (job == NULL) return 1500;
3234 size = ghb_settings_get_int(settings, "VideoTargetSize");
3235 return hb_calc_bitrate( job, size );
3239 ghb_validate_filter_string(const gchar *str, gint max_fields)
3245 if (str == NULL || *str == 0) return TRUE;
3248 val = g_strtod(str, &end);
3250 { // Found a numeric value
3252 // negative max_fields means infinate
3253 if (max_fields >= 0 && fields > max_fields) return FALSE;
3267 ghb_validate_filters(signal_user_data_t *ud)
3274 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3277 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3278 if (!ghb_validate_filter_string(str, 4))
3280 message = g_strdup_printf(
3281 "Invalid Deinterlace Settings:\n\n%s\n",
3283 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3291 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3294 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3295 if (!ghb_validate_filter_string(str, 6))
3297 message = g_strdup_printf(
3298 "Invalid Detelecine Settings:\n\n%s\n",
3300 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3308 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3311 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3312 if (!ghb_validate_filter_string(str, 7))
3314 message = g_strdup_printf(
3315 "Invalid Decomb Settings:\n\n%s\n",
3317 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3325 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3328 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3329 if (!ghb_validate_filter_string(str, 4))
3331 message = g_strdup_printf(
3332 "Invalid Denoise Settings:\n\n%s\n",
3334 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3345 ghb_validate_video(signal_user_data_t *ud)
3350 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3351 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3352 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3353 (vcodec == HB_VCODEC_THEORA))
3355 // mp4|avi/theora combination is not supported.
3356 message = g_strdup_printf(
3357 "Theora is not supported in the MP4 and AVI containers.\n\n"
3358 "You should choose a different video codec or container.\n"
3359 "If you continue, FFMPEG will be chosen for you.");
3360 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3366 vcodec = HB_VCODEC_FFMPEG;
3367 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3373 ghb_validate_subtitles(signal_user_data_t *ud)
3379 if (h_scan == NULL) return FALSE;
3380 list = hb_get_titles( h_scan );
3381 if( !hb_list_count( list ) )
3383 /* No valid title, stop right there */
3384 g_message("No title found.\n");
3390 titleindex = ghb_settings_combo_int(ud->settings, "title");
3391 title = hb_list_item( list, titleindex );
3392 if (title == NULL) return FALSE;
3393 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3395 const GValue *slist, *settings;
3396 gint count, ii, track, source;
3397 gboolean burned, one_burned = FALSE;
3399 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3400 count = ghb_array_len(slist);
3401 for (ii = 0; ii < count; ii++)
3403 settings = ghb_array_get_nth(slist, ii);
3404 track = ghb_settings_combo_int(settings, "SubtitleTrack");
3405 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3406 source = ghb_subtitle_track_source(ud, track);
3407 if (burned && one_burned)
3409 // MP4 can only handle burned vobsubs. make sure there isn't
3410 // already something burned in the list
3411 message = g_strdup_printf(
3412 "Only one subtitle may be burned into the video.\n\n"
3413 "You should change your subtitle selections.\n"
3414 "If you continue, some subtitles will be lost.");
3415 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3427 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3429 // MP4 can only handle burned vobsubs. make sure there isn't
3430 // already something burned in the list
3431 message = g_strdup_printf(
3432 "Your chosen container does not support soft bitmap subtitles.\n\n"
3433 "You should change your subtitle selections.\n"
3434 "If you continue, some subtitles will be lost.");
3435 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3448 ghb_validate_audio(signal_user_data_t *ud)
3455 if (h_scan == NULL) return FALSE;
3456 list = hb_get_titles( h_scan );
3457 if( !hb_list_count( list ) )
3459 /* No valid title, stop right there */
3460 g_message("No title found.\n");
3466 titleindex = ghb_settings_combo_int(ud->settings, "title");
3467 title = hb_list_item( list, titleindex );
3468 if (title == NULL) return FALSE;
3469 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3471 const GValue *audio_list;
3474 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3475 count = ghb_array_len(audio_list);
3476 for (ii = 0; ii < count; ii++)
3479 hb_audio_config_t *taudio;
3481 asettings = ghb_array_get_nth(audio_list, ii);
3482 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3483 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3484 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3485 title->list_audio, track );
3486 if (!(taudio->in.codec & codec) &&
3487 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3489 // Not supported. AC3 is passthrough only, so input must be AC3
3490 message = g_strdup_printf(
3491 "The source does not support Pass-Thru.\n\n"
3492 "You should choose a different audio codec.\n"
3493 "If you continue, one will be chosen for you.");
3494 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3500 if (mux == HB_MUX_AVI)
3502 codec = HB_ACODEC_LAME;
3506 codec = HB_ACODEC_FAAC;
3508 value = get_acodec_value(codec);
3509 ghb_settings_take_value(asettings, "AudioEncoder", value);
3511 gchar *a_unsup = NULL;
3512 gchar *mux_s = NULL;
3513 if (mux == HB_MUX_MP4)
3516 // mp4/mp3|vorbis combination is not supported.
3517 if (codec == HB_ACODEC_LAME)
3520 codec = HB_ACODEC_FAAC;
3522 if (codec == HB_ACODEC_VORBIS)
3525 codec = HB_ACODEC_FAAC;
3527 if (codec == HB_ACODEC_DCA)
3530 codec = HB_ACODEC_FAAC;
3533 else if (mux == HB_MUX_AVI)
3536 // avi/faac|vorbis combination is not supported.
3537 if (codec == HB_ACODEC_FAAC)
3540 codec = HB_ACODEC_LAME;
3542 if (codec == HB_ACODEC_VORBIS)
3545 codec = HB_ACODEC_LAME;
3548 else if (mux == HB_MUX_OGM)
3551 // avi/faac|vorbis combination is not supported.
3552 if (codec == HB_ACODEC_FAAC)
3555 codec = HB_ACODEC_VORBIS;
3557 if (codec == HB_ACODEC_AC3)
3560 codec = HB_ACODEC_VORBIS;
3562 if (codec == HB_ACODEC_DCA)
3565 codec = HB_ACODEC_VORBIS;
3570 message = g_strdup_printf(
3571 "%s is not supported in the %s container.\n\n"
3572 "You should choose a different audio codec.\n"
3573 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3574 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3580 value = get_acodec_value(codec);
3581 ghb_settings_take_value(asettings, "AudioEncoder", value);
3583 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3584 gboolean allow_mono = TRUE;
3585 gboolean allow_stereo = TRUE;
3586 gboolean allow_dolby = TRUE;
3587 gboolean allow_dpl2 = TRUE;
3588 gboolean allow_6ch = TRUE;
3590 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3591 (codec != HB_ACODEC_LAME);
3592 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3594 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3596 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3597 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3598 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3599 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3601 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3602 (codec != HB_ACODEC_LAME) &&
3603 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3604 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3606 gchar *mix_unsup = NULL;
3607 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3611 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3613 mix_unsup = "stereo";
3615 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3617 mix_unsup = "Dolby";
3619 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3621 mix_unsup = "Dolby Pro Logic II";
3623 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3625 mix_unsup = "6 Channel";
3629 message = g_strdup_printf(
3630 "The source audio does not support %s mixdown.\n\n"
3631 "You should choose a different mixdown.\n"
3632 "If you continue, one will be chosen for you.", mix_unsup);
3633 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3639 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3640 value = get_amix_value(mix);
3641 ghb_settings_take_value(asettings, "AudioMixdown", value);
3648 ghb_validate_vquality(GValue *settings)
3654 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3655 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3657 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3658 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3662 case HB_VCODEC_X264:
3668 case HB_VCODEC_FFMPEG:
3674 case HB_VCODEC_THEORA:
3686 if (vquality < min || vquality > max)
3688 message = g_strdup_printf(
3689 "Interesting video quality choise: %d\n\n"
3690 "Typical values range from %d to %d.\n"
3691 "Are you sure you wish to use this setting?",
3692 (gint)vquality, min, max);
3693 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3694 "Cancel", "Continue"))
3706 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3711 static gchar *x264opts;
3713 gboolean tweaks = FALSE;
3714 gchar *detel_str = NULL;
3715 gchar *decomb_str = NULL;
3716 gchar *deint_str = NULL;
3717 gchar *deblock_str = NULL;
3718 gchar *denoise_str = NULL;
3719 gchar *dest_str = NULL;
3721 g_debug("add_job()\n");
3722 if (h == NULL) return;
3723 list = hb_get_titles( h );
3724 if( !hb_list_count( list ) )
3726 /* No valid title, stop right there */
3730 title = hb_list_item( list, titleindex );
3731 if (title == NULL) return;
3733 /* Set job settings */
3735 if (job == NULL) return;
3737 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3738 if (job->start_at_preview)
3740 job->seek_points = ghb_settings_get_int(js, "preview_count");
3741 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3744 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3745 job->mux = ghb_settings_combo_int(js, "FileFormat");
3746 if (job->mux == HB_MUX_MP4)
3748 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3749 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3753 job->largeFileSize = FALSE;
3754 job->mp4_optimize = FALSE;
3756 if (!job->start_at_preview)
3758 gint chapter_start, chapter_end;
3759 chapter_start = ghb_settings_get_int(js, "start_chapter");
3760 chapter_end = ghb_settings_get_int(js, "end_chapter");
3761 gint num_chapters = hb_list_count(title->list_chapter);
3762 job->chapter_start = MIN( num_chapters, chapter_start );
3763 job->chapter_end = MAX( job->chapter_start, chapter_end );
3765 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3766 if (job->chapter_start == job->chapter_end)
3767 job->chapter_markers = 0;
3768 if ( job->chapter_markers )
3775 chapters = ghb_settings_get_value(js, "chapter_list");
3776 count = ghb_array_len(chapters);
3777 for(chap = chapter_start; chap <= chapter_end; chap++)
3779 hb_chapter_t * chapter_s;
3785 chapter = ghb_array_get_nth(chapters, chap-1);
3786 name = ghb_value_string(chapter);
3790 name = g_strdup_printf ("Chapter %2d", chap);
3792 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3793 strncpy(chapter_s->title, name, 1023);
3794 chapter_s->title[1023] = '\0';
3799 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3800 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3801 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3802 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3805 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3806 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3808 job->deinterlace = (deint != 0) ? 1 : 0;
3810 job->deinterlace = 0;
3811 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3813 gboolean keep_aspect;
3814 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
3815 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3816 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3817 if (job->anamorphic.mode)
3819 job->anamorphic.par_width = title->pixel_aspect_width;
3820 job->anamorphic.par_height = title->pixel_aspect_height;
3821 job->anamorphic.dar_width = 0;
3822 job->anamorphic.dar_height = 0;
3824 if (job->anamorphic.mode == 3 && !keep_aspect)
3826 job->anamorphic.keep_display_aspect = 0;
3827 job->anamorphic.par_width =
3828 ghb_settings_get_int(js, "PicturePARWidth");
3829 job->anamorphic.par_height =
3830 ghb_settings_get_int(js, "PicturePARHeight");
3834 job->anamorphic.keep_display_aspect = 1;
3838 /* Add selected filters */
3839 job->filters = hb_list_init();
3840 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3845 if (detel_opts.map[detel].svalue != NULL)
3846 detel_str = g_strdup(detel_opts.map[detel].svalue);
3849 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3850 hb_filter_detelecine.settings = detel_str;
3851 hb_list_add( job->filters, &hb_filter_detelecine );
3857 if (decomb_opts.map[decomb].svalue != NULL)
3858 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3861 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3862 hb_filter_decomb.settings = decomb_str;
3863 hb_list_add( job->filters, &hb_filter_decomb );
3865 if( job->deinterlace )
3869 if (deint_opts.map[deint].svalue != NULL)
3870 deint_str = g_strdup(deint_opts.map[deint].svalue);
3873 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3874 hb_filter_deinterlace.settings = deint_str;
3875 hb_list_add( job->filters, &hb_filter_deinterlace );
3877 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3880 deblock_str = g_strdup_printf("%d", deblock);
3881 hb_filter_deblock.settings = deblock_str;
3882 hb_list_add( job->filters, &hb_filter_deblock );
3884 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3889 if (denoise_opts.map[denoise].svalue != NULL)
3890 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3893 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3894 hb_filter_denoise.settings = denoise_str;
3895 hb_list_add( job->filters, &hb_filter_denoise );
3897 job->width = ghb_settings_get_int(js, "scale_width");
3898 job->height = ghb_settings_get_int(js, "scale_height");
3900 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3901 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3902 (job->vcodec == HB_VCODEC_THEORA))
3904 // mp4|avi/theora combination is not supported.
3905 job->vcodec = HB_VCODEC_FFMPEG;
3907 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3909 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3911 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3914 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3915 job->vquality = vquality;
3918 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3920 job->vquality = -1.0;
3921 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3924 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3927 job->vrate = title->rate;
3928 job->vrate_base = title->rate_base;
3933 job->vrate = 27000000;
3934 job->vrate_base = vrate;
3938 // AVI container does not support variable frame rate.
3939 // OGM supports variable frame rate, but bases all timing on
3940 // DTS, which breaks when b-frames are used since it is
3941 // impossible to reconstruct PTS from DTS when the framerate
3943 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3948 const GValue *audio_list;
3952 audio_list = ghb_settings_get_value(js, "audio_list");
3953 count = ghb_array_len(audio_list);
3954 for (ii = 0; ii < count; ii++)
3957 hb_audio_config_t audio;
3958 hb_audio_config_t *taudio;
3960 hb_audio_config_init(&audio);
3961 asettings = ghb_array_get_nth(audio_list, ii);
3962 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3963 audio.out.track = tcount;
3964 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3965 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3966 title->list_audio, audio.in.track );
3967 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3969 if (!(taudio->in.codec & audio.out.codec))
3971 // Not supported. AC3 is passthrough only, so input must be AC3
3972 if (job->mux == HB_MUX_AVI)
3974 audio.out.codec = HB_ACODEC_LAME;
3978 audio.out.codec = HB_ACODEC_FAAC;
3983 audio.out.codec &= taudio->in.codec;
3986 if ((job->mux == HB_MUX_MP4) &&
3987 ((audio.out.codec == HB_ACODEC_LAME) ||
3988 (audio.out.codec == HB_ACODEC_VORBIS)))
3990 // mp4/mp3|vorbis combination is not supported.
3991 audio.out.codec = HB_ACODEC_FAAC;
3993 if ((job->mux == HB_MUX_AVI) &&
3994 ((audio.out.codec == HB_ACODEC_FAAC) ||
3995 (audio.out.codec == HB_ACODEC_VORBIS)))
3997 // avi/faac|vorbis combination is not supported.
3998 audio.out.codec = HB_ACODEC_LAME;
4000 if ((job->mux == HB_MUX_OGM) &&
4001 ((audio.out.codec == HB_ACODEC_FAAC) ||
4002 (audio.out.codec == HB_ACODEC_AC3) ||
4003 (audio.out.codec == HB_ACODEC_DCA)))
4005 // ogm/faac|ac3 combination is not supported.
4006 audio.out.codec = HB_ACODEC_VORBIS;
4008 audio.out.dynamic_range_compression =
4009 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4010 if (audio.out.dynamic_range_compression < 1.0)
4011 audio.out.dynamic_range_compression = 0.0;
4013 // It would be better if this were done in libhb for us, but its not yet.
4014 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
4016 audio.out.mixdown = 0;
4020 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4021 // Make sure the mixdown is valid and pick a new one if not.
4022 audio.out.mixdown = ghb_get_best_mix(titleindex,
4023 audio.in.track, audio.out.codec, audio.out.mixdown);
4025 ghb_settings_combo_int(asettings, "AudioBitrate");
4026 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4027 if (srate == 0) // 0 is same as source
4028 audio.out.samplerate = taudio->in.samplerate;
4030 audio.out.samplerate = srate;
4033 // Add it to the jobs audio list
4034 hb_audio_add( job, &audio );
4037 // I was tempted to move this up with the reset of the video quality
4038 // settings, but I suspect the settings above need to be made
4039 // first in order for hb_calc_bitrate to be accurate.
4040 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4044 size = ghb_settings_get_int(js, "VideoTargetSize");
4045 job->vbitrate = hb_calc_bitrate( job, size );
4046 job->vquality = -1.0;
4049 dest_str = ghb_settings_get_string(js, "destination");
4050 job->file = dest_str;
4051 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
4053 const GValue *subtitle_list;
4055 gboolean force, burned, def, one_burned = FALSE;
4057 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4058 count = ghb_array_len(subtitle_list);
4059 for (ii = 0; ii < count; ii++)
4063 ssettings = ghb_array_get_nth(subtitle_list, ii);
4065 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4066 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4067 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4068 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4072 if (!burned && job->mux == HB_MUX_MKV)
4074 job->select_subtitle_config.dest = PASSTHRUSUB;
4076 else if (!burned && job->mux == HB_MUX_MP4)
4078 // Skip any non-burned vobsubs when output is mp4
4083 // Only allow one subtitle to be burned into the video
4086 job->select_subtitle_config.dest = RENDERSUB;
4089 job->select_subtitle_config.force = force;
4090 job->select_subtitle_config.default_track = def;
4091 job->indepth_scan = 1;
4093 else if (subtitle >= 0)
4095 hb_subtitle_t * subt;
4096 hb_subtitle_config_t sub_config;
4098 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4099 sub_config = subt->config;
4102 if (!burned && job->mux == HB_MUX_MKV &&
4103 subt->format == PICTURESUB)
4105 sub_config.dest = PASSTHRUSUB;
4107 else if (!burned && job->mux == HB_MUX_MP4 &&
4108 subt->format == PICTURESUB)
4110 // Skip any non-burned vobsubs when output is mp4
4113 else if ( burned && subt->format == PICTURESUB )
4115 // Only allow one subtitle to be burned into the video
4120 sub_config.force = force;
4121 sub_config.default_track = def;
4122 hb_subtitle_add( job, &sub_config, subtitle );
4127 // TODO: libhb holds onto a reference to the x264opts and is not
4128 // finished with it until encoding the job is done. But I can't
4129 // find a way to get at the job before it is removed in order to
4130 // free up the memory I am allocating here.
4131 // The short story is THIS LEAKS.
4132 x264opts = ghb_build_x264opts_string(js);
4134 if( *x264opts == '\0' )
4140 if (job->indepth_scan == 1)
4142 // Subtitle scan. Look for subtitle matching audio language
4145 * When subtitle scan is enabled do a fast pre-scan job
4146 * which will determine which subtitles to enable, if any.
4149 job->indepth_scan = 1;
4150 job->x264opts = NULL;
4153 * Add the pre-scan job
4155 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4159 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4160 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4163 * If subtitle_scan is enabled then only turn it on
4164 * for the second pass and then off again for the
4168 job->indepth_scan = 0;
4171 * If turbo options have been selected then append them
4172 * to the x264opts now (size includes one ':' and the '\0')
4174 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4176 gchar *tmp_x264opts;
4180 badapt = ghb_lookup_badapt(x264opts);
4183 extra_opts = g_strdup_printf("%s", turbo_opts);
4187 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4192 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4197 * No x264opts to modify, but apply the turbo options
4198 * anyway as they may be modifying defaults
4200 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4204 job->x264opts = tmp_x264opts;
4208 job->x264opts = x264opts;
4210 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4212 //if (job->x264opts != NULL)
4213 // g_free(job->x264opts);
4217 * On the second pass we turn off subtitle scan so that we
4218 * can actually encode using any subtitles that were auto
4219 * selected in the first pass (using the whacky select-subtitle
4220 * attribute of the job).
4222 job->indepth_scan = 0;
4223 job->x264opts = x264opts;
4224 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4226 //if (job->x264opts != NULL)
4227 // g_free(job->x264opts);
4231 job->x264opts = x264opts;
4232 job->indepth_scan = 0;
4234 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4236 //if (job->x264opts != NULL)
4237 // g_free(job->x264opts);
4240 // clean up audio list
4241 gint num_audio_tracks = hb_list_count(job->list_audio);
4242 for(ii = 0; ii < num_audio_tracks; ii++)
4244 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4245 hb_list_rem(job->list_audio, audio);
4249 // clean up subtitle list
4250 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4251 for(ii = 0; ii < num_subtitle_tracks; ii++)
4253 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4254 hb_list_rem(job->list_subtitle, subtitle);
4258 if (detel_str) g_free(detel_str);
4259 if (decomb_str) g_free(decomb_str);
4260 if (deint_str) g_free(deint_str);
4261 if (deblock_str) g_free(deblock_str);
4262 if (denoise_str) g_free(denoise_str);
4263 if (dest_str) g_free(dest_str);
4267 ghb_add_job(GValue *js, gint unique_id)
4269 // Since I'm doing a scan of the single title I want just prior
4270 // to adding the job, there is only the one title to choose from.
4271 add_job(h_queue, js, unique_id, 0);
4275 ghb_add_live_job(GValue *js, gint unique_id)
4277 // Since I'm doing a scan of the single title I want just prior
4278 // to adding the job, there is only the one title to choose from.
4279 gint titleindex = ghb_settings_combo_int(js, "title");
4280 add_job(h_scan, js, unique_id, titleindex);
4284 ghb_remove_job(gint unique_id)
4289 // Multiples passes all get the same id
4291 // Go backwards through list, so reordering doesn't screw me.
4292 ii = hb_count(h_queue) - 1;
4293 while ((job = hb_job(h_queue, ii--)) != NULL)
4295 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4296 hb_rem(h_queue, job);
4303 hb_start( h_queue );
4313 ghb_start_live_encode()
4319 ghb_stop_live_encode()
4328 hb_get_state2( h_queue, &s );
4330 if( s.state == HB_STATE_PAUSED )
4332 hb_resume( h_queue );
4336 hb_pause( h_queue );
4351 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4354 gint channels = gdk_pixbuf_get_n_channels (pb);
4355 gint stride = gdk_pixbuf_get_rowstride (pb);
4357 for (jj = 0; jj < width; jj++)
4359 dst = pixels + y * stride + (x+jj) * channels;
4360 for (ii = 0; ii < len; ii++)
4381 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4384 gint channels = gdk_pixbuf_get_n_channels (pb);
4385 gint stride = gdk_pixbuf_get_rowstride (pb);
4387 for (jj = 0; jj < width; jj++)
4389 dst = pixels + (y+jj) * stride + x * channels;
4390 for (ii = 0; ii < len; ii++)
4411 gint line_width = 8;
4418 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4423 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4425 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4431 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4433 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4439 ghb_get_preview_image(
4442 signal_user_data_t *ud,
4450 settings = ud->settings;
4451 list = hb_get_titles( h_scan );
4452 if( !hb_list_count( list ) )
4454 /* No valid title, stop right there */
4457 title = hb_list_item( list, titleindex );
4458 if (title == NULL) return NULL;
4459 if (title->job == NULL) return NULL;
4460 set_preview_job_settings(title->job, settings);
4462 // hb_get_preview doesn't compensate for anamorphic, so lets
4463 // calculate scale factors
4464 gint width, height, par_width = 1, par_height = 1;
4465 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4468 hb_set_anamorphic_size( title->job, &width, &height,
4469 &par_width, &par_height );
4472 // Make sure we have a big enough buffer to receive the image from libhb
4473 gint dstWidth = title->job->width;
4474 gint dstHeight= title->job->height;
4476 static guint8 *buffer = NULL;
4477 static gint bufferSize = 0;
4480 newSize = dstWidth * dstHeight * 4;
4481 if( bufferSize < newSize )
4483 bufferSize = newSize;
4484 buffer = (guint8*) g_realloc( buffer, bufferSize );
4486 hb_get_preview( h_scan, title, index, buffer );
4488 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4489 // libhb's format something suitable.
4491 // The image data returned by hb_get_preview is 4 bytes per pixel,
4492 // BGRA format. Alpha is ignored.
4494 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4495 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4497 guint32 *src = (guint32*)buffer;
4498 guint8 *dst = pixels;
4501 gint channels = gdk_pixbuf_get_n_channels (preview);
4502 gint stride = gdk_pixbuf_get_rowstride (preview);
4505 for (ii = 0; ii < dstHeight; ii++)
4508 for (jj = 0; jj < dstWidth; jj++)
4510 tmp[0] = src[0] >> 16;
4511 tmp[1] = src[0] >> 8;
4512 tmp[2] = src[0] >> 0;
4518 gint w = ghb_settings_get_int(settings, "scale_width");
4519 gint h = ghb_settings_get_int(settings, "scale_height");
4520 ghb_par_scale(ud, &w, &h, par_width, par_height);
4522 gint c0, c1, c2, c3;
4523 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4524 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4525 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4526 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4528 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4529 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4531 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4534 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4538 gint orig_w, orig_h;
4541 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4545 ss = gdk_screen_get_default();
4546 s_w = gdk_screen_get_width(ss);
4547 s_h = gdk_screen_get_height(ss);
4551 if (dstWidth > s_w * factor / 100)
4553 dstWidth = s_w * factor / 100;
4554 dstHeight = dstHeight * dstWidth / orig_w;
4556 if (dstHeight > s_h * factor / 100)
4558 dstHeight = s_h * factor / 100;
4559 dstWidth = dstWidth * dstHeight / orig_h;
4561 xscale *= (gdouble)dstWidth / orig_w;
4562 yscale *= (gdouble)dstHeight / orig_h;
4563 w *= (gdouble)dstWidth / orig_w;
4564 h *= (gdouble)dstHeight / orig_h;
4566 GdkPixbuf *scaled_preview;
4567 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4568 if (ghb_settings_get_boolean(settings, "show_crop"))
4575 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4577 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4579 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4581 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4583 g_object_unref (preview);
4584 return scaled_preview;
4588 sanitize_volname(gchar *name)
4613 ghb_dvd_volname(const gchar *device)
4616 name = hb_dvd_name((gchar*)device);
4617 if (name != NULL && name[0] != 0)
4619 name = g_strdup(name);
4620 sanitize_volname(name);