1 /***************************************************************************
4 * Fri Mar 28 10:38:44 2008
5 * Copyright 2008 John Stebbins
6 * <john at stebbins dot name>
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
29 #include <glib/gstdio.h>
30 #include "hb-backend.h"
32 #include "callbacks.h"
33 #include "subtitlehandler.h"
34 #include "x264handler.h"
42 const gchar *shortOpt;
53 static gchar **index_str = NULL;
54 static gint index_str_size = 0;
57 index_str_init(gint max_index)
61 if (max_index+1 > index_str_size)
63 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
64 for (ii = index_str_size; ii <= max_index; ii++)
66 index_str[ii] = g_strdup_printf("%d", ii);
68 index_str_size = max_index + 1;
72 static options_map_t d_par_opts[] =
75 {"Strict", "1", 1, "1"},
76 {"Loose", "2", 2, "2"},
77 {"Custom", "3", 3, "3"},
79 combo_opts_t par_opts =
81 sizeof(d_par_opts)/sizeof(options_map_t),
85 static options_map_t d_alignment_opts[] =
90 {"16", "16", 16, "16"},
92 combo_opts_t alignment_opts =
94 sizeof(d_alignment_opts)/sizeof(options_map_t),
98 static options_map_t d_logging_opts[] =
104 combo_opts_t logging_opts =
106 sizeof(d_logging_opts)/sizeof(options_map_t),
110 static options_map_t d_appcast_update_opts[] =
112 {"Never", "never", 0, "never"},
113 {"Daily", "daily", 1, "daily"},
114 {"Weekly", "weekly", 2, "weekly"},
115 {"Monthly", "monthly", 3, "monthly"},
117 combo_opts_t appcast_update_opts =
119 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
120 d_appcast_update_opts
123 static options_map_t d_vqual_granularity_opts[] =
125 {"0.2", "0.2", 0.2, "0.2"},
126 {"0.25", "0.25", 0.25, "0.25"},
127 {"0.5", "0.5", 0.5, "0.5"},
130 combo_opts_t vqual_granularity_opts =
132 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
133 d_vqual_granularity_opts
136 static options_map_t d_container_opts[] =
138 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
139 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
140 {"M4V", "m4v", HB_MUX_MP4, "m4v"},
142 combo_opts_t container_opts =
144 sizeof(d_container_opts)/sizeof(options_map_t),
148 static options_map_t d_detel_opts[] =
150 {"None", "none", 0, ""},
151 {"Custom", "custom", 1, ""},
152 {"Default","default",2, NULL},
154 combo_opts_t detel_opts =
156 sizeof(d_detel_opts)/sizeof(options_map_t),
160 static options_map_t d_decomb_opts[] =
162 {"None", "none", 0, ""},
163 {"Custom", "custom", 1, ""},
164 {"Default","default",2, NULL},
166 combo_opts_t decomb_opts =
168 sizeof(d_decomb_opts)/sizeof(options_map_t),
172 static options_map_t d_deint_opts[] =
174 {"None", "none", 0, ""},
175 {"Custom", "custom", 1, ""},
176 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
177 {"Slow", "slow", 3, "2:-1:-1:0:1"},
178 {"Slower", "slower", 4, "0:-1:-1:0:1"},
180 combo_opts_t deint_opts =
182 sizeof(d_deint_opts)/sizeof(options_map_t),
186 static options_map_t d_denoise_opts[] =
188 {"None", "none", 0, ""},
189 {"Custom", "custom", 1, ""},
190 {"Weak", "weak", 2, "2:1:2:3"},
191 {"Medium", "medium", 3, "3:2:2:3"},
192 {"Strong", "strong", 4, "7:7:5:5"},
194 combo_opts_t denoise_opts =
196 sizeof(d_denoise_opts)/sizeof(options_map_t),
200 static options_map_t d_vcodec_opts[] =
202 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
203 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
204 {"Theora", "theora", HB_VCODEC_THEORA, ""},
206 combo_opts_t vcodec_opts =
208 sizeof(d_vcodec_opts)/sizeof(options_map_t),
212 static options_map_t d_acodec_opts[] =
214 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
215 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
216 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
217 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
218 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
219 {"Auto Pass-Thru", "auto", HB_ACODEC_DCA|HB_ACODEC_AC3, "auto"},
221 combo_opts_t acodec_opts =
223 sizeof(d_acodec_opts)/sizeof(options_map_t),
227 static options_map_t d_direct_opts[] =
229 {"None", "none", 0, "none"},
230 {"Spatial", "spatial", 1, "spatial"},
231 {"Temporal", "temporal", 2, "temporal"},
232 {"Automatic", "auto", 3, "auto"},
234 combo_opts_t direct_opts =
236 sizeof(d_direct_opts)/sizeof(options_map_t),
240 static options_map_t d_badapt_opts[] =
242 {"Off", "0", 0, "0"},
243 {"Fast", "1", 1, "1"},
244 {"Optimal", "2", 2, "2"},
246 combo_opts_t badapt_opts =
248 sizeof(d_badapt_opts)/sizeof(options_map_t),
252 static options_map_t d_me_opts[] =
254 {"Diamond", "dia", 0, "dia"},
255 {"Hexagon", "hex", 1, "hex"},
256 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
257 {"Exhaustive", "esa", 3, "esa"},
258 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
260 combo_opts_t me_opts =
262 sizeof(d_me_opts)/sizeof(options_map_t),
266 static options_map_t d_subme_opts[] =
278 combo_opts_t subme_opts =
280 sizeof(d_subme_opts)/sizeof(options_map_t),
284 static options_map_t d_analyse_opts[] =
286 {"Some", "some", 0, "some"},
287 {"None", "none", 1, "none"},
288 {"All", "all", 2, "all"},
289 {"Custom", "custom", 3, "all"},
291 combo_opts_t analyse_opts =
293 sizeof(d_analyse_opts)/sizeof(options_map_t),
297 static options_map_t d_trellis_opts[] =
299 {"Disabled", "0", 0, "0"},
300 {"Final Macro Block", "1", 1, "1"},
301 {"Always", "2", 2, "2"},
303 combo_opts_t trellis_opts =
305 sizeof(d_trellis_opts)/sizeof(options_map_t),
309 combo_opts_t subtitle_opts =
315 combo_opts_t title_opts =
321 combo_opts_t audio_track_opts =
333 combo_name_map_t combo_name_map[] =
335 {"PicturePAR", &par_opts},
336 {"PictureModulus", &alignment_opts},
337 {"LoggingLevel", &logging_opts},
338 {"check_updates", &appcast_update_opts},
339 {"VideoQualityGranularity", &vqual_granularity_opts},
340 {"FileFormat", &container_opts},
341 {"PictureDeinterlace", &deint_opts},
342 {"PictureDecomb", &decomb_opts},
343 {"PictureDetelecine", &detel_opts},
344 {"PictureDenoise", &denoise_opts},
345 {"VideoEncoder", &vcodec_opts},
346 {"AudioEncoder", &acodec_opts},
347 {"x264_direct", &direct_opts},
348 {"x264_b_adapt", &badapt_opts},
349 {"x264_me", &me_opts},
350 {"x264_subme", &subme_opts},
351 {"x264_analyse", &analyse_opts},
352 {"x264_trellis", &trellis_opts},
353 {"SubtitleTrack", &subtitle_opts},
354 {"title", &title_opts},
355 {"AudioTrack", &audio_track_opts},
360 typedef struct iso639_lang_t
362 char * eng_name; /* Description in English */
363 char * native_name; /* Description in native language */
364 char * iso639_1; /* ISO-639-1 (2 characters) code */
365 char * iso639_2; /* ISO-639-2/t (3 character) code */
366 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
370 const iso639_lang_t ghb_language_table[] =
372 { "Any", "", "zz", "und" },
373 { "Afar", "", "aa", "aar" },
374 { "Abkhazian", "", "ab", "abk" },
375 { "Afrikaans", "", "af", "afr" },
376 { "Akan", "", "ak", "aka" },
377 { "Albanian", "", "sq", "sqi", "alb" },
378 { "Amharic", "", "am", "amh" },
379 { "Arabic", "", "ar", "ara" },
380 { "Aragonese", "", "an", "arg" },
381 { "Armenian", "", "hy", "hye", "arm" },
382 { "Assamese", "", "as", "asm" },
383 { "Avaric", "", "av", "ava" },
384 { "Avestan", "", "ae", "ave" },
385 { "Aymara", "", "ay", "aym" },
386 { "Azerbaijani", "", "az", "aze" },
387 { "Bashkir", "", "ba", "bak" },
388 { "Bambara", "", "bm", "bam" },
389 { "Basque", "", "eu", "eus", "baq" },
390 { "Belarusian", "", "be", "bel" },
391 { "Bengali", "", "bn", "ben" },
392 { "Bihari", "", "bh", "bih" },
393 { "Bislama", "", "bi", "bis" },
394 { "Bosnian", "", "bs", "bos" },
395 { "Breton", "", "br", "bre" },
396 { "Bulgarian", "", "bg", "bul" },
397 { "Burmese", "", "my", "mya", "bur" },
398 { "Catalan", "", "ca", "cat" },
399 { "Chamorro", "", "ch", "cha" },
400 { "Chechen", "", "ce", "che" },
401 { "Chinese", "", "zh", "zho", "chi" },
402 { "Church Slavic", "", "cu", "chu" },
403 { "Chuvash", "", "cv", "chv" },
404 { "Cornish", "", "kw", "cor" },
405 { "Corsican", "", "co", "cos" },
406 { "Cree", "", "cr", "cre" },
407 { "Czech", "", "cs", "ces", "cze" },
408 { "Danish", "Dansk", "da", "dan" },
409 { "Divehi", "", "dv", "div" },
410 { "Dutch", "Nederlands", "nl", "nld", "dut" },
411 { "Dzongkha", "", "dz", "dzo" },
412 { "English", "English", "en", "eng" },
413 { "Esperanto", "", "eo", "epo" },
414 { "Estonian", "", "et", "est" },
415 { "Ewe", "", "ee", "ewe" },
416 { "Faroese", "", "fo", "fao" },
417 { "Fijian", "", "fj", "fij" },
418 { "Finnish", "Suomi", "fi", "fin" },
419 { "French", "Francais", "fr", "fra", "fre" },
420 { "Western Frisian", "", "fy", "fry" },
421 { "Fulah", "", "ff", "ful" },
422 { "Georgian", "", "ka", "kat", "geo" },
423 { "German", "Deutsch", "de", "deu", "ger" },
424 { "Gaelic (Scots)", "", "gd", "gla" },
425 { "Irish", "", "ga", "gle" },
426 { "Galician", "", "gl", "glg" },
427 { "Manx", "", "gv", "glv" },
428 { "Greek, Modern", "", "el", "ell", "gre" },
429 { "Guarani", "", "gn", "grn" },
430 { "Gujarati", "", "gu", "guj" },
431 { "Haitian", "", "ht", "hat" },
432 { "Hausa", "", "ha", "hau" },
433 { "Hebrew", "", "he", "heb" },
434 { "Herero", "", "hz", "her" },
435 { "Hindi", "", "hi", "hin" },
436 { "Hiri Motu", "", "ho", "hmo" },
437 { "Hungarian", "Magyar", "hu", "hun" },
438 { "Igbo", "", "ig", "ibo" },
439 { "Icelandic", "Islenska", "is", "isl", "ice" },
440 { "Ido", "", "io", "ido" },
441 { "Sichuan Yi", "", "ii", "iii" },
442 { "Inuktitut", "", "iu", "iku" },
443 { "Interlingue", "", "ie", "ile" },
444 { "Interlingua", "", "ia", "ina" },
445 { "Indonesian", "", "id", "ind" },
446 { "Inupiaq", "", "ik", "ipk" },
447 { "Italian", "Italiano", "it", "ita" },
448 { "Javanese", "", "jv", "jav" },
449 { "Japanese", "", "ja", "jpn" },
450 { "Kalaallisut", "", "kl", "kal" },
451 { "Kannada", "", "kn", "kan" },
452 { "Kashmiri", "", "ks", "kas" },
453 { "Kanuri", "", "kr", "kau" },
454 { "Kazakh", "", "kk", "kaz" },
455 { "Central Khmer", "", "km", "khm" },
456 { "Kikuyu", "", "ki", "kik" },
457 { "Kinyarwanda", "", "rw", "kin" },
458 { "Kirghiz", "", "ky", "kir" },
459 { "Komi", "", "kv", "kom" },
460 { "Kongo", "", "kg", "kon" },
461 { "Korean", "", "ko", "kor" },
462 { "Kuanyama", "", "kj", "kua" },
463 { "Kurdish", "", "ku", "kur" },
464 { "Lao", "", "lo", "lao" },
465 { "Latin", "", "la", "lat" },
466 { "Latvian", "", "lv", "lav" },
467 { "Limburgan", "", "li", "lim" },
468 { "Lingala", "", "ln", "lin" },
469 { "Lithuanian", "", "lt", "lit" },
470 { "Luxembourgish", "", "lb", "ltz" },
471 { "Luba-Katanga", "", "lu", "lub" },
472 { "Ganda", "", "lg", "lug" },
473 { "Macedonian", "", "mk", "mkd", "mac" },
474 { "Marshallese", "", "mh", "mah" },
475 { "Malayalam", "", "ml", "mal" },
476 { "Maori", "", "mi", "mri", "mao" },
477 { "Marathi", "", "mr", "mar" },
478 { "Malay", "", "ms", "msa", "msa" },
479 { "Malagasy", "", "mg", "mlg" },
480 { "Maltese", "", "mt", "mlt" },
481 { "Moldavian", "", "mo", "mol" },
482 { "Mongolian", "", "mn", "mon" },
483 { "Nauru", "", "na", "nau" },
484 { "Navajo", "", "nv", "nav" },
485 { "Ndebele, South", "", "nr", "nbl" },
486 { "Ndebele, North", "", "nd", "nde" },
487 { "Ndonga", "", "ng", "ndo" },
488 { "Nepali", "", "ne", "nep" },
489 { "Norwegian Nynorsk", "", "nn", "nno" },
490 { "Norwegian Bokmål", "", "nb", "nob" },
491 { "Norwegian", "Norsk", "no", "nor" },
492 { "Chichewa; Nyanja", "", "ny", "nya" },
493 { "Occitan", "", "oc", "oci" },
494 { "Ojibwa", "", "oj", "oji" },
495 { "Oriya", "", "or", "ori" },
496 { "Oromo", "", "om", "orm" },
497 { "Ossetian", "", "os", "oss" },
498 { "Panjabi", "", "pa", "pan" },
499 { "Persian", "", "fa", "fas", "per" },
500 { "Pali", "", "pi", "pli" },
501 { "Polish", "", "pl", "pol" },
502 { "Portuguese", "Portugues", "pt", "por" },
503 { "Pushto", "", "ps", "pus" },
504 { "Quechua", "", "qu", "que" },
505 { "Romansh", "", "rm", "roh" },
506 { "Romanian", "", "ro", "ron", "rum" },
507 { "Rundi", "", "rn", "run" },
508 { "Russian", "", "ru", "rus" },
509 { "Sango", "", "sg", "sag" },
510 { "Sanskrit", "", "sa", "san" },
511 { "Serbian", "", "sr", "srp", "scc" },
512 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
513 { "Sinhala", "", "si", "sin" },
514 { "Slovak", "", "sk", "slk", "slo" },
515 { "Slovenian", "", "sl", "slv" },
516 { "Northern Sami", "", "se", "sme" },
517 { "Samoan", "", "sm", "smo" },
518 { "Shona", "", "sn", "sna" },
519 { "Sindhi", "", "sd", "snd" },
520 { "Somali", "", "so", "som" },
521 { "Sotho, Southern", "", "st", "sot" },
522 { "Spanish", "Espanol", "es", "spa" },
523 { "Sardinian", "", "sc", "srd" },
524 { "Swati", "", "ss", "ssw" },
525 { "Sundanese", "", "su", "sun" },
526 { "Swahili", "", "sw", "swa" },
527 { "Swedish", "Svenska", "sv", "swe" },
528 { "Tahitian", "", "ty", "tah" },
529 { "Tamil", "", "ta", "tam" },
530 { "Tatar", "", "tt", "tat" },
531 { "Telugu", "", "te", "tel" },
532 { "Tajik", "", "tg", "tgk" },
533 { "Tagalog", "", "tl", "tgl" },
534 { "Thai", "", "th", "tha" },
535 { "Tibetan", "", "bo", "bod", "tib" },
536 { "Tigrinya", "", "ti", "tir" },
537 { "Tonga", "", "to", "ton" },
538 { "Tswana", "", "tn", "tsn" },
539 { "Tsonga", "", "ts", "tso" },
540 { "Turkmen", "", "tk", "tuk" },
541 { "Turkish", "", "tr", "tur" },
542 { "Twi", "", "tw", "twi" },
543 { "Uighur", "", "ug", "uig" },
544 { "Ukrainian", "", "uk", "ukr" },
545 { "Urdu", "", "ur", "urd" },
546 { "Uzbek", "", "uz", "uzb" },
547 { "Venda", "", "ve", "ven" },
548 { "Vietnamese", "", "vi", "vie" },
549 { "Volapük", "", "vo", "vol" },
550 { "Welsh", "", "cy", "cym", "wel" },
551 { "Walloon", "", "wa", "wln" },
552 { "Wolof", "", "wo", "wol" },
553 { "Xhosa", "", "xh", "xho" },
554 { "Yiddish", "", "yi", "yid" },
555 { "Yoruba", "", "yo", "yor" },
556 { "Zhuang", "", "za", "zha" },
557 { "Zulu", "", "zu", "zul" },
558 {NULL, NULL, NULL, NULL}
560 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
562 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
565 del_tree(const gchar *name, gboolean del_top)
569 if (g_file_test(name, G_FILE_TEST_IS_DIR))
571 GDir *gdir = g_dir_open(name, 0, NULL);
572 file = g_dir_read_name(gdir);
576 path = g_strdup_printf("%s/%s", name, file);
577 del_tree(path, TRUE);
579 file = g_dir_read_name(gdir);
594 return hb_get_version(NULL);
599 signal_user_data_t *ud,
607 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
616 *step = ghb_settings_combo_double(ud->settings,
617 "VideoQualityGranularity");
618 if (*step == 0.2 || *step == 0.5)
620 else if (*step == 0.25)
625 case HB_VCODEC_FFMPEG:
633 case HB_VCODEC_THEORA:
652 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
656 const gchar *result = "";
658 str = ghb_value_string(gval);
659 for (ii = 0; ii < opts->count; ii++)
661 if (strcmp(opts->map[ii].shortOpt, str) == 0)
663 result = opts->map[ii].svalue;
672 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
678 str = ghb_value_string(gval);
679 for (ii = 0; ii < opts->count; ii++)
681 if (strcmp(opts->map[ii].shortOpt, str) == 0)
683 result = opts->map[ii].ivalue;
692 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
698 str = ghb_value_string(gval);
699 for (ii = 0; ii < opts->count; ii++)
701 if (strcmp(opts->map[ii].shortOpt, str) == 0)
703 result = opts->map[ii].ivalue;
712 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
716 const gchar *result = "";
718 str = ghb_value_string(gval);
719 for (ii = 0; ii < opts->count; ii++)
721 if (strcmp(opts->map[ii].shortOpt, str) == 0)
723 result = opts->map[ii].option;
732 lookup_mix_int(const GValue *mix)
739 str = ghb_value_string(mix);
740 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
742 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
744 result = hb_audio_mixdowns[ii].amixdown;
753 lookup_mix_option(const GValue *mix)
757 gchar *result = "None";
760 str = ghb_value_string(mix);
761 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
763 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
765 result = hb_audio_mixdowns[ii].human_readable_name;
774 lookup_video_rate_int(const GValue *vrate)
780 str = ghb_value_string(vrate);
781 for (ii = 0; ii < hb_video_rates_count; ii++)
783 if (strcmp(hb_video_rates[ii].string, str) == 0)
785 result = hb_video_rates[ii].rate;
790 // Default to "same as source"
795 lookup_video_rate_option(const GValue *vrate)
799 const gchar *result = "Same as source";
801 str = ghb_value_string(vrate);
802 for (ii = 0; ii < hb_video_rates_count; ii++)
804 if (strcmp(hb_video_rates[ii].string, str) == 0)
806 result = hb_video_rates[ii].string;
811 // Default to "same as source"
816 lookup_audio_rate_int(const GValue *rate)
822 // Coincidentally, the string "source" will return 0
823 // which is our flag to use "same as source"
824 str = ghb_value_string(rate);
825 for (ii = 0; ii < hb_audio_rates_count; ii++)
827 if (strcmp(hb_audio_rates[ii].string, str) == 0)
829 result = hb_audio_rates[ii].rate;
838 lookup_audio_rate_option(const GValue *rate)
842 const gchar *result = "Same as source";
844 // Coincidentally, the string "source" will return 0
845 // which is our flag to use "same as source"
846 str = ghb_value_string(rate);
847 for (ii = 0; ii < hb_audio_rates_count; ii++)
849 if (strcmp(hb_audio_rates[ii].string, str) == 0)
851 result = hb_audio_rates[ii].string;
860 lookup_audio_bitrate_int(const GValue *rate)
866 // Coincidentally, the string "source" will return 0
867 // which is our flag to use "same as source"
868 str = ghb_value_string(rate);
869 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
871 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
873 result = hb_audio_bitrates[ii].rate;
882 lookup_audio_bitrate_option(const GValue *rate)
886 const gchar *result = "Same as source";
888 // Coincidentally, the string "source" will return 0
889 // which is our flag to use "same as source"
890 str = ghb_value_string(rate);
891 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
893 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
895 result = hb_audio_bitrates[ii].string;
904 lookup_audio_lang_int(const GValue *rate)
910 // Coincidentally, the string "source" will return 0
911 // which is our flag to use "same as source"
912 str = ghb_value_string(rate);
913 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
915 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
926 lookup_audio_lang_option(const GValue *rate)
930 const gchar *result = "Same as source";
932 // Coincidentally, the string "source" will return 0
933 // which is our flag to use "same as source"
934 str = ghb_value_string(rate);
935 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
937 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
939 result = ghb_language_table[ii].eng_name;
948 get_acodec_value(gint val)
950 GValue *value = NULL;
953 for (ii = 0; ii < acodec_opts.count; ii++)
955 if ((int)acodec_opts.map[ii].ivalue == val)
957 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
965 get_amix_value(gint val)
967 GValue *value = NULL;
970 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
972 if (hb_audio_mixdowns[ii].amixdown == val)
974 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
981 // Handle for libhb. Gets set by ghb_backend_init()
982 static hb_handle_t * h_scan = NULL;
983 static hb_handle_t * h_queue = NULL;
985 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
992 hb_get_tempory_directory(h_scan, dir);
993 return g_strdup(dir);
997 ghb_hb_cleanup(gboolean partial)
1001 hb_get_tempory_directory(h_scan, dir);
1002 del_tree(dir, !partial);
1006 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1014 titleindex = ghb_settings_combo_int(ud->settings, "title");
1020 hb_subtitle_t * sub;
1022 if (h_scan == NULL) return VOBSUB;
1023 list = hb_get_titles( h_scan );
1024 if( !hb_list_count( list ) )
1026 /* No valid title, stop right there */
1029 title = hb_list_item( list, titleindex );
1030 if (title == NULL) return VOBSUB; // Bad titleindex
1031 sub = hb_list_item( title->list_subtitle, track);
1039 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1042 const gchar * name = "Unknown";
1055 titleindex = ghb_settings_combo_int(ud->settings, "title");
1061 hb_subtitle_t * sub;
1065 list = hb_get_titles( h_scan );
1066 if( !hb_list_count( list ) )
1069 title = hb_list_item( list, titleindex );
1073 sub = hb_list_item( title->list_subtitle, track);
1076 switch (sub->source)
1097 ghb_get_title_number(gint titleindex)
1102 if (h_scan == NULL) return 1;
1103 list = hb_get_titles( h_scan );
1104 if( !hb_list_count( list ) )
1106 /* No valid title, stop right there */
1109 title = hb_list_item( list, titleindex );
1110 if (title == NULL) return 1; // Bad titleindex
1111 return title->index;
1114 static hb_audio_config_t*
1115 get_hb_audio(gint titleindex, gint track)
1119 hb_audio_config_t *audio = NULL;
1121 if (h_scan == NULL) return NULL;
1122 list = hb_get_titles( h_scan );
1123 if( !hb_list_count( list ) )
1125 /* No valid title, stop right there */
1128 title = hb_list_item( list, titleindex );
1129 if (title == NULL) return NULL; // Bad titleindex
1130 if (!hb_list_count(title->list_audio))
1134 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1139 search_rates(hb_rate_t *rates, gint rate, gint count)
1142 for (ii = 0; ii < count; ii++)
1144 if (rates[ii].rate == rate)
1150 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1152 static GtkListStore*
1153 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1156 GtkListStore *store;
1158 g_debug("get_combo_box_store() %s\n", name);
1159 // First modify the combobox model to allow greying out of options
1160 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1161 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1166 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1168 GtkListStore *store;
1171 store = get_combo_box_store(builder, name);
1172 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1174 gtk_list_store_set(store, &iter,
1181 ghb_grey_combo_options(GtkBuilder *builder)
1184 gint container, track, titleindex, acodec;
1185 hb_audio_config_t *audio = NULL;
1188 widget = GHB_WIDGET (builder, "title");
1189 gval = ghb_widget_value(widget);
1190 titleindex = ghb_lookup_combo_int("title", gval);
1191 ghb_value_free(gval);
1192 widget = GHB_WIDGET (builder, "AudioTrack");
1193 gval = ghb_widget_value(widget);
1194 track = ghb_lookup_combo_int("AudioTrack", gval);
1195 ghb_value_free(gval);
1196 audio = get_hb_audio(titleindex, track);
1197 widget = GHB_WIDGET (builder, "FileFormat");
1198 gval = ghb_widget_value(widget);
1199 container = ghb_lookup_combo_int("FileFormat", gval);
1200 ghb_value_free(gval);
1202 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1203 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1204 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1205 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1207 gboolean allow_dca = TRUE;
1208 allow_dca = (container != HB_MUX_MP4);
1210 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1212 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1214 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1216 if (audio && audio->in.codec != HB_ACODEC_AC3)
1218 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1220 if (audio && audio->in.codec != HB_ACODEC_DCA)
1222 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1224 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1226 widget = GHB_WIDGET (builder, "AudioEncoder");
1227 gval = ghb_widget_value(widget);
1228 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1229 ghb_value_free(gval);
1230 if (acodec != HB_ACODEC_AC3)
1232 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1234 if (container == HB_MUX_MP4)
1236 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1237 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1238 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1240 else if (container == HB_MUX_AVI)
1242 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1243 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1244 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1246 else if (container == HB_MUX_OGM)
1248 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
1251 gboolean allow_mono = TRUE;
1252 gboolean allow_stereo = TRUE;
1253 gboolean allow_dolby = TRUE;
1254 gboolean allow_dpl2 = TRUE;
1255 gboolean allow_6ch = TRUE;
1259 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1260 (acodec != HB_ACODEC_LAME);
1261 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1263 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1265 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1266 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1267 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1268 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1270 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1271 (acodec != HB_ACODEC_LAME) &&
1272 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1273 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1275 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1276 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1277 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1278 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1279 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1283 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1285 hb_audio_config_t *audio = NULL;
1286 gboolean allow_mono = TRUE;
1287 gboolean allow_stereo = TRUE;
1288 gboolean allow_dolby = TRUE;
1289 gboolean allow_dpl2 = TRUE;
1290 gboolean allow_6ch = TRUE;
1292 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1294 // Audio codec pass-thru. No mixdown
1297 audio = get_hb_audio(titleindex, track);
1301 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1302 (acodec != HB_ACODEC_LAME);
1303 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1305 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1307 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1308 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1309 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1310 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1312 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1313 (acodec != HB_ACODEC_LAME) &&
1314 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1315 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1317 gboolean greater = FALSE;
1320 // If no mix is specified, select the best available.
1321 mix = HB_AMIXDOWN_6CH;
1323 if (mix == HB_AMIXDOWN_6CH)
1326 if (allow_6ch) return HB_AMIXDOWN_6CH;
1328 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1331 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1333 if (mix == HB_AMIXDOWN_DOLBY || greater)
1336 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1338 if (mix == HB_AMIXDOWN_STEREO || greater)
1341 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1343 if (mix == HB_AMIXDOWN_MONO || greater)
1346 if (allow_mono) return HB_AMIXDOWN_MONO;
1348 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1349 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1350 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1351 if (allow_6ch) return HB_AMIXDOWN_6CH;
1355 // Set up the model for the combo box
1357 init_combo_box(GtkBuilder *builder, const gchar *name)
1360 GtkListStore *store;
1361 GtkCellRenderer *cell;
1363 g_debug("init_combo_box() %s\n", name);
1364 // First modify the combobox model to allow greying out of options
1365 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1369 // 1 - String to display
1370 // 2 - bool indicating whether the entry is selectable (grey or not)
1371 // 3 - String that is used for presets
1372 // 4 - Int value determined by backend
1373 // 5 - String value determined by backend
1374 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1375 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1376 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1378 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1380 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1381 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1382 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1383 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1384 "text", 0, "sensitive", 1, NULL);
1387 { // Combo box entry
1388 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1393 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1396 GtkListStore *store;
1399 g_debug("audio_samplerate_opts_set ()\n");
1400 store = get_combo_box_store(builder, name);
1401 gtk_list_store_clear(store);
1402 // Add an item for "Same As Source"
1403 gtk_list_store_append(store, &iter);
1404 gtk_list_store_set(store, &iter,
1405 0, "Same as source",
1411 for (ii = 0; ii < count; ii++)
1413 gtk_list_store_append(store, &iter);
1414 gtk_list_store_set(store, &iter,
1415 0, rates[ii].string,
1417 2, rates[ii].string,
1418 3, (gdouble)rates[ii].rate,
1419 4, rates[ii].string,
1425 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1428 GtkListStore *store;
1431 g_debug("video_rate_opts_set ()\n");
1432 store = get_combo_box_store(builder, name);
1433 gtk_list_store_clear(store);
1434 // Add an item for "Same As Source"
1435 gtk_list_store_append(store, &iter);
1436 gtk_list_store_set(store, &iter,
1437 0, "Same as source",
1443 for (ii = 0; ii < count; ii++)
1447 if (strcmp(rates[ii].string, "23.976") == 0)
1449 desc = "(NTSC Film)";
1451 else if (strcmp(rates[ii].string, "25") == 0)
1453 desc = "(PAL Film/Video)";
1455 else if (strcmp(rates[ii].string, "29.97") == 0)
1457 desc = "(NTSC Video)";
1459 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1460 gtk_list_store_append(store, &iter);
1461 gtk_list_store_set(store, &iter,
1464 2, rates[ii].string,
1465 3, (gdouble)rates[ii].rate,
1466 4, rates[ii].string,
1473 mix_opts_set(GtkBuilder *builder, const gchar *name)
1476 GtkListStore *store;
1479 g_debug("mix_opts_set ()\n");
1480 store = get_combo_box_store(builder, name);
1481 gtk_list_store_clear(store);
1482 gtk_list_store_append(store, &iter);
1483 gtk_list_store_set(store, &iter,
1490 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1492 gtk_list_store_append(store, &iter);
1493 gtk_list_store_set(store, &iter,
1494 0, hb_audio_mixdowns[ii].human_readable_name,
1496 2, hb_audio_mixdowns[ii].short_name,
1497 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1498 4, hb_audio_mixdowns[ii].internal_name,
1504 language_opts_set(GtkBuilder *builder, const gchar *name)
1507 GtkListStore *store;
1510 g_debug("language_opts_set ()\n");
1511 store = get_combo_box_store(builder, name);
1512 gtk_list_store_clear(store);
1513 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1515 gtk_list_store_append(store, &iter);
1516 gtk_list_store_set(store, &iter,
1517 0, ghb_language_table[ii].eng_name,
1519 2, ghb_language_table[ii].iso639_2,
1521 4, ghb_language_table[ii].iso639_1,
1526 static gchar **titles = NULL;
1529 title_opts_set(GtkBuilder *builder, const gchar *name)
1532 GtkListStore *store;
1533 hb_list_t * list = NULL;
1534 hb_title_t * title = NULL;
1538 g_debug("title_opts_set ()\n");
1539 store = get_combo_box_store(builder, name);
1540 gtk_list_store_clear(store);
1543 list = hb_get_titles( h_scan );
1544 count = hb_list_count( list );
1545 if (count > 100) count = 100;
1547 if (titles) g_strfreev(titles);
1548 if (title_opts.map) g_free(title_opts.map);
1551 title_opts.count = count;
1552 title_opts.map = g_malloc(count*sizeof(options_map_t));
1553 titles = g_malloc((count+1) * sizeof(gchar*));
1557 title_opts.count = 1;
1558 title_opts.map = g_malloc(sizeof(options_map_t));
1563 // No titles. Fill in a default.
1564 gtk_list_store_append(store, &iter);
1565 gtk_list_store_set(store, &iter,
1572 title_opts.map[0].option = "No Titles";
1573 title_opts.map[0].shortOpt = "none";
1574 title_opts.map[0].ivalue = -1;
1575 title_opts.map[0].svalue = "none";
1578 for (ii = 0; ii < count; ii++)
1580 title = (hb_title_t*)hb_list_item(list, ii);
1581 if (title->duration != 0)
1583 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1584 title->index, title->hours, title->minutes, title->seconds);
1588 titles[ii] = g_strdup_printf ("%d - Unknown Length", title->index);
1590 gtk_list_store_append(store, &iter);
1591 gtk_list_store_set(store, &iter,
1598 title_opts.map[ii].option = titles[ii];
1599 title_opts.map[ii].shortOpt = titles[ii];
1600 title_opts.map[ii].ivalue = ii;
1601 title_opts.map[ii].svalue = titles[ii];
1607 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1610 gboolean foundit = FALSE;
1612 if (gtk_tree_model_get_iter_first (store, iter))
1616 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1617 if (value == (int)ivalue)
1622 } while (gtk_tree_model_iter_next (store, iter));
1628 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1631 GtkListStore *store;
1632 hb_list_t * list = NULL;
1633 hb_title_t * title = NULL;
1634 hb_audio_config_t * audio;
1638 g_debug("audio_track_opts_set ()\n");
1639 store = get_combo_box_store(builder, name);
1640 gtk_list_store_clear(store);
1643 list = hb_get_titles( h_scan );
1644 title = (hb_title_t*)hb_list_item( list, titleindex );
1647 count = hb_list_count( title->list_audio );
1650 if (count > 100) count = 100;
1651 if (audio_track_opts.map) g_free(audio_track_opts.map);
1654 audio_track_opts.count = count;
1655 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1659 audio_track_opts.count = 1;
1660 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1664 // No audio. set some default
1665 gtk_list_store_append(store, &iter);
1666 gtk_list_store_set(store, &iter,
1673 audio_track_opts.map[0].option = "No Audio";
1674 audio_track_opts.map[0].shortOpt = "none";
1675 audio_track_opts.map[0].ivalue = -1;
1676 audio_track_opts.map[0].svalue = "none";
1679 index_str_init(count-1);
1680 for (ii = 0; ii < count; ii++)
1682 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1683 gtk_list_store_append(store, &iter);
1684 gtk_list_store_set(store, &iter,
1685 0, audio->lang.description,
1691 audio_track_opts.map[ii].option = audio->lang.description,
1692 audio_track_opts.map[ii].shortOpt = index_str[ii];
1693 audio_track_opts.map[ii].ivalue = ii;
1694 audio_track_opts.map[ii].svalue = index_str[ii];
1699 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1702 GtkListStore *store;
1703 hb_list_t * list = NULL;
1704 hb_title_t * title = NULL;
1705 hb_subtitle_t * subtitle;
1707 static char ** options = NULL;
1709 g_debug("subtitle_track_opts_set ()\n");
1710 store = get_combo_box_store(builder, name);
1711 gtk_list_store_clear(store);
1714 list = hb_get_titles( h_scan );
1715 title = (hb_title_t*)hb_list_item( list, titleindex );
1718 count = hb_list_count( title->list_subtitle );
1721 if (count > 100) count = 100;
1722 if (subtitle_opts.map) g_free(subtitle_opts.map);
1725 subtitle_opts.count = count+1;
1726 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1730 subtitle_opts.count = LANG_TABLE_SIZE+1;
1731 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1733 gtk_list_store_append(store, &iter);
1734 gtk_list_store_set(store, &iter,
1735 0, "Foreign Audio Search",
1741 subtitle_opts.map[0].option = "Foreign Audio Search";
1742 subtitle_opts.map[0].shortOpt = "-1";
1743 subtitle_opts.map[0].ivalue = -1;
1744 subtitle_opts.map[0].svalue = "auto";
1747 if (options != NULL)
1748 g_strfreev(options);
1749 options = g_malloc((count+1)*sizeof(gchar*));
1750 index_str_init(count-1);
1751 for (ii = 0; ii < count; ii++)
1753 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1754 // Skip subtitles that must be burned if there is already
1755 // a burned subtitle in the list
1756 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1757 subtitle_opts.map[ii+1].option = options[ii];
1758 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1759 subtitle_opts.map[ii+1].ivalue = ii;
1760 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1761 gtk_list_store_append(store, &iter);
1762 gtk_list_store_set(store, &iter,
1767 4, subtitle->iso639_2,
1770 options[count] = NULL;
1774 index_str_init(LANG_TABLE_SIZE-1);
1775 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1777 subtitle_opts.map[ii+1].option = ghb_language_table[ii].eng_name;
1778 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1779 subtitle_opts.map[ii+1].ivalue = ii;
1780 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
1781 gtk_list_store_append(store, &iter);
1782 gtk_list_store_set(store, &iter,
1783 0, ghb_language_table[ii].eng_name,
1787 4, ghb_language_table[ii].iso639_2,
1800 guint64 longest = 0;
1801 gint titleindex = 0;
1803 g_debug("ghb_longest_title ()\n");
1804 if (h_scan == NULL) return 0;
1805 list = hb_get_titles( h_scan );
1806 count = hb_list_count( list );
1807 if (count > 100) count = 100;
1808 for (ii = 0; ii < count; ii++)
1810 title = (hb_title_t*)hb_list_item(list, ii);
1811 if (title->duration > longest)
1814 longest = title->duration;
1821 ghb_get_source_audio_lang(gint titleindex, gint track)
1825 hb_audio_config_t * audio;
1828 g_debug("ghb_lookup_1st_audio_lang ()\n");
1831 list = hb_get_titles( h_scan );
1832 title = (hb_title_t*)hb_list_item( list, titleindex );
1835 if (hb_list_count( title->list_audio ) <= track)
1838 audio = hb_list_audio_config_item(title->list_audio, track);
1842 lang = g_strdup(audio->lang.iso639_2);
1847 ghb_find_audio_track(
1851 GHashTable *track_indices)
1855 hb_audio_config_t * audio;
1862 g_debug("find_audio_track ()\n");
1863 if (h_scan == NULL) return -1;
1864 list = hb_get_titles( h_scan );
1865 title = (hb_title_t*)hb_list_item( list, titleindex );
1868 count = hb_list_count( title->list_audio );
1870 if (count > 10) count = 10;
1871 used = g_hash_table_lookup(track_indices, &acodec);
1874 used = g_malloc0(count * sizeof(gboolean));
1875 g_hash_table_insert(track_indices, &acodec, used);
1877 // Try to find an item that matches the preferred language and
1878 // the passthru codec type
1879 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1881 for (ii = 0; ii < count; ii++)
1888 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1889 title->list_audio, ii );
1890 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1891 audio->in.channel_layout);
1892 // Find a track that is not visually impaired or dirctor's
1893 // commentary, and has the highest channel count.
1894 if ((audio->in.codec & acodec) &&
1895 (audio->lang.type < 2) &&
1896 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1897 (strcmp(lang, "und") == 0)))
1899 if (channels > max_chan)
1902 max_chan = channels;
1912 // Try to find an item that matches the preferred language
1913 for (ii = 0; ii < count; ii++)
1917 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1918 title->list_audio, ii );
1919 // Find a track that is not visually impaired or dirctor's commentary
1920 if ((audio->lang.type < 2) &&
1921 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1922 (strcmp(lang, "und") == 0)))
1933 // Try to fine an item that does not match the preferred language and
1934 // matches the passthru codec type
1935 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1937 for (ii = 0; ii < count; ii++)
1944 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1945 title->list_audio, ii );
1946 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
1947 audio->in.channel_layout);
1948 // Find a track that is not visually impaired or dirctor's
1949 // commentary, and has the highest channel count.
1950 if ((audio->in.codec & acodec) &&
1951 (audio->lang.type < 2))
1953 if (channels > max_chan)
1956 max_chan = channels;
1966 // Try to fine an item that does not match the preferred language
1967 for (ii = 0; ii < count; ii++)
1971 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1972 title->list_audio, ii );
1973 // Find a track that is not visually impaired or dirctor's commentary
1974 if (audio->lang.type < 2)
1985 // Last ditch, anything goes
1986 for (ii = 0; ii < count; ii++)
1988 audio = (hb_audio_config_t*)hb_list_audio_config_item(
1989 title->list_audio, ii );
2004 ghb_find_pref_subtitle_track(const gchar *lang)
2007 count = subtitle_opts.count;
2008 for (ii = 0; ii < count; ii++)
2010 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2012 return subtitle_opts.map[ii].ivalue;
2019 ghb_find_subtitle_track(
2022 GHashTable *track_indices)
2026 hb_subtitle_t * subtitle;
2030 g_debug("find_subtitle_track ()\n");
2031 if (strcmp(lang, "auto") == 0)
2033 if (h_scan == NULL) return -1;
2034 list = hb_get_titles( h_scan );
2035 title = (hb_title_t*)hb_list_item( list, titleindex );
2038 count = hb_list_count( title->list_subtitle );
2039 used = g_hash_table_lookup(track_indices, lang);
2042 used = g_malloc0(count * sizeof(gboolean));
2043 g_hash_table_insert(track_indices, g_strdup(lang), used);
2045 // Try to find an item that matches the preferred language
2046 for (ii = 0; ii < count; ii++)
2051 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2052 if ((strcmp(lang, subtitle->iso639_2) == 0) ||
2053 (strcmp(lang, "und") == 0))
2064 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2067 GtkListStore *store;
2070 g_debug("generic_opts_set ()\n");
2071 if (name == NULL || opts == NULL) return;
2072 store = get_combo_box_store(builder, name);
2073 gtk_list_store_clear(store);
2074 for (ii = 0; ii < opts->count; ii++)
2076 gtk_list_store_append(store, &iter);
2077 gtk_list_store_set(store, &iter,
2078 0, opts->map[ii].option,
2080 2, opts->map[ii].shortOpt,
2081 3, opts->map[ii].ivalue,
2082 4, opts->map[ii].svalue,
2088 find_combo_table(const gchar *name)
2092 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2094 if (strcmp(name, combo_name_map[ii].name) == 0)
2096 return combo_name_map[ii].opts;
2103 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2107 if (strcmp(name, "AudioBitrate") == 0)
2108 return lookup_audio_bitrate_int(gval);
2109 else if (strcmp(name, "AudioSamplerate") == 0)
2110 return lookup_audio_rate_int(gval);
2111 else if (strcmp(name, "VideoFramerate") == 0)
2112 return lookup_video_rate_int(gval);
2113 else if (strcmp(name, "AudioMixdown") == 0)
2114 return lookup_mix_int(gval);
2115 else if (strcmp(name, "SourceAudioLang") == 0)
2116 return lookup_audio_lang_int(gval);
2119 return lookup_generic_int(find_combo_table(name), gval);
2121 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2126 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2130 if (strcmp(name, "AudioBitrate") == 0)
2131 return lookup_audio_bitrate_int(gval);
2132 else if (strcmp(name, "AudioSamplerate") == 0)
2133 return lookup_audio_rate_int(gval);
2134 else if (strcmp(name, "VideoFramerate") == 0)
2135 return lookup_video_rate_int(gval);
2136 else if (strcmp(name, "AudioMixdown") == 0)
2137 return lookup_mix_int(gval);
2138 else if (strcmp(name, "SourceAudioLang") == 0)
2139 return lookup_audio_lang_int(gval);
2142 return lookup_generic_double(find_combo_table(name), gval);
2144 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2149 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2153 if (strcmp(name, "AudioBitrate") == 0)
2154 return lookup_audio_bitrate_option(gval);
2155 else if (strcmp(name, "AudioSamplerate") == 0)
2156 return lookup_audio_rate_option(gval);
2157 else if (strcmp(name, "VideoFramerate") == 0)
2158 return lookup_video_rate_option(gval);
2159 else if (strcmp(name, "AudioMixdown") == 0)
2160 return lookup_mix_option(gval);
2161 else if (strcmp(name, "SourceAudioLang") == 0)
2162 return lookup_audio_lang_option(gval);
2165 return lookup_generic_option(find_combo_table(name), gval);
2167 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2172 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2176 if (strcmp(name, "AudioBitrate") == 0)
2177 return lookup_audio_bitrate_option(gval);
2178 else if (strcmp(name, "AudioSamplerate") == 0)
2179 return lookup_audio_rate_option(gval);
2180 else if (strcmp(name, "VideoFramerate") == 0)
2181 return lookup_video_rate_option(gval);
2182 else if (strcmp(name, "AudioMixdown") == 0)
2183 return lookup_mix_option(gval);
2184 else if (strcmp(name, "SourceAudioLang") == 0)
2185 return lookup_audio_lang_option(gval);
2188 return lookup_generic_string(find_combo_table(name), gval);
2190 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2195 ghb_update_ui_combo_box(
2196 signal_user_data_t *ud,
2201 GtkComboBox *combo = NULL;
2203 gint handler_id = 0;
2207 g_debug("ghb_update_ui_combo_box() %s\n", name);
2208 // Clearing a combo box causes a rash of "changed" events, even when
2209 // the active item is -1 (inactive). To control things, I'm disabling
2210 // the event till things are settled down.
2211 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2212 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2215 // Valid signal id found. This should always succeed.
2216 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2217 signal_id, 0, 0, 0, 0);
2220 // This should also always succeed
2221 g_signal_handler_block ((gpointer)combo, handler_id);
2227 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2228 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2229 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2230 mix_opts_set(ud->builder, "AudioMixdown");
2231 language_opts_set(ud->builder, "SourceAudioLang");
2232 title_opts_set(ud->builder, "title");
2233 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2234 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2235 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2236 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2237 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2238 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2239 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2240 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2241 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2242 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2243 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2244 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2245 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2246 generic_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2247 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2248 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2249 generic_opts_set(ud->builder, "x264_me", &me_opts);
2250 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2251 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2252 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2256 if (strcmp(name, "AudioBitrate") == 0)
2257 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2258 else if (strcmp(name, "AudioSamplerate") == 0)
2259 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2260 else if (strcmp(name, "VideoFramerate") == 0)
2261 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2262 else if (strcmp(name, "AudioMixdown") == 0)
2263 mix_opts_set(ud->builder, "AudioMixdown");
2264 else if (strcmp(name, "SourceAudioLang") == 0)
2265 language_opts_set(ud->builder, "SourceAudioLang");
2266 else if (strcmp(name, "title") == 0)
2267 title_opts_set(ud->builder, "title");
2268 else if (strcmp(name, "SubtitleTrack") == 0)
2269 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2270 else if (strcmp(name, "AudioTrack") == 0)
2271 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2273 generic_opts_set(ud->builder, name, find_combo_table(name));
2277 g_signal_handler_unblock ((gpointer)combo, handler_id);
2282 init_ui_combo_boxes(GtkBuilder *builder)
2286 init_combo_box(builder, "AudioBitrate");
2287 init_combo_box(builder, "AudioSamplerate");
2288 init_combo_box(builder, "VideoFramerate");
2289 init_combo_box(builder, "AudioMixdown");
2290 init_combo_box(builder, "SourceAudioLang");
2291 init_combo_box(builder, "title");
2292 init_combo_box(builder, "AudioTrack");
2293 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2295 init_combo_box(builder, combo_name_map[ii].name);
2299 static const char * turbo_opts =
2300 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
2301 "no-fast-pskip=0:8x8dct=0";
2303 // Construct the x264 options string
2304 // The result is allocated, so someone must free it at some point.
2306 ghb_build_x264opts_string(GValue *settings)
2309 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2316 result = g_strdup("");
2322 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2326 hb_chapter_t * chapter;
2329 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2330 *hh = *mm = *ss = 0;
2331 if (h_scan == NULL) return;
2332 list = hb_get_titles( h_scan );
2333 title = (hb_title_t*)hb_list_item( list, ti );
2334 if (title == NULL) return;
2335 count = hb_list_count( title->list_chapter );
2336 if (ii >= count) return;
2337 chapter = hb_list_item(title->list_chapter, ii);
2338 if (chapter == NULL) return;
2339 *hh = chapter->hours;
2340 *mm = chapter->minutes;
2341 *ss = chapter->seconds;
2345 ghb_get_chapters(gint titleindex)
2349 hb_chapter_t * chapter;
2351 GValue *chapters = NULL;
2353 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2354 if (h_scan == NULL) return NULL;
2355 list = hb_get_titles( h_scan );
2356 title = (hb_title_t*)hb_list_item( list, titleindex );
2357 if (title == NULL) return NULL;
2358 count = hb_list_count( title->list_chapter );
2359 chapters = ghb_array_value_new(count);
2360 for (ii = 0; ii < count; ii++)
2362 chapter = hb_list_item(title->list_chapter, ii);
2363 if (chapter == NULL) break;
2364 if (chapter->title == NULL || chapter->title[0] == 0)
2367 str = g_strdup_printf ("Chapter %2d", ii+1);
2368 ghb_array_append(chapters, ghb_string_value_new(str));
2373 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2380 ghb_ac3_in_audio_list(const GValue *audio_list)
2384 count = ghb_array_len(audio_list);
2385 for (ii = 0; ii < count; ii++)
2390 asettings = ghb_array_get_nth(audio_list, ii);
2391 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2392 if (acodec & HB_ACODEC_AC3)
2399 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2402 GtkListStore *store;
2405 g_debug("audio_rate_opts_add ()\n");
2406 store = get_combo_box_store(builder, name);
2407 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2409 str = g_strdup_printf ("%d", rate);
2410 gtk_list_store_append(store, &iter);
2411 gtk_list_store_set(store, &iter,
2423 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, gint last_rate)
2426 GtkListStore *store;
2428 gboolean done = FALSE;
2430 guint last = (guint)last_rate;
2432 g_debug("audio_bitrate_opts_clean ()\n");
2433 store = get_combo_box_store(builder, name);
2434 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2438 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2440 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2442 done = !gtk_list_store_remove(store, &iter);
2444 else if (ivalue > last)
2447 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2448 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2453 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2454 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2461 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2464 GtkListStore *store;
2467 g_debug("audio_bitrate_opts_set ()\n");
2468 store = get_combo_box_store(builder, name);
2469 gtk_list_store_clear(store);
2470 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2472 gtk_list_store_append(store, &iter);
2473 gtk_list_store_set(store, &iter,
2474 0, hb_audio_bitrates[ii].string,
2476 2, hb_audio_bitrates[ii].string,
2477 3, (gdouble)hb_audio_bitrates[ii].rate,
2478 4, hb_audio_bitrates[ii].string,
2484 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2486 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2490 ghb_set_default_bitrate_opts(GtkBuilder *builder, gint last_rate)
2492 audio_bitrate_opts_clean(builder, "AudioBitrate", last_rate);
2495 static ghb_status_t hb_status;
2498 ghb_combo_init(signal_user_data_t *ud)
2500 // Set up the list model for the combos
2501 init_ui_combo_boxes(ud->builder);
2502 // Populate all the combos
2503 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2507 ghb_backend_init(gint debug)
2510 h_scan = hb_init( debug, 0 );
2511 h_queue = hb_init( debug, 0 );
2522 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2524 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2525 hb_status.scan.state |= GHB_STATE_SCANNING;
2526 // initialize count and cur to something that won't cause FPE
2527 // when computing progress
2528 hb_status.scan.title_count = 1;
2529 hb_status.scan.title_cur = 0;
2533 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2535 g_debug("ghb_backend_queue_scan()");
2536 hb_scan( h_queue, path, titlenum, 10, 0 );
2537 hb_status.queue.state |= GHB_STATE_SCANNING;
2541 ghb_get_scan_state()
2543 return hb_status.scan.state;
2547 ghb_get_queue_state()
2549 return hb_status.queue.state;
2553 ghb_clear_scan_state(gint state)
2555 hb_status.scan.state &= ~state;
2559 ghb_clear_queue_state(gint state)
2561 hb_status.queue.state &= ~state;
2565 ghb_set_scan_state(gint state)
2567 hb_status.scan.state |= state;
2571 ghb_set_queue_state(gint state)
2573 hb_status.queue.state |= state;
2577 ghb_get_status(ghb_status_t *status)
2579 memcpy(status, &hb_status, sizeof(ghb_status_t));
2588 if (h_scan == NULL) return;
2589 hb_get_state( h_scan, &s_scan );
2590 switch( s_scan.state )
2592 #define p s_scan.param.scanning
2593 case HB_STATE_SCANNING:
2595 hb_status.scan.state |= GHB_STATE_SCANNING;
2596 hb_status.scan.title_count = p.title_count;
2597 hb_status.scan.title_cur = p.title_cur;
2601 case HB_STATE_SCANDONE:
2603 hb_status.scan.state &= ~GHB_STATE_SCANNING;
2604 hb_status.scan.state |= GHB_STATE_SCANDONE;
2607 #define p s_scan.param.working
2608 case HB_STATE_WORKING:
2609 hb_status.scan.state |= GHB_STATE_WORKING;
2610 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2611 hb_status.scan.job_cur = p.job_cur;
2612 hb_status.scan.job_count = p.job_count;
2613 hb_status.scan.progress = p.progress;
2614 hb_status.scan.rate_cur = p.rate_cur;
2615 hb_status.scan.rate_avg = p.rate_avg;
2616 hb_status.scan.hours = p.hours;
2617 hb_status.scan.minutes = p.minutes;
2618 hb_status.scan.seconds = p.seconds;
2619 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
2623 case HB_STATE_PAUSED:
2624 hb_status.scan.state |= GHB_STATE_PAUSED;
2627 case HB_STATE_MUXING:
2629 hb_status.scan.state |= GHB_STATE_MUXING;
2632 #define p s_scan.param.workdone
2633 case HB_STATE_WORKDONE:
2637 hb_status.scan.state |= GHB_STATE_WORKDONE;
2638 hb_status.scan.state &= ~GHB_STATE_MUXING;
2639 hb_status.scan.state &= ~GHB_STATE_PAUSED;
2640 hb_status.scan.state &= ~GHB_STATE_WORKING;
2644 hb_status.scan.error = GHB_ERROR_NONE;
2646 case HB_ERROR_CANCELED:
2647 hb_status.scan.error = GHB_ERROR_CANCELED;
2650 hb_status.scan.error = GHB_ERROR_FAIL;
2653 // Delete all remaining jobs of this encode.
2654 // An encode can be composed of multiple associated jobs.
2655 // When a job is stopped, libhb removes it from the job list,
2656 // but does not remove other jobs that may be associated with it.
2657 // Associated jobs are taged in the sequence id.
2658 while ((job = hb_job(h_scan, 0)) != NULL)
2659 hb_rem( h_scan, job );
2663 hb_get_state( h_queue, &s_queue );
2664 switch( s_queue.state )
2666 #define p s_queue.param.scanning
2667 case HB_STATE_SCANNING:
2669 hb_status.queue.state |= GHB_STATE_SCANNING;
2670 hb_status.queue.title_count = p.title_count;
2671 hb_status.queue.title_cur = p.title_cur;
2675 case HB_STATE_SCANDONE:
2677 hb_status.queue.state &= ~GHB_STATE_SCANNING;
2678 hb_status.queue.state |= GHB_STATE_SCANDONE;
2681 #define p s_queue.param.working
2682 case HB_STATE_WORKING:
2683 hb_status.queue.state |= GHB_STATE_WORKING;
2684 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2685 hb_status.queue.job_cur = p.job_cur;
2686 hb_status.queue.job_count = p.job_count;
2687 hb_status.queue.progress = p.progress;
2688 hb_status.queue.rate_cur = p.rate_cur;
2689 hb_status.queue.rate_avg = p.rate_avg;
2690 hb_status.queue.hours = p.hours;
2691 hb_status.queue.minutes = p.minutes;
2692 hb_status.queue.seconds = p.seconds;
2693 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
2697 case HB_STATE_PAUSED:
2698 hb_status.queue.state |= GHB_STATE_PAUSED;
2701 case HB_STATE_MUXING:
2703 hb_status.queue.state |= GHB_STATE_MUXING;
2706 #define p s_queue.param.workdone
2707 case HB_STATE_WORKDONE:
2711 hb_status.queue.state |= GHB_STATE_WORKDONE;
2712 hb_status.queue.state &= ~GHB_STATE_MUXING;
2713 hb_status.queue.state &= ~GHB_STATE_PAUSED;
2714 hb_status.queue.state &= ~GHB_STATE_WORKING;
2718 hb_status.queue.error = GHB_ERROR_NONE;
2720 case HB_ERROR_CANCELED:
2721 hb_status.queue.error = GHB_ERROR_CANCELED;
2724 hb_status.queue.error = GHB_ERROR_FAIL;
2727 // Delete all remaining jobs of this encode.
2728 // An encode can be composed of multiple associated jobs.
2729 // When a job is stopped, libhb removes it from the job list,
2730 // but does not remove other jobs that may be associated with it.
2731 // Associated jobs are taged in the sequence id.
2732 while ((job = hb_job(h_queue, 0)) != NULL)
2733 hb_rem( h_queue, job );
2740 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
2745 if (h_scan == NULL) return FALSE;
2746 list = hb_get_titles( h_scan );
2747 if( !hb_list_count( list ) )
2749 /* No valid title, stop right there */
2753 title = hb_list_item( list, titleindex );
2754 if (title == NULL) return FALSE; // Bad titleindex
2755 tinfo->width = title->width;
2756 tinfo->height = title->height;
2757 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2758 // Don't allow crop to 0
2759 if (title->crop[0] + title->crop[1] >= title->height)
2760 title->crop[0] = title->crop[1] = 0;
2761 if (title->crop[2] + title->crop[3] >= title->width)
2762 title->crop[2] = title->crop[3] = 0;
2763 tinfo->num_chapters = hb_list_count(title->list_chapter);
2764 tinfo->rate_base = title->rate_base;
2765 tinfo->rate = title->rate;
2766 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2767 title->width * title->pixel_aspect_width,
2768 title->height * title->pixel_aspect_height);
2769 tinfo->hours = title->hours;
2770 tinfo->minutes = title->minutes;
2771 tinfo->seconds = title->seconds;
2772 tinfo->duration = title->duration;
2774 tinfo->angle_count = title->angle_count;
2779 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2781 hb_audio_config_t *audio;
2783 audio = get_hb_audio(titleindex, audioindex);
2784 if (audio == NULL) return FALSE; // Bad audioindex
2785 ainfo->codec = audio->in.codec;
2786 ainfo->bitrate = audio->in.bitrate;
2787 ainfo->samplerate = audio->in.samplerate;
2792 ghb_audio_is_passthru(gint acodec)
2794 g_debug("ghb_audio_is_passthru () \n");
2795 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
2799 ghb_get_default_acodec()
2801 return HB_ACODEC_FAAC;
2805 picture_settings_deps(signal_user_data_t *ud)
2807 gboolean autoscale, keep_aspect, enable_keep_aspect;
2808 gboolean enable_scale_width, enable_scale_height;
2809 gboolean enable_disp_width, enable_disp_height, enable_par;
2813 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2816 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
2817 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
2818 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
2820 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
2821 if (!enable_keep_aspect)
2823 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
2825 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2826 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2828 enable_scale_width = !autoscale && (pic_par != 1);
2829 enable_scale_height = !autoscale && (pic_par != 1);
2830 enable_disp_width = (pic_par == 3) && !keep_aspect;
2831 enable_par = (pic_par == 3) && !keep_aspect;
2832 enable_disp_height = FALSE;
2834 widget = GHB_WIDGET(ud->builder, "PictureModulus");
2835 gtk_widget_set_sensitive(widget, pic_par != 1);
2836 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
2837 gtk_widget_set_sensitive(widget, pic_par != 1);
2838 widget = GHB_WIDGET(ud->builder, "scale_width");
2839 gtk_widget_set_sensitive(widget, enable_scale_width);
2840 widget = GHB_WIDGET(ud->builder, "scale_height");
2841 gtk_widget_set_sensitive(widget, enable_scale_height);
2842 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
2843 gtk_widget_set_sensitive(widget, enable_disp_width);
2844 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
2845 gtk_widget_set_sensitive(widget, enable_disp_height);
2846 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
2847 gtk_widget_set_sensitive(widget, enable_par);
2848 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
2849 gtk_widget_set_sensitive(widget, enable_par);
2850 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
2851 gtk_widget_set_sensitive(widget, enable_keep_aspect);
2852 widget = GHB_WIDGET(ud->builder, "autoscale");
2853 gtk_widget_set_sensitive(widget, pic_par != 1);
2857 ghb_set_scale(signal_user_data_t *ud, gint mode)
2862 gboolean keep_aspect;
2864 gboolean autocrop, autoscale, noscale;
2865 gint crop[4], width, height, par_width, par_height;
2866 gint crop_width, crop_height;
2867 gint aspect_n, aspect_d;
2868 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
2869 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
2874 gint max_height = 0;
2875 static gboolean busy = FALSE;
2877 g_debug("ghb_set_scale ()\n");
2878 if (h_scan == NULL) return;
2879 list = hb_get_titles( h_scan );
2880 if( !hb_list_count( list ) )
2882 /* No valid title, stop right there */
2887 titleindex = ghb_settings_combo_int(ud->settings, "title");
2888 title = hb_list_item( list, titleindex );
2889 if (title == NULL) return;
2891 if (job == NULL) return;
2893 picture_settings_deps(ud);
2898 // First configure widgets
2899 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
2900 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
2901 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
2902 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
2903 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2904 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2905 // alignment constraints rather than scaling to satisfy them.
2906 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
2907 // Align dimensions to either 16 or 2 pixels
2908 // The scaler crashes if the dimensions are not divisible by 2
2909 // x264 also will not accept dims that are not multiple of 2
2913 keep_height = FALSE;
2915 // Step needs to be at least 2 because odd widths cause scaler crash
2917 widget = GHB_WIDGET (ud->builder, "scale_width");
2918 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2919 widget = GHB_WIDGET (ud->builder, "scale_height");
2920 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2923 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2924 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2925 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2926 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2927 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2928 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2929 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2930 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2934 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
2935 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2936 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
2937 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2938 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
2939 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2940 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
2941 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
2943 ghb_title_info_t tinfo;
2944 ghb_get_title_info (&tinfo, titleindex);
2947 crop[0] = tinfo.crop[0];
2948 crop[1] = tinfo.crop[1];
2949 crop[2] = tinfo.crop[2];
2950 crop[3] = tinfo.crop[3];
2951 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2952 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2953 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2954 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2958 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
2959 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
2960 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
2961 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
2967 // Adjust the cropping to accomplish the desired width and height
2968 crop_width = tinfo.width - crop[2] - crop[3];
2969 crop_height = tinfo.height - crop[0] - crop[1];
2970 width = MOD_DOWN(crop_width, mod);
2971 height = MOD_DOWN(crop_height, mod);
2973 need1 = (crop_height - height) / 2;
2974 need2 = crop_height - height - need1;
2977 need1 = (crop_width - width) / 2;
2978 need2 = crop_width - width - need1;
2981 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
2982 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
2983 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
2984 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
2986 hb_reduce(&aspect_n, &aspect_d,
2987 title->width * title->pixel_aspect_width,
2988 title->height * title->pixel_aspect_height);
2989 crop_width = title->width - crop[2] - crop[3];
2990 crop_height = title->height - crop[0] - crop[1];
2994 height = crop_height;
2998 width = ghb_settings_get_int(ud->settings, "scale_width");
2999 height = ghb_settings_get_int(ud->settings, "scale_height");
3000 max_width = MOD_DOWN(
3001 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3002 max_height = MOD_DOWN(
3003 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3005 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3008 width = title->width - crop[2] - crop[3];
3010 height = title->height - crop[0] - crop[1];
3012 width = MOD_ROUND(width, mod);
3013 height = MOD_ROUND(height, mod);
3015 // Adjust dims according to max values
3017 height = MIN(height, max_height);
3019 width = MIN(width, max_width);
3023 job->anamorphic.mode = pic_par;
3024 // The scaler crashes if the dimensions are not divisible by 2
3025 // Align mod 2. And so does something in x264_encoder_headers()
3026 job->anamorphic.modulus = mod;
3027 job->anamorphic.par_width = title->pixel_aspect_width;
3028 job->anamorphic.par_height = title->pixel_aspect_height;
3029 job->anamorphic.dar_width = 0;
3030 job->anamorphic.dar_height = 0;
3032 if (keep_height && pic_par == 2)
3033 width = ((double)height * crop_width / crop_height) + 0.5;
3035 job->height = height;
3037 job->maxWidth = max_width;
3039 job->maxHeight = max_height;
3040 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3041 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3042 if (job->anamorphic.mode == 3 && !keep_aspect)
3044 job->anamorphic.keep_display_aspect = 0;
3045 if (mode & GHB_PIC_KEEP_PAR)
3047 job->anamorphic.par_width =
3048 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3049 job->anamorphic.par_height =
3050 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3054 job->anamorphic.dar_width =
3055 ghb_settings_get_int(ud->settings,
3056 "PictureDisplayWidth");
3057 job->anamorphic.dar_height =
3058 ghb_settings_get_int(ud->settings,
3059 "PictureDisplayHeight");
3064 job->anamorphic.keep_display_aspect = 1;
3066 hb_set_anamorphic_size( job, &width, &height,
3067 &par_width, &par_height );
3068 if (job->anamorphic.mode == 3 && !keep_aspect &&
3069 mode & GHB_PIC_KEEP_PAR)
3071 // hb_set_anamorphic_size reduces the par, which we
3072 // don't want in this case because the user is
3073 // explicitely specifying it.
3074 par_width = ghb_settings_get_int(ud->settings,
3076 par_height = ghb_settings_get_int(ud->settings,
3077 "PicturePARHeight");
3082 job->anamorphic.mode = pic_par;
3086 gint new_width, new_height;
3088 // Compute pixel aspect ration.
3089 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3090 // Must scale so that par becomes 1:1
3091 // Try to keep largest dimension
3092 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3093 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3095 if (max_width && new_width > max_width)
3097 height = new_height;
3099 else if (max_height && new_height > max_height)
3103 else if (keep_width)
3105 height = new_height;
3107 else if (keep_height)
3111 else if (width > new_width)
3113 height = new_height;
3119 g_debug("new w %d h %d\n", width, height);
3121 width = MOD_ROUND(width, mod);
3122 height = MOD_ROUND(height, mod);
3124 height = MIN(height, max_height);
3126 width = MIN(width, max_width);
3127 par_width = par_height = 1;
3129 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3130 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3132 gint disp_width, dar_width, dar_height;
3135 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3136 hb_reduce(&dar_width, &dar_height, disp_width, height);
3138 gint iaspect = dar_width * 9 / dar_height;
3139 if (dar_width > 2 * dar_height)
3141 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3143 else if (iaspect <= 16 && iaspect >= 15)
3145 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3147 else if (iaspect <= 12 && iaspect >= 11)
3149 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3153 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3155 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3157 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3158 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3159 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3160 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3165 set_preview_job_settings(hb_job_t *job, GValue *settings)
3167 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3168 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3169 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3170 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3172 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3173 job->anamorphic.modulus =
3174 ghb_settings_combo_int(settings, "PictureModulus");
3175 job->width = ghb_settings_get_int(settings, "scale_width");
3176 job->height = ghb_settings_get_int(settings, "scale_height");
3177 if (ghb_settings_get_boolean(settings, "show_crop"))
3179 gdouble xscale = (gdouble)job->width /
3180 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3181 gdouble yscale = (gdouble)job->height /
3182 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3184 job->width += xscale * (job->crop[2] + job->crop[3]);
3185 job->height += yscale * (job->crop[0] + job->crop[1]);
3190 job->anamorphic.modulus = 2;
3193 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3194 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3195 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
3197 gboolean keep_aspect;
3198 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3199 if (job->anamorphic.mode)
3201 job->anamorphic.par_width = job->title->pixel_aspect_width;
3202 job->anamorphic.par_height = job->title->pixel_aspect_height;
3203 job->anamorphic.dar_width = 0;
3204 job->anamorphic.dar_height = 0;
3206 if (job->anamorphic.mode == 3 && !keep_aspect)
3208 job->anamorphic.keep_display_aspect = 0;
3209 job->anamorphic.par_width =
3210 ghb_settings_get_int(settings, "PicturePARWidth");
3211 job->anamorphic.par_height =
3212 ghb_settings_get_int(settings, "PicturePARHeight");
3216 job->anamorphic.keep_display_aspect = 1;
3222 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3229 if (h_scan == NULL) return 1500;
3230 list = hb_get_titles( h_scan );
3231 title = hb_list_item( list, titleindex );
3232 if (title == NULL) return 1500;
3234 if (job == NULL) return 1500;
3235 size = ghb_settings_get_int(settings, "VideoTargetSize");
3236 return hb_calc_bitrate( job, size );
3240 ghb_validate_filter_string(const gchar *str, gint max_fields)
3246 if (str == NULL || *str == 0) return TRUE;
3249 val = g_strtod(str, &end);
3251 { // Found a numeric value
3253 // negative max_fields means infinate
3254 if (max_fields >= 0 && fields > max_fields) return FALSE;
3268 ghb_validate_filters(signal_user_data_t *ud)
3275 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3278 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3279 if (!ghb_validate_filter_string(str, 4))
3281 message = g_strdup_printf(
3282 "Invalid Deinterlace Settings:\n\n%s\n",
3284 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3292 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3295 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3296 if (!ghb_validate_filter_string(str, 6))
3298 message = g_strdup_printf(
3299 "Invalid Detelecine Settings:\n\n%s\n",
3301 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3309 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3312 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3313 if (!ghb_validate_filter_string(str, 7))
3315 message = g_strdup_printf(
3316 "Invalid Decomb Settings:\n\n%s\n",
3318 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3326 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3329 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3330 if (!ghb_validate_filter_string(str, 4))
3332 message = g_strdup_printf(
3333 "Invalid Denoise Settings:\n\n%s\n",
3335 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3346 ghb_validate_video(signal_user_data_t *ud)
3351 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3352 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3353 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
3354 (vcodec == HB_VCODEC_THEORA))
3356 // mp4|avi/theora combination is not supported.
3357 message = g_strdup_printf(
3358 "Theora is not supported in the MP4 and AVI containers.\n\n"
3359 "You should choose a different video codec or container.\n"
3360 "If you continue, FFMPEG will be chosen for you.");
3361 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3367 vcodec = HB_VCODEC_FFMPEG;
3368 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3374 ghb_validate_subtitles(signal_user_data_t *ud)
3380 if (h_scan == NULL) return FALSE;
3381 list = hb_get_titles( h_scan );
3382 if( !hb_list_count( list ) )
3384 /* No valid title, stop right there */
3385 g_message("No title found.\n");
3391 titleindex = ghb_settings_combo_int(ud->settings, "title");
3392 title = hb_list_item( list, titleindex );
3393 if (title == NULL) return FALSE;
3394 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3396 const GValue *slist, *settings;
3397 gint count, ii, track, source;
3398 gboolean burned, one_burned = FALSE;
3400 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3401 count = ghb_array_len(slist);
3402 for (ii = 0; ii < count; ii++)
3404 settings = ghb_array_get_nth(slist, ii);
3405 track = ghb_settings_combo_int(settings, "SubtitleTrack");
3406 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3407 source = ghb_subtitle_track_source(ud, track);
3408 if (burned && one_burned)
3410 // MP4 can only handle burned vobsubs. make sure there isn't
3411 // already something burned in the list
3412 message = g_strdup_printf(
3413 "Only one subtitle may be burned into the video.\n\n"
3414 "You should change your subtitle selections.\n"
3415 "If you continue, some subtitles will be lost.");
3416 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3428 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3430 // MP4 can only handle burned vobsubs. make sure there isn't
3431 // already something burned in the list
3432 message = g_strdup_printf(
3433 "Your chosen container does not support soft bitmap subtitles.\n\n"
3434 "You should change your subtitle selections.\n"
3435 "If you continue, some subtitles will be lost.");
3436 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3449 ghb_validate_audio(signal_user_data_t *ud)
3456 if (h_scan == NULL) return FALSE;
3457 list = hb_get_titles( h_scan );
3458 if( !hb_list_count( list ) )
3460 /* No valid title, stop right there */
3461 g_message("No title found.\n");
3467 titleindex = ghb_settings_combo_int(ud->settings, "title");
3468 title = hb_list_item( list, titleindex );
3469 if (title == NULL) return FALSE;
3470 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3472 const GValue *audio_list;
3475 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3476 count = ghb_array_len(audio_list);
3477 for (ii = 0; ii < count; ii++)
3480 hb_audio_config_t *taudio;
3482 asettings = ghb_array_get_nth(audio_list, ii);
3483 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
3484 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3485 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3486 title->list_audio, track );
3487 if (!(taudio->in.codec & codec) &&
3488 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
3490 // Not supported. AC3 is passthrough only, so input must be AC3
3491 message = g_strdup_printf(
3492 "The source does not support Pass-Thru.\n\n"
3493 "You should choose a different audio codec.\n"
3494 "If you continue, one will be chosen for you.");
3495 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3501 if (mux == HB_MUX_AVI)
3503 codec = HB_ACODEC_LAME;
3507 codec = HB_ACODEC_FAAC;
3509 value = get_acodec_value(codec);
3510 ghb_settings_take_value(asettings, "AudioEncoder", value);
3512 gchar *a_unsup = NULL;
3513 gchar *mux_s = NULL;
3514 if (mux == HB_MUX_MP4)
3517 // mp4/mp3|vorbis combination is not supported.
3518 if (codec == HB_ACODEC_LAME)
3521 codec = HB_ACODEC_FAAC;
3523 if (codec == HB_ACODEC_VORBIS)
3526 codec = HB_ACODEC_FAAC;
3528 if (codec == HB_ACODEC_DCA)
3531 codec = HB_ACODEC_FAAC;
3534 else if (mux == HB_MUX_AVI)
3537 // avi/faac|vorbis combination is not supported.
3538 if (codec == HB_ACODEC_FAAC)
3541 codec = HB_ACODEC_LAME;
3543 if (codec == HB_ACODEC_VORBIS)
3546 codec = HB_ACODEC_LAME;
3549 else if (mux == HB_MUX_OGM)
3552 // avi/faac|vorbis combination is not supported.
3553 if (codec == HB_ACODEC_FAAC)
3556 codec = HB_ACODEC_VORBIS;
3558 if (codec == HB_ACODEC_AC3)
3561 codec = HB_ACODEC_VORBIS;
3563 if (codec == HB_ACODEC_DCA)
3566 codec = HB_ACODEC_VORBIS;
3571 message = g_strdup_printf(
3572 "%s is not supported in the %s container.\n\n"
3573 "You should choose a different audio codec.\n"
3574 "If you continue, one will be chosen for you.", a_unsup, mux_s);
3575 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3581 value = get_acodec_value(codec);
3582 ghb_settings_take_value(asettings, "AudioEncoder", value);
3584 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
3585 gboolean allow_mono = TRUE;
3586 gboolean allow_stereo = TRUE;
3587 gboolean allow_dolby = TRUE;
3588 gboolean allow_dpl2 = TRUE;
3589 gboolean allow_6ch = TRUE;
3591 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3592 (codec != HB_ACODEC_LAME);
3593 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
3595 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
3597 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
3598 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
3599 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
3600 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
3602 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
3603 (codec != HB_ACODEC_LAME) &&
3604 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
3605 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
3607 gchar *mix_unsup = NULL;
3608 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
3612 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
3614 mix_unsup = "stereo";
3616 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
3618 mix_unsup = "Dolby";
3620 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
3622 mix_unsup = "Dolby Pro Logic II";
3624 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
3626 mix_unsup = "6 Channel";
3630 message = g_strdup_printf(
3631 "The source audio does not support %s mixdown.\n\n"
3632 "You should choose a different mixdown.\n"
3633 "If you continue, one will be chosen for you.", mix_unsup);
3634 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3640 mix = ghb_get_best_mix(titleindex, track, codec, mix);
3641 value = get_amix_value(mix);
3642 ghb_settings_take_value(asettings, "AudioMixdown", value);
3649 ghb_validate_vquality(GValue *settings)
3655 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
3656 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
3658 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
3659 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
3663 case HB_VCODEC_X264:
3669 case HB_VCODEC_FFMPEG:
3675 case HB_VCODEC_THEORA:
3687 if (vquality < min || vquality > max)
3689 message = g_strdup_printf(
3690 "Interesting video quality choise: %d\n\n"
3691 "Typical values range from %d to %d.\n"
3692 "Are you sure you wish to use this setting?",
3693 (gint)vquality, min, max);
3694 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
3695 "Cancel", "Continue"))
3707 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
3712 static gchar *x264opts;
3714 gboolean tweaks = FALSE;
3715 gchar *detel_str = NULL;
3716 gchar *decomb_str = NULL;
3717 gchar *deint_str = NULL;
3718 gchar *deblock_str = NULL;
3719 gchar *denoise_str = NULL;
3720 gchar *dest_str = NULL;
3722 g_debug("add_job()\n");
3723 if (h == NULL) return;
3724 list = hb_get_titles( h );
3725 if( !hb_list_count( list ) )
3727 /* No valid title, stop right there */
3731 title = hb_list_item( list, titleindex );
3732 if (title == NULL) return;
3734 /* Set job settings */
3736 if (job == NULL) return;
3738 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
3739 if (job->start_at_preview)
3741 job->seek_points = ghb_settings_get_int(js, "preview_count");
3742 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
3745 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
3746 job->mux = ghb_settings_combo_int(js, "FileFormat");
3747 if (job->mux == HB_MUX_MP4)
3749 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
3750 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
3754 job->largeFileSize = FALSE;
3755 job->mp4_optimize = FALSE;
3757 if (!job->start_at_preview)
3759 gint chapter_start, chapter_end;
3760 chapter_start = ghb_settings_get_int(js, "start_chapter");
3761 chapter_end = ghb_settings_get_int(js, "end_chapter");
3762 gint num_chapters = hb_list_count(title->list_chapter);
3763 job->chapter_start = MIN( num_chapters, chapter_start );
3764 job->chapter_end = MAX( job->chapter_start, chapter_end );
3766 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
3767 if (job->chapter_start == job->chapter_end)
3768 job->chapter_markers = 0;
3769 if ( job->chapter_markers )
3776 chapters = ghb_settings_get_value(js, "chapter_list");
3777 count = ghb_array_len(chapters);
3778 for(chap = chapter_start; chap <= chapter_end; chap++)
3780 hb_chapter_t * chapter_s;
3786 chapter = ghb_array_get_nth(chapters, chap-1);
3787 name = ghb_value_string(chapter);
3791 name = g_strdup_printf ("Chapter %2d", chap);
3793 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
3794 strncpy(chapter_s->title, name, 1023);
3795 chapter_s->title[1023] = '\0';
3800 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
3801 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
3802 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
3803 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
3806 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
3807 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
3809 job->deinterlace = (deint != 0) ? 1 : 0;
3811 job->deinterlace = 0;
3812 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
3814 gboolean keep_aspect;
3815 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
3816 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
3817 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
3818 if (job->anamorphic.mode)
3820 job->anamorphic.par_width = title->pixel_aspect_width;
3821 job->anamorphic.par_height = title->pixel_aspect_height;
3822 job->anamorphic.dar_width = 0;
3823 job->anamorphic.dar_height = 0;
3825 if (job->anamorphic.mode == 3 && !keep_aspect)
3827 job->anamorphic.keep_display_aspect = 0;
3828 job->anamorphic.par_width =
3829 ghb_settings_get_int(js, "PicturePARWidth");
3830 job->anamorphic.par_height =
3831 ghb_settings_get_int(js, "PicturePARHeight");
3835 job->anamorphic.keep_display_aspect = 1;
3839 /* Add selected filters */
3840 job->filters = hb_list_init();
3841 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
3846 if (detel_opts.map[detel].svalue != NULL)
3847 detel_str = g_strdup(detel_opts.map[detel].svalue);
3850 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
3851 hb_filter_detelecine.settings = detel_str;
3852 hb_list_add( job->filters, &hb_filter_detelecine );
3858 if (decomb_opts.map[decomb].svalue != NULL)
3859 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
3862 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
3863 hb_filter_decomb.settings = decomb_str;
3864 hb_list_add( job->filters, &hb_filter_decomb );
3866 if( job->deinterlace )
3870 if (deint_opts.map[deint].svalue != NULL)
3871 deint_str = g_strdup(deint_opts.map[deint].svalue);
3874 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
3875 hb_filter_deinterlace.settings = deint_str;
3876 hb_list_add( job->filters, &hb_filter_deinterlace );
3878 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
3881 deblock_str = g_strdup_printf("%d", deblock);
3882 hb_filter_deblock.settings = deblock_str;
3883 hb_list_add( job->filters, &hb_filter_deblock );
3885 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
3890 if (denoise_opts.map[denoise].svalue != NULL)
3891 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
3894 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
3895 hb_filter_denoise.settings = denoise_str;
3896 hb_list_add( job->filters, &hb_filter_denoise );
3898 job->width = ghb_settings_get_int(js, "scale_width");
3899 job->height = ghb_settings_get_int(js, "scale_height");
3901 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
3902 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3903 (job->vcodec == HB_VCODEC_THEORA))
3905 // mp4|avi/theora combination is not supported.
3906 job->vcodec = HB_VCODEC_FFMPEG;
3908 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3910 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
3912 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3915 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
3916 job->vquality = vquality;
3919 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3921 job->vquality = -1.0;
3922 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
3925 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
3928 job->vrate = title->rate;
3929 job->vrate_base = title->rate_base;
3934 job->vrate = 27000000;
3935 job->vrate_base = vrate;
3939 // AVI container does not support variable frame rate.
3940 // OGM supports variable frame rate, but bases all timing on
3941 // DTS, which breaks when b-frames are used since it is
3942 // impossible to reconstruct PTS from DTS when the framerate
3944 if (job->mux == HB_MUX_AVI || job->mux == HB_MUX_OGM)
3949 const GValue *audio_list;
3953 audio_list = ghb_settings_get_value(js, "audio_list");
3954 count = ghb_array_len(audio_list);
3955 for (ii = 0; ii < count; ii++)
3958 hb_audio_config_t audio;
3959 hb_audio_config_t *taudio;
3961 hb_audio_config_init(&audio);
3962 asettings = ghb_array_get_nth(audio_list, ii);
3963 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
3964 audio.out.track = tcount;
3965 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
3966 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
3967 title->list_audio, audio.in.track );
3968 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
3970 if (!(taudio->in.codec & audio.out.codec))
3972 // Not supported. AC3 is passthrough only, so input must be AC3
3973 if (job->mux == HB_MUX_AVI)
3975 audio.out.codec = HB_ACODEC_LAME;
3979 audio.out.codec = HB_ACODEC_FAAC;
3984 audio.out.codec &= taudio->in.codec;
3987 if ((job->mux == HB_MUX_MP4) &&
3988 ((audio.out.codec == HB_ACODEC_LAME) ||
3989 (audio.out.codec == HB_ACODEC_VORBIS)))
3991 // mp4/mp3|vorbis combination is not supported.
3992 audio.out.codec = HB_ACODEC_FAAC;
3994 if ((job->mux == HB_MUX_AVI) &&
3995 ((audio.out.codec == HB_ACODEC_FAAC) ||
3996 (audio.out.codec == HB_ACODEC_VORBIS)))
3998 // avi/faac|vorbis combination is not supported.
3999 audio.out.codec = HB_ACODEC_LAME;
4001 if ((job->mux == HB_MUX_OGM) &&
4002 ((audio.out.codec == HB_ACODEC_FAAC) ||
4003 (audio.out.codec == HB_ACODEC_AC3) ||
4004 (audio.out.codec == HB_ACODEC_DCA)))
4006 // ogm/faac|ac3 combination is not supported.
4007 audio.out.codec = HB_ACODEC_VORBIS;
4009 audio.out.dynamic_range_compression =
4010 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4011 if (audio.out.dynamic_range_compression < 1.0)
4012 audio.out.dynamic_range_compression = 0.0;
4014 // It would be better if this were done in libhb for us, but its not yet.
4015 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
4017 audio.out.mixdown = 0;
4021 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4022 // Make sure the mixdown is valid and pick a new one if not.
4023 audio.out.mixdown = ghb_get_best_mix(titleindex,
4024 audio.in.track, audio.out.codec, audio.out.mixdown);
4026 ghb_settings_combo_int(asettings, "AudioBitrate");
4027 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4028 if (srate == 0) // 0 is same as source
4029 audio.out.samplerate = taudio->in.samplerate;
4031 audio.out.samplerate = srate;
4034 // Add it to the jobs audio list
4035 hb_audio_add( job, &audio );
4038 // I was tempted to move this up with the reset of the video quality
4039 // settings, but I suspect the settings above need to be made
4040 // first in order for hb_calc_bitrate to be accurate.
4041 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4045 size = ghb_settings_get_int(js, "VideoTargetSize");
4046 job->vbitrate = hb_calc_bitrate( job, size );
4047 job->vquality = -1.0;
4050 dest_str = ghb_settings_get_string(js, "destination");
4051 job->file = dest_str;
4052 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
4054 const GValue *subtitle_list;
4056 gboolean force, burned, def, one_burned = FALSE;
4058 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4059 count = ghb_array_len(subtitle_list);
4060 for (ii = 0; ii < count; ii++)
4064 ssettings = ghb_array_get_nth(subtitle_list, ii);
4066 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4067 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4068 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4069 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4073 if (!burned && job->mux == HB_MUX_MKV)
4075 job->select_subtitle_config.dest = PASSTHRUSUB;
4077 else if (!burned && job->mux == HB_MUX_MP4)
4079 // Skip any non-burned vobsubs when output is mp4
4084 // Only allow one subtitle to be burned into the video
4087 job->select_subtitle_config.dest = RENDERSUB;
4090 job->select_subtitle_config.force = force;
4091 job->select_subtitle_config.default_track = def;
4092 job->indepth_scan = 1;
4094 else if (subtitle >= 0)
4096 hb_subtitle_t * subt;
4097 hb_subtitle_config_t sub_config;
4099 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4100 sub_config = subt->config;
4103 if (!burned && job->mux == HB_MUX_MKV &&
4104 subt->format == PICTURESUB)
4106 sub_config.dest = PASSTHRUSUB;
4108 else if (!burned && job->mux == HB_MUX_MP4 &&
4109 subt->format == PICTURESUB)
4111 // Skip any non-burned vobsubs when output is mp4
4114 else if ( burned && subt->format == PICTURESUB )
4116 // Only allow one subtitle to be burned into the video
4121 sub_config.force = force;
4122 sub_config.default_track = def;
4123 hb_subtitle_add( job, &sub_config, subtitle );
4128 // TODO: libhb holds onto a reference to the x264opts and is not
4129 // finished with it until encoding the job is done. But I can't
4130 // find a way to get at the job before it is removed in order to
4131 // free up the memory I am allocating here.
4132 // The short story is THIS LEAKS.
4133 x264opts = ghb_build_x264opts_string(js);
4135 if( *x264opts == '\0' )
4141 if (job->indepth_scan == 1)
4143 // Subtitle scan. Look for subtitle matching audio language
4146 * When subtitle scan is enabled do a fast pre-scan job
4147 * which will determine which subtitles to enable, if any.
4150 job->indepth_scan = 1;
4151 job->x264opts = NULL;
4154 * Add the pre-scan job
4156 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4160 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4161 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4164 * If subtitle_scan is enabled then only turn it on
4165 * for the second pass and then off again for the
4169 job->indepth_scan = 0;
4172 * If turbo options have been selected then append them
4173 * to the x264opts now (size includes one ':' and the '\0')
4175 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4177 gchar *tmp_x264opts;
4181 badapt = ghb_lookup_badapt(x264opts);
4184 extra_opts = g_strdup_printf("%s", turbo_opts);
4188 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4193 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4198 * No x264opts to modify, but apply the turbo options
4199 * anyway as they may be modifying defaults
4201 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4205 job->x264opts = tmp_x264opts;
4209 job->x264opts = x264opts;
4211 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4213 //if (job->x264opts != NULL)
4214 // g_free(job->x264opts);
4218 * On the second pass we turn off subtitle scan so that we
4219 * can actually encode using any subtitles that were auto
4220 * selected in the first pass (using the whacky select-subtitle
4221 * attribute of the job).
4223 job->indepth_scan = 0;
4224 job->x264opts = x264opts;
4225 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4227 //if (job->x264opts != NULL)
4228 // g_free(job->x264opts);
4232 job->x264opts = x264opts;
4233 job->indepth_scan = 0;
4235 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4237 //if (job->x264opts != NULL)
4238 // g_free(job->x264opts);
4241 // clean up audio list
4242 gint num_audio_tracks = hb_list_count(job->list_audio);
4243 for(ii = 0; ii < num_audio_tracks; ii++)
4245 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4246 hb_list_rem(job->list_audio, audio);
4250 // clean up subtitle list
4251 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4252 for(ii = 0; ii < num_subtitle_tracks; ii++)
4254 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4255 hb_list_rem(job->list_subtitle, subtitle);
4259 if (detel_str) g_free(detel_str);
4260 if (decomb_str) g_free(decomb_str);
4261 if (deint_str) g_free(deint_str);
4262 if (deblock_str) g_free(deblock_str);
4263 if (denoise_str) g_free(denoise_str);
4264 if (dest_str) g_free(dest_str);
4268 ghb_add_job(GValue *js, gint unique_id)
4270 // Since I'm doing a scan of the single title I want just prior
4271 // to adding the job, there is only the one title to choose from.
4272 add_job(h_queue, js, unique_id, 0);
4276 ghb_add_live_job(GValue *js, gint unique_id)
4278 // Since I'm doing a scan of the single title I want just prior
4279 // to adding the job, there is only the one title to choose from.
4280 gint titleindex = ghb_settings_combo_int(js, "title");
4281 add_job(h_scan, js, unique_id, titleindex);
4285 ghb_remove_job(gint unique_id)
4290 // Multiples passes all get the same id
4292 // Go backwards through list, so reordering doesn't screw me.
4293 ii = hb_count(h_queue) - 1;
4294 while ((job = hb_job(h_queue, ii--)) != NULL)
4296 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4297 hb_rem(h_queue, job);
4304 hb_start( h_queue );
4314 ghb_start_live_encode()
4320 ghb_stop_live_encode()
4329 hb_get_state2( h_queue, &s );
4331 if( s.state == HB_STATE_PAUSED )
4333 hb_resume( h_queue );
4337 hb_pause( h_queue );
4352 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4355 gint channels = gdk_pixbuf_get_n_channels (pb);
4356 gint stride = gdk_pixbuf_get_rowstride (pb);
4358 for (jj = 0; jj < width; jj++)
4360 dst = pixels + y * stride + (x+jj) * channels;
4361 for (ii = 0; ii < len; ii++)
4382 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4385 gint channels = gdk_pixbuf_get_n_channels (pb);
4386 gint stride = gdk_pixbuf_get_rowstride (pb);
4388 for (jj = 0; jj < width; jj++)
4390 dst = pixels + (y+jj) * stride + x * channels;
4391 for (ii = 0; ii < len; ii++)
4412 gint line_width = 8;
4419 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4424 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4426 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4432 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4434 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4440 ghb_get_preview_image(
4443 signal_user_data_t *ud,
4451 settings = ud->settings;
4452 list = hb_get_titles( h_scan );
4453 if( !hb_list_count( list ) )
4455 /* No valid title, stop right there */
4458 title = hb_list_item( list, titleindex );
4459 if (title == NULL) return NULL;
4460 if (title->job == NULL) return NULL;
4461 set_preview_job_settings(title->job, settings);
4463 // hb_get_preview doesn't compensate for anamorphic, so lets
4464 // calculate scale factors
4465 gint width, height, par_width = 1, par_height = 1;
4466 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
4469 hb_set_anamorphic_size( title->job, &width, &height,
4470 &par_width, &par_height );
4473 // Make sure we have a big enough buffer to receive the image from libhb
4474 gint dstWidth = title->job->width;
4475 gint dstHeight= title->job->height;
4477 static guint8 *buffer = NULL;
4478 static gint bufferSize = 0;
4481 newSize = dstWidth * dstHeight * 4;
4482 if( bufferSize < newSize )
4484 bufferSize = newSize;
4485 buffer = (guint8*) g_realloc( buffer, bufferSize );
4487 hb_get_preview( h_scan, title, index, buffer );
4489 // Create an GdkPixbuf and copy the libhb image into it, converting it from
4490 // libhb's format something suitable.
4492 // The image data returned by hb_get_preview is 4 bytes per pixel,
4493 // BGRA format. Alpha is ignored.
4495 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
4496 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
4498 guint32 *src = (guint32*)buffer;
4499 guint8 *dst = pixels;
4502 gint channels = gdk_pixbuf_get_n_channels (preview);
4503 gint stride = gdk_pixbuf_get_rowstride (preview);
4506 for (ii = 0; ii < dstHeight; ii++)
4509 for (jj = 0; jj < dstWidth; jj++)
4511 tmp[0] = src[0] >> 16;
4512 tmp[1] = src[0] >> 8;
4513 tmp[2] = src[0] >> 0;
4519 gint w = ghb_settings_get_int(settings, "scale_width");
4520 gint h = ghb_settings_get_int(settings, "scale_height");
4521 ghb_par_scale(ud, &w, &h, par_width, par_height);
4523 gint c0, c1, c2, c3;
4524 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
4525 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
4526 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
4527 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
4529 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
4530 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
4532 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
4535 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
4539 gint orig_w, orig_h;
4542 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
4546 ss = gdk_screen_get_default();
4547 s_w = gdk_screen_get_width(ss);
4548 s_h = gdk_screen_get_height(ss);
4552 if (dstWidth > s_w * factor / 100)
4554 dstWidth = s_w * factor / 100;
4555 dstHeight = dstHeight * dstWidth / orig_w;
4557 if (dstHeight > s_h * factor / 100)
4559 dstHeight = s_h * factor / 100;
4560 dstWidth = dstWidth * dstHeight / orig_h;
4562 xscale *= (gdouble)dstWidth / orig_w;
4563 yscale *= (gdouble)dstHeight / orig_h;
4564 w *= (gdouble)dstWidth / orig_w;
4565 h *= (gdouble)dstHeight / orig_h;
4567 GdkPixbuf *scaled_preview;
4568 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
4569 if (ghb_settings_get_boolean(settings, "show_crop"))
4576 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
4578 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
4580 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
4582 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
4584 g_object_unref (preview);
4585 return scaled_preview;
4589 sanitize_volname(gchar *name)
4614 ghb_dvd_volname(const gchar *device)
4617 name = hb_dvd_name((gchar*)device);
4618 if (name != NULL && name[0] != 0)
4620 name = g_strdup(name);
4621 sanitize_volname(name);