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"
41 const gchar *shortOpt;
52 static gchar **index_str = NULL;
53 static gint index_str_size = 0;
56 index_str_init(gint max_index)
60 if (max_index+1 > index_str_size)
62 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
63 for (ii = index_str_size; ii <= max_index; ii++)
65 index_str[ii] = g_strdup_printf("%d", ii);
67 index_str_size = max_index + 1;
71 static options_map_t d_par_opts[] =
74 {"Strict", "1", 1, "1"},
75 {"Loose", "2", 2, "2"},
76 {"Custom", "3", 3, "3"},
78 combo_opts_t par_opts =
80 sizeof(d_par_opts)/sizeof(options_map_t),
84 static options_map_t d_alignment_opts[] =
89 {"16", "16", 16, "16"},
91 combo_opts_t alignment_opts =
93 sizeof(d_alignment_opts)/sizeof(options_map_t),
97 static options_map_t d_logging_opts[] =
103 combo_opts_t logging_opts =
105 sizeof(d_logging_opts)/sizeof(options_map_t),
109 static options_map_t d_vqual_granularity_opts[] =
111 {"0.2", "0.2", 0.2, "0.2"},
112 {"0.25", "0.25", 0.25, "0.25"},
113 {"0.5", "0.5", 0.5, "0.5"},
116 combo_opts_t vqual_granularity_opts =
118 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
119 d_vqual_granularity_opts
122 static options_map_t d_container_opts[] =
124 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
125 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
126 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
128 combo_opts_t container_opts =
130 sizeof(d_container_opts)/sizeof(options_map_t),
134 static options_map_t d_detel_opts[] =
136 {"None", "none", 0, ""},
137 {"Custom", "custom", 1, ""},
138 {"Default","default",2, NULL},
140 combo_opts_t detel_opts =
142 sizeof(d_detel_opts)/sizeof(options_map_t),
146 static options_map_t d_decomb_opts[] =
148 {"None", "none", 0, ""},
149 {"Custom", "custom", 1, ""},
150 {"Default","default",2, NULL},
152 combo_opts_t decomb_opts =
154 sizeof(d_decomb_opts)/sizeof(options_map_t),
158 static options_map_t d_deint_opts[] =
160 {"None", "none", 0, ""},
161 {"Custom", "custom", 1, ""},
162 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
163 {"Slow", "slow", 3, "2:-1:-1:0:1"},
164 {"Slower", "slower", 4, "0:-1:-1:0:1"},
166 combo_opts_t deint_opts =
168 sizeof(d_deint_opts)/sizeof(options_map_t),
172 static options_map_t d_denoise_opts[] =
174 {"None", "none", 0, ""},
175 {"Custom", "custom", 1, ""},
176 {"Weak", "weak", 2, "2:1:2:3"},
177 {"Medium", "medium", 3, "3:2:2:3"},
178 {"Strong", "strong", 4, "7:7:5:5"},
180 combo_opts_t denoise_opts =
182 sizeof(d_denoise_opts)/sizeof(options_map_t),
186 static options_map_t d_vcodec_opts[] =
188 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
189 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
190 {"Theora", "theora", HB_VCODEC_THEORA, ""},
192 combo_opts_t vcodec_opts =
194 sizeof(d_vcodec_opts)/sizeof(options_map_t),
198 static options_map_t d_acodec_opts[] =
200 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
201 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
202 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
203 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
204 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
205 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
207 combo_opts_t acodec_opts =
209 sizeof(d_acodec_opts)/sizeof(options_map_t),
213 static options_map_t d_direct_opts[] =
215 {"None", "none", 0, "none"},
216 {"Spatial", "spatial", 1, "spatial"},
217 {"Temporal", "temporal", 2, "temporal"},
218 {"Automatic", "auto", 3, "auto"},
220 combo_opts_t direct_opts =
222 sizeof(d_direct_opts)/sizeof(options_map_t),
226 static options_map_t d_badapt_opts[] =
228 {"Off", "0", 0, "0"},
229 {"Fast", "1", 1, "1"},
230 {"Optimal", "2", 2, "2"},
232 combo_opts_t badapt_opts =
234 sizeof(d_badapt_opts)/sizeof(options_map_t),
238 static options_map_t d_me_opts[] =
240 {"Diamond", "dia", 0, "dia"},
241 {"Hexagon", "hex", 1, "hex"},
242 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
243 {"Exhaustive", "esa", 3, "esa"},
244 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
246 combo_opts_t me_opts =
248 sizeof(d_me_opts)/sizeof(options_map_t),
252 static options_map_t d_subme_opts[] =
264 combo_opts_t subme_opts =
266 sizeof(d_subme_opts)/sizeof(options_map_t),
270 static options_map_t d_analyse_opts[] =
272 {"Some", "some", 0, "some"},
273 {"None", "none", 1, "none"},
274 {"All", "all", 2, "all"},
275 {"Custom", "custom", 3, "all"},
277 combo_opts_t analyse_opts =
279 sizeof(d_analyse_opts)/sizeof(options_map_t),
283 static options_map_t d_trellis_opts[] =
285 {"Disabled", "0", 0, "0"},
286 {"Final Macro Block", "1", 1, "1"},
287 {"Always", "2", 2, "2"},
289 combo_opts_t trellis_opts =
291 sizeof(d_trellis_opts)/sizeof(options_map_t),
295 combo_opts_t subtitle_opts =
301 combo_opts_t title_opts =
307 combo_opts_t audio_track_opts =
319 combo_name_map_t combo_name_map[] =
321 {"PicturePAR", &par_opts},
322 {"PictureModulus", &alignment_opts},
323 {"LoggingLevel", &logging_opts},
324 {"VideoQualityGranularity", &vqual_granularity_opts},
325 {"FileFormat", &container_opts},
326 {"PictureDeinterlace", &deint_opts},
327 {"PictureDecomb", &decomb_opts},
328 {"PictureDetelecine", &detel_opts},
329 {"PictureDenoise", &denoise_opts},
330 {"VideoEncoder", &vcodec_opts},
331 {"AudioEncoder", &acodec_opts},
332 {"x264_direct", &direct_opts},
333 {"x264_b_adapt", &badapt_opts},
334 {"x264_me", &me_opts},
335 {"x264_subme", &subme_opts},
336 {"x264_analyse", &analyse_opts},
337 {"x264_trellis", &trellis_opts},
338 {"SubtitleTrack", &subtitle_opts},
339 {"title", &title_opts},
340 {"AudioTrack", &audio_track_opts},
345 typedef struct iso639_lang_t
347 char * eng_name; /* Description in English */
348 char * native_name; /* Description in native language */
349 char * iso639_1; /* ISO-639-1 (2 characters) code */
350 char * iso639_2; /* ISO-639-2/t (3 character) code */
351 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
355 const iso639_lang_t ghb_language_table[] =
357 { "Any", "", "zz", "und" },
358 { "Afar", "", "aa", "aar" },
359 { "Abkhazian", "", "ab", "abk" },
360 { "Afrikaans", "", "af", "afr" },
361 { "Akan", "", "ak", "aka" },
362 { "Albanian", "", "sq", "sqi", "alb" },
363 { "Amharic", "", "am", "amh" },
364 { "Arabic", "", "ar", "ara" },
365 { "Aragonese", "", "an", "arg" },
366 { "Armenian", "", "hy", "hye", "arm" },
367 { "Assamese", "", "as", "asm" },
368 { "Avaric", "", "av", "ava" },
369 { "Avestan", "", "ae", "ave" },
370 { "Aymara", "", "ay", "aym" },
371 { "Azerbaijani", "", "az", "aze" },
372 { "Bashkir", "", "ba", "bak" },
373 { "Bambara", "", "bm", "bam" },
374 { "Basque", "", "eu", "eus", "baq" },
375 { "Belarusian", "", "be", "bel" },
376 { "Bengali", "", "bn", "ben" },
377 { "Bihari", "", "bh", "bih" },
378 { "Bislama", "", "bi", "bis" },
379 { "Bosnian", "", "bs", "bos" },
380 { "Breton", "", "br", "bre" },
381 { "Bulgarian", "", "bg", "bul" },
382 { "Burmese", "", "my", "mya", "bur" },
383 { "Catalan", "", "ca", "cat" },
384 { "Chamorro", "", "ch", "cha" },
385 { "Chechen", "", "ce", "che" },
386 { "Chinese", "", "zh", "zho", "chi" },
387 { "Church Slavic", "", "cu", "chu" },
388 { "Chuvash", "", "cv", "chv" },
389 { "Cornish", "", "kw", "cor" },
390 { "Corsican", "", "co", "cos" },
391 { "Cree", "", "cr", "cre" },
392 { "Czech", "", "cs", "ces", "cze" },
393 { "Danish", "Dansk", "da", "dan" },
394 { "Divehi", "", "dv", "div" },
395 { "Dutch", "Nederlands", "nl", "nld", "dut" },
396 { "Dzongkha", "", "dz", "dzo" },
397 { "English", "English", "en", "eng" },
398 { "Esperanto", "", "eo", "epo" },
399 { "Estonian", "", "et", "est" },
400 { "Ewe", "", "ee", "ewe" },
401 { "Faroese", "", "fo", "fao" },
402 { "Fijian", "", "fj", "fij" },
403 { "Finnish", "Suomi", "fi", "fin" },
404 { "French", "Francais", "fr", "fra", "fre" },
405 { "Western Frisian", "", "fy", "fry" },
406 { "Fulah", "", "ff", "ful" },
407 { "Georgian", "", "ka", "kat", "geo" },
408 { "German", "Deutsch", "de", "deu", "ger" },
409 { "Gaelic (Scots)", "", "gd", "gla" },
410 { "Irish", "", "ga", "gle" },
411 { "Galician", "", "gl", "glg" },
412 { "Manx", "", "gv", "glv" },
413 { "Greek, Modern", "", "el", "ell", "gre" },
414 { "Guarani", "", "gn", "grn" },
415 { "Gujarati", "", "gu", "guj" },
416 { "Haitian", "", "ht", "hat" },
417 { "Hausa", "", "ha", "hau" },
418 { "Hebrew", "", "he", "heb" },
419 { "Herero", "", "hz", "her" },
420 { "Hindi", "", "hi", "hin" },
421 { "Hiri Motu", "", "ho", "hmo" },
422 { "Hungarian", "Magyar", "hu", "hun" },
423 { "Igbo", "", "ig", "ibo" },
424 { "Icelandic", "Islenska", "is", "isl", "ice" },
425 { "Ido", "", "io", "ido" },
426 { "Sichuan Yi", "", "ii", "iii" },
427 { "Inuktitut", "", "iu", "iku" },
428 { "Interlingue", "", "ie", "ile" },
429 { "Interlingua", "", "ia", "ina" },
430 { "Indonesian", "", "id", "ind" },
431 { "Inupiaq", "", "ik", "ipk" },
432 { "Italian", "Italiano", "it", "ita" },
433 { "Javanese", "", "jv", "jav" },
434 { "Japanese", "", "ja", "jpn" },
435 { "Kalaallisut", "", "kl", "kal" },
436 { "Kannada", "", "kn", "kan" },
437 { "Kashmiri", "", "ks", "kas" },
438 { "Kanuri", "", "kr", "kau" },
439 { "Kazakh", "", "kk", "kaz" },
440 { "Central Khmer", "", "km", "khm" },
441 { "Kikuyu", "", "ki", "kik" },
442 { "Kinyarwanda", "", "rw", "kin" },
443 { "Kirghiz", "", "ky", "kir" },
444 { "Komi", "", "kv", "kom" },
445 { "Kongo", "", "kg", "kon" },
446 { "Korean", "", "ko", "kor" },
447 { "Kuanyama", "", "kj", "kua" },
448 { "Kurdish", "", "ku", "kur" },
449 { "Lao", "", "lo", "lao" },
450 { "Latin", "", "la", "lat" },
451 { "Latvian", "", "lv", "lav" },
452 { "Limburgan", "", "li", "lim" },
453 { "Lingala", "", "ln", "lin" },
454 { "Lithuanian", "", "lt", "lit" },
455 { "Luxembourgish", "", "lb", "ltz" },
456 { "Luba-Katanga", "", "lu", "lub" },
457 { "Ganda", "", "lg", "lug" },
458 { "Macedonian", "", "mk", "mkd", "mac" },
459 { "Marshallese", "", "mh", "mah" },
460 { "Malayalam", "", "ml", "mal" },
461 { "Maori", "", "mi", "mri", "mao" },
462 { "Marathi", "", "mr", "mar" },
463 { "Malay", "", "ms", "msa", "msa" },
464 { "Malagasy", "", "mg", "mlg" },
465 { "Maltese", "", "mt", "mlt" },
466 { "Moldavian", "", "mo", "mol" },
467 { "Mongolian", "", "mn", "mon" },
468 { "Nauru", "", "na", "nau" },
469 { "Navajo", "", "nv", "nav" },
470 { "Ndebele, South", "", "nr", "nbl" },
471 { "Ndebele, North", "", "nd", "nde" },
472 { "Ndonga", "", "ng", "ndo" },
473 { "Nepali", "", "ne", "nep" },
474 { "Norwegian Nynorsk", "", "nn", "nno" },
475 { "Norwegian Bokmål", "", "nb", "nob" },
476 { "Norwegian", "Norsk", "no", "nor" },
477 { "Chichewa; Nyanja", "", "ny", "nya" },
478 { "Occitan", "", "oc", "oci" },
479 { "Ojibwa", "", "oj", "oji" },
480 { "Oriya", "", "or", "ori" },
481 { "Oromo", "", "om", "orm" },
482 { "Ossetian", "", "os", "oss" },
483 { "Panjabi", "", "pa", "pan" },
484 { "Persian", "", "fa", "fas", "per" },
485 { "Pali", "", "pi", "pli" },
486 { "Polish", "", "pl", "pol" },
487 { "Portuguese", "Portugues", "pt", "por" },
488 { "Pushto", "", "ps", "pus" },
489 { "Quechua", "", "qu", "que" },
490 { "Romansh", "", "rm", "roh" },
491 { "Romanian", "", "ro", "ron", "rum" },
492 { "Rundi", "", "rn", "run" },
493 { "Russian", "", "ru", "rus" },
494 { "Sango", "", "sg", "sag" },
495 { "Sanskrit", "", "sa", "san" },
496 { "Serbian", "", "sr", "srp", "scc" },
497 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
498 { "Sinhala", "", "si", "sin" },
499 { "Slovak", "", "sk", "slk", "slo" },
500 { "Slovenian", "", "sl", "slv" },
501 { "Northern Sami", "", "se", "sme" },
502 { "Samoan", "", "sm", "smo" },
503 { "Shona", "", "sn", "sna" },
504 { "Sindhi", "", "sd", "snd" },
505 { "Somali", "", "so", "som" },
506 { "Sotho, Southern", "", "st", "sot" },
507 { "Spanish", "Espanol", "es", "spa" },
508 { "Sardinian", "", "sc", "srd" },
509 { "Swati", "", "ss", "ssw" },
510 { "Sundanese", "", "su", "sun" },
511 { "Swahili", "", "sw", "swa" },
512 { "Swedish", "Svenska", "sv", "swe" },
513 { "Tahitian", "", "ty", "tah" },
514 { "Tamil", "", "ta", "tam" },
515 { "Tatar", "", "tt", "tat" },
516 { "Telugu", "", "te", "tel" },
517 { "Tajik", "", "tg", "tgk" },
518 { "Tagalog", "", "tl", "tgl" },
519 { "Thai", "", "th", "tha" },
520 { "Tibetan", "", "bo", "bod", "tib" },
521 { "Tigrinya", "", "ti", "tir" },
522 { "Tonga", "", "to", "ton" },
523 { "Tswana", "", "tn", "tsn" },
524 { "Tsonga", "", "ts", "tso" },
525 { "Turkmen", "", "tk", "tuk" },
526 { "Turkish", "", "tr", "tur" },
527 { "Twi", "", "tw", "twi" },
528 { "Uighur", "", "ug", "uig" },
529 { "Ukrainian", "", "uk", "ukr" },
530 { "Urdu", "", "ur", "urd" },
531 { "Uzbek", "", "uz", "uzb" },
532 { "Venda", "", "ve", "ven" },
533 { "Vietnamese", "", "vi", "vie" },
534 { "Volapük", "", "vo", "vol" },
535 { "Welsh", "", "cy", "cym", "wel" },
536 { "Walloon", "", "wa", "wln" },
537 { "Wolof", "", "wo", "wol" },
538 { "Xhosa", "", "xh", "xho" },
539 { "Yiddish", "", "yi", "yid" },
540 { "Yoruba", "", "yo", "yor" },
541 { "Zhuang", "", "za", "zha" },
542 { "Zulu", "", "zu", "zul" },
543 {NULL, NULL, NULL, NULL}
545 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
547 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
550 del_tree(const gchar *name, gboolean del_top)
554 if (g_file_test(name, G_FILE_TEST_IS_DIR))
556 GDir *gdir = g_dir_open(name, 0, NULL);
557 file = g_dir_read_name(gdir);
561 path = g_strdup_printf("%s/%s", name, file);
562 del_tree(path, TRUE);
564 file = g_dir_read_name(gdir);
579 return hb_get_version(NULL);
584 signal_user_data_t *ud,
592 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
601 *step = ghb_settings_combo_double(ud->settings,
602 "VideoQualityGranularity");
603 if (*step == 0.2 || *step == 0.5)
605 else if (*step == 0.25)
610 case HB_VCODEC_FFMPEG:
618 case HB_VCODEC_THEORA:
637 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
641 const gchar *result = "";
643 str = ghb_value_string(gval);
644 for (ii = 0; ii < opts->count; ii++)
646 if (strcmp(opts->map[ii].shortOpt, str) == 0)
648 result = opts->map[ii].svalue;
657 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
663 str = ghb_value_string(gval);
664 for (ii = 0; ii < opts->count; ii++)
666 if (strcmp(opts->map[ii].shortOpt, str) == 0)
668 result = opts->map[ii].ivalue;
677 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
683 str = ghb_value_string(gval);
684 for (ii = 0; ii < opts->count; ii++)
686 if (strcmp(opts->map[ii].shortOpt, str) == 0)
688 result = opts->map[ii].ivalue;
697 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
701 const gchar *result = "";
703 str = ghb_value_string(gval);
704 for (ii = 0; ii < opts->count; ii++)
706 if (strcmp(opts->map[ii].shortOpt, str) == 0)
708 result = opts->map[ii].option;
717 lookup_mix_int(const GValue *mix)
724 str = ghb_value_string(mix);
725 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
727 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
729 result = hb_audio_mixdowns[ii].amixdown;
738 lookup_mix_option(const GValue *mix)
742 gchar *result = "None";
745 str = ghb_value_string(mix);
746 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
748 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
750 result = hb_audio_mixdowns[ii].human_readable_name;
759 lookup_video_rate_int(const GValue *vrate)
765 str = ghb_value_string(vrate);
766 for (ii = 0; ii < hb_video_rates_count; ii++)
768 if (strcmp(hb_video_rates[ii].string, str) == 0)
770 result = hb_video_rates[ii].rate;
775 // Default to "same as source"
780 lookup_video_rate_option(const GValue *vrate)
784 const gchar *result = "Same as source";
786 str = ghb_value_string(vrate);
787 for (ii = 0; ii < hb_video_rates_count; ii++)
789 if (strcmp(hb_video_rates[ii].string, str) == 0)
791 result = hb_video_rates[ii].string;
796 // Default to "same as source"
801 lookup_audio_rate_int(const GValue *rate)
807 // Coincidentally, the string "source" will return 0
808 // which is our flag to use "same as source"
809 str = ghb_value_string(rate);
810 for (ii = 0; ii < hb_audio_rates_count; ii++)
812 if (strcmp(hb_audio_rates[ii].string, str) == 0)
814 result = hb_audio_rates[ii].rate;
823 lookup_audio_rate_option(const GValue *rate)
827 const gchar *result = "Same as source";
829 // Coincidentally, the string "source" will return 0
830 // which is our flag to use "same as source"
831 str = ghb_value_string(rate);
832 for (ii = 0; ii < hb_audio_rates_count; ii++)
834 if (strcmp(hb_audio_rates[ii].string, str) == 0)
836 result = hb_audio_rates[ii].string;
845 lookup_audio_bitrate_int(const GValue *rate)
851 // Coincidentally, the string "source" will return 0
852 // which is our flag to use "same as source"
853 str = ghb_value_string(rate);
854 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
856 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
858 result = hb_audio_bitrates[ii].rate;
867 lookup_audio_bitrate_option(const GValue *rate)
871 const gchar *result = "Same as source";
873 // Coincidentally, the string "source" will return 0
874 // which is our flag to use "same as source"
875 str = ghb_value_string(rate);
876 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
878 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
880 result = hb_audio_bitrates[ii].string;
889 lookup_audio_lang_int(const GValue *rate)
895 // Coincidentally, the string "source" will return 0
896 // which is our flag to use "same as source"
897 str = ghb_value_string(rate);
898 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
900 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
911 lookup_audio_lang_option(const GValue *rate)
915 const gchar *result = "Same as source";
917 // Coincidentally, the string "source" will return 0
918 // which is our flag to use "same as source"
919 str = ghb_value_string(rate);
920 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
922 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
924 result = ghb_language_table[ii].eng_name;
933 get_acodec_value(gint val)
935 GValue *value = NULL;
938 for (ii = 0; ii < acodec_opts.count; ii++)
940 if ((int)acodec_opts.map[ii].ivalue == val)
942 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
950 get_amix_value(gint val)
952 GValue *value = NULL;
955 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
957 if (hb_audio_mixdowns[ii].amixdown == val)
959 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
966 // Handle for libhb. Gets set by ghb_backend_init()
967 static hb_handle_t * h_scan = NULL;
968 static hb_handle_t * h_queue = NULL;
970 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
977 hb_get_tempory_directory(h_scan, dir);
978 return g_strdup(dir);
982 ghb_hb_cleanup(gboolean partial)
986 hb_get_tempory_directory(h_scan, dir);
987 del_tree(dir, !partial);
991 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
999 titleindex = ghb_settings_combo_int(ud->settings, "title");
1005 hb_subtitle_t * sub;
1007 if (h_scan == NULL) return VOBSUB;
1008 list = hb_get_titles( h_scan );
1009 if( !hb_list_count( list ) )
1011 /* No valid title, stop right there */
1014 title = hb_list_item( list, titleindex );
1015 if (title == NULL) return VOBSUB; // Bad titleindex
1016 sub = hb_list_item( title->list_subtitle, track);
1024 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1027 const gchar * name = "Unknown";
1040 titleindex = ghb_settings_combo_int(ud->settings, "title");
1046 hb_subtitle_t * sub;
1050 list = hb_get_titles( h_scan );
1051 if( !hb_list_count( list ) )
1054 title = hb_list_item( list, titleindex );
1058 sub = hb_list_item( title->list_subtitle, track);
1061 switch (sub->source)
1082 ghb_get_title_number(gint titleindex)
1087 if (h_scan == NULL) return 1;
1088 list = hb_get_titles( h_scan );
1089 if( !hb_list_count( list ) )
1091 /* No valid title, stop right there */
1094 title = hb_list_item( list, titleindex );
1095 if (title == NULL) return 1; // Bad titleindex
1096 return title->index;
1099 static hb_audio_config_t*
1100 get_hb_audio(gint titleindex, gint track)
1104 hb_audio_config_t *audio = NULL;
1106 if (h_scan == NULL) return NULL;
1107 list = hb_get_titles( h_scan );
1108 if( !hb_list_count( list ) )
1110 /* No valid title, stop right there */
1113 title = hb_list_item( list, titleindex );
1114 if (title == NULL) return NULL; // Bad titleindex
1115 if (!hb_list_count(title->list_audio))
1119 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1124 search_rates(hb_rate_t *rates, gint rate, gint count)
1127 for (ii = 0; ii < count; ii++)
1129 if (rates[ii].rate == rate)
1135 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1137 static GtkListStore*
1138 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1141 GtkListStore *store;
1143 g_debug("get_combo_box_store() %s\n", name);
1144 // First modify the combobox model to allow greying out of options
1145 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1146 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1151 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1153 GtkListStore *store;
1156 store = get_combo_box_store(builder, name);
1157 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1159 gtk_list_store_set(store, &iter,
1166 ghb_grey_combo_options(GtkBuilder *builder)
1169 gint container, track, titleindex, acodec;
1170 hb_audio_config_t *audio = NULL;
1173 widget = GHB_WIDGET (builder, "title");
1174 gval = ghb_widget_value(widget);
1175 titleindex = ghb_lookup_combo_int("title", gval);
1176 ghb_value_free(gval);
1177 widget = GHB_WIDGET (builder, "AudioTrack");
1178 gval = ghb_widget_value(widget);
1179 track = ghb_lookup_combo_int("AudioTrack", gval);
1180 ghb_value_free(gval);
1181 audio = get_hb_audio(titleindex, track);
1182 widget = GHB_WIDGET (builder, "FileFormat");
1183 gval = ghb_widget_value(widget);
1184 container = ghb_lookup_combo_int("FileFormat", gval);
1185 ghb_value_free(gval);
1187 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1188 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1189 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1190 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1192 gboolean allow_dca = TRUE;
1193 allow_dca = (container != HB_MUX_MP4);
1195 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1197 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1199 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1201 if (audio && audio->in.codec != HB_ACODEC_AC3)
1203 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1205 if (audio && audio->in.codec != HB_ACODEC_DCA)
1207 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1209 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1211 widget = GHB_WIDGET (builder, "AudioEncoder");
1212 gval = ghb_widget_value(widget);
1213 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1214 ghb_value_free(gval);
1215 if (acodec != HB_ACODEC_AC3)
1217 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1219 if (container == HB_MUX_MP4)
1221 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1222 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1223 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1225 else if (container == HB_MUX_AVI)
1227 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1228 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1229 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1231 else if (container == HB_MUX_OGM)
1233 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1236 gboolean allow_mono = TRUE;
1237 gboolean allow_stereo = TRUE;
1238 gboolean allow_dolby = TRUE;
1239 gboolean allow_dpl2 = TRUE;
1240 gboolean allow_6ch = TRUE;
1244 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1245 (acodec != HB_ACODEC_LAME);
1246 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1248 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1250 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1251 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1252 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1253 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1255 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1256 (acodec != HB_ACODEC_LAME) &&
1257 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1258 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1260 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1261 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1262 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1263 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1264 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1268 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1270 hb_audio_config_t *audio = NULL;
1271 gboolean allow_mono = TRUE;
1272 gboolean allow_stereo = TRUE;
1273 gboolean allow_dolby = TRUE;
1274 gboolean allow_dpl2 = TRUE;
1275 gboolean allow_6ch = TRUE;
1277 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1279 // Audio codec pass-thru. No mixdown
1282 audio = get_hb_audio(titleindex, track);
1286 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1287 (acodec != HB_ACODEC_LAME);
1288 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1290 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1292 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1293 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1294 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1295 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1297 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1298 (acodec != HB_ACODEC_LAME) &&
1299 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1300 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1302 gboolean greater = FALSE;
1305 // If no mix is specified, select the best available.
1306 mix = HB_AMIXDOWN_6CH;
1308 if (mix == HB_AMIXDOWN_6CH)
1311 if (allow_6ch) return HB_AMIXDOWN_6CH;
1313 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1316 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1318 if (mix == HB_AMIXDOWN_DOLBY || greater)
1321 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1323 if (mix == HB_AMIXDOWN_STEREO || greater)
1326 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1328 if (mix == HB_AMIXDOWN_MONO || greater)
1331 if (allow_mono) return HB_AMIXDOWN_MONO;
1333 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1334 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1335 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1336 if (allow_6ch) return HB_AMIXDOWN_6CH;
1340 // Set up the model for the combo box
1342 init_combo_box(GtkBuilder *builder, const gchar *name)
1345 GtkListStore *store;
1346 GtkCellRenderer *cell;
1348 g_debug("init_combo_box() %s\n", name);
1349 // First modify the combobox model to allow greying out of options
1350 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1354 // 1 - String to display
1355 // 2 - bool indicating whether the entry is selectable (grey or not)
1356 // 3 - String that is used for presets
1357 // 4 - Int value determined by backend
1358 // 5 - String value determined by backend
1359 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1360 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1361 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1363 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1365 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1366 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1367 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1368 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1369 "text", 0, "sensitive", 1, NULL);
1372 { // Combo box entry
1373 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1378 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1381 GtkListStore *store;
1384 g_debug("audio_samplerate_opts_set ()\n");
1385 store = get_combo_box_store(builder, name);
1386 gtk_list_store_clear(store);
1387 // Add an item for "Same As Source"
1388 gtk_list_store_append(store, &iter);
1389 gtk_list_store_set(store, &iter,
1390 0, "Same as source",
1396 for (ii = 0; ii < count; ii++)
1398 gtk_list_store_append(store, &iter);
1399 gtk_list_store_set(store, &iter,
1400 0, rates[ii].string,
1402 2, rates[ii].string,
1403 3, (gdouble)rates[ii].rate,
1404 4, rates[ii].string,
1410 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1413 GtkListStore *store;
1416 g_debug("video_rate_opts_set ()\n");
1417 store = get_combo_box_store(builder, name);
1418 gtk_list_store_clear(store);
1419 // Add an item for "Same As Source"
1420 gtk_list_store_append(store, &iter);
1421 gtk_list_store_set(store, &iter,
1422 0, "Same as source",
1428 for (ii = 0; ii < count; ii++)
1432 if (strcmp(rates[ii].string, "23.976") == 0)
1434 desc = "(NTSC Film)";
1436 else if (strcmp(rates[ii].string, "25") == 0)
1438 desc = "(PAL Film/Video)";
1440 else if (strcmp(rates[ii].string, "29.97") == 0)
1442 desc = "(NTSC Video)";
1444 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1445 gtk_list_store_append(store, &iter);
1446 gtk_list_store_set(store, &iter,
1449 2, rates[ii].string,
1450 3, (gdouble)rates[ii].rate,
1451 4, rates[ii].string,
1458 mix_opts_set(GtkBuilder *builder, const gchar *name)
1461 GtkListStore *store;
1464 g_debug("mix_opts_set ()\n");
1465 store = get_combo_box_store(builder, name);
1466 gtk_list_store_clear(store);
1467 gtk_list_store_append(store, &iter);
1468 gtk_list_store_set(store, &iter,
1475 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1477 gtk_list_store_append(store, &iter);
1478 gtk_list_store_set(store, &iter,
1479 0, hb_audio_mixdowns[ii].human_readable_name,
1481 2, hb_audio_mixdowns[ii].short_name,
1482 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1483 4, hb_audio_mixdowns[ii].internal_name,
1489 language_opts_set(GtkBuilder *builder, const gchar *name)
1492 GtkListStore *store;
1495 g_debug("language_opts_set ()\n");
1496 store = get_combo_box_store(builder, name);
1497 gtk_list_store_clear(store);
1498 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1500 gtk_list_store_append(store, &iter);
1501 gtk_list_store_set(store, &iter,
1502 0, ghb_language_table[ii].eng_name,
1504 2, ghb_language_table[ii].iso639_2,
1506 4, ghb_language_table[ii].iso639_1,
1511 static gchar **titles = NULL;
1514 title_opts_set(GtkBuilder *builder, const gchar *name)
1517 GtkListStore *store;
1518 hb_list_t * list = NULL;
1519 hb_title_t * title = NULL;
1523 g_debug("title_opts_set ()\n");
1524 store = get_combo_box_store(builder, name);
1525 gtk_list_store_clear(store);
1528 list = hb_get_titles( h_scan );
1529 count = hb_list_count( list );
1530 if (count > 100) count = 100;
1532 if (titles) g_strfreev(titles);
1533 if (title_opts.map) g_free(title_opts.map);
1536 title_opts.count = count;
1537 title_opts.map = g_malloc(count*sizeof(options_map_t));
1538 titles = g_malloc((count+1) * sizeof(gchar*));
1542 title_opts.count = 1;
1543 title_opts.map = g_malloc(sizeof(options_map_t));
1548 // No titles. Fill in a default.
1549 gtk_list_store_append(store, &iter);
1550 gtk_list_store_set(store, &iter,
1557 title_opts.map[0].option = "No Titles";
1558 title_opts.map[0].shortOpt = "none";
1559 title_opts.map[0].ivalue = -1;
1560 title_opts.map[0].svalue = "none";
1563 for (ii = 0; ii < count; ii++)
1565 title = (hb_title_t*)hb_list_item(list, ii);
1566 if (title->duration != 0)
1568 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1569 title->index, title->hours, title->minutes, title->seconds);
1573 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1575 gtk_list_store_append(store, &iter);
1576 gtk_list_store_set(store, &iter,
1583 title_opts.map[ii].option = titles[ii];
1584 title_opts.map[ii].shortOpt = titles[ii];
1585 title_opts.map[ii].ivalue = ii;
1586 title_opts.map[ii].svalue = titles[ii];
1592 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1595 gboolean foundit = FALSE;
1597 if (gtk_tree_model_get_iter_first (store, iter))
1601 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1602 if (value == (int)ivalue)
1607 } while (gtk_tree_model_iter_next (store, iter));
1613 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1616 GtkListStore *store;
1617 hb_list_t * list = NULL;
1618 hb_title_t * title = NULL;
1619 hb_audio_config_t * audio;
1623 g_debug("audio_track_opts_set ()\n");
1624 store = get_combo_box_store(builder, name);
1625 gtk_list_store_clear(store);
1628 list = hb_get_titles( h_scan );
1629 title = (hb_title_t*)hb_list_item( list, titleindex );
1632 count = hb_list_count( title->list_audio );
1635 if (count > 100) count = 100;
1636 if (audio_track_opts.map) g_free(audio_track_opts.map);
1639 audio_track_opts.count = count;
1640 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1644 audio_track_opts.count = 1;
1645 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1649 // No audio. set some default
1650 gtk_list_store_append(store, &iter);
1651 gtk_list_store_set(store, &iter,
1658 audio_track_opts.map[0].option = "No Audio";
1659 audio_track_opts.map[0].shortOpt = "none";
1660 audio_track_opts.map[0].ivalue = -1;
1661 audio_track_opts.map[0].svalue = "none";
1664 index_str_init(count-1);
1665 for (ii = 0; ii < count; ii++)
1667 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1668 gtk_list_store_append(store, &iter);
1669 gtk_list_store_set(store, &iter,
1670 0, audio->lang.description,
1676 audio_track_opts.map[ii].option = audio->lang.description,
1677 audio_track_opts.map[ii].shortOpt = index_str[ii];
1678 audio_track_opts.map[ii].ivalue = ii;
1679 audio_track_opts.map[ii].svalue = index_str[ii];
1684 ghb_subtitle_track_model(signal_user_data_t *ud, gint titleindex)
1687 GtkListStore *store;
1688 hb_list_t * list = NULL;
1689 hb_title_t * title = NULL;
1690 hb_subtitle_t * subtitle;
1693 g_debug("ghb_subtitle_track_model ()\n");
1696 list = hb_get_titles( h_scan );
1697 title = (hb_title_t*)hb_list_item( list, titleindex );
1700 count = hb_list_count( title->list_subtitle );
1703 if (count > 100) count = 100;
1704 if (subtitle_opts.map) g_free(subtitle_opts.map);
1707 subtitle_opts.count = count+1;
1708 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1712 subtitle_opts.count = LANG_TABLE_SIZE+1;
1713 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1715 if (ud->subtitle_track_model == NULL)
1718 // 1 - String to display
1719 // 2 - bool indicating whether the entry is selectable (grey or not)
1720 // 3 - String that is used for presets
1721 // 4 - Int value determined by backend
1722 // 5 - String value determined by backend
1723 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1724 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1725 ud->subtitle_track_model = store;
1729 store = ud->subtitle_track_model;
1730 gtk_list_store_clear(store);
1732 gtk_list_store_append(store, &iter);
1733 gtk_list_store_set(store, &iter,
1740 subtitle_opts.map[0].option = "Same as audio";
1741 subtitle_opts.map[0].shortOpt = "-1";
1742 subtitle_opts.map[0].ivalue = -1;
1743 subtitle_opts.map[0].svalue = "auto";
1746 index_str_init(count-1);
1747 for (ii = 0; ii < count; ii++)
1749 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1750 // Skip subtitles that must be burned if there is already
1751 // a burned subtitle in the list
1752 subtitle_opts.map[ii+1].option = subtitle->lang;
1753 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1754 subtitle_opts.map[ii+1].ivalue = ii;
1755 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1756 gtk_list_store_append(store, &iter);
1757 gtk_list_store_set(store, &iter,
1762 4, subtitle->iso639_2,
1768 index_str_init(LANG_TABLE_SIZE-1);
1769 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1771 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1772 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1773 subtitle_opts.map[ii+1].ivalue = ii;
1774 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1775 gtk_list_store_append(store, &iter);
1776 gtk_list_store_set(store, &iter,
1777 0, ghb_language_table[ii].eng_name,
1781 4, ghb_language_table[ii].iso639_2,
1794 guint64 longest = 0;
1795 gint titleindex = 0;
1797 g_debug("ghb_longest_title ()\n");
1798 if (h_scan == NULL) return 0;
1799 list = hb_get_titles( h_scan );
1800 count = hb_list_count( list );
1801 if (count > 100) count = 100;
1802 for (ii = 0; ii < count; ii++)
1804 title = (hb_title_t*)hb_list_item(list, ii);
1805 if (title->duration > longest)
1808 longest = title->duration;
1815 ghb_find_audio_track(
1819 GHashTable *track_indices)
1823 hb_audio_config_t * audio;
1830 g_debug("find_audio_track ()\n");
1831 if (h_scan == NULL) return -1;
1832 list = hb_get_titles( h_scan );
1833 title = (hb_title_t*)hb_list_item( list, titleindex );
1836 count = hb_list_count( title->list_audio );
1838 if (count > 10) count = 10;
1839 used = g_hash_table_lookup(track_indices, &acodec);
1842 used = g_malloc0(count * sizeof(gboolean));
1843 g_hash_table_insert(track_indices, &acodec, used);
1845 // Try to find an item that matches the preferred language and
1846 // the passthru codec type
1847 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1849 for (ii = 0; ii < count; ii++)
1856 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1857 title->list_audio, ii );
1858 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1859 audio->in.channel_layout);
1860 // Find a track that is not visually impaired or dirctor's
1861 // commentary, and has the highest channel count.
1862 if ((audio->in.codec & acodec) &&
1863 (audio->lang.type < 2) &&
1864 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1865 (strcmp(lang, "und") == 0)))
1867 if (channels > max_chan)
1870 max_chan = channels;
1880 // Try to find an item that matches the preferred language
1881 for (ii = 0; ii < count; ii++)
1885 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1886 title->list_audio, ii );
1887 // Find a track that is not visually impaired or dirctor's commentary
1888 if ((audio->lang.type < 2) &&
1889 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1890 (strcmp(lang, "und") == 0)))
1901 // Try to fine an item that does not match the preferred language and
1902 // matches the passthru codec type
1903 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1905 for (ii = 0; ii < count; ii++)
1912 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1913 title->list_audio, ii );
1914 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1915 audio->in.channel_layout);
1916 // Find a track that is not visually impaired or dirctor's
1917 // commentary, and has the highest channel count.
1918 if ((audio->in.codec & acodec) &&
1919 (audio->lang.type < 2))
1921 if (channels > max_chan)
1924 max_chan = channels;
1934 // Try to fine an item that does not match the preferred language
1935 for (ii = 0; ii < count; ii++)
1939 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1940 title->list_audio, ii );
1941 // Find a track that is not visually impaired or dirctor's commentary
1942 if (audio->lang.type < 2)
1953 // Last ditch, anything goes
1954 for (ii = 0; ii < count; ii++)
1956 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1957 title->list_audio, ii );
1972 ghb_add_all_subtitles(signal_user_data_t *ud, gint titleindex)
1976 hb_subtitle_t * subtitle;
1981 g_debug("ghb_add_all_subtitles ()\n");
1984 list = hb_get_titles( h_scan );
1985 title = (hb_title_t*)hb_list_item( list, titleindex );
1989 // Add special auto selection track
1990 subdict = ghb_dict_value_new();
1991 ghb_settings_set_boolean(subdict, "SubtitleEnabled", FALSE);
1992 ghb_settings_set_int(subdict, "SubtitleTrack", -1);
1993 ghb_settings_set_boolean(subdict, "SubtitleForced", FALSE);
1994 ghb_settings_set_boolean(subdict, "SubtitleBurned", FALSE);
1995 ghb_settings_set_string(subdict, "SubtitleLanguage", "auto");
1996 ghb_add_subtitle(ud, subdict, FALSE);
1998 count = hb_list_count( title->list_subtitle );
1999 for (ii = 0; ii < count; ii++)
2001 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2002 subdict = ghb_dict_value_new();
2003 ghb_settings_set_boolean(subdict, "SubtitleEnabled", FALSE);
2004 ghb_settings_set_int(subdict, "SubtitleTrack", ii);
2005 ghb_settings_set_boolean(subdict, "SubtitleForced", FALSE);
2006 ghb_settings_set_boolean(subdict, "SubtitleBurned", FALSE);
2007 ghb_settings_set_string(subdict, "SubtitleLanguage",
2008 subtitle->iso639_2);
2009 ghb_add_subtitle(ud, subdict, FALSE);
2014 ghb_find_pref_subtitle_track(const gchar *lang)
2017 count = subtitle_opts.count;
2018 for (ii = 0; ii < count; ii++)
2020 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2022 return subtitle_opts.map[ii].ivalue;
2029 ghb_find_subtitle_track(
2032 GHashTable *track_indices)
2036 hb_subtitle_t * subtitle;
2040 g_debug("find_subtitle_track ()\n");
2041 if (strcmp(lang, "auto") == 0)
2043 if (h_scan == NULL) return -1;
2044 list = hb_get_titles( h_scan );
2045 title = (hb_title_t*)hb_list_item( list, titleindex );
2048 count = hb_list_count( title->list_subtitle );
2049 used = g_hash_table_lookup(track_indices, lang);
2052 used = g_malloc0(count * sizeof(gboolean));
2053 g_hash_table_insert(track_indices, g_strdup(lang), used);
2055 // Try to find an item that matches the preferred language
2056 for (ii = 0; ii < count; ii++)
2061 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2062 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2063 (strcmp(lang, "und") == 0))
2074 ghb_pick_subtitle_track(signal_user_data_t *ud)
2076 gint ii, count, track, candidate, first;
2077 GValue *settings, *subtitle_list;
2079 first = candidate = ghb_settings_combo_int(ud->settings, "SubtitleTrack");
2080 subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
2081 count = ghb_array_len(subtitle_list);
2082 for (ii = 0; ii < count; ii++)
2084 settings = ghb_array_get_nth(subtitle_list, ii);
2085 track = ghb_settings_combo_int(settings, "SubtitleTrack");
2086 if (candidate == track)
2088 // Already in use, pick another
2090 if (candidate >= subtitle_opts.count-1)
2094 if (candidate == first)
2106 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2109 GtkListStore *store;
2112 g_debug("generic_opts_set ()\n");
2113 if (name == NULL || opts == NULL) return;
2114 store = get_combo_box_store(builder, name);
2115 gtk_list_store_clear(store);
2116 for (ii = 0; ii < opts->count; ii++)
2118 gtk_list_store_append(store, &iter);
2119 gtk_list_store_set(store, &iter,
2120 0, opts->map[ii].option,
2122 2, opts->map[ii].shortOpt,
2123 3, opts->map[ii].ivalue,
2124 4, opts->map[ii].svalue,
2130 find_combo_table(const gchar *name)
2134 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2136 if (strcmp(name, combo_name_map[ii].name) == 0)
2138 return combo_name_map[ii].opts;
2145 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2149 if (strcmp(name, "AudioBitrate") == 0)
2150 return lookup_audio_bitrate_int(gval);
2151 else if (strcmp(name, "AudioSamplerate") == 0)
2152 return lookup_audio_rate_int(gval);
2153 else if (strcmp(name, "VideoFramerate") == 0)
2154 return lookup_video_rate_int(gval);
2155 else if (strcmp(name, "AudioMixdown") == 0)
2156 return lookup_mix_int(gval);
2157 else if (strcmp(name, "SourceAudioLang") == 0)
2158 return lookup_audio_lang_int(gval);
2161 return lookup_generic_int(find_combo_table(name), gval);
2163 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2168 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2172 if (strcmp(name, "AudioBitrate") == 0)
2173 return lookup_audio_bitrate_int(gval);
2174 else if (strcmp(name, "AudioSamplerate") == 0)
2175 return lookup_audio_rate_int(gval);
2176 else if (strcmp(name, "VideoFramerate") == 0)
2177 return lookup_video_rate_int(gval);
2178 else if (strcmp(name, "AudioMixdown") == 0)
2179 return lookup_mix_int(gval);
2180 else if (strcmp(name, "SourceAudioLang") == 0)
2181 return lookup_audio_lang_int(gval);
2184 return lookup_generic_double(find_combo_table(name), gval);
2186 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2191 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2195 if (strcmp(name, "AudioBitrate") == 0)
2196 return lookup_audio_bitrate_option(gval);
2197 else if (strcmp(name, "AudioSamplerate") == 0)
2198 return lookup_audio_rate_option(gval);
2199 else if (strcmp(name, "VideoFramerate") == 0)
2200 return lookup_video_rate_option(gval);
2201 else if (strcmp(name, "AudioMixdown") == 0)
2202 return lookup_mix_option(gval);
2203 else if (strcmp(name, "SourceAudioLang") == 0)
2204 return lookup_audio_lang_option(gval);
2207 return lookup_generic_option(find_combo_table(name), gval);
2209 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2214 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2218 if (strcmp(name, "AudioBitrate") == 0)
2219 return lookup_audio_bitrate_option(gval);
2220 else if (strcmp(name, "AudioSamplerate") == 0)
2221 return lookup_audio_rate_option(gval);
2222 else if (strcmp(name, "VideoFramerate") == 0)
2223 return lookup_video_rate_option(gval);
2224 else if (strcmp(name, "AudioMixdown") == 0)
2225 return lookup_mix_option(gval);
2226 else if (strcmp(name, "SourceAudioLang") == 0)
2227 return lookup_audio_lang_option(gval);
2230 return lookup_generic_string(find_combo_table(name), gval);
2232 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2237 ghb_update_ui_combo_box(
2238 signal_user_data_t *ud,
2243 GtkComboBox *combo = NULL;
2245 gint handler_id = 0;
2249 g_debug("ghb_update_ui_combo_box() %s\n", name);
2250 // Clearing a combo box causes a rash of "changed" events, even when
2251 // the active item is -1 (inactive). To control things, I'm disabling
2252 // the event till things are settled down.
2253 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2254 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2257 // Valid signal id found. This should always succeed.
2258 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2259 signal_id, 0, 0, 0, 0);
2262 // This should also always succeed
2263 g_signal_handler_block ((gpointer)combo, handler_id);
2269 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2270 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2271 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2272 mix_opts_set(ud->builder, "AudioMixdown");
2273 language_opts_set(ud->builder, "SourceAudioLang");
2274 title_opts_set(ud->builder, "title");
2275 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2276 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2277 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2278 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2279 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2280 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2281 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2282 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2283 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2284 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2285 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2286 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2287 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2288 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2289 generic_opts_set(ud->builder, "x264_me", &me_opts);
2290 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2291 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2292 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2296 if (strcmp(name, "AudioBitrate") == 0)
2297 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2298 else if (strcmp(name, "AudioSamplerate") == 0)
2299 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2300 else if (strcmp(name, "VideoFramerate") == 0)
2301 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2302 else if (strcmp(name, "AudioMixdown") == 0)
2303 mix_opts_set(ud->builder, "AudioMixdown");
2304 else if (strcmp(name, "SourceAudioLang") == 0)
2305 language_opts_set(ud->builder, "SourceAudioLang");
2306 else if (strcmp(name, "title") == 0)
2307 title_opts_set(ud->builder, "title");
2308 else if (strcmp(name, "AudioTrack") == 0)
2309 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2311 generic_opts_set(ud->builder, name, find_combo_table(name));
2315 g_signal_handler_unblock ((gpointer)combo, handler_id);
2320 init_ui_combo_boxes(GtkBuilder *builder)
2324 init_combo_box(builder, "AudioBitrate");
2325 init_combo_box(builder, "AudioSamplerate");
2326 init_combo_box(builder, "VideoFramerate");
2327 init_combo_box(builder, "AudioMixdown");
2328 init_combo_box(builder, "SourceAudioLang");
2329 init_combo_box(builder, "title");
2330 init_combo_box(builder, "AudioTrack");
2331 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2333 init_combo_box(builder, combo_name_map[ii].name);
2337 static const char * turbo_opts =
2338 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2339 "no-fast-pskip=0:8x8dct=0:weightb=0";
2341 // Construct the x264 options string
2342 // The result is allocated, so someone must free it at some point.
2344 ghb_build_x264opts_string(GValue *settings)
2347 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2354 result = g_strdup("");
2360 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2364 hb_chapter_t * chapter;
2367 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2368 *hh = *mm = *ss = 0;
2369 if (h_scan == NULL) return;
2370 list = hb_get_titles( h_scan );
2371 title = (hb_title_t*)hb_list_item( list, ti );
2372 if (title == NULL) return;
2373 count = hb_list_count( title->list_chapter );
2374 if (ii >= count) return;
2375 chapter = hb_list_item(title->list_chapter, ii);
2376 if (chapter == NULL) return;
2377 *hh = chapter->hours;
2378 *mm = chapter->minutes;
2379 *ss = chapter->seconds;
2383 ghb_get_chapters(gint titleindex)
2387 hb_chapter_t * chapter;
2389 GValue *chapters = NULL;
2391 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2392 if (h_scan == NULL) return NULL;
2393 list = hb_get_titles( h_scan );
2394 title = (hb_title_t*)hb_list_item( list, titleindex );
2395 if (title == NULL) return NULL;
2396 count = hb_list_count( title->list_chapter );
2397 chapters = ghb_array_value_new(count);
2398 for (ii = 0; ii < count; ii++)
2400 chapter = hb_list_item(title->list_chapter, ii);
2401 if (chapter == NULL) break;
2402 if (chapter->title == NULL || chapter->title[0] == 0)
2405 str = g_strdup_printf ("Chapter %2d", ii+1);
2406 ghb_array_append(chapters, ghb_string_value_new(str));
2411 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2418 ghb_ac3_in_audio_list(const GValue *audio_list)
2422 count = ghb_array_len(audio_list);
2423 for (ii = 0; ii < count; ii++)
2428 asettings = ghb_array_get_nth(audio_list, ii);
2429 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2430 if (acodec == HB_ACODEC_AC3)
2437 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2440 GtkListStore *store;
2443 g_debug("audio_rate_opts_add ()\n");
2444 store = get_combo_box_store(builder, name);
2445 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2447 str = g_strdup_printf ("%d", rate);
2448 gtk_list_store_append(store, &iter);
2449 gtk_list_store_set(store, &iter,
2461 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2464 GtkListStore *store;
2466 gboolean done = FALSE;
2468 guint last = (guint)last_rate;
2470 g_debug("audio_bitrate_opts_clean ()\n");
2471 store = get_combo_box_store(builder, name);
2472 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2476 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2478 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2480 done = !gtk_list_store_remove(store, &iter);
2482 else if (ivalue > last)
2485 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2486 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2491 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2492 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2499 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2502 GtkListStore *store;
2505 g_debug("audio_bitrate_opts_set ()\n");
2506 store = get_combo_box_store(builder, name);
2507 gtk_list_store_clear(store);
2508 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2510 gtk_list_store_append(store, &iter);
2511 gtk_list_store_set(store, &iter,
2512 0, hb_audio_bitrates[ii].string,
2514 2, hb_audio_bitrates[ii].string,
2515 3, (gdouble)hb_audio_bitrates[ii].rate,
2516 4, hb_audio_bitrates[ii].string,
2522 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2524 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2528 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2530 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2533 static ghb_status_t hb_status;
2536 ghb_combo_init(signal_user_data_t *ud)
2538 // Set up the list model for the combos
2539 init_ui_combo_boxes(ud->builder);
2540 // Populate all the combos
2541 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2545 ghb_backend_init(gint debug)
2548 h_scan = hb_init( debug, 0 );
2549 h_queue = hb_init( debug, 0 );
2560 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2562 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2563 hb_status.scan.state |= GHB_STATE_SCANNING;
2564 // initialize count and cur to something that won't cause FPE
2565 // when computing progress
2566 hb_status.scan.title_count = 1;
2567 hb_status.scan.title_cur = 0;
2571 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2573 g_debug("ghb_backend_queue_scan()");
2574 hb_scan( h_queue, path, titlenum, 10, 0 );
2575 hb_status.queue.state |= GHB_STATE_SCANNING;
2579 ghb_get_scan_state()
2581 return hb_status.scan.state;
2585 ghb_get_queue_state()
2587 return hb_status.queue.state;
2591 ghb_clear_scan_state(gint state)
2593 hb_status.scan.state &= ~state;
2597 ghb_clear_queue_state(gint state)
2599 hb_status.queue.state &= ~state;
2603 ghb_set_scan_state(gint state)
2605 hb_status.scan.state |= state;
2609 ghb_set_queue_state(gint state)
2611 hb_status.queue.state |= state;
2615 ghb_get_status(ghb_status_t *status)
2617 memcpy(status, &hb_status, sizeof(ghb_status_t));
2626 if (h_scan == NULL) return;
2627 hb_get_state( h_scan, &s_scan );
2628 switch( s_scan.state )
2630 #define p s_scan.param.scanning
2631 case HB_STATE_SCANNING:
2633 hb_status.scan.state |= GHB_STATE_SCANNING;
2634 hb_status.scan.title_count = p.title_count;
2635 hb_status.scan.title_cur = p.title_cur;
2639 case HB_STATE_SCANDONE:
2641 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2642 hb_status.scan.state |= GHB_STATE_SCANDONE;
2645 #define p s_scan.param.working
2646 case HB_STATE_WORKING:
2647 hb_status.scan.state |= GHB_STATE_WORKING;
2648 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2649 hb_status.scan.job_cur = p.job_cur;
2650 hb_status.scan.job_count = p.job_count;
2651 hb_status.scan.progress = p.progress;
2652 hb_status.scan.rate_cur = p.rate_cur;
2653 hb_status.scan.rate_avg = p.rate_avg;
2654 hb_status.scan.hours = p.hours;
2655 hb_status.scan.minutes = p.minutes;
2656 hb_status.scan.seconds = p.seconds;
2657 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2661 case HB_STATE_PAUSED:
2662 hb_status.scan.state |= GHB_STATE_PAUSED;
2665 case HB_STATE_MUXING:
2667 hb_status.scan.state |= GHB_STATE_MUXING;
2670 #define p s_scan.param.workdone
2671 case HB_STATE_WORKDONE:
2675 hb_status.scan.state |= GHB_STATE_WORKDONE;
2676 hb_status.scan.state &= ~GHB_STATE_MUXING;
2677 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2678 hb_status.scan.state &= ~GHB_STATE_WORKING;
2682 hb_status.scan.error = GHB_ERROR_NONE;
2684 case HB_ERROR_CANCELED:
2685 hb_status.scan.error = GHB_ERROR_CANCELED;
2688 hb_status.scan.error = GHB_ERROR_FAIL;
2691 // Delete all remaining jobs of this encode.
2692 // An encode can be composed of multiple associated jobs.
2693 // When a job is stopped, libhb removes it from the job list,
2694 // but does not remove other jobs that may be associated with it.
2695 // Associated jobs are taged in the sequence id.
2696 while ((job = hb_job(h_scan, 0)) != NULL)
2697 hb_rem( h_scan, job );
2701 hb_get_state( h_queue, &s_queue );
2702 switch( s_queue.state )
2704 #define p s_queue.param.scanning
2705 case HB_STATE_SCANNING:
2707 hb_status.queue.state |= GHB_STATE_SCANNING;
2708 hb_status.queue.title_count = p.title_count;
2709 hb_status.queue.title_cur = p.title_cur;
2713 case HB_STATE_SCANDONE:
2715 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2716 hb_status.queue.state |= GHB_STATE_SCANDONE;
2719 #define p s_queue.param.working
2720 case HB_STATE_WORKING:
2721 hb_status.queue.state |= GHB_STATE_WORKING;
2722 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2723 hb_status.queue.job_cur = p.job_cur;
2724 hb_status.queue.job_count = p.job_count;
2725 hb_status.queue.progress = p.progress;
2726 hb_status.queue.rate_cur = p.rate_cur;
2727 hb_status.queue.rate_avg = p.rate_avg;
2728 hb_status.queue.hours = p.hours;
2729 hb_status.queue.minutes = p.minutes;
2730 hb_status.queue.seconds = p.seconds;
2731 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2735 case HB_STATE_PAUSED:
2736 hb_status.queue.state |= GHB_STATE_PAUSED;
2739 case HB_STATE_MUXING:
2741 hb_status.queue.state |= GHB_STATE_MUXING;
2744 #define p s_queue.param.workdone
2745 case HB_STATE_WORKDONE:
2749 hb_status.queue.state |= GHB_STATE_WORKDONE;
2750 hb_status.queue.state &= ~GHB_STATE_MUXING;
2751 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2752 hb_status.queue.state &= ~GHB_STATE_WORKING;
2756 hb_status.queue.error = GHB_ERROR_NONE;
2758 case HB_ERROR_CANCELED:
2759 hb_status.queue.error = GHB_ERROR_CANCELED;
2762 hb_status.queue.error = GHB_ERROR_FAIL;
2765 // Delete all remaining jobs of this encode.
2766 // An encode can be composed of multiple associated jobs.
2767 // When a job is stopped, libhb removes it from the job list,
2768 // but does not remove other jobs that may be associated with it.
2769 // Associated jobs are taged in the sequence id.
2770 while ((job = hb_job(h_queue, 0)) != NULL)
2771 hb_rem( h_queue, job );
2778 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2783 if (h_scan == NULL) return FALSE;
2784 list = hb_get_titles( h_scan );
2785 if( !hb_list_count( list ) )
2787 /* No valid title, stop right there */
2791 title = hb_list_item( list, titleindex );
2792 if (title == NULL) return FALSE; // Bad titleindex
2793 tinfo->width = title->width;
2794 tinfo->height = title->height;
2795 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2796 // Don't allow crop to 0
2797 if (title->crop[0] + title->crop[1] >= title->height)
2798 title->crop[0] = title->crop[1] = 0;
2799 if (title->crop[2] + title->crop[3] >= title->width)
2800 title->crop[2] = title->crop[3] = 0;
2801 tinfo->num_chapters = hb_list_count(title->list_chapter);
2802 tinfo->rate_base = title->rate_base;
2803 tinfo->rate = title->rate;
2804 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2805 title->width * title->pixel_aspect_width,
2806 title->height * title->pixel_aspect_height);
2807 tinfo->hours = title->hours;
2808 tinfo->minutes = title->minutes;
2809 tinfo->seconds = title->seconds;
2810 tinfo->duration = title->duration;
2812 tinfo->angle_count = title->angle_count;
2817 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2819 hb_audio_config_t *audio;
2821 audio = get_hb_audio(titleindex, audioindex);
2822 if (audio == NULL) return FALSE; // Bad audioindex
2823 ainfo->codec = audio->in.codec;
2824 ainfo->bitrate = audio->in.bitrate;
2825 ainfo->samplerate = audio->in.samplerate;
2830 ghb_audio_is_passthru(gint acodec)
2832 g_debug("ghb_audio_is_passthru () \n");
2833 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2837 ghb_get_default_acodec()
2839 return HB_ACODEC_FAAC;
2843 picture_settings_deps(signal_user_data_t *ud)
2845 gboolean autoscale, keep_aspect, enable_keep_aspect;
2846 gboolean enable_scale_width, enable_scale_height;
2847 gboolean enable_disp_width, enable_disp_height;
2851 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2854 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2855 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2856 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2858 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2859 if (!enable_keep_aspect)
2861 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2863 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2864 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2866 enable_scale_width = !autoscale && (pic_par != 1);
2867 enable_scale_height = !autoscale && (pic_par != 1);
2868 enable_disp_width = (pic_par == 3) && !keep_aspect;
2869 enable_disp_height = FALSE;
2871 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2872 gtk_widget_set_sensitive(widget, pic_par != 1);
2873 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2874 gtk_widget_set_sensitive(widget, pic_par != 1);
2875 widget = GHB_WIDGET(ud->builder, "scale_width");
2876 gtk_widget_set_sensitive(widget, enable_scale_width);
2877 widget = GHB_WIDGET(ud->builder, "scale_height");
2878 gtk_widget_set_sensitive(widget, enable_scale_height);
2879 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2880 gtk_widget_set_sensitive(widget, enable_disp_width);
2881 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2882 gtk_widget_set_sensitive(widget, enable_disp_height);
2883 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2884 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2885 widget = GHB_WIDGET(ud->builder, "autoscale");
2886 gtk_widget_set_sensitive(widget, pic_par != 1);
2890 ghb_set_scale(signal_user_data_t *ud, gint mode)
2895 gboolean keep_aspect;
2897 gboolean autocrop, autoscale, noscale;
2898 gint crop[4], width, height, par_width, par_height;
2899 gint crop_width, crop_height;
2900 gint aspect_n, aspect_d;
2901 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2902 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2907 gint max_height = 0;
2908 static gboolean busy = FALSE;
2910 g_debug("ghb_set_scale ()\n");
2911 if (h_scan == NULL) return;
2912 list = hb_get_titles( h_scan );
2913 if( !hb_list_count( list ) )
2915 /* No valid title, stop right there */
2920 titleindex = ghb_settings_combo_int(ud->settings, "title");
2921 title = hb_list_item( list, titleindex );
2922 if (title == NULL) return;
2924 if (job == NULL) return;
2926 picture_settings_deps(ud);
2931 // First configure widgets
2932 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2933 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2934 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2935 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2936 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2937 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2938 // alignment constraints rather than scaling to satisfy them.
2939 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2940 // Align dimensions to either 16 or 2 pixels
2941 // The scaler crashes if the dimensions are not divisible by 2
2942 // x264 also will not accept dims that are not multiple of 2
2946 keep_height = FALSE;
2948 // Step needs to be at least 2 because odd widths cause scaler crash
2950 widget = GHB_WIDGET (ud->builder, "scale_width");
2951 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2952 widget = GHB_WIDGET (ud->builder, "scale_height");
2953 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2956 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2957 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2958 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2959 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2960 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2961 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2962 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2963 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2967 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2968 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2969 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2970 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2971 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2972 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2973 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2974 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2976 ghb_title_info_t tinfo;
2977 ghb_get_title_info (&tinfo, titleindex);
2980 crop[0] = tinfo.crop[0];
2981 crop[1] = tinfo.crop[1];
2982 crop[2] = tinfo.crop[2];
2983 crop[3] = tinfo.crop[3];
2984 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2985 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2986 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2987 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2991 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2992 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2993 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2994 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3000 // Adjust the cropping to accomplish the desired width and height
3001 crop_width = tinfo.width - crop[2] - crop[3];
3002 crop_height = tinfo.height - crop[0] - crop[1];
3003 width = MOD_DOWN(crop_width, mod);
3004 height = MOD_DOWN(crop_height, mod);
3006 need1 = (crop_height - height) / 2;
3007 need2 = crop_height - height - need1;
3010 need1 = (crop_width - width) / 2;
3011 need2 = crop_width - width - need1;
3014 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3015 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3016 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3017 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3019 hb_reduce(&aspect_n, &aspect_d,
3020 title->width * title->pixel_aspect_width,
3021 title->height * title->pixel_aspect_height);
3022 crop_width = title->width - crop[2] - crop[3];
3023 crop_height = title->height - crop[0] - crop[1];
3027 height = crop_height;
3031 width = ghb_settings_get_int(ud->settings, "scale_width");
3032 height = ghb_settings_get_int(ud->settings, "scale_height");
3033 max_width = MOD_DOWN(
3034 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3035 max_height = MOD_DOWN(
3036 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3038 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3041 width = title->width - crop[2] - crop[3];
3043 height = title->height - crop[0] - crop[1];
3045 width = MOD_ROUND(width, mod);
3046 height = MOD_ROUND(height, mod);
3048 // Adjust dims according to max values
3050 height = MIN(height, max_height);
3052 width = MIN(width, max_width);
3056 job->anamorphic.mode = pic_par;
3057 // The scaler crashes if the dimensions are not divisible by 2
3058 // Align mod 2. And so does something in x264_encoder_headers()
3059 job->anamorphic.modulus = mod;
3060 if (keep_height && pic_par == 2)
3061 width = ((double)height * crop_width / crop_height) + 0.5;
3063 job->height = height;
3065 job->maxWidth = max_width;
3067 job->maxHeight = max_height;
3068 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3069 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3070 if (job->anamorphic.mode == 3 && !keep_aspect)
3072 gint dar_width, dar_height;
3073 if (mode & GHB_PIC_KEEP_PAR)
3075 par_width = ghb_settings_get_int(ud->settings,
3077 par_height = ghb_settings_get_int(ud->settings,
3078 "PicturePARHeight");
3079 dar_width = ((gdouble)width * par_width / par_height) + 0.5;
3080 dar_height = height;
3084 dar_width = ghb_settings_get_int(ud->settings,
3085 "PictureDisplayWidth");
3086 dar_height = ghb_settings_get_int(ud->settings,
3087 "PictureDisplayHeight");
3089 job->anamorphic.dar_width = dar_width;
3090 job->anamorphic.dar_height = dar_height;
3094 job->anamorphic.dar_width = 0;
3095 job->anamorphic.dar_height = 0;
3097 hb_set_anamorphic_size( job, &width, &height,
3098 &par_width, &par_height );
3102 job->anamorphic.mode = pic_par;
3106 gint new_width, new_height;
3108 // Compute pixel aspect ration.
3109 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3110 // Must scale so that par becomes 1:1
3111 // Try to keep largest dimension
3112 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3113 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3115 if (max_width && new_width > max_width)
3117 height = new_height;
3119 else if (max_height && new_height > max_height)
3123 else if (keep_width)
3125 height = new_height;
3127 else if (keep_height)
3131 else if (width > new_width)
3133 height = new_height;
3139 g_debug("new w %d h %d\n", width, height);
3141 width = MOD_ROUND(width, mod);
3142 height = MOD_ROUND(height, mod);
3144 height = MIN(height, max_height);
3146 width = MIN(width, max_width);
3147 par_width = par_height = 1;
3149 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3150 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3152 gint disp_width, dar_width, dar_height;
3155 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3156 hb_reduce(&dar_width, &dar_height, disp_width, height);
3158 gint iaspect = dar_width * 9 / dar_height;
3159 if (dar_width > 2 * dar_height)
3161 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3163 else if (iaspect <= 16 && iaspect >= 15)
3165 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3167 else if (iaspect <= 12 && iaspect >= 11)
3169 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3173 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3175 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3177 ghb_ui_update(ud, "par_width", ghb_int64_value(par_width));
3178 ghb_ui_update(ud, "par_height", ghb_int64_value(par_height));
3179 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3180 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3185 set_preview_job_settings(hb_job_t *job, GValue *settings)
3187 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3188 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3189 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3190 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3192 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3193 job->anamorphic.modulus =
3194 ghb_settings_combo_int(settings, "PictureModulus");
3195 job->width = ghb_settings_get_int(settings, "scale_width");
3196 job->height = ghb_settings_get_int(settings, "scale_height");
3197 if (ghb_settings_get_boolean(settings, "show_crop"))
3203 job->width = job->title->width;
3204 job->height = job->title->height;
3205 job->anamorphic.modulus = 2;
3208 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3209 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3210 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3212 gboolean keep_aspect;
3213 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3214 if (job->anamorphic.mode == 3 && !keep_aspect)
3216 gint disp_width, disp_height;
3217 disp_width = ghb_settings_get_int(settings, "PictureDisplayWidth");
3218 disp_height = ghb_settings_get_int(settings, "PictureDisplayHeight");
3219 job->anamorphic.dar_width = disp_width;
3220 job->anamorphic.dar_height = disp_height;
3224 job->anamorphic.dar_width = 0;
3225 job->anamorphic.dar_height = 0;
3230 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3237 if (h_scan == NULL) return 1500;
3238 list = hb_get_titles( h_scan );
3239 title = hb_list_item( list, titleindex );
3240 if (title == NULL) return 1500;
3242 if (job == NULL) return 1500;
3243 size = ghb_settings_get_int(settings, "VideoTargetSize");
3244 return hb_calc_bitrate( job, size );
3248 ghb_validate_filter_string(const gchar *str, gint max_fields)
3254 if (str == NULL || *str == 0) return TRUE;
3257 val = g_strtod(str, &end);
3259 { // Found a numeric value
3261 // negative max_fields means infinate
3262 if (max_fields >= 0 && fields > max_fields) return FALSE;
3276 ghb_validate_filters(signal_user_data_t *ud)
3283 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3286 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3287 if (!ghb_validate_filter_string(str, 4))
3289 message = g_strdup_printf(
3290 "Invalid Deinterlace Settings:\n\n%s\n",
3292 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3300 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3303 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3304 if (!ghb_validate_filter_string(str, 6))
3306 message = g_strdup_printf(
3307 "Invalid Detelecine Settings:\n\n%s\n",
3309 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3317 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3320 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3321 if (!ghb_validate_filter_string(str, 7))
3323 message = g_strdup_printf(
3324 "Invalid Decomb Settings:\n\n%s\n",
3326 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3334 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3337 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3338 if (!ghb_validate_filter_string(str, 4))
3340 message = g_strdup_printf(
3341 "Invalid Denoise Settings:\n\n%s\n",
3343 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3354 ghb_validate_video(signal_user_data_t *ud)
3359 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3360 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3361 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3362 (vcodec == HB_VCODEC_THEORA))
3364 // mp4|avi/theora combination is not supported.
3365 message = g_strdup_printf(
3366 "Theora is not supported in the MP4 and AVI containers.\n\n"
3367 "You should choose a different video codec or container.\n"
3368 "If you continue, FFMPEG will be chosen for you.");
3369 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3375 vcodec = HB_VCODEC_FFMPEG;
3376 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3382 ghb_validate_subtitles(signal_user_data_t *ud)
3388 if (h_scan == NULL) return FALSE;
3389 list = hb_get_titles( h_scan );
3390 if( !hb_list_count( list ) )
3392 /* No valid title, stop right there */
3393 g_message("No title found.\n");
3399 titleindex = ghb_settings_combo_int(ud->settings, "title");
3400 title = hb_list_item( list, titleindex );
3401 if (title == NULL) return FALSE;
3402 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3404 const GValue *slist, *settings;
3405 gint count, ii, track, source;
3406 gboolean burned, enabled;
3408 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3409 count = ghb_array_len(slist);
3410 for (ii = 0; ii < count; ii++)
3412 settings = ghb_array_get_nth(slist, ii);
3413 track = ghb_settings_combo_int(settings, "SubtitleTrack");
3414 enabled = ghb_settings_get_boolean(settings, "SubtitleEnabled");
3415 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3416 source = ghb_subtitle_track_source(ud, track);
3417 if (enabled && !burned && mux == HB_MUX_MP4 && source == VOBSUB)
3419 // MP4 can only handle burned vobsubs. make sure there isn't
3420 // already something burned in the list
3421 message = g_strdup_printf(
3422 "Your chosen container does not support soft bitmap subtitles.\n\n"
3423 "You should change your subtitle selections.\n"
3424 "If you continue, some subtitles will be lost.");
3425 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3438 ghb_validate_audio(signal_user_data_t *ud)
3445 if (h_scan == NULL) return FALSE;
3446 list = hb_get_titles( h_scan );
3447 if( !hb_list_count( list ) )
3449 /* No valid title, stop right there */
3450 g_message("No title found.\n");
3456 titleindex = ghb_settings_combo_int(ud->settings, "title");
3457 title = hb_list_item( list, titleindex );
3458 if (title == NULL) return FALSE;
3459 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3461 const GValue *audio_list;
3464 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3465 count = ghb_array_len(audio_list);
3466 for (ii = 0; ii < count; ii++)
3469 hb_audio_config_t *taudio;
3471 asettings = ghb_array_get_nth(audio_list, ii);
3472 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3473 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3474 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3475 title->list_audio, track );
3476 if (!(taudio->in.codec & codec) &&
3477 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3479 // Not supported. AC3 is passthrough only, so input must be AC3
3480 message = g_strdup_printf(
3481 "The source does not support Pass-Thru.\n\n"
3482 "You should choose a different audio codec.\n"
3483 "If you continue, one will be chosen for you.");
3484 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3490 if (mux == HB_MUX_AVI)
3492 codec = HB_ACODEC_LAME;
3496 codec = HB_ACODEC_FAAC;
3498 value = get_acodec_value(codec);
3499 ghb_settings_take_value(asettings, "AudioEncoder", value);
3501 gchar *a_unsup = NULL;
3502 gchar *mux_s = NULL;
3503 if (mux == HB_MUX_MP4)
3506 // mp4/mp3|vorbis combination is not supported.
3507 if (codec == HB_ACODEC_LAME)
3510 codec = HB_ACODEC_FAAC;
3512 if (codec == HB_ACODEC_VORBIS)
3515 codec = HB_ACODEC_FAAC;
3517 if (codec == HB_ACODEC_DCA)
3520 codec = HB_ACODEC_FAAC;
3523 else if (mux == HB_MUX_AVI)
3526 // avi/faac|vorbis combination is not supported.
3527 if (codec == HB_ACODEC_FAAC)
3530 codec = HB_ACODEC_LAME;
3532 if (codec == HB_ACODEC_VORBIS)
3535 codec = HB_ACODEC_LAME;
3538 else if (mux == HB_MUX_OGM)
3541 // avi/faac|vorbis combination is not supported.
3542 if (codec == HB_ACODEC_FAAC)
3545 codec = HB_ACODEC_VORBIS;
3547 if (codec == HB_ACODEC_AC3)
3550 codec = HB_ACODEC_VORBIS;
3552 if (codec == HB_ACODEC_DCA)
3555 codec = HB_ACODEC_VORBIS;
3560 message = g_strdup_printf(
3561 "%s is not supported in the %s container.\n\n"
3562 "You should choose a different audio codec.\n"
3563 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3564 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3570 value = get_acodec_value(codec);
3571 ghb_settings_take_value(asettings, "AudioEncoder", value);
3573 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3574 gboolean allow_mono = TRUE;
3575 gboolean allow_stereo = TRUE;
3576 gboolean allow_dolby = TRUE;
3577 gboolean allow_dpl2 = TRUE;
3578 gboolean allow_6ch = TRUE;
3580 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3581 (codec != HB_ACODEC_LAME);
3582 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3584 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3586 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3587 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3588 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3589 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3591 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3592 (codec != HB_ACODEC_LAME) &&
3593 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3594 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3596 gchar *mix_unsup = NULL;
3597 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3601 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3603 mix_unsup = "stereo";
3605 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3607 mix_unsup = "Dolby";
3609 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3611 mix_unsup = "Dolby Pro Logic II";
3613 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3615 mix_unsup = "6 Channel";
3619 message = g_strdup_printf(
3620 "The source audio does not support %s mixdown.\n\n"
3621 "You should choose a different mixdown.\n"
3622 "If you continue, one will be chosen for you.", mix_unsup);
3623 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3629 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3630 value = get_amix_value(mix);
3631 ghb_settings_take_value(asettings, "AudioMixdown", value);
3638 ghb_validate_vquality(GValue *settings)
3644 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3645 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3647 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3648 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3652 case HB_VCODEC_X264:
3658 case HB_VCODEC_FFMPEG:
3664 case HB_VCODEC_THEORA:
3676 if (vquality < min || vquality > max)
3678 message = g_strdup_printf(
3679 "Interesting video quality choise: %d\n\n"
3680 "Typical values range from %d to %d.\n"
3681 "Are you sure you wish to use this setting?",
3682 (gint)vquality, min, max);
3683 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3684 "Cancel", "Continue"))
3696 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3701 static gchar *x264opts;
3703 gboolean tweaks = FALSE;
3704 gchar *detel_str = NULL;
3705 gchar *decomb_str = NULL;
3706 gchar *deint_str = NULL;
3707 gchar *deblock_str = NULL;
3708 gchar *denoise_str = NULL;
3709 gchar *dest_str = NULL;
3711 g_debug("add_job()\n");
3712 if (h == NULL) return;
3713 list = hb_get_titles( h );
3714 if( !hb_list_count( list ) )
3716 /* No valid title, stop right there */
3720 title = hb_list_item( list, titleindex );
3721 if (title == NULL) return;
3723 /* Set job settings */
3725 if (job == NULL) return;
3727 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3728 if (job->start_at_preview)
3730 job->seek_points = ghb_settings_get_int(js, "preview_count");
3731 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3734 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3735 job->mux = ghb_settings_combo_int(js, "FileFormat");
3736 if (job->mux == HB_MUX_MP4)
3738 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3739 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3743 job->largeFileSize = FALSE;
3744 job->mp4_optimize = FALSE;
3746 if (!job->start_at_preview)
3748 gint chapter_start, chapter_end;
3749 chapter_start = ghb_settings_get_int(js, "start_chapter");
3750 chapter_end = ghb_settings_get_int(js, "end_chapter");
3751 gint num_chapters = hb_list_count(title->list_chapter);
3752 job->chapter_start = MIN( num_chapters, chapter_start );
3753 job->chapter_end = MAX( job->chapter_start, chapter_end );
3755 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3756 if (job->chapter_start == job->chapter_end)
3757 job->chapter_markers = 0;
3758 if ( job->chapter_markers )
3765 chapters = ghb_settings_get_value(js, "chapter_list");
3766 count = ghb_array_len(chapters);
3767 for(chap = chapter_start; chap <= chapter_end; chap++)
3769 hb_chapter_t * chapter_s;
3775 chapter = ghb_array_get_nth(chapters, chap-1);
3776 name = ghb_value_string(chapter);
3780 name = g_strdup_printf ("Chapter %2d", chap);
3782 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3783 strncpy(chapter_s->title, name, 1023);
3784 chapter_s->title[1023] = '\0';
3789 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3790 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3791 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3792 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3795 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3796 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3798 job->deinterlace = (deint != 0) ? 1 : 0;
3800 job->deinterlace = 0;
3801 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3803 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3804 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3806 /* Add selected filters */
3807 job->filters = hb_list_init();
3808 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3813 if (detel_opts.map[detel].svalue != NULL)
3814 detel_str = g_strdup(detel_opts.map[detel].svalue);
3817 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3818 hb_filter_detelecine.settings = detel_str;
3819 hb_list_add( job->filters, &hb_filter_detelecine );
3825 if (decomb_opts.map[decomb].svalue != NULL)
3826 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3829 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3830 hb_filter_decomb.settings = decomb_str;
3831 hb_list_add( job->filters, &hb_filter_decomb );
3833 if( job->deinterlace )
3837 if (deint_opts.map[deint].svalue != NULL)
3838 deint_str = g_strdup(deint_opts.map[deint].svalue);
3841 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3842 hb_filter_deinterlace.settings = deint_str;
3843 hb_list_add( job->filters, &hb_filter_deinterlace );
3845 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3848 deblock_str = g_strdup_printf("%d", deblock);
3849 hb_filter_deblock.settings = deblock_str;
3850 hb_list_add( job->filters, &hb_filter_deblock );
3852 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3857 if (denoise_opts.map[denoise].svalue != NULL)
3858 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3861 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3862 hb_filter_denoise.settings = denoise_str;
3863 hb_list_add( job->filters, &hb_filter_denoise );
3865 job->width = ghb_settings_get_int(js, "scale_width");
3866 job->height = ghb_settings_get_int(js, "scale_height");
3868 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3869 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3870 (job->vcodec == HB_VCODEC_THEORA))
3872 // mp4|avi/theora combination is not supported.
3873 job->vcodec = HB_VCODEC_FFMPEG;
3875 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3877 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3879 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3882 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3883 job->vquality = vquality;
3886 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3888 job->vquality = -1.0;
3889 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3892 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3895 job->vrate = title->rate;
3896 job->vrate_base = title->rate_base;
3901 job->vrate = 27000000;
3902 job->vrate_base = vrate;
3906 // AVI container does not support variable frame rate.
3907 // OGM supports variable frame rate, but bases all timing on
3908 // DTS, which breaks when b-frames are used since it is
3909 // impossible to reconstruct PTS from DTS when the framerate
3911 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3916 // First remove any audios that are already in the list
3917 // This happens if you are encoding the same title a second time.
3918 gint num_audio_tracks = hb_list_count(job->list_audio);
3920 for(ii = 0; ii < num_audio_tracks; ii++)
3922 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3923 hb_list_rem(job->list_audio, audio);
3926 const GValue *audio_list;
3930 audio_list = ghb_settings_get_value(js, "audio_list");
3931 count = ghb_array_len(audio_list);
3932 for (ii = 0; ii < count; ii++)
3935 hb_audio_config_t audio;
3936 hb_audio_config_t *taudio;
3938 hb_audio_config_init(&audio);
3939 asettings = ghb_array_get_nth(audio_list, ii);
3940 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3941 audio.out.track = tcount;
3942 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3943 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3944 title->list_audio, audio.in.track );
3945 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3947 if (!(taudio->in.codec & audio.out.codec))
3949 // Not supported. AC3 is passthrough only, so input must be AC3
3950 if (job->mux == HB_MUX_AVI)
3952 audio.out.codec = HB_ACODEC_LAME;
3956 audio.out.codec = HB_ACODEC_FAAC;
3961 audio.out.codec &= taudio->in.codec;
3964 if ((job->mux == HB_MUX_MP4) &&
3965 ((audio.out.codec == HB_ACODEC_LAME) ||
3966 (audio.out.codec == HB_ACODEC_VORBIS)))
3968 // mp4/mp3|vorbis combination is not supported.
3969 audio.out.codec = HB_ACODEC_FAAC;
3971 if ((job->mux == HB_MUX_AVI) &&
3972 ((audio.out.codec == HB_ACODEC_FAAC) ||
3973 (audio.out.codec == HB_ACODEC_VORBIS)))
3975 // avi/faac|vorbis combination is not supported.
3976 audio.out.codec = HB_ACODEC_LAME;
3978 if ((job->mux == HB_MUX_OGM) &&
3979 ((audio.out.codec == HB_ACODEC_FAAC) ||
3980 (audio.out.codec == HB_ACODEC_AC3) ||
3981 (audio.out.codec == HB_ACODEC_DCA)))
3983 // ogm/faac|ac3 combination is not supported.
3984 audio.out.codec = HB_ACODEC_VORBIS;
3986 audio.out.dynamic_range_compression =
3987 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
3988 // It would be better if this were done in libhb for us, but its not yet.
3989 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3991 audio.out.mixdown = 0;
3995 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
3996 // Make sure the mixdown is valid and pick a new one if not.
3997 audio.out.mixdown = ghb_get_best_mix(titleindex,
3998 audio.in.track, audio.out.codec, audio.out.mixdown);
4000 ghb_settings_combo_int(asettings, "AudioBitrate");
4001 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4002 if (srate == 0) // 0 is same as source
4003 audio.out.samplerate = taudio->in.samplerate;
4005 audio.out.samplerate = srate;
4008 // Add it to the jobs audio list
4009 hb_audio_add( job, &audio );
4012 // I was tempted to move this up with the reset of the video quality
4013 // settings, but I suspect the settings above need to be made
4014 // first in order for hb_calc_bitrate to be accurate.
4015 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4019 size = ghb_settings_get_int(js, "VideoTargetSize");
4020 job->vbitrate = hb_calc_bitrate( job, size );
4021 job->vquality = -1.0;
4024 dest_str = ghb_settings_get_string(js, "destination");
4025 job->file = dest_str;
4026 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
4027 // TODO: libhb holds onto a reference to the x264opts and is not
4028 // finished with it until encoding the job is done. But I can't
4029 // find a way to get at the job before it is removed in order to
4030 // free up the memory I am allocating here.
4031 // The short story is THIS LEAKS.
4032 x264opts = ghb_build_x264opts_string(js);
4034 if( x264opts != NULL && *x264opts != '\0' )
4036 job->x264opts = x264opts;
4038 else /*avoids a bus error crash when options aren't specified*/
4040 job->x264opts = NULL;
4043 const GValue *subtitle_list;
4046 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4047 count = ghb_array_len(subtitle_list);
4048 for (ii = 0; ii < count; ii++)
4051 gboolean burned, enabled, one_burned = FALSE;
4053 ssettings = ghb_array_get_nth(subtitle_list, ii);
4055 enabled = ghb_settings_get_boolean(ssettings, "SubtitleEnabled");
4060 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4061 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4065 job->indepth_scan = 1;
4067 else if (subtitle >= 0)
4069 hb_subtitle_t * subt;
4071 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4074 if (!burned && job->mux == HB_MUX_MKV &&
4075 subt->format == PICTURESUB)
4077 subt->dest = PASSTHRUSUB;
4079 else if (!burned && job->mux == HB_MUX_MP4 &&
4080 subt->format == PICTURESUB)
4082 // Skip any non-burned vobsubs when output is mp4
4085 else if (subt->format == PICTURESUB)
4087 // Only allow one subtitle to be burned into the video
4092 subt->force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4093 hb_list_add(job->list_subtitle, subt);
4098 if (job->indepth_scan == 1)
4100 // Subtitle scan. Look for subtitle matching audio language
4104 * When subtitle scan is enabled do a fast pre-scan job
4105 * which will determine which subtitles to enable, if any.
4108 job->indepth_scan = 1;
4110 x264opts_tmp = job->x264opts;
4111 job->x264opts = NULL;
4113 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
4114 *(job->select_subtitle) = NULL;
4117 * Add the pre-scan job
4119 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4121 //if (job->x264opts != NULL)
4122 // g_free(job->x264opts);
4124 job->x264opts = x264opts_tmp;
4128 job->select_subtitle = NULL;
4130 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4131 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4134 * If subtitle_scan is enabled then only turn it on
4135 * for the second pass and then off again for the
4138 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
4139 job->select_subtitle = NULL;
4141 job->indepth_scan = 0;
4142 gchar *x264opts2 = NULL;
4145 x264opts2 = g_strdup(x264opts);
4148 * If turbo options have been selected then append them
4149 * to the x264opts now (size includes one ':' and the '\0')
4151 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4157 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
4163 * No x264opts to modify, but apply the turbo options
4164 * anyway as they may be modifying defaults
4166 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
4168 x264opts = tmp_x264opts;
4170 job->x264opts = x264opts;
4172 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4174 //if (job->x264opts != NULL)
4175 // g_free(job->x264opts);
4177 job->select_subtitle = subtitle_tmp;
4180 * On the second pass we turn off subtitle scan so that we
4181 * can actually encode using any subtitles that were auto
4182 * selected in the first pass (using the whacky select-subtitle
4183 * attribute of the job).
4185 job->indepth_scan = 0;
4186 job->x264opts = x264opts2;
4187 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4189 //if (job->x264opts != NULL)
4190 // g_free(job->x264opts);
4194 job->indepth_scan = 0;
4196 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4198 //if (job->x264opts != NULL)
4199 // g_free(job->x264opts);
4201 if (detel_str) g_free(detel_str);
4202 if (decomb_str) g_free(decomb_str);
4203 if (deint_str) g_free(deint_str);
4204 if (deblock_str) g_free(deblock_str);
4205 if (denoise_str) g_free(denoise_str);
4206 if (dest_str) g_free(dest_str);
4210 ghb_add_job(GValue *js, gint unique_id)
4212 // Since I'm doing a scan of the single title I want just prior
4213 // to adding the job, there is only the one title to choose from.
4214 add_job(h_queue, js, unique_id, 0);
4218 ghb_add_live_job(GValue *js, gint unique_id)
4220 // Since I'm doing a scan of the single title I want just prior
4221 // to adding the job, there is only the one title to choose from.
4222 gint titleindex = ghb_settings_combo_int(js, "title");
4223 add_job(h_scan, js, unique_id, titleindex);
4227 ghb_remove_job(gint unique_id)
4232 // Multiples passes all get the same id
4234 // Go backwards through list, so reordering doesn't screw me.
4235 ii = hb_count(h_queue) - 1;
4236 while ((job = hb_job(h_queue, ii--)) != NULL)
4238 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4239 hb_rem(h_queue, job);
4246 hb_start( h_queue );
4256 ghb_start_live_encode()
4262 ghb_stop_live_encode()
4271 hb_get_state2( h_queue, &s );
4273 if( s.state == HB_STATE_PAUSED )
4275 hb_resume( h_queue );
4279 hb_pause( h_queue );
4294 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4297 gint channels = gdk_pixbuf_get_n_channels (pb);
4298 gint stride = gdk_pixbuf_get_rowstride (pb);
4300 for (jj = 0; jj < width; jj++)
4302 dst = pixels + y * stride + (x+jj) * channels;
4303 for (ii = 0; ii < len; ii++)
4324 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4327 gint channels = gdk_pixbuf_get_n_channels (pb);
4328 gint stride = gdk_pixbuf_get_rowstride (pb);
4330 for (jj = 0; jj < width; jj++)
4332 dst = pixels + (y+jj) * stride + x * channels;
4333 for (ii = 0; ii < len; ii++)
4354 gint line_width = 8;
4361 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4366 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4368 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4374 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4376 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4382 ghb_get_preview_image(
4385 signal_user_data_t *ud,
4393 settings = ud->settings;
4394 list = hb_get_titles( h_scan );
4395 if( !hb_list_count( list ) )
4397 /* No valid title, stop right there */
4400 title = hb_list_item( list, titleindex );
4401 if (title == NULL) return NULL;
4402 if (title->job == NULL) return NULL;
4403 set_preview_job_settings(title->job, settings);
4405 // hb_get_preview doesn't compensate for anamorphic, so lets
4406 // calculate scale factors
4407 gint width, height, par_width = 1, par_height = 1;
4408 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4411 hb_set_anamorphic_size( title->job, &width, &height,
4412 &par_width, &par_height );
4415 // Make sure we have a big enough buffer to receive the image from libhb
4416 gint dstWidth = title->job->width;
4417 gint dstHeight= title->job->height;
4419 static guint8 *buffer = NULL;
4420 static gint bufferSize = 0;
4423 newSize = dstWidth * dstHeight * 4;
4424 if( bufferSize < newSize )
4426 bufferSize = newSize;
4427 buffer = (guint8*) g_realloc( buffer, bufferSize );
4429 hb_get_preview( h_scan, title, index, buffer );
4431 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4432 // libhb's format something suitable.
4434 // The image data returned by hb_get_preview is 4 bytes per pixel,
4435 // BGRA format. Alpha is ignored.
4437 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4438 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4440 guint32 *src = (guint32*)buffer;
4441 guint8 *dst = pixels;
4444 gint channels = gdk_pixbuf_get_n_channels (preview);
4445 gint stride = gdk_pixbuf_get_rowstride (preview);
4448 for (ii = 0; ii < dstHeight; ii++)
4451 for (jj = 0; jj < dstWidth; jj++)
4453 tmp[0] = src[0] >> 16;
4454 tmp[1] = src[0] >> 8;
4455 tmp[2] = src[0] >> 0;
4461 gint w = ghb_settings_get_int(settings, "scale_width");
4462 gint h = ghb_settings_get_int(settings, "scale_height");
4463 ghb_par_scale(ud, &w, &h, par_width, par_height);
4465 gint c0, c1, c2, c3;
4466 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4467 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4468 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4469 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4471 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4472 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4474 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4477 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4481 gint orig_w, orig_h;
4484 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4488 ss = gdk_screen_get_default();
4489 s_w = gdk_screen_get_width(ss);
4490 s_h = gdk_screen_get_height(ss);
4494 if (dstWidth > s_w * factor / 100)
4496 dstWidth = s_w * factor / 100;
4497 dstHeight = dstHeight * dstWidth / orig_w;
4499 if (dstHeight > s_h * factor / 100)
4501 dstHeight = s_h * factor / 100;
4502 dstWidth = dstWidth * dstHeight / orig_h;
4504 xscale *= (gdouble)dstWidth / orig_w;
4505 yscale *= (gdouble)dstHeight / orig_h;
4506 w *= (gdouble)dstWidth / orig_w;
4507 h *= (gdouble)dstHeight / orig_h;
4509 g_debug("scaled %d x %d", dstWidth, dstHeight);
4510 GdkPixbuf *scaled_preview;
4511 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4512 if (ghb_settings_get_boolean(settings, "show_crop"))
4519 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4521 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4523 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4525 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4527 g_object_unref (preview);
4528 return scaled_preview;
4532 sanitize_volname(gchar *name)
4557 ghb_dvd_volname(const gchar *device)
4560 name = hb_dvd_name((gchar*)device);
4561 if (name != NULL && name[0] != 0)
4563 name = g_strdup(name);
4564 sanitize_volname(name);