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 "audiohandler.h"
35 #include "x264handler.h"
43 const gchar *shortOpt;
54 static gchar **index_str = NULL;
55 static gint index_str_size = 0;
58 index_str_init(gint max_index)
62 if (max_index+1 > index_str_size)
64 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
65 for (ii = index_str_size; ii <= max_index; ii++)
67 index_str[ii] = g_strdup_printf("%d", ii);
69 index_str_size = max_index + 1;
73 static options_map_t d_point_to_point_opts[] =
75 {"Chapters:", "chapter", 0, "0"},
76 {"Seconds:", "time", 1, "1"},
77 {"Frames:", "frame", 2, "2"},
79 combo_opts_t point_to_point_opts =
81 sizeof(d_point_to_point_opts)/sizeof(options_map_t),
85 static options_map_t d_when_complete_opts[] =
87 {"Do Nothing", "nothing", 0, "0"},
88 {"Show Notification", "notify", 1, "1"},
89 {"Put Computer To Sleep", "sleep", 2, "2"},
90 {"Shutdown Computer", "shutdown", 3, "3"},
92 combo_opts_t when_complete_opts =
94 sizeof(d_when_complete_opts)/sizeof(options_map_t),
98 static options_map_t d_par_opts[] =
100 {"Off", "0", 0, "0"},
101 {"Strict", "1", 1, "1"},
102 {"Loose", "2", 2, "2"},
103 {"Custom", "3", 3, "3"},
105 combo_opts_t par_opts =
107 sizeof(d_par_opts)/sizeof(options_map_t),
111 static options_map_t d_alignment_opts[] =
116 {"16", "16", 16, "16"},
118 combo_opts_t alignment_opts =
120 sizeof(d_alignment_opts)/sizeof(options_map_t),
124 static options_map_t d_logging_opts[] =
130 combo_opts_t logging_opts =
132 sizeof(d_logging_opts)/sizeof(options_map_t),
136 static options_map_t d_log_longevity_opts[] =
138 {"Week", "week", 7, "7"},
139 {"Month", "month", 30, "30"},
140 {"Year", "year", 365, "365"},
141 {"Immortal", "immortal", 366, "366"},
143 combo_opts_t log_longevity_opts =
145 sizeof(d_log_longevity_opts)/sizeof(options_map_t),
149 static options_map_t d_appcast_update_opts[] =
151 {"Never", "never", 0, "never"},
152 {"Daily", "daily", 1, "daily"},
153 {"Weekly", "weekly", 2, "weekly"},
154 {"Monthly", "monthly", 3, "monthly"},
156 combo_opts_t appcast_update_opts =
158 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
159 d_appcast_update_opts
162 static options_map_t d_vqual_granularity_opts[] =
164 {"0.2", "0.2", 0.2, "0.2"},
165 {"0.25", "0.25", 0.25, "0.25"},
166 {"0.5", "0.5", 0.5, "0.5"},
169 combo_opts_t vqual_granularity_opts =
171 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
172 d_vqual_granularity_opts
175 static options_map_t d_container_opts[] =
177 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
178 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
180 combo_opts_t container_opts =
182 sizeof(d_container_opts)/sizeof(options_map_t),
186 static options_map_t d_detel_opts[] =
188 {"Off", "off", 0, ""},
189 {"Custom", "custom", 1, ""},
190 {"Default","default",2, NULL},
192 combo_opts_t detel_opts =
194 sizeof(d_detel_opts)/sizeof(options_map_t),
198 static options_map_t d_decomb_opts[] =
200 {"Off", "off", 0, ""},
201 {"Custom", "custom", 1, ""},
202 {"Default","default",2, NULL},
204 combo_opts_t decomb_opts =
206 sizeof(d_decomb_opts)/sizeof(options_map_t),
210 static options_map_t d_deint_opts[] =
212 {"Off", "off", 0, ""},
213 {"Custom", "custom", 1, ""},
214 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
215 {"Slow", "slow", 3, "2:-1:-1:0:1"},
216 {"Slower", "slower", 4, "0:-1:-1:0:1"},
218 combo_opts_t deint_opts =
220 sizeof(d_deint_opts)/sizeof(options_map_t),
224 static options_map_t d_denoise_opts[] =
226 {"Off", "off", 0, ""},
227 {"Custom", "custom", 1, ""},
228 {"Weak", "weak", 2, "2:1:2:3"},
229 {"Medium", "medium", 3, "3:2:2:3"},
230 {"Strong", "strong", 4, "7:7:5:5"},
232 combo_opts_t denoise_opts =
234 sizeof(d_denoise_opts)/sizeof(options_map_t),
238 static options_map_t d_vcodec_opts[] =
240 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
241 {"MPEG-4 (FFmpeg)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
242 {"VP3 (Theora)", "theora", HB_VCODEC_THEORA, ""},
244 combo_opts_t vcodec_opts =
246 sizeof(d_vcodec_opts)/sizeof(options_map_t),
250 static options_map_t d_acodec_opts[] =
252 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
253 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
254 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
255 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
256 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
257 {"Choose For Me", "auto", HB_ACODEC_MASK, "auto"},
259 combo_opts_t acodec_opts =
261 sizeof(d_acodec_opts)/sizeof(options_map_t),
265 static options_map_t d_direct_opts[] =
267 {"None", "none", 0, "none"},
268 {"Spatial", "spatial", 1, "spatial"},
269 {"Temporal", "temporal", 2, "temporal"},
270 {"Automatic", "auto", 3, "auto"},
272 combo_opts_t direct_opts =
274 sizeof(d_direct_opts)/sizeof(options_map_t),
278 static options_map_t d_badapt_opts[] =
280 {"Off", "0", 0, "0"},
281 {"Fast", "1", 1, "1"},
282 {"Optimal", "2", 2, "2"},
284 combo_opts_t badapt_opts =
286 sizeof(d_badapt_opts)/sizeof(options_map_t),
290 static options_map_t d_me_opts[] =
292 {"Diamond", "dia", 0, "dia"},
293 {"Hexagon", "hex", 1, "hex"},
294 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
295 {"Exhaustive", "esa", 3, "esa"},
296 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
298 combo_opts_t me_opts =
300 sizeof(d_me_opts)/sizeof(options_map_t),
304 static options_map_t d_subme_opts[] =
315 {"10", "10", 10, "10"},
317 combo_opts_t subme_opts =
319 sizeof(d_subme_opts)/sizeof(options_map_t),
323 static options_map_t d_analyse_opts[] =
325 {"Some", "some", 0, "some"},
326 {"None", "none", 1, "none"},
327 {"All", "all", 2, "all"},
328 {"Custom", "custom", 3, "all"},
330 combo_opts_t analyse_opts =
332 sizeof(d_analyse_opts)/sizeof(options_map_t),
336 static options_map_t d_trellis_opts[] =
338 {"Disabled", "0", 0, "0"},
339 {"Final Macro Block", "1", 1, "1"},
340 {"Always", "2", 2, "2"},
342 combo_opts_t trellis_opts =
344 sizeof(d_trellis_opts)/sizeof(options_map_t),
348 combo_opts_t subtitle_opts =
354 combo_opts_t title_opts =
360 combo_opts_t audio_track_opts =
372 combo_name_map_t combo_name_map[] =
374 {"PtoPType", &point_to_point_opts},
375 {"WhenComplete", &when_complete_opts},
376 {"PicturePAR", &par_opts},
377 {"PictureModulus", &alignment_opts},
378 {"LoggingLevel", &logging_opts},
379 {"LogLongevity", &log_longevity_opts},
380 {"check_updates", &appcast_update_opts},
381 {"VideoQualityGranularity", &vqual_granularity_opts},
382 {"FileFormat", &container_opts},
383 {"PictureDeinterlace", &deint_opts},
384 {"PictureDecomb", &decomb_opts},
385 {"PictureDetelecine", &detel_opts},
386 {"PictureDenoise", &denoise_opts},
387 {"VideoEncoder", &vcodec_opts},
388 {"AudioEncoder", &acodec_opts},
389 {"x264_direct", &direct_opts},
390 {"x264_b_adapt", &badapt_opts},
391 {"x264_me", &me_opts},
392 {"x264_subme", &subme_opts},
393 {"x264_analyse", &analyse_opts},
394 {"x264_trellis", &trellis_opts},
395 {"SubtitleTrack", &subtitle_opts},
396 {"title", &title_opts},
397 {"AudioTrack", &audio_track_opts},
401 const gchar *srt_codeset_table[] =
440 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
443 typedef struct iso639_lang_t
445 char * eng_name; /* Description in English */
446 char * native_name; /* Description in native language */
447 char * iso639_1; /* ISO-639-1 (2 characters) code */
448 char * iso639_2; /* ISO-639-2/t (3 character) code */
449 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
453 const iso639_lang_t ghb_language_table[] =
455 { "Any", "", "zz", "und" },
456 { "Afar", "", "aa", "aar" },
457 { "Abkhazian", "", "ab", "abk" },
458 { "Afrikaans", "", "af", "afr" },
459 { "Akan", "", "ak", "aka" },
460 { "Albanian", "", "sq", "sqi", "alb" },
461 { "Amharic", "", "am", "amh" },
462 { "Arabic", "", "ar", "ara" },
463 { "Aragonese", "", "an", "arg" },
464 { "Armenian", "", "hy", "hye", "arm" },
465 { "Assamese", "", "as", "asm" },
466 { "Avaric", "", "av", "ava" },
467 { "Avestan", "", "ae", "ave" },
468 { "Aymara", "", "ay", "aym" },
469 { "Azerbaijani", "", "az", "aze" },
470 { "Bashkir", "", "ba", "bak" },
471 { "Bambara", "", "bm", "bam" },
472 { "Basque", "", "eu", "eus", "baq" },
473 { "Belarusian", "", "be", "bel" },
474 { "Bengali", "", "bn", "ben" },
475 { "Bihari", "", "bh", "bih" },
476 { "Bislama", "", "bi", "bis" },
477 { "Bosnian", "", "bs", "bos" },
478 { "Breton", "", "br", "bre" },
479 { "Bulgarian", "", "bg", "bul" },
480 { "Burmese", "", "my", "mya", "bur" },
481 { "Catalan", "", "ca", "cat" },
482 { "Chamorro", "", "ch", "cha" },
483 { "Chechen", "", "ce", "che" },
484 { "Chinese", "", "zh", "zho", "chi" },
485 { "Church Slavic", "", "cu", "chu" },
486 { "Chuvash", "", "cv", "chv" },
487 { "Cornish", "", "kw", "cor" },
488 { "Corsican", "", "co", "cos" },
489 { "Cree", "", "cr", "cre" },
490 { "Czech", "", "cs", "ces", "cze" },
491 { "Danish", "Dansk", "da", "dan" },
492 { "German", "Deutsch", "de", "deu", "ger" },
493 { "Divehi", "", "dv", "div" },
494 { "Dzongkha", "", "dz", "dzo" },
495 { "English", "English", "en", "eng" },
496 { "Spanish", "Espanol", "es", "spa" },
497 { "Esperanto", "", "eo", "epo" },
498 { "Estonian", "", "et", "est" },
499 { "Ewe", "", "ee", "ewe" },
500 { "Faroese", "", "fo", "fao" },
501 { "Fijian", "", "fj", "fij" },
502 { "French", "Francais", "fr", "fra", "fre" },
503 { "Western Frisian", "", "fy", "fry" },
504 { "Fulah", "", "ff", "ful" },
505 { "Georgian", "", "ka", "kat", "geo" },
506 { "Gaelic (Scots)", "", "gd", "gla" },
507 { "Irish", "", "ga", "gle" },
508 { "Galician", "", "gl", "glg" },
509 { "Manx", "", "gv", "glv" },
510 { "Greek, Modern", "", "el", "ell", "gre" },
511 { "Guarani", "", "gn", "grn" },
512 { "Gujarati", "", "gu", "guj" },
513 { "Haitian", "", "ht", "hat" },
514 { "Hausa", "", "ha", "hau" },
515 { "Hebrew", "", "he", "heb" },
516 { "Herero", "", "hz", "her" },
517 { "Hindi", "", "hi", "hin" },
518 { "Hiri Motu", "", "ho", "hmo" },
519 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
520 { "Igbo", "", "ig", "ibo" },
521 { "Ido", "", "io", "ido" },
522 { "Icelandic", "Islenska", "is", "isl", "ice" },
523 { "Sichuan Yi", "", "ii", "iii" },
524 { "Inuktitut", "", "iu", "iku" },
525 { "Interlingue", "", "ie", "ile" },
526 { "Interlingua", "", "ia", "ina" },
527 { "Indonesian", "", "id", "ind" },
528 { "Inupiaq", "", "ik", "ipk" },
529 { "Italian", "Italiano", "it", "ita" },
530 { "Javanese", "", "jv", "jav" },
531 { "Japanese", "", "ja", "jpn" },
532 { "Kalaallisut", "", "kl", "kal" },
533 { "Kannada", "", "kn", "kan" },
534 { "Kashmiri", "", "ks", "kas" },
535 { "Kanuri", "", "kr", "kau" },
536 { "Kazakh", "", "kk", "kaz" },
537 { "Central Khmer", "", "km", "khm" },
538 { "Kikuyu", "", "ki", "kik" },
539 { "Kinyarwanda", "", "rw", "kin" },
540 { "Kirghiz", "", "ky", "kir" },
541 { "Komi", "", "kv", "kom" },
542 { "Kongo", "", "kg", "kon" },
543 { "Korean", "", "ko", "kor" },
544 { "Kuanyama", "", "kj", "kua" },
545 { "Kurdish", "", "ku", "kur" },
546 { "Lao", "", "lo", "lao" },
547 { "Latin", "", "la", "lat" },
548 { "Latvian", "", "lv", "lav" },
549 { "Limburgan", "", "li", "lim" },
550 { "Lingala", "", "ln", "lin" },
551 { "Lithuanian", "", "lt", "lit" },
552 { "Luxembourgish", "", "lb", "ltz" },
553 { "Luba-Katanga", "", "lu", "lub" },
554 { "Ganda", "", "lg", "lug" },
555 { "Macedonian", "", "mk", "mkd", "mac" },
556 { "Hungarian", "Magyar", "hu", "hun" },
557 { "Marshallese", "", "mh", "mah" },
558 { "Malayalam", "", "ml", "mal" },
559 { "Maori", "", "mi", "mri", "mao" },
560 { "Marathi", "", "mr", "mar" },
561 { "Malay", "", "ms", "msa", "msa" },
562 { "Malagasy", "", "mg", "mlg" },
563 { "Maltese", "", "mt", "mlt" },
564 { "Moldavian", "", "mo", "mol" },
565 { "Mongolian", "", "mn", "mon" },
566 { "Nauru", "", "na", "nau" },
567 { "Navajo", "", "nv", "nav" },
568 { "Dutch", "Nederlands", "nl", "nld", "dut" },
569 { "Ndebele, South", "", "nr", "nbl" },
570 { "Ndebele, North", "", "nd", "nde" },
571 { "Ndonga", "", "ng", "ndo" },
572 { "Nepali", "", "ne", "nep" },
573 { "Norwegian", "Norsk", "no", "nor" },
574 { "Norwegian Nynorsk", "", "nn", "nno" },
575 { "Norwegian Bokmål", "", "nb", "nob" },
576 { "Chichewa; Nyanja", "", "ny", "nya" },
577 { "Occitan", "", "oc", "oci" },
578 { "Ojibwa", "", "oj", "oji" },
579 { "Oriya", "", "or", "ori" },
580 { "Oromo", "", "om", "orm" },
581 { "Ossetian", "", "os", "oss" },
582 { "Panjabi", "", "pa", "pan" },
583 { "Persian", "", "fa", "fas", "per" },
584 { "Pali", "", "pi", "pli" },
585 { "Polish", "", "pl", "pol" },
586 { "Portuguese", "Portugues", "pt", "por" },
587 { "Pushto", "", "ps", "pus" },
588 { "Quechua", "", "qu", "que" },
589 { "Romansh", "", "rm", "roh" },
590 { "Romanian", "", "ro", "ron", "rum" },
591 { "Rundi", "", "rn", "run" },
592 { "Russian", "", "ru", "rus" },
593 { "Sango", "", "sg", "sag" },
594 { "Sanskrit", "", "sa", "san" },
595 { "Serbian", "", "sr", "srp", "scc" },
596 { "Sinhala", "", "si", "sin" },
597 { "Slovak", "", "sk", "slk", "slo" },
598 { "Slovenian", "", "sl", "slv" },
599 { "Northern Sami", "", "se", "sme" },
600 { "Samoan", "", "sm", "smo" },
601 { "Shona", "", "sn", "sna" },
602 { "Sindhi", "", "sd", "snd" },
603 { "Somali", "", "so", "som" },
604 { "Sotho, Southern", "", "st", "sot" },
605 { "Sardinian", "", "sc", "srd" },
606 { "Swati", "", "ss", "ssw" },
607 { "Sundanese", "", "su", "sun" },
608 { "Finnish", "Suomi", "fi", "fin" },
609 { "Swahili", "", "sw", "swa" },
610 { "Swedish", "Svenska", "sv", "swe" },
611 { "Tahitian", "", "ty", "tah" },
612 { "Tamil", "", "ta", "tam" },
613 { "Tatar", "", "tt", "tat" },
614 { "Telugu", "", "te", "tel" },
615 { "Tajik", "", "tg", "tgk" },
616 { "Tagalog", "", "tl", "tgl" },
617 { "Thai", "", "th", "tha" },
618 { "Tibetan", "", "bo", "bod", "tib" },
619 { "Tigrinya", "", "ti", "tir" },
620 { "Tonga", "", "to", "ton" },
621 { "Tswana", "", "tn", "tsn" },
622 { "Tsonga", "", "ts", "tso" },
623 { "Turkmen", "", "tk", "tuk" },
624 { "Turkish", "", "tr", "tur" },
625 { "Twi", "", "tw", "twi" },
626 { "Uighur", "", "ug", "uig" },
627 { "Ukrainian", "", "uk", "ukr" },
628 { "Urdu", "", "ur", "urd" },
629 { "Uzbek", "", "uz", "uzb" },
630 { "Venda", "", "ve", "ven" },
631 { "Vietnamese", "", "vi", "vie" },
632 { "Volapük", "", "vo", "vol" },
633 { "Welsh", "", "cy", "cym", "wel" },
634 { "Walloon", "", "wa", "wln" },
635 { "Wolof", "", "wo", "wol" },
636 { "Xhosa", "", "xh", "xho" },
637 { "Yiddish", "", "yi", "yid" },
638 { "Yoruba", "", "yo", "yor" },
639 { "Zhuang", "", "za", "zha" },
640 { "Zulu", "", "zu", "zul" },
641 {NULL, NULL, NULL, NULL}
643 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
645 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
648 del_tree(const gchar *name, gboolean del_top)
652 if (g_file_test(name, G_FILE_TEST_IS_DIR))
654 GDir *gdir = g_dir_open(name, 0, NULL);
655 file = g_dir_read_name(gdir);
659 path = g_strdup_printf("%s/%s", name, file);
660 del_tree(path, TRUE);
662 file = g_dir_read_name(gdir);
677 return hb_get_version(NULL);
682 signal_user_data_t *ud,
690 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
699 *step = ghb_settings_combo_double(ud->settings,
700 "VideoQualityGranularity");
701 if (*step == 0.2 || *step == 0.5)
703 else if (*step == 0.25)
708 case HB_VCODEC_FFMPEG:
716 case HB_VCODEC_THEORA:
735 find_combo_entry(combo_opts_t *opts, const GValue *gval)
739 if (G_VALUE_TYPE(gval) == G_TYPE_STRING)
742 str = ghb_value_string(gval);
743 for (ii = 0; ii < opts->count; ii++)
745 if (strcmp(opts->map[ii].shortOpt, str) == 0)
753 else if (G_VALUE_TYPE(gval) == G_TYPE_DOUBLE)
756 val = ghb_value_double(gval);
757 for (ii = 0; ii < opts->count; ii++)
759 if (opts->map[ii].ivalue == val)
766 else if (G_VALUE_TYPE(gval) == G_TYPE_INT ||
767 G_VALUE_TYPE(gval) == G_TYPE_BOOLEAN ||
768 G_VALUE_TYPE(gval) == G_TYPE_INT64)
771 val = ghb_value_int64(gval);
772 for (ii = 0; ii < opts->count; ii++)
774 if ((gint64)opts->map[ii].ivalue == val)
785 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
788 const gchar *result = "";
790 ii = find_combo_entry(opts, gval);
791 if (ii < opts->count)
793 result = opts->map[ii].svalue;
799 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
804 ii = find_combo_entry(opts, gval);
805 if (ii < opts->count)
807 result = opts->map[ii].ivalue;
813 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
818 ii = find_combo_entry(opts, gval);
819 if (ii < opts->count)
821 result = opts->map[ii].ivalue;
827 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
830 const gchar *result = "";
832 ii = find_combo_entry(opts, gval);
833 if (ii < opts->count)
835 result = opts->map[ii].option;
841 lookup_mix_int(const GValue *mix)
848 str = ghb_value_string(mix);
849 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
851 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
853 result = hb_audio_mixdowns[ii].amixdown;
862 lookup_mix_option(const GValue *mix)
866 gchar *result = "None";
869 str = ghb_value_string(mix);
870 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
872 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
874 result = hb_audio_mixdowns[ii].human_readable_name;
883 lookup_video_rate_int(const GValue *vrate)
889 str = ghb_value_string(vrate);
890 for (ii = 0; ii < hb_video_rates_count; ii++)
892 if (strcmp(hb_video_rates[ii].string, str) == 0)
894 result = hb_video_rates[ii].rate;
899 // Default to "same as source"
904 lookup_video_rate_option(const GValue *vrate)
908 const gchar *result = "Same as source";
910 str = ghb_value_string(vrate);
911 for (ii = 0; ii < hb_video_rates_count; ii++)
913 if (strcmp(hb_video_rates[ii].string, str) == 0)
915 result = hb_video_rates[ii].string;
920 // Default to "same as source"
925 lookup_audio_rate_int(const GValue *rate)
931 // Coincidentally, the string "source" will return 0
932 // which is our flag to use "same as source"
933 str = ghb_value_string(rate);
934 for (ii = 0; ii < hb_audio_rates_count; ii++)
936 if (strcmp(hb_audio_rates[ii].string, str) == 0)
938 result = hb_audio_rates[ii].rate;
947 lookup_audio_rate_option(const GValue *rate)
951 const gchar *result = "Same as source";
953 // Coincidentally, the string "source" will return 0
954 // which is our flag to use "same as source"
955 str = ghb_value_string(rate);
956 for (ii = 0; ii < hb_audio_rates_count; ii++)
958 if (strcmp(hb_audio_rates[ii].string, str) == 0)
960 result = hb_audio_rates[ii].string;
969 ghb_find_closest_audio_bitrate(gint codec, gint rate)
976 if (codec == HB_ACODEC_FAAC)
980 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
982 if (hb_audio_bitrates[ii].rate < low)
984 if (hb_audio_bitrates[ii].rate > high)
986 if (rate <= hb_audio_bitrates[ii].rate)
988 result = hb_audio_bitrates[ii].rate;
996 lookup_audio_bitrate_int(const GValue *rate)
1002 // Coincidentally, the string "source" will return 0
1003 // which is our flag to use "same as source"
1004 str = ghb_value_string(rate);
1005 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1007 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1009 result = hb_audio_bitrates[ii].rate;
1018 lookup_audio_bitrate_option(const GValue *rate)
1022 const gchar *result = "Same as source";
1024 // Coincidentally, the string "source" will return 0
1025 // which is our flag to use "same as source"
1026 str = ghb_value_string(rate);
1027 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1029 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1031 result = hb_audio_bitrates[ii].string;
1040 lookup_audio_lang_int(const GValue *rate)
1046 // Coincidentally, the string "source" will return 0
1047 // which is our flag to use "same as source"
1048 str = ghb_value_string(rate);
1049 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1051 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1062 lookup_audio_lang_option(const GValue *rate)
1066 const gchar *result = "Same as source";
1068 // Coincidentally, the string "source" will return 0
1069 // which is our flag to use "same as source"
1070 str = ghb_value_string(rate);
1071 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1073 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1075 if (ghb_language_table[ii].native_name[0] != 0)
1076 result = ghb_language_table[ii].native_name;
1078 result = ghb_language_table[ii].eng_name;
1087 ghb_lookup_acodec_value(gint val)
1089 GValue *value = NULL;
1092 for (ii = 0; ii < acodec_opts.count; ii++)
1094 if ((int)acodec_opts.map[ii].ivalue == val)
1096 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1100 value = ghb_string_value_new("auto");
1105 get_amix_value(gint val)
1107 GValue *value = NULL;
1110 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1112 if (hb_audio_mixdowns[ii].amixdown == val)
1114 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1121 // Handle for libhb. Gets set by ghb_backend_init()
1122 static hb_handle_t * h_scan = NULL;
1123 static hb_handle_t * h_queue = NULL;
1125 extern void hb_get_temporary_directory(char path[512]);
1132 hb_get_temporary_directory(dir);
1133 return g_strdup(dir);
1137 ghb_hb_cleanup(gboolean partial)
1141 hb_get_temporary_directory(dir);
1142 del_tree(dir, !partial);
1146 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1154 titleindex = ghb_settings_combo_int(ud->settings, "title");
1160 hb_subtitle_t * sub;
1162 if (h_scan == NULL) return VOBSUB;
1163 list = hb_get_titles( h_scan );
1164 if( !hb_list_count( list ) )
1166 /* No valid title, stop right there */
1169 title = hb_list_item( list, titleindex );
1170 if (title == NULL) return VOBSUB; // Bad titleindex
1171 sub = hb_list_item( title->list_subtitle, track);
1179 ghb_subtitle_source_name(gint source)
1181 const gchar * name = "Unknown";
1210 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1213 const gchar * name = "Unknown";
1226 titleindex = ghb_settings_combo_int(ud->settings, "title");
1232 hb_subtitle_t * sub;
1236 list = hb_get_titles( h_scan );
1237 if( !hb_list_count( list ) )
1240 title = hb_list_item( list, titleindex );
1244 sub = hb_list_item( title->list_subtitle, track);
1247 name = ghb_subtitle_source_name(sub->source);
1255 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1259 titleindex = ghb_settings_combo_int(ud->settings, "title");
1263 return ghb_get_user_audio_lang(ud, titleindex, 0);
1269 hb_subtitle_t * sub;
1274 list = hb_get_titles( h_scan );
1275 if( !hb_list_count( list ) )
1277 /* No valid title, stop right there */
1280 title = hb_list_item( list, titleindex );
1281 if (title == NULL) // Bad titleindex
1283 sub = hb_list_item( title->list_subtitle, track);
1285 return g_strdup(sub->iso639_2);
1288 return g_strdup("und");
1292 ghb_get_title_number(gint titleindex)
1297 if (h_scan == NULL) return 1;
1298 list = hb_get_titles( h_scan );
1299 if( !hb_list_count( list ) )
1301 /* No valid title, stop right there */
1304 title = hb_list_item( list, titleindex );
1305 if (title == NULL) return 1; // Bad titleindex
1306 return title->index;
1309 static hb_audio_config_t*
1310 get_hb_audio(gint titleindex, gint track)
1314 hb_audio_config_t *audio = NULL;
1316 if (h_scan == NULL) return NULL;
1317 list = hb_get_titles( h_scan );
1318 if( !hb_list_count( list ) )
1320 /* No valid title, stop right there */
1323 title = hb_list_item( list, titleindex );
1324 if (title == NULL) return NULL; // Bad titleindex
1325 if (!hb_list_count(title->list_audio))
1329 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1334 search_rates(hb_rate_t *rates, gint rate, gint count)
1337 for (ii = 0; ii < count; ii++)
1339 if (rates[ii].rate == rate)
1345 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1347 static GtkListStore*
1348 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1351 GtkListStore *store;
1353 g_debug("get_combo_box_store() %s\n", name);
1354 // First modify the combobox model to allow greying out of options
1355 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1356 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1361 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1363 GtkListStore *store;
1366 store = get_combo_box_store(builder, name);
1367 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1369 gtk_list_store_set(store, &iter,
1376 ghb_grey_combo_options(GtkBuilder *builder)
1379 gint container, track, titleindex, acodec;
1380 hb_audio_config_t *audio = NULL;
1383 widget = GHB_WIDGET (builder, "title");
1384 gval = ghb_widget_value(widget);
1385 titleindex = ghb_lookup_combo_int("title", gval);
1386 ghb_value_free(gval);
1387 widget = GHB_WIDGET (builder, "AudioTrack");
1388 gval = ghb_widget_value(widget);
1389 track = ghb_lookup_combo_int("AudioTrack", gval);
1390 ghb_value_free(gval);
1391 audio = get_hb_audio(titleindex, track);
1392 widget = GHB_WIDGET (builder, "FileFormat");
1393 gval = ghb_widget_value(widget);
1394 container = ghb_lookup_combo_int("FileFormat", gval);
1395 ghb_value_free(gval);
1397 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1398 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1399 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1400 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1402 gboolean allow_dca = TRUE;
1403 allow_dca = (container != HB_MUX_MP4);
1405 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1407 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1409 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1411 if (audio && audio->in.codec != HB_ACODEC_AC3)
1413 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1415 if (audio && audio->in.codec != HB_ACODEC_DCA)
1417 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1419 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1421 widget = GHB_WIDGET (builder, "AudioEncoder");
1422 gval = ghb_widget_value(widget);
1423 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1424 ghb_value_free(gval);
1425 if (acodec != HB_ACODEC_AC3)
1427 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1429 if (container == HB_MUX_MP4)
1431 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1432 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1435 gboolean allow_mono = TRUE;
1436 gboolean allow_stereo = TRUE;
1437 gboolean allow_dolby = TRUE;
1438 gboolean allow_dpl2 = TRUE;
1439 gboolean allow_6ch = TRUE;
1441 allow_6ch = acodec & ~HB_ACODEC_LAME;
1444 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1446 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1448 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1449 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1450 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1451 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1452 allow_6ch = allow_6ch &&
1453 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1454 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1456 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1457 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1458 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1459 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1460 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1464 ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
1466 if (acodec & HB_ACODEC_FAAC)
1481 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1483 hb_audio_config_t *audio = NULL;
1484 gboolean allow_mono = TRUE;
1485 gboolean allow_stereo = TRUE;
1486 gboolean allow_dolby = TRUE;
1487 gboolean allow_dpl2 = TRUE;
1488 gboolean allow_6ch = TRUE;
1490 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1492 // Audio codec pass-thru. No mixdown
1495 audio = get_hb_audio(titleindex, track);
1499 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1501 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1503 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1504 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1505 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1506 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1508 (acodec & ~HB_ACODEC_LAME) &&
1509 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1510 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1512 gboolean greater = FALSE;
1515 // If no mix is specified, select the best available.
1516 mix = HB_AMIXDOWN_6CH;
1518 if (mix == HB_AMIXDOWN_6CH)
1521 if (allow_6ch) return HB_AMIXDOWN_6CH;
1523 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1526 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1528 if (mix == HB_AMIXDOWN_DOLBY || greater)
1531 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1533 if (mix == HB_AMIXDOWN_STEREO || greater)
1536 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1538 if (mix == HB_AMIXDOWN_MONO || greater)
1541 if (allow_mono) return HB_AMIXDOWN_MONO;
1543 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1544 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1545 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1546 if (allow_6ch) return HB_AMIXDOWN_6CH;
1550 // Set up the model for the combo box
1552 init_combo_box(GtkBuilder *builder, const gchar *name)
1555 GtkListStore *store;
1556 GtkCellRenderer *cell;
1558 g_debug("init_combo_box() %s\n", name);
1559 // First modify the combobox model to allow greying out of options
1560 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1564 // 1 - String to display
1565 // 2 - bool indicating whether the entry is selectable (grey or not)
1566 // 3 - String that is used for presets
1567 // 4 - Int value determined by backend
1568 // 5 - String value determined by backend
1569 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1570 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1571 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1573 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1575 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1576 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1577 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1578 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1579 "markup", 0, "sensitive", 1, NULL);
1582 { // Combo box entry
1583 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1588 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1591 GtkListStore *store;
1595 g_debug("audio_samplerate_opts_set ()\n");
1596 store = get_combo_box_store(builder, name);
1597 gtk_list_store_clear(store);
1598 // Add an item for "Same As Source"
1599 gtk_list_store_append(store, &iter);
1600 gtk_list_store_set(store, &iter,
1601 0, "<small>Same as source</small>",
1607 for (ii = 0; ii < count; ii++)
1609 gtk_list_store_append(store, &iter);
1610 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1611 gtk_list_store_set(store, &iter,
1614 2, rates[ii].string,
1615 3, (gdouble)rates[ii].rate,
1616 4, rates[ii].string,
1623 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1626 GtkListStore *store;
1629 g_debug("video_rate_opts_set ()\n");
1630 store = get_combo_box_store(builder, name);
1631 gtk_list_store_clear(store);
1632 // Add an item for "Same As Source"
1633 gtk_list_store_append(store, &iter);
1634 gtk_list_store_set(store, &iter,
1635 0, "Same as source",
1641 for (ii = 0; ii < count; ii++)
1645 if (strcmp(rates[ii].string, "23.976") == 0)
1647 desc = "(NTSC Film)";
1649 else if (strcmp(rates[ii].string, "25") == 0)
1651 desc = "(PAL Film/Video)";
1653 else if (strcmp(rates[ii].string, "29.97") == 0)
1655 desc = "(NTSC Video)";
1657 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1658 gtk_list_store_append(store, &iter);
1659 gtk_list_store_set(store, &iter,
1662 2, rates[ii].string,
1663 3, (gdouble)rates[ii].rate,
1664 4, rates[ii].string,
1671 mix_opts_set(GtkBuilder *builder, const gchar *name)
1674 GtkListStore *store;
1678 g_debug("mix_opts_set ()\n");
1679 store = get_combo_box_store(builder, name);
1680 gtk_list_store_clear(store);
1681 gtk_list_store_append(store, &iter);
1682 gtk_list_store_set(store, &iter,
1683 0, "<small>None</small>",
1689 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1691 gtk_list_store_append(store, &iter);
1692 str = g_strdup_printf("<small>%s</small>",
1693 hb_audio_mixdowns[ii].human_readable_name);
1694 gtk_list_store_set(store, &iter,
1697 2, hb_audio_mixdowns[ii].short_name,
1698 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1699 4, hb_audio_mixdowns[ii].internal_name,
1706 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1709 GtkListStore *store;
1712 g_debug("srt_codeset_opts_set ()\n");
1713 store = get_combo_box_store(builder, name);
1714 gtk_list_store_clear(store);
1715 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1717 gtk_list_store_append(store, &iter);
1718 gtk_list_store_set(store, &iter,
1719 0, srt_codeset_table[ii],
1721 2, srt_codeset_table[ii],
1723 4, srt_codeset_table[ii],
1726 GtkComboBoxEntry *cbe;
1728 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1729 //gtk_combo_box_entry_set_text_column(cbe, 0);
1733 language_opts_set(GtkBuilder *builder, const gchar *name)
1736 GtkListStore *store;
1739 g_debug("language_opts_set ()\n");
1740 store = get_combo_box_store(builder, name);
1741 gtk_list_store_clear(store);
1742 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1746 if (ghb_language_table[ii].native_name[0] != 0)
1747 lang = ghb_language_table[ii].native_name;
1749 lang = ghb_language_table[ii].eng_name;
1751 gtk_list_store_append(store, &iter);
1752 gtk_list_store_set(store, &iter,
1755 2, ghb_language_table[ii].iso639_2,
1757 4, ghb_language_table[ii].iso639_1,
1762 static gchar **titles = NULL;
1765 title_opts_set(GtkBuilder *builder, const gchar *name)
1768 GtkListStore *store;
1769 hb_list_t * list = NULL;
1770 hb_title_t * title = NULL;
1774 g_debug("title_opts_set ()\n");
1775 store = get_combo_box_store(builder, name);
1776 gtk_list_store_clear(store);
1779 list = hb_get_titles( h_scan );
1780 count = hb_list_count( list );
1781 if (count > 100) count = 100;
1783 if (titles) g_strfreev(titles);
1784 if (title_opts.map) g_free(title_opts.map);
1787 title_opts.count = count;
1788 title_opts.map = g_malloc(count*sizeof(options_map_t));
1789 titles = g_malloc((count+1) * sizeof(gchar*));
1793 title_opts.count = 1;
1794 title_opts.map = g_malloc(sizeof(options_map_t));
1799 // No titles. Fill in a default.
1800 gtk_list_store_append(store, &iter);
1801 gtk_list_store_set(store, &iter,
1808 title_opts.map[0].option = "No Titles";
1809 title_opts.map[0].shortOpt = "none";
1810 title_opts.map[0].ivalue = -1;
1811 title_opts.map[0].svalue = "none";
1814 for (ii = 0; ii < count; ii++)
1816 title = (hb_title_t*)hb_list_item(list, ii);
1817 if (title->type == HB_STREAM_TYPE)
1819 if (title->duration != 0)
1821 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
1822 title->index, title->hours, title->minutes, title->seconds,
1827 titles[ii] = g_strdup_printf ("%d - %s",
1828 title->index, title->name);
1833 if (title->duration != 0)
1835 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1836 title->index, title->hours, title->minutes, title->seconds);
1840 titles[ii] = g_strdup_printf ("%d - Unknown Length",
1844 gtk_list_store_append(store, &iter);
1845 gtk_list_store_set(store, &iter,
1852 title_opts.map[ii].option = titles[ii];
1853 title_opts.map[ii].shortOpt = titles[ii];
1854 title_opts.map[ii].ivalue = ii;
1855 title_opts.map[ii].svalue = titles[ii];
1861 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1864 gboolean foundit = FALSE;
1866 if (gtk_tree_model_get_iter_first (store, iter))
1870 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1871 if (value == (int)ivalue)
1876 } while (gtk_tree_model_iter_next (store, iter));
1882 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1885 GtkListStore *store;
1886 hb_list_t * list = NULL;
1887 hb_title_t * title = NULL;
1888 hb_audio_config_t * audio;
1893 g_debug("audio_track_opts_set ()\n");
1894 store = get_combo_box_store(builder, name);
1895 gtk_list_store_clear(store);
1898 list = hb_get_titles( h_scan );
1899 title = (hb_title_t*)hb_list_item( list, titleindex );
1902 count = hb_list_count( title->list_audio );
1905 if (count > 100) count = 100;
1906 if (audio_track_opts.map) g_free(audio_track_opts.map);
1909 audio_track_opts.count = count;
1910 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1914 audio_track_opts.count = 1;
1915 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1919 // No audio. set some default
1920 gtk_list_store_append(store, &iter);
1921 gtk_list_store_set(store, &iter,
1922 0, "<small>No Audio</small>",
1928 audio_track_opts.map[0].option = "No Audio";
1929 audio_track_opts.map[0].shortOpt = "none";
1930 audio_track_opts.map[0].ivalue = -1;
1931 audio_track_opts.map[0].svalue = "none";
1934 index_str_init(count-1);
1935 for (ii = 0; ii < count; ii++)
1937 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1938 gtk_list_store_append(store, &iter);
1939 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
1940 gtk_list_store_set(store, &iter,
1948 audio_track_opts.map[ii].option = audio->lang.description,
1949 audio_track_opts.map[ii].shortOpt = index_str[ii];
1950 audio_track_opts.map[ii].ivalue = ii;
1951 audio_track_opts.map[ii].svalue = index_str[ii];
1956 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1959 GtkListStore *store;
1960 hb_list_t * list = NULL;
1961 hb_title_t * title = NULL;
1962 hb_subtitle_t * subtitle;
1964 static char ** options = NULL;
1966 g_debug("subtitle_track_opts_set ()\n");
1967 store = get_combo_box_store(builder, name);
1968 gtk_list_store_clear(store);
1971 list = hb_get_titles( h_scan );
1972 title = (hb_title_t*)hb_list_item( list, titleindex );
1975 count = hb_list_count( title->list_subtitle );
1978 if (count > 100) count = 100;
1979 if (subtitle_opts.map) g_free(subtitle_opts.map);
1982 subtitle_opts.count = count+1;
1983 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1987 subtitle_opts.count = LANG_TABLE_SIZE+1;
1988 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1990 gtk_list_store_append(store, &iter);
1991 gtk_list_store_set(store, &iter,
1992 0, "Foreign Audio Search",
1998 subtitle_opts.map[0].option = "Foreign Audio Search";
1999 subtitle_opts.map[0].shortOpt = "-1";
2000 subtitle_opts.map[0].ivalue = -1;
2001 subtitle_opts.map[0].svalue = "auto";
2004 if (options != NULL)
2005 g_strfreev(options);
2006 options = g_malloc((count+1)*sizeof(gchar*));
2007 index_str_init(count-1);
2008 for (ii = 0; ii < count; ii++)
2010 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
2011 // Skip subtitles that must be burned if there is already
2012 // a burned subtitle in the list
2014 if (subtitle->source == VOBSUB)
2016 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
2021 options[ii] = g_strdup_printf("%d - %s (%s)", ii+1,
2023 ghb_subtitle_source_name(subtitle->source));
2025 subtitle_opts.map[ii+1].option = options[ii];
2026 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2027 subtitle_opts.map[ii+1].ivalue = ii;
2028 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
2029 gtk_list_store_append(store, &iter);
2030 gtk_list_store_set(store, &iter,
2035 4, subtitle->iso639_2,
2038 options[count] = NULL;
2042 index_str_init(LANG_TABLE_SIZE-1);
2043 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
2047 if (ghb_language_table[ii].native_name[0] != 0)
2048 lang = ghb_language_table[ii].native_name;
2050 lang = ghb_language_table[ii].eng_name;
2052 subtitle_opts.map[ii+1].option = lang;
2053 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2054 subtitle_opts.map[ii+1].ivalue = ii;
2055 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
2056 gtk_list_store_append(store, &iter);
2057 gtk_list_store_set(store, &iter,
2062 4, ghb_language_table[ii].iso639_2,
2075 gint titleindex = 0;
2078 g_debug("ghb_longest_title ()\n");
2079 if (h_scan == NULL) return 0;
2080 list = hb_get_titles( h_scan );
2081 count = hb_list_count( list );
2082 if (count > 100) count = 100;
2083 if (count < 1) return 0;
2084 title = (hb_title_t*)hb_list_item(list, 0);
2085 feature = title->job->feature;
2086 for (ii = 0; ii < count; ii++)
2088 title = (hb_title_t*)hb_list_item(list, ii);
2089 if (title->index == feature)
2098 ghb_get_source_audio_lang(gint titleindex, gint track)
2102 hb_audio_config_t * audio;
2105 g_debug("ghb_lookup_1st_audio_lang ()\n");
2108 list = hb_get_titles( h_scan );
2109 title = (hb_title_t*)hb_list_item( list, titleindex );
2112 if (hb_list_count( title->list_audio ) <= track)
2115 audio = hb_list_audio_config_item(title->list_audio, track);
2119 lang = g_strdup(audio->lang.iso639_2);
2124 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2128 used = g_hash_table_lookup(track_indices, &acodec);
2133 used = g_malloc0(count * sizeof(gboolean));
2134 key = g_malloc(sizeof(gint));
2136 g_hash_table_insert(track_indices, key, used);
2142 ghb_find_audio_track(
2146 gint fallback_acodec,
2147 GHashTable *track_indices)
2151 hb_audio_config_t * audio;
2156 gboolean *used = NULL;
2157 gboolean *passthru_used;
2159 gint passthru_acodec;
2163 g_debug("find_audio_track ()\n");
2164 if (h_scan == NULL) return -1;
2165 list = hb_get_titles( h_scan );
2166 title = (hb_title_t*)hb_list_item( list, titleindex );
2169 count = hb_list_count( title->list_audio );
2171 if (count > 10) count = 10;
2172 // Try to find an item that matches the preferred language and
2173 // the passthru codec type
2174 passthru = (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)) != 0;
2177 for (ii = 0; ii < count; ii++)
2179 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2180 title->list_audio, ii );
2181 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2182 // Is the source track use a passthru capable codec?
2183 if (passthru_acodec == 0)
2185 used = get_track_used(passthru_acodec, track_indices, count);
2186 // Has the track already been used with this codec?
2190 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2191 audio->in.channel_layout);
2192 // Find a track that is not visually impaired or dirctor's
2193 // commentary, and has the highest channel count.
2194 if ((audio->lang.type < 2) &&
2195 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2196 (strcmp(lang, "und") == 0)))
2198 if (channels > max_chan)
2201 max_chan = channels;
2205 try_acodec = fallback_acodec;
2209 try_acodec = acodec;
2216 // Try to find an item that matches the preferred language
2218 used = get_track_used(try_acodec, track_indices, count);
2219 for (ii = 0; ii < count; ii++)
2221 // Has the track already been used with this codec?
2224 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2225 title->list_audio, ii );
2226 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2227 if (passthru_acodec && passthru)
2229 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2230 // Has the track already been used with this codec for passthru?
2231 if (passthru_used[ii])
2234 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2235 audio->in.channel_layout);
2236 // Find a track that is not visually impaired or dirctor's commentary
2237 if ((audio->lang.type < 2) &&
2238 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2239 (strcmp(lang, "und") == 0)))
2241 if (channels > max_chan)
2244 max_chan = channels;
2253 // Try to fine an item that does not match the preferred language and
2254 // matches the passthru codec type
2258 for (ii = 0; ii < count; ii++)
2262 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2263 title->list_audio, ii );
2264 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2265 // Is the source track use a passthru capable codec?
2266 if (passthru_acodec == 0)
2268 used = get_track_used(passthru_acodec, track_indices, count);
2269 // Has the track already been used with this codec?
2273 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2274 audio->in.channel_layout);
2275 // Find a track that is not visually impaired or dirctor's
2276 // commentary, and has the highest channel count.
2277 if (audio->lang.type < 2)
2279 if (channels > max_chan)
2282 max_chan = channels;
2286 try_acodec = fallback_acodec;
2290 try_acodec = acodec;
2297 // Try to fine an item that does not match the preferred language
2299 used = get_track_used(try_acodec, track_indices, count);
2300 for (ii = 0; ii < count; ii++)
2302 // Has the track already been used with this codec?
2305 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2306 title->list_audio, ii );
2307 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2308 if (passthru_acodec && passthru)
2310 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2311 // Has the track already been used with this codec for passthru?
2312 if (passthru_used[ii])
2315 // Find a track that is not visually impaired or dirctor's commentary
2316 if (audio->lang.type < 2)
2318 if (channels > max_chan)
2321 max_chan = channels;
2330 // Last ditch, anything goes
2331 for (ii = 0; ii < count; ii++)
2333 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2334 title->list_audio, ii );
2335 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2336 if (passthru_acodec && passthru)
2338 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2339 // Has the track already been used with this codec for passthru?
2340 if (passthru_used[ii])
2343 // Has the track already been used with this codec?
2358 ghb_find_pref_subtitle_track(const gchar *lang)
2361 count = subtitle_opts.count;
2362 for (ii = 0; ii < count; ii++)
2364 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2366 return subtitle_opts.map[ii].ivalue;
2373 ghb_find_cc_track(gint titleindex)
2377 hb_subtitle_t * subtitle;
2380 g_debug("ghb_find_cc_track ()\n");
2381 if (h_scan == NULL) return -2;
2382 list = hb_get_titles( h_scan );
2383 title = (hb_title_t*)hb_list_item( list, titleindex );
2386 count = hb_list_count( title->list_subtitle );
2387 // Try to find an item that matches the preferred language
2388 for (ii = 0; ii < count; ii++)
2390 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2391 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2399 ghb_find_subtitle_track(
2405 GHashTable * track_indices)
2409 hb_subtitle_t * subtitle;
2413 g_debug("find_subtitle_track ()\n");
2414 if (strcmp(lang, "auto") == 0)
2416 if (h_scan == NULL) return -1;
2417 list = hb_get_titles( h_scan );
2418 title = (hb_title_t*)hb_list_item( list, titleindex );
2421 count = hb_list_count( title->list_subtitle );
2422 used = g_hash_table_lookup(track_indices, lang);
2425 used = g_malloc0(count * sizeof(gboolean));
2426 g_hash_table_insert(track_indices, g_strdup(lang), used);
2428 // Try to find an item that matches the preferred language and source
2429 for (ii = 0; ii < count; ii++)
2434 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2435 if (source == subtitle->source &&
2436 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2437 (strcmp(lang, "und") == 0)))
2443 // Try to find an item that matches the preferred language
2444 for (ii = 0; ii < count; ii++)
2449 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2450 if ((!(burn || force) || (subtitle->source == VOBSUB)) &&
2451 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2452 (strcmp(lang, "und") == 0)))
2463 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2466 GtkListStore *store;
2469 g_debug("generic_opts_set ()\n");
2470 if (name == NULL || opts == NULL) return;
2471 store = get_combo_box_store(builder, name);
2472 gtk_list_store_clear(store);
2473 for (ii = 0; ii < opts->count; ii++)
2475 gtk_list_store_append(store, &iter);
2476 gtk_list_store_set(store, &iter,
2477 0, opts->map[ii].option,
2479 2, opts->map[ii].shortOpt,
2480 3, opts->map[ii].ivalue,
2481 4, opts->map[ii].svalue,
2487 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2490 GtkListStore *store;
2494 g_debug("small_opts_set ()\n");
2495 if (name == NULL || opts == NULL) return;
2496 store = get_combo_box_store(builder, name);
2497 gtk_list_store_clear(store);
2498 for (ii = 0; ii < opts->count; ii++)
2500 gtk_list_store_append(store, &iter);
2501 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2502 gtk_list_store_set(store, &iter,
2505 2, opts->map[ii].shortOpt,
2506 3, opts->map[ii].ivalue,
2507 4, opts->map[ii].svalue,
2514 find_combo_table(const gchar *name)
2518 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2520 if (strcmp(name, combo_name_map[ii].name) == 0)
2522 return combo_name_map[ii].opts;
2529 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2533 if (strcmp(name, "AudioBitrate") == 0)
2534 return lookup_audio_bitrate_int(gval);
2535 else if (strcmp(name, "AudioSamplerate") == 0)
2536 return lookup_audio_rate_int(gval);
2537 else if (strcmp(name, "VideoFramerate") == 0)
2538 return lookup_video_rate_int(gval);
2539 else if (strcmp(name, "AudioMixdown") == 0)
2540 return lookup_mix_int(gval);
2541 else if (strcmp(name, "SrtLanguage") == 0)
2542 return lookup_audio_lang_int(gval);
2543 else if (strcmp(name, "PreferredLanguage") == 0)
2544 return lookup_audio_lang_int(gval);
2547 return lookup_generic_int(find_combo_table(name), gval);
2549 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2554 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2558 if (strcmp(name, "AudioBitrate") == 0)
2559 return lookup_audio_bitrate_int(gval);
2560 else if (strcmp(name, "AudioSamplerate") == 0)
2561 return lookup_audio_rate_int(gval);
2562 else if (strcmp(name, "VideoFramerate") == 0)
2563 return lookup_video_rate_int(gval);
2564 else if (strcmp(name, "AudioMixdown") == 0)
2565 return lookup_mix_int(gval);
2566 else if (strcmp(name, "SrtLanguage") == 0)
2567 return lookup_audio_lang_int(gval);
2568 else if (strcmp(name, "PreferredLanguage") == 0)
2569 return lookup_audio_lang_int(gval);
2572 return lookup_generic_double(find_combo_table(name), gval);
2574 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2579 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2583 if (strcmp(name, "AudioBitrate") == 0)
2584 return lookup_audio_bitrate_option(gval);
2585 else if (strcmp(name, "AudioSamplerate") == 0)
2586 return lookup_audio_rate_option(gval);
2587 else if (strcmp(name, "VideoFramerate") == 0)
2588 return lookup_video_rate_option(gval);
2589 else if (strcmp(name, "AudioMixdown") == 0)
2590 return lookup_mix_option(gval);
2591 else if (strcmp(name, "SrtLanguage") == 0)
2592 return lookup_audio_lang_option(gval);
2593 else if (strcmp(name, "PreferredLanguage") == 0)
2594 return lookup_audio_lang_option(gval);
2597 return lookup_generic_option(find_combo_table(name), gval);
2599 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2604 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2608 if (strcmp(name, "AudioBitrate") == 0)
2609 return lookup_audio_bitrate_option(gval);
2610 else if (strcmp(name, "AudioSamplerate") == 0)
2611 return lookup_audio_rate_option(gval);
2612 else if (strcmp(name, "VideoFramerate") == 0)
2613 return lookup_video_rate_option(gval);
2614 else if (strcmp(name, "AudioMixdown") == 0)
2615 return lookup_mix_option(gval);
2616 else if (strcmp(name, "SrtLanguage") == 0)
2617 return lookup_audio_lang_option(gval);
2618 else if (strcmp(name, "PreferredLanguage") == 0)
2619 return lookup_audio_lang_option(gval);
2622 return lookup_generic_string(find_combo_table(name), gval);
2624 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2629 ghb_update_ui_combo_box(
2630 signal_user_data_t *ud,
2635 GtkComboBox *combo = NULL;
2637 gint handler_id = 0;
2641 g_debug("ghb_update_ui_combo_box() %s\n", name);
2642 // Clearing a combo box causes a rash of "changed" events, even when
2643 // the active item is -1 (inactive). To control things, I'm disabling
2644 // the event till things are settled down.
2645 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2646 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2649 // Valid signal id found. This should always succeed.
2650 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2651 signal_id, 0, 0, 0, 0);
2654 // This should also always succeed
2655 g_signal_handler_block ((gpointer)combo, handler_id);
2661 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2662 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2663 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2664 mix_opts_set(ud->builder, "AudioMixdown");
2665 language_opts_set(ud->builder, "SrtLanguage");
2666 language_opts_set(ud->builder, "PreferredLanguage");
2667 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2668 title_opts_set(ud->builder, "title");
2669 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2670 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2671 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2672 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2673 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2674 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2675 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2676 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2677 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2678 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2679 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2680 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2681 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2682 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2683 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2684 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2685 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2686 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2687 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2688 generic_opts_set(ud->builder, "x264_me", &me_opts);
2689 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2690 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2691 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2695 if (strcmp(name, "AudioBitrate") == 0)
2696 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2697 else if (strcmp(name, "AudioSamplerate") == 0)
2698 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2699 else if (strcmp(name, "VideoFramerate") == 0)
2700 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2701 else if (strcmp(name, "AudioMixdown") == 0)
2702 mix_opts_set(ud->builder, "AudioMixdown");
2703 else if (strcmp(name, "SrtLanguage") == 0)
2704 language_opts_set(ud->builder, "SrtLanguage");
2705 else if (strcmp(name, "PreferredLanguage") == 0)
2706 language_opts_set(ud->builder, "PreferredLanguage");
2707 else if (strcmp(name, "SrtCodeset") == 0)
2708 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2709 else if (strcmp(name, "title") == 0)
2710 title_opts_set(ud->builder, "title");
2711 else if (strcmp(name, "SubtitleTrack") == 0)
2712 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2713 else if (strcmp(name, "AudioTrack") == 0)
2714 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2716 generic_opts_set(ud->builder, name, find_combo_table(name));
2720 g_signal_handler_unblock ((gpointer)combo, handler_id);
2725 init_ui_combo_boxes(GtkBuilder *builder)
2729 init_combo_box(builder, "AudioBitrate");
2730 init_combo_box(builder, "AudioSamplerate");
2731 init_combo_box(builder, "VideoFramerate");
2732 init_combo_box(builder, "AudioMixdown");
2733 init_combo_box(builder, "SrtLanguage");
2734 init_combo_box(builder, "PreferredLanguage");
2735 init_combo_box(builder, "SrtCodeset");
2736 init_combo_box(builder, "title");
2737 init_combo_box(builder, "AudioTrack");
2738 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2740 init_combo_box(builder, combo_name_map[ii].name);
2744 static const char * turbo_opts =
2745 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2746 "no-fast-pskip=0:8x8dct=0";
2748 // Construct the x264 options string
2749 // The result is allocated, so someone must free it at some point.
2751 ghb_build_x264opts_string(GValue *settings)
2754 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2761 result = g_strdup("");
2767 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2771 hb_chapter_t * chapter;
2775 *hh = *mm = *ss = 0;
2776 if (h_scan == NULL) return;
2777 list = hb_get_titles( h_scan );
2778 title = (hb_title_t*)hb_list_item( list, tt );
2779 if (title == NULL) return;
2782 *mm = title->minutes;
2783 *ss = title->seconds;
2785 count = hb_list_count(title->list_chapter);
2786 if (sc > count) sc = count;
2787 if (ec > count) ec = count;
2789 if (sc == 1 && ec == count)
2793 for (c = sc; c <= ec; c++)
2795 chapter = hb_list_item(title->list_chapter, c-1);
2796 duration += chapter->duration;
2799 *hh = duration / 90000 / 3600;
2800 *mm = ((duration / 90000) % 3600) / 60;
2801 *ss = (duration / 90000) % 60;
2805 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2809 hb_chapter_t * chapter;
2812 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2813 *hh = *mm = *ss = 0;
2814 if (h_scan == NULL) return;
2815 list = hb_get_titles( h_scan );
2816 title = (hb_title_t*)hb_list_item( list, ti );
2817 if (title == NULL) return;
2818 count = hb_list_count( title->list_chapter );
2819 if (ii >= count) return;
2820 chapter = hb_list_item(title->list_chapter, ii);
2821 if (chapter == NULL) return;
2822 *hh = chapter->hours;
2823 *mm = chapter->minutes;
2824 *ss = chapter->seconds;
2828 ghb_get_chapters(gint titleindex)
2832 hb_chapter_t * chapter;
2834 GValue *chapters = NULL;
2836 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2837 if (h_scan == NULL) return NULL;
2838 list = hb_get_titles( h_scan );
2839 title = (hb_title_t*)hb_list_item( list, titleindex );
2840 if (title == NULL) return NULL;
2841 count = hb_list_count( title->list_chapter );
2842 chapters = ghb_array_value_new(count);
2843 for (ii = 0; ii < count; ii++)
2845 chapter = hb_list_item(title->list_chapter, ii);
2846 if (chapter == NULL) break;
2847 if (chapter->title == NULL || chapter->title[0] == 0)
2850 str = g_strdup_printf ("Chapter %2d", ii+1);
2851 ghb_array_append(chapters, ghb_string_value_new(str));
2856 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2863 ghb_ac3_in_audio_list(const GValue *audio_list)
2867 count = ghb_array_len(audio_list);
2868 for (ii = 0; ii < count; ii++)
2873 asettings = ghb_array_get_nth(audio_list, ii);
2874 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2875 if (acodec & HB_ACODEC_AC3)
2882 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2885 GtkListStore *store;
2888 g_debug("audio_bitrate_opts_add ()\n");
2890 if (rate < 8) return;
2892 store = get_combo_box_store(builder, name);
2893 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2895 str = g_strdup_printf ("<small>%d</small>", rate);
2896 gtk_list_store_append(store, &iter);
2897 gtk_list_store_set(store, &iter,
2909 audio_bitrate_opts_clean(
2910 GtkBuilder *builder,
2916 GtkListStore *store;
2918 gboolean done = FALSE;
2920 guint last = (guint)last_rate;
2921 guint first = (guint)first_rate;
2923 g_debug("audio_bitrate_opts_clean ()\n");
2924 store = get_combo_box_store(builder, name);
2925 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2929 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2931 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2933 done = !gtk_list_store_remove(store, &iter);
2935 else if (ivalue < first || ivalue > last)
2938 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2939 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2944 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2945 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2952 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2955 GtkListStore *store;
2959 g_debug("audio_bitrate_opts_set ()\n");
2960 store = get_combo_box_store(builder, name);
2961 gtk_list_store_clear(store);
2962 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2964 gtk_list_store_append(store, &iter);
2965 str = g_strdup_printf ("<small>%s</small>",
2966 hb_audio_bitrates[ii].string);
2967 gtk_list_store_set(store, &iter,
2970 2, hb_audio_bitrates[ii].string,
2971 3, (gdouble)hb_audio_bitrates[ii].rate,
2972 4, hb_audio_bitrates[ii].string,
2979 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2981 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2985 ghb_set_default_bitrate_opts(
2986 GtkBuilder *builder,
2990 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
2993 static ghb_status_t hb_status;
2996 ghb_combo_init(signal_user_data_t *ud)
2998 // Set up the list model for the combos
2999 init_ui_combo_boxes(ud->builder);
3000 // Populate all the combos
3001 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
3005 ghb_backend_init(gint debug)
3008 h_scan = hb_init( debug, 0 );
3009 h_queue = hb_init( debug, 0 );
3020 void ghb_backend_scan_stop()
3022 hb_scan_stop( h_scan );
3026 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
3028 hb_scan( h_scan, path, titleindex, preview_count, 1 );
3029 hb_status.scan.state |= GHB_STATE_SCANNING;
3030 // initialize count and cur to something that won't cause FPE
3031 // when computing progress
3032 hb_status.scan.title_count = 1;
3033 hb_status.scan.title_cur = 0;
3037 ghb_backend_queue_scan(const gchar *path, gint titlenum)
3039 g_debug("ghb_backend_queue_scan()");
3040 hb_scan( h_queue, path, titlenum, 10, 0 );
3041 hb_status.queue.state |= GHB_STATE_SCANNING;
3045 ghb_get_scan_state()
3047 return hb_status.scan.state;
3051 ghb_get_queue_state()
3053 return hb_status.queue.state;
3057 ghb_clear_scan_state(gint state)
3059 hb_status.scan.state &= ~state;
3063 ghb_clear_queue_state(gint state)
3065 hb_status.queue.state &= ~state;
3069 ghb_set_scan_state(gint state)
3071 hb_status.scan.state |= state;
3075 ghb_set_queue_state(gint state)
3077 hb_status.queue.state |= state;
3081 ghb_get_status(ghb_status_t *status)
3083 memcpy(status, &hb_status, sizeof(ghb_status_t));
3092 if (h_scan == NULL) return;
3093 hb_get_state( h_scan, &s_scan );
3094 switch( s_scan.state )
3096 #define p s_scan.param.scanning
3097 case HB_STATE_SCANNING:
3099 hb_status.scan.state |= GHB_STATE_SCANNING;
3100 hb_status.scan.title_count = p.title_count;
3101 hb_status.scan.title_cur = p.title_cur;
3105 case HB_STATE_SCANDONE:
3107 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3108 hb_status.scan.state |= GHB_STATE_SCANDONE;
3111 #define p s_scan.param.working
3112 case HB_STATE_WORKING:
3113 hb_status.scan.state |= GHB_STATE_WORKING;
3114 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3115 hb_status.scan.job_cur = p.job_cur;
3116 hb_status.scan.job_count = p.job_count;
3117 hb_status.scan.progress = p.progress;
3118 hb_status.scan.rate_cur = p.rate_cur;
3119 hb_status.scan.rate_avg = p.rate_avg;
3120 hb_status.scan.hours = p.hours;
3121 hb_status.scan.minutes = p.minutes;
3122 hb_status.scan.seconds = p.seconds;
3123 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3127 case HB_STATE_PAUSED:
3128 hb_status.scan.state |= GHB_STATE_PAUSED;
3131 case HB_STATE_MUXING:
3133 hb_status.scan.state |= GHB_STATE_MUXING;
3136 #define p s_scan.param.workdone
3137 case HB_STATE_WORKDONE:
3141 hb_status.scan.state |= GHB_STATE_WORKDONE;
3142 hb_status.scan.state &= ~GHB_STATE_MUXING;
3143 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3144 hb_status.scan.state &= ~GHB_STATE_WORKING;
3148 hb_status.scan.error = GHB_ERROR_NONE;
3150 case HB_ERROR_CANCELED:
3151 hb_status.scan.error = GHB_ERROR_CANCELED;
3154 hb_status.scan.error = GHB_ERROR_FAIL;
3157 // Delete all remaining jobs of this encode.
3158 // An encode can be composed of multiple associated jobs.
3159 // When a job is stopped, libhb removes it from the job list,
3160 // but does not remove other jobs that may be associated with it.
3161 // Associated jobs are taged in the sequence id.
3162 while ((job = hb_job(h_scan, 0)) != NULL)
3163 hb_rem( h_scan, job );
3167 hb_get_state( h_queue, &s_queue );
3168 switch( s_queue.state )
3170 #define p s_queue.param.scanning
3171 case HB_STATE_SCANNING:
3173 hb_status.queue.state |= GHB_STATE_SCANNING;
3174 hb_status.queue.title_count = p.title_count;
3175 hb_status.queue.title_cur = p.title_cur;
3179 case HB_STATE_SCANDONE:
3181 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3182 hb_status.queue.state |= GHB_STATE_SCANDONE;
3185 #define p s_queue.param.working
3186 case HB_STATE_WORKING:
3187 hb_status.queue.state |= GHB_STATE_WORKING;
3188 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3189 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3190 hb_status.queue.job_cur = p.job_cur;
3191 hb_status.queue.job_count = p.job_count;
3192 hb_status.queue.progress = p.progress;
3193 hb_status.queue.rate_cur = p.rate_cur;
3194 hb_status.queue.rate_avg = p.rate_avg;
3195 hb_status.queue.hours = p.hours;
3196 hb_status.queue.minutes = p.minutes;
3197 hb_status.queue.seconds = p.seconds;
3198 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3201 case HB_STATE_SEARCHING:
3202 hb_status.queue.state |= GHB_STATE_SEARCHING;
3203 hb_status.queue.state &= ~GHB_STATE_WORKING;
3204 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3205 hb_status.queue.job_cur = p.job_cur;
3206 hb_status.queue.job_count = p.job_count;
3207 hb_status.queue.progress = p.progress;
3208 hb_status.queue.rate_cur = p.rate_cur;
3209 hb_status.queue.rate_avg = p.rate_avg;
3210 hb_status.queue.hours = p.hours;
3211 hb_status.queue.minutes = p.minutes;
3212 hb_status.queue.seconds = p.seconds;
3213 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3217 case HB_STATE_PAUSED:
3218 hb_status.queue.state |= GHB_STATE_PAUSED;
3221 case HB_STATE_MUXING:
3223 hb_status.queue.state |= GHB_STATE_MUXING;
3226 #define p s_queue.param.workdone
3227 case HB_STATE_WORKDONE:
3231 hb_status.queue.state |= GHB_STATE_WORKDONE;
3232 hb_status.queue.state &= ~GHB_STATE_MUXING;
3233 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3234 hb_status.queue.state &= ~GHB_STATE_WORKING;
3235 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3239 hb_status.queue.error = GHB_ERROR_NONE;
3241 case HB_ERROR_CANCELED:
3242 hb_status.queue.error = GHB_ERROR_CANCELED;
3245 hb_status.queue.error = GHB_ERROR_FAIL;
3248 // Delete all remaining jobs of this encode.
3249 // An encode can be composed of multiple associated jobs.
3250 // When a job is stopped, libhb removes it from the job list,
3251 // but does not remove other jobs that may be associated with it.
3252 // Associated jobs are taged in the sequence id.
3253 while ((job = hb_job(h_queue, 0)) != NULL)
3254 hb_rem( h_queue, job );
3261 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3266 if (h_scan == NULL) return FALSE;
3267 list = hb_get_titles( h_scan );
3268 if( !hb_list_count( list ) )
3270 /* No valid title, stop right there */
3274 title = hb_list_item( list, titleindex );
3275 if (title == NULL) return FALSE; // Bad titleindex
3276 tinfo->index = titleindex;
3277 tinfo->width = title->width;
3278 tinfo->height = title->height;
3279 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3280 // Don't allow crop to 0
3281 if (title->crop[0] + title->crop[1] >= title->height)
3282 title->crop[0] = title->crop[1] = 0;
3283 if (title->crop[2] + title->crop[3] >= title->width)
3284 title->crop[2] = title->crop[3] = 0;
3285 tinfo->num_chapters = hb_list_count(title->list_chapter);
3286 tinfo->rate_base = title->rate_base;
3287 tinfo->rate = title->rate;
3288 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3289 title->width * title->pixel_aspect_width,
3290 title->height * title->pixel_aspect_height);
3291 tinfo->hours = title->hours;
3292 tinfo->minutes = title->minutes;
3293 tinfo->seconds = title->seconds;
3294 tinfo->duration = title->duration;
3296 tinfo->angle_count = title->angle_count;
3297 tinfo->path = title->path;
3298 tinfo->name = title->name;
3299 tinfo->type = title->type;
3304 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3306 hb_audio_config_t *audio;
3308 audio = get_hb_audio(titleindex, audioindex);
3309 if (audio == NULL) return FALSE; // Bad audioindex
3310 ainfo->codec = audio->in.codec;
3311 ainfo->bitrate = audio->in.bitrate;
3312 ainfo->samplerate = audio->in.samplerate;
3317 ghb_audio_is_passthru(gint acodec)
3319 g_debug("ghb_audio_is_passthru () \n");
3320 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
3324 ghb_get_default_acodec()
3326 return HB_ACODEC_FAAC;
3330 picture_settings_deps(signal_user_data_t *ud)
3332 gboolean autoscale, keep_aspect, enable_keep_aspect;
3333 gboolean enable_scale_width, enable_scale_height;
3334 gboolean enable_disp_width, enable_disp_height, enable_par;
3338 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3341 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3342 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3343 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3345 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3346 if (!enable_keep_aspect)
3348 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3350 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3351 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3353 enable_scale_width = !autoscale && (pic_par != 1);
3354 enable_scale_height = !autoscale && (pic_par != 1);
3355 enable_disp_width = (pic_par == 3) && !keep_aspect;
3356 enable_par = (pic_par == 3) && !keep_aspect;
3357 enable_disp_height = FALSE;
3359 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3360 gtk_widget_set_sensitive(widget, pic_par != 1);
3361 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3362 gtk_widget_set_sensitive(widget, pic_par != 1);
3363 widget = GHB_WIDGET(ud->builder, "scale_width");
3364 gtk_widget_set_sensitive(widget, enable_scale_width);
3365 widget = GHB_WIDGET(ud->builder, "scale_height");
3366 gtk_widget_set_sensitive(widget, enable_scale_height);
3367 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3368 gtk_widget_set_sensitive(widget, enable_disp_width);
3369 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3370 gtk_widget_set_sensitive(widget, enable_disp_height);
3371 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3372 gtk_widget_set_sensitive(widget, enable_par);
3373 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3374 gtk_widget_set_sensitive(widget, enable_par);
3375 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3376 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3377 widget = GHB_WIDGET(ud->builder, "autoscale");
3378 gtk_widget_set_sensitive(widget, pic_par != 1);
3382 ghb_set_scale(signal_user_data_t *ud, gint mode)
3387 gboolean keep_aspect;
3389 gboolean autocrop, autoscale, noscale;
3390 gint crop[4], width, height, par_width, par_height;
3391 gint crop_width, crop_height;
3392 gint aspect_n, aspect_d;
3393 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3394 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3399 gint max_height = 0;
3400 static gboolean busy = FALSE;
3402 g_debug("ghb_set_scale ()\n");
3403 picture_settings_deps(ud);
3404 if (h_scan == NULL) return;
3405 list = hb_get_titles( h_scan );
3406 if( !hb_list_count( list ) )
3408 /* No valid title, stop right there */
3413 titleindex = ghb_settings_combo_int(ud->settings, "title");
3414 title = hb_list_item( list, titleindex );
3415 if (title == NULL) return;
3417 if (job == NULL) return;
3422 if (!ud->dont_clear_presets && (keep_width || keep_height))
3424 ghb_settings_set_int(ud->settings, "PictureWidth", 0);
3425 ghb_settings_set_int(ud->settings, "PictureHeight", 0);
3428 // First configure widgets
3429 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3430 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3431 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3432 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3433 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3434 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3435 // alignment constraints rather than scaling to satisfy them.
3436 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3437 // Align dimensions to either 16 or 2 pixels
3438 // The scaler crashes if the dimensions are not divisible by 2
3439 // x264 also will not accept dims that are not multiple of 2
3443 keep_height = FALSE;
3445 // Step needs to be at least 2 because odd widths cause scaler crash
3447 widget = GHB_WIDGET (ud->builder, "scale_width");
3448 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3449 widget = GHB_WIDGET (ud->builder, "scale_height");
3450 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3453 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3454 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3455 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3456 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3457 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3458 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3459 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3460 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3464 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3465 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3466 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3467 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3468 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3469 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3470 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3471 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3473 ghb_title_info_t tinfo;
3474 ghb_get_title_info (&tinfo, titleindex);
3477 crop[0] = tinfo.crop[0];
3478 crop[1] = tinfo.crop[1];
3479 crop[2] = tinfo.crop[2];
3480 crop[3] = tinfo.crop[3];
3481 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3482 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3483 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3484 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3488 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3489 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3490 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3491 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3497 // Adjust the cropping to accomplish the desired width and height
3498 crop_width = tinfo.width - crop[2] - crop[3];
3499 crop_height = tinfo.height - crop[0] - crop[1];
3500 width = MOD_DOWN(crop_width, mod);
3501 height = MOD_DOWN(crop_height, mod);
3503 need1 = (crop_height - height) / 2;
3504 need2 = crop_height - height - need1;
3507 need1 = (crop_width - width) / 2;
3508 need2 = crop_width - width - need1;
3511 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3512 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3513 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3514 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3516 hb_reduce(&aspect_n, &aspect_d,
3517 title->width * title->pixel_aspect_width,
3518 title->height * title->pixel_aspect_height);
3519 crop_width = title->width - crop[2] - crop[3];
3520 crop_height = title->height - crop[0] - crop[1];
3524 height = crop_height;
3528 width = ghb_settings_get_int(ud->settings, "scale_width");
3529 height = ghb_settings_get_int(ud->settings, "scale_height");
3530 max_width = MOD_DOWN(
3531 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3532 max_height = MOD_DOWN(
3533 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3535 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3538 width = title->width - crop[2] - crop[3];
3540 height = title->height - crop[0] - crop[1];
3542 width = MOD_ROUND(width, mod);
3543 height = MOD_ROUND(height, mod);
3545 // Adjust dims according to max values
3547 height = MIN(height, max_height);
3549 width = MIN(width, max_width);
3553 job->anamorphic.mode = pic_par;
3554 // The scaler crashes if the dimensions are not divisible by 2
3555 // Align mod 2. And so does something in x264_encoder_headers()
3557 job->anamorphic.par_width = title->pixel_aspect_width;
3558 job->anamorphic.par_height = title->pixel_aspect_height;
3559 job->anamorphic.dar_width = 0;
3560 job->anamorphic.dar_height = 0;
3562 if (keep_height && pic_par == 2)
3563 width = ((double)height * crop_width / crop_height) + mod / 2;
3565 job->height = height;
3566 job->maxWidth = max_width;
3567 job->maxHeight = max_height;
3568 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3569 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3570 if (job->anamorphic.mode == 3 && !keep_aspect)
3572 job->anamorphic.keep_display_aspect = 0;
3573 if (mode & GHB_PIC_KEEP_PAR)
3575 job->anamorphic.par_width =
3576 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3577 job->anamorphic.par_height =
3578 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3582 job->anamorphic.dar_width =
3583 ghb_settings_get_int(ud->settings,
3584 "PictureDisplayWidth");
3585 job->anamorphic.dar_height = height;
3590 job->anamorphic.keep_display_aspect = 1;
3592 hb_set_anamorphic_size( job, &width, &height,
3593 &par_width, &par_height );
3594 if (job->anamorphic.mode == 3 && !keep_aspect &&
3595 mode & GHB_PIC_KEEP_PAR)
3597 // hb_set_anamorphic_size reduces the par, which we
3598 // don't want in this case because the user is
3599 // explicitely specifying it.
3600 par_width = ghb_settings_get_int(ud->settings,
3602 par_height = ghb_settings_get_int(ud->settings,
3603 "PicturePARHeight");
3608 job->anamorphic.mode = pic_par;
3612 gint new_width, new_height;
3614 // Compute pixel aspect ration.
3615 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3616 // Must scale so that par becomes 1:1
3617 // Try to keep largest dimension
3618 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3619 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3621 if (max_width && new_width > max_width)
3623 height = new_height;
3625 else if (max_height && new_height > max_height)
3629 else if (keep_width)
3631 height = new_height;
3633 else if (keep_height)
3637 else if (width > new_width)
3639 height = new_height;
3645 g_debug("new w %d h %d\n", width, height);
3647 width = MOD_ROUND(width, mod);
3648 height = MOD_ROUND(height, mod);
3650 height = MIN(height, max_height);
3652 width = MIN(width, max_width);
3653 par_width = par_height = 1;
3655 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3656 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3658 gint disp_width, dar_width, dar_height;
3661 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3662 hb_reduce(&dar_width, &dar_height, disp_width, height);
3664 gint iaspect = dar_width * 9 / dar_height;
3665 if (dar_width > 2 * dar_height)
3667 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3669 else if (iaspect <= 16 && iaspect >= 15)
3671 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3673 else if (iaspect <= 12 && iaspect >= 11)
3675 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3679 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3681 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3683 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3684 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3685 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3686 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3691 set_preview_job_settings(hb_job_t *job, GValue *settings)
3693 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3694 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3695 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3696 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3698 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3700 ghb_settings_combo_int(settings, "PictureModulus");
3701 job->width = ghb_settings_get_int(settings, "scale_width");
3702 job->height = ghb_settings_get_int(settings, "scale_height");
3703 if (ghb_settings_get_boolean(settings, "show_crop"))
3705 gdouble xscale = (gdouble)job->width /
3706 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3707 gdouble yscale = (gdouble)job->height /
3708 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3710 job->width += xscale * (job->crop[2] + job->crop[3]);
3711 job->height += yscale * (job->crop[0] + job->crop[1]);
3719 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3722 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3723 job->deinterlace = (decomb == 0) ? 0 : 1;
3727 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3728 job->deinterlace = (deint == 0) ? 0 : 1;
3731 gboolean keep_aspect;
3732 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3733 if (job->anamorphic.mode)
3735 job->anamorphic.par_width = job->title->pixel_aspect_width;
3736 job->anamorphic.par_height = job->title->pixel_aspect_height;
3737 job->anamorphic.dar_width = 0;
3738 job->anamorphic.dar_height = 0;
3740 if (job->anamorphic.mode == 3 && !keep_aspect)
3742 job->anamorphic.keep_display_aspect = 0;
3743 job->anamorphic.par_width =
3744 ghb_settings_get_int(settings, "PicturePARWidth");
3745 job->anamorphic.par_height =
3746 ghb_settings_get_int(settings, "PicturePARHeight");
3750 job->anamorphic.keep_display_aspect = 1;
3756 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3763 if (h_scan == NULL) return 1500;
3764 list = hb_get_titles( h_scan );
3765 title = hb_list_item( list, titleindex );
3766 if (title == NULL) return 1500;
3768 if (job == NULL) return 1500;
3769 size = ghb_settings_get_int(settings, "VideoTargetSize");
3770 return hb_calc_bitrate( job, size );
3774 ghb_validate_filter_string(const gchar *str, gint max_fields)
3780 if (str == NULL || *str == 0) return TRUE;
3783 val = g_strtod(str, &end);
3785 { // Found a numeric value
3787 // negative max_fields means infinate
3788 if (max_fields >= 0 && fields > max_fields) return FALSE;
3802 ghb_validate_filters(signal_user_data_t *ud)
3808 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3810 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3811 if (!decomb_deint && index == 1)
3813 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3814 if (!ghb_validate_filter_string(str, -1))
3816 message = g_strdup_printf(
3817 "Invalid Deinterlace Settings:\n\n%s\n",
3819 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3827 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3830 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3831 if (!ghb_validate_filter_string(str, -1))
3833 message = g_strdup_printf(
3834 "Invalid Detelecine Settings:\n\n%s\n",
3836 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3844 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3845 if (decomb_deint && index == 1)
3847 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3848 if (!ghb_validate_filter_string(str, -1))
3850 message = g_strdup_printf(
3851 "Invalid Decomb Settings:\n\n%s\n",
3853 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3861 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3864 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3865 if (!ghb_validate_filter_string(str, -1))
3867 message = g_strdup_printf(
3868 "Invalid Denoise Settings:\n\n%s\n",
3870 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3881 ghb_validate_video(signal_user_data_t *ud)
3886 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3887 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3888 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
3890 // mp4/theora combination is not supported.
3891 message = g_strdup_printf(
3892 "Theora is not supported in the MP4 container.\n\n"
3893 "You should choose a different video codec or container.\n"
3894 "If you continue, FFMPEG will be chosen for you.");
3895 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3901 vcodec = HB_VCODEC_FFMPEG;
3902 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3908 ghb_validate_subtitles(signal_user_data_t *ud)
3914 if (h_scan == NULL) return FALSE;
3915 list = hb_get_titles( h_scan );
3916 if( !hb_list_count( list ) )
3918 /* No valid title, stop right there */
3919 g_message("No title found.\n");
3925 titleindex = ghb_settings_combo_int(ud->settings, "title");
3926 title = hb_list_item( list, titleindex );
3927 if (title == NULL) return FALSE;
3929 const GValue *slist, *settings;
3930 gint count, ii, source;
3931 gboolean burned, one_burned = FALSE;
3933 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3934 count = ghb_array_len(slist);
3935 for (ii = 0; ii < count; ii++)
3937 settings = ghb_array_get_nth(slist, ii);
3938 source = ghb_settings_get_int(settings, "SubtitleSource");
3939 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3940 if (burned && one_burned)
3942 // MP4 can only handle burned vobsubs. make sure there isn't
3943 // already something burned in the list
3944 message = g_strdup_printf(
3945 "Only one subtitle may be burned into the video.\n\n"
3946 "You should change your subtitle selections.\n"
3947 "If you continue, some subtitles will be lost.");
3948 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3960 if (source == SRTSUB)
3964 filename = ghb_settings_get_string(settings, "SrtFile");
3965 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3967 message = g_strdup_printf(
3968 "Srt file does not exist or not a regular file.\n\n"
3969 "You should choose a valid file.\n"
3970 "If you continue, this subtitle will be ignored.");
3971 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3972 "Cancel", "Continue"))
3986 ghb_select_audio_codec(signal_user_data_t *ud, gint track)
3990 hb_audio_config_t *audio;
3992 if (h_scan == NULL) return -1;
3993 list = hb_get_titles( h_scan );
3994 if( !hb_list_count( list ) )
4001 titleindex = ghb_settings_combo_int(ud->settings, "title");
4002 title = hb_list_item( list, titleindex );
4003 if (title == NULL) return -1;
4005 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4007 if (track < 0 || track >= hb_list_count(title->list_audio))
4010 audio = (hb_audio_config_t *) hb_list_audio_config_item(
4011 title->list_audio, track );
4012 if (mux == HB_MUX_MP4)
4014 if (audio->in.codec == HB_ACODEC_AC3)
4015 return audio->in.codec;
4017 return HB_ACODEC_FAAC;
4021 if (audio->in.codec == HB_ACODEC_AC3 || audio->in.codec == HB_ACODEC_DCA)
4022 return audio->in.codec;
4024 return HB_ACODEC_LAME;
4029 ghb_select_audio_codec_str(signal_user_data_t *ud, gint track)
4033 acodec = ghb_select_audio_codec(ud, track);
4034 for (ii = 0; ii < acodec_opts.count; ii++)
4036 if (acodec_opts.map[ii].ivalue == acodec)
4037 return acodec_opts.map[ii].option;
4043 ghb_validate_audio(signal_user_data_t *ud)
4050 if (h_scan == NULL) return FALSE;
4051 list = hb_get_titles( h_scan );
4052 if( !hb_list_count( list ) )
4054 /* No valid title, stop right there */
4055 g_message("No title found.\n");
4061 titleindex = ghb_settings_combo_int(ud->settings, "title");
4062 title = hb_list_item( list, titleindex );
4063 if (title == NULL) return FALSE;
4064 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4066 const GValue *audio_list;
4069 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
4070 count = ghb_array_len(audio_list);
4071 for (ii = 0; ii < count; ii++)
4074 hb_audio_config_t *taudio;
4076 asettings = ghb_array_get_nth(audio_list, ii);
4077 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4078 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4079 if (codec == HB_ACODEC_MASK)
4082 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4083 title->list_audio, track );
4084 if (!(taudio->in.codec & codec) &&
4085 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4087 // Not supported. AC3 is passthrough only, so input must be AC3
4088 message = g_strdup_printf(
4089 "The source does not support Pass-Thru.\n\n"
4090 "You should choose a different audio codec.\n"
4091 "If you continue, one will be chosen for you.");
4092 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4098 if (mux == HB_MUX_MKV)
4100 codec = HB_ACODEC_LAME;
4104 codec = HB_ACODEC_FAAC;
4106 value = ghb_lookup_acodec_value(codec);
4107 ghb_settings_take_value(asettings, "AudioEncoder", value);
4109 gchar *a_unsup = NULL;
4110 gchar *mux_s = NULL;
4111 if (mux == HB_MUX_MP4)
4114 // mp4/vorbis|DTS combination is not supported.
4115 if (codec == HB_ACODEC_VORBIS)
4118 codec = HB_ACODEC_FAAC;
4120 if (codec == HB_ACODEC_DCA)
4123 codec = HB_ACODEC_FAAC;
4128 message = g_strdup_printf(
4129 "%s is not supported in the %s container.\n\n"
4130 "You should choose a different audio codec.\n"
4131 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4132 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4138 value = ghb_lookup_acodec_value(codec);
4139 ghb_settings_take_value(asettings, "AudioEncoder", value);
4141 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4142 gboolean allow_mono = TRUE;
4143 gboolean allow_stereo = TRUE;
4144 gboolean allow_dolby = TRUE;
4145 gboolean allow_dpl2 = TRUE;
4146 gboolean allow_6ch = TRUE;
4148 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4150 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4152 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4153 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4154 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4155 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4157 (codec & ~HB_ACODEC_LAME) &&
4158 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4159 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4161 gchar *mix_unsup = NULL;
4162 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4166 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4168 mix_unsup = "stereo";
4170 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4172 mix_unsup = "Dolby";
4174 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4176 mix_unsup = "Dolby Pro Logic II";
4178 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4180 mix_unsup = "6 Channel";
4184 message = g_strdup_printf(
4185 "The source audio does not support %s mixdown.\n\n"
4186 "You should choose a different mixdown.\n"
4187 "If you continue, one will be chosen for you.", mix_unsup);
4188 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4194 mix = ghb_get_best_mix(titleindex, track, codec, mix);
4195 value = get_amix_value(mix);
4196 ghb_settings_take_value(asettings, "AudioMixdown", value);
4203 ghb_validate_vquality(GValue *settings)
4209 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4210 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4212 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4213 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4217 case HB_VCODEC_X264:
4223 case HB_VCODEC_FFMPEG:
4229 case HB_VCODEC_THEORA:
4241 if (vquality < min || vquality > max)
4243 message = g_strdup_printf(
4244 "Interesting video quality choise: %d\n\n"
4245 "Typical values range from %d to %d.\n"
4246 "Are you sure you wish to use this setting?",
4247 (gint)vquality, min, max);
4248 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4249 "Cancel", "Continue"))
4261 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4266 static gchar *x264opts;
4268 gboolean tweaks = FALSE;
4269 gchar *detel_str = NULL;
4270 gchar *decomb_str = NULL;
4271 gchar *deint_str = NULL;
4272 gchar *deblock_str = NULL;
4273 gchar *denoise_str = NULL;
4274 gchar *dest_str = NULL;
4276 g_debug("add_job()\n");
4277 if (h == NULL) return;
4278 list = hb_get_titles( h );
4279 if( !hb_list_count( list ) )
4281 /* No valid title, stop right there */
4285 title = hb_list_item( list, titleindex );
4286 if (title == NULL) return;
4288 /* Set job settings */
4290 if (job == NULL) return;
4292 job->angle = ghb_settings_get_int(js, "angle");
4293 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4294 if (job->start_at_preview)
4296 job->seek_points = ghb_settings_get_int(js, "preview_count");
4297 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4300 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4301 job->mux = ghb_settings_combo_int(js, "FileFormat");
4302 if (job->mux == HB_MUX_MP4)
4304 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4305 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4309 job->largeFileSize = FALSE;
4310 job->mp4_optimize = FALSE;
4312 if (!job->start_at_preview)
4315 gint num_chapters = hb_list_count(title->list_chapter);
4316 gint duration = title->duration / 90000;
4317 job->chapter_start = 1;
4318 job->chapter_end = num_chapters;
4320 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4322 start = ghb_settings_get_int(js, "start_point");
4323 end = ghb_settings_get_int(js, "end_point");
4324 job->chapter_start = MIN( num_chapters, start );
4325 job->chapter_end = MAX( job->chapter_start, end );
4328 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4330 job->chapter_start = 1;
4331 job->chapter_end = num_chapters;
4332 start = ghb_settings_get_int(js, "start_point");
4333 end = ghb_settings_get_int(js, "end_point");
4334 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4335 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4338 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4340 job->chapter_start = 1;
4341 job->chapter_end = num_chapters;
4342 start = ghb_settings_get_int(js, "start_point");
4343 end = ghb_settings_get_int(js, "end_point");
4345 max_frames = (gint64)duration * title->rate / title->rate_base;
4346 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4347 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4348 job->frame_to_start;
4350 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4351 if (job->chapter_start == job->chapter_end)
4352 job->chapter_markers = 0;
4353 if ( job->chapter_markers )
4360 chapters = ghb_settings_get_value(js, "chapter_list");
4361 count = ghb_array_len(chapters);
4362 for(chap = 0; chap < count; chap++)
4364 hb_chapter_t * chapter_s;
4368 chapter = ghb_array_get_nth(chapters, chap);
4369 name = ghb_value_string(chapter);
4372 name = g_strdup_printf ("Chapter %2d", chap+1);
4374 chapter_s = hb_list_item( job->title->list_chapter, chap);
4375 strncpy(chapter_s->title, name, 1023);
4376 chapter_s->title[1023] = '\0';
4381 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4382 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4383 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4384 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4387 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4388 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4389 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4391 job->deinterlace = (deint != 0) ? 1 : 0;
4393 job->deinterlace = 0;
4394 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4396 gboolean keep_aspect;
4397 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4398 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4399 job->modulus = ghb_settings_combo_int(js, "PictureModulus");
4400 if (job->anamorphic.mode)
4402 job->anamorphic.par_width = title->pixel_aspect_width;
4403 job->anamorphic.par_height = title->pixel_aspect_height;
4404 job->anamorphic.dar_width = 0;
4405 job->anamorphic.dar_height = 0;
4407 if (job->anamorphic.mode == 3 && !keep_aspect)
4409 job->anamorphic.keep_display_aspect = 0;
4410 job->anamorphic.par_width =
4411 ghb_settings_get_int(js, "PicturePARWidth");
4412 job->anamorphic.par_height =
4413 ghb_settings_get_int(js, "PicturePARHeight");
4417 job->anamorphic.keep_display_aspect = 1;
4421 /* Add selected filters */
4422 job->filters = hb_list_init();
4423 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4428 if (detel_opts.map[detel].svalue != NULL)
4429 detel_str = g_strdup(detel_opts.map[detel].svalue);
4432 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4433 hb_filter_detelecine.settings = detel_str;
4434 hb_list_add( job->filters, &hb_filter_detelecine );
4436 if ( decomb_deint && decomb )
4440 if (decomb_opts.map[decomb].svalue != NULL)
4441 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4444 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4445 hb_filter_decomb.settings = decomb_str;
4446 hb_list_add( job->filters, &hb_filter_decomb );
4448 if( job->deinterlace )
4452 if (deint_opts.map[deint].svalue != NULL)
4453 deint_str = g_strdup(deint_opts.map[deint].svalue);
4456 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4457 hb_filter_deinterlace.settings = deint_str;
4458 hb_list_add( job->filters, &hb_filter_deinterlace );
4460 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4463 deblock_str = g_strdup_printf("%d", deblock);
4464 hb_filter_deblock.settings = deblock_str;
4465 hb_list_add( job->filters, &hb_filter_deblock );
4467 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4472 if (denoise_opts.map[denoise].svalue != NULL)
4473 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4476 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4477 hb_filter_denoise.settings = denoise_str;
4478 hb_list_add( job->filters, &hb_filter_denoise );
4480 job->width = ghb_settings_get_int(js, "scale_width");
4481 job->height = ghb_settings_get_int(js, "scale_height");
4483 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4484 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4486 // mp4/theora combination is not supported.
4487 job->vcodec = HB_VCODEC_FFMPEG;
4489 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4491 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4493 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4496 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4497 job->vquality = vquality;
4500 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4502 job->vquality = -1.0;
4503 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4506 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4509 job->vrate = title->rate;
4510 job->vrate_base = title->rate_base;
4515 job->vrate = 27000000;
4516 job->vrate_base = vrate;
4520 const GValue *audio_list;
4524 audio_list = ghb_settings_get_value(js, "audio_list");
4525 count = ghb_array_len(audio_list);
4526 for (ii = 0; ii < count; ii++)
4529 hb_audio_config_t audio;
4530 hb_audio_config_t *taudio;
4532 hb_audio_config_init(&audio);
4533 asettings = ghb_array_get_nth(audio_list, ii);
4534 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4535 audio.out.track = tcount;
4536 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4537 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4538 title->list_audio, audio.in.track );
4539 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4541 if (!(taudio->in.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4544 // AC3/DTS is passthrough only, so input must be AC3/DTS
4545 if (job->mux == HB_MUX_MKV)
4547 audio.out.codec = HB_ACODEC_LAME;
4551 audio.out.codec = HB_ACODEC_FAAC;
4556 audio.out.codec &= taudio->in.codec;
4559 if ((job->mux == HB_MUX_MP4) &&
4560 ((audio.out.codec & HB_ACODEC_DCA) ||
4561 (audio.out.codec & HB_ACODEC_VORBIS)))
4563 // mp4/mp3|dts|vorbis combination is not supported.
4564 audio.out.codec = HB_ACODEC_FAAC;
4566 audio.out.dynamic_range_compression =
4567 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4568 if (audio.out.dynamic_range_compression < 1.0)
4569 audio.out.dynamic_range_compression = 0.0;
4571 // It would be better if this were done in libhb for us, but its not yet.
4572 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4574 audio.out.mixdown = 0;
4580 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4581 if (audio.out.mixdown == HB_AMIXDOWN_MONO)
4583 else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
4588 // Make sure the mixdown is valid and pick a new one if not.
4589 audio.out.mixdown = ghb_get_best_mix(titleindex,
4590 audio.in.track, audio.out.codec, audio.out.mixdown);
4592 ghb_settings_combo_int(asettings, "AudioBitrate");
4593 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4594 if (srate == 0) // 0 is same as source
4595 audio.out.samplerate = taudio->in.samplerate;
4597 audio.out.samplerate = srate;
4599 audio.out.bitrate = ghb_get_best_audio_bitrate(
4600 audio.out.codec, audio.out.bitrate, channels);
4603 // Add it to the jobs audio list
4604 hb_audio_add( job, &audio );
4607 // I was tempted to move this up with the reset of the video quality
4608 // settings, but I suspect the settings above need to be made
4609 // first in order for hb_calc_bitrate to be accurate.
4610 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4614 size = ghb_settings_get_int(js, "VideoTargetSize");
4615 job->vbitrate = hb_calc_bitrate( job, size );
4616 job->vquality = -1.0;
4619 dest_str = ghb_settings_get_string(js, "destination");
4620 job->file = dest_str;
4622 const GValue *subtitle_list;
4624 gboolean force, burned, def, one_burned = FALSE;
4626 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4627 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4628 count = ghb_array_len(subtitle_list);
4629 for (ii = 0; ii < count; ii++)
4634 ssettings = ghb_array_get_nth(subtitle_list, ii);
4636 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4637 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4638 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4639 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4641 if (source == SRTSUB)
4643 hb_subtitle_config_t sub_config;
4644 gchar *filename, *lang, *code;
4646 filename = ghb_settings_get_string(ssettings, "SrtFile");
4647 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4651 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4652 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4653 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4654 strncpy(sub_config.src_filename, filename, 128);
4655 strncpy(sub_config.src_codeset, code, 40);
4656 sub_config.force = 0;
4657 sub_config.dest = PASSTHRUSUB;
4658 sub_config.default_track = def;
4660 hb_srt_add( job, &sub_config, lang);
4668 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4673 job->select_subtitle_config.dest = PASSTHRUSUB;
4677 // Only allow one subtitle to be burned into the video
4680 job->select_subtitle_config.dest = RENDERSUB;
4683 job->select_subtitle_config.force = force;
4684 job->select_subtitle_config.default_track = def;
4685 job->indepth_scan = 1;
4686 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4688 else if (subtitle >= 0)
4690 hb_subtitle_t * subt;
4691 hb_subtitle_config_t sub_config;
4693 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4696 sub_config = subt->config;
4697 if (!burned && subt->format == PICTURESUB)
4699 sub_config.dest = PASSTHRUSUB;
4701 else if ( burned && subt->format == PICTURESUB )
4703 // Only allow one subtitle to be burned into the video
4708 sub_config.force = force;
4709 sub_config.default_track = def;
4710 hb_subtitle_add( job, &sub_config, subtitle );
4715 // TODO: libhb holds onto a reference to the x264opts and is not
4716 // finished with it until encoding the job is done. But I can't
4717 // find a way to get at the job before it is removed in order to
4718 // free up the memory I am allocating here.
4719 // The short story is THIS LEAKS.
4720 x264opts = ghb_build_x264opts_string(js);
4722 if( *x264opts == '\0' )
4728 if (job->indepth_scan == 1)
4730 // Subtitle scan. Look for subtitle matching audio language
4733 * When subtitle scan is enabled do a fast pre-scan job
4734 * which will determine which subtitles to enable, if any.
4737 job->indepth_scan = 1;
4738 job->x264opts = NULL;
4741 * Add the pre-scan job
4743 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4747 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4748 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4751 * If subtitle_scan is enabled then only turn it on
4752 * for the second pass and then off again for the
4756 job->indepth_scan = 0;
4759 * If turbo options have been selected then append them
4760 * to the x264opts now (size includes one ':' and the '\0')
4762 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4764 gchar *tmp_x264opts;
4768 badapt = ghb_lookup_badapt(x264opts);
4771 extra_opts = g_strdup_printf("%s", turbo_opts);
4775 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4780 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4785 * No x264opts to modify, but apply the turbo options
4786 * anyway as they may be modifying defaults
4788 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4792 job->x264opts = tmp_x264opts;
4796 job->x264opts = x264opts;
4798 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4800 //if (job->x264opts != NULL)
4801 // g_free(job->x264opts);
4805 * On the second pass we turn off subtitle scan so that we
4806 * can actually encode using any subtitles that were auto
4807 * selected in the first pass (using the whacky select-subtitle
4808 * attribute of the job).
4810 job->indepth_scan = 0;
4811 job->x264opts = x264opts;
4812 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4814 //if (job->x264opts != NULL)
4815 // g_free(job->x264opts);
4819 job->x264opts = x264opts;
4820 job->indepth_scan = 0;
4822 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4824 //if (job->x264opts != NULL)
4825 // g_free(job->x264opts);
4828 // clean up audio list
4829 gint num_audio_tracks = hb_list_count(job->list_audio);
4830 for(ii = 0; ii < num_audio_tracks; ii++)
4832 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4833 hb_list_rem(job->list_audio, audio);
4837 // clean up subtitle list
4838 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4839 for(ii = 0; ii < num_subtitle_tracks; ii++)
4841 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4842 hb_list_rem(job->list_subtitle, subtitle);
4846 if (detel_str) g_free(detel_str);
4847 if (decomb_str) g_free(decomb_str);
4848 if (deint_str) g_free(deint_str);
4849 if (deblock_str) g_free(deblock_str);
4850 if (denoise_str) g_free(denoise_str);
4851 if (dest_str) g_free(dest_str);
4855 ghb_add_job(GValue *js, gint unique_id)
4857 // Since I'm doing a scan of the single title I want just prior
4858 // to adding the job, there is only the one title to choose from.
4859 add_job(h_queue, js, unique_id, 0);
4863 ghb_add_live_job(GValue *js, gint unique_id)
4865 // Since I'm doing a scan of the single title I want just prior
4866 // to adding the job, there is only the one title to choose from.
4867 gint titleindex = ghb_settings_combo_int(js, "title");
4868 add_job(h_scan, js, unique_id, titleindex);
4872 ghb_remove_job(gint unique_id)
4877 // Multiples passes all get the same id
4879 // Go backwards through list, so reordering doesn't screw me.
4880 ii = hb_count(h_queue) - 1;
4881 while ((job = hb_job(h_queue, ii--)) != NULL)
4883 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4884 hb_rem(h_queue, job);
4891 hb_start( h_queue );
4901 ghb_start_live_encode()
4907 ghb_stop_live_encode()
4916 hb_get_state2( h_queue, &s );
4918 if( s.state == HB_STATE_PAUSED )
4920 hb_status.queue.state &= ~GHB_STATE_PAUSED;
4921 hb_resume( h_queue );
4925 hb_status.queue.state |= GHB_STATE_PAUSED;
4926 hb_pause( h_queue );
4941 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4944 gint channels = gdk_pixbuf_get_n_channels (pb);
4945 gint stride = gdk_pixbuf_get_rowstride (pb);
4947 for (jj = 0; jj < width; jj++)
4949 dst = pixels + y * stride + (x+jj) * channels;
4950 for (ii = 0; ii < len; ii++)
4971 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4974 gint channels = gdk_pixbuf_get_n_channels (pb);
4975 gint stride = gdk_pixbuf_get_rowstride (pb);
4977 for (jj = 0; jj < width; jj++)
4979 dst = pixels + (y+jj) * stride + x * channels;
4980 for (ii = 0; ii < len; ii++)
5001 gint line_width = 8;
5008 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
5013 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
5015 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
5021 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
5023 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
5029 ghb_get_preview_image(
5032 signal_user_data_t *ud,
5040 settings = ud->settings;
5041 list = hb_get_titles( h_scan );
5042 if( !hb_list_count( list ) )
5044 /* No valid title, stop right there */
5047 title = hb_list_item( list, titleindex );
5048 if (title == NULL) return NULL;
5049 if (title->job == NULL) return NULL;
5050 set_preview_job_settings(title->job, settings);
5052 // hb_get_preview doesn't compensate for anamorphic, so lets
5053 // calculate scale factors
5054 gint width, height, par_width = 1, par_height = 1;
5055 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5058 hb_set_anamorphic_size( title->job, &width, &height,
5059 &par_width, &par_height );
5062 // Make sure we have a big enough buffer to receive the image from libhb
5063 gint dstWidth = title->job->width;
5064 gint dstHeight= title->job->height;
5066 static guint8 *buffer = NULL;
5067 static gint bufferSize = 0;
5070 newSize = dstWidth * dstHeight * 4;
5071 if( bufferSize < newSize )
5073 bufferSize = newSize;
5074 buffer = (guint8*) g_realloc( buffer, bufferSize );
5076 hb_get_preview( h_scan, title, index, buffer );
5078 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5079 // libhb's format something suitable.
5081 // The image data returned by hb_get_preview is 4 bytes per pixel,
5082 // BGRA format. Alpha is ignored.
5084 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5085 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5087 guint32 *src = (guint32*)buffer;
5088 guint8 *dst = pixels;
5091 gint channels = gdk_pixbuf_get_n_channels (preview);
5092 gint stride = gdk_pixbuf_get_rowstride (preview);
5095 for (ii = 0; ii < dstHeight; ii++)
5098 for (jj = 0; jj < dstWidth; jj++)
5100 tmp[0] = src[0] >> 16;
5101 tmp[1] = src[0] >> 8;
5102 tmp[2] = src[0] >> 0;
5108 gint w = ghb_settings_get_int(settings, "scale_width");
5109 gint h = ghb_settings_get_int(settings, "scale_height");
5110 ghb_par_scale(ud, &w, &h, par_width, par_height);
5112 gint c0, c1, c2, c3;
5113 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5114 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5115 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5116 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5118 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5119 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5121 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5124 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5128 gint orig_w, orig_h;
5131 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5135 ss = gdk_screen_get_default();
5136 s_w = gdk_screen_get_width(ss);
5137 s_h = gdk_screen_get_height(ss);
5141 if (dstWidth > s_w * factor / 100)
5143 dstWidth = s_w * factor / 100;
5144 dstHeight = dstHeight * dstWidth / orig_w;
5146 if (dstHeight > s_h * factor / 100)
5148 dstHeight = s_h * factor / 100;
5149 dstWidth = dstWidth * dstHeight / orig_h;
5151 xscale *= (gdouble)dstWidth / orig_w;
5152 yscale *= (gdouble)dstHeight / orig_h;
5153 w *= (gdouble)dstWidth / orig_w;
5154 h *= (gdouble)dstHeight / orig_h;
5156 GdkPixbuf *scaled_preview;
5157 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5158 if (ghb_settings_get_boolean(settings, "show_crop"))
5165 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5167 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5169 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5171 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5173 g_object_unref (preview);
5174 return scaled_preview;
5178 sanitize_volname(gchar *name)
5203 ghb_dvd_volname(const gchar *device)
5206 name = hb_dvd_name((gchar*)device);
5207 if (name != NULL && name[0] != 0)
5209 name = g_strdup(name);
5210 sanitize_volname(name);