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 (ffmpeg)", "ac3", HB_ACODEC_AC3, "ac3"},
256 {"AC3 (pass-thru)", "ac3pass", HB_ACODEC_AC3_PASS, "ac3pass"},
257 {"DTS (pass-thru)", "dtspass", HB_ACODEC_DCA_PASS, "dtspass"},
258 {"Choose For Me", "auto", HB_ACODEC_ANY, "auto"},
260 combo_opts_t acodec_opts =
262 sizeof(d_acodec_opts)/sizeof(options_map_t),
266 static options_map_t d_direct_opts[] =
268 {"None", "none", 0, "none"},
269 {"Spatial", "spatial", 1, "spatial"},
270 {"Temporal", "temporal", 2, "temporal"},
271 {"Automatic", "auto", 3, "auto"},
273 combo_opts_t direct_opts =
275 sizeof(d_direct_opts)/sizeof(options_map_t),
279 static options_map_t d_badapt_opts[] =
281 {"Off", "0", 0, "0"},
282 {"Fast", "1", 1, "1"},
283 {"Optimal", "2", 2, "2"},
285 combo_opts_t badapt_opts =
287 sizeof(d_badapt_opts)/sizeof(options_map_t),
291 static options_map_t d_bpyramid_opts[] =
293 {"Off", "none", 0, "none"},
294 {"Strict", "strict", 1, "strict"},
295 {"Normal", "normal", 2, "normal"},
297 combo_opts_t bpyramid_opts =
299 sizeof(d_bpyramid_opts)/sizeof(options_map_t),
303 static options_map_t d_weightp_opts[] =
305 {"Off", "0", 0, "0"},
306 {"Blind", "1", 1, "1"},
307 {"Smart", "2", 2, "2"},
309 combo_opts_t weightp_opts =
311 sizeof(d_weightp_opts)/sizeof(options_map_t),
315 static options_map_t d_me_opts[] =
317 {"Diamond", "dia", 0, "dia"},
318 {"Hexagon", "hex", 1, "hex"},
319 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
320 {"Exhaustive", "esa", 3, "esa"},
321 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
323 combo_opts_t me_opts =
325 sizeof(d_me_opts)/sizeof(options_map_t),
329 static options_map_t d_subme_opts[] =
331 {"0: SAD, no subpel", "0", 0, "0"},
332 {"1: SAD, qpel", "1", 1, "1"},
333 {"2: SATD, qpel", "2", 2, "2"},
334 {"3: SATD: multi-qpel", "3", 3, "3"},
335 {"4: SATD, qpel on all", "4", 4, "4"},
336 {"5: SATD, multi-qpel on all", "5", 5, "5"},
337 {"6: RD in I/P-frames", "6", 6, "6"},
338 {"7: RD in all frames", "7", 7, "7"},
339 {"8: RD refine in I/P-frames", "8", 8, "8"},
340 {"9: RD refine in all frames", "9", 9, "9"},
341 {"10: QPRD in all frames", "10", 10, "10"},
343 combo_opts_t subme_opts =
345 sizeof(d_subme_opts)/sizeof(options_map_t),
349 static options_map_t d_analyse_opts[] =
351 {"Most", "p8x8,b8x8,i8x8,i4x4", 0, "p8x8,b8x8,i8x8,i4x4"},
352 {"None", "none", 1, "none"},
353 {"Some", "i4x4,i8x8", 2, "i4x4,i8x8"},
354 {"All", "all", 3, "all"},
355 {"Custom", "custom", 4, "all"},
357 combo_opts_t analyse_opts =
359 sizeof(d_analyse_opts)/sizeof(options_map_t),
363 static options_map_t d_trellis_opts[] =
365 {"Off", "0", 0, "0"},
366 {"Encode only", "1", 1, "1"},
367 {"Always", "2", 2, "2"},
369 combo_opts_t trellis_opts =
371 sizeof(d_trellis_opts)/sizeof(options_map_t),
375 combo_opts_t subtitle_opts =
381 combo_opts_t title_opts =
387 combo_opts_t audio_track_opts =
399 combo_name_map_t combo_name_map[] =
401 {"PtoPType", &point_to_point_opts},
402 {"WhenComplete", &when_complete_opts},
403 {"PicturePAR", &par_opts},
404 {"PictureModulus", &alignment_opts},
405 {"LoggingLevel", &logging_opts},
406 {"LogLongevity", &log_longevity_opts},
407 {"check_updates", &appcast_update_opts},
408 {"VideoQualityGranularity", &vqual_granularity_opts},
409 {"FileFormat", &container_opts},
410 {"PictureDeinterlace", &deint_opts},
411 {"PictureDecomb", &decomb_opts},
412 {"PictureDetelecine", &detel_opts},
413 {"PictureDenoise", &denoise_opts},
414 {"VideoEncoder", &vcodec_opts},
415 {"AudioEncoder", &acodec_opts},
416 {"x264_direct", &direct_opts},
417 {"x264_b_adapt", &badapt_opts},
418 {"x264_bpyramid", &bpyramid_opts},
419 {"x264_weighted_pframes", &weightp_opts},
420 {"x264_me", &me_opts},
421 {"x264_subme", &subme_opts},
422 {"x264_analyse", &analyse_opts},
423 {"x264_trellis", &trellis_opts},
424 {"SubtitleTrack", &subtitle_opts},
425 {"title", &title_opts},
426 {"AudioTrack", &audio_track_opts},
430 const gchar *srt_codeset_table[] =
469 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
472 typedef struct iso639_lang_t
474 char * eng_name; /* Description in English */
475 char * native_name; /* Description in native language */
476 char * iso639_1; /* ISO-639-1 (2 characters) code */
477 char * iso639_2; /* ISO-639-2/t (3 character) code */
478 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
482 const iso639_lang_t ghb_language_table[] =
484 { "Any", "", "zz", "und" },
485 { "Afar", "", "aa", "aar" },
486 { "Abkhazian", "", "ab", "abk" },
487 { "Afrikaans", "", "af", "afr" },
488 { "Akan", "", "ak", "aka" },
489 { "Albanian", "", "sq", "sqi", "alb" },
490 { "Amharic", "", "am", "amh" },
491 { "Arabic", "", "ar", "ara" },
492 { "Aragonese", "", "an", "arg" },
493 { "Armenian", "", "hy", "hye", "arm" },
494 { "Assamese", "", "as", "asm" },
495 { "Avaric", "", "av", "ava" },
496 { "Avestan", "", "ae", "ave" },
497 { "Aymara", "", "ay", "aym" },
498 { "Azerbaijani", "", "az", "aze" },
499 { "Bashkir", "", "ba", "bak" },
500 { "Bambara", "", "bm", "bam" },
501 { "Basque", "", "eu", "eus", "baq" },
502 { "Belarusian", "", "be", "bel" },
503 { "Bengali", "", "bn", "ben" },
504 { "Bihari", "", "bh", "bih" },
505 { "Bislama", "", "bi", "bis" },
506 { "Bosnian", "", "bs", "bos" },
507 { "Breton", "", "br", "bre" },
508 { "Bulgarian", "", "bg", "bul" },
509 { "Burmese", "", "my", "mya", "bur" },
510 { "Catalan", "", "ca", "cat" },
511 { "Chamorro", "", "ch", "cha" },
512 { "Chechen", "", "ce", "che" },
513 { "Chinese", "", "zh", "zho", "chi" },
514 { "Church Slavic", "", "cu", "chu" },
515 { "Chuvash", "", "cv", "chv" },
516 { "Cornish", "", "kw", "cor" },
517 { "Corsican", "", "co", "cos" },
518 { "Cree", "", "cr", "cre" },
519 { "Czech", "", "cs", "ces", "cze" },
520 { "Danish", "Dansk", "da", "dan" },
521 { "German", "Deutsch", "de", "deu", "ger" },
522 { "Divehi", "", "dv", "div" },
523 { "Dzongkha", "", "dz", "dzo" },
524 { "English", "English", "en", "eng" },
525 { "Spanish", "Espanol", "es", "spa" },
526 { "Esperanto", "", "eo", "epo" },
527 { "Estonian", "", "et", "est" },
528 { "Ewe", "", "ee", "ewe" },
529 { "Faroese", "", "fo", "fao" },
530 { "Fijian", "", "fj", "fij" },
531 { "French", "Francais", "fr", "fra", "fre" },
532 { "Western Frisian", "", "fy", "fry" },
533 { "Fulah", "", "ff", "ful" },
534 { "Georgian", "", "ka", "kat", "geo" },
535 { "Gaelic (Scots)", "", "gd", "gla" },
536 { "Irish", "", "ga", "gle" },
537 { "Galician", "", "gl", "glg" },
538 { "Manx", "", "gv", "glv" },
539 { "Greek, Modern", "", "el", "ell", "gre" },
540 { "Guarani", "", "gn", "grn" },
541 { "Gujarati", "", "gu", "guj" },
542 { "Haitian", "", "ht", "hat" },
543 { "Hausa", "", "ha", "hau" },
544 { "Hebrew", "", "he", "heb" },
545 { "Herero", "", "hz", "her" },
546 { "Hindi", "", "hi", "hin" },
547 { "Hiri Motu", "", "ho", "hmo" },
548 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
549 { "Igbo", "", "ig", "ibo" },
550 { "Ido", "", "io", "ido" },
551 { "Icelandic", "Islenska", "is", "isl", "ice" },
552 { "Sichuan Yi", "", "ii", "iii" },
553 { "Inuktitut", "", "iu", "iku" },
554 { "Interlingue", "", "ie", "ile" },
555 { "Interlingua", "", "ia", "ina" },
556 { "Indonesian", "", "id", "ind" },
557 { "Inupiaq", "", "ik", "ipk" },
558 { "Italian", "Italiano", "it", "ita" },
559 { "Javanese", "", "jv", "jav" },
560 { "Japanese", "", "ja", "jpn" },
561 { "Kalaallisut", "", "kl", "kal" },
562 { "Kannada", "", "kn", "kan" },
563 { "Kashmiri", "", "ks", "kas" },
564 { "Kanuri", "", "kr", "kau" },
565 { "Kazakh", "", "kk", "kaz" },
566 { "Central Khmer", "", "km", "khm" },
567 { "Kikuyu", "", "ki", "kik" },
568 { "Kinyarwanda", "", "rw", "kin" },
569 { "Kirghiz", "", "ky", "kir" },
570 { "Komi", "", "kv", "kom" },
571 { "Kongo", "", "kg", "kon" },
572 { "Korean", "", "ko", "kor" },
573 { "Kuanyama", "", "kj", "kua" },
574 { "Kurdish", "", "ku", "kur" },
575 { "Lao", "", "lo", "lao" },
576 { "Latin", "", "la", "lat" },
577 { "Latvian", "", "lv", "lav" },
578 { "Limburgan", "", "li", "lim" },
579 { "Lingala", "", "ln", "lin" },
580 { "Lithuanian", "", "lt", "lit" },
581 { "Luxembourgish", "", "lb", "ltz" },
582 { "Luba-Katanga", "", "lu", "lub" },
583 { "Ganda", "", "lg", "lug" },
584 { "Macedonian", "", "mk", "mkd", "mac" },
585 { "Hungarian", "Magyar", "hu", "hun" },
586 { "Marshallese", "", "mh", "mah" },
587 { "Malayalam", "", "ml", "mal" },
588 { "Maori", "", "mi", "mri", "mao" },
589 { "Marathi", "", "mr", "mar" },
590 { "Malay", "", "ms", "msa", "msa" },
591 { "Malagasy", "", "mg", "mlg" },
592 { "Maltese", "", "mt", "mlt" },
593 { "Moldavian", "", "mo", "mol" },
594 { "Mongolian", "", "mn", "mon" },
595 { "Nauru", "", "na", "nau" },
596 { "Navajo", "", "nv", "nav" },
597 { "Dutch", "Nederlands", "nl", "nld", "dut" },
598 { "Ndebele, South", "", "nr", "nbl" },
599 { "Ndebele, North", "", "nd", "nde" },
600 { "Ndonga", "", "ng", "ndo" },
601 { "Nepali", "", "ne", "nep" },
602 { "Norwegian", "Norsk", "no", "nor" },
603 { "Norwegian Nynorsk", "", "nn", "nno" },
604 { "Norwegian Bokmål", "", "nb", "nob" },
605 { "Chichewa; Nyanja", "", "ny", "nya" },
606 { "Occitan", "", "oc", "oci" },
607 { "Ojibwa", "", "oj", "oji" },
608 { "Oriya", "", "or", "ori" },
609 { "Oromo", "", "om", "orm" },
610 { "Ossetian", "", "os", "oss" },
611 { "Panjabi", "", "pa", "pan" },
612 { "Persian", "", "fa", "fas", "per" },
613 { "Pali", "", "pi", "pli" },
614 { "Polish", "", "pl", "pol" },
615 { "Portuguese", "Portugues", "pt", "por" },
616 { "Pushto", "", "ps", "pus" },
617 { "Quechua", "", "qu", "que" },
618 { "Romansh", "", "rm", "roh" },
619 { "Romanian", "", "ro", "ron", "rum" },
620 { "Rundi", "", "rn", "run" },
621 { "Russian", "", "ru", "rus" },
622 { "Sango", "", "sg", "sag" },
623 { "Sanskrit", "", "sa", "san" },
624 { "Serbian", "", "sr", "srp", "scc" },
625 { "Sinhala", "", "si", "sin" },
626 { "Slovak", "", "sk", "slk", "slo" },
627 { "Slovenian", "", "sl", "slv" },
628 { "Northern Sami", "", "se", "sme" },
629 { "Samoan", "", "sm", "smo" },
630 { "Shona", "", "sn", "sna" },
631 { "Sindhi", "", "sd", "snd" },
632 { "Somali", "", "so", "som" },
633 { "Sotho, Southern", "", "st", "sot" },
634 { "Sardinian", "", "sc", "srd" },
635 { "Swati", "", "ss", "ssw" },
636 { "Sundanese", "", "su", "sun" },
637 { "Finnish", "Suomi", "fi", "fin" },
638 { "Swahili", "", "sw", "swa" },
639 { "Swedish", "Svenska", "sv", "swe" },
640 { "Tahitian", "", "ty", "tah" },
641 { "Tamil", "", "ta", "tam" },
642 { "Tatar", "", "tt", "tat" },
643 { "Telugu", "", "te", "tel" },
644 { "Tajik", "", "tg", "tgk" },
645 { "Tagalog", "", "tl", "tgl" },
646 { "Thai", "", "th", "tha" },
647 { "Tibetan", "", "bo", "bod", "tib" },
648 { "Tigrinya", "", "ti", "tir" },
649 { "Tonga", "", "to", "ton" },
650 { "Tswana", "", "tn", "tsn" },
651 { "Tsonga", "", "ts", "tso" },
652 { "Turkmen", "", "tk", "tuk" },
653 { "Turkish", "", "tr", "tur" },
654 { "Twi", "", "tw", "twi" },
655 { "Uighur", "", "ug", "uig" },
656 { "Ukrainian", "", "uk", "ukr" },
657 { "Urdu", "", "ur", "urd" },
658 { "Uzbek", "", "uz", "uzb" },
659 { "Venda", "", "ve", "ven" },
660 { "Vietnamese", "", "vi", "vie" },
661 { "Volapük", "", "vo", "vol" },
662 { "Welsh", "", "cy", "cym", "wel" },
663 { "Walloon", "", "wa", "wln" },
664 { "Wolof", "", "wo", "wol" },
665 { "Xhosa", "", "xh", "xho" },
666 { "Yiddish", "", "yi", "yid" },
667 { "Yoruba", "", "yo", "yor" },
668 { "Zhuang", "", "za", "zha" },
669 { "Zulu", "", "zu", "zul" },
670 {NULL, NULL, NULL, NULL}
672 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
674 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
677 del_tree(const gchar *name, gboolean del_top)
681 if (g_file_test(name, G_FILE_TEST_IS_DIR))
683 GDir *gdir = g_dir_open(name, 0, NULL);
684 file = g_dir_read_name(gdir);
688 path = g_strdup_printf("%s/%s", name, file);
689 del_tree(path, TRUE);
691 file = g_dir_read_name(gdir);
706 return hb_get_version(NULL);
711 signal_user_data_t *ud,
719 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
728 *step = ghb_settings_combo_double(ud->settings,
729 "VideoQualityGranularity");
730 if (*step == 0.2 || *step == 0.5)
732 else if (*step == 0.25)
737 case HB_VCODEC_FFMPEG:
745 case HB_VCODEC_THEORA:
764 find_combo_entry(combo_opts_t *opts, const GValue *gval)
768 if (G_VALUE_TYPE(gval) == G_TYPE_STRING)
771 str = ghb_value_string(gval);
772 for (ii = 0; ii < opts->count; ii++)
774 if (strcmp(opts->map[ii].shortOpt, str) == 0)
782 else if (G_VALUE_TYPE(gval) == G_TYPE_DOUBLE)
785 val = ghb_value_double(gval);
786 for (ii = 0; ii < opts->count; ii++)
788 if (opts->map[ii].ivalue == val)
795 else if (G_VALUE_TYPE(gval) == G_TYPE_INT ||
796 G_VALUE_TYPE(gval) == G_TYPE_BOOLEAN ||
797 G_VALUE_TYPE(gval) == G_TYPE_INT64)
800 val = ghb_value_int64(gval);
801 for (ii = 0; ii < opts->count; ii++)
803 if ((gint64)opts->map[ii].ivalue == val)
814 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
817 const gchar *result = "";
819 ii = find_combo_entry(opts, gval);
820 if (ii < opts->count)
822 result = opts->map[ii].svalue;
828 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
833 ii = find_combo_entry(opts, gval);
834 if (ii < opts->count)
836 result = opts->map[ii].ivalue;
842 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
847 ii = find_combo_entry(opts, gval);
848 if (ii < opts->count)
850 result = opts->map[ii].ivalue;
856 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
859 const gchar *result = "";
861 ii = find_combo_entry(opts, gval);
862 if (ii < opts->count)
864 result = opts->map[ii].option;
870 lookup_mix_int(const GValue *mix)
876 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
878 gchar * str = ghb_value_string(mix);
879 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
881 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
883 result = hb_audio_mixdowns[ii].amixdown;
889 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
890 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
891 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
893 gint val = ghb_value_int(mix);
894 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
896 if (hb_audio_mixdowns[ii].amixdown == val)
898 result = hb_audio_mixdowns[ii].amixdown;
907 lookup_mix_option(const GValue *mix)
910 gchar *result = "None";
913 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
915 gchar *str = ghb_value_string(mix);
916 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
918 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
920 result = hb_audio_mixdowns[ii].human_readable_name;
926 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
927 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
928 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
930 gint val = ghb_value_int(mix);
931 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
933 if (hb_audio_mixdowns[ii].amixdown == val)
935 result = hb_audio_mixdowns[ii].human_readable_name;
944 lookup_mix_string(const GValue *mix)
947 gchar *result = "None";
950 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
952 gchar *str = ghb_value_string(mix);
953 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
955 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
957 result = hb_audio_mixdowns[ii].short_name;
963 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
964 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
965 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
967 gint val = ghb_value_int(mix);
968 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
970 if (hb_audio_mixdowns[ii].amixdown == val)
972 result = hb_audio_mixdowns[ii].short_name;
981 lookup_video_rate_int(const GValue *vrate)
987 str = ghb_value_string(vrate);
988 for (ii = 0; ii < hb_video_rates_count; ii++)
990 if (strcmp(hb_video_rates[ii].string, str) == 0)
992 result = hb_video_rates[ii].rate;
997 // Default to "same as source"
1002 lookup_video_rate_option(const GValue *vrate)
1006 const gchar *result = "Same as source";
1008 str = ghb_value_string(vrate);
1009 for (ii = 0; ii < hb_video_rates_count; ii++)
1011 if (strcmp(hb_video_rates[ii].string, str) == 0)
1013 result = hb_video_rates[ii].string;
1018 // Default to "same as source"
1023 lookup_audio_rate_int(const GValue *rate)
1028 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1030 // Coincidentally, the string "source" will return 0
1031 // which is our flag to use "same as source"
1032 gchar * str = ghb_value_string(rate);
1033 for (ii = 0; ii < hb_audio_rates_count; ii++)
1035 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1037 result = hb_audio_rates[ii].rate;
1043 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1044 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1045 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1047 for (ii = 0; ii < hb_audio_rates_count; ii++)
1049 gint val = ghb_value_int(rate);
1050 if (val == hb_audio_rates[ii].rate)
1052 result = hb_audio_rates[ii].rate;
1061 lookup_audio_rate_option(const GValue *rate)
1064 const gchar *result = "Same as source";
1066 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1068 // Coincidentally, the string "source" will return 0
1069 // which is our flag to use "same as source"
1070 gchar *str = ghb_value_string(rate);
1071 for (ii = 0; ii < hb_audio_rates_count; ii++)
1073 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1075 result = hb_audio_rates[ii].string;
1081 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1082 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1083 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1085 for (ii = 0; ii < hb_audio_rates_count; ii++)
1087 gint val = ghb_value_int(rate);
1088 if (val == hb_audio_rates[ii].rate)
1090 result = hb_audio_rates[ii].string;
1099 ghb_find_closest_audio_bitrate(gint codec, gint rate)
1106 if (codec == HB_ACODEC_FAAC)
1108 else if (codec == HB_ACODEC_AC3)
1112 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1114 if (hb_audio_bitrates[ii].rate < low)
1116 if (hb_audio_bitrates[ii].rate > high)
1118 if (rate <= hb_audio_bitrates[ii].rate)
1120 result = hb_audio_bitrates[ii].rate;
1128 ghb_find_closest_audio_rate(gint rate)
1134 for (ii = 0; ii < hb_audio_rates_count; ii++)
1136 if (rate <= hb_audio_rates[ii].rate)
1138 result = hb_audio_rates[ii].rate;
1146 lookup_audio_bitrate_int(const GValue *rate)
1151 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1153 // Coincidentally, the string "source" will return 0
1154 // which is our flag to use "same as source"
1155 gchar *str = ghb_value_string(rate);
1156 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1158 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1160 result = hb_audio_bitrates[ii].rate;
1166 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1167 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1168 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1170 gint val = ghb_value_int(rate);
1171 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1173 if (hb_audio_bitrates[ii].rate == val)
1175 result = hb_audio_bitrates[ii].rate;
1184 lookup_audio_bitrate_option(const GValue *rate)
1187 const gchar *result = "Same as source";
1189 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1191 // Coincidentally, the string "source" will return 0
1192 // which is our flag to use "same as source"
1193 gchar *str = ghb_value_string(rate);
1194 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1196 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1198 result = hb_audio_bitrates[ii].string;
1204 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1205 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1206 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1208 gint val = ghb_value_int(rate);
1209 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1211 if (hb_audio_bitrates[ii].rate == val)
1213 result = hb_audio_bitrates[ii].string;
1222 lookup_audio_lang_int(const GValue *rate)
1228 // Coincidentally, the string "source" will return 0
1229 // which is our flag to use "same as source"
1230 str = ghb_value_string(rate);
1231 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1233 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1244 lookup_audio_lang_option(const GValue *rate)
1248 const gchar *result = "Same as source";
1250 // Coincidentally, the string "source" will return 0
1251 // which is our flag to use "same as source"
1252 str = ghb_value_string(rate);
1253 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1255 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1257 if (ghb_language_table[ii].native_name[0] != 0)
1258 result = ghb_language_table[ii].native_name;
1260 result = ghb_language_table[ii].eng_name;
1269 ghb_lookup_acodec_value(gint val)
1271 GValue *value = NULL;
1274 for (ii = 0; ii < acodec_opts.count; ii++)
1276 if ((int)acodec_opts.map[ii].ivalue == val)
1278 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1282 value = ghb_string_value_new("auto");
1287 get_amix_value(gint val)
1289 GValue *value = NULL;
1292 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1294 if (hb_audio_mixdowns[ii].amixdown == val)
1296 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1303 // Handle for libhb. Gets set by ghb_backend_init()
1304 static hb_handle_t * h_scan = NULL;
1305 static hb_handle_t * h_queue = NULL;
1307 extern void hb_get_temporary_directory(char path[512]);
1314 hb_get_temporary_directory(dir);
1315 return g_strdup(dir);
1319 ghb_hb_cleanup(gboolean partial)
1323 hb_get_temporary_directory(dir);
1324 del_tree(dir, !partial);
1328 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1336 titleindex = ghb_settings_combo_int(ud->settings, "title");
1342 hb_subtitle_t * sub;
1344 if (h_scan == NULL) return VOBSUB;
1345 list = hb_get_titles( h_scan );
1346 if( !hb_list_count( list ) )
1348 /* No valid title, stop right there */
1351 title = hb_list_item( list, titleindex );
1352 if (title == NULL) return VOBSUB; // Bad titleindex
1353 sub = hb_list_item( title->list_subtitle, track);
1361 ghb_subtitle_source_name(gint source)
1363 const gchar * name = "Unknown";
1392 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1395 const gchar * name = "Unknown";
1408 titleindex = ghb_settings_combo_int(ud->settings, "title");
1414 hb_subtitle_t * sub;
1418 list = hb_get_titles( h_scan );
1419 if( !hb_list_count( list ) )
1422 title = hb_list_item( list, titleindex );
1426 sub = hb_list_item( title->list_subtitle, track);
1429 name = ghb_subtitle_source_name(sub->source);
1437 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1441 titleindex = ghb_settings_combo_int(ud->settings, "title");
1445 return ghb_get_user_audio_lang(ud, titleindex, 0);
1451 hb_subtitle_t * sub;
1456 list = hb_get_titles( h_scan );
1457 if( !hb_list_count( list ) )
1459 /* No valid title, stop right there */
1462 title = hb_list_item( list, titleindex );
1463 if (title == NULL) // Bad titleindex
1465 sub = hb_list_item( title->list_subtitle, track);
1467 return g_strdup(sub->iso639_2);
1470 return g_strdup("und");
1474 ghb_get_title_number(gint titleindex)
1479 if (h_scan == NULL) return 1;
1480 list = hb_get_titles( h_scan );
1481 if( !hb_list_count( list ) )
1483 /* No valid title, stop right there */
1486 title = hb_list_item( list, titleindex );
1487 if (title == NULL) return 1; // Bad titleindex
1488 return title->index;
1491 static hb_audio_config_t*
1492 get_hb_audio(gint titleindex, gint track)
1496 hb_audio_config_t *audio = NULL;
1498 if (h_scan == NULL) return NULL;
1499 list = hb_get_titles( h_scan );
1500 if( !hb_list_count( list ) )
1502 /* No valid title, stop right there */
1505 title = hb_list_item( list, titleindex );
1506 if (title == NULL) return NULL; // Bad titleindex
1507 if (!hb_list_count(title->list_audio))
1511 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1516 search_rates(hb_rate_t *rates, gint rate, gint count)
1519 for (ii = 0; ii < count; ii++)
1521 if (rates[ii].rate == rate)
1527 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1529 static GtkListStore*
1530 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1533 GtkListStore *store;
1535 g_debug("get_combo_box_store() %s\n", name);
1536 // First modify the combobox model to allow greying out of options
1537 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1538 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1543 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1545 GtkListStore *store;
1548 store = get_combo_box_store(builder, name);
1549 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1551 gtk_list_store_set(store, &iter,
1558 ghb_grey_combo_options(GtkBuilder *builder)
1561 gint container, track, titleindex, acodec;
1562 hb_audio_config_t *audio = NULL;
1565 widget = GHB_WIDGET (builder, "title");
1566 gval = ghb_widget_value(widget);
1567 titleindex = ghb_lookup_combo_int("title", gval);
1568 ghb_value_free(gval);
1569 widget = GHB_WIDGET (builder, "AudioTrack");
1570 gval = ghb_widget_value(widget);
1571 track = ghb_lookup_combo_int("AudioTrack", gval);
1572 ghb_value_free(gval);
1573 audio = get_hb_audio(titleindex, track);
1574 widget = GHB_WIDGET (builder, "FileFormat");
1575 gval = ghb_widget_value(widget);
1576 container = ghb_lookup_combo_int("FileFormat", gval);
1577 ghb_value_free(gval);
1579 grey_combo_box_item(builder, "x264_analyse", 4, TRUE);
1580 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1581 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1582 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1584 gboolean allow_dca = TRUE;
1585 allow_dca = (container != HB_MUX_MP4);
1587 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3_PASS, FALSE);
1589 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, FALSE);
1591 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, TRUE);
1593 if (audio && audio->in.codec != HB_ACODEC_AC3)
1595 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3_PASS, TRUE);
1597 if (audio && audio->in.codec != HB_ACODEC_DCA)
1599 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, TRUE);
1601 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1603 widget = GHB_WIDGET (builder, "AudioEncoder");
1604 gval = ghb_widget_value(widget);
1605 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1606 ghb_value_free(gval);
1607 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1608 if (container == HB_MUX_MP4)
1610 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1611 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1614 gboolean allow_mono = TRUE;
1615 gboolean allow_stereo = TRUE;
1616 gboolean allow_dolby = TRUE;
1617 gboolean allow_dpl2 = TRUE;
1618 gboolean allow_6ch = TRUE;
1620 allow_6ch = acodec & ~HB_ACODEC_LAME;
1623 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1625 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1627 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1628 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1629 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1630 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1631 allow_6ch = allow_6ch &&
1632 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1633 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1635 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1636 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1637 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1638 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1639 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1643 ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
1645 if (acodec & HB_ACODEC_FAAC)
1660 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1662 hb_audio_config_t *audio = NULL;
1663 gboolean allow_mono = TRUE;
1664 gboolean allow_stereo = TRUE;
1665 gboolean allow_dolby = TRUE;
1666 gboolean allow_dpl2 = TRUE;
1667 gboolean allow_6ch = TRUE;
1669 if (acodec & HB_ACODEC_PASS_FLAG)
1671 // Audio codec pass-thru. No mixdown
1674 audio = get_hb_audio(titleindex, track);
1678 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1680 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1682 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1683 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1684 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1685 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1687 (acodec & ~HB_ACODEC_LAME) &&
1688 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1689 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1691 gboolean greater = FALSE;
1694 // If no mix is specified, select the best available.
1695 mix = HB_AMIXDOWN_6CH;
1697 if (mix == HB_AMIXDOWN_6CH)
1700 if (allow_6ch) return HB_AMIXDOWN_6CH;
1702 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1705 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1707 if (mix == HB_AMIXDOWN_DOLBY || greater)
1710 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1712 if (mix == HB_AMIXDOWN_STEREO || greater)
1715 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1717 if (mix == HB_AMIXDOWN_MONO || greater)
1720 if (allow_mono) return HB_AMIXDOWN_MONO;
1722 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1723 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1724 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1725 if (allow_6ch) return HB_AMIXDOWN_6CH;
1729 // Set up the model for the combo box
1731 init_combo_box(GtkBuilder *builder, const gchar *name)
1734 GtkListStore *store;
1735 GtkCellRenderer *cell;
1737 g_debug("init_combo_box() %s\n", name);
1738 // First modify the combobox model to allow greying out of options
1739 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1743 // 1 - String to display
1744 // 2 - bool indicating whether the entry is selectable (grey or not)
1745 // 3 - String that is used for presets
1746 // 4 - Int value determined by backend
1747 // 5 - String value determined by backend
1748 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1749 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1750 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1752 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1754 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1755 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1756 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1757 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1758 "markup", 0, "sensitive", 1, NULL);
1761 { // Combo box entry
1762 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1767 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1770 GtkListStore *store;
1774 g_debug("audio_samplerate_opts_set ()\n");
1775 store = get_combo_box_store(builder, name);
1776 gtk_list_store_clear(store);
1777 // Add an item for "Same As Source"
1778 gtk_list_store_append(store, &iter);
1779 gtk_list_store_set(store, &iter,
1780 0, "<small>Same as source</small>",
1786 for (ii = 0; ii < count; ii++)
1788 gtk_list_store_append(store, &iter);
1789 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1790 gtk_list_store_set(store, &iter,
1793 2, rates[ii].string,
1794 3, (gdouble)rates[ii].rate,
1795 4, rates[ii].string,
1802 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1805 GtkListStore *store;
1808 g_debug("video_rate_opts_set ()\n");
1809 store = get_combo_box_store(builder, name);
1810 gtk_list_store_clear(store);
1811 // Add an item for "Same As Source"
1812 gtk_list_store_append(store, &iter);
1813 gtk_list_store_set(store, &iter,
1814 0, "Same as source",
1820 for (ii = 0; ii < count; ii++)
1824 if (strcmp(rates[ii].string, "23.976") == 0)
1826 desc = "(NTSC Film)";
1828 else if (strcmp(rates[ii].string, "25") == 0)
1830 desc = "(PAL Film/Video)";
1832 else if (strcmp(rates[ii].string, "29.97") == 0)
1834 desc = "(NTSC Video)";
1836 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1837 gtk_list_store_append(store, &iter);
1838 gtk_list_store_set(store, &iter,
1841 2, rates[ii].string,
1842 3, (gdouble)rates[ii].rate,
1843 4, rates[ii].string,
1850 mix_opts_set(GtkBuilder *builder, const gchar *name)
1853 GtkListStore *store;
1857 g_debug("mix_opts_set ()\n");
1858 store = get_combo_box_store(builder, name);
1859 gtk_list_store_clear(store);
1860 gtk_list_store_append(store, &iter);
1861 gtk_list_store_set(store, &iter,
1862 0, "<small>None</small>",
1868 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1870 gtk_list_store_append(store, &iter);
1871 str = g_strdup_printf("<small>%s</small>",
1872 hb_audio_mixdowns[ii].human_readable_name);
1873 gtk_list_store_set(store, &iter,
1876 2, hb_audio_mixdowns[ii].short_name,
1877 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1878 4, hb_audio_mixdowns[ii].internal_name,
1885 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1888 GtkListStore *store;
1891 g_debug("srt_codeset_opts_set ()\n");
1892 store = get_combo_box_store(builder, name);
1893 gtk_list_store_clear(store);
1894 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1896 gtk_list_store_append(store, &iter);
1897 gtk_list_store_set(store, &iter,
1898 0, srt_codeset_table[ii],
1900 2, srt_codeset_table[ii],
1902 4, srt_codeset_table[ii],
1905 GtkComboBoxEntry *cbe;
1907 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1908 //gtk_combo_box_entry_set_text_column(cbe, 0);
1912 language_opts_set(GtkBuilder *builder, const gchar *name)
1915 GtkListStore *store;
1918 g_debug("language_opts_set ()\n");
1919 store = get_combo_box_store(builder, name);
1920 gtk_list_store_clear(store);
1921 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1925 if (ghb_language_table[ii].native_name[0] != 0)
1926 lang = ghb_language_table[ii].native_name;
1928 lang = ghb_language_table[ii].eng_name;
1930 gtk_list_store_append(store, &iter);
1931 gtk_list_store_set(store, &iter,
1934 2, ghb_language_table[ii].iso639_2,
1936 4, ghb_language_table[ii].iso639_1,
1941 static gchar **titles = NULL;
1944 title_opts_set(GtkBuilder *builder, const gchar *name)
1947 GtkListStore *store;
1948 hb_list_t * list = NULL;
1949 hb_title_t * title = NULL;
1953 g_debug("title_opts_set ()\n");
1954 store = get_combo_box_store(builder, name);
1955 gtk_list_store_clear(store);
1958 list = hb_get_titles( h_scan );
1959 count = hb_list_count( list );
1960 if (count > 100) count = 100;
1962 if (titles) g_strfreev(titles);
1963 if (title_opts.map) g_free(title_opts.map);
1966 title_opts.count = count;
1967 title_opts.map = g_malloc(count*sizeof(options_map_t));
1968 titles = g_malloc((count+1) * sizeof(gchar*));
1972 title_opts.count = 1;
1973 title_opts.map = g_malloc(sizeof(options_map_t));
1978 // No titles. Fill in a default.
1979 gtk_list_store_append(store, &iter);
1980 gtk_list_store_set(store, &iter,
1987 title_opts.map[0].option = "No Titles";
1988 title_opts.map[0].shortOpt = "none";
1989 title_opts.map[0].ivalue = -1;
1990 title_opts.map[0].svalue = "none";
1993 for (ii = 0; ii < count; ii++)
1995 title = (hb_title_t*)hb_list_item(list, ii);
1996 if (title->type == HB_STREAM_TYPE)
1998 if (title->duration != 0)
2000 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
2001 title->index, title->hours, title->minutes, title->seconds,
2006 titles[ii] = g_strdup_printf ("%d - %s",
2007 title->index, title->name);
2012 if (title->duration != 0)
2014 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
2015 title->index, title->hours, title->minutes, title->seconds);
2019 titles[ii] = g_strdup_printf ("%d - Unknown Length",
2023 gtk_list_store_append(store, &iter);
2024 gtk_list_store_set(store, &iter,
2031 title_opts.map[ii].option = titles[ii];
2032 title_opts.map[ii].shortOpt = titles[ii];
2033 title_opts.map[ii].ivalue = ii;
2034 title_opts.map[ii].svalue = titles[ii];
2040 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
2043 gboolean foundit = FALSE;
2045 if (gtk_tree_model_get_iter_first (store, iter))
2049 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
2050 if (value == (gint)ivalue)
2055 } while (gtk_tree_model_iter_next (store, iter));
2061 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2064 GtkListStore *store;
2065 hb_list_t * list = NULL;
2066 hb_title_t * title = NULL;
2067 hb_audio_config_t * audio;
2072 g_debug("audio_track_opts_set ()\n");
2073 store = get_combo_box_store(builder, name);
2074 gtk_list_store_clear(store);
2077 list = hb_get_titles( h_scan );
2078 title = (hb_title_t*)hb_list_item( list, titleindex );
2081 count = hb_list_count( title->list_audio );
2084 if (count > 100) count = 100;
2085 if (audio_track_opts.map) g_free(audio_track_opts.map);
2088 audio_track_opts.count = count;
2089 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
2093 audio_track_opts.count = 1;
2094 audio_track_opts.map = g_malloc(sizeof(options_map_t));
2098 // No audio. set some default
2099 gtk_list_store_append(store, &iter);
2100 gtk_list_store_set(store, &iter,
2101 0, "<small>No Audio</small>",
2107 audio_track_opts.map[0].option = "No Audio";
2108 audio_track_opts.map[0].shortOpt = "none";
2109 audio_track_opts.map[0].ivalue = -1;
2110 audio_track_opts.map[0].svalue = "none";
2113 index_str_init(count-1);
2114 for (ii = 0; ii < count; ii++)
2116 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
2117 gtk_list_store_append(store, &iter);
2118 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
2119 gtk_list_store_set(store, &iter,
2127 audio_track_opts.map[ii].option = audio->lang.description,
2128 audio_track_opts.map[ii].shortOpt = index_str[ii];
2129 audio_track_opts.map[ii].ivalue = ii;
2130 audio_track_opts.map[ii].svalue = index_str[ii];
2135 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2138 GtkListStore *store;
2139 hb_list_t * list = NULL;
2140 hb_title_t * title = NULL;
2141 hb_subtitle_t * subtitle;
2143 static char ** options = NULL;
2145 g_debug("subtitle_track_opts_set ()\n");
2146 store = get_combo_box_store(builder, name);
2147 gtk_list_store_clear(store);
2150 list = hb_get_titles( h_scan );
2151 title = (hb_title_t*)hb_list_item( list, titleindex );
2154 count = hb_list_count( title->list_subtitle );
2157 if (count > 100) count = 100;
2158 if (subtitle_opts.map) g_free(subtitle_opts.map);
2161 subtitle_opts.count = count+1;
2162 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
2166 subtitle_opts.count = LANG_TABLE_SIZE+1;
2167 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
2169 gtk_list_store_append(store, &iter);
2170 gtk_list_store_set(store, &iter,
2171 0, "Foreign Audio Search",
2177 subtitle_opts.map[0].option = "Foreign Audio Search";
2178 subtitle_opts.map[0].shortOpt = "-1";
2179 subtitle_opts.map[0].ivalue = -1;
2180 subtitle_opts.map[0].svalue = "auto";
2183 if (options != NULL)
2184 g_strfreev(options);
2185 options = g_malloc((count+1)*sizeof(gchar*));
2186 index_str_init(count-1);
2187 for (ii = 0; ii < count; ii++)
2189 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
2190 options[ii] = g_strdup_printf("%d - %s (%s)", ii+1,
2192 ghb_subtitle_source_name(subtitle->source));
2193 subtitle_opts.map[ii+1].option = options[ii];
2194 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2195 subtitle_opts.map[ii+1].ivalue = ii;
2196 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
2197 gtk_list_store_append(store, &iter);
2198 gtk_list_store_set(store, &iter,
2203 4, subtitle->iso639_2,
2206 options[count] = NULL;
2210 index_str_init(LANG_TABLE_SIZE-1);
2211 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
2215 if (ghb_language_table[ii].native_name[0] != 0)
2216 lang = ghb_language_table[ii].native_name;
2218 lang = ghb_language_table[ii].eng_name;
2220 subtitle_opts.map[ii+1].option = lang;
2221 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2222 subtitle_opts.map[ii+1].ivalue = ii;
2223 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
2224 gtk_list_store_append(store, &iter);
2225 gtk_list_store_set(store, &iter,
2230 4, ghb_language_table[ii].iso639_2,
2243 gint titleindex = 0;
2246 g_debug("ghb_longest_title ()\n");
2247 if (h_scan == NULL) return 0;
2248 list = hb_get_titles( h_scan );
2249 count = hb_list_count( list );
2250 if (count > 100) count = 100;
2251 if (count < 1) return 0;
2252 title = (hb_title_t*)hb_list_item(list, 0);
2253 feature = title->job->feature;
2254 for (ii = 0; ii < count; ii++)
2256 title = (hb_title_t*)hb_list_item(list, ii);
2257 if (title->index == feature)
2266 ghb_get_source_audio_lang(gint titleindex, gint track)
2270 hb_audio_config_t * audio;
2273 g_debug("ghb_lookup_1st_audio_lang ()\n");
2276 list = hb_get_titles( h_scan );
2277 title = (hb_title_t*)hb_list_item( list, titleindex );
2280 if (hb_list_count( title->list_audio ) <= track)
2283 audio = hb_list_audio_config_item(title->list_audio, track);
2287 lang = g_strdup(audio->lang.iso639_2);
2292 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2296 used = g_hash_table_lookup(track_indices, &acodec);
2301 used = g_malloc0(count * sizeof(gboolean));
2302 key = g_malloc(sizeof(gint));
2304 g_hash_table_insert(track_indices, key, used);
2310 ghb_find_audio_track(
2314 gint fallback_acodec,
2315 GHashTable *track_indices)
2319 hb_audio_config_t * audio;
2324 gboolean *used = NULL;
2325 gboolean *passthru_used;
2327 gint passthru_acodec;
2331 g_debug("find_audio_track ()\n");
2332 if (h_scan == NULL) return -1;
2333 list = hb_get_titles( h_scan );
2334 title = (hb_title_t*)hb_list_item( list, titleindex );
2337 count = hb_list_count( title->list_audio );
2339 if (count > 10) count = 10;
2340 // Try to find an item that matches the preferred language and
2341 // the passthru codec type
2343 passthru = (acodec & HB_ACODEC_PASS_FLAG) != 0;
2346 for (ii = 0; ii < count; ii++)
2348 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2349 title->list_audio, ii );
2350 passthru_acodec = acodec & audio->in.codec;
2351 // Is the source track use a passthru capable codec?
2352 if (passthru_acodec == 0)
2354 used = get_track_used(passthru_acodec, track_indices, count);
2355 // Has the track already been used with this codec?
2359 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2360 audio->in.channel_layout);
2361 // Find a track that is not visually impaired or dirctor's
2362 // commentary, and has the highest channel count.
2363 if ((audio->lang.type < 2) &&
2364 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2365 (strcmp(lang, "und") == 0)))
2367 if (channels > max_chan)
2370 max_chan = channels;
2374 try_acodec = fallback_acodec;
2378 try_acodec = acodec;
2385 // Try to find an item that matches the preferred language
2387 used = get_track_used(try_acodec, track_indices, count);
2388 for (ii = 0; ii < count; ii++)
2390 // Has the track already been used with this codec?
2393 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2394 title->list_audio, ii );
2395 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2396 if (passthru_acodec && passthru)
2398 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2399 // Has the track already been used with this codec for passthru?
2400 if (passthru_used[ii])
2403 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2404 audio->in.channel_layout);
2405 // Find a track that is not visually impaired or dirctor's commentary
2406 if ((audio->lang.type < 2) &&
2407 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2408 (strcmp(lang, "und") == 0)))
2410 if (channels > max_chan)
2413 max_chan = channels;
2422 // Try to fine an item that does not match the preferred language and
2423 // matches the passthru codec type
2427 for (ii = 0; ii < count; ii++)
2429 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2430 title->list_audio, ii );
2431 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2432 // Is the source track use a passthru capable codec?
2433 if (passthru_acodec == 0)
2435 used = get_track_used(passthru_acodec, track_indices, count);
2436 // Has the track already been used with this codec?
2440 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2441 audio->in.channel_layout);
2442 // Find a track that is not visually impaired or dirctor's
2443 // commentary, and has the highest channel count.
2444 if (audio->lang.type < 2)
2446 if (channels > max_chan)
2449 max_chan = channels;
2453 try_acodec = fallback_acodec;
2457 try_acodec = acodec;
2464 // Try to fine an item that does not match the preferred language
2466 used = get_track_used(try_acodec, track_indices, count);
2467 for (ii = 0; ii < count; ii++)
2469 // Has the track already been used with this codec?
2472 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2473 title->list_audio, ii );
2474 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2475 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2476 audio->in.channel_layout);
2477 if (passthru_acodec && passthru)
2479 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2480 // Has the track already been used with this codec for passthru?
2481 if (passthru_used[ii])
2484 // Find a track that is not visually impaired or dirctor's commentary
2485 if (audio->lang.type < 2)
2487 if (channels > max_chan)
2490 max_chan = channels;
2499 // Last ditch, anything goes
2500 for (ii = 0; ii < count; ii++)
2502 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2503 title->list_audio, ii );
2504 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2505 if (passthru_acodec && passthru)
2507 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2508 // Has the track already been used with this codec for passthru?
2509 if (passthru_used[ii])
2512 // Has the track already been used with this codec?
2527 ghb_find_pref_subtitle_track(const gchar *lang)
2530 count = subtitle_opts.count;
2531 for (ii = 0; ii < count; ii++)
2533 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2535 return subtitle_opts.map[ii].ivalue;
2542 ghb_find_cc_track(gint titleindex)
2546 hb_subtitle_t * subtitle;
2549 g_debug("ghb_find_cc_track ()\n");
2550 if (h_scan == NULL) return -2;
2551 list = hb_get_titles( h_scan );
2552 title = (hb_title_t*)hb_list_item( list, titleindex );
2555 count = hb_list_count( title->list_subtitle );
2556 // Try to find an item that matches the preferred language
2557 for (ii = 0; ii < count; ii++)
2559 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2560 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2568 canForce(int source)
2570 return (source == VOBSUB);
2576 return (source == VOBSUB || source == SSASUB);
2580 ghb_find_subtitle_track(
2586 GHashTable * track_indices)
2590 hb_subtitle_t * subtitle;
2594 g_debug("find_subtitle_track ()\n");
2595 if (strcmp(lang, "auto") == 0)
2597 if (h_scan == NULL) return -1;
2598 list = hb_get_titles( h_scan );
2599 title = (hb_title_t*)hb_list_item( list, titleindex );
2602 count = hb_list_count( title->list_subtitle );
2603 used = g_hash_table_lookup(track_indices, lang);
2606 used = g_malloc0(count * sizeof(gboolean));
2607 g_hash_table_insert(track_indices, g_strdup(lang), used);
2609 // Try to find an item that matches the preferred language and source
2610 for (ii = 0; ii < count; ii++)
2615 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2616 if (source == subtitle->source &&
2617 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2618 (strcmp(lang, "und") == 0)))
2624 // Try to find an item that matches the preferred language
2625 for (ii = 0; ii < count; ii++)
2630 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2631 if (((!force || (force && canForce(subtitle->source))) &&
2632 (!burn || (burn && canBurn(subtitle->source)))) &&
2633 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2634 (strcmp(lang, "und") == 0)))
2645 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2648 GtkListStore *store;
2651 g_debug("generic_opts_set ()\n");
2652 if (name == NULL || opts == NULL) return;
2653 store = get_combo_box_store(builder, name);
2654 gtk_list_store_clear(store);
2655 for (ii = 0; ii < opts->count; ii++)
2657 gtk_list_store_append(store, &iter);
2658 gtk_list_store_set(store, &iter,
2659 0, opts->map[ii].option,
2661 2, opts->map[ii].shortOpt,
2662 3, opts->map[ii].ivalue,
2663 4, opts->map[ii].svalue,
2669 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2672 GtkListStore *store;
2676 g_debug("small_opts_set ()\n");
2677 if (name == NULL || opts == NULL) return;
2678 store = get_combo_box_store(builder, name);
2679 gtk_list_store_clear(store);
2680 for (ii = 0; ii < opts->count; ii++)
2682 gtk_list_store_append(store, &iter);
2683 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2684 gtk_list_store_set(store, &iter,
2687 2, opts->map[ii].shortOpt,
2688 3, opts->map[ii].ivalue,
2689 4, opts->map[ii].svalue,
2696 find_combo_table(const gchar *name)
2700 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2702 if (strcmp(name, combo_name_map[ii].name) == 0)
2704 return combo_name_map[ii].opts;
2711 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2715 if (strcmp(name, "AudioBitrate") == 0)
2716 return lookup_audio_bitrate_int(gval);
2717 else if (strcmp(name, "AudioSamplerate") == 0)
2718 return lookup_audio_rate_int(gval);
2719 else if (strcmp(name, "VideoFramerate") == 0)
2720 return lookup_video_rate_int(gval);
2721 else if (strcmp(name, "AudioMixdown") == 0)
2722 return lookup_mix_int(gval);
2723 else if (strcmp(name, "SrtLanguage") == 0)
2724 return lookup_audio_lang_int(gval);
2725 else if (strcmp(name, "PreferredLanguage") == 0)
2726 return lookup_audio_lang_int(gval);
2729 return lookup_generic_int(find_combo_table(name), gval);
2731 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2736 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2740 if (strcmp(name, "AudioBitrate") == 0)
2741 return lookup_audio_bitrate_int(gval);
2742 else if (strcmp(name, "AudioSamplerate") == 0)
2743 return lookup_audio_rate_int(gval);
2744 else if (strcmp(name, "VideoFramerate") == 0)
2745 return lookup_video_rate_int(gval);
2746 else if (strcmp(name, "AudioMixdown") == 0)
2747 return lookup_mix_int(gval);
2748 else if (strcmp(name, "SrtLanguage") == 0)
2749 return lookup_audio_lang_int(gval);
2750 else if (strcmp(name, "PreferredLanguage") == 0)
2751 return lookup_audio_lang_int(gval);
2754 return lookup_generic_double(find_combo_table(name), gval);
2756 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2761 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2765 if (strcmp(name, "AudioBitrate") == 0)
2766 return lookup_audio_bitrate_option(gval);
2767 else if (strcmp(name, "AudioSamplerate") == 0)
2768 return lookup_audio_rate_option(gval);
2769 else if (strcmp(name, "VideoFramerate") == 0)
2770 return lookup_video_rate_option(gval);
2771 else if (strcmp(name, "AudioMixdown") == 0)
2772 return lookup_mix_option(gval);
2773 else if (strcmp(name, "SrtLanguage") == 0)
2774 return lookup_audio_lang_option(gval);
2775 else if (strcmp(name, "PreferredLanguage") == 0)
2776 return lookup_audio_lang_option(gval);
2779 return lookup_generic_option(find_combo_table(name), gval);
2781 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2786 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2790 if (strcmp(name, "AudioBitrate") == 0)
2791 return lookup_audio_bitrate_option(gval);
2792 else if (strcmp(name, "AudioSamplerate") == 0)
2793 return lookup_audio_rate_option(gval);
2794 else if (strcmp(name, "VideoFramerate") == 0)
2795 return lookup_video_rate_option(gval);
2796 else if (strcmp(name, "AudioMixdown") == 0)
2797 return lookup_mix_string(gval);
2798 else if (strcmp(name, "SrtLanguage") == 0)
2799 return lookup_audio_lang_option(gval);
2800 else if (strcmp(name, "PreferredLanguage") == 0)
2801 return lookup_audio_lang_option(gval);
2804 return lookup_generic_string(find_combo_table(name), gval);
2806 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2811 ghb_update_ui_combo_box(
2812 signal_user_data_t *ud,
2817 GtkComboBox *combo = NULL;
2819 gint handler_id = 0;
2823 g_debug("ghb_update_ui_combo_box() %s\n", name);
2824 // Clearing a combo box causes a rash of "changed" events, even when
2825 // the active item is -1 (inactive). To control things, I'm disabling
2826 // the event till things are settled down.
2827 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2828 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2831 // Valid signal id found. This should always succeed.
2832 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2833 signal_id, 0, 0, 0, 0);
2836 // This should also always succeed
2837 g_signal_handler_block ((gpointer)combo, handler_id);
2843 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2844 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2845 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2846 mix_opts_set(ud->builder, "AudioMixdown");
2847 language_opts_set(ud->builder, "SrtLanguage");
2848 language_opts_set(ud->builder, "PreferredLanguage");
2849 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2850 title_opts_set(ud->builder, "title");
2851 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2852 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2853 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2854 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2855 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2856 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2857 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2858 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2859 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2860 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2861 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2862 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2863 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2864 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2865 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2866 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2867 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2868 small_opts_set(ud->builder, "x264_direct", &direct_opts);
2869 small_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2870 small_opts_set(ud->builder, "x264_bpyramid", &bpyramid_opts);
2871 small_opts_set(ud->builder, "x264_weighted_pframes", &weightp_opts);
2872 small_opts_set(ud->builder, "x264_me", &me_opts);
2873 small_opts_set(ud->builder, "x264_subme", &subme_opts);
2874 small_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2875 small_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2879 if (strcmp(name, "AudioBitrate") == 0)
2880 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2881 else if (strcmp(name, "AudioSamplerate") == 0)
2882 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2883 else if (strcmp(name, "VideoFramerate") == 0)
2884 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2885 else if (strcmp(name, "AudioMixdown") == 0)
2886 mix_opts_set(ud->builder, "AudioMixdown");
2887 else if (strcmp(name, "SrtLanguage") == 0)
2888 language_opts_set(ud->builder, "SrtLanguage");
2889 else if (strcmp(name, "PreferredLanguage") == 0)
2890 language_opts_set(ud->builder, "PreferredLanguage");
2891 else if (strcmp(name, "SrtCodeset") == 0)
2892 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2893 else if (strcmp(name, "title") == 0)
2894 title_opts_set(ud->builder, "title");
2895 else if (strcmp(name, "SubtitleTrack") == 0)
2896 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2897 else if (strcmp(name, "AudioTrack") == 0)
2898 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2900 generic_opts_set(ud->builder, name, find_combo_table(name));
2904 g_signal_handler_unblock ((gpointer)combo, handler_id);
2909 init_ui_combo_boxes(GtkBuilder *builder)
2913 init_combo_box(builder, "AudioBitrate");
2914 init_combo_box(builder, "AudioSamplerate");
2915 init_combo_box(builder, "VideoFramerate");
2916 init_combo_box(builder, "AudioMixdown");
2917 init_combo_box(builder, "SrtLanguage");
2918 init_combo_box(builder, "PreferredLanguage");
2919 init_combo_box(builder, "SrtCodeset");
2920 init_combo_box(builder, "title");
2921 init_combo_box(builder, "AudioTrack");
2922 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2924 init_combo_box(builder, combo_name_map[ii].name);
2928 static const char * turbo_opts =
2929 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2930 "no-fast-pskip=0:8x8dct=0";
2932 // Construct the x264 options string
2933 // The result is allocated, so someone must free it at some point.
2935 ghb_build_x264opts_string(GValue *settings)
2938 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2945 result = g_strdup("");
2951 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2955 hb_chapter_t * chapter;
2959 *hh = *mm = *ss = 0;
2960 if (h_scan == NULL) return;
2961 list = hb_get_titles( h_scan );
2962 title = (hb_title_t*)hb_list_item( list, tt );
2963 if (title == NULL) return;
2966 *mm = title->minutes;
2967 *ss = title->seconds;
2969 count = hb_list_count(title->list_chapter);
2970 if (sc > count) sc = count;
2971 if (ec > count) ec = count;
2973 if (sc == 1 && ec == count)
2977 for (c = sc; c <= ec; c++)
2979 chapter = hb_list_item(title->list_chapter, c-1);
2980 duration += chapter->duration;
2983 *hh = duration / 90000 / 3600;
2984 *mm = ((duration / 90000) % 3600) / 60;
2985 *ss = (duration / 90000) % 60;
2989 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2993 hb_chapter_t * chapter;
2996 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2997 *hh = *mm = *ss = 0;
2998 if (h_scan == NULL) return;
2999 list = hb_get_titles( h_scan );
3000 title = (hb_title_t*)hb_list_item( list, ti );
3001 if (title == NULL) return;
3002 count = hb_list_count( title->list_chapter );
3003 if (ii >= count) return;
3004 chapter = hb_list_item(title->list_chapter, ii);
3005 if (chapter == NULL) return;
3006 *hh = chapter->hours;
3007 *mm = chapter->minutes;
3008 *ss = chapter->seconds;
3012 ghb_get_chapters(gint titleindex)
3016 hb_chapter_t * chapter;
3018 GValue *chapters = NULL;
3020 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
3021 if (h_scan == NULL) return NULL;
3022 list = hb_get_titles( h_scan );
3023 title = (hb_title_t*)hb_list_item( list, titleindex );
3024 if (title == NULL) return NULL;
3025 count = hb_list_count( title->list_chapter );
3026 chapters = ghb_array_value_new(count);
3027 for (ii = 0; ii < count; ii++)
3029 chapter = hb_list_item(title->list_chapter, ii);
3030 if (chapter == NULL) break;
3031 if (chapter->title == NULL || chapter->title[0] == 0)
3034 str = g_strdup_printf ("Chapter %2d", ii+1);
3035 ghb_array_append(chapters, ghb_string_value_new(str));
3040 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
3047 ghb_ac3_in_audio_list(const GValue *audio_list)
3051 count = ghb_array_len(audio_list);
3052 for (ii = 0; ii < count; ii++)
3057 asettings = ghb_array_get_nth(audio_list, ii);
3058 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
3059 if (acodec & HB_ACODEC_AC3)
3066 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
3069 GtkListStore *store;
3072 g_debug("audio_bitrate_opts_add ()\n");
3074 if (rate < 8) return;
3076 store = get_combo_box_store(builder, name);
3077 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
3079 str = g_strdup_printf ("<small>%d</small>", rate);
3080 gtk_list_store_append(store, &iter);
3081 gtk_list_store_set(store, &iter,
3093 audio_bitrate_opts_clean(
3094 GtkBuilder *builder,
3100 GtkListStore *store;
3102 gboolean done = FALSE;
3104 guint last = (guint)last_rate;
3105 guint first = (guint)first_rate;
3107 g_debug("audio_bitrate_opts_clean ()\n");
3108 store = get_combo_box_store(builder, name);
3109 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
3113 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
3115 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
3117 done = !gtk_list_store_remove(store, &iter);
3119 else if (ivalue < first || ivalue > last)
3122 gtk_list_store_set(store, &iter, 1, FALSE, -1);
3123 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3128 gtk_list_store_set(store, &iter, 1, TRUE, -1);
3129 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3136 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
3139 GtkListStore *store;
3143 g_debug("audio_bitrate_opts_set ()\n");
3144 store = get_combo_box_store(builder, name);
3145 gtk_list_store_clear(store);
3146 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
3148 gtk_list_store_append(store, &iter);
3149 str = g_strdup_printf ("<small>%s</small>",
3150 hb_audio_bitrates[ii].string);
3151 gtk_list_store_set(store, &iter,
3154 2, hb_audio_bitrates[ii].string,
3155 3, (gdouble)hb_audio_bitrates[ii].rate,
3156 4, hb_audio_bitrates[ii].string,
3163 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
3165 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
3169 ghb_set_default_bitrate_opts(
3170 GtkBuilder *builder,
3174 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
3177 static ghb_status_t hb_status;
3180 ghb_combo_init(signal_user_data_t *ud)
3182 // Set up the list model for the combos
3183 init_ui_combo_boxes(ud->builder);
3184 // Populate all the combos
3185 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
3189 ghb_backend_init(gint debug)
3192 h_scan = hb_init( debug, 0 );
3193 h_queue = hb_init( debug, 0 );
3204 void ghb_backend_scan_stop()
3206 hb_scan_stop( h_scan );
3210 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count, uint64_t min_duration)
3212 hb_scan( h_scan, path, titleindex, preview_count, 1, min_duration );
3213 hb_status.scan.state |= GHB_STATE_SCANNING;
3214 // initialize count and cur to something that won't cause FPE
3215 // when computing progress
3216 hb_status.scan.title_count = 1;
3217 hb_status.scan.title_cur = 0;
3221 ghb_backend_queue_scan(const gchar *path, gint titlenum)
3223 g_debug("ghb_backend_queue_scan()");
3224 hb_scan( h_queue, path, titlenum, 10, 0, 0 );
3225 hb_status.queue.state |= GHB_STATE_SCANNING;
3229 ghb_get_scan_state()
3231 return hb_status.scan.state;
3235 ghb_get_queue_state()
3237 return hb_status.queue.state;
3241 ghb_clear_scan_state(gint state)
3243 hb_status.scan.state &= ~state;
3247 ghb_clear_queue_state(gint state)
3249 hb_status.queue.state &= ~state;
3253 ghb_set_scan_state(gint state)
3255 hb_status.scan.state |= state;
3259 ghb_set_queue_state(gint state)
3261 hb_status.queue.state |= state;
3265 ghb_get_status(ghb_status_t *status)
3267 memcpy(status, &hb_status, sizeof(ghb_status_t));
3276 if (h_scan == NULL) return;
3277 hb_get_state( h_scan, &s_scan );
3278 switch( s_scan.state )
3280 #define p s_scan.param.scanning
3281 case HB_STATE_SCANNING:
3283 hb_status.scan.state |= GHB_STATE_SCANNING;
3284 hb_status.scan.title_count = p.title_count;
3285 hb_status.scan.title_cur = p.title_cur;
3289 case HB_STATE_SCANDONE:
3291 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3292 hb_status.scan.state |= GHB_STATE_SCANDONE;
3295 #define p s_scan.param.working
3296 case HB_STATE_WORKING:
3297 hb_status.scan.state |= GHB_STATE_WORKING;
3298 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3299 hb_status.scan.job_cur = p.job_cur;
3300 hb_status.scan.job_count = p.job_count;
3301 hb_status.scan.progress = p.progress;
3302 hb_status.scan.rate_cur = p.rate_cur;
3303 hb_status.scan.rate_avg = p.rate_avg;
3304 hb_status.scan.hours = p.hours;
3305 hb_status.scan.minutes = p.minutes;
3306 hb_status.scan.seconds = p.seconds;
3307 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3311 case HB_STATE_PAUSED:
3312 hb_status.scan.state |= GHB_STATE_PAUSED;
3315 case HB_STATE_MUXING:
3317 hb_status.scan.state |= GHB_STATE_MUXING;
3320 #define p s_scan.param.workdone
3321 case HB_STATE_WORKDONE:
3325 hb_status.scan.state |= GHB_STATE_WORKDONE;
3326 hb_status.scan.state &= ~GHB_STATE_MUXING;
3327 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3328 hb_status.scan.state &= ~GHB_STATE_WORKING;
3332 hb_status.scan.error = GHB_ERROR_NONE;
3334 case HB_ERROR_CANCELED:
3335 hb_status.scan.error = GHB_ERROR_CANCELED;
3338 hb_status.scan.error = GHB_ERROR_FAIL;
3341 // Delete all remaining jobs of this encode.
3342 // An encode can be composed of multiple associated jobs.
3343 // When a job is stopped, libhb removes it from the job list,
3344 // but does not remove other jobs that may be associated with it.
3345 // Associated jobs are taged in the sequence id.
3346 while ((job = hb_job(h_scan, 0)) != NULL)
3347 hb_rem( h_scan, job );
3351 hb_get_state( h_queue, &s_queue );
3352 switch( s_queue.state )
3354 #define p s_queue.param.scanning
3355 case HB_STATE_SCANNING:
3357 hb_status.queue.state |= GHB_STATE_SCANNING;
3358 hb_status.queue.title_count = p.title_count;
3359 hb_status.queue.title_cur = p.title_cur;
3363 case HB_STATE_SCANDONE:
3365 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3366 hb_status.queue.state |= GHB_STATE_SCANDONE;
3369 #define p s_queue.param.working
3370 case HB_STATE_WORKING:
3371 hb_status.queue.state |= GHB_STATE_WORKING;
3372 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3373 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3374 hb_status.queue.job_cur = p.job_cur;
3375 hb_status.queue.job_count = p.job_count;
3376 hb_status.queue.progress = p.progress;
3377 hb_status.queue.rate_cur = p.rate_cur;
3378 hb_status.queue.rate_avg = p.rate_avg;
3379 hb_status.queue.hours = p.hours;
3380 hb_status.queue.minutes = p.minutes;
3381 hb_status.queue.seconds = p.seconds;
3382 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3385 case HB_STATE_SEARCHING:
3386 hb_status.queue.state |= GHB_STATE_SEARCHING;
3387 hb_status.queue.state &= ~GHB_STATE_WORKING;
3388 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3389 hb_status.queue.job_cur = p.job_cur;
3390 hb_status.queue.job_count = p.job_count;
3391 hb_status.queue.progress = p.progress;
3392 hb_status.queue.rate_cur = p.rate_cur;
3393 hb_status.queue.rate_avg = p.rate_avg;
3394 hb_status.queue.hours = p.hours;
3395 hb_status.queue.minutes = p.minutes;
3396 hb_status.queue.seconds = p.seconds;
3397 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3401 case HB_STATE_PAUSED:
3402 hb_status.queue.state |= GHB_STATE_PAUSED;
3405 case HB_STATE_MUXING:
3407 hb_status.queue.state |= GHB_STATE_MUXING;
3410 #define p s_queue.param.workdone
3411 case HB_STATE_WORKDONE:
3415 hb_status.queue.state |= GHB_STATE_WORKDONE;
3416 hb_status.queue.state &= ~GHB_STATE_MUXING;
3417 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3418 hb_status.queue.state &= ~GHB_STATE_WORKING;
3419 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3423 hb_status.queue.error = GHB_ERROR_NONE;
3425 case HB_ERROR_CANCELED:
3426 hb_status.queue.error = GHB_ERROR_CANCELED;
3429 hb_status.queue.error = GHB_ERROR_FAIL;
3432 // Delete all remaining jobs of this encode.
3433 // An encode can be composed of multiple associated jobs.
3434 // When a job is stopped, libhb removes it from the job list,
3435 // but does not remove other jobs that may be associated with it.
3436 // Associated jobs are taged in the sequence id.
3437 while ((job = hb_job(h_queue, 0)) != NULL)
3438 hb_rem( h_queue, job );
3445 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3450 if (h_scan == NULL) return FALSE;
3451 list = hb_get_titles( h_scan );
3452 if( !hb_list_count( list ) )
3454 /* No valid title, stop right there */
3458 title = hb_list_item( list, titleindex );
3459 if (title == NULL) return FALSE; // Bad titleindex
3460 tinfo->index = titleindex;
3461 tinfo->width = title->width;
3462 tinfo->height = title->height;
3463 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3464 // Don't allow crop to 0
3465 if (title->crop[0] + title->crop[1] >= title->height)
3466 title->crop[0] = title->crop[1] = 0;
3467 if (title->crop[2] + title->crop[3] >= title->width)
3468 title->crop[2] = title->crop[3] = 0;
3469 tinfo->num_chapters = hb_list_count(title->list_chapter);
3470 tinfo->rate_base = title->rate_base;
3471 tinfo->rate = title->rate;
3472 tinfo->interlaced = title->detected_interlacing;
3473 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3474 title->width * title->pixel_aspect_width,
3475 title->height * title->pixel_aspect_height);
3476 tinfo->hours = title->hours;
3477 tinfo->minutes = title->minutes;
3478 tinfo->seconds = title->seconds;
3479 tinfo->duration = title->duration;
3481 tinfo->angle_count = title->angle_count;
3482 tinfo->path = title->path;
3483 tinfo->name = title->name;
3484 tinfo->type = title->type;
3489 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3491 hb_audio_config_t *audio;
3493 audio = get_hb_audio(titleindex, audioindex);
3494 if (audio == NULL) return FALSE; // Bad audioindex
3495 ainfo->codec = audio->in.codec;
3496 ainfo->bitrate = audio->in.bitrate;
3497 ainfo->samplerate = audio->in.samplerate;
3502 ghb_audio_is_passthru(gint acodec)
3504 g_debug("ghb_audio_is_passthru () \n");
3505 return (acodec & HB_ACODEC_PASS_FLAG) != 0;
3509 ghb_audio_can_passthru(gint acodec)
3511 g_debug("ghb_audio_can_passthru () \n");
3512 return (acodec & HB_ACODEC_PASS_MASK) != 0;
3516 ghb_get_default_acodec()
3518 return HB_ACODEC_FAAC;
3522 picture_settings_deps(signal_user_data_t *ud)
3524 gboolean autoscale, keep_aspect, enable_keep_aspect;
3525 gboolean enable_scale_width, enable_scale_height;
3526 gboolean enable_disp_width, enable_disp_height, enable_par;
3530 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3533 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3534 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3535 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3537 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3538 if (!enable_keep_aspect)
3540 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3542 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3543 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3545 enable_scale_width = !autoscale && (pic_par != 1);
3546 enable_scale_height = !autoscale && (pic_par != 1);
3547 enable_disp_width = (pic_par == 3) && !keep_aspect;
3548 enable_par = (pic_par == 3) && !keep_aspect;
3549 enable_disp_height = FALSE;
3551 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3552 gtk_widget_set_sensitive(widget, pic_par != 1);
3553 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3554 gtk_widget_set_sensitive(widget, pic_par != 1);
3555 widget = GHB_WIDGET(ud->builder, "scale_width");
3556 gtk_widget_set_sensitive(widget, enable_scale_width);
3557 widget = GHB_WIDGET(ud->builder, "scale_height");
3558 gtk_widget_set_sensitive(widget, enable_scale_height);
3559 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3560 gtk_widget_set_sensitive(widget, enable_disp_width);
3561 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3562 gtk_widget_set_sensitive(widget, enable_disp_height);
3563 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3564 gtk_widget_set_sensitive(widget, enable_par);
3565 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3566 gtk_widget_set_sensitive(widget, enable_par);
3567 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3568 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3569 widget = GHB_WIDGET(ud->builder, "autoscale");
3570 gtk_widget_set_sensitive(widget, pic_par != 1);
3574 ghb_set_scale(signal_user_data_t *ud, gint mode)
3579 gboolean keep_aspect;
3581 gboolean autocrop, autoscale, noscale;
3582 gint crop[4], width, height, par_width, par_height;
3583 gint crop_width, crop_height;
3584 gint aspect_n, aspect_d;
3585 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3586 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3591 gint max_height = 0;
3593 g_debug("ghb_set_scale ()\n");
3594 picture_settings_deps(ud);
3595 if (h_scan == NULL) return;
3596 list = hb_get_titles( h_scan );
3597 if( !hb_list_count( list ) )
3599 /* No valid title, stop right there */
3604 titleindex = ghb_settings_combo_int(ud->settings, "title");
3605 title = hb_list_item( list, titleindex );
3606 if (title == NULL) return;
3608 if (job == NULL) return;
3610 if (ud->scale_busy) return;
3611 ud->scale_busy = TRUE;
3613 // First configure widgets
3614 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3615 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3616 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3617 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3618 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3619 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3620 // alignment constraints rather than scaling to satisfy them.
3621 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3622 // Align dimensions to either 16 or 2 pixels
3623 // The scaler crashes if the dimensions are not divisible by 2
3624 // x264 also will not accept dims that are not multiple of 2
3628 keep_height = FALSE;
3630 // Step needs to be at least 2 because odd widths cause scaler crash
3632 widget = GHB_WIDGET (ud->builder, "scale_width");
3633 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3634 widget = GHB_WIDGET (ud->builder, "scale_height");
3635 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3638 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3639 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3640 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3641 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3642 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3643 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3644 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3645 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3649 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3650 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3651 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3652 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3653 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3654 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3655 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3656 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3658 ghb_title_info_t tinfo;
3659 ghb_get_title_info (&tinfo, titleindex);
3662 crop[0] = tinfo.crop[0];
3663 crop[1] = tinfo.crop[1];
3664 crop[2] = tinfo.crop[2];
3665 crop[3] = tinfo.crop[3];
3666 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3667 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3668 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3669 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3673 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3674 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3675 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3676 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3682 // Adjust the cropping to accomplish the desired width and height
3683 crop_width = tinfo.width - crop[2] - crop[3];
3684 crop_height = tinfo.height - crop[0] - crop[1];
3685 width = MOD_DOWN(crop_width, mod);
3686 height = MOD_DOWN(crop_height, mod);
3688 need1 = (crop_height - height) / 2;
3689 need2 = crop_height - height - need1;
3692 need1 = (crop_width - width) / 2;
3693 need2 = crop_width - width - need1;
3696 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3697 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3698 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3699 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3701 hb_reduce(&aspect_n, &aspect_d,
3702 title->width * title->pixel_aspect_width,
3703 title->height * title->pixel_aspect_height);
3704 crop_width = title->width - crop[2] - crop[3];
3705 crop_height = title->height - crop[0] - crop[1];
3709 height = crop_height;
3713 width = ghb_settings_get_int(ud->settings, "scale_width");
3714 height = ghb_settings_get_int(ud->settings, "scale_height");
3715 if (mode & GHB_PIC_USE_MAX)
3717 max_width = MOD_DOWN(
3718 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3719 max_height = MOD_DOWN(
3720 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3723 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3726 width = title->width - crop[2] - crop[3];
3728 height = title->height - crop[0] - crop[1];
3730 width = MOD_ROUND(width, mod);
3731 height = MOD_ROUND(height, mod);
3733 job->anamorphic.mode = pic_par;
3736 // The scaler crashes if the dimensions are not divisible by 2
3737 // Align mod 2. And so does something in x264_encoder_headers()
3739 job->anamorphic.par_width = title->pixel_aspect_width;
3740 job->anamorphic.par_height = title->pixel_aspect_height;
3741 job->anamorphic.dar_width = 0;
3742 job->anamorphic.dar_height = 0;
3744 if (keep_height && pic_par == 2)
3745 width = ((double)height * crop_width / crop_height);
3747 job->height = height;
3748 job->maxWidth = max_width;
3749 job->maxHeight = max_height;
3750 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3751 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3752 if (job->anamorphic.mode == 3 && !keep_aspect)
3754 job->anamorphic.keep_display_aspect = 0;
3755 if (mode & GHB_PIC_KEEP_PAR)
3757 job->anamorphic.par_width =
3758 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3759 job->anamorphic.par_height =
3760 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3764 job->anamorphic.dar_width =
3765 ghb_settings_get_int(ud->settings,
3766 "PictureDisplayWidth");
3767 job->anamorphic.dar_height = height;
3772 job->anamorphic.keep_display_aspect = 1;
3774 // hb_set_anamorphic_size will adjust par, dar, and width/height
3775 // to conform to job parameters that have been set, including
3776 // maxWidth and maxHeight
3777 hb_set_anamorphic_size( job, &width, &height,
3778 &par_width, &par_height );
3779 if (job->anamorphic.mode == 3 && !keep_aspect &&
3780 mode & GHB_PIC_KEEP_PAR)
3782 // hb_set_anamorphic_size reduces the par, which we
3783 // don't want in this case because the user is
3784 // explicitely specifying it.
3785 par_width = ghb_settings_get_int(ud->settings,
3787 par_height = ghb_settings_get_int(ud->settings,
3788 "PicturePARHeight");
3793 // Adjust dims according to max values
3795 height = MIN(height, max_height);
3797 width = MIN(width, max_width);
3802 gint new_width, new_height;
3804 // Compute pixel aspect ration.
3805 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3806 // Must scale so that par becomes 1:1
3807 // Try to keep largest dimension
3808 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3809 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3811 if (max_width && new_width > max_width)
3813 height = new_height;
3815 else if (max_height && new_height > max_height)
3819 else if (keep_width)
3821 height = new_height;
3823 else if (keep_height)
3827 else if (width > new_width)
3829 height = new_height;
3835 g_debug("new w %d h %d\n", width, height);
3837 width = MOD_ROUND(width, mod);
3838 height = MOD_ROUND(height, mod);
3840 height = MIN(height, max_height);
3842 width = MIN(width, max_width);
3843 par_width = par_height = 1;
3845 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3846 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3848 gint disp_width, dar_width, dar_height;
3851 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3852 hb_reduce(&dar_width, &dar_height, disp_width, height);
3854 gint iaspect = dar_width * 9 / dar_height;
3855 if (dar_width > 2 * dar_height)
3857 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3859 else if (iaspect <= 16 && iaspect >= 15)
3861 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3863 else if (iaspect <= 12 && iaspect >= 11)
3865 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3869 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3871 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3873 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3874 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3875 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3876 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3877 ud->scale_busy = FALSE;
3881 set_preview_job_settings(hb_job_t *job, GValue *settings)
3883 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3884 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3885 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3886 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3888 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3890 ghb_settings_combo_int(settings, "PictureModulus");
3891 job->width = ghb_settings_get_int(settings, "scale_width");
3892 job->height = ghb_settings_get_int(settings, "scale_height");
3893 if (ghb_settings_get_boolean(settings, "show_crop"))
3895 gdouble xscale = (gdouble)job->width /
3896 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3897 gdouble yscale = (gdouble)job->height /
3898 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3900 job->width += xscale * (job->crop[2] + job->crop[3]);
3901 job->height += yscale * (job->crop[0] + job->crop[1]);
3909 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3912 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3913 job->deinterlace = (decomb == 0) ? 0 : 1;
3917 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3918 job->deinterlace = (deint == 0) ? 0 : 1;
3921 gboolean keep_aspect;
3922 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3923 if (job->anamorphic.mode)
3925 job->anamorphic.par_width = job->title->pixel_aspect_width;
3926 job->anamorphic.par_height = job->title->pixel_aspect_height;
3927 job->anamorphic.dar_width = 0;
3928 job->anamorphic.dar_height = 0;
3930 if (job->anamorphic.mode == 3 && !keep_aspect)
3932 job->anamorphic.keep_display_aspect = 0;
3933 job->anamorphic.par_width =
3934 ghb_settings_get_int(settings, "PicturePARWidth");
3935 job->anamorphic.par_height =
3936 ghb_settings_get_int(settings, "PicturePARHeight");
3940 job->anamorphic.keep_display_aspect = 1;
3946 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3953 if (h_scan == NULL) return 1500;
3954 list = hb_get_titles( h_scan );
3955 title = hb_list_item( list, titleindex );
3956 if (title == NULL) return 1500;
3958 if (job == NULL) return 1500;
3959 size = ghb_settings_get_int(settings, "VideoTargetSize");
3960 return hb_calc_bitrate( job, size );
3964 ghb_validate_filter_string(const gchar *str, gint max_fields)
3970 if (str == NULL || *str == 0) return TRUE;
3973 val = g_strtod(str, &end);
3975 { // Found a numeric value
3977 // negative max_fields means infinate
3978 if (max_fields >= 0 && fields > max_fields) return FALSE;
3992 ghb_validate_filters(signal_user_data_t *ud)
3998 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
4000 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
4001 if (!decomb_deint && index == 1)
4003 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
4004 if (!ghb_validate_filter_string(str, -1))
4006 message = g_strdup_printf(
4007 "Invalid Deinterlace Settings:\n\n%s\n",
4009 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4017 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
4020 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
4021 if (!ghb_validate_filter_string(str, -1))
4023 message = g_strdup_printf(
4024 "Invalid Detelecine Settings:\n\n%s\n",
4026 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4034 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
4035 if (decomb_deint && index == 1)
4037 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
4038 if (!ghb_validate_filter_string(str, -1))
4040 message = g_strdup_printf(
4041 "Invalid Decomb Settings:\n\n%s\n",
4043 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4051 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
4054 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
4055 if (!ghb_validate_filter_string(str, -1))
4057 message = g_strdup_printf(
4058 "Invalid Denoise Settings:\n\n%s\n",
4060 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4071 ghb_validate_video(signal_user_data_t *ud)
4076 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4077 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
4078 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
4080 // mp4/theora combination is not supported.
4081 message = g_strdup_printf(
4082 "Theora is not supported in the MP4 container.\n\n"
4083 "You should choose a different video codec or container.\n"
4084 "If you continue, FFMPEG will be chosen for you.");
4085 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4091 vcodec = HB_VCODEC_FFMPEG;
4092 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
4098 ghb_validate_subtitles(signal_user_data_t *ud)
4104 if (h_scan == NULL) return FALSE;
4105 list = hb_get_titles( h_scan );
4106 if( !hb_list_count( list ) )
4108 /* No valid title, stop right there */
4109 g_message("No title found.\n");
4115 titleindex = ghb_settings_combo_int(ud->settings, "title");
4116 title = hb_list_item( list, titleindex );
4117 if (title == NULL) return FALSE;
4119 const GValue *slist, *settings;
4120 gint count, ii, source;
4121 gboolean burned, one_burned = FALSE;
4123 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
4124 count = ghb_array_len(slist);
4125 for (ii = 0; ii < count; ii++)
4127 settings = ghb_array_get_nth(slist, ii);
4128 source = ghb_settings_get_int(settings, "SubtitleSource");
4129 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
4130 if (burned && one_burned)
4132 // MP4 can only handle burned vobsubs. make sure there isn't
4133 // already something burned in the list
4134 message = g_strdup_printf(
4135 "Only one subtitle may be burned into the video.\n\n"
4136 "You should change your subtitle selections.\n"
4137 "If you continue, some subtitles will be lost.");
4138 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4150 if (source == SRTSUB)
4154 filename = ghb_settings_get_string(settings, "SrtFile");
4155 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4157 message = g_strdup_printf(
4158 "Srt file does not exist or not a regular file.\n\n"
4159 "You should choose a valid file.\n"
4160 "If you continue, this subtitle will be ignored.");
4161 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
4162 "Cancel", "Continue"))
4176 ghb_select_audio_codec(GValue *settings, gint acodec, gint track)
4180 hb_audio_config_t *audio;
4182 if (h_scan == NULL) return -1;
4183 list = hb_get_titles( h_scan );
4184 if( !hb_list_count( list ) )
4191 titleindex = ghb_settings_combo_int(settings, "title");
4192 title = hb_list_item( list, titleindex );
4193 if (title == NULL) return -1;
4195 gint mux = ghb_settings_combo_int(settings, "FileFormat");
4197 if (track < 0 || track >= hb_list_count(title->list_audio))
4200 audio = (hb_audio_config_t *) hb_list_audio_config_item(
4201 title->list_audio, track );
4203 if (mux == HB_MUX_MP4)
4205 if ((acodec & audio->in.codec & HB_ACODEC_AC3))
4207 return acodec & (audio->in.codec | HB_ACODEC_PASS_FLAG);
4209 else if (acodec & HB_ACODEC_AC3)
4211 return HB_ACODEC_AC3;
4213 else if (acodec & HB_ACODEC_FAAC)
4215 return HB_ACODEC_FAAC;
4219 return HB_ACODEC_FAAC;
4224 if ((acodec & audio->in.codec & HB_ACODEC_PASS_MASK))
4226 return acodec & (audio->in.codec | HB_ACODEC_PASS_FLAG);
4228 else if (acodec & HB_ACODEC_AC3)
4230 return HB_ACODEC_AC3;
4232 else if (acodec & HB_ACODEC_VORBIS)
4234 return HB_ACODEC_VORBIS;
4236 else if (acodec & HB_ACODEC_LAME)
4238 return HB_ACODEC_LAME;
4242 return HB_ACODEC_LAME;
4248 ghb_select_audio_codec_str(GValue *settings, gint icodec, gint track)
4252 acodec = ghb_select_audio_codec(settings, icodec, track);
4253 for (ii = 0; ii < acodec_opts.count; ii++)
4255 if (acodec_opts.map[ii].ivalue == acodec)
4256 return acodec_opts.map[ii].option;
4262 ghb_validate_audio(signal_user_data_t *ud)
4269 if (h_scan == NULL) return FALSE;
4270 list = hb_get_titles( h_scan );
4271 if( !hb_list_count( list ) )
4273 /* No valid title, stop right there */
4274 g_message("No title found.\n");
4280 titleindex = ghb_settings_combo_int(ud->settings, "title");
4281 title = hb_list_item( list, titleindex );
4282 if (title == NULL) return FALSE;
4283 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4285 const GValue *audio_list;
4288 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
4289 count = ghb_array_len(audio_list);
4290 for (ii = 0; ii < count; ii++)
4293 hb_audio_config_t *taudio;
4295 asettings = ghb_array_get_nth(audio_list, ii);
4296 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4297 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4298 if (codec == HB_ACODEC_ANY)
4301 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4302 title->list_audio, track );
4303 if ( ghb_audio_is_passthru(codec) &&
4304 !(ghb_audio_can_passthru(taudio->in.codec) &&
4305 (taudio->in.codec & codec)))
4307 // Not supported. AC3 is passthrough only, so input must be AC3
4308 message = g_strdup_printf(
4309 "The source does not support Pass-Thru.\n\n"
4310 "You should choose a different audio codec.\n"
4311 "If you continue, one will be chosen for you.");
4312 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4318 if ((codec & HB_ACODEC_AC3) ||
4319 taudio->in.codec == HB_ACODEC_DCA)
4321 codec = HB_ACODEC_AC3;
4323 else if (mux == HB_MUX_MKV)
4325 codec = HB_ACODEC_LAME;
4329 codec = HB_ACODEC_FAAC;
4331 value = ghb_lookup_acodec_value(codec);
4332 ghb_settings_take_value(asettings, "AudioEncoder", value);
4334 gchar *a_unsup = NULL;
4335 gchar *mux_s = NULL;
4336 if (mux == HB_MUX_MP4)
4339 // mp4/vorbis|DTS combination is not supported.
4340 if (codec == HB_ACODEC_VORBIS)
4343 codec = HB_ACODEC_FAAC;
4345 if (codec == HB_ACODEC_DCA)
4348 codec = HB_ACODEC_AC3;
4353 message = g_strdup_printf(
4354 "%s is not supported in the %s container.\n\n"
4355 "You should choose a different audio codec.\n"
4356 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4357 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4363 value = ghb_lookup_acodec_value(codec);
4364 ghb_settings_take_value(asettings, "AudioEncoder", value);
4366 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4367 gboolean allow_mono = TRUE;
4368 gboolean allow_stereo = TRUE;
4369 gboolean allow_dolby = TRUE;
4370 gboolean allow_dpl2 = TRUE;
4371 gboolean allow_6ch = TRUE;
4373 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4375 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4377 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4378 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4379 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4380 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4382 (codec & ~HB_ACODEC_LAME) &&
4383 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4384 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4386 gchar *mix_unsup = NULL;
4387 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4391 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4393 mix_unsup = "stereo";
4395 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4397 mix_unsup = "Dolby";
4399 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4401 mix_unsup = "Dolby Pro Logic II";
4403 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4405 mix_unsup = "6 Channel";
4409 message = g_strdup_printf(
4410 "The source audio does not support %s mixdown.\n\n"
4411 "You should choose a different mixdown.\n"
4412 "If you continue, one will be chosen for you.", mix_unsup);
4413 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4419 mix = ghb_get_best_mix(titleindex, track, codec, mix);
4420 value = get_amix_value(mix);
4421 ghb_settings_take_value(asettings, "AudioMixdown", value);
4428 ghb_validate_vquality(GValue *settings)
4434 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4435 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4437 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4438 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4442 case HB_VCODEC_X264:
4448 case HB_VCODEC_FFMPEG:
4454 case HB_VCODEC_THEORA:
4466 if (vquality < min || vquality > max)
4468 message = g_strdup_printf(
4469 "Interesting video quality choise: %d\n\n"
4470 "Typical values range from %d to %d.\n"
4471 "Are you sure you wish to use this setting?",
4472 (gint)vquality, min, max);
4473 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4474 "Cancel", "Continue"))
4486 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4491 static gchar *x264opts;
4493 gboolean tweaks = FALSE;
4494 gchar *detel_str = NULL;
4495 gchar *decomb_str = NULL;
4496 gchar *deint_str = NULL;
4497 gchar *deblock_str = NULL;
4498 gchar *denoise_str = NULL;
4499 gchar *dest_str = NULL;
4501 g_debug("add_job()\n");
4502 if (h == NULL) return;
4503 list = hb_get_titles( h );
4504 if( !hb_list_count( list ) )
4506 /* No valid title, stop right there */
4510 title = hb_list_item( list, titleindex );
4511 if (title == NULL) return;
4513 /* Set job settings */
4515 if (job == NULL) return;
4517 job->angle = ghb_settings_get_int(js, "angle");
4518 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4519 if (job->start_at_preview)
4521 job->seek_points = ghb_settings_get_int(js, "preview_count");
4522 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4525 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4526 job->mux = ghb_settings_combo_int(js, "FileFormat");
4527 if (job->mux == HB_MUX_MP4)
4529 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4530 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4534 job->largeFileSize = FALSE;
4535 job->mp4_optimize = FALSE;
4537 if (!job->start_at_preview)
4540 gint num_chapters = hb_list_count(title->list_chapter);
4541 gint duration = title->duration / 90000;
4542 job->chapter_start = 1;
4543 job->chapter_end = num_chapters;
4545 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4547 start = ghb_settings_get_int(js, "start_point");
4548 end = ghb_settings_get_int(js, "end_point");
4549 job->chapter_start = MIN( num_chapters, start );
4550 job->chapter_end = MAX( job->chapter_start, end );
4553 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4555 job->chapter_start = 1;
4556 job->chapter_end = num_chapters;
4557 start = ghb_settings_get_int(js, "start_point");
4558 end = ghb_settings_get_int(js, "end_point");
4559 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4560 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4563 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4565 job->chapter_start = 1;
4566 job->chapter_end = num_chapters;
4567 start = ghb_settings_get_int(js, "start_point");
4568 end = ghb_settings_get_int(js, "end_point");
4570 max_frames = (gint64)duration * title->rate / title->rate_base;
4571 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4572 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4573 job->frame_to_start;
4575 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4576 if (job->chapter_start == job->chapter_end)
4577 job->chapter_markers = 0;
4578 if ( job->chapter_markers )
4585 chapters = ghb_settings_get_value(js, "chapter_list");
4586 count = ghb_array_len(chapters);
4587 for(chap = 0; chap < count; chap++)
4589 hb_chapter_t * chapter_s;
4593 chapter = ghb_array_get_nth(chapters, chap);
4594 name = ghb_value_string(chapter);
4597 name = g_strdup_printf ("Chapter %2d", chap+1);
4599 chapter_s = hb_list_item( job->title->list_chapter, chap);
4600 strncpy(chapter_s->title, name, 1023);
4601 chapter_s->title[1023] = '\0';
4606 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4607 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4608 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4609 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4612 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4613 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4614 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4616 job->deinterlace = (deint != 0) ? 1 : 0;
4618 job->deinterlace = 0;
4619 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4621 gboolean keep_aspect;
4622 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4623 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4624 job->modulus = ghb_settings_combo_int(js, "PictureModulus");
4625 if (job->anamorphic.mode)
4627 job->anamorphic.par_width = title->pixel_aspect_width;
4628 job->anamorphic.par_height = title->pixel_aspect_height;
4629 job->anamorphic.dar_width = 0;
4630 job->anamorphic.dar_height = 0;
4632 if (job->anamorphic.mode == 3 && !keep_aspect)
4634 job->anamorphic.keep_display_aspect = 0;
4635 job->anamorphic.par_width =
4636 ghb_settings_get_int(js, "PicturePARWidth");
4637 job->anamorphic.par_height =
4638 ghb_settings_get_int(js, "PicturePARHeight");
4642 job->anamorphic.keep_display_aspect = 1;
4646 /* Add selected filters */
4647 job->filters = hb_list_init();
4648 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4653 if (detel_opts.map[detel].svalue != NULL)
4654 detel_str = g_strdup(detel_opts.map[detel].svalue);
4657 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4658 hb_filter_detelecine.settings = detel_str;
4659 hb_list_add( job->filters, &hb_filter_detelecine );
4661 if ( decomb_deint && decomb )
4665 if (decomb_opts.map[decomb].svalue != NULL)
4666 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4669 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4670 hb_filter_decomb.settings = decomb_str;
4671 hb_list_add( job->filters, &hb_filter_decomb );
4673 if( job->deinterlace )
4677 if (deint_opts.map[deint].svalue != NULL)
4678 deint_str = g_strdup(deint_opts.map[deint].svalue);
4681 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4682 hb_filter_deinterlace.settings = deint_str;
4683 hb_list_add( job->filters, &hb_filter_deinterlace );
4685 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4688 deblock_str = g_strdup_printf("%d", deblock);
4689 hb_filter_deblock.settings = deblock_str;
4690 hb_list_add( job->filters, &hb_filter_deblock );
4692 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4697 if (denoise_opts.map[denoise].svalue != NULL)
4698 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4701 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4702 hb_filter_denoise.settings = denoise_str;
4703 hb_list_add( job->filters, &hb_filter_denoise );
4705 job->width = ghb_settings_get_int(js, "scale_width");
4706 job->height = ghb_settings_get_int(js, "scale_height");
4708 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4709 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4711 // mp4/theora combination is not supported.
4712 job->vcodec = HB_VCODEC_FFMPEG;
4714 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4716 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4718 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4721 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4722 job->vquality = vquality;
4725 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4727 job->vquality = -1.0;
4728 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4731 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4734 job->vrate = title->rate;
4735 job->vrate_base = title->rate_base;
4740 job->vrate = 27000000;
4741 job->vrate_base = vrate;
4742 gboolean pfr = ghb_settings_get_boolean(js, "VideoFrameratePFR");
4749 const GValue *audio_list;
4753 audio_list = ghb_settings_get_value(js, "audio_list");
4754 count = ghb_array_len(audio_list);
4755 for (ii = 0; ii < count; ii++)
4758 hb_audio_config_t audio;
4759 hb_audio_config_t *taudio;
4762 hb_audio_config_init(&audio);
4763 asettings = ghb_array_get_nth(audio_list, ii);
4764 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4765 audio.out.track = tcount;
4766 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
4767 audio.out.codec = ghb_select_audio_codec(js, acodec, audio.in.track);
4769 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4770 title->list_audio, audio.in.track );
4771 audio.out.dynamic_range_compression =
4772 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4773 if (audio.out.dynamic_range_compression < 1.0)
4774 audio.out.dynamic_range_compression = 0.0;
4776 // It would be better if this were done in libhb for us, but its not yet.
4777 if (ghb_audio_is_passthru(audio.out.codec))
4779 audio.out.mixdown = 0;
4785 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4786 if (audio.out.mixdown == HB_AMIXDOWN_MONO)
4788 else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
4793 // Make sure the mixdown is valid and pick a new one if not.
4794 audio.out.mixdown = ghb_get_best_mix(titleindex,
4795 audio.in.track, audio.out.codec, audio.out.mixdown);
4797 ghb_settings_combo_int(asettings, "AudioBitrate");
4798 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4799 if (srate == 0) // 0 is same as source
4800 audio.out.samplerate = taudio->in.samplerate;
4802 audio.out.samplerate = srate;
4804 audio.out.bitrate = ghb_get_best_audio_bitrate(
4805 audio.out.codec, audio.out.bitrate, channels);
4808 // Add it to the jobs audio list
4809 hb_audio_add( job, &audio );
4812 // I was tempted to move this up with the reset of the video quality
4813 // settings, but I suspect the settings above need to be made
4814 // first in order for hb_calc_bitrate to be accurate.
4815 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4819 size = ghb_settings_get_int(js, "VideoTargetSize");
4820 job->vbitrate = hb_calc_bitrate( job, size );
4821 job->vquality = -1.0;
4824 dest_str = ghb_settings_get_string(js, "destination");
4825 job->file = dest_str;
4827 const GValue *subtitle_list;
4829 gboolean force, burned, def, one_burned = FALSE;
4831 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4832 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4833 count = ghb_array_len(subtitle_list);
4834 for (ii = 0; ii < count; ii++)
4839 ssettings = ghb_array_get_nth(subtitle_list, ii);
4841 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4842 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4843 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4844 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4846 if (source == SRTSUB)
4848 hb_subtitle_config_t sub_config;
4849 gchar *filename, *lang, *code;
4851 filename = ghb_settings_get_string(ssettings, "SrtFile");
4852 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4856 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4857 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4858 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4859 strncpy(sub_config.src_filename, filename, 128);
4860 strncpy(sub_config.src_codeset, code, 40);
4861 sub_config.force = 0;
4862 sub_config.dest = PASSTHRUSUB;
4863 sub_config.default_track = def;
4865 hb_srt_add( job, &sub_config, lang);
4873 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4878 job->select_subtitle_config.dest = PASSTHRUSUB;
4882 // Only allow one subtitle to be burned into the video
4885 job->select_subtitle_config.dest = RENDERSUB;
4888 job->select_subtitle_config.force = force;
4889 job->select_subtitle_config.default_track = def;
4890 job->indepth_scan = 1;
4891 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4893 else if (subtitle >= 0)
4895 hb_subtitle_t * subt;
4896 hb_subtitle_config_t sub_config;
4898 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4901 sub_config = subt->config;
4904 sub_config.dest = PASSTHRUSUB;
4906 else if ( burned && canBurn(subt->source) )
4908 // Only allow one subtitle to be burned into the video
4911 sub_config.dest = RENDERSUB;
4914 sub_config.force = force;
4915 sub_config.default_track = def;
4916 hb_subtitle_add( job, &sub_config, subtitle );
4921 // TODO: libhb holds onto a reference to the x264opts and is not
4922 // finished with it until encoding the job is done. But I can't
4923 // find a way to get at the job before it is removed in order to
4924 // free up the memory I am allocating here.
4925 // The short story is THIS LEAKS.
4926 x264opts = ghb_build_x264opts_string(js);
4928 if( *x264opts == '\0' )
4934 if (job->indepth_scan == 1)
4936 // Subtitle scan. Look for subtitle matching audio language
4939 * When subtitle scan is enabled do a fast pre-scan job
4940 * which will determine which subtitles to enable, if any.
4943 job->indepth_scan = 1;
4944 job->x264opts = NULL;
4947 * Add the pre-scan job
4949 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4953 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4954 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4957 * If subtitle_scan is enabled then only turn it on
4958 * for the second pass and then off again for the
4962 job->indepth_scan = 0;
4965 * If turbo options have been selected then append them
4966 * to the x264opts now (size includes one ':' and the '\0')
4968 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4970 gchar *tmp_x264opts;
4974 badapt = ghb_lookup_badapt(x264opts);
4977 extra_opts = g_strdup_printf("%s", turbo_opts);
4981 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4986 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4991 * No x264opts to modify, but apply the turbo options
4992 * anyway as they may be modifying defaults
4994 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4998 job->x264opts = tmp_x264opts;
5002 job->x264opts = x264opts;
5004 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
5006 //if (job->x264opts != NULL)
5007 // g_free(job->x264opts);
5011 * On the second pass we turn off subtitle scan so that we
5012 * can actually encode using any subtitles that were auto
5013 * selected in the first pass (using the whacky select-subtitle
5014 * attribute of the job).
5016 job->indepth_scan = 0;
5017 job->x264opts = x264opts;
5018 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
5020 //if (job->x264opts != NULL)
5021 // g_free(job->x264opts);
5025 job->x264opts = x264opts;
5026 job->indepth_scan = 0;
5028 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
5030 //if (job->x264opts != NULL)
5031 // g_free(job->x264opts);
5034 // clean up audio list
5035 gint num_audio_tracks = hb_list_count(job->list_audio);
5036 for(ii = 0; ii < num_audio_tracks; ii++)
5038 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
5039 hb_list_rem(job->list_audio, audio);
5043 // clean up subtitle list
5044 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
5045 for(ii = 0; ii < num_subtitle_tracks; ii++)
5047 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
5048 hb_list_rem(job->list_subtitle, subtitle);
5052 if (detel_str) g_free(detel_str);
5053 if (decomb_str) g_free(decomb_str);
5054 if (deint_str) g_free(deint_str);
5055 if (deblock_str) g_free(deblock_str);
5056 if (denoise_str) g_free(denoise_str);
5057 if (dest_str) g_free(dest_str);
5061 ghb_add_job(GValue *js, gint unique_id)
5063 // Since I'm doing a scan of the single title I want just prior
5064 // to adding the job, there is only the one title to choose from.
5065 add_job(h_queue, js, unique_id, 0);
5069 ghb_add_live_job(GValue *js, gint unique_id)
5071 // Since I'm doing a scan of the single title I want just prior
5072 // to adding the job, there is only the one title to choose from.
5073 gint titleindex = ghb_settings_combo_int(js, "title");
5074 add_job(h_scan, js, unique_id, titleindex);
5078 ghb_remove_job(gint unique_id)
5083 // Multiples passes all get the same id
5085 // Go backwards through list, so reordering doesn't screw me.
5086 ii = hb_count(h_queue) - 1;
5087 while ((job = hb_job(h_queue, ii--)) != NULL)
5089 if ((job->sequence_id & 0xFFFFFF) == unique_id)
5090 hb_rem(h_queue, job);
5097 hb_start( h_queue );
5107 ghb_start_live_encode()
5113 ghb_stop_live_encode()
5122 hb_get_state2( h_queue, &s );
5124 if( s.state == HB_STATE_PAUSED )
5126 hb_status.queue.state &= ~GHB_STATE_PAUSED;
5127 hb_resume( h_queue );
5131 hb_status.queue.state |= GHB_STATE_PAUSED;
5132 hb_pause( h_queue );
5147 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5150 gint channels = gdk_pixbuf_get_n_channels (pb);
5151 gint stride = gdk_pixbuf_get_rowstride (pb);
5153 for (jj = 0; jj < width; jj++)
5155 dst = pixels + y * stride + (x+jj) * channels;
5156 for (ii = 0; ii < len; ii++)
5177 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5180 gint channels = gdk_pixbuf_get_n_channels (pb);
5181 gint stride = gdk_pixbuf_get_rowstride (pb);
5183 for (jj = 0; jj < width; jj++)
5185 dst = pixels + (y+jj) * stride + x * channels;
5186 for (ii = 0; ii < len; ii++)
5207 gint line_width = 8;
5214 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
5219 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
5221 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
5227 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
5229 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
5235 ghb_get_preview_image(
5238 signal_user_data_t *ud,
5246 settings = ud->settings;
5247 list = hb_get_titles( h_scan );
5248 if( !hb_list_count( list ) )
5250 /* No valid title, stop right there */
5253 title = hb_list_item( list, titleindex );
5254 if (title == NULL) return NULL;
5255 if (title->job == NULL) return NULL;
5256 set_preview_job_settings(title->job, settings);
5258 // hb_get_preview doesn't compensate for anamorphic, so lets
5259 // calculate scale factors
5260 gint width, height, par_width = 1, par_height = 1;
5261 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5264 hb_set_anamorphic_size( title->job, &width, &height,
5265 &par_width, &par_height );
5268 // Make sure we have a big enough buffer to receive the image from libhb
5269 gint dstWidth = title->job->width;
5270 gint dstHeight= title->job->height;
5272 static guint8 *buffer = NULL;
5273 static gint bufferSize = 0;
5276 newSize = dstWidth * dstHeight * 4;
5277 if( bufferSize < newSize )
5279 bufferSize = newSize;
5280 buffer = (guint8*) g_realloc( buffer, bufferSize );
5282 hb_get_preview( h_scan, title, index, buffer );
5284 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5285 // libhb's format something suitable.
5287 // The image data returned by hb_get_preview is 4 bytes per pixel,
5288 // BGRA format. Alpha is ignored.
5290 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5291 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5293 guint32 *src = (guint32*)buffer;
5294 guint8 *dst = pixels;
5297 gint channels = gdk_pixbuf_get_n_channels (preview);
5298 gint stride = gdk_pixbuf_get_rowstride (preview);
5301 for (ii = 0; ii < dstHeight; ii++)
5304 for (jj = 0; jj < dstWidth; jj++)
5306 tmp[0] = src[0] >> 16;
5307 tmp[1] = src[0] >> 8;
5308 tmp[2] = src[0] >> 0;
5314 gint w = ghb_settings_get_int(settings, "scale_width");
5315 gint h = ghb_settings_get_int(settings, "scale_height");
5316 ghb_par_scale(ud, &w, &h, par_width, par_height);
5318 gint c0, c1, c2, c3;
5319 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5320 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5321 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5322 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5324 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5325 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5327 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5330 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5334 gint orig_w, orig_h;
5337 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5341 ss = gdk_screen_get_default();
5342 s_w = gdk_screen_get_width(ss);
5343 s_h = gdk_screen_get_height(ss);
5347 if (dstWidth > s_w * factor / 100)
5349 dstWidth = s_w * factor / 100;
5350 dstHeight = dstHeight * dstWidth / orig_w;
5352 if (dstHeight > s_h * factor / 100)
5354 dstHeight = s_h * factor / 100;
5355 dstWidth = dstWidth * dstHeight / orig_h;
5357 xscale *= (gdouble)dstWidth / orig_w;
5358 yscale *= (gdouble)dstHeight / orig_h;
5359 w *= (gdouble)dstWidth / orig_w;
5360 h *= (gdouble)dstHeight / orig_h;
5362 GdkPixbuf *scaled_preview;
5363 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5364 if (ghb_settings_get_boolean(settings, "show_crop"))
5371 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5373 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5375 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5377 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5379 g_object_unref (preview);
5380 return scaled_preview;
5384 sanitize_volname(gchar *name)
5409 ghb_dvd_volname(const gchar *device)
5412 name = hb_dvd_name((gchar*)device);
5413 if (name != NULL && name[0] != 0)
5415 name = g_strdup(name);
5416 sanitize_volname(name);