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 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
739 const gchar *result = "";
741 str = ghb_value_string(gval);
742 for (ii = 0; ii < opts->count; ii++)
744 if (strcmp(opts->map[ii].shortOpt, str) == 0)
746 result = opts->map[ii].svalue;
755 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
761 str = ghb_value_string(gval);
762 for (ii = 0; ii < opts->count; ii++)
764 if (strcmp(opts->map[ii].shortOpt, str) == 0)
766 result = opts->map[ii].ivalue;
775 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
781 str = ghb_value_string(gval);
782 for (ii = 0; ii < opts->count; ii++)
784 if (strcmp(opts->map[ii].shortOpt, str) == 0)
786 result = opts->map[ii].ivalue;
795 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
799 const gchar *result = "";
801 str = ghb_value_string(gval);
802 for (ii = 0; ii < opts->count; ii++)
804 if (strcmp(opts->map[ii].shortOpt, str) == 0)
806 result = opts->map[ii].option;
815 lookup_mix_int(const GValue *mix)
822 str = ghb_value_string(mix);
823 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
825 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
827 result = hb_audio_mixdowns[ii].amixdown;
836 lookup_mix_option(const GValue *mix)
840 gchar *result = "None";
843 str = ghb_value_string(mix);
844 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
846 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
848 result = hb_audio_mixdowns[ii].human_readable_name;
857 lookup_video_rate_int(const GValue *vrate)
863 str = ghb_value_string(vrate);
864 for (ii = 0; ii < hb_video_rates_count; ii++)
866 if (strcmp(hb_video_rates[ii].string, str) == 0)
868 result = hb_video_rates[ii].rate;
873 // Default to "same as source"
878 lookup_video_rate_option(const GValue *vrate)
882 const gchar *result = "Same as source";
884 str = ghb_value_string(vrate);
885 for (ii = 0; ii < hb_video_rates_count; ii++)
887 if (strcmp(hb_video_rates[ii].string, str) == 0)
889 result = hb_video_rates[ii].string;
894 // Default to "same as source"
899 lookup_audio_rate_int(const GValue *rate)
905 // Coincidentally, the string "source" will return 0
906 // which is our flag to use "same as source"
907 str = ghb_value_string(rate);
908 for (ii = 0; ii < hb_audio_rates_count; ii++)
910 if (strcmp(hb_audio_rates[ii].string, str) == 0)
912 result = hb_audio_rates[ii].rate;
921 lookup_audio_rate_option(const GValue *rate)
925 const gchar *result = "Same as source";
927 // Coincidentally, the string "source" will return 0
928 // which is our flag to use "same as source"
929 str = ghb_value_string(rate);
930 for (ii = 0; ii < hb_audio_rates_count; ii++)
932 if (strcmp(hb_audio_rates[ii].string, str) == 0)
934 result = hb_audio_rates[ii].string;
943 ghb_find_closest_audio_bitrate(gint codec, gint rate)
950 if (codec == HB_ACODEC_FAAC)
954 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
956 if (hb_audio_bitrates[ii].rate < low)
958 if (hb_audio_bitrates[ii].rate > high)
960 if (rate <= hb_audio_bitrates[ii].rate)
962 result = hb_audio_bitrates[ii].rate;
970 lookup_audio_bitrate_int(const GValue *rate)
976 // Coincidentally, the string "source" will return 0
977 // which is our flag to use "same as source"
978 str = ghb_value_string(rate);
979 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
981 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
983 result = hb_audio_bitrates[ii].rate;
992 lookup_audio_bitrate_option(const GValue *rate)
996 const gchar *result = "Same as source";
998 // Coincidentally, the string "source" will return 0
999 // which is our flag to use "same as source"
1000 str = ghb_value_string(rate);
1001 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1003 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1005 result = hb_audio_bitrates[ii].string;
1014 lookup_audio_lang_int(const GValue *rate)
1020 // Coincidentally, the string "source" will return 0
1021 // which is our flag to use "same as source"
1022 str = ghb_value_string(rate);
1023 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1025 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1036 lookup_audio_lang_option(const GValue *rate)
1040 const gchar *result = "Same as source";
1042 // Coincidentally, the string "source" will return 0
1043 // which is our flag to use "same as source"
1044 str = ghb_value_string(rate);
1045 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1047 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1049 if (ghb_language_table[ii].native_name[0] != 0)
1050 result = ghb_language_table[ii].native_name;
1052 result = ghb_language_table[ii].eng_name;
1061 ghb_lookup_acodec_value(gint val)
1063 GValue *value = NULL;
1066 for (ii = 0; ii < acodec_opts.count; ii++)
1068 if ((int)acodec_opts.map[ii].ivalue == val)
1070 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1078 get_amix_value(gint val)
1080 GValue *value = NULL;
1083 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1085 if (hb_audio_mixdowns[ii].amixdown == val)
1087 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1094 // Handle for libhb. Gets set by ghb_backend_init()
1095 static hb_handle_t * h_scan = NULL;
1096 static hb_handle_t * h_queue = NULL;
1098 extern void hb_get_temporary_directory(char path[512]);
1105 hb_get_temporary_directory(dir);
1106 return g_strdup(dir);
1110 ghb_hb_cleanup(gboolean partial)
1114 hb_get_temporary_directory(dir);
1115 del_tree(dir, !partial);
1119 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1127 titleindex = ghb_settings_combo_int(ud->settings, "title");
1133 hb_subtitle_t * sub;
1135 if (h_scan == NULL) return VOBSUB;
1136 list = hb_get_titles( h_scan );
1137 if( !hb_list_count( list ) )
1139 /* No valid title, stop right there */
1142 title = hb_list_item( list, titleindex );
1143 if (title == NULL) return VOBSUB; // Bad titleindex
1144 sub = hb_list_item( title->list_subtitle, track);
1152 ghb_subtitle_source_name(gint source)
1154 const gchar * name = "Unknown";
1183 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1186 const gchar * name = "Unknown";
1199 titleindex = ghb_settings_combo_int(ud->settings, "title");
1205 hb_subtitle_t * sub;
1209 list = hb_get_titles( h_scan );
1210 if( !hb_list_count( list ) )
1213 title = hb_list_item( list, titleindex );
1217 sub = hb_list_item( title->list_subtitle, track);
1220 name = ghb_subtitle_source_name(sub->source);
1228 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1232 titleindex = ghb_settings_combo_int(ud->settings, "title");
1236 return ghb_get_user_audio_lang(ud, titleindex, 0);
1242 hb_subtitle_t * sub;
1247 list = hb_get_titles( h_scan );
1248 if( !hb_list_count( list ) )
1250 /* No valid title, stop right there */
1253 title = hb_list_item( list, titleindex );
1254 if (title == NULL) // Bad titleindex
1256 sub = hb_list_item( title->list_subtitle, track);
1258 return g_strdup(sub->iso639_2);
1261 return g_strdup("und");
1265 ghb_get_title_number(gint titleindex)
1270 if (h_scan == NULL) return 1;
1271 list = hb_get_titles( h_scan );
1272 if( !hb_list_count( list ) )
1274 /* No valid title, stop right there */
1277 title = hb_list_item( list, titleindex );
1278 if (title == NULL) return 1; // Bad titleindex
1279 return title->index;
1282 static hb_audio_config_t*
1283 get_hb_audio(gint titleindex, gint track)
1287 hb_audio_config_t *audio = NULL;
1289 if (h_scan == NULL) return NULL;
1290 list = hb_get_titles( h_scan );
1291 if( !hb_list_count( list ) )
1293 /* No valid title, stop right there */
1296 title = hb_list_item( list, titleindex );
1297 if (title == NULL) return NULL; // Bad titleindex
1298 if (!hb_list_count(title->list_audio))
1302 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1307 search_rates(hb_rate_t *rates, gint rate, gint count)
1310 for (ii = 0; ii < count; ii++)
1312 if (rates[ii].rate == rate)
1318 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1320 static GtkListStore*
1321 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1324 GtkListStore *store;
1326 g_debug("get_combo_box_store() %s\n", name);
1327 // First modify the combobox model to allow greying out of options
1328 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1329 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1334 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1336 GtkListStore *store;
1339 store = get_combo_box_store(builder, name);
1340 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1342 gtk_list_store_set(store, &iter,
1349 ghb_grey_combo_options(GtkBuilder *builder)
1352 gint container, track, titleindex, acodec;
1353 hb_audio_config_t *audio = NULL;
1356 widget = GHB_WIDGET (builder, "title");
1357 gval = ghb_widget_value(widget);
1358 titleindex = ghb_lookup_combo_int("title", gval);
1359 ghb_value_free(gval);
1360 widget = GHB_WIDGET (builder, "AudioTrack");
1361 gval = ghb_widget_value(widget);
1362 track = ghb_lookup_combo_int("AudioTrack", gval);
1363 ghb_value_free(gval);
1364 audio = get_hb_audio(titleindex, track);
1365 widget = GHB_WIDGET (builder, "FileFormat");
1366 gval = ghb_widget_value(widget);
1367 container = ghb_lookup_combo_int("FileFormat", gval);
1368 ghb_value_free(gval);
1370 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1371 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1372 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1373 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1375 gboolean allow_dca = TRUE;
1376 allow_dca = (container != HB_MUX_MP4);
1378 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1380 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1382 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1384 if (audio && audio->in.codec != HB_ACODEC_AC3)
1386 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1388 if (audio && audio->in.codec != HB_ACODEC_DCA)
1390 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1392 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1394 widget = GHB_WIDGET (builder, "AudioEncoder");
1395 gval = ghb_widget_value(widget);
1396 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1397 ghb_value_free(gval);
1398 if (acodec != HB_ACODEC_AC3)
1400 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1402 if (container == HB_MUX_MP4)
1404 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1405 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1408 gboolean allow_mono = TRUE;
1409 gboolean allow_stereo = TRUE;
1410 gboolean allow_dolby = TRUE;
1411 gboolean allow_dpl2 = TRUE;
1412 gboolean allow_6ch = TRUE;
1414 allow_6ch = acodec & ~HB_ACODEC_LAME;
1417 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1419 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1421 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1422 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1423 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1424 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1425 allow_6ch = allow_6ch &&
1426 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1427 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1429 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1430 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1431 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1432 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1433 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1437 ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
1439 if (acodec & HB_ACODEC_FAAC)
1454 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1456 hb_audio_config_t *audio = NULL;
1457 gboolean allow_mono = TRUE;
1458 gboolean allow_stereo = TRUE;
1459 gboolean allow_dolby = TRUE;
1460 gboolean allow_dpl2 = TRUE;
1461 gboolean allow_6ch = TRUE;
1463 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1465 // Audio codec pass-thru. No mixdown
1468 audio = get_hb_audio(titleindex, track);
1472 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1474 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1476 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1477 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1478 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1479 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1481 (acodec & ~HB_ACODEC_LAME) &&
1482 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1483 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1485 gboolean greater = FALSE;
1488 // If no mix is specified, select the best available.
1489 mix = HB_AMIXDOWN_6CH;
1491 if (mix == HB_AMIXDOWN_6CH)
1494 if (allow_6ch) return HB_AMIXDOWN_6CH;
1496 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1499 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1501 if (mix == HB_AMIXDOWN_DOLBY || greater)
1504 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1506 if (mix == HB_AMIXDOWN_STEREO || greater)
1509 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1511 if (mix == HB_AMIXDOWN_MONO || greater)
1514 if (allow_mono) return HB_AMIXDOWN_MONO;
1516 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1517 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1518 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1519 if (allow_6ch) return HB_AMIXDOWN_6CH;
1523 // Set up the model for the combo box
1525 init_combo_box(GtkBuilder *builder, const gchar *name)
1528 GtkListStore *store;
1529 GtkCellRenderer *cell;
1531 g_debug("init_combo_box() %s\n", name);
1532 // First modify the combobox model to allow greying out of options
1533 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1537 // 1 - String to display
1538 // 2 - bool indicating whether the entry is selectable (grey or not)
1539 // 3 - String that is used for presets
1540 // 4 - Int value determined by backend
1541 // 5 - String value determined by backend
1542 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1543 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1544 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1546 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1548 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1549 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1550 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1551 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1552 "markup", 0, "sensitive", 1, NULL);
1555 { // Combo box entry
1556 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1561 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1564 GtkListStore *store;
1568 g_debug("audio_samplerate_opts_set ()\n");
1569 store = get_combo_box_store(builder, name);
1570 gtk_list_store_clear(store);
1571 // Add an item for "Same As Source"
1572 gtk_list_store_append(store, &iter);
1573 gtk_list_store_set(store, &iter,
1574 0, "<small>Same as source</small>",
1580 for (ii = 0; ii < count; ii++)
1582 gtk_list_store_append(store, &iter);
1583 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1584 gtk_list_store_set(store, &iter,
1587 2, rates[ii].string,
1588 3, (gdouble)rates[ii].rate,
1589 4, rates[ii].string,
1596 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1599 GtkListStore *store;
1602 g_debug("video_rate_opts_set ()\n");
1603 store = get_combo_box_store(builder, name);
1604 gtk_list_store_clear(store);
1605 // Add an item for "Same As Source"
1606 gtk_list_store_append(store, &iter);
1607 gtk_list_store_set(store, &iter,
1608 0, "Same as source",
1614 for (ii = 0; ii < count; ii++)
1618 if (strcmp(rates[ii].string, "23.976") == 0)
1620 desc = "(NTSC Film)";
1622 else if (strcmp(rates[ii].string, "25") == 0)
1624 desc = "(PAL Film/Video)";
1626 else if (strcmp(rates[ii].string, "29.97") == 0)
1628 desc = "(NTSC Video)";
1630 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1631 gtk_list_store_append(store, &iter);
1632 gtk_list_store_set(store, &iter,
1635 2, rates[ii].string,
1636 3, (gdouble)rates[ii].rate,
1637 4, rates[ii].string,
1644 mix_opts_set(GtkBuilder *builder, const gchar *name)
1647 GtkListStore *store;
1651 g_debug("mix_opts_set ()\n");
1652 store = get_combo_box_store(builder, name);
1653 gtk_list_store_clear(store);
1654 gtk_list_store_append(store, &iter);
1655 gtk_list_store_set(store, &iter,
1656 0, "<small>None</small>",
1662 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1664 gtk_list_store_append(store, &iter);
1665 str = g_strdup_printf("<small>%s</small>",
1666 hb_audio_mixdowns[ii].human_readable_name);
1667 gtk_list_store_set(store, &iter,
1670 2, hb_audio_mixdowns[ii].short_name,
1671 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1672 4, hb_audio_mixdowns[ii].internal_name,
1679 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1682 GtkListStore *store;
1685 g_debug("srt_codeset_opts_set ()\n");
1686 store = get_combo_box_store(builder, name);
1687 gtk_list_store_clear(store);
1688 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1690 gtk_list_store_append(store, &iter);
1691 gtk_list_store_set(store, &iter,
1692 0, srt_codeset_table[ii],
1694 2, srt_codeset_table[ii],
1696 4, srt_codeset_table[ii],
1699 GtkComboBoxEntry *cbe;
1701 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1702 //gtk_combo_box_entry_set_text_column(cbe, 0);
1706 language_opts_set(GtkBuilder *builder, const gchar *name)
1709 GtkListStore *store;
1712 g_debug("language_opts_set ()\n");
1713 store = get_combo_box_store(builder, name);
1714 gtk_list_store_clear(store);
1715 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1719 if (ghb_language_table[ii].native_name[0] != 0)
1720 lang = ghb_language_table[ii].native_name;
1722 lang = ghb_language_table[ii].eng_name;
1724 gtk_list_store_append(store, &iter);
1725 gtk_list_store_set(store, &iter,
1728 2, ghb_language_table[ii].iso639_2,
1730 4, ghb_language_table[ii].iso639_1,
1735 static gchar **titles = NULL;
1738 title_opts_set(GtkBuilder *builder, const gchar *name)
1741 GtkListStore *store;
1742 hb_list_t * list = NULL;
1743 hb_title_t * title = NULL;
1747 g_debug("title_opts_set ()\n");
1748 store = get_combo_box_store(builder, name);
1749 gtk_list_store_clear(store);
1752 list = hb_get_titles( h_scan );
1753 count = hb_list_count( list );
1754 if (count > 100) count = 100;
1756 if (titles) g_strfreev(titles);
1757 if (title_opts.map) g_free(title_opts.map);
1760 title_opts.count = count;
1761 title_opts.map = g_malloc(count*sizeof(options_map_t));
1762 titles = g_malloc((count+1) * sizeof(gchar*));
1766 title_opts.count = 1;
1767 title_opts.map = g_malloc(sizeof(options_map_t));
1772 // No titles. Fill in a default.
1773 gtk_list_store_append(store, &iter);
1774 gtk_list_store_set(store, &iter,
1781 title_opts.map[0].option = "No Titles";
1782 title_opts.map[0].shortOpt = "none";
1783 title_opts.map[0].ivalue = -1;
1784 title_opts.map[0].svalue = "none";
1787 for (ii = 0; ii < count; ii++)
1789 title = (hb_title_t*)hb_list_item(list, ii);
1790 if (title->type == HB_STREAM_TYPE)
1792 if (title->duration != 0)
1794 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
1795 title->index, title->hours, title->minutes, title->seconds,
1800 titles[ii] = g_strdup_printf ("%d - %s",
1801 title->index, title->name);
1806 if (title->duration != 0)
1808 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1809 title->index, title->hours, title->minutes, title->seconds);
1813 titles[ii] = g_strdup_printf ("%d - Unknown Length",
1817 gtk_list_store_append(store, &iter);
1818 gtk_list_store_set(store, &iter,
1825 title_opts.map[ii].option = titles[ii];
1826 title_opts.map[ii].shortOpt = titles[ii];
1827 title_opts.map[ii].ivalue = ii;
1828 title_opts.map[ii].svalue = titles[ii];
1834 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1837 gboolean foundit = FALSE;
1839 if (gtk_tree_model_get_iter_first (store, iter))
1843 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1844 if (value == (int)ivalue)
1849 } while (gtk_tree_model_iter_next (store, iter));
1855 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1858 GtkListStore *store;
1859 hb_list_t * list = NULL;
1860 hb_title_t * title = NULL;
1861 hb_audio_config_t * audio;
1866 g_debug("audio_track_opts_set ()\n");
1867 store = get_combo_box_store(builder, name);
1868 gtk_list_store_clear(store);
1871 list = hb_get_titles( h_scan );
1872 title = (hb_title_t*)hb_list_item( list, titleindex );
1875 count = hb_list_count( title->list_audio );
1878 if (count > 100) count = 100;
1879 if (audio_track_opts.map) g_free(audio_track_opts.map);
1882 audio_track_opts.count = count;
1883 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1887 audio_track_opts.count = 1;
1888 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1892 // No audio. set some default
1893 gtk_list_store_append(store, &iter);
1894 gtk_list_store_set(store, &iter,
1895 0, "<small>No Audio</small>",
1901 audio_track_opts.map[0].option = "No Audio";
1902 audio_track_opts.map[0].shortOpt = "none";
1903 audio_track_opts.map[0].ivalue = -1;
1904 audio_track_opts.map[0].svalue = "none";
1907 index_str_init(count-1);
1908 for (ii = 0; ii < count; ii++)
1910 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1911 gtk_list_store_append(store, &iter);
1912 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
1913 gtk_list_store_set(store, &iter,
1921 audio_track_opts.map[ii].option = audio->lang.description,
1922 audio_track_opts.map[ii].shortOpt = index_str[ii];
1923 audio_track_opts.map[ii].ivalue = ii;
1924 audio_track_opts.map[ii].svalue = index_str[ii];
1929 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1932 GtkListStore *store;
1933 hb_list_t * list = NULL;
1934 hb_title_t * title = NULL;
1935 hb_subtitle_t * subtitle;
1937 static char ** options = NULL;
1939 g_debug("subtitle_track_opts_set ()\n");
1940 store = get_combo_box_store(builder, name);
1941 gtk_list_store_clear(store);
1944 list = hb_get_titles( h_scan );
1945 title = (hb_title_t*)hb_list_item( list, titleindex );
1948 count = hb_list_count( title->list_subtitle );
1951 if (count > 100) count = 100;
1952 if (subtitle_opts.map) g_free(subtitle_opts.map);
1955 subtitle_opts.count = count+1;
1956 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1960 subtitle_opts.count = LANG_TABLE_SIZE+1;
1961 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1963 gtk_list_store_append(store, &iter);
1964 gtk_list_store_set(store, &iter,
1965 0, "Foreign Audio Search",
1971 subtitle_opts.map[0].option = "Foreign Audio Search";
1972 subtitle_opts.map[0].shortOpt = "-1";
1973 subtitle_opts.map[0].ivalue = -1;
1974 subtitle_opts.map[0].svalue = "auto";
1977 if (options != NULL)
1978 g_strfreev(options);
1979 options = g_malloc((count+1)*sizeof(gchar*));
1980 index_str_init(count-1);
1981 for (ii = 0; ii < count; ii++)
1983 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1984 // Skip subtitles that must be burned if there is already
1985 // a burned subtitle in the list
1987 if (subtitle->source == VOBSUB)
1989 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1994 options[ii] = g_strdup_printf("%d - %s (%s)", ii+1,
1996 ghb_subtitle_source_name(subtitle->source));
1998 subtitle_opts.map[ii+1].option = options[ii];
1999 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2000 subtitle_opts.map[ii+1].ivalue = ii;
2001 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
2002 gtk_list_store_append(store, &iter);
2003 gtk_list_store_set(store, &iter,
2008 4, subtitle->iso639_2,
2011 options[count] = NULL;
2015 index_str_init(LANG_TABLE_SIZE-1);
2016 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
2020 if (ghb_language_table[ii].native_name[0] != 0)
2021 lang = ghb_language_table[ii].native_name;
2023 lang = ghb_language_table[ii].eng_name;
2025 subtitle_opts.map[ii+1].option = lang;
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 = ghb_language_table[ii].iso639_2;
2029 gtk_list_store_append(store, &iter);
2030 gtk_list_store_set(store, &iter,
2035 4, ghb_language_table[ii].iso639_2,
2048 gint titleindex = 0;
2051 g_debug("ghb_longest_title ()\n");
2052 if (h_scan == NULL) return 0;
2053 list = hb_get_titles( h_scan );
2054 count = hb_list_count( list );
2055 if (count > 100) count = 100;
2056 if (count < 1) return 0;
2057 title = (hb_title_t*)hb_list_item(list, 0);
2058 feature = title->job->feature;
2059 for (ii = 0; ii < count; ii++)
2061 title = (hb_title_t*)hb_list_item(list, ii);
2062 if (title->index == feature)
2071 ghb_get_source_audio_lang(gint titleindex, gint track)
2075 hb_audio_config_t * audio;
2078 g_debug("ghb_lookup_1st_audio_lang ()\n");
2081 list = hb_get_titles( h_scan );
2082 title = (hb_title_t*)hb_list_item( list, titleindex );
2085 if (hb_list_count( title->list_audio ) <= track)
2088 audio = hb_list_audio_config_item(title->list_audio, track);
2092 lang = g_strdup(audio->lang.iso639_2);
2097 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2101 used = g_hash_table_lookup(track_indices, &acodec);
2106 used = g_malloc0(count * sizeof(gboolean));
2107 key = g_malloc(sizeof(gint));
2109 g_hash_table_insert(track_indices, key, used);
2115 ghb_find_audio_track(
2119 gint fallback_acodec,
2120 GHashTable *track_indices)
2124 hb_audio_config_t * audio;
2129 gboolean *used = NULL;
2130 gboolean *passthru_used;
2132 gint passthru_acodec;
2135 g_debug("find_audio_track ()\n");
2136 if (h_scan == NULL) return -1;
2137 list = hb_get_titles( h_scan );
2138 title = (hb_title_t*)hb_list_item( list, titleindex );
2141 count = hb_list_count( title->list_audio );
2143 if (count > 10) count = 10;
2144 // Try to find an item that matches the preferred language and
2145 // the passthru codec type
2146 passthru = (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)) != 0;
2149 for (ii = 0; ii < count; ii++)
2153 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2154 title->list_audio, ii );
2155 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2156 // Is the source track use a passthru capable codec?
2157 if (passthru_acodec == 0)
2159 used = get_track_used(passthru_acodec, track_indices, count);
2160 // Has the track already been used with this codec?
2164 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2165 audio->in.channel_layout);
2166 // Find a track that is not visually impaired or dirctor's
2167 // commentary, and has the highest channel count.
2168 if ((audio->lang.type < 2) &&
2169 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2170 (strcmp(lang, "und") == 0)))
2172 if (channels > max_chan)
2175 max_chan = channels;
2179 try_acodec = fallback_acodec;
2183 try_acodec = acodec;
2190 // Try to find an item that matches the preferred language
2191 used = get_track_used(try_acodec, track_indices, count);
2192 for (ii = 0; ii < count; ii++)
2194 // Has the track already been used with this codec?
2197 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2198 title->list_audio, ii );
2199 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2200 if (passthru_acodec && passthru)
2202 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2203 // Has the track already been used with this codec for passthru?
2204 if (passthru_used[ii])
2207 // Find a track that is not visually impaired or dirctor's commentary
2208 if ((audio->lang.type < 2) &&
2209 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2210 (strcmp(lang, "und") == 0)))
2221 // Try to fine an item that does not match the preferred language and
2222 // matches the passthru codec type
2225 for (ii = 0; ii < count; ii++)
2229 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2230 title->list_audio, ii );
2231 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2232 // Is the source track use a passthru capable codec?
2233 if (passthru_acodec == 0)
2235 used = get_track_used(passthru_acodec, track_indices, count);
2236 // Has the track already been used with this codec?
2240 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2241 audio->in.channel_layout);
2242 // Find a track that is not visually impaired or dirctor's
2243 // commentary, and has the highest channel count.
2244 if (audio->lang.type < 2)
2246 if (channels > max_chan)
2249 max_chan = channels;
2253 try_acodec = fallback_acodec;
2257 try_acodec = acodec;
2264 // Try to fine an item that does not match the preferred language
2265 used = get_track_used(try_acodec, track_indices, count);
2266 for (ii = 0; ii < count; ii++)
2268 // Has the track already been used with this codec?
2271 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2272 title->list_audio, ii );
2273 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2274 if (passthru_acodec && passthru)
2276 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2277 // Has the track already been used with this codec for passthru?
2278 if (passthru_used[ii])
2281 // Find a track that is not visually impaired or dirctor's commentary
2282 if (audio->lang.type < 2)
2293 // Last ditch, anything goes
2294 for (ii = 0; ii < count; ii++)
2296 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2297 title->list_audio, ii );
2298 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2299 if (passthru_acodec && passthru)
2301 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2302 // Has the track already been used with this codec for passthru?
2303 if (passthru_used[ii])
2306 // Has the track already been used with this codec?
2321 ghb_find_pref_subtitle_track(const gchar *lang)
2324 count = subtitle_opts.count;
2325 for (ii = 0; ii < count; ii++)
2327 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2329 return subtitle_opts.map[ii].ivalue;
2336 ghb_find_cc_track(gint titleindex)
2340 hb_subtitle_t * subtitle;
2343 g_debug("ghb_find_cc_track ()\n");
2344 if (h_scan == NULL) return -2;
2345 list = hb_get_titles( h_scan );
2346 title = (hb_title_t*)hb_list_item( list, titleindex );
2349 count = hb_list_count( title->list_subtitle );
2350 // Try to find an item that matches the preferred language
2351 for (ii = 0; ii < count; ii++)
2353 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2354 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2362 ghb_find_subtitle_track(
2368 GHashTable * track_indices)
2372 hb_subtitle_t * subtitle;
2376 g_debug("find_subtitle_track ()\n");
2377 if (strcmp(lang, "auto") == 0)
2379 if (h_scan == NULL) return -1;
2380 list = hb_get_titles( h_scan );
2381 title = (hb_title_t*)hb_list_item( list, titleindex );
2384 count = hb_list_count( title->list_subtitle );
2385 used = g_hash_table_lookup(track_indices, lang);
2388 used = g_malloc0(count * sizeof(gboolean));
2389 g_hash_table_insert(track_indices, g_strdup(lang), used);
2391 // Try to find an item that matches the preferred language and source
2392 for (ii = 0; ii < count; ii++)
2397 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2398 if (source == subtitle->source &&
2399 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2400 (strcmp(lang, "und") == 0)))
2406 // Try to find an item that matches the preferred language
2407 for (ii = 0; ii < count; ii++)
2412 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2413 if ((!(burn || force) || (subtitle->source == VOBSUB)) &&
2414 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2415 (strcmp(lang, "und") == 0)))
2426 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2429 GtkListStore *store;
2432 g_debug("generic_opts_set ()\n");
2433 if (name == NULL || opts == NULL) return;
2434 store = get_combo_box_store(builder, name);
2435 gtk_list_store_clear(store);
2436 for (ii = 0; ii < opts->count; ii++)
2438 gtk_list_store_append(store, &iter);
2439 gtk_list_store_set(store, &iter,
2440 0, opts->map[ii].option,
2442 2, opts->map[ii].shortOpt,
2443 3, opts->map[ii].ivalue,
2444 4, opts->map[ii].svalue,
2450 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2453 GtkListStore *store;
2457 g_debug("generic_opts_set ()\n");
2458 if (name == NULL || opts == NULL) return;
2459 store = get_combo_box_store(builder, name);
2460 gtk_list_store_clear(store);
2461 for (ii = 0; ii < opts->count; ii++)
2463 gtk_list_store_append(store, &iter);
2464 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2465 gtk_list_store_set(store, &iter,
2468 2, opts->map[ii].shortOpt,
2469 3, opts->map[ii].ivalue,
2470 4, opts->map[ii].svalue,
2477 find_combo_table(const gchar *name)
2481 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2483 if (strcmp(name, combo_name_map[ii].name) == 0)
2485 return combo_name_map[ii].opts;
2492 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2496 if (strcmp(name, "AudioBitrate") == 0)
2497 return lookup_audio_bitrate_int(gval);
2498 else if (strcmp(name, "AudioSamplerate") == 0)
2499 return lookup_audio_rate_int(gval);
2500 else if (strcmp(name, "VideoFramerate") == 0)
2501 return lookup_video_rate_int(gval);
2502 else if (strcmp(name, "AudioMixdown") == 0)
2503 return lookup_mix_int(gval);
2504 else if (strcmp(name, "SrtLanguage") == 0)
2505 return lookup_audio_lang_int(gval);
2506 else if (strcmp(name, "PreferredLanguage") == 0)
2507 return lookup_audio_lang_int(gval);
2510 return lookup_generic_int(find_combo_table(name), gval);
2512 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2517 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2521 if (strcmp(name, "AudioBitrate") == 0)
2522 return lookup_audio_bitrate_int(gval);
2523 else if (strcmp(name, "AudioSamplerate") == 0)
2524 return lookup_audio_rate_int(gval);
2525 else if (strcmp(name, "VideoFramerate") == 0)
2526 return lookup_video_rate_int(gval);
2527 else if (strcmp(name, "AudioMixdown") == 0)
2528 return lookup_mix_int(gval);
2529 else if (strcmp(name, "SrtLanguage") == 0)
2530 return lookup_audio_lang_int(gval);
2531 else if (strcmp(name, "PreferredLanguage") == 0)
2532 return lookup_audio_lang_int(gval);
2535 return lookup_generic_double(find_combo_table(name), gval);
2537 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2542 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2546 if (strcmp(name, "AudioBitrate") == 0)
2547 return lookup_audio_bitrate_option(gval);
2548 else if (strcmp(name, "AudioSamplerate") == 0)
2549 return lookup_audio_rate_option(gval);
2550 else if (strcmp(name, "VideoFramerate") == 0)
2551 return lookup_video_rate_option(gval);
2552 else if (strcmp(name, "AudioMixdown") == 0)
2553 return lookup_mix_option(gval);
2554 else if (strcmp(name, "SrtLanguage") == 0)
2555 return lookup_audio_lang_option(gval);
2556 else if (strcmp(name, "PreferredLanguage") == 0)
2557 return lookup_audio_lang_option(gval);
2560 return lookup_generic_option(find_combo_table(name), gval);
2562 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2567 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2571 if (strcmp(name, "AudioBitrate") == 0)
2572 return lookup_audio_bitrate_option(gval);
2573 else if (strcmp(name, "AudioSamplerate") == 0)
2574 return lookup_audio_rate_option(gval);
2575 else if (strcmp(name, "VideoFramerate") == 0)
2576 return lookup_video_rate_option(gval);
2577 else if (strcmp(name, "AudioMixdown") == 0)
2578 return lookup_mix_option(gval);
2579 else if (strcmp(name, "SrtLanguage") == 0)
2580 return lookup_audio_lang_option(gval);
2581 else if (strcmp(name, "PreferredLanguage") == 0)
2582 return lookup_audio_lang_option(gval);
2585 return lookup_generic_string(find_combo_table(name), gval);
2587 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2592 ghb_update_ui_combo_box(
2593 signal_user_data_t *ud,
2598 GtkComboBox *combo = NULL;
2600 gint handler_id = 0;
2604 g_debug("ghb_update_ui_combo_box() %s\n", name);
2605 // Clearing a combo box causes a rash of "changed" events, even when
2606 // the active item is -1 (inactive). To control things, I'm disabling
2607 // the event till things are settled down.
2608 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2609 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2612 // Valid signal id found. This should always succeed.
2613 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2614 signal_id, 0, 0, 0, 0);
2617 // This should also always succeed
2618 g_signal_handler_block ((gpointer)combo, handler_id);
2624 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2625 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2626 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2627 mix_opts_set(ud->builder, "AudioMixdown");
2628 language_opts_set(ud->builder, "SrtLanguage");
2629 language_opts_set(ud->builder, "PreferredLanguage");
2630 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2631 title_opts_set(ud->builder, "title");
2632 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2633 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2634 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2635 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2636 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2637 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2638 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2639 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2640 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2641 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2642 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2643 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2644 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2645 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2646 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2647 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2648 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2649 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2650 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2651 generic_opts_set(ud->builder, "x264_me", &me_opts);
2652 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2653 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2654 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2658 if (strcmp(name, "AudioBitrate") == 0)
2659 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2660 else if (strcmp(name, "AudioSamplerate") == 0)
2661 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2662 else if (strcmp(name, "VideoFramerate") == 0)
2663 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2664 else if (strcmp(name, "AudioMixdown") == 0)
2665 mix_opts_set(ud->builder, "AudioMixdown");
2666 else if (strcmp(name, "SrtLanguage") == 0)
2667 language_opts_set(ud->builder, "SrtLanguage");
2668 else if (strcmp(name, "PreferredLanguage") == 0)
2669 language_opts_set(ud->builder, "PreferredLanguage");
2670 else if (strcmp(name, "SrtCodeset") == 0)
2671 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2672 else if (strcmp(name, "title") == 0)
2673 title_opts_set(ud->builder, "title");
2674 else if (strcmp(name, "SubtitleTrack") == 0)
2675 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2676 else if (strcmp(name, "AudioTrack") == 0)
2677 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2679 generic_opts_set(ud->builder, name, find_combo_table(name));
2683 g_signal_handler_unblock ((gpointer)combo, handler_id);
2688 init_ui_combo_boxes(GtkBuilder *builder)
2692 init_combo_box(builder, "AudioBitrate");
2693 init_combo_box(builder, "AudioSamplerate");
2694 init_combo_box(builder, "VideoFramerate");
2695 init_combo_box(builder, "AudioMixdown");
2696 init_combo_box(builder, "SrtLanguage");
2697 init_combo_box(builder, "PreferredLanguage");
2698 init_combo_box(builder, "SrtCodeset");
2699 init_combo_box(builder, "title");
2700 init_combo_box(builder, "AudioTrack");
2701 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2703 init_combo_box(builder, combo_name_map[ii].name);
2707 static const char * turbo_opts =
2708 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2709 "no-fast-pskip=0:8x8dct=0";
2711 // Construct the x264 options string
2712 // The result is allocated, so someone must free it at some point.
2714 ghb_build_x264opts_string(GValue *settings)
2717 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2724 result = g_strdup("");
2730 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2734 hb_chapter_t * chapter;
2738 *hh = *mm = *ss = 0;
2739 if (h_scan == NULL) return;
2740 list = hb_get_titles( h_scan );
2741 title = (hb_title_t*)hb_list_item( list, tt );
2742 if (title == NULL) return;
2745 *mm = title->minutes;
2746 *ss = title->seconds;
2748 count = hb_list_count(title->list_chapter);
2749 if (sc > count) sc = count;
2750 if (ec > count) ec = count;
2752 if (sc == 1 && ec == count)
2756 for (c = sc; c <= ec; c++)
2758 chapter = hb_list_item(title->list_chapter, c-1);
2759 duration += chapter->duration;
2762 *hh = duration / 90000 / 3600;
2763 *mm = ((duration / 90000) % 3600) / 60;
2764 *ss = (duration / 90000) % 60;
2768 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2772 hb_chapter_t * chapter;
2775 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2776 *hh = *mm = *ss = 0;
2777 if (h_scan == NULL) return;
2778 list = hb_get_titles( h_scan );
2779 title = (hb_title_t*)hb_list_item( list, ti );
2780 if (title == NULL) return;
2781 count = hb_list_count( title->list_chapter );
2782 if (ii >= count) return;
2783 chapter = hb_list_item(title->list_chapter, ii);
2784 if (chapter == NULL) return;
2785 *hh = chapter->hours;
2786 *mm = chapter->minutes;
2787 *ss = chapter->seconds;
2791 ghb_get_chapters(gint titleindex)
2795 hb_chapter_t * chapter;
2797 GValue *chapters = NULL;
2799 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2800 if (h_scan == NULL) return NULL;
2801 list = hb_get_titles( h_scan );
2802 title = (hb_title_t*)hb_list_item( list, titleindex );
2803 if (title == NULL) return NULL;
2804 count = hb_list_count( title->list_chapter );
2805 chapters = ghb_array_value_new(count);
2806 for (ii = 0; ii < count; ii++)
2808 chapter = hb_list_item(title->list_chapter, ii);
2809 if (chapter == NULL) break;
2810 if (chapter->title == NULL || chapter->title[0] == 0)
2813 str = g_strdup_printf ("Chapter %2d", ii+1);
2814 ghb_array_append(chapters, ghb_string_value_new(str));
2819 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2826 ghb_ac3_in_audio_list(const GValue *audio_list)
2830 count = ghb_array_len(audio_list);
2831 for (ii = 0; ii < count; ii++)
2836 asettings = ghb_array_get_nth(audio_list, ii);
2837 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2838 if (acodec & HB_ACODEC_AC3)
2845 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2848 GtkListStore *store;
2851 g_debug("audio_bitrate_opts_add ()\n");
2853 if (rate < 8) return;
2855 store = get_combo_box_store(builder, name);
2856 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2858 str = g_strdup_printf ("<small>%d</small>", rate);
2859 gtk_list_store_append(store, &iter);
2860 gtk_list_store_set(store, &iter,
2872 audio_bitrate_opts_clean(
2873 GtkBuilder *builder,
2879 GtkListStore *store;
2881 gboolean done = FALSE;
2883 guint last = (guint)last_rate;
2884 guint first = (guint)first_rate;
2886 g_debug("audio_bitrate_opts_clean ()\n");
2887 store = get_combo_box_store(builder, name);
2888 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2892 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2894 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2896 done = !gtk_list_store_remove(store, &iter);
2898 else if (ivalue < first || ivalue > last)
2901 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2902 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2907 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2908 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2915 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2918 GtkListStore *store;
2922 g_debug("audio_bitrate_opts_set ()\n");
2923 store = get_combo_box_store(builder, name);
2924 gtk_list_store_clear(store);
2925 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2927 gtk_list_store_append(store, &iter);
2928 str = g_strdup_printf ("<small>%s</small>",
2929 hb_audio_bitrates[ii].string);
2930 gtk_list_store_set(store, &iter,
2933 2, hb_audio_bitrates[ii].string,
2934 3, (gdouble)hb_audio_bitrates[ii].rate,
2935 4, hb_audio_bitrates[ii].string,
2942 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2944 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2948 ghb_set_default_bitrate_opts(
2949 GtkBuilder *builder,
2953 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
2956 static ghb_status_t hb_status;
2959 ghb_combo_init(signal_user_data_t *ud)
2961 // Set up the list model for the combos
2962 init_ui_combo_boxes(ud->builder);
2963 // Populate all the combos
2964 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2968 ghb_backend_init(gint debug)
2971 h_scan = hb_init( debug, 0 );
2972 h_queue = hb_init( debug, 0 );
2983 void ghb_backend_scan_stop()
2985 hb_scan_stop( h_scan );
2989 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2991 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2992 hb_status.scan.state |= GHB_STATE_SCANNING;
2993 // initialize count and cur to something that won't cause FPE
2994 // when computing progress
2995 hb_status.scan.title_count = 1;
2996 hb_status.scan.title_cur = 0;
3000 ghb_backend_queue_scan(const gchar *path, gint titlenum)
3002 g_debug("ghb_backend_queue_scan()");
3003 hb_scan( h_queue, path, titlenum, 10, 0 );
3004 hb_status.queue.state |= GHB_STATE_SCANNING;
3008 ghb_get_scan_state()
3010 return hb_status.scan.state;
3014 ghb_get_queue_state()
3016 return hb_status.queue.state;
3020 ghb_clear_scan_state(gint state)
3022 hb_status.scan.state &= ~state;
3026 ghb_clear_queue_state(gint state)
3028 hb_status.queue.state &= ~state;
3032 ghb_set_scan_state(gint state)
3034 hb_status.scan.state |= state;
3038 ghb_set_queue_state(gint state)
3040 hb_status.queue.state |= state;
3044 ghb_get_status(ghb_status_t *status)
3046 memcpy(status, &hb_status, sizeof(ghb_status_t));
3055 if (h_scan == NULL) return;
3056 hb_get_state( h_scan, &s_scan );
3057 switch( s_scan.state )
3059 #define p s_scan.param.scanning
3060 case HB_STATE_SCANNING:
3062 hb_status.scan.state |= GHB_STATE_SCANNING;
3063 hb_status.scan.title_count = p.title_count;
3064 hb_status.scan.title_cur = p.title_cur;
3068 case HB_STATE_SCANDONE:
3070 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3071 hb_status.scan.state |= GHB_STATE_SCANDONE;
3074 #define p s_scan.param.working
3075 case HB_STATE_WORKING:
3076 hb_status.scan.state |= GHB_STATE_WORKING;
3077 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3078 hb_status.scan.job_cur = p.job_cur;
3079 hb_status.scan.job_count = p.job_count;
3080 hb_status.scan.progress = p.progress;
3081 hb_status.scan.rate_cur = p.rate_cur;
3082 hb_status.scan.rate_avg = p.rate_avg;
3083 hb_status.scan.hours = p.hours;
3084 hb_status.scan.minutes = p.minutes;
3085 hb_status.scan.seconds = p.seconds;
3086 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3090 case HB_STATE_PAUSED:
3091 hb_status.scan.state |= GHB_STATE_PAUSED;
3094 case HB_STATE_MUXING:
3096 hb_status.scan.state |= GHB_STATE_MUXING;
3099 #define p s_scan.param.workdone
3100 case HB_STATE_WORKDONE:
3104 hb_status.scan.state |= GHB_STATE_WORKDONE;
3105 hb_status.scan.state &= ~GHB_STATE_MUXING;
3106 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3107 hb_status.scan.state &= ~GHB_STATE_WORKING;
3111 hb_status.scan.error = GHB_ERROR_NONE;
3113 case HB_ERROR_CANCELED:
3114 hb_status.scan.error = GHB_ERROR_CANCELED;
3117 hb_status.scan.error = GHB_ERROR_FAIL;
3120 // Delete all remaining jobs of this encode.
3121 // An encode can be composed of multiple associated jobs.
3122 // When a job is stopped, libhb removes it from the job list,
3123 // but does not remove other jobs that may be associated with it.
3124 // Associated jobs are taged in the sequence id.
3125 while ((job = hb_job(h_scan, 0)) != NULL)
3126 hb_rem( h_scan, job );
3130 hb_get_state( h_queue, &s_queue );
3131 switch( s_queue.state )
3133 #define p s_queue.param.scanning
3134 case HB_STATE_SCANNING:
3136 hb_status.queue.state |= GHB_STATE_SCANNING;
3137 hb_status.queue.title_count = p.title_count;
3138 hb_status.queue.title_cur = p.title_cur;
3142 case HB_STATE_SCANDONE:
3144 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3145 hb_status.queue.state |= GHB_STATE_SCANDONE;
3148 #define p s_queue.param.working
3149 case HB_STATE_WORKING:
3150 hb_status.queue.state |= GHB_STATE_WORKING;
3151 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3152 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3153 hb_status.queue.job_cur = p.job_cur;
3154 hb_status.queue.job_count = p.job_count;
3155 hb_status.queue.progress = p.progress;
3156 hb_status.queue.rate_cur = p.rate_cur;
3157 hb_status.queue.rate_avg = p.rate_avg;
3158 hb_status.queue.hours = p.hours;
3159 hb_status.queue.minutes = p.minutes;
3160 hb_status.queue.seconds = p.seconds;
3161 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3164 case HB_STATE_SEARCHING:
3165 hb_status.queue.state |= GHB_STATE_SEARCHING;
3166 hb_status.queue.state &= ~GHB_STATE_WORKING;
3167 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3168 hb_status.queue.job_cur = p.job_cur;
3169 hb_status.queue.job_count = p.job_count;
3170 hb_status.queue.progress = p.progress;
3171 hb_status.queue.rate_cur = p.rate_cur;
3172 hb_status.queue.rate_avg = p.rate_avg;
3173 hb_status.queue.hours = p.hours;
3174 hb_status.queue.minutes = p.minutes;
3175 hb_status.queue.seconds = p.seconds;
3176 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3180 case HB_STATE_PAUSED:
3181 hb_status.queue.state |= GHB_STATE_PAUSED;
3184 case HB_STATE_MUXING:
3186 hb_status.queue.state |= GHB_STATE_MUXING;
3189 #define p s_queue.param.workdone
3190 case HB_STATE_WORKDONE:
3194 hb_status.queue.state |= GHB_STATE_WORKDONE;
3195 hb_status.queue.state &= ~GHB_STATE_MUXING;
3196 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3197 hb_status.queue.state &= ~GHB_STATE_WORKING;
3198 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3202 hb_status.queue.error = GHB_ERROR_NONE;
3204 case HB_ERROR_CANCELED:
3205 hb_status.queue.error = GHB_ERROR_CANCELED;
3208 hb_status.queue.error = GHB_ERROR_FAIL;
3211 // Delete all remaining jobs of this encode.
3212 // An encode can be composed of multiple associated jobs.
3213 // When a job is stopped, libhb removes it from the job list,
3214 // but does not remove other jobs that may be associated with it.
3215 // Associated jobs are taged in the sequence id.
3216 while ((job = hb_job(h_queue, 0)) != NULL)
3217 hb_rem( h_queue, job );
3224 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3229 if (h_scan == NULL) return FALSE;
3230 list = hb_get_titles( h_scan );
3231 if( !hb_list_count( list ) )
3233 /* No valid title, stop right there */
3237 title = hb_list_item( list, titleindex );
3238 if (title == NULL) return FALSE; // Bad titleindex
3239 tinfo->index = titleindex;
3240 tinfo->width = title->width;
3241 tinfo->height = title->height;
3242 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3243 // Don't allow crop to 0
3244 if (title->crop[0] + title->crop[1] >= title->height)
3245 title->crop[0] = title->crop[1] = 0;
3246 if (title->crop[2] + title->crop[3] >= title->width)
3247 title->crop[2] = title->crop[3] = 0;
3248 tinfo->num_chapters = hb_list_count(title->list_chapter);
3249 tinfo->rate_base = title->rate_base;
3250 tinfo->rate = title->rate;
3251 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3252 title->width * title->pixel_aspect_width,
3253 title->height * title->pixel_aspect_height);
3254 tinfo->hours = title->hours;
3255 tinfo->minutes = title->minutes;
3256 tinfo->seconds = title->seconds;
3257 tinfo->duration = title->duration;
3259 tinfo->angle_count = title->angle_count;
3260 tinfo->path = title->path;
3261 tinfo->name = title->name;
3262 tinfo->type = title->type;
3267 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3269 hb_audio_config_t *audio;
3271 audio = get_hb_audio(titleindex, audioindex);
3272 if (audio == NULL) return FALSE; // Bad audioindex
3273 ainfo->codec = audio->in.codec;
3274 ainfo->bitrate = audio->in.bitrate;
3275 ainfo->samplerate = audio->in.samplerate;
3280 ghb_audio_is_passthru(gint acodec)
3282 g_debug("ghb_audio_is_passthru () \n");
3283 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
3287 ghb_get_default_acodec()
3289 return HB_ACODEC_FAAC;
3293 picture_settings_deps(signal_user_data_t *ud)
3295 gboolean autoscale, keep_aspect, enable_keep_aspect;
3296 gboolean enable_scale_width, enable_scale_height;
3297 gboolean enable_disp_width, enable_disp_height, enable_par;
3301 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3304 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3305 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3306 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3308 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3309 if (!enable_keep_aspect)
3311 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3313 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3314 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3316 enable_scale_width = !autoscale && (pic_par != 1);
3317 enable_scale_height = !autoscale && (pic_par != 1);
3318 enable_disp_width = (pic_par == 3) && !keep_aspect;
3319 enable_par = (pic_par == 3) && !keep_aspect;
3320 enable_disp_height = FALSE;
3322 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3323 gtk_widget_set_sensitive(widget, pic_par != 1);
3324 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3325 gtk_widget_set_sensitive(widget, pic_par != 1);
3326 widget = GHB_WIDGET(ud->builder, "scale_width");
3327 gtk_widget_set_sensitive(widget, enable_scale_width);
3328 widget = GHB_WIDGET(ud->builder, "scale_height");
3329 gtk_widget_set_sensitive(widget, enable_scale_height);
3330 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3331 gtk_widget_set_sensitive(widget, enable_disp_width);
3332 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3333 gtk_widget_set_sensitive(widget, enable_disp_height);
3334 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3335 gtk_widget_set_sensitive(widget, enable_par);
3336 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3337 gtk_widget_set_sensitive(widget, enable_par);
3338 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3339 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3340 widget = GHB_WIDGET(ud->builder, "autoscale");
3341 gtk_widget_set_sensitive(widget, pic_par != 1);
3345 ghb_set_scale(signal_user_data_t *ud, gint mode)
3350 gboolean keep_aspect;
3352 gboolean autocrop, autoscale, noscale;
3353 gint crop[4], width, height, par_width, par_height;
3354 gint crop_width, crop_height;
3355 gint aspect_n, aspect_d;
3356 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3357 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3362 gint max_height = 0;
3363 static gboolean busy = FALSE;
3365 g_debug("ghb_set_scale ()\n");
3366 picture_settings_deps(ud);
3367 if (h_scan == NULL) return;
3368 list = hb_get_titles( h_scan );
3369 if( !hb_list_count( list ) )
3371 /* No valid title, stop right there */
3376 titleindex = ghb_settings_combo_int(ud->settings, "title");
3377 title = hb_list_item( list, titleindex );
3378 if (title == NULL) return;
3380 if (job == NULL) return;
3385 if (!ud->dont_clear_presets && (keep_width || keep_height))
3387 ghb_settings_set_int(ud->settings, "PictureWidth", 0);
3388 ghb_settings_set_int(ud->settings, "PictureHeight", 0);
3391 // First configure widgets
3392 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3393 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3394 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3395 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3396 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3397 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3398 // alignment constraints rather than scaling to satisfy them.
3399 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3400 // Align dimensions to either 16 or 2 pixels
3401 // The scaler crashes if the dimensions are not divisible by 2
3402 // x264 also will not accept dims that are not multiple of 2
3406 keep_height = FALSE;
3408 // Step needs to be at least 2 because odd widths cause scaler crash
3410 widget = GHB_WIDGET (ud->builder, "scale_width");
3411 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3412 widget = GHB_WIDGET (ud->builder, "scale_height");
3413 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3416 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3417 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3418 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3419 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3420 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3421 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3422 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3423 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3427 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3428 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3429 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3430 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3431 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3432 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3433 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3434 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3436 ghb_title_info_t tinfo;
3437 ghb_get_title_info (&tinfo, titleindex);
3440 crop[0] = tinfo.crop[0];
3441 crop[1] = tinfo.crop[1];
3442 crop[2] = tinfo.crop[2];
3443 crop[3] = tinfo.crop[3];
3444 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3445 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3446 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3447 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3451 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3452 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3453 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3454 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3460 // Adjust the cropping to accomplish the desired width and height
3461 crop_width = tinfo.width - crop[2] - crop[3];
3462 crop_height = tinfo.height - crop[0] - crop[1];
3463 width = MOD_DOWN(crop_width, mod);
3464 height = MOD_DOWN(crop_height, mod);
3466 need1 = (crop_height - height) / 2;
3467 need2 = crop_height - height - need1;
3470 need1 = (crop_width - width) / 2;
3471 need2 = crop_width - width - need1;
3474 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3475 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3476 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3477 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3479 hb_reduce(&aspect_n, &aspect_d,
3480 title->width * title->pixel_aspect_width,
3481 title->height * title->pixel_aspect_height);
3482 crop_width = title->width - crop[2] - crop[3];
3483 crop_height = title->height - crop[0] - crop[1];
3487 height = crop_height;
3491 width = ghb_settings_get_int(ud->settings, "scale_width");
3492 height = ghb_settings_get_int(ud->settings, "scale_height");
3493 max_width = MOD_DOWN(
3494 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3495 max_height = MOD_DOWN(
3496 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3498 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3501 width = title->width - crop[2] - crop[3];
3503 height = title->height - crop[0] - crop[1];
3505 width = MOD_ROUND(width, mod);
3506 height = MOD_ROUND(height, mod);
3508 // Adjust dims according to max values
3510 height = MIN(height, max_height);
3512 width = MIN(width, max_width);
3516 job->anamorphic.mode = pic_par;
3517 // The scaler crashes if the dimensions are not divisible by 2
3518 // Align mod 2. And so does something in x264_encoder_headers()
3520 job->anamorphic.par_width = title->pixel_aspect_width;
3521 job->anamorphic.par_height = title->pixel_aspect_height;
3522 job->anamorphic.dar_width = 0;
3523 job->anamorphic.dar_height = 0;
3525 if (keep_height && pic_par == 2)
3526 width = ((double)height * crop_width / crop_height) + mod / 2;
3528 job->height = height;
3529 job->maxWidth = max_width;
3530 job->maxHeight = max_height;
3531 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3532 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3533 if (job->anamorphic.mode == 3 && !keep_aspect)
3535 job->anamorphic.keep_display_aspect = 0;
3536 if (mode & GHB_PIC_KEEP_PAR)
3538 job->anamorphic.par_width =
3539 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3540 job->anamorphic.par_height =
3541 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3545 job->anamorphic.dar_width =
3546 ghb_settings_get_int(ud->settings,
3547 "PictureDisplayWidth");
3548 job->anamorphic.dar_height = height;
3553 job->anamorphic.keep_display_aspect = 1;
3555 hb_set_anamorphic_size( job, &width, &height,
3556 &par_width, &par_height );
3557 if (job->anamorphic.mode == 3 && !keep_aspect &&
3558 mode & GHB_PIC_KEEP_PAR)
3560 // hb_set_anamorphic_size reduces the par, which we
3561 // don't want in this case because the user is
3562 // explicitely specifying it.
3563 par_width = ghb_settings_get_int(ud->settings,
3565 par_height = ghb_settings_get_int(ud->settings,
3566 "PicturePARHeight");
3571 job->anamorphic.mode = pic_par;
3575 gint new_width, new_height;
3577 // Compute pixel aspect ration.
3578 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3579 // Must scale so that par becomes 1:1
3580 // Try to keep largest dimension
3581 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3582 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3584 if (max_width && new_width > max_width)
3586 height = new_height;
3588 else if (max_height && new_height > max_height)
3592 else if (keep_width)
3594 height = new_height;
3596 else if (keep_height)
3600 else if (width > new_width)
3602 height = new_height;
3608 g_debug("new w %d h %d\n", width, height);
3610 width = MOD_ROUND(width, mod);
3611 height = MOD_ROUND(height, mod);
3613 height = MIN(height, max_height);
3615 width = MIN(width, max_width);
3616 par_width = par_height = 1;
3618 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3619 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3621 gint disp_width, dar_width, dar_height;
3624 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3625 hb_reduce(&dar_width, &dar_height, disp_width, height);
3627 gint iaspect = dar_width * 9 / dar_height;
3628 if (dar_width > 2 * dar_height)
3630 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3632 else if (iaspect <= 16 && iaspect >= 15)
3634 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3636 else if (iaspect <= 12 && iaspect >= 11)
3638 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3642 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3644 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3646 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3647 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3648 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3649 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3654 set_preview_job_settings(hb_job_t *job, GValue *settings)
3656 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3657 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3658 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3659 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3661 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3663 ghb_settings_combo_int(settings, "PictureModulus");
3664 job->width = ghb_settings_get_int(settings, "scale_width");
3665 job->height = ghb_settings_get_int(settings, "scale_height");
3666 if (ghb_settings_get_boolean(settings, "show_crop"))
3668 gdouble xscale = (gdouble)job->width /
3669 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3670 gdouble yscale = (gdouble)job->height /
3671 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3673 job->width += xscale * (job->crop[2] + job->crop[3]);
3674 job->height += yscale * (job->crop[0] + job->crop[1]);
3682 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3685 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3686 job->deinterlace = (decomb == 0) ? 0 : 1;
3690 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3691 job->deinterlace = (deint == 0) ? 0 : 1;
3694 gboolean keep_aspect;
3695 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3696 if (job->anamorphic.mode)
3698 job->anamorphic.par_width = job->title->pixel_aspect_width;
3699 job->anamorphic.par_height = job->title->pixel_aspect_height;
3700 job->anamorphic.dar_width = 0;
3701 job->anamorphic.dar_height = 0;
3703 if (job->anamorphic.mode == 3 && !keep_aspect)
3705 job->anamorphic.keep_display_aspect = 0;
3706 job->anamorphic.par_width =
3707 ghb_settings_get_int(settings, "PicturePARWidth");
3708 job->anamorphic.par_height =
3709 ghb_settings_get_int(settings, "PicturePARHeight");
3713 job->anamorphic.keep_display_aspect = 1;
3719 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3726 if (h_scan == NULL) return 1500;
3727 list = hb_get_titles( h_scan );
3728 title = hb_list_item( list, titleindex );
3729 if (title == NULL) return 1500;
3731 if (job == NULL) return 1500;
3732 size = ghb_settings_get_int(settings, "VideoTargetSize");
3733 return hb_calc_bitrate( job, size );
3737 ghb_validate_filter_string(const gchar *str, gint max_fields)
3743 if (str == NULL || *str == 0) return TRUE;
3746 val = g_strtod(str, &end);
3748 { // Found a numeric value
3750 // negative max_fields means infinate
3751 if (max_fields >= 0 && fields > max_fields) return FALSE;
3765 ghb_validate_filters(signal_user_data_t *ud)
3771 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3773 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3774 if (!decomb_deint && index == 1)
3776 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3777 if (!ghb_validate_filter_string(str, -1))
3779 message = g_strdup_printf(
3780 "Invalid Deinterlace Settings:\n\n%s\n",
3782 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3790 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3793 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3794 if (!ghb_validate_filter_string(str, -1))
3796 message = g_strdup_printf(
3797 "Invalid Detelecine Settings:\n\n%s\n",
3799 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3807 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3808 if (decomb_deint && index == 1)
3810 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3811 if (!ghb_validate_filter_string(str, -1))
3813 message = g_strdup_printf(
3814 "Invalid Decomb Settings:\n\n%s\n",
3816 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3824 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3827 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3828 if (!ghb_validate_filter_string(str, -1))
3830 message = g_strdup_printf(
3831 "Invalid Denoise Settings:\n\n%s\n",
3833 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3844 ghb_validate_video(signal_user_data_t *ud)
3849 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3850 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3851 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
3853 // mp4/theora combination is not supported.
3854 message = g_strdup_printf(
3855 "Theora is not supported in the MP4 container.\n\n"
3856 "You should choose a different video codec or container.\n"
3857 "If you continue, FFMPEG will be chosen for you.");
3858 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3864 vcodec = HB_VCODEC_FFMPEG;
3865 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3871 ghb_validate_subtitles(signal_user_data_t *ud)
3877 if (h_scan == NULL) return FALSE;
3878 list = hb_get_titles( h_scan );
3879 if( !hb_list_count( list ) )
3881 /* No valid title, stop right there */
3882 g_message("No title found.\n");
3888 titleindex = ghb_settings_combo_int(ud->settings, "title");
3889 title = hb_list_item( list, titleindex );
3890 if (title == NULL) return FALSE;
3892 const GValue *slist, *settings;
3893 gint count, ii, source;
3894 gboolean burned, one_burned = FALSE;
3896 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3897 count = ghb_array_len(slist);
3898 for (ii = 0; ii < count; ii++)
3900 settings = ghb_array_get_nth(slist, ii);
3901 source = ghb_settings_get_int(settings, "SubtitleSource");
3902 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3903 if (burned && one_burned)
3905 // MP4 can only handle burned vobsubs. make sure there isn't
3906 // already something burned in the list
3907 message = g_strdup_printf(
3908 "Only one subtitle may be burned into the video.\n\n"
3909 "You should change your subtitle selections.\n"
3910 "If you continue, some subtitles will be lost.");
3911 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3923 if (source == SRTSUB)
3927 filename = ghb_settings_get_string(settings, "SrtFile");
3928 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3930 message = g_strdup_printf(
3931 "Srt file does not exist or not a regular file.\n\n"
3932 "You should choose a valid file.\n"
3933 "If you continue, this subtitle will be ignored.");
3934 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3935 "Cancel", "Continue"))
3949 ghb_select_audio_codec(signal_user_data_t *ud, gint track)
3953 hb_audio_config_t *audio;
3955 if (h_scan == NULL) return -1;
3956 list = hb_get_titles( h_scan );
3957 if( !hb_list_count( list ) )
3964 titleindex = ghb_settings_combo_int(ud->settings, "title");
3965 title = hb_list_item( list, titleindex );
3966 if (title == NULL) return -1;
3968 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3970 if (track < 0 || track >= hb_list_count(title->list_audio))
3973 audio = (hb_audio_config_t *) hb_list_audio_config_item(
3974 title->list_audio, track );
3975 if (mux == HB_MUX_MP4)
3977 if (audio->in.codec == HB_ACODEC_AC3)
3978 return audio->in.codec;
3980 return HB_ACODEC_FAAC;
3984 if (audio->in.codec == HB_ACODEC_AC3 || audio->in.codec == HB_ACODEC_DCA)
3985 return audio->in.codec;
3987 return HB_ACODEC_LAME;
3992 ghb_select_audio_codec_str(signal_user_data_t *ud, gint track)
3996 acodec = ghb_select_audio_codec(ud, track);
3997 for (ii = 0; ii < acodec_opts.count; ii++)
3999 if (acodec_opts.map[ii].ivalue == acodec)
4000 return acodec_opts.map[ii].option;
4006 ghb_validate_audio(signal_user_data_t *ud)
4013 if (h_scan == NULL) return FALSE;
4014 list = hb_get_titles( h_scan );
4015 if( !hb_list_count( list ) )
4017 /* No valid title, stop right there */
4018 g_message("No title found.\n");
4024 titleindex = ghb_settings_combo_int(ud->settings, "title");
4025 title = hb_list_item( list, titleindex );
4026 if (title == NULL) return FALSE;
4027 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4029 const GValue *audio_list;
4032 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
4033 count = ghb_array_len(audio_list);
4034 for (ii = 0; ii < count; ii++)
4037 hb_audio_config_t *taudio;
4039 asettings = ghb_array_get_nth(audio_list, ii);
4040 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4041 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4042 if (codec == HB_ACODEC_MASK)
4045 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4046 title->list_audio, track );
4047 if (!(taudio->in.codec & codec) &&
4048 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4050 // Not supported. AC3 is passthrough only, so input must be AC3
4051 message = g_strdup_printf(
4052 "The source does not support Pass-Thru.\n\n"
4053 "You should choose a different audio codec.\n"
4054 "If you continue, one will be chosen for you.");
4055 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4061 if (mux == HB_MUX_MKV)
4063 codec = HB_ACODEC_LAME;
4067 codec = HB_ACODEC_FAAC;
4069 value = ghb_lookup_acodec_value(codec);
4070 ghb_settings_take_value(asettings, "AudioEncoder", value);
4072 gchar *a_unsup = NULL;
4073 gchar *mux_s = NULL;
4074 if (mux == HB_MUX_MP4)
4077 // mp4/vorbis|DTS combination is not supported.
4078 if (codec == HB_ACODEC_VORBIS)
4081 codec = HB_ACODEC_FAAC;
4083 if (codec == HB_ACODEC_DCA)
4086 codec = HB_ACODEC_FAAC;
4091 message = g_strdup_printf(
4092 "%s is not supported in the %s container.\n\n"
4093 "You should choose a different audio codec.\n"
4094 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4095 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4101 value = ghb_lookup_acodec_value(codec);
4102 ghb_settings_take_value(asettings, "AudioEncoder", value);
4104 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4105 gboolean allow_mono = TRUE;
4106 gboolean allow_stereo = TRUE;
4107 gboolean allow_dolby = TRUE;
4108 gboolean allow_dpl2 = TRUE;
4109 gboolean allow_6ch = TRUE;
4111 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4113 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4115 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4116 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4117 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4118 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4120 (codec & ~HB_ACODEC_LAME) &&
4121 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4122 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4124 gchar *mix_unsup = NULL;
4125 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4129 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4131 mix_unsup = "stereo";
4133 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4135 mix_unsup = "Dolby";
4137 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4139 mix_unsup = "Dolby Pro Logic II";
4141 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4143 mix_unsup = "6 Channel";
4147 message = g_strdup_printf(
4148 "The source audio does not support %s mixdown.\n\n"
4149 "You should choose a different mixdown.\n"
4150 "If you continue, one will be chosen for you.", mix_unsup);
4151 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4157 mix = ghb_get_best_mix(titleindex, track, codec, mix);
4158 value = get_amix_value(mix);
4159 ghb_settings_take_value(asettings, "AudioMixdown", value);
4166 ghb_validate_vquality(GValue *settings)
4172 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4173 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4175 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4176 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4180 case HB_VCODEC_X264:
4186 case HB_VCODEC_FFMPEG:
4192 case HB_VCODEC_THEORA:
4204 if (vquality < min || vquality > max)
4206 message = g_strdup_printf(
4207 "Interesting video quality choise: %d\n\n"
4208 "Typical values range from %d to %d.\n"
4209 "Are you sure you wish to use this setting?",
4210 (gint)vquality, min, max);
4211 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4212 "Cancel", "Continue"))
4224 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4229 static gchar *x264opts;
4231 gboolean tweaks = FALSE;
4232 gchar *detel_str = NULL;
4233 gchar *decomb_str = NULL;
4234 gchar *deint_str = NULL;
4235 gchar *deblock_str = NULL;
4236 gchar *denoise_str = NULL;
4237 gchar *dest_str = NULL;
4239 g_debug("add_job()\n");
4240 if (h == NULL) return;
4241 list = hb_get_titles( h );
4242 if( !hb_list_count( list ) )
4244 /* No valid title, stop right there */
4248 title = hb_list_item( list, titleindex );
4249 if (title == NULL) return;
4251 /* Set job settings */
4253 if (job == NULL) return;
4255 job->angle = ghb_settings_get_int(js, "angle");
4256 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4257 if (job->start_at_preview)
4259 job->seek_points = ghb_settings_get_int(js, "preview_count");
4260 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4263 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4264 job->mux = ghb_settings_combo_int(js, "FileFormat");
4265 if (job->mux == HB_MUX_MP4)
4267 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4268 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4272 job->largeFileSize = FALSE;
4273 job->mp4_optimize = FALSE;
4275 if (!job->start_at_preview)
4278 gint num_chapters = hb_list_count(title->list_chapter);
4279 gint duration = title->duration / 90000;
4280 job->chapter_start = 1;
4281 job->chapter_end = num_chapters;
4283 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4285 start = ghb_settings_get_int(js, "start_point");
4286 end = ghb_settings_get_int(js, "end_point");
4287 job->chapter_start = MIN( num_chapters, start );
4288 job->chapter_end = MAX( job->chapter_start, end );
4291 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4293 job->chapter_start = 1;
4294 job->chapter_end = num_chapters;
4295 start = ghb_settings_get_int(js, "start_point");
4296 end = ghb_settings_get_int(js, "end_point");
4297 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4298 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4301 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4303 job->chapter_start = 1;
4304 job->chapter_end = num_chapters;
4305 start = ghb_settings_get_int(js, "start_point");
4306 end = ghb_settings_get_int(js, "end_point");
4308 max_frames = (gint64)duration * title->rate / title->rate_base;
4309 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4310 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4311 job->frame_to_start;
4313 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4314 if (job->chapter_start == job->chapter_end)
4315 job->chapter_markers = 0;
4316 if ( job->chapter_markers )
4323 chapters = ghb_settings_get_value(js, "chapter_list");
4324 count = ghb_array_len(chapters);
4325 for(chap = 0; chap < count; chap++)
4327 hb_chapter_t * chapter_s;
4331 chapter = ghb_array_get_nth(chapters, chap);
4332 name = ghb_value_string(chapter);
4335 name = g_strdup_printf ("Chapter %2d", chap+1);
4337 chapter_s = hb_list_item( job->title->list_chapter, chap);
4338 strncpy(chapter_s->title, name, 1023);
4339 chapter_s->title[1023] = '\0';
4344 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4345 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4346 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4347 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4350 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4351 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4352 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4354 job->deinterlace = (deint != 0) ? 1 : 0;
4356 job->deinterlace = 0;
4357 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4359 gboolean keep_aspect;
4360 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4361 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4362 job->modulus = ghb_settings_combo_int(js, "PictureModulus");
4363 if (job->anamorphic.mode)
4365 job->anamorphic.par_width = title->pixel_aspect_width;
4366 job->anamorphic.par_height = title->pixel_aspect_height;
4367 job->anamorphic.dar_width = 0;
4368 job->anamorphic.dar_height = 0;
4370 if (job->anamorphic.mode == 3 && !keep_aspect)
4372 job->anamorphic.keep_display_aspect = 0;
4373 job->anamorphic.par_width =
4374 ghb_settings_get_int(js, "PicturePARWidth");
4375 job->anamorphic.par_height =
4376 ghb_settings_get_int(js, "PicturePARHeight");
4380 job->anamorphic.keep_display_aspect = 1;
4384 /* Add selected filters */
4385 job->filters = hb_list_init();
4386 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4391 if (detel_opts.map[detel].svalue != NULL)
4392 detel_str = g_strdup(detel_opts.map[detel].svalue);
4395 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4396 hb_filter_detelecine.settings = detel_str;
4397 hb_list_add( job->filters, &hb_filter_detelecine );
4399 if ( decomb_deint && decomb )
4403 if (decomb_opts.map[decomb].svalue != NULL)
4404 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4407 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4408 hb_filter_decomb.settings = decomb_str;
4409 hb_list_add( job->filters, &hb_filter_decomb );
4411 if( job->deinterlace )
4415 if (deint_opts.map[deint].svalue != NULL)
4416 deint_str = g_strdup(deint_opts.map[deint].svalue);
4419 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4420 hb_filter_deinterlace.settings = deint_str;
4421 hb_list_add( job->filters, &hb_filter_deinterlace );
4423 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4426 deblock_str = g_strdup_printf("%d", deblock);
4427 hb_filter_deblock.settings = deblock_str;
4428 hb_list_add( job->filters, &hb_filter_deblock );
4430 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4435 if (denoise_opts.map[denoise].svalue != NULL)
4436 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4439 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4440 hb_filter_denoise.settings = denoise_str;
4441 hb_list_add( job->filters, &hb_filter_denoise );
4443 job->width = ghb_settings_get_int(js, "scale_width");
4444 job->height = ghb_settings_get_int(js, "scale_height");
4446 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4447 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4449 // mp4/theora combination is not supported.
4450 job->vcodec = HB_VCODEC_FFMPEG;
4452 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4454 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4456 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4459 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4460 job->vquality = vquality;
4463 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4465 job->vquality = -1.0;
4466 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4469 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4472 job->vrate = title->rate;
4473 job->vrate_base = title->rate_base;
4478 job->vrate = 27000000;
4479 job->vrate_base = vrate;
4483 const GValue *audio_list;
4487 audio_list = ghb_settings_get_value(js, "audio_list");
4488 count = ghb_array_len(audio_list);
4489 for (ii = 0; ii < count; ii++)
4492 hb_audio_config_t audio;
4493 hb_audio_config_t *taudio;
4495 hb_audio_config_init(&audio);
4496 asettings = ghb_array_get_nth(audio_list, ii);
4497 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4498 audio.out.track = tcount;
4499 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4500 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4501 title->list_audio, audio.in.track );
4502 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4504 if (!(taudio->in.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4507 // AC3/DTS is passthrough only, so input must be AC3/DTS
4508 if (job->mux == HB_MUX_MKV)
4510 audio.out.codec = HB_ACODEC_LAME;
4514 audio.out.codec = HB_ACODEC_FAAC;
4519 audio.out.codec &= taudio->in.codec;
4522 if ((job->mux == HB_MUX_MP4) &&
4523 ((audio.out.codec & HB_ACODEC_DCA) ||
4524 (audio.out.codec & HB_ACODEC_VORBIS)))
4526 // mp4/mp3|dts|vorbis combination is not supported.
4527 audio.out.codec = HB_ACODEC_FAAC;
4529 audio.out.dynamic_range_compression =
4530 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4531 if (audio.out.dynamic_range_compression < 1.0)
4532 audio.out.dynamic_range_compression = 0.0;
4534 // It would be better if this were done in libhb for us, but its not yet.
4535 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4537 audio.out.mixdown = 0;
4543 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4544 if (audio.out.mixdown == HB_AMIXDOWN_MONO)
4546 else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
4551 // Make sure the mixdown is valid and pick a new one if not.
4552 audio.out.mixdown = ghb_get_best_mix(titleindex,
4553 audio.in.track, audio.out.codec, audio.out.mixdown);
4555 ghb_settings_combo_int(asettings, "AudioBitrate");
4556 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4557 if (srate == 0) // 0 is same as source
4558 audio.out.samplerate = taudio->in.samplerate;
4560 audio.out.samplerate = srate;
4562 audio.out.bitrate = ghb_get_best_audio_bitrate(
4563 audio.out.codec, audio.out.bitrate, channels);
4566 // Add it to the jobs audio list
4567 hb_audio_add( job, &audio );
4570 // I was tempted to move this up with the reset of the video quality
4571 // settings, but I suspect the settings above need to be made
4572 // first in order for hb_calc_bitrate to be accurate.
4573 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4577 size = ghb_settings_get_int(js, "VideoTargetSize");
4578 job->vbitrate = hb_calc_bitrate( job, size );
4579 job->vquality = -1.0;
4582 dest_str = ghb_settings_get_string(js, "destination");
4583 job->file = dest_str;
4585 const GValue *subtitle_list;
4587 gboolean force, burned, def, one_burned = FALSE;
4589 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4590 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4591 count = ghb_array_len(subtitle_list);
4592 for (ii = 0; ii < count; ii++)
4597 ssettings = ghb_array_get_nth(subtitle_list, ii);
4599 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4600 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4601 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4602 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4604 if (source == SRTSUB)
4606 hb_subtitle_config_t sub_config;
4607 gchar *filename, *lang, *code;
4609 filename = ghb_settings_get_string(ssettings, "SrtFile");
4610 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4614 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4615 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4616 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4617 strncpy(sub_config.src_filename, filename, 128);
4618 strncpy(sub_config.src_codeset, code, 40);
4619 sub_config.force = 0;
4620 sub_config.dest = PASSTHRUSUB;
4621 sub_config.default_track = def;
4623 hb_srt_add( job, &sub_config, lang);
4631 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4636 job->select_subtitle_config.dest = PASSTHRUSUB;
4640 // Only allow one subtitle to be burned into the video
4643 job->select_subtitle_config.dest = RENDERSUB;
4646 job->select_subtitle_config.force = force;
4647 job->select_subtitle_config.default_track = def;
4648 job->indepth_scan = 1;
4649 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4651 else if (subtitle >= 0)
4653 hb_subtitle_t * subt;
4654 hb_subtitle_config_t sub_config;
4656 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4659 sub_config = subt->config;
4660 if (!burned && subt->format == PICTURESUB)
4662 sub_config.dest = PASSTHRUSUB;
4664 else if ( burned && subt->format == PICTURESUB )
4666 // Only allow one subtitle to be burned into the video
4671 sub_config.force = force;
4672 sub_config.default_track = def;
4673 hb_subtitle_add( job, &sub_config, subtitle );
4678 // TODO: libhb holds onto a reference to the x264opts and is not
4679 // finished with it until encoding the job is done. But I can't
4680 // find a way to get at the job before it is removed in order to
4681 // free up the memory I am allocating here.
4682 // The short story is THIS LEAKS.
4683 x264opts = ghb_build_x264opts_string(js);
4685 if( *x264opts == '\0' )
4691 if (job->indepth_scan == 1)
4693 // Subtitle scan. Look for subtitle matching audio language
4696 * When subtitle scan is enabled do a fast pre-scan job
4697 * which will determine which subtitles to enable, if any.
4700 job->indepth_scan = 1;
4701 job->x264opts = NULL;
4704 * Add the pre-scan job
4706 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4710 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4711 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4714 * If subtitle_scan is enabled then only turn it on
4715 * for the second pass and then off again for the
4719 job->indepth_scan = 0;
4722 * If turbo options have been selected then append them
4723 * to the x264opts now (size includes one ':' and the '\0')
4725 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4727 gchar *tmp_x264opts;
4731 badapt = ghb_lookup_badapt(x264opts);
4734 extra_opts = g_strdup_printf("%s", turbo_opts);
4738 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4743 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4748 * No x264opts to modify, but apply the turbo options
4749 * anyway as they may be modifying defaults
4751 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4755 job->x264opts = tmp_x264opts;
4759 job->x264opts = x264opts;
4761 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4763 //if (job->x264opts != NULL)
4764 // g_free(job->x264opts);
4768 * On the second pass we turn off subtitle scan so that we
4769 * can actually encode using any subtitles that were auto
4770 * selected in the first pass (using the whacky select-subtitle
4771 * attribute of the job).
4773 job->indepth_scan = 0;
4774 job->x264opts = x264opts;
4775 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4777 //if (job->x264opts != NULL)
4778 // g_free(job->x264opts);
4782 job->x264opts = x264opts;
4783 job->indepth_scan = 0;
4785 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4787 //if (job->x264opts != NULL)
4788 // g_free(job->x264opts);
4791 // clean up audio list
4792 gint num_audio_tracks = hb_list_count(job->list_audio);
4793 for(ii = 0; ii < num_audio_tracks; ii++)
4795 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4796 hb_list_rem(job->list_audio, audio);
4800 // clean up subtitle list
4801 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4802 for(ii = 0; ii < num_subtitle_tracks; ii++)
4804 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4805 hb_list_rem(job->list_subtitle, subtitle);
4809 if (detel_str) g_free(detel_str);
4810 if (decomb_str) g_free(decomb_str);
4811 if (deint_str) g_free(deint_str);
4812 if (deblock_str) g_free(deblock_str);
4813 if (denoise_str) g_free(denoise_str);
4814 if (dest_str) g_free(dest_str);
4818 ghb_add_job(GValue *js, gint unique_id)
4820 // Since I'm doing a scan of the single title I want just prior
4821 // to adding the job, there is only the one title to choose from.
4822 add_job(h_queue, js, unique_id, 0);
4826 ghb_add_live_job(GValue *js, gint unique_id)
4828 // Since I'm doing a scan of the single title I want just prior
4829 // to adding the job, there is only the one title to choose from.
4830 gint titleindex = ghb_settings_combo_int(js, "title");
4831 add_job(h_scan, js, unique_id, titleindex);
4835 ghb_remove_job(gint unique_id)
4840 // Multiples passes all get the same id
4842 // Go backwards through list, so reordering doesn't screw me.
4843 ii = hb_count(h_queue) - 1;
4844 while ((job = hb_job(h_queue, ii--)) != NULL)
4846 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4847 hb_rem(h_queue, job);
4854 hb_start( h_queue );
4864 ghb_start_live_encode()
4870 ghb_stop_live_encode()
4879 hb_get_state2( h_queue, &s );
4881 if( s.state == HB_STATE_PAUSED )
4883 hb_status.queue.state &= ~GHB_STATE_PAUSED;
4884 hb_resume( h_queue );
4888 hb_status.queue.state |= GHB_STATE_PAUSED;
4889 hb_pause( h_queue );
4904 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4907 gint channels = gdk_pixbuf_get_n_channels (pb);
4908 gint stride = gdk_pixbuf_get_rowstride (pb);
4910 for (jj = 0; jj < width; jj++)
4912 dst = pixels + y * stride + (x+jj) * channels;
4913 for (ii = 0; ii < len; ii++)
4934 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4937 gint channels = gdk_pixbuf_get_n_channels (pb);
4938 gint stride = gdk_pixbuf_get_rowstride (pb);
4940 for (jj = 0; jj < width; jj++)
4942 dst = pixels + (y+jj) * stride + x * channels;
4943 for (ii = 0; ii < len; ii++)
4964 gint line_width = 8;
4971 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4976 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4978 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4984 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4986 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4992 ghb_get_preview_image(
4995 signal_user_data_t *ud,
5003 settings = ud->settings;
5004 list = hb_get_titles( h_scan );
5005 if( !hb_list_count( list ) )
5007 /* No valid title, stop right there */
5010 title = hb_list_item( list, titleindex );
5011 if (title == NULL) return NULL;
5012 if (title->job == NULL) return NULL;
5013 set_preview_job_settings(title->job, settings);
5015 // hb_get_preview doesn't compensate for anamorphic, so lets
5016 // calculate scale factors
5017 gint width, height, par_width = 1, par_height = 1;
5018 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5021 hb_set_anamorphic_size( title->job, &width, &height,
5022 &par_width, &par_height );
5025 // Make sure we have a big enough buffer to receive the image from libhb
5026 gint dstWidth = title->job->width;
5027 gint dstHeight= title->job->height;
5029 static guint8 *buffer = NULL;
5030 static gint bufferSize = 0;
5033 newSize = dstWidth * dstHeight * 4;
5034 if( bufferSize < newSize )
5036 bufferSize = newSize;
5037 buffer = (guint8*) g_realloc( buffer, bufferSize );
5039 hb_get_preview( h_scan, title, index, buffer );
5041 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5042 // libhb's format something suitable.
5044 // The image data returned by hb_get_preview is 4 bytes per pixel,
5045 // BGRA format. Alpha is ignored.
5047 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5048 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5050 guint32 *src = (guint32*)buffer;
5051 guint8 *dst = pixels;
5054 gint channels = gdk_pixbuf_get_n_channels (preview);
5055 gint stride = gdk_pixbuf_get_rowstride (preview);
5058 for (ii = 0; ii < dstHeight; ii++)
5061 for (jj = 0; jj < dstWidth; jj++)
5063 tmp[0] = src[0] >> 16;
5064 tmp[1] = src[0] >> 8;
5065 tmp[2] = src[0] >> 0;
5071 gint w = ghb_settings_get_int(settings, "scale_width");
5072 gint h = ghb_settings_get_int(settings, "scale_height");
5073 ghb_par_scale(ud, &w, &h, par_width, par_height);
5075 gint c0, c1, c2, c3;
5076 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5077 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5078 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5079 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5081 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5082 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5084 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5087 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5091 gint orig_w, orig_h;
5094 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5098 ss = gdk_screen_get_default();
5099 s_w = gdk_screen_get_width(ss);
5100 s_h = gdk_screen_get_height(ss);
5104 if (dstWidth > s_w * factor / 100)
5106 dstWidth = s_w * factor / 100;
5107 dstHeight = dstHeight * dstWidth / orig_w;
5109 if (dstHeight > s_h * factor / 100)
5111 dstHeight = s_h * factor / 100;
5112 dstWidth = dstWidth * dstHeight / orig_h;
5114 xscale *= (gdouble)dstWidth / orig_w;
5115 yscale *= (gdouble)dstHeight / orig_h;
5116 w *= (gdouble)dstWidth / orig_w;
5117 h *= (gdouble)dstHeight / orig_h;
5119 GdkPixbuf *scaled_preview;
5120 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5121 if (ghb_settings_get_boolean(settings, "show_crop"))
5128 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5130 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5132 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5134 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5136 g_object_unref (preview);
5137 return scaled_preview;
5141 sanitize_volname(gchar *name)
5166 ghb_dvd_volname(const gchar *device)
5169 name = hb_dvd_name((gchar*)device);
5170 if (name != NULL && name[0] != 0)
5172 name = g_strdup(name);
5173 sanitize_volname(name);