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_tempory_directory(hb_handle_t *h, char path[512]);
1105 hb_get_tempory_directory(h_scan, dir);
1106 return g_strdup(dir);
1110 ghb_hb_cleanup(gboolean partial)
1114 hb_get_tempory_directory(h_scan, 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_track_source_name(signal_user_data_t *ud, gint track)
1155 const gchar * name = "Unknown";
1168 titleindex = ghb_settings_combo_int(ud->settings, "title");
1174 hb_subtitle_t * sub;
1178 list = hb_get_titles( h_scan );
1179 if( !hb_list_count( list ) )
1182 title = hb_list_item( list, titleindex );
1186 sub = hb_list_item( title->list_subtitle, track);
1189 switch (sub->source)
1211 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1215 titleindex = ghb_settings_combo_int(ud->settings, "title");
1219 return ghb_get_user_audio_lang(ud, titleindex, 0);
1225 hb_subtitle_t * sub;
1230 list = hb_get_titles( h_scan );
1231 if( !hb_list_count( list ) )
1233 /* No valid title, stop right there */
1236 title = hb_list_item( list, titleindex );
1237 if (title == NULL) // Bad titleindex
1239 sub = hb_list_item( title->list_subtitle, track);
1241 return g_strdup(sub->iso639_2);
1244 return g_strdup("und");
1248 ghb_get_title_number(gint titleindex)
1253 if (h_scan == NULL) return 1;
1254 list = hb_get_titles( h_scan );
1255 if( !hb_list_count( list ) )
1257 /* No valid title, stop right there */
1260 title = hb_list_item( list, titleindex );
1261 if (title == NULL) return 1; // Bad titleindex
1262 return title->index;
1265 static hb_audio_config_t*
1266 get_hb_audio(gint titleindex, gint track)
1270 hb_audio_config_t *audio = NULL;
1272 if (h_scan == NULL) return NULL;
1273 list = hb_get_titles( h_scan );
1274 if( !hb_list_count( list ) )
1276 /* No valid title, stop right there */
1279 title = hb_list_item( list, titleindex );
1280 if (title == NULL) return NULL; // Bad titleindex
1281 if (!hb_list_count(title->list_audio))
1285 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1290 search_rates(hb_rate_t *rates, gint rate, gint count)
1293 for (ii = 0; ii < count; ii++)
1295 if (rates[ii].rate == rate)
1301 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1303 static GtkListStore*
1304 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1307 GtkListStore *store;
1309 g_debug("get_combo_box_store() %s\n", name);
1310 // First modify the combobox model to allow greying out of options
1311 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1312 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1317 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1319 GtkListStore *store;
1322 store = get_combo_box_store(builder, name);
1323 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1325 gtk_list_store_set(store, &iter,
1332 ghb_grey_combo_options(GtkBuilder *builder)
1335 gint container, track, titleindex, acodec;
1336 hb_audio_config_t *audio = NULL;
1339 widget = GHB_WIDGET (builder, "title");
1340 gval = ghb_widget_value(widget);
1341 titleindex = ghb_lookup_combo_int("title", gval);
1342 ghb_value_free(gval);
1343 widget = GHB_WIDGET (builder, "AudioTrack");
1344 gval = ghb_widget_value(widget);
1345 track = ghb_lookup_combo_int("AudioTrack", gval);
1346 ghb_value_free(gval);
1347 audio = get_hb_audio(titleindex, track);
1348 widget = GHB_WIDGET (builder, "FileFormat");
1349 gval = ghb_widget_value(widget);
1350 container = ghb_lookup_combo_int("FileFormat", gval);
1351 ghb_value_free(gval);
1353 grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
1354 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1355 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1356 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1358 gboolean allow_dca = TRUE;
1359 allow_dca = (container != HB_MUX_MP4);
1361 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1363 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1365 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1367 if (audio && audio->in.codec != HB_ACODEC_AC3)
1369 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1371 if (audio && audio->in.codec != HB_ACODEC_DCA)
1373 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1375 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1377 widget = GHB_WIDGET (builder, "AudioEncoder");
1378 gval = ghb_widget_value(widget);
1379 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1380 ghb_value_free(gval);
1381 if (acodec != HB_ACODEC_AC3)
1383 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1385 if (container == HB_MUX_MP4)
1387 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
1388 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1389 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1392 gboolean allow_mono = TRUE;
1393 gboolean allow_stereo = TRUE;
1394 gboolean allow_dolby = TRUE;
1395 gboolean allow_dpl2 = TRUE;
1396 gboolean allow_6ch = TRUE;
1397 allow_mono = acodec & ~HB_ACODEC_LAME;
1398 allow_6ch = acodec & ~HB_ACODEC_LAME;
1401 allow_mono = allow_mono &&
1402 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA));
1403 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1405 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1407 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1408 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1409 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1410 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1411 allow_6ch = allow_6ch &&
1412 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1413 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1414 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1416 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1417 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1418 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1419 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1420 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1424 ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
1426 if (acodec & HB_ACODEC_FAAC)
1428 int maxbr = channels * 80;
1436 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1438 hb_audio_config_t *audio = NULL;
1439 gboolean allow_mono = TRUE;
1440 gboolean allow_stereo = TRUE;
1441 gboolean allow_dolby = TRUE;
1442 gboolean allow_dpl2 = TRUE;
1443 gboolean allow_6ch = TRUE;
1445 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1447 // Audio codec pass-thru. No mixdown
1450 audio = get_hb_audio(titleindex, track);
1454 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1455 (acodec & ~HB_ACODEC_LAME);
1456 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1458 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1460 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1461 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1462 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1463 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1465 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1466 (acodec & ~HB_ACODEC_LAME) &&
1467 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1468 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1470 gboolean greater = FALSE;
1473 // If no mix is specified, select the best available.
1474 mix = HB_AMIXDOWN_6CH;
1476 if (mix == HB_AMIXDOWN_6CH)
1479 if (allow_6ch) return HB_AMIXDOWN_6CH;
1481 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1484 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1486 if (mix == HB_AMIXDOWN_DOLBY || greater)
1489 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1491 if (mix == HB_AMIXDOWN_STEREO || greater)
1494 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1496 if (mix == HB_AMIXDOWN_MONO || greater)
1499 if (allow_mono) return HB_AMIXDOWN_MONO;
1501 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1502 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1503 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1504 if (allow_6ch) return HB_AMIXDOWN_6CH;
1508 // Set up the model for the combo box
1510 init_combo_box(GtkBuilder *builder, const gchar *name)
1513 GtkListStore *store;
1514 GtkCellRenderer *cell;
1516 g_debug("init_combo_box() %s\n", name);
1517 // First modify the combobox model to allow greying out of options
1518 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1522 // 1 - String to display
1523 // 2 - bool indicating whether the entry is selectable (grey or not)
1524 // 3 - String that is used for presets
1525 // 4 - Int value determined by backend
1526 // 5 - String value determined by backend
1527 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1528 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1529 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1531 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1533 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1534 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1535 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1536 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1537 "markup", 0, "sensitive", 1, NULL);
1540 { // Combo box entry
1541 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1546 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1549 GtkListStore *store;
1553 g_debug("audio_samplerate_opts_set ()\n");
1554 store = get_combo_box_store(builder, name);
1555 gtk_list_store_clear(store);
1556 // Add an item for "Same As Source"
1557 gtk_list_store_append(store, &iter);
1558 gtk_list_store_set(store, &iter,
1559 0, "<small>Same as source</small>",
1565 for (ii = 0; ii < count; ii++)
1567 gtk_list_store_append(store, &iter);
1568 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1569 gtk_list_store_set(store, &iter,
1572 2, rates[ii].string,
1573 3, (gdouble)rates[ii].rate,
1574 4, rates[ii].string,
1581 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1584 GtkListStore *store;
1587 g_debug("video_rate_opts_set ()\n");
1588 store = get_combo_box_store(builder, name);
1589 gtk_list_store_clear(store);
1590 // Add an item for "Same As Source"
1591 gtk_list_store_append(store, &iter);
1592 gtk_list_store_set(store, &iter,
1593 0, "Same as source",
1599 for (ii = 0; ii < count; ii++)
1603 if (strcmp(rates[ii].string, "23.976") == 0)
1605 desc = "(NTSC Film)";
1607 else if (strcmp(rates[ii].string, "25") == 0)
1609 desc = "(PAL Film/Video)";
1611 else if (strcmp(rates[ii].string, "29.97") == 0)
1613 desc = "(NTSC Video)";
1615 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1616 gtk_list_store_append(store, &iter);
1617 gtk_list_store_set(store, &iter,
1620 2, rates[ii].string,
1621 3, (gdouble)rates[ii].rate,
1622 4, rates[ii].string,
1629 mix_opts_set(GtkBuilder *builder, const gchar *name)
1632 GtkListStore *store;
1636 g_debug("mix_opts_set ()\n");
1637 store = get_combo_box_store(builder, name);
1638 gtk_list_store_clear(store);
1639 gtk_list_store_append(store, &iter);
1640 gtk_list_store_set(store, &iter,
1641 0, "<small>None</small>",
1647 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1649 gtk_list_store_append(store, &iter);
1650 str = g_strdup_printf("<small>%s</small>",
1651 hb_audio_mixdowns[ii].human_readable_name);
1652 gtk_list_store_set(store, &iter,
1655 2, hb_audio_mixdowns[ii].short_name,
1656 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1657 4, hb_audio_mixdowns[ii].internal_name,
1664 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1667 GtkListStore *store;
1670 g_debug("srt_codeset_opts_set ()\n");
1671 store = get_combo_box_store(builder, name);
1672 gtk_list_store_clear(store);
1673 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1675 gtk_list_store_append(store, &iter);
1676 gtk_list_store_set(store, &iter,
1677 0, srt_codeset_table[ii],
1679 2, srt_codeset_table[ii],
1681 4, srt_codeset_table[ii],
1684 GtkComboBoxEntry *cbe;
1686 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1687 //gtk_combo_box_entry_set_text_column(cbe, 0);
1691 language_opts_set(GtkBuilder *builder, const gchar *name)
1694 GtkListStore *store;
1697 g_debug("language_opts_set ()\n");
1698 store = get_combo_box_store(builder, name);
1699 gtk_list_store_clear(store);
1700 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1704 if (ghb_language_table[ii].native_name[0] != 0)
1705 lang = ghb_language_table[ii].native_name;
1707 lang = ghb_language_table[ii].eng_name;
1709 gtk_list_store_append(store, &iter);
1710 gtk_list_store_set(store, &iter,
1713 2, ghb_language_table[ii].iso639_2,
1715 4, ghb_language_table[ii].iso639_1,
1720 static gchar **titles = NULL;
1723 title_opts_set(GtkBuilder *builder, const gchar *name)
1726 GtkListStore *store;
1727 hb_list_t * list = NULL;
1728 hb_title_t * title = NULL;
1732 g_debug("title_opts_set ()\n");
1733 store = get_combo_box_store(builder, name);
1734 gtk_list_store_clear(store);
1737 list = hb_get_titles( h_scan );
1738 count = hb_list_count( list );
1739 if (count > 100) count = 100;
1741 if (titles) g_strfreev(titles);
1742 if (title_opts.map) g_free(title_opts.map);
1745 title_opts.count = count;
1746 title_opts.map = g_malloc(count*sizeof(options_map_t));
1747 titles = g_malloc((count+1) * sizeof(gchar*));
1751 title_opts.count = 1;
1752 title_opts.map = g_malloc(sizeof(options_map_t));
1757 // No titles. Fill in a default.
1758 gtk_list_store_append(store, &iter);
1759 gtk_list_store_set(store, &iter,
1766 title_opts.map[0].option = "No Titles";
1767 title_opts.map[0].shortOpt = "none";
1768 title_opts.map[0].ivalue = -1;
1769 title_opts.map[0].svalue = "none";
1772 for (ii = 0; ii < count; ii++)
1774 title = (hb_title_t*)hb_list_item(list, ii);
1775 if (title->type == HB_STREAM_TYPE)
1777 if (title->duration != 0)
1779 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
1780 title->index, title->hours, title->minutes, title->seconds,
1785 titles[ii] = g_strdup_printf ("%d - %s",
1786 title->index, title->name);
1791 if (title->duration != 0)
1793 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1794 title->index, title->hours, title->minutes, title->seconds);
1798 titles[ii] = g_strdup_printf ("%d - Unknown Length",
1802 gtk_list_store_append(store, &iter);
1803 gtk_list_store_set(store, &iter,
1810 title_opts.map[ii].option = titles[ii];
1811 title_opts.map[ii].shortOpt = titles[ii];
1812 title_opts.map[ii].ivalue = ii;
1813 title_opts.map[ii].svalue = titles[ii];
1819 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1822 gboolean foundit = FALSE;
1824 if (gtk_tree_model_get_iter_first (store, iter))
1828 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1829 if (value == (int)ivalue)
1834 } while (gtk_tree_model_iter_next (store, iter));
1840 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1843 GtkListStore *store;
1844 hb_list_t * list = NULL;
1845 hb_title_t * title = NULL;
1846 hb_audio_config_t * audio;
1851 g_debug("audio_track_opts_set ()\n");
1852 store = get_combo_box_store(builder, name);
1853 gtk_list_store_clear(store);
1856 list = hb_get_titles( h_scan );
1857 title = (hb_title_t*)hb_list_item( list, titleindex );
1860 count = hb_list_count( title->list_audio );
1863 if (count > 100) count = 100;
1864 if (audio_track_opts.map) g_free(audio_track_opts.map);
1867 audio_track_opts.count = count;
1868 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1872 audio_track_opts.count = 1;
1873 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1877 // No audio. set some default
1878 gtk_list_store_append(store, &iter);
1879 gtk_list_store_set(store, &iter,
1880 0, "<small>No Audio</small>",
1886 audio_track_opts.map[0].option = "No Audio";
1887 audio_track_opts.map[0].shortOpt = "none";
1888 audio_track_opts.map[0].ivalue = -1;
1889 audio_track_opts.map[0].svalue = "none";
1892 index_str_init(count-1);
1893 for (ii = 0; ii < count; ii++)
1895 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1896 gtk_list_store_append(store, &iter);
1897 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
1898 gtk_list_store_set(store, &iter,
1906 audio_track_opts.map[ii].option = audio->lang.description,
1907 audio_track_opts.map[ii].shortOpt = index_str[ii];
1908 audio_track_opts.map[ii].ivalue = ii;
1909 audio_track_opts.map[ii].svalue = index_str[ii];
1914 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1917 GtkListStore *store;
1918 hb_list_t * list = NULL;
1919 hb_title_t * title = NULL;
1920 hb_subtitle_t * subtitle;
1922 static char ** options = NULL;
1924 g_debug("subtitle_track_opts_set ()\n");
1925 store = get_combo_box_store(builder, name);
1926 gtk_list_store_clear(store);
1929 list = hb_get_titles( h_scan );
1930 title = (hb_title_t*)hb_list_item( list, titleindex );
1933 count = hb_list_count( title->list_subtitle );
1936 if (count > 100) count = 100;
1937 if (subtitle_opts.map) g_free(subtitle_opts.map);
1940 subtitle_opts.count = count+1;
1941 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
1945 subtitle_opts.count = LANG_TABLE_SIZE+1;
1946 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
1948 gtk_list_store_append(store, &iter);
1949 gtk_list_store_set(store, &iter,
1950 0, "Foreign Audio Search",
1956 subtitle_opts.map[0].option = "Foreign Audio Search";
1957 subtitle_opts.map[0].shortOpt = "-1";
1958 subtitle_opts.map[0].ivalue = -1;
1959 subtitle_opts.map[0].svalue = "auto";
1962 if (options != NULL)
1963 g_strfreev(options);
1964 options = g_malloc((count+1)*sizeof(gchar*));
1965 index_str_init(count-1);
1966 for (ii = 0; ii < count; ii++)
1968 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
1969 // Skip subtitles that must be burned if there is already
1970 // a burned subtitle in the list
1971 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
1972 subtitle_opts.map[ii+1].option = options[ii];
1973 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
1974 subtitle_opts.map[ii+1].ivalue = ii;
1975 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
1976 gtk_list_store_append(store, &iter);
1977 gtk_list_store_set(store, &iter,
1982 4, subtitle->iso639_2,
1985 options[count] = NULL;
1989 index_str_init(LANG_TABLE_SIZE-1);
1990 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1994 if (ghb_language_table[ii].native_name[0] != 0)
1995 lang = ghb_language_table[ii].native_name;
1997 lang = ghb_language_table[ii].eng_name;
1999 subtitle_opts.map[ii+1].option = lang;
2000 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2001 subtitle_opts.map[ii+1].ivalue = ii;
2002 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
2003 gtk_list_store_append(store, &iter);
2004 gtk_list_store_set(store, &iter,
2009 4, ghb_language_table[ii].iso639_2,
2022 guint64 longest = 0;
2023 gint titleindex = 0;
2025 g_debug("ghb_longest_title ()\n");
2026 if (h_scan == NULL) return 0;
2027 list = hb_get_titles( h_scan );
2028 count = hb_list_count( list );
2029 if (count > 100) count = 100;
2030 for (ii = 0; ii < count; ii++)
2032 title = (hb_title_t*)hb_list_item(list, ii);
2033 if (title->duration > longest)
2036 longest = title->duration;
2043 ghb_get_source_audio_lang(gint titleindex, gint track)
2047 hb_audio_config_t * audio;
2050 g_debug("ghb_lookup_1st_audio_lang ()\n");
2053 list = hb_get_titles( h_scan );
2054 title = (hb_title_t*)hb_list_item( list, titleindex );
2057 if (hb_list_count( title->list_audio ) <= track)
2060 audio = hb_list_audio_config_item(title->list_audio, track);
2064 lang = g_strdup(audio->lang.iso639_2);
2069 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2073 used = g_hash_table_lookup(track_indices, &acodec);
2078 used = g_malloc0(count * sizeof(gboolean));
2079 key = g_malloc(sizeof(gint));
2081 g_hash_table_insert(track_indices, key, used);
2087 ghb_find_audio_track(
2091 gint fallback_acodec,
2092 GHashTable *track_indices)
2096 hb_audio_config_t * audio;
2104 g_debug("find_audio_track ()\n");
2105 if (h_scan == NULL) return -1;
2106 list = hb_get_titles( h_scan );
2107 title = (hb_title_t*)hb_list_item( list, titleindex );
2110 count = hb_list_count( title->list_audio );
2112 if (count > 10) count = 10;
2113 // Try to find an item that matches the preferred language and
2114 // the passthru codec type
2115 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2117 for (ii = 0; ii < count; ii++)
2121 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2122 title->list_audio, ii );
2123 try_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2124 // Is the source track use a passthru capable codec?
2125 if (try_acodec == 0)
2127 used = get_track_used(try_acodec, track_indices, count);
2128 // Has the track already been used with this codec?
2132 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2133 audio->in.channel_layout);
2134 // Find a track that is not visually impaired or dirctor's
2135 // commentary, and has the highest channel count.
2136 if ((audio->lang.type < 2) &&
2137 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2138 (strcmp(lang, "und") == 0)))
2140 if (channels > max_chan)
2143 max_chan = channels;
2147 try_acodec = fallback_acodec;
2151 try_acodec = acodec;
2158 // Try to find an item that matches the preferred language
2159 used = get_track_used(try_acodec, track_indices, count);
2160 for (ii = 0; ii < count; ii++)
2162 // Has the track already been used with this codec?
2165 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2166 title->list_audio, ii );
2167 // Find a track that is not visually impaired or dirctor's commentary
2168 if ((audio->lang.type < 2) &&
2169 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2170 (strcmp(lang, "und") == 0)))
2181 // Try to fine an item that does not match the preferred language and
2182 // matches the passthru codec type
2183 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
2185 for (ii = 0; ii < count; ii++)
2189 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2190 title->list_audio, ii );
2191 try_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2192 // Is the source track use a passthru capable codec?
2193 if (try_acodec == 0)
2195 used = get_track_used(try_acodec, track_indices, count);
2196 // Has the track already been used with this codec?
2200 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2201 audio->in.channel_layout);
2202 // Find a track that is not visually impaired or dirctor's
2203 // commentary, and has the highest channel count.
2204 if (audio->lang.type < 2)
2206 if (channels > max_chan)
2209 max_chan = channels;
2213 try_acodec = fallback_acodec;
2217 try_acodec = acodec;
2224 // Try to fine an item that does not match the preferred language
2225 used = get_track_used(try_acodec, track_indices, count);
2226 for (ii = 0; ii < count; ii++)
2228 // Has the track already been used with this codec?
2231 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2232 title->list_audio, ii );
2233 // Find a track that is not visually impaired or dirctor's commentary
2234 if (audio->lang.type < 2)
2245 // Last ditch, anything goes
2246 for (ii = 0; ii < count; ii++)
2248 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2249 title->list_audio, ii );
2250 // Has the track already been used with this codec?
2265 ghb_find_pref_subtitle_track(const gchar *lang)
2268 count = subtitle_opts.count;
2269 for (ii = 0; ii < count; ii++)
2271 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2273 return subtitle_opts.map[ii].ivalue;
2280 ghb_find_cc_track(gint titleindex)
2284 hb_subtitle_t * subtitle;
2287 g_debug("ghb_find_cc_track ()\n");
2288 if (h_scan == NULL) return -2;
2289 list = hb_get_titles( h_scan );
2290 title = (hb_title_t*)hb_list_item( list, titleindex );
2293 count = hb_list_count( title->list_subtitle );
2294 // Try to find an item that matches the preferred language
2295 for (ii = 0; ii < count; ii++)
2297 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2298 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2306 ghb_find_subtitle_track(
2312 GHashTable * track_indices)
2316 hb_subtitle_t * subtitle;
2320 g_debug("find_subtitle_track ()\n");
2321 if (strcmp(lang, "auto") == 0)
2323 if (h_scan == NULL) return -1;
2324 list = hb_get_titles( h_scan );
2325 title = (hb_title_t*)hb_list_item( list, titleindex );
2328 count = hb_list_count( title->list_subtitle );
2329 used = g_hash_table_lookup(track_indices, lang);
2332 used = g_malloc0(count * sizeof(gboolean));
2333 g_hash_table_insert(track_indices, g_strdup(lang), used);
2335 // Try to find an item that matches the preferred language and source
2336 for (ii = 0; ii < count; ii++)
2341 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2342 if (source == subtitle->source &&
2343 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2344 (strcmp(lang, "und") == 0)))
2350 // Try to find an item that matches the preferred language
2351 for (ii = 0; ii < count; ii++)
2356 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2357 if (((burn || force) && (subtitle->source == VOBSUB)) &&
2358 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2359 (strcmp(lang, "und") == 0)))
2370 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2373 GtkListStore *store;
2376 g_debug("generic_opts_set ()\n");
2377 if (name == NULL || opts == NULL) return;
2378 store = get_combo_box_store(builder, name);
2379 gtk_list_store_clear(store);
2380 for (ii = 0; ii < opts->count; ii++)
2382 gtk_list_store_append(store, &iter);
2383 gtk_list_store_set(store, &iter,
2384 0, opts->map[ii].option,
2386 2, opts->map[ii].shortOpt,
2387 3, opts->map[ii].ivalue,
2388 4, opts->map[ii].svalue,
2394 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2397 GtkListStore *store;
2401 g_debug("generic_opts_set ()\n");
2402 if (name == NULL || opts == NULL) return;
2403 store = get_combo_box_store(builder, name);
2404 gtk_list_store_clear(store);
2405 for (ii = 0; ii < opts->count; ii++)
2407 gtk_list_store_append(store, &iter);
2408 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2409 gtk_list_store_set(store, &iter,
2412 2, opts->map[ii].shortOpt,
2413 3, opts->map[ii].ivalue,
2414 4, opts->map[ii].svalue,
2421 find_combo_table(const gchar *name)
2425 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2427 if (strcmp(name, combo_name_map[ii].name) == 0)
2429 return combo_name_map[ii].opts;
2436 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2440 if (strcmp(name, "AudioBitrate") == 0)
2441 return lookup_audio_bitrate_int(gval);
2442 else if (strcmp(name, "AudioSamplerate") == 0)
2443 return lookup_audio_rate_int(gval);
2444 else if (strcmp(name, "VideoFramerate") == 0)
2445 return lookup_video_rate_int(gval);
2446 else if (strcmp(name, "AudioMixdown") == 0)
2447 return lookup_mix_int(gval);
2448 else if (strcmp(name, "SrtLanguage") == 0)
2449 return lookup_audio_lang_int(gval);
2450 else if (strcmp(name, "PreferredLanguage") == 0)
2451 return lookup_audio_lang_int(gval);
2454 return lookup_generic_int(find_combo_table(name), gval);
2456 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2461 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2465 if (strcmp(name, "AudioBitrate") == 0)
2466 return lookup_audio_bitrate_int(gval);
2467 else if (strcmp(name, "AudioSamplerate") == 0)
2468 return lookup_audio_rate_int(gval);
2469 else if (strcmp(name, "VideoFramerate") == 0)
2470 return lookup_video_rate_int(gval);
2471 else if (strcmp(name, "AudioMixdown") == 0)
2472 return lookup_mix_int(gval);
2473 else if (strcmp(name, "SrtLanguage") == 0)
2474 return lookup_audio_lang_int(gval);
2475 else if (strcmp(name, "PreferredLanguage") == 0)
2476 return lookup_audio_lang_int(gval);
2479 return lookup_generic_double(find_combo_table(name), gval);
2481 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2486 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2490 if (strcmp(name, "AudioBitrate") == 0)
2491 return lookup_audio_bitrate_option(gval);
2492 else if (strcmp(name, "AudioSamplerate") == 0)
2493 return lookup_audio_rate_option(gval);
2494 else if (strcmp(name, "VideoFramerate") == 0)
2495 return lookup_video_rate_option(gval);
2496 else if (strcmp(name, "AudioMixdown") == 0)
2497 return lookup_mix_option(gval);
2498 else if (strcmp(name, "SrtLanguage") == 0)
2499 return lookup_audio_lang_option(gval);
2500 else if (strcmp(name, "PreferredLanguage") == 0)
2501 return lookup_audio_lang_option(gval);
2504 return lookup_generic_option(find_combo_table(name), gval);
2506 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2511 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2515 if (strcmp(name, "AudioBitrate") == 0)
2516 return lookup_audio_bitrate_option(gval);
2517 else if (strcmp(name, "AudioSamplerate") == 0)
2518 return lookup_audio_rate_option(gval);
2519 else if (strcmp(name, "VideoFramerate") == 0)
2520 return lookup_video_rate_option(gval);
2521 else if (strcmp(name, "AudioMixdown") == 0)
2522 return lookup_mix_option(gval);
2523 else if (strcmp(name, "SrtLanguage") == 0)
2524 return lookup_audio_lang_option(gval);
2525 else if (strcmp(name, "PreferredLanguage") == 0)
2526 return lookup_audio_lang_option(gval);
2529 return lookup_generic_string(find_combo_table(name), gval);
2531 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2536 ghb_update_ui_combo_box(
2537 signal_user_data_t *ud,
2542 GtkComboBox *combo = NULL;
2544 gint handler_id = 0;
2548 g_debug("ghb_update_ui_combo_box() %s\n", name);
2549 // Clearing a combo box causes a rash of "changed" events, even when
2550 // the active item is -1 (inactive). To control things, I'm disabling
2551 // the event till things are settled down.
2552 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2553 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2556 // Valid signal id found. This should always succeed.
2557 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2558 signal_id, 0, 0, 0, 0);
2561 // This should also always succeed
2562 g_signal_handler_block ((gpointer)combo, handler_id);
2568 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2569 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2570 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2571 mix_opts_set(ud->builder, "AudioMixdown");
2572 language_opts_set(ud->builder, "SrtLanguage");
2573 language_opts_set(ud->builder, "PreferredLanguage");
2574 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2575 title_opts_set(ud->builder, "title");
2576 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2577 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2578 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2579 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2580 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2581 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2582 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2583 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2584 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2585 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2586 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2587 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2588 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2589 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2590 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2591 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2592 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2593 generic_opts_set(ud->builder, "x264_direct", &direct_opts);
2594 generic_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2595 generic_opts_set(ud->builder, "x264_me", &me_opts);
2596 generic_opts_set(ud->builder, "x264_subme", &subme_opts);
2597 generic_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2598 generic_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2602 if (strcmp(name, "AudioBitrate") == 0)
2603 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2604 else if (strcmp(name, "AudioSamplerate") == 0)
2605 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2606 else if (strcmp(name, "VideoFramerate") == 0)
2607 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2608 else if (strcmp(name, "AudioMixdown") == 0)
2609 mix_opts_set(ud->builder, "AudioMixdown");
2610 else if (strcmp(name, "SrtLanguage") == 0)
2611 language_opts_set(ud->builder, "SrtLanguage");
2612 else if (strcmp(name, "PreferredLanguage") == 0)
2613 language_opts_set(ud->builder, "PreferredLanguage");
2614 else if (strcmp(name, "SrtCodeset") == 0)
2615 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2616 else if (strcmp(name, "title") == 0)
2617 title_opts_set(ud->builder, "title");
2618 else if (strcmp(name, "SubtitleTrack") == 0)
2619 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2620 else if (strcmp(name, "AudioTrack") == 0)
2621 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2623 generic_opts_set(ud->builder, name, find_combo_table(name));
2627 g_signal_handler_unblock ((gpointer)combo, handler_id);
2632 init_ui_combo_boxes(GtkBuilder *builder)
2636 init_combo_box(builder, "AudioBitrate");
2637 init_combo_box(builder, "AudioSamplerate");
2638 init_combo_box(builder, "VideoFramerate");
2639 init_combo_box(builder, "AudioMixdown");
2640 init_combo_box(builder, "SrtLanguage");
2641 init_combo_box(builder, "PreferredLanguage");
2642 init_combo_box(builder, "SrtCodeset");
2643 init_combo_box(builder, "title");
2644 init_combo_box(builder, "AudioTrack");
2645 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2647 init_combo_box(builder, combo_name_map[ii].name);
2651 static const char * turbo_opts =
2652 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2653 "no-fast-pskip=0:8x8dct=0";
2655 // Construct the x264 options string
2656 // The result is allocated, so someone must free it at some point.
2658 ghb_build_x264opts_string(GValue *settings)
2661 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2668 result = g_strdup("");
2674 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2678 hb_chapter_t * chapter;
2682 *hh = *mm = *ss = 0;
2683 if (h_scan == NULL) return;
2684 list = hb_get_titles( h_scan );
2685 title = (hb_title_t*)hb_list_item( list, tt );
2686 if (title == NULL) return;
2689 *mm = title->minutes;
2690 *ss = title->seconds;
2692 count = hb_list_count(title->list_chapter);
2693 if (sc > count) sc = count;
2694 if (ec > count) ec = count;
2696 if (sc == 1 && ec == count)
2700 for (c = sc; c <= ec; c++)
2702 chapter = hb_list_item(title->list_chapter, c-1);
2703 duration += chapter->duration;
2706 *hh = duration / 90000 / 3600;
2707 *mm = ((duration / 90000) % 3600) / 60;
2708 *ss = (duration / 90000) % 60;
2712 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2716 hb_chapter_t * chapter;
2719 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2720 *hh = *mm = *ss = 0;
2721 if (h_scan == NULL) return;
2722 list = hb_get_titles( h_scan );
2723 title = (hb_title_t*)hb_list_item( list, ti );
2724 if (title == NULL) return;
2725 count = hb_list_count( title->list_chapter );
2726 if (ii >= count) return;
2727 chapter = hb_list_item(title->list_chapter, ii);
2728 if (chapter == NULL) return;
2729 *hh = chapter->hours;
2730 *mm = chapter->minutes;
2731 *ss = chapter->seconds;
2735 ghb_get_chapters(gint titleindex)
2739 hb_chapter_t * chapter;
2741 GValue *chapters = NULL;
2743 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2744 if (h_scan == NULL) return NULL;
2745 list = hb_get_titles( h_scan );
2746 title = (hb_title_t*)hb_list_item( list, titleindex );
2747 if (title == NULL) return NULL;
2748 count = hb_list_count( title->list_chapter );
2749 chapters = ghb_array_value_new(count);
2750 for (ii = 0; ii < count; ii++)
2752 chapter = hb_list_item(title->list_chapter, ii);
2753 if (chapter == NULL) break;
2754 if (chapter->title == NULL || chapter->title[0] == 0)
2757 str = g_strdup_printf ("Chapter %2d", ii+1);
2758 ghb_array_append(chapters, ghb_string_value_new(str));
2763 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2770 ghb_ac3_in_audio_list(const GValue *audio_list)
2774 count = ghb_array_len(audio_list);
2775 for (ii = 0; ii < count; ii++)
2780 asettings = ghb_array_get_nth(audio_list, ii);
2781 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2782 if (acodec & HB_ACODEC_AC3)
2789 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2792 GtkListStore *store;
2795 g_debug("audio_bitrate_opts_add ()\n");
2797 if (rate < 8) return;
2799 store = get_combo_box_store(builder, name);
2800 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2802 str = g_strdup_printf ("<small>%d</small>", rate);
2803 gtk_list_store_append(store, &iter);
2804 gtk_list_store_set(store, &iter,
2816 audio_bitrate_opts_clean(
2817 GtkBuilder *builder,
2823 GtkListStore *store;
2825 gboolean done = FALSE;
2827 guint last = (guint)last_rate;
2828 guint first = (guint)first_rate;
2830 g_debug("audio_bitrate_opts_clean ()\n");
2831 store = get_combo_box_store(builder, name);
2832 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
2836 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
2838 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
2840 done = !gtk_list_store_remove(store, &iter);
2842 else if (ivalue < first || ivalue > last)
2845 gtk_list_store_set(store, &iter, 1, FALSE, -1);
2846 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2851 gtk_list_store_set(store, &iter, 1, TRUE, -1);
2852 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
2859 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
2862 GtkListStore *store;
2866 g_debug("audio_bitrate_opts_set ()\n");
2867 store = get_combo_box_store(builder, name);
2868 gtk_list_store_clear(store);
2869 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
2871 gtk_list_store_append(store, &iter);
2872 str = g_strdup_printf ("<small>%s</small>",
2873 hb_audio_bitrates[ii].string);
2874 gtk_list_store_set(store, &iter,
2877 2, hb_audio_bitrates[ii].string,
2878 3, (gdouble)hb_audio_bitrates[ii].rate,
2879 4, hb_audio_bitrates[ii].string,
2886 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
2888 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
2892 ghb_set_default_bitrate_opts(
2893 GtkBuilder *builder,
2897 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
2900 static ghb_status_t hb_status;
2903 ghb_combo_init(signal_user_data_t *ud)
2905 // Set up the list model for the combos
2906 init_ui_combo_boxes(ud->builder);
2907 // Populate all the combos
2908 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
2912 ghb_backend_init(gint debug)
2915 h_scan = hb_init( debug, 0 );
2916 h_queue = hb_init( debug, 0 );
2926 void ghb_backend_scan_stop()
2928 hb_scan_stop( h_scan );
2932 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
2934 hb_scan( h_scan, path, titleindex, preview_count, 1 );
2935 hb_status.scan.state |= GHB_STATE_SCANNING;
2936 // initialize count and cur to something that won't cause FPE
2937 // when computing progress
2938 hb_status.scan.title_count = 1;
2939 hb_status.scan.title_cur = 0;
2943 ghb_backend_queue_scan(const gchar *path, gint titlenum)
2945 g_debug("ghb_backend_queue_scan()");
2946 hb_scan( h_queue, path, titlenum, 10, 0 );
2947 hb_status.queue.state |= GHB_STATE_SCANNING;
2951 ghb_get_scan_state()
2953 return hb_status.scan.state;
2957 ghb_get_queue_state()
2959 return hb_status.queue.state;
2963 ghb_clear_scan_state(gint state)
2965 hb_status.scan.state &= ~state;
2969 ghb_clear_queue_state(gint state)
2971 hb_status.queue.state &= ~state;
2975 ghb_set_scan_state(gint state)
2977 hb_status.scan.state |= state;
2981 ghb_set_queue_state(gint state)
2983 hb_status.queue.state |= state;
2987 ghb_get_status(ghb_status_t *status)
2989 memcpy(status, &hb_status, sizeof(ghb_status_t));
2998 if (h_scan == NULL) return;
2999 hb_get_state( h_scan, &s_scan );
3000 switch( s_scan.state )
3002 #define p s_scan.param.scanning
3003 case HB_STATE_SCANNING:
3005 hb_status.scan.state |= GHB_STATE_SCANNING;
3006 hb_status.scan.title_count = p.title_count;
3007 hb_status.scan.title_cur = p.title_cur;
3011 case HB_STATE_SCANDONE:
3013 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3014 hb_status.scan.state |= GHB_STATE_SCANDONE;
3017 #define p s_scan.param.working
3018 case HB_STATE_WORKING:
3019 hb_status.scan.state |= GHB_STATE_WORKING;
3020 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3021 hb_status.scan.job_cur = p.job_cur;
3022 hb_status.scan.job_count = p.job_count;
3023 hb_status.scan.progress = p.progress;
3024 hb_status.scan.rate_cur = p.rate_cur;
3025 hb_status.scan.rate_avg = p.rate_avg;
3026 hb_status.scan.hours = p.hours;
3027 hb_status.scan.minutes = p.minutes;
3028 hb_status.scan.seconds = p.seconds;
3029 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3033 case HB_STATE_PAUSED:
3034 hb_status.scan.state |= GHB_STATE_PAUSED;
3037 case HB_STATE_MUXING:
3039 hb_status.scan.state |= GHB_STATE_MUXING;
3042 #define p s_scan.param.workdone
3043 case HB_STATE_WORKDONE:
3047 hb_status.scan.state |= GHB_STATE_WORKDONE;
3048 hb_status.scan.state &= ~GHB_STATE_MUXING;
3049 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3050 hb_status.scan.state &= ~GHB_STATE_WORKING;
3054 hb_status.scan.error = GHB_ERROR_NONE;
3056 case HB_ERROR_CANCELED:
3057 hb_status.scan.error = GHB_ERROR_CANCELED;
3060 hb_status.scan.error = GHB_ERROR_FAIL;
3063 // Delete all remaining jobs of this encode.
3064 // An encode can be composed of multiple associated jobs.
3065 // When a job is stopped, libhb removes it from the job list,
3066 // but does not remove other jobs that may be associated with it.
3067 // Associated jobs are taged in the sequence id.
3068 while ((job = hb_job(h_scan, 0)) != NULL)
3069 hb_rem( h_scan, job );
3073 hb_get_state( h_queue, &s_queue );
3074 switch( s_queue.state )
3076 #define p s_queue.param.scanning
3077 case HB_STATE_SCANNING:
3079 hb_status.queue.state |= GHB_STATE_SCANNING;
3080 hb_status.queue.title_count = p.title_count;
3081 hb_status.queue.title_cur = p.title_cur;
3085 case HB_STATE_SCANDONE:
3087 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3088 hb_status.queue.state |= GHB_STATE_SCANDONE;
3091 #define p s_queue.param.working
3092 case HB_STATE_WORKING:
3093 hb_status.queue.state |= GHB_STATE_WORKING;
3094 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3095 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3096 hb_status.queue.job_cur = p.job_cur;
3097 hb_status.queue.job_count = p.job_count;
3098 hb_status.queue.progress = p.progress;
3099 hb_status.queue.rate_cur = p.rate_cur;
3100 hb_status.queue.rate_avg = p.rate_avg;
3101 hb_status.queue.hours = p.hours;
3102 hb_status.queue.minutes = p.minutes;
3103 hb_status.queue.seconds = p.seconds;
3104 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3107 case HB_STATE_SEARCHING:
3108 hb_status.queue.state |= GHB_STATE_SEARCHING;
3109 hb_status.queue.state &= ~GHB_STATE_WORKING;
3110 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3111 hb_status.queue.job_cur = p.job_cur;
3112 hb_status.queue.job_count = p.job_count;
3113 hb_status.queue.progress = p.progress;
3114 hb_status.queue.rate_cur = p.rate_cur;
3115 hb_status.queue.rate_avg = p.rate_avg;
3116 hb_status.queue.hours = p.hours;
3117 hb_status.queue.minutes = p.minutes;
3118 hb_status.queue.seconds = p.seconds;
3119 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3123 case HB_STATE_PAUSED:
3124 hb_status.queue.state |= GHB_STATE_PAUSED;
3127 case HB_STATE_MUXING:
3129 hb_status.queue.state |= GHB_STATE_MUXING;
3132 #define p s_queue.param.workdone
3133 case HB_STATE_WORKDONE:
3137 hb_status.queue.state |= GHB_STATE_WORKDONE;
3138 hb_status.queue.state &= ~GHB_STATE_MUXING;
3139 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3140 hb_status.queue.state &= ~GHB_STATE_WORKING;
3144 hb_status.queue.error = GHB_ERROR_NONE;
3146 case HB_ERROR_CANCELED:
3147 hb_status.queue.error = GHB_ERROR_CANCELED;
3150 hb_status.queue.error = GHB_ERROR_FAIL;
3153 // Delete all remaining jobs of this encode.
3154 // An encode can be composed of multiple associated jobs.
3155 // When a job is stopped, libhb removes it from the job list,
3156 // but does not remove other jobs that may be associated with it.
3157 // Associated jobs are taged in the sequence id.
3158 while ((job = hb_job(h_queue, 0)) != NULL)
3159 hb_rem( h_queue, job );
3166 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3171 if (h_scan == NULL) return FALSE;
3172 list = hb_get_titles( h_scan );
3173 if( !hb_list_count( list ) )
3175 /* No valid title, stop right there */
3179 title = hb_list_item( list, titleindex );
3180 if (title == NULL) return FALSE; // Bad titleindex
3181 tinfo->index = titleindex;
3182 tinfo->width = title->width;
3183 tinfo->height = title->height;
3184 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3185 // Don't allow crop to 0
3186 if (title->crop[0] + title->crop[1] >= title->height)
3187 title->crop[0] = title->crop[1] = 0;
3188 if (title->crop[2] + title->crop[3] >= title->width)
3189 title->crop[2] = title->crop[3] = 0;
3190 tinfo->num_chapters = hb_list_count(title->list_chapter);
3191 tinfo->rate_base = title->rate_base;
3192 tinfo->rate = title->rate;
3193 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3194 title->width * title->pixel_aspect_width,
3195 title->height * title->pixel_aspect_height);
3196 tinfo->hours = title->hours;
3197 tinfo->minutes = title->minutes;
3198 tinfo->seconds = title->seconds;
3199 tinfo->duration = title->duration;
3201 tinfo->angle_count = title->angle_count;
3202 tinfo->path = title->path;
3203 tinfo->name = title->name;
3204 tinfo->type = title->type;
3209 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3211 hb_audio_config_t *audio;
3213 audio = get_hb_audio(titleindex, audioindex);
3214 if (audio == NULL) return FALSE; // Bad audioindex
3215 ainfo->codec = audio->in.codec;
3216 ainfo->bitrate = audio->in.bitrate;
3217 ainfo->samplerate = audio->in.samplerate;
3222 ghb_audio_is_passthru(gint acodec)
3224 g_debug("ghb_audio_is_passthru () \n");
3225 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
3229 ghb_get_default_acodec()
3231 return HB_ACODEC_FAAC;
3235 picture_settings_deps(signal_user_data_t *ud)
3237 gboolean autoscale, keep_aspect, enable_keep_aspect;
3238 gboolean enable_scale_width, enable_scale_height;
3239 gboolean enable_disp_width, enable_disp_height, enable_par;
3243 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3246 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3247 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3248 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3250 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3251 if (!enable_keep_aspect)
3253 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3255 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3256 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3258 enable_scale_width = !autoscale && (pic_par != 1);
3259 enable_scale_height = !autoscale && (pic_par != 1);
3260 enable_disp_width = (pic_par == 3) && !keep_aspect;
3261 enable_par = (pic_par == 3) && !keep_aspect;
3262 enable_disp_height = FALSE;
3264 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3265 gtk_widget_set_sensitive(widget, pic_par != 1);
3266 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3267 gtk_widget_set_sensitive(widget, pic_par != 1);
3268 widget = GHB_WIDGET(ud->builder, "scale_width");
3269 gtk_widget_set_sensitive(widget, enable_scale_width);
3270 widget = GHB_WIDGET(ud->builder, "scale_height");
3271 gtk_widget_set_sensitive(widget, enable_scale_height);
3272 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3273 gtk_widget_set_sensitive(widget, enable_disp_width);
3274 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3275 gtk_widget_set_sensitive(widget, enable_disp_height);
3276 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3277 gtk_widget_set_sensitive(widget, enable_par);
3278 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3279 gtk_widget_set_sensitive(widget, enable_par);
3280 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3281 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3282 widget = GHB_WIDGET(ud->builder, "autoscale");
3283 gtk_widget_set_sensitive(widget, pic_par != 1);
3287 ghb_set_scale(signal_user_data_t *ud, gint mode)
3292 gboolean keep_aspect;
3294 gboolean autocrop, autoscale, noscale;
3295 gint crop[4], width, height, par_width, par_height;
3296 gint crop_width, crop_height;
3297 gint aspect_n, aspect_d;
3298 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3299 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3304 gint max_height = 0;
3305 static gboolean busy = FALSE;
3307 g_debug("ghb_set_scale ()\n");
3308 picture_settings_deps(ud);
3309 if (h_scan == NULL) return;
3310 list = hb_get_titles( h_scan );
3311 if( !hb_list_count( list ) )
3313 /* No valid title, stop right there */
3318 titleindex = ghb_settings_combo_int(ud->settings, "title");
3319 title = hb_list_item( list, titleindex );
3320 if (title == NULL) return;
3322 if (job == NULL) return;
3327 if (!ud->dont_clear_presets && (keep_width || keep_height))
3329 ghb_settings_set_int(ud->settings, "PictureWidth", 0);
3330 ghb_settings_set_int(ud->settings, "PictureHeight", 0);
3333 // First configure widgets
3334 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3335 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3336 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3337 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3338 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3339 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3340 // alignment constraints rather than scaling to satisfy them.
3341 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3342 // Align dimensions to either 16 or 2 pixels
3343 // The scaler crashes if the dimensions are not divisible by 2
3344 // x264 also will not accept dims that are not multiple of 2
3348 keep_height = FALSE;
3350 // Step needs to be at least 2 because odd widths cause scaler crash
3352 widget = GHB_WIDGET (ud->builder, "scale_width");
3353 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3354 widget = GHB_WIDGET (ud->builder, "scale_height");
3355 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3358 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3359 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3360 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3361 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3362 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3363 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3364 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3365 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3369 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3370 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3371 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3372 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3373 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3374 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3375 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3376 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3378 ghb_title_info_t tinfo;
3379 ghb_get_title_info (&tinfo, titleindex);
3382 crop[0] = tinfo.crop[0];
3383 crop[1] = tinfo.crop[1];
3384 crop[2] = tinfo.crop[2];
3385 crop[3] = tinfo.crop[3];
3386 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3387 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3388 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3389 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3393 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3394 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3395 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3396 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3402 // Adjust the cropping to accomplish the desired width and height
3403 crop_width = tinfo.width - crop[2] - crop[3];
3404 crop_height = tinfo.height - crop[0] - crop[1];
3405 width = MOD_DOWN(crop_width, mod);
3406 height = MOD_DOWN(crop_height, mod);
3408 need1 = (crop_height - height) / 2;
3409 need2 = crop_height - height - need1;
3412 need1 = (crop_width - width) / 2;
3413 need2 = crop_width - width - need1;
3416 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3417 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3418 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3419 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3421 hb_reduce(&aspect_n, &aspect_d,
3422 title->width * title->pixel_aspect_width,
3423 title->height * title->pixel_aspect_height);
3424 crop_width = title->width - crop[2] - crop[3];
3425 crop_height = title->height - crop[0] - crop[1];
3429 height = crop_height;
3433 width = ghb_settings_get_int(ud->settings, "scale_width");
3434 height = ghb_settings_get_int(ud->settings, "scale_height");
3435 max_width = MOD_DOWN(
3436 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3437 max_height = MOD_DOWN(
3438 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3440 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3443 width = title->width - crop[2] - crop[3];
3445 height = title->height - crop[0] - crop[1];
3447 width = MOD_ROUND(width, mod);
3448 height = MOD_ROUND(height, mod);
3450 // Adjust dims according to max values
3452 height = MIN(height, max_height);
3454 width = MIN(width, max_width);
3458 job->anamorphic.mode = pic_par;
3459 // The scaler crashes if the dimensions are not divisible by 2
3460 // Align mod 2. And so does something in x264_encoder_headers()
3461 job->anamorphic.modulus = mod;
3462 job->anamorphic.par_width = title->pixel_aspect_width;
3463 job->anamorphic.par_height = title->pixel_aspect_height;
3464 job->anamorphic.dar_width = 0;
3465 job->anamorphic.dar_height = 0;
3467 if (keep_height && pic_par == 2)
3468 width = ((double)height * crop_width / crop_height) + mod / 2;
3470 job->height = height;
3471 job->maxWidth = max_width;
3472 job->maxHeight = max_height;
3473 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3474 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3475 if (job->anamorphic.mode == 3 && !keep_aspect)
3477 job->anamorphic.keep_display_aspect = 0;
3478 if (mode & GHB_PIC_KEEP_PAR)
3480 job->anamorphic.par_width =
3481 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3482 job->anamorphic.par_height =
3483 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3487 job->anamorphic.dar_width =
3488 ghb_settings_get_int(ud->settings,
3489 "PictureDisplayWidth");
3490 job->anamorphic.dar_height = height;
3495 job->anamorphic.keep_display_aspect = 1;
3497 hb_set_anamorphic_size( job, &width, &height,
3498 &par_width, &par_height );
3499 if (job->anamorphic.mode == 3 && !keep_aspect &&
3500 mode & GHB_PIC_KEEP_PAR)
3502 // hb_set_anamorphic_size reduces the par, which we
3503 // don't want in this case because the user is
3504 // explicitely specifying it.
3505 par_width = ghb_settings_get_int(ud->settings,
3507 par_height = ghb_settings_get_int(ud->settings,
3508 "PicturePARHeight");
3513 job->anamorphic.mode = pic_par;
3517 gint new_width, new_height;
3519 // Compute pixel aspect ration.
3520 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3521 // Must scale so that par becomes 1:1
3522 // Try to keep largest dimension
3523 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3524 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3526 if (max_width && new_width > max_width)
3528 height = new_height;
3530 else if (max_height && new_height > max_height)
3534 else if (keep_width)
3536 height = new_height;
3538 else if (keep_height)
3542 else if (width > new_width)
3544 height = new_height;
3550 g_debug("new w %d h %d\n", width, height);
3552 width = MOD_ROUND(width, mod);
3553 height = MOD_ROUND(height, mod);
3555 height = MIN(height, max_height);
3557 width = MIN(width, max_width);
3558 par_width = par_height = 1;
3560 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3561 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3563 gint disp_width, dar_width, dar_height;
3566 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3567 hb_reduce(&dar_width, &dar_height, disp_width, height);
3569 gint iaspect = dar_width * 9 / dar_height;
3570 if (dar_width > 2 * dar_height)
3572 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3574 else if (iaspect <= 16 && iaspect >= 15)
3576 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3578 else if (iaspect <= 12 && iaspect >= 11)
3580 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3584 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3586 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3588 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3589 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3590 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3591 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3596 set_preview_job_settings(hb_job_t *job, GValue *settings)
3598 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3599 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3600 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3601 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3603 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3604 job->anamorphic.modulus =
3605 ghb_settings_combo_int(settings, "PictureModulus");
3606 job->width = ghb_settings_get_int(settings, "scale_width");
3607 job->height = ghb_settings_get_int(settings, "scale_height");
3608 if (ghb_settings_get_boolean(settings, "show_crop"))
3610 gdouble xscale = (gdouble)job->width /
3611 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3612 gdouble yscale = (gdouble)job->height /
3613 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3615 job->width += xscale * (job->crop[2] + job->crop[3]);
3616 job->height += yscale * (job->crop[0] + job->crop[1]);
3621 job->anamorphic.modulus = 2;
3624 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3627 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3628 job->deinterlace = (decomb == 0) ? 0 : 1;
3632 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3633 job->deinterlace = (deint == 0) ? 0 : 1;
3636 gboolean keep_aspect;
3637 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3638 if (job->anamorphic.mode)
3640 job->anamorphic.par_width = job->title->pixel_aspect_width;
3641 job->anamorphic.par_height = job->title->pixel_aspect_height;
3642 job->anamorphic.dar_width = 0;
3643 job->anamorphic.dar_height = 0;
3645 if (job->anamorphic.mode == 3 && !keep_aspect)
3647 job->anamorphic.keep_display_aspect = 0;
3648 job->anamorphic.par_width =
3649 ghb_settings_get_int(settings, "PicturePARWidth");
3650 job->anamorphic.par_height =
3651 ghb_settings_get_int(settings, "PicturePARHeight");
3655 job->anamorphic.keep_display_aspect = 1;
3661 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3668 if (h_scan == NULL) return 1500;
3669 list = hb_get_titles( h_scan );
3670 title = hb_list_item( list, titleindex );
3671 if (title == NULL) return 1500;
3673 if (job == NULL) return 1500;
3674 size = ghb_settings_get_int(settings, "VideoTargetSize");
3675 return hb_calc_bitrate( job, size );
3679 ghb_validate_filter_string(const gchar *str, gint max_fields)
3685 if (str == NULL || *str == 0) return TRUE;
3688 val = g_strtod(str, &end);
3690 { // Found a numeric value
3692 // negative max_fields means infinate
3693 if (max_fields >= 0 && fields > max_fields) return FALSE;
3707 ghb_validate_filters(signal_user_data_t *ud)
3713 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3715 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3716 if (!decomb_deint && index == 1)
3718 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3719 if (!ghb_validate_filter_string(str, -1))
3721 message = g_strdup_printf(
3722 "Invalid Deinterlace Settings:\n\n%s\n",
3724 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3732 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3735 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3736 if (!ghb_validate_filter_string(str, -1))
3738 message = g_strdup_printf(
3739 "Invalid Detelecine Settings:\n\n%s\n",
3741 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3749 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3750 if (decomb_deint && index == 1)
3752 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3753 if (!ghb_validate_filter_string(str, -1))
3755 message = g_strdup_printf(
3756 "Invalid Decomb Settings:\n\n%s\n",
3758 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3766 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3769 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3770 if (!ghb_validate_filter_string(str, -1))
3772 message = g_strdup_printf(
3773 "Invalid Denoise Settings:\n\n%s\n",
3775 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3786 ghb_validate_video(signal_user_data_t *ud)
3791 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3792 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3793 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
3795 // mp4/theora combination is not supported.
3796 message = g_strdup_printf(
3797 "Theora is not supported in the MP4 container.\n\n"
3798 "You should choose a different video codec or container.\n"
3799 "If you continue, FFMPEG will be chosen for you.");
3800 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3806 vcodec = HB_VCODEC_FFMPEG;
3807 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
3813 ghb_validate_subtitles(signal_user_data_t *ud)
3819 if (h_scan == NULL) return FALSE;
3820 list = hb_get_titles( h_scan );
3821 if( !hb_list_count( list ) )
3823 /* No valid title, stop right there */
3824 g_message("No title found.\n");
3830 titleindex = ghb_settings_combo_int(ud->settings, "title");
3831 title = hb_list_item( list, titleindex );
3832 if (title == NULL) return FALSE;
3833 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3835 const GValue *slist, *settings;
3836 gint count, ii, source;
3837 gboolean burned, one_burned = FALSE;
3839 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
3840 count = ghb_array_len(slist);
3841 for (ii = 0; ii < count; ii++)
3843 settings = ghb_array_get_nth(slist, ii);
3844 source = ghb_settings_get_int(settings, "SubtitleSource");
3845 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
3846 if (burned && one_burned)
3848 // MP4 can only handle burned vobsubs. make sure there isn't
3849 // already something burned in the list
3850 message = g_strdup_printf(
3851 "Only one subtitle may be burned into the video.\n\n"
3852 "You should change your subtitle selections.\n"
3853 "If you continue, some subtitles will be lost.");
3854 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
3866 if (!burned && mux == HB_MUX_MP4 && source == VOBSUB)
3868 // MP4 can only handle burned vobsubs. make sure there isn't
3869 // already something burned in the list
3870 message = g_strdup_printf(
3871 "Your chosen container does not support soft bitmap subtitles.\n\n"
3872 "You should change your subtitle selections.\n"
3873 "If you continue, some subtitles will be lost.");
3874 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3875 "Cancel", "Continue"))
3883 if (source == SRTSUB)
3887 filename = ghb_settings_get_string(settings, "SrtFile");
3888 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
3890 message = g_strdup_printf(
3891 "Srt file does not exist or not a regular file.\n\n"
3892 "You should choose a valid file.\n"
3893 "If you continue, this subtitle will be ignored.");
3894 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
3895 "Cancel", "Continue"))
3909 ghb_select_audio_codec(signal_user_data_t *ud, gint track)
3913 hb_audio_config_t *audio;
3915 if (h_scan == NULL) return -1;
3916 list = hb_get_titles( h_scan );
3917 if( !hb_list_count( list ) )
3924 titleindex = ghb_settings_combo_int(ud->settings, "title");
3925 title = hb_list_item( list, titleindex );
3926 if (title == NULL) return -1;
3928 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3930 if (track < 0 || track >= hb_list_count(title->list_audio))
3933 audio = (hb_audio_config_t *) hb_list_audio_config_item(
3934 title->list_audio, track );
3935 if (mux == HB_MUX_MP4)
3937 if (audio->in.codec == HB_ACODEC_AC3)
3938 return audio->in.codec;
3940 return HB_ACODEC_FAAC;
3944 if (audio->in.codec == HB_ACODEC_AC3 || audio->in.codec == HB_ACODEC_DCA)
3945 return audio->in.codec;
3947 return HB_ACODEC_LAME;
3952 ghb_select_audio_codec_str(signal_user_data_t *ud, gint track)
3956 acodec = ghb_select_audio_codec(ud, track);
3957 for (ii = 0; ii < acodec_opts.count; ii++)
3959 if (acodec_opts.map[ii].ivalue == acodec)
3960 return acodec_opts.map[ii].option;
3966 ghb_validate_audio(signal_user_data_t *ud)
3973 if (h_scan == NULL) return FALSE;
3974 list = hb_get_titles( h_scan );
3975 if( !hb_list_count( list ) )
3977 /* No valid title, stop right there */
3978 g_message("No title found.\n");
3984 titleindex = ghb_settings_combo_int(ud->settings, "title");
3985 title = hb_list_item( list, titleindex );
3986 if (title == NULL) return FALSE;
3987 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3989 const GValue *audio_list;
3992 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
3993 count = ghb_array_len(audio_list);
3994 for (ii = 0; ii < count; ii++)
3997 hb_audio_config_t *taudio;
3999 asettings = ghb_array_get_nth(audio_list, ii);
4000 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4001 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4002 if (codec == HB_ACODEC_MASK)
4005 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4006 title->list_audio, track );
4007 if (!(taudio->in.codec & codec) &&
4008 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4010 // Not supported. AC3 is passthrough only, so input must be AC3
4011 message = g_strdup_printf(
4012 "The source does not support Pass-Thru.\n\n"
4013 "You should choose a different audio codec.\n"
4014 "If you continue, one will be chosen for you.");
4015 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4021 if (mux == HB_MUX_MKV)
4023 codec = HB_ACODEC_LAME;
4027 codec = HB_ACODEC_FAAC;
4029 value = ghb_lookup_acodec_value(codec);
4030 ghb_settings_take_value(asettings, "AudioEncoder", value);
4032 gchar *a_unsup = NULL;
4033 gchar *mux_s = NULL;
4034 if (mux == HB_MUX_MP4)
4037 // mp4/mp3|vorbis combination is not supported.
4038 if (codec == HB_ACODEC_LAME)
4041 codec = HB_ACODEC_FAAC;
4043 if (codec == HB_ACODEC_VORBIS)
4046 codec = HB_ACODEC_FAAC;
4048 if (codec == HB_ACODEC_DCA)
4051 codec = HB_ACODEC_FAAC;
4056 message = g_strdup_printf(
4057 "%s is not supported in the %s container.\n\n"
4058 "You should choose a different audio codec.\n"
4059 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4060 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4066 value = ghb_lookup_acodec_value(codec);
4067 ghb_settings_take_value(asettings, "AudioEncoder", value);
4069 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4070 gboolean allow_mono = TRUE;
4071 gboolean allow_stereo = TRUE;
4072 gboolean allow_dolby = TRUE;
4073 gboolean allow_dpl2 = TRUE;
4074 gboolean allow_6ch = TRUE;
4076 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4077 (codec & ~HB_ACODEC_LAME);
4078 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4080 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4082 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4083 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4084 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4085 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4087 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
4088 (codec & ~HB_ACODEC_LAME) &&
4089 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4090 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4092 gchar *mix_unsup = NULL;
4093 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4097 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4099 mix_unsup = "stereo";
4101 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4103 mix_unsup = "Dolby";
4105 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4107 mix_unsup = "Dolby Pro Logic II";
4109 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4111 mix_unsup = "6 Channel";
4115 message = g_strdup_printf(
4116 "The source audio does not support %s mixdown.\n\n"
4117 "You should choose a different mixdown.\n"
4118 "If you continue, one will be chosen for you.", mix_unsup);
4119 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4125 mix = ghb_get_best_mix(titleindex, track, codec, mix);
4126 value = get_amix_value(mix);
4127 ghb_settings_take_value(asettings, "AudioMixdown", value);
4134 ghb_validate_vquality(GValue *settings)
4140 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4141 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4143 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4144 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4148 case HB_VCODEC_X264:
4154 case HB_VCODEC_FFMPEG:
4160 case HB_VCODEC_THEORA:
4172 if (vquality < min || vquality > max)
4174 message = g_strdup_printf(
4175 "Interesting video quality choise: %d\n\n"
4176 "Typical values range from %d to %d.\n"
4177 "Are you sure you wish to use this setting?",
4178 (gint)vquality, min, max);
4179 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4180 "Cancel", "Continue"))
4192 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4197 static gchar *x264opts;
4199 gboolean tweaks = FALSE;
4200 gchar *detel_str = NULL;
4201 gchar *decomb_str = NULL;
4202 gchar *deint_str = NULL;
4203 gchar *deblock_str = NULL;
4204 gchar *denoise_str = NULL;
4205 gchar *dest_str = NULL;
4207 g_debug("add_job()\n");
4208 if (h == NULL) return;
4209 list = hb_get_titles( h );
4210 if( !hb_list_count( list ) )
4212 /* No valid title, stop right there */
4216 title = hb_list_item( list, titleindex );
4217 if (title == NULL) return;
4219 /* Set job settings */
4221 if (job == NULL) return;
4223 job->angle = ghb_settings_get_int(js, "angle");
4224 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4225 if (job->start_at_preview)
4227 job->seek_points = ghb_settings_get_int(js, "preview_count");
4228 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4231 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4232 job->mux = ghb_settings_combo_int(js, "FileFormat");
4233 if (job->mux == HB_MUX_MP4)
4235 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4236 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4240 job->largeFileSize = FALSE;
4241 job->mp4_optimize = FALSE;
4243 if (!job->start_at_preview)
4246 gint num_chapters = hb_list_count(title->list_chapter);
4247 gint duration = title->duration / 90000;
4248 job->chapter_start = 1;
4249 job->chapter_end = num_chapters;
4251 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4253 start = ghb_settings_get_int(js, "start_point");
4254 end = ghb_settings_get_int(js, "end_point");
4255 job->chapter_start = MIN( num_chapters, start );
4256 job->chapter_end = MAX( job->chapter_start, end );
4259 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4261 job->chapter_start = 1;
4262 job->chapter_end = num_chapters;
4263 start = ghb_settings_get_int(js, "start_point");
4264 end = ghb_settings_get_int(js, "end_point");
4265 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4266 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4269 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4271 job->chapter_start = 1;
4272 job->chapter_end = num_chapters;
4273 start = ghb_settings_get_int(js, "start_point");
4274 end = ghb_settings_get_int(js, "end_point");
4276 max_frames = (gint64)duration * title->rate / title->rate_base;
4277 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4278 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4279 job->frame_to_start;
4281 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4282 if (job->chapter_start == job->chapter_end)
4283 job->chapter_markers = 0;
4284 if ( job->chapter_markers )
4291 chapters = ghb_settings_get_value(js, "chapter_list");
4292 count = ghb_array_len(chapters);
4293 for(chap = start; chap <= end; chap++)
4295 hb_chapter_t * chapter_s;
4301 chapter = ghb_array_get_nth(chapters, chap-1);
4302 name = ghb_value_string(chapter);
4306 name = g_strdup_printf ("Chapter %2d", chap);
4308 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
4309 strncpy(chapter_s->title, name, 1023);
4310 chapter_s->title[1023] = '\0';
4315 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4316 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4317 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4318 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4321 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4322 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4323 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4325 job->deinterlace = (deint != 0) ? 1 : 0;
4327 job->deinterlace = 0;
4328 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4330 gboolean keep_aspect;
4331 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4332 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4333 job->anamorphic.modulus = ghb_settings_combo_int(js, "PictureModulus");
4334 if (job->anamorphic.mode)
4336 job->anamorphic.par_width = title->pixel_aspect_width;
4337 job->anamorphic.par_height = title->pixel_aspect_height;
4338 job->anamorphic.dar_width = 0;
4339 job->anamorphic.dar_height = 0;
4341 if (job->anamorphic.mode == 3 && !keep_aspect)
4343 job->anamorphic.keep_display_aspect = 0;
4344 job->anamorphic.par_width =
4345 ghb_settings_get_int(js, "PicturePARWidth");
4346 job->anamorphic.par_height =
4347 ghb_settings_get_int(js, "PicturePARHeight");
4351 job->anamorphic.keep_display_aspect = 1;
4355 /* Add selected filters */
4356 job->filters = hb_list_init();
4357 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4362 if (detel_opts.map[detel].svalue != NULL)
4363 detel_str = g_strdup(detel_opts.map[detel].svalue);
4366 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4367 hb_filter_detelecine.settings = detel_str;
4368 hb_list_add( job->filters, &hb_filter_detelecine );
4370 if ( decomb_deint && decomb )
4374 if (decomb_opts.map[decomb].svalue != NULL)
4375 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4378 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4379 hb_filter_decomb.settings = decomb_str;
4380 hb_list_add( job->filters, &hb_filter_decomb );
4382 if( job->deinterlace )
4386 if (deint_opts.map[deint].svalue != NULL)
4387 deint_str = g_strdup(deint_opts.map[deint].svalue);
4390 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4391 hb_filter_deinterlace.settings = deint_str;
4392 hb_list_add( job->filters, &hb_filter_deinterlace );
4394 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4397 deblock_str = g_strdup_printf("%d", deblock);
4398 hb_filter_deblock.settings = deblock_str;
4399 hb_list_add( job->filters, &hb_filter_deblock );
4401 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4406 if (denoise_opts.map[denoise].svalue != NULL)
4407 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4410 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4411 hb_filter_denoise.settings = denoise_str;
4412 hb_list_add( job->filters, &hb_filter_denoise );
4414 job->width = ghb_settings_get_int(js, "scale_width");
4415 job->height = ghb_settings_get_int(js, "scale_height");
4417 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4418 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4420 // mp4/theora combination is not supported.
4421 job->vcodec = HB_VCODEC_FFMPEG;
4423 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4425 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4427 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4430 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4431 job->vquality = vquality;
4434 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4436 job->vquality = -1.0;
4437 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4440 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4443 job->vrate = title->rate;
4444 job->vrate_base = title->rate_base;
4449 job->vrate = 27000000;
4450 job->vrate_base = vrate;
4454 const GValue *audio_list;
4458 audio_list = ghb_settings_get_value(js, "audio_list");
4459 count = ghb_array_len(audio_list);
4460 for (ii = 0; ii < count; ii++)
4463 hb_audio_config_t audio;
4464 hb_audio_config_t *taudio;
4466 hb_audio_config_init(&audio);
4467 asettings = ghb_array_get_nth(audio_list, ii);
4468 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4469 audio.out.track = tcount;
4470 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4471 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4472 title->list_audio, audio.in.track );
4473 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4475 if (!(taudio->in.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4478 // AC3/DTS is passthrough only, so input must be AC3/DTS
4479 if (job->mux == HB_MUX_MKV)
4481 audio.out.codec = HB_ACODEC_LAME;
4485 audio.out.codec = HB_ACODEC_FAAC;
4490 audio.out.codec &= taudio->in.codec;
4493 if ((job->mux == HB_MUX_MP4) &&
4494 ((audio.out.codec & HB_ACODEC_LAME) ||
4495 (audio.out.codec & HB_ACODEC_DCA) ||
4496 (audio.out.codec & HB_ACODEC_VORBIS)))
4498 // mp4/mp3|dts|vorbis combination is not supported.
4499 audio.out.codec = HB_ACODEC_FAAC;
4501 audio.out.dynamic_range_compression =
4502 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4503 if (audio.out.dynamic_range_compression < 1.0)
4504 audio.out.dynamic_range_compression = 0.0;
4506 // It would be better if this were done in libhb for us, but its not yet.
4507 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4509 audio.out.mixdown = 0;
4515 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4516 if (audio.out.mixdown == HB_AMIXDOWN_MONO)
4518 else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
4523 // Make sure the mixdown is valid and pick a new one if not.
4524 audio.out.mixdown = ghb_get_best_mix(titleindex,
4525 audio.in.track, audio.out.codec, audio.out.mixdown);
4527 ghb_settings_combo_int(asettings, "AudioBitrate");
4528 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4529 if (srate == 0) // 0 is same as source
4530 audio.out.samplerate = taudio->in.samplerate;
4532 audio.out.samplerate = srate;
4534 audio.out.bitrate = ghb_get_best_audio_bitrate(
4535 audio.out.codec, audio.out.bitrate, channels);
4538 // Add it to the jobs audio list
4539 hb_audio_add( job, &audio );
4542 // I was tempted to move this up with the reset of the video quality
4543 // settings, but I suspect the settings above need to be made
4544 // first in order for hb_calc_bitrate to be accurate.
4545 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4549 size = ghb_settings_get_int(js, "VideoTargetSize");
4550 job->vbitrate = hb_calc_bitrate( job, size );
4551 job->vquality = -1.0;
4554 dest_str = ghb_settings_get_string(js, "destination");
4555 job->file = dest_str;
4557 const GValue *subtitle_list;
4559 gboolean force, burned, def, one_burned = FALSE;
4561 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4562 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4563 count = ghb_array_len(subtitle_list);
4564 for (ii = 0; ii < count; ii++)
4569 ssettings = ghb_array_get_nth(subtitle_list, ii);
4571 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4572 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4573 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4574 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4576 if (source == SRTSUB)
4578 hb_subtitle_config_t sub_config;
4579 gchar *filename, *lang, *code;
4581 filename = ghb_settings_get_string(ssettings, "SrtFile");
4582 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4586 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4587 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4588 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4589 strncpy(sub_config.src_filename, filename, 128);
4590 strncpy(sub_config.src_codeset, code, 40);
4591 sub_config.force = 0;
4592 sub_config.dest = PASSTHRUSUB;
4593 sub_config.default_track = def;
4595 hb_srt_add( job, &sub_config, lang);
4603 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4606 if (!burned && job->mux == HB_MUX_MKV)
4608 job->select_subtitle_config.dest = PASSTHRUSUB;
4610 else if (!burned && job->mux == HB_MUX_MP4)
4612 // Skip any non-burned vobsubs when output is mp4
4617 // Only allow one subtitle to be burned into the video
4620 job->select_subtitle_config.dest = RENDERSUB;
4623 job->select_subtitle_config.force = force;
4624 job->select_subtitle_config.default_track = def;
4625 job->indepth_scan = 1;
4626 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4628 else if (subtitle >= 0)
4630 hb_subtitle_t * subt;
4631 hb_subtitle_config_t sub_config;
4633 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4634 sub_config = subt->config;
4637 if (!burned && job->mux == HB_MUX_MKV &&
4638 subt->format == PICTURESUB)
4640 sub_config.dest = PASSTHRUSUB;
4642 else if (!burned && job->mux == HB_MUX_MP4 &&
4643 subt->format == PICTURESUB)
4645 // Skip any non-burned vobsubs when output is mp4
4648 else if ( burned && subt->format == PICTURESUB )
4650 // Only allow one subtitle to be burned into the video
4655 sub_config.force = force;
4656 sub_config.default_track = def;
4657 hb_subtitle_add( job, &sub_config, subtitle );
4662 // TODO: libhb holds onto a reference to the x264opts and is not
4663 // finished with it until encoding the job is done. But I can't
4664 // find a way to get at the job before it is removed in order to
4665 // free up the memory I am allocating here.
4666 // The short story is THIS LEAKS.
4667 x264opts = ghb_build_x264opts_string(js);
4669 if( *x264opts == '\0' )
4675 if (job->indepth_scan == 1)
4677 // Subtitle scan. Look for subtitle matching audio language
4680 * When subtitle scan is enabled do a fast pre-scan job
4681 * which will determine which subtitles to enable, if any.
4684 job->indepth_scan = 1;
4685 job->x264opts = NULL;
4688 * Add the pre-scan job
4690 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4694 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4695 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4698 * If subtitle_scan is enabled then only turn it on
4699 * for the second pass and then off again for the
4703 job->indepth_scan = 0;
4706 * If turbo options have been selected then append them
4707 * to the x264opts now (size includes one ':' and the '\0')
4709 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4711 gchar *tmp_x264opts;
4715 badapt = ghb_lookup_badapt(x264opts);
4718 extra_opts = g_strdup_printf("%s", turbo_opts);
4722 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4727 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4732 * No x264opts to modify, but apply the turbo options
4733 * anyway as they may be modifying defaults
4735 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4739 job->x264opts = tmp_x264opts;
4743 job->x264opts = x264opts;
4745 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4747 //if (job->x264opts != NULL)
4748 // g_free(job->x264opts);
4752 * On the second pass we turn off subtitle scan so that we
4753 * can actually encode using any subtitles that were auto
4754 * selected in the first pass (using the whacky select-subtitle
4755 * attribute of the job).
4757 job->indepth_scan = 0;
4758 job->x264opts = x264opts;
4759 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4761 //if (job->x264opts != NULL)
4762 // g_free(job->x264opts);
4766 job->x264opts = x264opts;
4767 job->indepth_scan = 0;
4769 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4771 //if (job->x264opts != NULL)
4772 // g_free(job->x264opts);
4775 // clean up audio list
4776 gint num_audio_tracks = hb_list_count(job->list_audio);
4777 for(ii = 0; ii < num_audio_tracks; ii++)
4779 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4780 hb_list_rem(job->list_audio, audio);
4784 // clean up subtitle list
4785 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4786 for(ii = 0; ii < num_subtitle_tracks; ii++)
4788 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4789 hb_list_rem(job->list_subtitle, subtitle);
4793 if (detel_str) g_free(detel_str);
4794 if (decomb_str) g_free(decomb_str);
4795 if (deint_str) g_free(deint_str);
4796 if (deblock_str) g_free(deblock_str);
4797 if (denoise_str) g_free(denoise_str);
4798 if (dest_str) g_free(dest_str);
4802 ghb_add_job(GValue *js, gint unique_id)
4804 // Since I'm doing a scan of the single title I want just prior
4805 // to adding the job, there is only the one title to choose from.
4806 add_job(h_queue, js, unique_id, 0);
4810 ghb_add_live_job(GValue *js, gint unique_id)
4812 // Since I'm doing a scan of the single title I want just prior
4813 // to adding the job, there is only the one title to choose from.
4814 gint titleindex = ghb_settings_combo_int(js, "title");
4815 add_job(h_scan, js, unique_id, titleindex);
4819 ghb_remove_job(gint unique_id)
4824 // Multiples passes all get the same id
4826 // Go backwards through list, so reordering doesn't screw me.
4827 ii = hb_count(h_queue) - 1;
4828 while ((job = hb_job(h_queue, ii--)) != NULL)
4830 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4831 hb_rem(h_queue, job);
4838 hb_start( h_queue );
4848 ghb_start_live_encode()
4854 ghb_stop_live_encode()
4863 hb_get_state2( h_queue, &s );
4865 if( s.state == HB_STATE_PAUSED )
4867 hb_status.queue.state &= ~GHB_STATE_PAUSED;
4868 hb_resume( h_queue );
4872 hb_status.queue.state |= GHB_STATE_PAUSED;
4873 hb_pause( h_queue );
4888 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4891 gint channels = gdk_pixbuf_get_n_channels (pb);
4892 gint stride = gdk_pixbuf_get_rowstride (pb);
4894 for (jj = 0; jj < width; jj++)
4896 dst = pixels + y * stride + (x+jj) * channels;
4897 for (ii = 0; ii < len; ii++)
4918 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
4921 gint channels = gdk_pixbuf_get_n_channels (pb);
4922 gint stride = gdk_pixbuf_get_rowstride (pb);
4924 for (jj = 0; jj < width; jj++)
4926 dst = pixels + (y+jj) * stride + x * channels;
4927 for (ii = 0; ii < len; ii++)
4948 gint line_width = 8;
4955 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
4960 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
4962 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
4968 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
4970 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
4976 ghb_get_preview_image(
4979 signal_user_data_t *ud,
4987 settings = ud->settings;
4988 list = hb_get_titles( h_scan );
4989 if( !hb_list_count( list ) )
4991 /* No valid title, stop right there */
4994 title = hb_list_item( list, titleindex );
4995 if (title == NULL) return NULL;
4996 if (title->job == NULL) return NULL;
4997 set_preview_job_settings(title->job, settings);
4999 // hb_get_preview doesn't compensate for anamorphic, so lets
5000 // calculate scale factors
5001 gint width, height, par_width = 1, par_height = 1;
5002 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5005 hb_set_anamorphic_size( title->job, &width, &height,
5006 &par_width, &par_height );
5009 // Make sure we have a big enough buffer to receive the image from libhb
5010 gint dstWidth = title->job->width;
5011 gint dstHeight= title->job->height;
5013 static guint8 *buffer = NULL;
5014 static gint bufferSize = 0;
5017 newSize = dstWidth * dstHeight * 4;
5018 if( bufferSize < newSize )
5020 bufferSize = newSize;
5021 buffer = (guint8*) g_realloc( buffer, bufferSize );
5023 hb_get_preview( h_scan, title, index, buffer );
5025 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5026 // libhb's format something suitable.
5028 // The image data returned by hb_get_preview is 4 bytes per pixel,
5029 // BGRA format. Alpha is ignored.
5031 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5032 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5034 guint32 *src = (guint32*)buffer;
5035 guint8 *dst = pixels;
5038 gint channels = gdk_pixbuf_get_n_channels (preview);
5039 gint stride = gdk_pixbuf_get_rowstride (preview);
5042 for (ii = 0; ii < dstHeight; ii++)
5045 for (jj = 0; jj < dstWidth; jj++)
5047 tmp[0] = src[0] >> 16;
5048 tmp[1] = src[0] >> 8;
5049 tmp[2] = src[0] >> 0;
5055 gint w = ghb_settings_get_int(settings, "scale_width");
5056 gint h = ghb_settings_get_int(settings, "scale_height");
5057 ghb_par_scale(ud, &w, &h, par_width, par_height);
5059 gint c0, c1, c2, c3;
5060 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5061 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5062 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5063 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5065 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5066 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5068 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5071 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5075 gint orig_w, orig_h;
5078 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5082 ss = gdk_screen_get_default();
5083 s_w = gdk_screen_get_width(ss);
5084 s_h = gdk_screen_get_height(ss);
5088 if (dstWidth > s_w * factor / 100)
5090 dstWidth = s_w * factor / 100;
5091 dstHeight = dstHeight * dstWidth / orig_w;
5093 if (dstHeight > s_h * factor / 100)
5095 dstHeight = s_h * factor / 100;
5096 dstWidth = dstWidth * dstHeight / orig_h;
5098 xscale *= (gdouble)dstWidth / orig_w;
5099 yscale *= (gdouble)dstHeight / orig_h;
5100 w *= (gdouble)dstWidth / orig_w;
5101 h *= (gdouble)dstHeight / orig_h;
5103 GdkPixbuf *scaled_preview;
5104 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5105 if (ghb_settings_get_boolean(settings, "show_crop"))
5112 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5114 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5116 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5118 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5120 g_object_unref (preview);
5121 return scaled_preview;
5125 sanitize_volname(gchar *name)
5150 ghb_dvd_volname(const gchar *device)
5153 name = hb_dvd_name((gchar*)device);
5154 if (name != NULL && name[0] != 0)
5156 name = g_strdup(name);
5157 sanitize_volname(name);