1 /***************************************************************************
4 * Fri Mar 28 10:38:44 2008
5 * Copyright 2008 John Stebbins
6 * <john at stebbins dot name>
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
29 #include <glib/gstdio.h>
30 #include "hb-backend.h"
32 #include "callbacks.h"
33 #include "subtitlehandler.h"
34 #include "audiohandler.h"
35 #include "x264handler.h"
43 const gchar *shortOpt;
54 static gchar **index_str = NULL;
55 static gint index_str_size = 0;
58 index_str_init(gint max_index)
62 if (max_index+1 > index_str_size)
64 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
65 for (ii = index_str_size; ii <= max_index; ii++)
67 index_str[ii] = g_strdup_printf("%d", ii);
69 index_str_size = max_index + 1;
73 static options_map_t d_point_to_point_opts[] =
75 {"Chapters:", "chapter", 0, "0"},
76 {"Seconds:", "time", 1, "1"},
77 {"Frames:", "frame", 2, "2"},
79 combo_opts_t point_to_point_opts =
81 sizeof(d_point_to_point_opts)/sizeof(options_map_t),
85 static options_map_t d_when_complete_opts[] =
87 {"Do Nothing", "nothing", 0, "0"},
88 {"Show Notification", "notify", 1, "1"},
89 {"Put Computer To Sleep", "sleep", 2, "2"},
90 {"Shutdown Computer", "shutdown", 3, "3"},
92 combo_opts_t when_complete_opts =
94 sizeof(d_when_complete_opts)/sizeof(options_map_t),
98 static options_map_t d_par_opts[] =
100 {"Off", "0", 0, "0"},
101 {"Strict", "1", 1, "1"},
102 {"Loose", "2", 2, "2"},
103 {"Custom", "3", 3, "3"},
105 combo_opts_t par_opts =
107 sizeof(d_par_opts)/sizeof(options_map_t),
111 static options_map_t d_alignment_opts[] =
116 {"16", "16", 16, "16"},
118 combo_opts_t alignment_opts =
120 sizeof(d_alignment_opts)/sizeof(options_map_t),
124 static options_map_t d_logging_opts[] =
130 combo_opts_t logging_opts =
132 sizeof(d_logging_opts)/sizeof(options_map_t),
136 static options_map_t d_log_longevity_opts[] =
138 {"Week", "week", 7, "7"},
139 {"Month", "month", 30, "30"},
140 {"Year", "year", 365, "365"},
141 {"Immortal", "immortal", 366, "366"},
143 combo_opts_t log_longevity_opts =
145 sizeof(d_log_longevity_opts)/sizeof(options_map_t),
149 static options_map_t d_appcast_update_opts[] =
151 {"Never", "never", 0, "never"},
152 {"Daily", "daily", 1, "daily"},
153 {"Weekly", "weekly", 2, "weekly"},
154 {"Monthly", "monthly", 3, "monthly"},
156 combo_opts_t appcast_update_opts =
158 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
159 d_appcast_update_opts
162 static options_map_t d_vqual_granularity_opts[] =
164 {"0.2", "0.2", 0.2, "0.2"},
165 {"0.25", "0.25", 0.25, "0.25"},
166 {"0.5", "0.5", 0.5, "0.5"},
169 combo_opts_t vqual_granularity_opts =
171 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
172 d_vqual_granularity_opts
175 static options_map_t d_container_opts[] =
177 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
178 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
180 combo_opts_t container_opts =
182 sizeof(d_container_opts)/sizeof(options_map_t),
186 static options_map_t d_detel_opts[] =
188 {"Off", "off", 0, ""},
189 {"Custom", "custom", 1, ""},
190 {"Default","default",2, NULL},
192 combo_opts_t detel_opts =
194 sizeof(d_detel_opts)/sizeof(options_map_t),
198 static options_map_t d_decomb_opts[] =
200 {"Off", "off", 0, ""},
201 {"Custom", "custom", 1, ""},
202 {"Default","default",2, NULL},
204 combo_opts_t decomb_opts =
206 sizeof(d_decomb_opts)/sizeof(options_map_t),
210 static options_map_t d_deint_opts[] =
212 {"Off", "off", 0, ""},
213 {"Custom", "custom", 1, ""},
214 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
215 {"Slow", "slow", 3, "2:-1:-1:0:1"},
216 {"Slower", "slower", 4, "0:-1:-1:0:1"},
218 combo_opts_t deint_opts =
220 sizeof(d_deint_opts)/sizeof(options_map_t),
224 static options_map_t d_denoise_opts[] =
226 {"Off", "off", 0, ""},
227 {"Custom", "custom", 1, ""},
228 {"Weak", "weak", 2, "2:1:2:3"},
229 {"Medium", "medium", 3, "3:2:2:3"},
230 {"Strong", "strong", 4, "7:7:5:5"},
232 combo_opts_t denoise_opts =
234 sizeof(d_denoise_opts)/sizeof(options_map_t),
238 static options_map_t d_vcodec_opts[] =
240 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
241 {"MPEG-4 (FFmpeg)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
242 {"VP3 (Theora)", "theora", HB_VCODEC_THEORA, ""},
244 combo_opts_t vcodec_opts =
246 sizeof(d_vcodec_opts)/sizeof(options_map_t),
250 static options_map_t d_acodec_opts[] =
252 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
253 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
254 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
255 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, "ac3"},
256 {"DTS (pass-thru)", "dts", HB_ACODEC_DCA, "dts"},
257 {"Choose For Me", "auto", HB_ACODEC_MASK, "auto"},
259 combo_opts_t acodec_opts =
261 sizeof(d_acodec_opts)/sizeof(options_map_t),
265 static options_map_t d_direct_opts[] =
267 {"None", "none", 0, "none"},
268 {"Spatial", "spatial", 1, "spatial"},
269 {"Temporal", "temporal", 2, "temporal"},
270 {"Automatic", "auto", 3, "auto"},
272 combo_opts_t direct_opts =
274 sizeof(d_direct_opts)/sizeof(options_map_t),
278 static options_map_t d_badapt_opts[] =
280 {"Off", "0", 0, "0"},
281 {"Fast", "1", 1, "1"},
282 {"Optimal", "2", 2, "2"},
284 combo_opts_t badapt_opts =
286 sizeof(d_badapt_opts)/sizeof(options_map_t),
290 static options_map_t d_bpyramid_opts[] =
292 {"Off", "none", 0, "none"},
293 {"Strict", "strict", 1, "strict"},
294 {"Normal", "normal", 2, "normal"},
296 combo_opts_t bpyramid_opts =
298 sizeof(d_bpyramid_opts)/sizeof(options_map_t),
302 static options_map_t d_weightp_opts[] =
304 {"Off", "0", 0, "0"},
305 {"Blind", "1", 1, "1"},
306 {"Smart", "2", 2, "2"},
308 combo_opts_t weightp_opts =
310 sizeof(d_weightp_opts)/sizeof(options_map_t),
314 static options_map_t d_me_opts[] =
316 {"Diamond", "dia", 0, "dia"},
317 {"Hexagon", "hex", 1, "hex"},
318 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
319 {"Exhaustive", "esa", 3, "esa"},
320 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
322 combo_opts_t me_opts =
324 sizeof(d_me_opts)/sizeof(options_map_t),
328 static options_map_t d_subme_opts[] =
330 {"0: SAD, no subpel", "0", 0, "0"},
331 {"1: SAD, qpel", "1", 1, "1"},
332 {"2: SATD, qpel", "2", 2, "2"},
333 {"3: SATD: multi-qpel", "3", 3, "3"},
334 {"4: SATD, qpel on all", "4", 4, "4"},
335 {"5: SATD, multi-qpel on all", "5", 5, "5"},
336 {"6: RD in I/P-frames", "6", 6, "6"},
337 {"7: RD in all frames", "7", 7, "7"},
338 {"8: RD refine in I/P-frames", "8", 8, "8"},
339 {"9: RD refine in all frames", "9", 9, "9"},
340 {"10: QPRD in all frames", "10", 10, "10"},
342 combo_opts_t subme_opts =
344 sizeof(d_subme_opts)/sizeof(options_map_t),
348 static options_map_t d_analyse_opts[] =
350 {"Most", "p8x8,b8x8,i8x8,i4x4", 0, "p8x8,b8x8,i8x8,i4x4"},
351 {"None", "none", 1, "none"},
352 {"Some", "i4x4,i8x8", 2, "i4x4,i8x8"},
353 {"All", "all", 3, "all"},
354 {"Custom", "custom", 4, "all"},
356 combo_opts_t analyse_opts =
358 sizeof(d_analyse_opts)/sizeof(options_map_t),
362 static options_map_t d_trellis_opts[] =
364 {"Off", "0", 0, "0"},
365 {"Encode only", "1", 1, "1"},
366 {"Always", "2", 2, "2"},
368 combo_opts_t trellis_opts =
370 sizeof(d_trellis_opts)/sizeof(options_map_t),
374 combo_opts_t subtitle_opts =
380 combo_opts_t title_opts =
386 combo_opts_t audio_track_opts =
398 combo_name_map_t combo_name_map[] =
400 {"PtoPType", &point_to_point_opts},
401 {"WhenComplete", &when_complete_opts},
402 {"PicturePAR", &par_opts},
403 {"PictureModulus", &alignment_opts},
404 {"LoggingLevel", &logging_opts},
405 {"LogLongevity", &log_longevity_opts},
406 {"check_updates", &appcast_update_opts},
407 {"VideoQualityGranularity", &vqual_granularity_opts},
408 {"FileFormat", &container_opts},
409 {"PictureDeinterlace", &deint_opts},
410 {"PictureDecomb", &decomb_opts},
411 {"PictureDetelecine", &detel_opts},
412 {"PictureDenoise", &denoise_opts},
413 {"VideoEncoder", &vcodec_opts},
414 {"AudioEncoder", &acodec_opts},
415 {"x264_direct", &direct_opts},
416 {"x264_b_adapt", &badapt_opts},
417 {"x264_bpyramid", &bpyramid_opts},
418 {"x264_weighted_pframes", &weightp_opts},
419 {"x264_me", &me_opts},
420 {"x264_subme", &subme_opts},
421 {"x264_analyse", &analyse_opts},
422 {"x264_trellis", &trellis_opts},
423 {"SubtitleTrack", &subtitle_opts},
424 {"title", &title_opts},
425 {"AudioTrack", &audio_track_opts},
429 const gchar *srt_codeset_table[] =
468 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
471 typedef struct iso639_lang_t
473 char * eng_name; /* Description in English */
474 char * native_name; /* Description in native language */
475 char * iso639_1; /* ISO-639-1 (2 characters) code */
476 char * iso639_2; /* ISO-639-2/t (3 character) code */
477 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
481 const iso639_lang_t ghb_language_table[] =
483 { "Any", "", "zz", "und" },
484 { "Afar", "", "aa", "aar" },
485 { "Abkhazian", "", "ab", "abk" },
486 { "Afrikaans", "", "af", "afr" },
487 { "Akan", "", "ak", "aka" },
488 { "Albanian", "", "sq", "sqi", "alb" },
489 { "Amharic", "", "am", "amh" },
490 { "Arabic", "", "ar", "ara" },
491 { "Aragonese", "", "an", "arg" },
492 { "Armenian", "", "hy", "hye", "arm" },
493 { "Assamese", "", "as", "asm" },
494 { "Avaric", "", "av", "ava" },
495 { "Avestan", "", "ae", "ave" },
496 { "Aymara", "", "ay", "aym" },
497 { "Azerbaijani", "", "az", "aze" },
498 { "Bashkir", "", "ba", "bak" },
499 { "Bambara", "", "bm", "bam" },
500 { "Basque", "", "eu", "eus", "baq" },
501 { "Belarusian", "", "be", "bel" },
502 { "Bengali", "", "bn", "ben" },
503 { "Bihari", "", "bh", "bih" },
504 { "Bislama", "", "bi", "bis" },
505 { "Bosnian", "", "bs", "bos" },
506 { "Breton", "", "br", "bre" },
507 { "Bulgarian", "", "bg", "bul" },
508 { "Burmese", "", "my", "mya", "bur" },
509 { "Catalan", "", "ca", "cat" },
510 { "Chamorro", "", "ch", "cha" },
511 { "Chechen", "", "ce", "che" },
512 { "Chinese", "", "zh", "zho", "chi" },
513 { "Church Slavic", "", "cu", "chu" },
514 { "Chuvash", "", "cv", "chv" },
515 { "Cornish", "", "kw", "cor" },
516 { "Corsican", "", "co", "cos" },
517 { "Cree", "", "cr", "cre" },
518 { "Czech", "", "cs", "ces", "cze" },
519 { "Danish", "Dansk", "da", "dan" },
520 { "German", "Deutsch", "de", "deu", "ger" },
521 { "Divehi", "", "dv", "div" },
522 { "Dzongkha", "", "dz", "dzo" },
523 { "English", "English", "en", "eng" },
524 { "Spanish", "Espanol", "es", "spa" },
525 { "Esperanto", "", "eo", "epo" },
526 { "Estonian", "", "et", "est" },
527 { "Ewe", "", "ee", "ewe" },
528 { "Faroese", "", "fo", "fao" },
529 { "Fijian", "", "fj", "fij" },
530 { "French", "Francais", "fr", "fra", "fre" },
531 { "Western Frisian", "", "fy", "fry" },
532 { "Fulah", "", "ff", "ful" },
533 { "Georgian", "", "ka", "kat", "geo" },
534 { "Gaelic (Scots)", "", "gd", "gla" },
535 { "Irish", "", "ga", "gle" },
536 { "Galician", "", "gl", "glg" },
537 { "Manx", "", "gv", "glv" },
538 { "Greek, Modern", "", "el", "ell", "gre" },
539 { "Guarani", "", "gn", "grn" },
540 { "Gujarati", "", "gu", "guj" },
541 { "Haitian", "", "ht", "hat" },
542 { "Hausa", "", "ha", "hau" },
543 { "Hebrew", "", "he", "heb" },
544 { "Herero", "", "hz", "her" },
545 { "Hindi", "", "hi", "hin" },
546 { "Hiri Motu", "", "ho", "hmo" },
547 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
548 { "Igbo", "", "ig", "ibo" },
549 { "Ido", "", "io", "ido" },
550 { "Icelandic", "Islenska", "is", "isl", "ice" },
551 { "Sichuan Yi", "", "ii", "iii" },
552 { "Inuktitut", "", "iu", "iku" },
553 { "Interlingue", "", "ie", "ile" },
554 { "Interlingua", "", "ia", "ina" },
555 { "Indonesian", "", "id", "ind" },
556 { "Inupiaq", "", "ik", "ipk" },
557 { "Italian", "Italiano", "it", "ita" },
558 { "Javanese", "", "jv", "jav" },
559 { "Japanese", "", "ja", "jpn" },
560 { "Kalaallisut", "", "kl", "kal" },
561 { "Kannada", "", "kn", "kan" },
562 { "Kashmiri", "", "ks", "kas" },
563 { "Kanuri", "", "kr", "kau" },
564 { "Kazakh", "", "kk", "kaz" },
565 { "Central Khmer", "", "km", "khm" },
566 { "Kikuyu", "", "ki", "kik" },
567 { "Kinyarwanda", "", "rw", "kin" },
568 { "Kirghiz", "", "ky", "kir" },
569 { "Komi", "", "kv", "kom" },
570 { "Kongo", "", "kg", "kon" },
571 { "Korean", "", "ko", "kor" },
572 { "Kuanyama", "", "kj", "kua" },
573 { "Kurdish", "", "ku", "kur" },
574 { "Lao", "", "lo", "lao" },
575 { "Latin", "", "la", "lat" },
576 { "Latvian", "", "lv", "lav" },
577 { "Limburgan", "", "li", "lim" },
578 { "Lingala", "", "ln", "lin" },
579 { "Lithuanian", "", "lt", "lit" },
580 { "Luxembourgish", "", "lb", "ltz" },
581 { "Luba-Katanga", "", "lu", "lub" },
582 { "Ganda", "", "lg", "lug" },
583 { "Macedonian", "", "mk", "mkd", "mac" },
584 { "Hungarian", "Magyar", "hu", "hun" },
585 { "Marshallese", "", "mh", "mah" },
586 { "Malayalam", "", "ml", "mal" },
587 { "Maori", "", "mi", "mri", "mao" },
588 { "Marathi", "", "mr", "mar" },
589 { "Malay", "", "ms", "msa", "msa" },
590 { "Malagasy", "", "mg", "mlg" },
591 { "Maltese", "", "mt", "mlt" },
592 { "Moldavian", "", "mo", "mol" },
593 { "Mongolian", "", "mn", "mon" },
594 { "Nauru", "", "na", "nau" },
595 { "Navajo", "", "nv", "nav" },
596 { "Dutch", "Nederlands", "nl", "nld", "dut" },
597 { "Ndebele, South", "", "nr", "nbl" },
598 { "Ndebele, North", "", "nd", "nde" },
599 { "Ndonga", "", "ng", "ndo" },
600 { "Nepali", "", "ne", "nep" },
601 { "Norwegian", "Norsk", "no", "nor" },
602 { "Norwegian Nynorsk", "", "nn", "nno" },
603 { "Norwegian Bokmål", "", "nb", "nob" },
604 { "Chichewa; Nyanja", "", "ny", "nya" },
605 { "Occitan", "", "oc", "oci" },
606 { "Ojibwa", "", "oj", "oji" },
607 { "Oriya", "", "or", "ori" },
608 { "Oromo", "", "om", "orm" },
609 { "Ossetian", "", "os", "oss" },
610 { "Panjabi", "", "pa", "pan" },
611 { "Persian", "", "fa", "fas", "per" },
612 { "Pali", "", "pi", "pli" },
613 { "Polish", "", "pl", "pol" },
614 { "Portuguese", "Portugues", "pt", "por" },
615 { "Pushto", "", "ps", "pus" },
616 { "Quechua", "", "qu", "que" },
617 { "Romansh", "", "rm", "roh" },
618 { "Romanian", "", "ro", "ron", "rum" },
619 { "Rundi", "", "rn", "run" },
620 { "Russian", "", "ru", "rus" },
621 { "Sango", "", "sg", "sag" },
622 { "Sanskrit", "", "sa", "san" },
623 { "Serbian", "", "sr", "srp", "scc" },
624 { "Sinhala", "", "si", "sin" },
625 { "Slovak", "", "sk", "slk", "slo" },
626 { "Slovenian", "", "sl", "slv" },
627 { "Northern Sami", "", "se", "sme" },
628 { "Samoan", "", "sm", "smo" },
629 { "Shona", "", "sn", "sna" },
630 { "Sindhi", "", "sd", "snd" },
631 { "Somali", "", "so", "som" },
632 { "Sotho, Southern", "", "st", "sot" },
633 { "Sardinian", "", "sc", "srd" },
634 { "Swati", "", "ss", "ssw" },
635 { "Sundanese", "", "su", "sun" },
636 { "Finnish", "Suomi", "fi", "fin" },
637 { "Swahili", "", "sw", "swa" },
638 { "Swedish", "Svenska", "sv", "swe" },
639 { "Tahitian", "", "ty", "tah" },
640 { "Tamil", "", "ta", "tam" },
641 { "Tatar", "", "tt", "tat" },
642 { "Telugu", "", "te", "tel" },
643 { "Tajik", "", "tg", "tgk" },
644 { "Tagalog", "", "tl", "tgl" },
645 { "Thai", "", "th", "tha" },
646 { "Tibetan", "", "bo", "bod", "tib" },
647 { "Tigrinya", "", "ti", "tir" },
648 { "Tonga", "", "to", "ton" },
649 { "Tswana", "", "tn", "tsn" },
650 { "Tsonga", "", "ts", "tso" },
651 { "Turkmen", "", "tk", "tuk" },
652 { "Turkish", "", "tr", "tur" },
653 { "Twi", "", "tw", "twi" },
654 { "Uighur", "", "ug", "uig" },
655 { "Ukrainian", "", "uk", "ukr" },
656 { "Urdu", "", "ur", "urd" },
657 { "Uzbek", "", "uz", "uzb" },
658 { "Venda", "", "ve", "ven" },
659 { "Vietnamese", "", "vi", "vie" },
660 { "Volapük", "", "vo", "vol" },
661 { "Welsh", "", "cy", "cym", "wel" },
662 { "Walloon", "", "wa", "wln" },
663 { "Wolof", "", "wo", "wol" },
664 { "Xhosa", "", "xh", "xho" },
665 { "Yiddish", "", "yi", "yid" },
666 { "Yoruba", "", "yo", "yor" },
667 { "Zhuang", "", "za", "zha" },
668 { "Zulu", "", "zu", "zul" },
669 {NULL, NULL, NULL, NULL}
671 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
673 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
676 del_tree(const gchar *name, gboolean del_top)
680 if (g_file_test(name, G_FILE_TEST_IS_DIR))
682 GDir *gdir = g_dir_open(name, 0, NULL);
683 file = g_dir_read_name(gdir);
687 path = g_strdup_printf("%s/%s", name, file);
688 del_tree(path, TRUE);
690 file = g_dir_read_name(gdir);
705 return hb_get_version(NULL);
710 signal_user_data_t *ud,
718 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
727 *step = ghb_settings_combo_double(ud->settings,
728 "VideoQualityGranularity");
729 if (*step == 0.2 || *step == 0.5)
731 else if (*step == 0.25)
736 case HB_VCODEC_FFMPEG:
744 case HB_VCODEC_THEORA:
763 find_combo_entry(combo_opts_t *opts, const GValue *gval)
767 if (G_VALUE_TYPE(gval) == G_TYPE_STRING)
770 str = ghb_value_string(gval);
771 for (ii = 0; ii < opts->count; ii++)
773 if (strcmp(opts->map[ii].shortOpt, str) == 0)
781 else if (G_VALUE_TYPE(gval) == G_TYPE_DOUBLE)
784 val = ghb_value_double(gval);
785 for (ii = 0; ii < opts->count; ii++)
787 if (opts->map[ii].ivalue == val)
794 else if (G_VALUE_TYPE(gval) == G_TYPE_INT ||
795 G_VALUE_TYPE(gval) == G_TYPE_BOOLEAN ||
796 G_VALUE_TYPE(gval) == G_TYPE_INT64)
799 val = ghb_value_int64(gval);
800 for (ii = 0; ii < opts->count; ii++)
802 if ((gint64)opts->map[ii].ivalue == val)
813 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
816 const gchar *result = "";
818 ii = find_combo_entry(opts, gval);
819 if (ii < opts->count)
821 result = opts->map[ii].svalue;
827 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
832 ii = find_combo_entry(opts, gval);
833 if (ii < opts->count)
835 result = opts->map[ii].ivalue;
841 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
846 ii = find_combo_entry(opts, gval);
847 if (ii < opts->count)
849 result = opts->map[ii].ivalue;
855 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
858 const gchar *result = "";
860 ii = find_combo_entry(opts, gval);
861 if (ii < opts->count)
863 result = opts->map[ii].option;
869 lookup_mix_int(const GValue *mix)
875 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
877 gchar * str = ghb_value_string(mix);
878 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
880 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
882 result = hb_audio_mixdowns[ii].amixdown;
888 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
889 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
890 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
892 gint val = ghb_value_int(mix);
893 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
895 if (hb_audio_mixdowns[ii].amixdown == val)
897 result = hb_audio_mixdowns[ii].amixdown;
906 lookup_mix_option(const GValue *mix)
909 gchar *result = "None";
912 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
914 gchar *str = ghb_value_string(mix);
915 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
917 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
919 result = hb_audio_mixdowns[ii].human_readable_name;
925 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
926 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
927 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
929 gint val = ghb_value_int(mix);
930 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
932 if (hb_audio_mixdowns[ii].amixdown == val)
934 result = hb_audio_mixdowns[ii].human_readable_name;
943 lookup_mix_string(const GValue *mix)
946 gchar *result = "None";
949 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
951 gchar *str = ghb_value_string(mix);
952 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
954 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
956 result = hb_audio_mixdowns[ii].short_name;
962 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
963 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
964 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
966 gint val = ghb_value_int(mix);
967 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
969 if (hb_audio_mixdowns[ii].amixdown == val)
971 result = hb_audio_mixdowns[ii].short_name;
980 lookup_video_rate_int(const GValue *vrate)
986 str = ghb_value_string(vrate);
987 for (ii = 0; ii < hb_video_rates_count; ii++)
989 if (strcmp(hb_video_rates[ii].string, str) == 0)
991 result = hb_video_rates[ii].rate;
996 // Default to "same as source"
1001 lookup_video_rate_option(const GValue *vrate)
1005 const gchar *result = "Same as source";
1007 str = ghb_value_string(vrate);
1008 for (ii = 0; ii < hb_video_rates_count; ii++)
1010 if (strcmp(hb_video_rates[ii].string, str) == 0)
1012 result = hb_video_rates[ii].string;
1017 // Default to "same as source"
1022 lookup_audio_rate_int(const GValue *rate)
1027 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1029 // Coincidentally, the string "source" will return 0
1030 // which is our flag to use "same as source"
1031 gchar * str = ghb_value_string(rate);
1032 for (ii = 0; ii < hb_audio_rates_count; ii++)
1034 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1036 result = hb_audio_rates[ii].rate;
1042 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1043 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1044 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1046 for (ii = 0; ii < hb_audio_rates_count; ii++)
1048 gint val = ghb_value_int(rate);
1049 if (val == hb_audio_rates[ii].rate)
1051 result = hb_audio_rates[ii].rate;
1060 lookup_audio_rate_option(const GValue *rate)
1063 const gchar *result = "Same as source";
1065 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1067 // Coincidentally, the string "source" will return 0
1068 // which is our flag to use "same as source"
1069 gchar *str = ghb_value_string(rate);
1070 for (ii = 0; ii < hb_audio_rates_count; ii++)
1072 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1074 result = hb_audio_rates[ii].string;
1080 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1081 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1082 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1084 for (ii = 0; ii < hb_audio_rates_count; ii++)
1086 gint val = ghb_value_int(rate);
1087 if (val == hb_audio_rates[ii].rate)
1089 result = hb_audio_rates[ii].string;
1098 ghb_find_closest_audio_bitrate(gint codec, gint rate)
1105 if (codec == HB_ACODEC_FAAC)
1109 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1111 if (hb_audio_bitrates[ii].rate < low)
1113 if (hb_audio_bitrates[ii].rate > high)
1115 if (rate <= hb_audio_bitrates[ii].rate)
1117 result = hb_audio_bitrates[ii].rate;
1125 lookup_audio_bitrate_int(const GValue *rate)
1130 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1132 // Coincidentally, the string "source" will return 0
1133 // which is our flag to use "same as source"
1134 gchar *str = ghb_value_string(rate);
1135 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1137 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1139 result = hb_audio_bitrates[ii].rate;
1145 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1146 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1147 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1149 gint val = ghb_value_int(rate);
1150 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1152 if (hb_audio_bitrates[ii].rate == val)
1154 result = hb_audio_bitrates[ii].rate;
1163 lookup_audio_bitrate_option(const GValue *rate)
1166 const gchar *result = "Same as source";
1168 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1170 // Coincidentally, the string "source" will return 0
1171 // which is our flag to use "same as source"
1172 gchar *str = ghb_value_string(rate);
1173 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1175 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1177 result = hb_audio_bitrates[ii].string;
1183 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1184 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1185 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1187 gint val = ghb_value_int(rate);
1188 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1190 if (hb_audio_bitrates[ii].rate == val)
1192 result = hb_audio_bitrates[ii].string;
1201 lookup_audio_lang_int(const GValue *rate)
1207 // Coincidentally, the string "source" will return 0
1208 // which is our flag to use "same as source"
1209 str = ghb_value_string(rate);
1210 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1212 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1223 lookup_audio_lang_option(const GValue *rate)
1227 const gchar *result = "Same as source";
1229 // Coincidentally, the string "source" will return 0
1230 // which is our flag to use "same as source"
1231 str = ghb_value_string(rate);
1232 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1234 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1236 if (ghb_language_table[ii].native_name[0] != 0)
1237 result = ghb_language_table[ii].native_name;
1239 result = ghb_language_table[ii].eng_name;
1248 ghb_lookup_acodec_value(gint val)
1250 GValue *value = NULL;
1253 for (ii = 0; ii < acodec_opts.count; ii++)
1255 if ((int)acodec_opts.map[ii].ivalue == val)
1257 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1261 value = ghb_string_value_new("auto");
1266 get_amix_value(gint val)
1268 GValue *value = NULL;
1271 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1273 if (hb_audio_mixdowns[ii].amixdown == val)
1275 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1282 // Handle for libhb. Gets set by ghb_backend_init()
1283 static hb_handle_t * h_scan = NULL;
1284 static hb_handle_t * h_queue = NULL;
1286 extern void hb_get_temporary_directory(char path[512]);
1293 hb_get_temporary_directory(dir);
1294 return g_strdup(dir);
1298 ghb_hb_cleanup(gboolean partial)
1302 hb_get_temporary_directory(dir);
1303 del_tree(dir, !partial);
1307 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1315 titleindex = ghb_settings_combo_int(ud->settings, "title");
1321 hb_subtitle_t * sub;
1323 if (h_scan == NULL) return VOBSUB;
1324 list = hb_get_titles( h_scan );
1325 if( !hb_list_count( list ) )
1327 /* No valid title, stop right there */
1330 title = hb_list_item( list, titleindex );
1331 if (title == NULL) return VOBSUB; // Bad titleindex
1332 sub = hb_list_item( title->list_subtitle, track);
1340 ghb_subtitle_source_name(gint source)
1342 const gchar * name = "Unknown";
1371 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1374 const gchar * name = "Unknown";
1387 titleindex = ghb_settings_combo_int(ud->settings, "title");
1393 hb_subtitle_t * sub;
1397 list = hb_get_titles( h_scan );
1398 if( !hb_list_count( list ) )
1401 title = hb_list_item( list, titleindex );
1405 sub = hb_list_item( title->list_subtitle, track);
1408 name = ghb_subtitle_source_name(sub->source);
1416 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1420 titleindex = ghb_settings_combo_int(ud->settings, "title");
1424 return ghb_get_user_audio_lang(ud, titleindex, 0);
1430 hb_subtitle_t * sub;
1435 list = hb_get_titles( h_scan );
1436 if( !hb_list_count( list ) )
1438 /* No valid title, stop right there */
1441 title = hb_list_item( list, titleindex );
1442 if (title == NULL) // Bad titleindex
1444 sub = hb_list_item( title->list_subtitle, track);
1446 return g_strdup(sub->iso639_2);
1449 return g_strdup("und");
1453 ghb_get_title_number(gint titleindex)
1458 if (h_scan == NULL) return 1;
1459 list = hb_get_titles( h_scan );
1460 if( !hb_list_count( list ) )
1462 /* No valid title, stop right there */
1465 title = hb_list_item( list, titleindex );
1466 if (title == NULL) return 1; // Bad titleindex
1467 return title->index;
1470 static hb_audio_config_t*
1471 get_hb_audio(gint titleindex, gint track)
1475 hb_audio_config_t *audio = NULL;
1477 if (h_scan == NULL) return NULL;
1478 list = hb_get_titles( h_scan );
1479 if( !hb_list_count( list ) )
1481 /* No valid title, stop right there */
1484 title = hb_list_item( list, titleindex );
1485 if (title == NULL) return NULL; // Bad titleindex
1486 if (!hb_list_count(title->list_audio))
1490 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1495 search_rates(hb_rate_t *rates, gint rate, gint count)
1498 for (ii = 0; ii < count; ii++)
1500 if (rates[ii].rate == rate)
1506 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1508 static GtkListStore*
1509 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1512 GtkListStore *store;
1514 g_debug("get_combo_box_store() %s\n", name);
1515 // First modify the combobox model to allow greying out of options
1516 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1517 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1522 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1524 GtkListStore *store;
1527 store = get_combo_box_store(builder, name);
1528 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1530 gtk_list_store_set(store, &iter,
1537 ghb_grey_combo_options(GtkBuilder *builder)
1540 gint container, track, titleindex, acodec;
1541 hb_audio_config_t *audio = NULL;
1544 widget = GHB_WIDGET (builder, "title");
1545 gval = ghb_widget_value(widget);
1546 titleindex = ghb_lookup_combo_int("title", gval);
1547 ghb_value_free(gval);
1548 widget = GHB_WIDGET (builder, "AudioTrack");
1549 gval = ghb_widget_value(widget);
1550 track = ghb_lookup_combo_int("AudioTrack", gval);
1551 ghb_value_free(gval);
1552 audio = get_hb_audio(titleindex, track);
1553 widget = GHB_WIDGET (builder, "FileFormat");
1554 gval = ghb_widget_value(widget);
1555 container = ghb_lookup_combo_int("FileFormat", gval);
1556 ghb_value_free(gval);
1558 grey_combo_box_item(builder, "x264_analyse", 4, TRUE);
1559 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1560 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1561 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1563 gboolean allow_dca = TRUE;
1564 allow_dca = (container != HB_MUX_MP4);
1566 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
1568 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
1570 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1572 if (audio && audio->in.codec != HB_ACODEC_AC3)
1574 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
1576 if (audio && audio->in.codec != HB_ACODEC_DCA)
1578 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
1580 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1582 widget = GHB_WIDGET (builder, "AudioEncoder");
1583 gval = ghb_widget_value(widget);
1584 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1585 ghb_value_free(gval);
1586 if (acodec != HB_ACODEC_AC3)
1588 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1590 if (container == HB_MUX_MP4)
1592 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1593 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1596 gboolean allow_mono = TRUE;
1597 gboolean allow_stereo = TRUE;
1598 gboolean allow_dolby = TRUE;
1599 gboolean allow_dpl2 = TRUE;
1600 gboolean allow_6ch = TRUE;
1602 allow_6ch = acodec & ~HB_ACODEC_LAME;
1605 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1607 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1609 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1610 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1611 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1612 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1613 allow_6ch = allow_6ch &&
1614 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1615 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1617 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1618 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1619 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1620 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1621 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1625 ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels)
1627 if (acodec & HB_ACODEC_FAAC)
1642 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1644 hb_audio_config_t *audio = NULL;
1645 gboolean allow_mono = TRUE;
1646 gboolean allow_stereo = TRUE;
1647 gboolean allow_dolby = TRUE;
1648 gboolean allow_dpl2 = TRUE;
1649 gboolean allow_6ch = TRUE;
1651 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1653 // Audio codec pass-thru. No mixdown
1656 audio = get_hb_audio(titleindex, track);
1660 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1662 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1664 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1665 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1666 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1667 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1669 (acodec & ~HB_ACODEC_LAME) &&
1670 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1671 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1673 gboolean greater = FALSE;
1676 // If no mix is specified, select the best available.
1677 mix = HB_AMIXDOWN_6CH;
1679 if (mix == HB_AMIXDOWN_6CH)
1682 if (allow_6ch) return HB_AMIXDOWN_6CH;
1684 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1687 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1689 if (mix == HB_AMIXDOWN_DOLBY || greater)
1692 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1694 if (mix == HB_AMIXDOWN_STEREO || greater)
1697 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1699 if (mix == HB_AMIXDOWN_MONO || greater)
1702 if (allow_mono) return HB_AMIXDOWN_MONO;
1704 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1705 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1706 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1707 if (allow_6ch) return HB_AMIXDOWN_6CH;
1711 // Set up the model for the combo box
1713 init_combo_box(GtkBuilder *builder, const gchar *name)
1716 GtkListStore *store;
1717 GtkCellRenderer *cell;
1719 g_debug("init_combo_box() %s\n", name);
1720 // First modify the combobox model to allow greying out of options
1721 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1725 // 1 - String to display
1726 // 2 - bool indicating whether the entry is selectable (grey or not)
1727 // 3 - String that is used for presets
1728 // 4 - Int value determined by backend
1729 // 5 - String value determined by backend
1730 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1731 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1732 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1734 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1736 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1737 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1738 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1739 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1740 "markup", 0, "sensitive", 1, NULL);
1743 { // Combo box entry
1744 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1749 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1752 GtkListStore *store;
1756 g_debug("audio_samplerate_opts_set ()\n");
1757 store = get_combo_box_store(builder, name);
1758 gtk_list_store_clear(store);
1759 // Add an item for "Same As Source"
1760 gtk_list_store_append(store, &iter);
1761 gtk_list_store_set(store, &iter,
1762 0, "<small>Same as source</small>",
1768 for (ii = 0; ii < count; ii++)
1770 gtk_list_store_append(store, &iter);
1771 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1772 gtk_list_store_set(store, &iter,
1775 2, rates[ii].string,
1776 3, (gdouble)rates[ii].rate,
1777 4, rates[ii].string,
1784 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1787 GtkListStore *store;
1790 g_debug("video_rate_opts_set ()\n");
1791 store = get_combo_box_store(builder, name);
1792 gtk_list_store_clear(store);
1793 // Add an item for "Same As Source"
1794 gtk_list_store_append(store, &iter);
1795 gtk_list_store_set(store, &iter,
1796 0, "Same as source",
1802 for (ii = 0; ii < count; ii++)
1806 if (strcmp(rates[ii].string, "23.976") == 0)
1808 desc = "(NTSC Film)";
1810 else if (strcmp(rates[ii].string, "25") == 0)
1812 desc = "(PAL Film/Video)";
1814 else if (strcmp(rates[ii].string, "29.97") == 0)
1816 desc = "(NTSC Video)";
1818 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1819 gtk_list_store_append(store, &iter);
1820 gtk_list_store_set(store, &iter,
1823 2, rates[ii].string,
1824 3, (gdouble)rates[ii].rate,
1825 4, rates[ii].string,
1832 mix_opts_set(GtkBuilder *builder, const gchar *name)
1835 GtkListStore *store;
1839 g_debug("mix_opts_set ()\n");
1840 store = get_combo_box_store(builder, name);
1841 gtk_list_store_clear(store);
1842 gtk_list_store_append(store, &iter);
1843 gtk_list_store_set(store, &iter,
1844 0, "<small>None</small>",
1850 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1852 gtk_list_store_append(store, &iter);
1853 str = g_strdup_printf("<small>%s</small>",
1854 hb_audio_mixdowns[ii].human_readable_name);
1855 gtk_list_store_set(store, &iter,
1858 2, hb_audio_mixdowns[ii].short_name,
1859 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1860 4, hb_audio_mixdowns[ii].internal_name,
1867 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1870 GtkListStore *store;
1873 g_debug("srt_codeset_opts_set ()\n");
1874 store = get_combo_box_store(builder, name);
1875 gtk_list_store_clear(store);
1876 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1878 gtk_list_store_append(store, &iter);
1879 gtk_list_store_set(store, &iter,
1880 0, srt_codeset_table[ii],
1882 2, srt_codeset_table[ii],
1884 4, srt_codeset_table[ii],
1887 GtkComboBoxEntry *cbe;
1889 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1890 //gtk_combo_box_entry_set_text_column(cbe, 0);
1894 language_opts_set(GtkBuilder *builder, const gchar *name)
1897 GtkListStore *store;
1900 g_debug("language_opts_set ()\n");
1901 store = get_combo_box_store(builder, name);
1902 gtk_list_store_clear(store);
1903 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1907 if (ghb_language_table[ii].native_name[0] != 0)
1908 lang = ghb_language_table[ii].native_name;
1910 lang = ghb_language_table[ii].eng_name;
1912 gtk_list_store_append(store, &iter);
1913 gtk_list_store_set(store, &iter,
1916 2, ghb_language_table[ii].iso639_2,
1918 4, ghb_language_table[ii].iso639_1,
1923 static gchar **titles = NULL;
1926 title_opts_set(GtkBuilder *builder, const gchar *name)
1929 GtkListStore *store;
1930 hb_list_t * list = NULL;
1931 hb_title_t * title = NULL;
1935 g_debug("title_opts_set ()\n");
1936 store = get_combo_box_store(builder, name);
1937 gtk_list_store_clear(store);
1940 list = hb_get_titles( h_scan );
1941 count = hb_list_count( list );
1942 if (count > 100) count = 100;
1944 if (titles) g_strfreev(titles);
1945 if (title_opts.map) g_free(title_opts.map);
1948 title_opts.count = count;
1949 title_opts.map = g_malloc(count*sizeof(options_map_t));
1950 titles = g_malloc((count+1) * sizeof(gchar*));
1954 title_opts.count = 1;
1955 title_opts.map = g_malloc(sizeof(options_map_t));
1960 // No titles. Fill in a default.
1961 gtk_list_store_append(store, &iter);
1962 gtk_list_store_set(store, &iter,
1969 title_opts.map[0].option = "No Titles";
1970 title_opts.map[0].shortOpt = "none";
1971 title_opts.map[0].ivalue = -1;
1972 title_opts.map[0].svalue = "none";
1975 for (ii = 0; ii < count; ii++)
1977 title = (hb_title_t*)hb_list_item(list, ii);
1978 if (title->type == HB_STREAM_TYPE)
1980 if (title->duration != 0)
1982 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
1983 title->index, title->hours, title->minutes, title->seconds,
1988 titles[ii] = g_strdup_printf ("%d - %s",
1989 title->index, title->name);
1994 if (title->duration != 0)
1996 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1997 title->index, title->hours, title->minutes, title->seconds);
2001 titles[ii] = g_strdup_printf ("%d - Unknown Length",
2005 gtk_list_store_append(store, &iter);
2006 gtk_list_store_set(store, &iter,
2013 title_opts.map[ii].option = titles[ii];
2014 title_opts.map[ii].shortOpt = titles[ii];
2015 title_opts.map[ii].ivalue = ii;
2016 title_opts.map[ii].svalue = titles[ii];
2022 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
2025 gboolean foundit = FALSE;
2027 if (gtk_tree_model_get_iter_first (store, iter))
2031 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
2032 if (value == (int)ivalue)
2037 } while (gtk_tree_model_iter_next (store, iter));
2043 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2046 GtkListStore *store;
2047 hb_list_t * list = NULL;
2048 hb_title_t * title = NULL;
2049 hb_audio_config_t * audio;
2054 g_debug("audio_track_opts_set ()\n");
2055 store = get_combo_box_store(builder, name);
2056 gtk_list_store_clear(store);
2059 list = hb_get_titles( h_scan );
2060 title = (hb_title_t*)hb_list_item( list, titleindex );
2063 count = hb_list_count( title->list_audio );
2066 if (count > 100) count = 100;
2067 if (audio_track_opts.map) g_free(audio_track_opts.map);
2070 audio_track_opts.count = count;
2071 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
2075 audio_track_opts.count = 1;
2076 audio_track_opts.map = g_malloc(sizeof(options_map_t));
2080 // No audio. set some default
2081 gtk_list_store_append(store, &iter);
2082 gtk_list_store_set(store, &iter,
2083 0, "<small>No Audio</small>",
2089 audio_track_opts.map[0].option = "No Audio";
2090 audio_track_opts.map[0].shortOpt = "none";
2091 audio_track_opts.map[0].ivalue = -1;
2092 audio_track_opts.map[0].svalue = "none";
2095 index_str_init(count-1);
2096 for (ii = 0; ii < count; ii++)
2098 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
2099 gtk_list_store_append(store, &iter);
2100 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
2101 gtk_list_store_set(store, &iter,
2109 audio_track_opts.map[ii].option = audio->lang.description,
2110 audio_track_opts.map[ii].shortOpt = index_str[ii];
2111 audio_track_opts.map[ii].ivalue = ii;
2112 audio_track_opts.map[ii].svalue = index_str[ii];
2117 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2120 GtkListStore *store;
2121 hb_list_t * list = NULL;
2122 hb_title_t * title = NULL;
2123 hb_subtitle_t * subtitle;
2125 static char ** options = NULL;
2127 g_debug("subtitle_track_opts_set ()\n");
2128 store = get_combo_box_store(builder, name);
2129 gtk_list_store_clear(store);
2132 list = hb_get_titles( h_scan );
2133 title = (hb_title_t*)hb_list_item( list, titleindex );
2136 count = hb_list_count( title->list_subtitle );
2139 if (count > 100) count = 100;
2140 if (subtitle_opts.map) g_free(subtitle_opts.map);
2143 subtitle_opts.count = count+1;
2144 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
2148 subtitle_opts.count = LANG_TABLE_SIZE+1;
2149 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
2151 gtk_list_store_append(store, &iter);
2152 gtk_list_store_set(store, &iter,
2153 0, "Foreign Audio Search",
2159 subtitle_opts.map[0].option = "Foreign Audio Search";
2160 subtitle_opts.map[0].shortOpt = "-1";
2161 subtitle_opts.map[0].ivalue = -1;
2162 subtitle_opts.map[0].svalue = "auto";
2165 if (options != NULL)
2166 g_strfreev(options);
2167 options = g_malloc((count+1)*sizeof(gchar*));
2168 index_str_init(count-1);
2169 for (ii = 0; ii < count; ii++)
2171 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
2172 // Skip subtitles that must be burned if there is already
2173 // a burned subtitle in the list
2175 if (subtitle->source == VOBSUB)
2177 options[ii] = g_strdup_printf("%d - %s", ii+1, subtitle->lang);
2182 options[ii] = g_strdup_printf("%d - %s (%s)", ii+1,
2184 ghb_subtitle_source_name(subtitle->source));
2186 subtitle_opts.map[ii+1].option = options[ii];
2187 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2188 subtitle_opts.map[ii+1].ivalue = ii;
2189 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
2190 gtk_list_store_append(store, &iter);
2191 gtk_list_store_set(store, &iter,
2196 4, subtitle->iso639_2,
2199 options[count] = NULL;
2203 index_str_init(LANG_TABLE_SIZE-1);
2204 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
2208 if (ghb_language_table[ii].native_name[0] != 0)
2209 lang = ghb_language_table[ii].native_name;
2211 lang = ghb_language_table[ii].eng_name;
2213 subtitle_opts.map[ii+1].option = lang;
2214 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2215 subtitle_opts.map[ii+1].ivalue = ii;
2216 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
2217 gtk_list_store_append(store, &iter);
2218 gtk_list_store_set(store, &iter,
2223 4, ghb_language_table[ii].iso639_2,
2236 gint titleindex = 0;
2239 g_debug("ghb_longest_title ()\n");
2240 if (h_scan == NULL) return 0;
2241 list = hb_get_titles( h_scan );
2242 count = hb_list_count( list );
2243 if (count > 100) count = 100;
2244 if (count < 1) return 0;
2245 title = (hb_title_t*)hb_list_item(list, 0);
2246 feature = title->job->feature;
2247 for (ii = 0; ii < count; ii++)
2249 title = (hb_title_t*)hb_list_item(list, ii);
2250 if (title->index == feature)
2259 ghb_get_source_audio_lang(gint titleindex, gint track)
2263 hb_audio_config_t * audio;
2266 g_debug("ghb_lookup_1st_audio_lang ()\n");
2269 list = hb_get_titles( h_scan );
2270 title = (hb_title_t*)hb_list_item( list, titleindex );
2273 if (hb_list_count( title->list_audio ) <= track)
2276 audio = hb_list_audio_config_item(title->list_audio, track);
2280 lang = g_strdup(audio->lang.iso639_2);
2285 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2289 used = g_hash_table_lookup(track_indices, &acodec);
2294 used = g_malloc0(count * sizeof(gboolean));
2295 key = g_malloc(sizeof(gint));
2297 g_hash_table_insert(track_indices, key, used);
2303 ghb_find_audio_track(
2307 gint fallback_acodec,
2308 GHashTable *track_indices)
2312 hb_audio_config_t * audio;
2317 gboolean *used = NULL;
2318 gboolean *passthru_used;
2320 gint passthru_acodec;
2324 g_debug("find_audio_track ()\n");
2325 if (h_scan == NULL) return -1;
2326 list = hb_get_titles( h_scan );
2327 title = (hb_title_t*)hb_list_item( list, titleindex );
2330 count = hb_list_count( title->list_audio );
2332 if (count > 10) count = 10;
2333 // Try to find an item that matches the preferred language and
2334 // the passthru codec type
2336 passthru = (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)) != 0;
2339 for (ii = 0; ii < count; ii++)
2341 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2342 title->list_audio, ii );
2343 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2344 // Is the source track use a passthru capable codec?
2345 if (passthru_acodec == 0)
2347 used = get_track_used(passthru_acodec, track_indices, count);
2348 // Has the track already been used with this codec?
2352 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2353 audio->in.channel_layout);
2354 // Find a track that is not visually impaired or dirctor's
2355 // commentary, and has the highest channel count.
2356 if ((audio->lang.type < 2) &&
2357 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2358 (strcmp(lang, "und") == 0)))
2360 if (channels > max_chan)
2363 max_chan = channels;
2367 try_acodec = fallback_acodec;
2371 try_acodec = acodec;
2378 // Try to find an item that matches the preferred language
2380 used = get_track_used(try_acodec, track_indices, count);
2381 for (ii = 0; ii < count; ii++)
2383 // Has the track already been used with this codec?
2386 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2387 title->list_audio, ii );
2388 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2389 if (passthru_acodec && passthru)
2391 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2392 // Has the track already been used with this codec for passthru?
2393 if (passthru_used[ii])
2396 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2397 audio->in.channel_layout);
2398 // Find a track that is not visually impaired or dirctor's commentary
2399 if ((audio->lang.type < 2) &&
2400 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2401 (strcmp(lang, "und") == 0)))
2403 if (channels > max_chan)
2406 max_chan = channels;
2415 // Try to fine an item that does not match the preferred language and
2416 // matches the passthru codec type
2420 for (ii = 0; ii < count; ii++)
2422 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2423 title->list_audio, ii );
2424 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2425 // Is the source track use a passthru capable codec?
2426 if (passthru_acodec == 0)
2428 used = get_track_used(passthru_acodec, track_indices, count);
2429 // Has the track already been used with this codec?
2433 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2434 audio->in.channel_layout);
2435 // Find a track that is not visually impaired or dirctor's
2436 // commentary, and has the highest channel count.
2437 if (audio->lang.type < 2)
2439 if (channels > max_chan)
2442 max_chan = channels;
2446 try_acodec = fallback_acodec;
2450 try_acodec = acodec;
2457 // Try to fine an item that does not match the preferred language
2459 used = get_track_used(try_acodec, track_indices, count);
2460 for (ii = 0; ii < count; ii++)
2462 // Has the track already been used with this codec?
2465 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2466 title->list_audio, ii );
2467 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2468 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2469 audio->in.channel_layout);
2470 if (passthru_acodec && passthru)
2472 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2473 // Has the track already been used with this codec for passthru?
2474 if (passthru_used[ii])
2477 // Find a track that is not visually impaired or dirctor's commentary
2478 if (audio->lang.type < 2)
2480 if (channels > max_chan)
2483 max_chan = channels;
2492 // Last ditch, anything goes
2493 for (ii = 0; ii < count; ii++)
2495 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2496 title->list_audio, ii );
2497 passthru_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec;
2498 if (passthru_acodec && passthru)
2500 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2501 // Has the track already been used with this codec for passthru?
2502 if (passthru_used[ii])
2505 // Has the track already been used with this codec?
2520 ghb_find_pref_subtitle_track(const gchar *lang)
2523 count = subtitle_opts.count;
2524 for (ii = 0; ii < count; ii++)
2526 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2528 return subtitle_opts.map[ii].ivalue;
2535 ghb_find_cc_track(gint titleindex)
2539 hb_subtitle_t * subtitle;
2542 g_debug("ghb_find_cc_track ()\n");
2543 if (h_scan == NULL) return -2;
2544 list = hb_get_titles( h_scan );
2545 title = (hb_title_t*)hb_list_item( list, titleindex );
2548 count = hb_list_count( title->list_subtitle );
2549 // Try to find an item that matches the preferred language
2550 for (ii = 0; ii < count; ii++)
2552 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2553 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2561 ghb_find_subtitle_track(
2567 GHashTable * track_indices)
2571 hb_subtitle_t * subtitle;
2575 g_debug("find_subtitle_track ()\n");
2576 if (strcmp(lang, "auto") == 0)
2578 if (h_scan == NULL) return -1;
2579 list = hb_get_titles( h_scan );
2580 title = (hb_title_t*)hb_list_item( list, titleindex );
2583 count = hb_list_count( title->list_subtitle );
2584 used = g_hash_table_lookup(track_indices, lang);
2587 used = g_malloc0(count * sizeof(gboolean));
2588 g_hash_table_insert(track_indices, g_strdup(lang), used);
2590 // Try to find an item that matches the preferred language and source
2591 for (ii = 0; ii < count; ii++)
2596 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2597 if (source == subtitle->source &&
2598 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2599 (strcmp(lang, "und") == 0)))
2605 // Try to find an item that matches the preferred language
2606 for (ii = 0; ii < count; ii++)
2611 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2612 if ((!(burn || force) || (subtitle->source == VOBSUB)) &&
2613 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2614 (strcmp(lang, "und") == 0)))
2625 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2628 GtkListStore *store;
2631 g_debug("generic_opts_set ()\n");
2632 if (name == NULL || opts == NULL) return;
2633 store = get_combo_box_store(builder, name);
2634 gtk_list_store_clear(store);
2635 for (ii = 0; ii < opts->count; ii++)
2637 gtk_list_store_append(store, &iter);
2638 gtk_list_store_set(store, &iter,
2639 0, opts->map[ii].option,
2641 2, opts->map[ii].shortOpt,
2642 3, opts->map[ii].ivalue,
2643 4, opts->map[ii].svalue,
2649 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2652 GtkListStore *store;
2656 g_debug("small_opts_set ()\n");
2657 if (name == NULL || opts == NULL) return;
2658 store = get_combo_box_store(builder, name);
2659 gtk_list_store_clear(store);
2660 for (ii = 0; ii < opts->count; ii++)
2662 gtk_list_store_append(store, &iter);
2663 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2664 gtk_list_store_set(store, &iter,
2667 2, opts->map[ii].shortOpt,
2668 3, opts->map[ii].ivalue,
2669 4, opts->map[ii].svalue,
2676 find_combo_table(const gchar *name)
2680 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2682 if (strcmp(name, combo_name_map[ii].name) == 0)
2684 return combo_name_map[ii].opts;
2691 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2695 if (strcmp(name, "AudioBitrate") == 0)
2696 return lookup_audio_bitrate_int(gval);
2697 else if (strcmp(name, "AudioSamplerate") == 0)
2698 return lookup_audio_rate_int(gval);
2699 else if (strcmp(name, "VideoFramerate") == 0)
2700 return lookup_video_rate_int(gval);
2701 else if (strcmp(name, "AudioMixdown") == 0)
2702 return lookup_mix_int(gval);
2703 else if (strcmp(name, "SrtLanguage") == 0)
2704 return lookup_audio_lang_int(gval);
2705 else if (strcmp(name, "PreferredLanguage") == 0)
2706 return lookup_audio_lang_int(gval);
2709 return lookup_generic_int(find_combo_table(name), gval);
2711 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2716 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2720 if (strcmp(name, "AudioBitrate") == 0)
2721 return lookup_audio_bitrate_int(gval);
2722 else if (strcmp(name, "AudioSamplerate") == 0)
2723 return lookup_audio_rate_int(gval);
2724 else if (strcmp(name, "VideoFramerate") == 0)
2725 return lookup_video_rate_int(gval);
2726 else if (strcmp(name, "AudioMixdown") == 0)
2727 return lookup_mix_int(gval);
2728 else if (strcmp(name, "SrtLanguage") == 0)
2729 return lookup_audio_lang_int(gval);
2730 else if (strcmp(name, "PreferredLanguage") == 0)
2731 return lookup_audio_lang_int(gval);
2734 return lookup_generic_double(find_combo_table(name), gval);
2736 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2741 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2745 if (strcmp(name, "AudioBitrate") == 0)
2746 return lookup_audio_bitrate_option(gval);
2747 else if (strcmp(name, "AudioSamplerate") == 0)
2748 return lookup_audio_rate_option(gval);
2749 else if (strcmp(name, "VideoFramerate") == 0)
2750 return lookup_video_rate_option(gval);
2751 else if (strcmp(name, "AudioMixdown") == 0)
2752 return lookup_mix_option(gval);
2753 else if (strcmp(name, "SrtLanguage") == 0)
2754 return lookup_audio_lang_option(gval);
2755 else if (strcmp(name, "PreferredLanguage") == 0)
2756 return lookup_audio_lang_option(gval);
2759 return lookup_generic_option(find_combo_table(name), gval);
2761 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2766 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2770 if (strcmp(name, "AudioBitrate") == 0)
2771 return lookup_audio_bitrate_option(gval);
2772 else if (strcmp(name, "AudioSamplerate") == 0)
2773 return lookup_audio_rate_option(gval);
2774 else if (strcmp(name, "VideoFramerate") == 0)
2775 return lookup_video_rate_option(gval);
2776 else if (strcmp(name, "AudioMixdown") == 0)
2777 return lookup_mix_string(gval);
2778 else if (strcmp(name, "SrtLanguage") == 0)
2779 return lookup_audio_lang_option(gval);
2780 else if (strcmp(name, "PreferredLanguage") == 0)
2781 return lookup_audio_lang_option(gval);
2784 return lookup_generic_string(find_combo_table(name), gval);
2786 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2791 ghb_update_ui_combo_box(
2792 signal_user_data_t *ud,
2797 GtkComboBox *combo = NULL;
2799 gint handler_id = 0;
2803 g_debug("ghb_update_ui_combo_box() %s\n", name);
2804 // Clearing a combo box causes a rash of "changed" events, even when
2805 // the active item is -1 (inactive). To control things, I'm disabling
2806 // the event till things are settled down.
2807 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2808 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2811 // Valid signal id found. This should always succeed.
2812 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2813 signal_id, 0, 0, 0, 0);
2816 // This should also always succeed
2817 g_signal_handler_block ((gpointer)combo, handler_id);
2823 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2824 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2825 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2826 mix_opts_set(ud->builder, "AudioMixdown");
2827 language_opts_set(ud->builder, "SrtLanguage");
2828 language_opts_set(ud->builder, "PreferredLanguage");
2829 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2830 title_opts_set(ud->builder, "title");
2831 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2832 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2833 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2834 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2835 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2836 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2837 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2838 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2839 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2840 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2841 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2842 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2843 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2844 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2845 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2846 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2847 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2848 small_opts_set(ud->builder, "x264_direct", &direct_opts);
2849 small_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2850 small_opts_set(ud->builder, "x264_bpyramid", &bpyramid_opts);
2851 small_opts_set(ud->builder, "x264_weighted_pframes", &weightp_opts);
2852 small_opts_set(ud->builder, "x264_me", &me_opts);
2853 small_opts_set(ud->builder, "x264_subme", &subme_opts);
2854 small_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2855 small_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2859 if (strcmp(name, "AudioBitrate") == 0)
2860 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2861 else if (strcmp(name, "AudioSamplerate") == 0)
2862 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2863 else if (strcmp(name, "VideoFramerate") == 0)
2864 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2865 else if (strcmp(name, "AudioMixdown") == 0)
2866 mix_opts_set(ud->builder, "AudioMixdown");
2867 else if (strcmp(name, "SrtLanguage") == 0)
2868 language_opts_set(ud->builder, "SrtLanguage");
2869 else if (strcmp(name, "PreferredLanguage") == 0)
2870 language_opts_set(ud->builder, "PreferredLanguage");
2871 else if (strcmp(name, "SrtCodeset") == 0)
2872 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2873 else if (strcmp(name, "title") == 0)
2874 title_opts_set(ud->builder, "title");
2875 else if (strcmp(name, "SubtitleTrack") == 0)
2876 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2877 else if (strcmp(name, "AudioTrack") == 0)
2878 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2880 generic_opts_set(ud->builder, name, find_combo_table(name));
2884 g_signal_handler_unblock ((gpointer)combo, handler_id);
2889 init_ui_combo_boxes(GtkBuilder *builder)
2893 init_combo_box(builder, "AudioBitrate");
2894 init_combo_box(builder, "AudioSamplerate");
2895 init_combo_box(builder, "VideoFramerate");
2896 init_combo_box(builder, "AudioMixdown");
2897 init_combo_box(builder, "SrtLanguage");
2898 init_combo_box(builder, "PreferredLanguage");
2899 init_combo_box(builder, "SrtCodeset");
2900 init_combo_box(builder, "title");
2901 init_combo_box(builder, "AudioTrack");
2902 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2904 init_combo_box(builder, combo_name_map[ii].name);
2908 static const char * turbo_opts =
2909 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2910 "no-fast-pskip=0:8x8dct=0";
2912 // Construct the x264 options string
2913 // The result is allocated, so someone must free it at some point.
2915 ghb_build_x264opts_string(GValue *settings)
2918 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2925 result = g_strdup("");
2931 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2935 hb_chapter_t * chapter;
2939 *hh = *mm = *ss = 0;
2940 if (h_scan == NULL) return;
2941 list = hb_get_titles( h_scan );
2942 title = (hb_title_t*)hb_list_item( list, tt );
2943 if (title == NULL) return;
2946 *mm = title->minutes;
2947 *ss = title->seconds;
2949 count = hb_list_count(title->list_chapter);
2950 if (sc > count) sc = count;
2951 if (ec > count) ec = count;
2953 if (sc == 1 && ec == count)
2957 for (c = sc; c <= ec; c++)
2959 chapter = hb_list_item(title->list_chapter, c-1);
2960 duration += chapter->duration;
2963 *hh = duration / 90000 / 3600;
2964 *mm = ((duration / 90000) % 3600) / 60;
2965 *ss = (duration / 90000) % 60;
2969 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2973 hb_chapter_t * chapter;
2976 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2977 *hh = *mm = *ss = 0;
2978 if (h_scan == NULL) return;
2979 list = hb_get_titles( h_scan );
2980 title = (hb_title_t*)hb_list_item( list, ti );
2981 if (title == NULL) return;
2982 count = hb_list_count( title->list_chapter );
2983 if (ii >= count) return;
2984 chapter = hb_list_item(title->list_chapter, ii);
2985 if (chapter == NULL) return;
2986 *hh = chapter->hours;
2987 *mm = chapter->minutes;
2988 *ss = chapter->seconds;
2992 ghb_get_chapters(gint titleindex)
2996 hb_chapter_t * chapter;
2998 GValue *chapters = NULL;
3000 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
3001 if (h_scan == NULL) return NULL;
3002 list = hb_get_titles( h_scan );
3003 title = (hb_title_t*)hb_list_item( list, titleindex );
3004 if (title == NULL) return NULL;
3005 count = hb_list_count( title->list_chapter );
3006 chapters = ghb_array_value_new(count);
3007 for (ii = 0; ii < count; ii++)
3009 chapter = hb_list_item(title->list_chapter, ii);
3010 if (chapter == NULL) break;
3011 if (chapter->title == NULL || chapter->title[0] == 0)
3014 str = g_strdup_printf ("Chapter %2d", ii+1);
3015 ghb_array_append(chapters, ghb_string_value_new(str));
3020 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
3027 ghb_ac3_in_audio_list(const GValue *audio_list)
3031 count = ghb_array_len(audio_list);
3032 for (ii = 0; ii < count; ii++)
3037 asettings = ghb_array_get_nth(audio_list, ii);
3038 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
3039 if (acodec & HB_ACODEC_AC3)
3046 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
3049 GtkListStore *store;
3052 g_debug("audio_bitrate_opts_add ()\n");
3054 if (rate < 8) return;
3056 store = get_combo_box_store(builder, name);
3057 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
3059 str = g_strdup_printf ("<small>%d</small>", rate);
3060 gtk_list_store_append(store, &iter);
3061 gtk_list_store_set(store, &iter,
3073 audio_bitrate_opts_clean(
3074 GtkBuilder *builder,
3080 GtkListStore *store;
3082 gboolean done = FALSE;
3084 guint last = (guint)last_rate;
3085 guint first = (guint)first_rate;
3087 g_debug("audio_bitrate_opts_clean ()\n");
3088 store = get_combo_box_store(builder, name);
3089 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
3093 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
3095 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
3097 done = !gtk_list_store_remove(store, &iter);
3099 else if (ivalue < first || ivalue > last)
3102 gtk_list_store_set(store, &iter, 1, FALSE, -1);
3103 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3108 gtk_list_store_set(store, &iter, 1, TRUE, -1);
3109 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3116 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
3119 GtkListStore *store;
3123 g_debug("audio_bitrate_opts_set ()\n");
3124 store = get_combo_box_store(builder, name);
3125 gtk_list_store_clear(store);
3126 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
3128 gtk_list_store_append(store, &iter);
3129 str = g_strdup_printf ("<small>%s</small>",
3130 hb_audio_bitrates[ii].string);
3131 gtk_list_store_set(store, &iter,
3134 2, hb_audio_bitrates[ii].string,
3135 3, (gdouble)hb_audio_bitrates[ii].rate,
3136 4, hb_audio_bitrates[ii].string,
3143 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
3145 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
3149 ghb_set_default_bitrate_opts(
3150 GtkBuilder *builder,
3154 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
3157 static ghb_status_t hb_status;
3160 ghb_combo_init(signal_user_data_t *ud)
3162 // Set up the list model for the combos
3163 init_ui_combo_boxes(ud->builder);
3164 // Populate all the combos
3165 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
3169 ghb_backend_init(gint debug)
3172 h_scan = hb_init( debug, 0 );
3173 h_queue = hb_init( debug, 0 );
3184 void ghb_backend_scan_stop()
3186 hb_scan_stop( h_scan );
3190 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count)
3192 hb_scan( h_scan, path, titleindex, preview_count, 1 );
3193 hb_status.scan.state |= GHB_STATE_SCANNING;
3194 // initialize count and cur to something that won't cause FPE
3195 // when computing progress
3196 hb_status.scan.title_count = 1;
3197 hb_status.scan.title_cur = 0;
3201 ghb_backend_queue_scan(const gchar *path, gint titlenum)
3203 g_debug("ghb_backend_queue_scan()");
3204 hb_scan( h_queue, path, titlenum, 10, 0 );
3205 hb_status.queue.state |= GHB_STATE_SCANNING;
3209 ghb_get_scan_state()
3211 return hb_status.scan.state;
3215 ghb_get_queue_state()
3217 return hb_status.queue.state;
3221 ghb_clear_scan_state(gint state)
3223 hb_status.scan.state &= ~state;
3227 ghb_clear_queue_state(gint state)
3229 hb_status.queue.state &= ~state;
3233 ghb_set_scan_state(gint state)
3235 hb_status.scan.state |= state;
3239 ghb_set_queue_state(gint state)
3241 hb_status.queue.state |= state;
3245 ghb_get_status(ghb_status_t *status)
3247 memcpy(status, &hb_status, sizeof(ghb_status_t));
3256 if (h_scan == NULL) return;
3257 hb_get_state( h_scan, &s_scan );
3258 switch( s_scan.state )
3260 #define p s_scan.param.scanning
3261 case HB_STATE_SCANNING:
3263 hb_status.scan.state |= GHB_STATE_SCANNING;
3264 hb_status.scan.title_count = p.title_count;
3265 hb_status.scan.title_cur = p.title_cur;
3269 case HB_STATE_SCANDONE:
3271 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3272 hb_status.scan.state |= GHB_STATE_SCANDONE;
3275 #define p s_scan.param.working
3276 case HB_STATE_WORKING:
3277 hb_status.scan.state |= GHB_STATE_WORKING;
3278 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3279 hb_status.scan.job_cur = p.job_cur;
3280 hb_status.scan.job_count = p.job_count;
3281 hb_status.scan.progress = p.progress;
3282 hb_status.scan.rate_cur = p.rate_cur;
3283 hb_status.scan.rate_avg = p.rate_avg;
3284 hb_status.scan.hours = p.hours;
3285 hb_status.scan.minutes = p.minutes;
3286 hb_status.scan.seconds = p.seconds;
3287 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3291 case HB_STATE_PAUSED:
3292 hb_status.scan.state |= GHB_STATE_PAUSED;
3295 case HB_STATE_MUXING:
3297 hb_status.scan.state |= GHB_STATE_MUXING;
3300 #define p s_scan.param.workdone
3301 case HB_STATE_WORKDONE:
3305 hb_status.scan.state |= GHB_STATE_WORKDONE;
3306 hb_status.scan.state &= ~GHB_STATE_MUXING;
3307 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3308 hb_status.scan.state &= ~GHB_STATE_WORKING;
3312 hb_status.scan.error = GHB_ERROR_NONE;
3314 case HB_ERROR_CANCELED:
3315 hb_status.scan.error = GHB_ERROR_CANCELED;
3318 hb_status.scan.error = GHB_ERROR_FAIL;
3321 // Delete all remaining jobs of this encode.
3322 // An encode can be composed of multiple associated jobs.
3323 // When a job is stopped, libhb removes it from the job list,
3324 // but does not remove other jobs that may be associated with it.
3325 // Associated jobs are taged in the sequence id.
3326 while ((job = hb_job(h_scan, 0)) != NULL)
3327 hb_rem( h_scan, job );
3331 hb_get_state( h_queue, &s_queue );
3332 switch( s_queue.state )
3334 #define p s_queue.param.scanning
3335 case HB_STATE_SCANNING:
3337 hb_status.queue.state |= GHB_STATE_SCANNING;
3338 hb_status.queue.title_count = p.title_count;
3339 hb_status.queue.title_cur = p.title_cur;
3343 case HB_STATE_SCANDONE:
3345 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3346 hb_status.queue.state |= GHB_STATE_SCANDONE;
3349 #define p s_queue.param.working
3350 case HB_STATE_WORKING:
3351 hb_status.queue.state |= GHB_STATE_WORKING;
3352 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3353 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3354 hb_status.queue.job_cur = p.job_cur;
3355 hb_status.queue.job_count = p.job_count;
3356 hb_status.queue.progress = p.progress;
3357 hb_status.queue.rate_cur = p.rate_cur;
3358 hb_status.queue.rate_avg = p.rate_avg;
3359 hb_status.queue.hours = p.hours;
3360 hb_status.queue.minutes = p.minutes;
3361 hb_status.queue.seconds = p.seconds;
3362 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3365 case HB_STATE_SEARCHING:
3366 hb_status.queue.state |= GHB_STATE_SEARCHING;
3367 hb_status.queue.state &= ~GHB_STATE_WORKING;
3368 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3369 hb_status.queue.job_cur = p.job_cur;
3370 hb_status.queue.job_count = p.job_count;
3371 hb_status.queue.progress = p.progress;
3372 hb_status.queue.rate_cur = p.rate_cur;
3373 hb_status.queue.rate_avg = p.rate_avg;
3374 hb_status.queue.hours = p.hours;
3375 hb_status.queue.minutes = p.minutes;
3376 hb_status.queue.seconds = p.seconds;
3377 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3381 case HB_STATE_PAUSED:
3382 hb_status.queue.state |= GHB_STATE_PAUSED;
3385 case HB_STATE_MUXING:
3387 hb_status.queue.state |= GHB_STATE_MUXING;
3390 #define p s_queue.param.workdone
3391 case HB_STATE_WORKDONE:
3395 hb_status.queue.state |= GHB_STATE_WORKDONE;
3396 hb_status.queue.state &= ~GHB_STATE_MUXING;
3397 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3398 hb_status.queue.state &= ~GHB_STATE_WORKING;
3399 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3403 hb_status.queue.error = GHB_ERROR_NONE;
3405 case HB_ERROR_CANCELED:
3406 hb_status.queue.error = GHB_ERROR_CANCELED;
3409 hb_status.queue.error = GHB_ERROR_FAIL;
3412 // Delete all remaining jobs of this encode.
3413 // An encode can be composed of multiple associated jobs.
3414 // When a job is stopped, libhb removes it from the job list,
3415 // but does not remove other jobs that may be associated with it.
3416 // Associated jobs are taged in the sequence id.
3417 while ((job = hb_job(h_queue, 0)) != NULL)
3418 hb_rem( h_queue, job );
3425 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3430 if (h_scan == NULL) return FALSE;
3431 list = hb_get_titles( h_scan );
3432 if( !hb_list_count( list ) )
3434 /* No valid title, stop right there */
3438 title = hb_list_item( list, titleindex );
3439 if (title == NULL) return FALSE; // Bad titleindex
3440 tinfo->index = titleindex;
3441 tinfo->width = title->width;
3442 tinfo->height = title->height;
3443 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3444 // Don't allow crop to 0
3445 if (title->crop[0] + title->crop[1] >= title->height)
3446 title->crop[0] = title->crop[1] = 0;
3447 if (title->crop[2] + title->crop[3] >= title->width)
3448 title->crop[2] = title->crop[3] = 0;
3449 tinfo->num_chapters = hb_list_count(title->list_chapter);
3450 tinfo->rate_base = title->rate_base;
3451 tinfo->rate = title->rate;
3452 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3453 title->width * title->pixel_aspect_width,
3454 title->height * title->pixel_aspect_height);
3455 tinfo->hours = title->hours;
3456 tinfo->minutes = title->minutes;
3457 tinfo->seconds = title->seconds;
3458 tinfo->duration = title->duration;
3460 tinfo->angle_count = title->angle_count;
3461 tinfo->path = title->path;
3462 tinfo->name = title->name;
3463 tinfo->type = title->type;
3468 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3470 hb_audio_config_t *audio;
3472 audio = get_hb_audio(titleindex, audioindex);
3473 if (audio == NULL) return FALSE; // Bad audioindex
3474 ainfo->codec = audio->in.codec;
3475 ainfo->bitrate = audio->in.bitrate;
3476 ainfo->samplerate = audio->in.samplerate;
3481 ghb_audio_is_passthru(gint acodec)
3483 g_debug("ghb_audio_is_passthru () \n");
3484 return (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA));
3488 ghb_get_default_acodec()
3490 return HB_ACODEC_FAAC;
3494 picture_settings_deps(signal_user_data_t *ud)
3496 gboolean autoscale, keep_aspect, enable_keep_aspect;
3497 gboolean enable_scale_width, enable_scale_height;
3498 gboolean enable_disp_width, enable_disp_height, enable_par;
3502 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3505 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3506 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3507 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3509 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3510 if (!enable_keep_aspect)
3512 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3514 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3515 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3517 enable_scale_width = !autoscale && (pic_par != 1);
3518 enable_scale_height = !autoscale && (pic_par != 1);
3519 enable_disp_width = (pic_par == 3) && !keep_aspect;
3520 enable_par = (pic_par == 3) && !keep_aspect;
3521 enable_disp_height = FALSE;
3523 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3524 gtk_widget_set_sensitive(widget, pic_par != 1);
3525 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3526 gtk_widget_set_sensitive(widget, pic_par != 1);
3527 widget = GHB_WIDGET(ud->builder, "scale_width");
3528 gtk_widget_set_sensitive(widget, enable_scale_width);
3529 widget = GHB_WIDGET(ud->builder, "scale_height");
3530 gtk_widget_set_sensitive(widget, enable_scale_height);
3531 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3532 gtk_widget_set_sensitive(widget, enable_disp_width);
3533 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3534 gtk_widget_set_sensitive(widget, enable_disp_height);
3535 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3536 gtk_widget_set_sensitive(widget, enable_par);
3537 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3538 gtk_widget_set_sensitive(widget, enable_par);
3539 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3540 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3541 widget = GHB_WIDGET(ud->builder, "autoscale");
3542 gtk_widget_set_sensitive(widget, pic_par != 1);
3546 ghb_set_scale(signal_user_data_t *ud, gint mode)
3551 gboolean keep_aspect;
3553 gboolean autocrop, autoscale, noscale;
3554 gint crop[4], width, height, par_width, par_height;
3555 gint crop_width, crop_height;
3556 gint aspect_n, aspect_d;
3557 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3558 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3563 gint max_height = 0;
3564 static gboolean busy = FALSE;
3566 g_debug("ghb_set_scale ()\n");
3567 picture_settings_deps(ud);
3568 if (h_scan == NULL) return;
3569 list = hb_get_titles( h_scan );
3570 if( !hb_list_count( list ) )
3572 /* No valid title, stop right there */
3577 titleindex = ghb_settings_combo_int(ud->settings, "title");
3578 title = hb_list_item( list, titleindex );
3579 if (title == NULL) return;
3581 if (job == NULL) return;
3586 if (!ud->dont_clear_presets && (keep_width || keep_height))
3588 ghb_settings_set_int(ud->settings, "PictureWidth", 0);
3589 ghb_settings_set_int(ud->settings, "PictureHeight", 0);
3592 // First configure widgets
3593 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3594 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3595 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3596 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3597 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3598 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3599 // alignment constraints rather than scaling to satisfy them.
3600 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3601 // Align dimensions to either 16 or 2 pixels
3602 // The scaler crashes if the dimensions are not divisible by 2
3603 // x264 also will not accept dims that are not multiple of 2
3607 keep_height = FALSE;
3609 // Step needs to be at least 2 because odd widths cause scaler crash
3611 widget = GHB_WIDGET (ud->builder, "scale_width");
3612 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3613 widget = GHB_WIDGET (ud->builder, "scale_height");
3614 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3617 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3618 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3619 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3620 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3621 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3622 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3623 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3624 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3628 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3629 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3630 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3631 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3632 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3633 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3634 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3635 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3637 ghb_title_info_t tinfo;
3638 ghb_get_title_info (&tinfo, titleindex);
3641 crop[0] = tinfo.crop[0];
3642 crop[1] = tinfo.crop[1];
3643 crop[2] = tinfo.crop[2];
3644 crop[3] = tinfo.crop[3];
3645 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3646 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3647 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3648 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3652 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3653 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3654 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3655 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3661 // Adjust the cropping to accomplish the desired width and height
3662 crop_width = tinfo.width - crop[2] - crop[3];
3663 crop_height = tinfo.height - crop[0] - crop[1];
3664 width = MOD_DOWN(crop_width, mod);
3665 height = MOD_DOWN(crop_height, mod);
3667 need1 = (crop_height - height) / 2;
3668 need2 = crop_height - height - need1;
3671 need1 = (crop_width - width) / 2;
3672 need2 = crop_width - width - need1;
3675 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3676 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3677 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3678 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3680 hb_reduce(&aspect_n, &aspect_d,
3681 title->width * title->pixel_aspect_width,
3682 title->height * title->pixel_aspect_height);
3683 crop_width = title->width - crop[2] - crop[3];
3684 crop_height = title->height - crop[0] - crop[1];
3688 height = crop_height;
3692 width = ghb_settings_get_int(ud->settings, "scale_width");
3693 height = ghb_settings_get_int(ud->settings, "scale_height");
3694 max_width = MOD_DOWN(
3695 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3696 max_height = MOD_DOWN(
3697 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3699 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3702 width = title->width - crop[2] - crop[3];
3704 height = title->height - crop[0] - crop[1];
3706 width = MOD_ROUND(width, mod);
3707 height = MOD_ROUND(height, mod);
3709 // Adjust dims according to max values
3711 height = MIN(height, max_height);
3713 width = MIN(width, max_width);
3717 job->anamorphic.mode = pic_par;
3718 // The scaler crashes if the dimensions are not divisible by 2
3719 // Align mod 2. And so does something in x264_encoder_headers()
3721 job->anamorphic.par_width = title->pixel_aspect_width;
3722 job->anamorphic.par_height = title->pixel_aspect_height;
3723 job->anamorphic.dar_width = 0;
3724 job->anamorphic.dar_height = 0;
3726 if (keep_height && pic_par == 2)
3727 width = ((double)height * crop_width / crop_height) + mod / 2;
3729 job->height = height;
3730 job->maxWidth = max_width;
3731 job->maxHeight = max_height;
3732 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3733 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3734 if (job->anamorphic.mode == 3 && !keep_aspect)
3736 job->anamorphic.keep_display_aspect = 0;
3737 if (mode & GHB_PIC_KEEP_PAR)
3739 job->anamorphic.par_width =
3740 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3741 job->anamorphic.par_height =
3742 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3746 job->anamorphic.dar_width =
3747 ghb_settings_get_int(ud->settings,
3748 "PictureDisplayWidth");
3749 job->anamorphic.dar_height = height;
3754 job->anamorphic.keep_display_aspect = 1;
3756 hb_set_anamorphic_size( job, &width, &height,
3757 &par_width, &par_height );
3758 if (job->anamorphic.mode == 3 && !keep_aspect &&
3759 mode & GHB_PIC_KEEP_PAR)
3761 // hb_set_anamorphic_size reduces the par, which we
3762 // don't want in this case because the user is
3763 // explicitely specifying it.
3764 par_width = ghb_settings_get_int(ud->settings,
3766 par_height = ghb_settings_get_int(ud->settings,
3767 "PicturePARHeight");
3772 job->anamorphic.mode = pic_par;
3776 gint new_width, new_height;
3778 // Compute pixel aspect ration.
3779 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3780 // Must scale so that par becomes 1:1
3781 // Try to keep largest dimension
3782 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3783 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3785 if (max_width && new_width > max_width)
3787 height = new_height;
3789 else if (max_height && new_height > max_height)
3793 else if (keep_width)
3795 height = new_height;
3797 else if (keep_height)
3801 else if (width > new_width)
3803 height = new_height;
3809 g_debug("new w %d h %d\n", width, height);
3811 width = MOD_ROUND(width, mod);
3812 height = MOD_ROUND(height, mod);
3814 height = MIN(height, max_height);
3816 width = MIN(width, max_width);
3817 par_width = par_height = 1;
3819 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3820 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3822 gint disp_width, dar_width, dar_height;
3825 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3826 hb_reduce(&dar_width, &dar_height, disp_width, height);
3828 gint iaspect = dar_width * 9 / dar_height;
3829 if (dar_width > 2 * dar_height)
3831 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3833 else if (iaspect <= 16 && iaspect >= 15)
3835 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3837 else if (iaspect <= 12 && iaspect >= 11)
3839 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3843 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3845 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3847 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3848 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3849 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3850 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3855 set_preview_job_settings(hb_job_t *job, GValue *settings)
3857 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3858 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3859 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3860 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3862 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3864 ghb_settings_combo_int(settings, "PictureModulus");
3865 job->width = ghb_settings_get_int(settings, "scale_width");
3866 job->height = ghb_settings_get_int(settings, "scale_height");
3867 if (ghb_settings_get_boolean(settings, "show_crop"))
3869 gdouble xscale = (gdouble)job->width /
3870 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3871 gdouble yscale = (gdouble)job->height /
3872 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3874 job->width += xscale * (job->crop[2] + job->crop[3]);
3875 job->height += yscale * (job->crop[0] + job->crop[1]);
3883 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3886 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3887 job->deinterlace = (decomb == 0) ? 0 : 1;
3891 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3892 job->deinterlace = (deint == 0) ? 0 : 1;
3895 gboolean keep_aspect;
3896 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3897 if (job->anamorphic.mode)
3899 job->anamorphic.par_width = job->title->pixel_aspect_width;
3900 job->anamorphic.par_height = job->title->pixel_aspect_height;
3901 job->anamorphic.dar_width = 0;
3902 job->anamorphic.dar_height = 0;
3904 if (job->anamorphic.mode == 3 && !keep_aspect)
3906 job->anamorphic.keep_display_aspect = 0;
3907 job->anamorphic.par_width =
3908 ghb_settings_get_int(settings, "PicturePARWidth");
3909 job->anamorphic.par_height =
3910 ghb_settings_get_int(settings, "PicturePARHeight");
3914 job->anamorphic.keep_display_aspect = 1;
3920 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3927 if (h_scan == NULL) return 1500;
3928 list = hb_get_titles( h_scan );
3929 title = hb_list_item( list, titleindex );
3930 if (title == NULL) return 1500;
3932 if (job == NULL) return 1500;
3933 size = ghb_settings_get_int(settings, "VideoTargetSize");
3934 return hb_calc_bitrate( job, size );
3938 ghb_validate_filter_string(const gchar *str, gint max_fields)
3944 if (str == NULL || *str == 0) return TRUE;
3947 val = g_strtod(str, &end);
3949 { // Found a numeric value
3951 // negative max_fields means infinate
3952 if (max_fields >= 0 && fields > max_fields) return FALSE;
3966 ghb_validate_filters(signal_user_data_t *ud)
3972 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3974 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3975 if (!decomb_deint && index == 1)
3977 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3978 if (!ghb_validate_filter_string(str, -1))
3980 message = g_strdup_printf(
3981 "Invalid Deinterlace Settings:\n\n%s\n",
3983 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3991 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3994 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3995 if (!ghb_validate_filter_string(str, -1))
3997 message = g_strdup_printf(
3998 "Invalid Detelecine Settings:\n\n%s\n",
4000 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4008 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
4009 if (decomb_deint && index == 1)
4011 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
4012 if (!ghb_validate_filter_string(str, -1))
4014 message = g_strdup_printf(
4015 "Invalid Decomb Settings:\n\n%s\n",
4017 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4025 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
4028 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
4029 if (!ghb_validate_filter_string(str, -1))
4031 message = g_strdup_printf(
4032 "Invalid Denoise Settings:\n\n%s\n",
4034 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4045 ghb_validate_video(signal_user_data_t *ud)
4050 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4051 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
4052 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
4054 // mp4/theora combination is not supported.
4055 message = g_strdup_printf(
4056 "Theora is not supported in the MP4 container.\n\n"
4057 "You should choose a different video codec or container.\n"
4058 "If you continue, FFMPEG will be chosen for you.");
4059 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4065 vcodec = HB_VCODEC_FFMPEG;
4066 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
4072 ghb_validate_subtitles(signal_user_data_t *ud)
4078 if (h_scan == NULL) return FALSE;
4079 list = hb_get_titles( h_scan );
4080 if( !hb_list_count( list ) )
4082 /* No valid title, stop right there */
4083 g_message("No title found.\n");
4089 titleindex = ghb_settings_combo_int(ud->settings, "title");
4090 title = hb_list_item( list, titleindex );
4091 if (title == NULL) return FALSE;
4093 const GValue *slist, *settings;
4094 gint count, ii, source;
4095 gboolean burned, one_burned = FALSE;
4097 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
4098 count = ghb_array_len(slist);
4099 for (ii = 0; ii < count; ii++)
4101 settings = ghb_array_get_nth(slist, ii);
4102 source = ghb_settings_get_int(settings, "SubtitleSource");
4103 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
4104 if (burned && one_burned)
4106 // MP4 can only handle burned vobsubs. make sure there isn't
4107 // already something burned in the list
4108 message = g_strdup_printf(
4109 "Only one subtitle may be burned into the video.\n\n"
4110 "You should change your subtitle selections.\n"
4111 "If you continue, some subtitles will be lost.");
4112 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4124 if (source == SRTSUB)
4128 filename = ghb_settings_get_string(settings, "SrtFile");
4129 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4131 message = g_strdup_printf(
4132 "Srt file does not exist or not a regular file.\n\n"
4133 "You should choose a valid file.\n"
4134 "If you continue, this subtitle will be ignored.");
4135 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
4136 "Cancel", "Continue"))
4150 ghb_select_audio_codec(signal_user_data_t *ud, gint track)
4154 hb_audio_config_t *audio;
4156 if (h_scan == NULL) return -1;
4157 list = hb_get_titles( h_scan );
4158 if( !hb_list_count( list ) )
4165 titleindex = ghb_settings_combo_int(ud->settings, "title");
4166 title = hb_list_item( list, titleindex );
4167 if (title == NULL) return -1;
4169 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4171 if (track < 0 || track >= hb_list_count(title->list_audio))
4174 audio = (hb_audio_config_t *) hb_list_audio_config_item(
4175 title->list_audio, track );
4176 if (mux == HB_MUX_MP4)
4178 if (audio->in.codec == HB_ACODEC_AC3)
4179 return audio->in.codec;
4181 return HB_ACODEC_FAAC;
4185 if (audio->in.codec == HB_ACODEC_AC3 || audio->in.codec == HB_ACODEC_DCA)
4186 return audio->in.codec;
4188 return HB_ACODEC_LAME;
4193 ghb_select_audio_codec_str(signal_user_data_t *ud, gint track)
4197 acodec = ghb_select_audio_codec(ud, track);
4198 for (ii = 0; ii < acodec_opts.count; ii++)
4200 if (acodec_opts.map[ii].ivalue == acodec)
4201 return acodec_opts.map[ii].option;
4207 ghb_validate_audio(signal_user_data_t *ud)
4214 if (h_scan == NULL) return FALSE;
4215 list = hb_get_titles( h_scan );
4216 if( !hb_list_count( list ) )
4218 /* No valid title, stop right there */
4219 g_message("No title found.\n");
4225 titleindex = ghb_settings_combo_int(ud->settings, "title");
4226 title = hb_list_item( list, titleindex );
4227 if (title == NULL) return FALSE;
4228 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4230 const GValue *audio_list;
4233 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
4234 count = ghb_array_len(audio_list);
4235 for (ii = 0; ii < count; ii++)
4238 hb_audio_config_t *taudio;
4240 asettings = ghb_array_get_nth(audio_list, ii);
4241 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4242 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4243 if (codec == HB_ACODEC_MASK)
4246 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4247 title->list_audio, track );
4248 if (!(taudio->in.codec & codec) &&
4249 (codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4251 // Not supported. AC3 is passthrough only, so input must be AC3
4252 message = g_strdup_printf(
4253 "The source does not support Pass-Thru.\n\n"
4254 "You should choose a different audio codec.\n"
4255 "If you continue, one will be chosen for you.");
4256 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4262 if (mux == HB_MUX_MKV)
4264 codec = HB_ACODEC_LAME;
4268 codec = HB_ACODEC_FAAC;
4270 value = ghb_lookup_acodec_value(codec);
4271 ghb_settings_take_value(asettings, "AudioEncoder", value);
4273 gchar *a_unsup = NULL;
4274 gchar *mux_s = NULL;
4275 if (mux == HB_MUX_MP4)
4278 // mp4/vorbis|DTS combination is not supported.
4279 if (codec == HB_ACODEC_VORBIS)
4282 codec = HB_ACODEC_FAAC;
4284 if (codec == HB_ACODEC_DCA)
4287 codec = HB_ACODEC_FAAC;
4292 message = g_strdup_printf(
4293 "%s is not supported in the %s container.\n\n"
4294 "You should choose a different audio codec.\n"
4295 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4296 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4302 value = ghb_lookup_acodec_value(codec);
4303 ghb_settings_take_value(asettings, "AudioEncoder", value);
4305 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4306 gboolean allow_mono = TRUE;
4307 gboolean allow_stereo = TRUE;
4308 gboolean allow_dolby = TRUE;
4309 gboolean allow_dpl2 = TRUE;
4310 gboolean allow_6ch = TRUE;
4312 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4314 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4316 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4317 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4318 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4319 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4321 (codec & ~HB_ACODEC_LAME) &&
4322 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4323 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4325 gchar *mix_unsup = NULL;
4326 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4330 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4332 mix_unsup = "stereo";
4334 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4336 mix_unsup = "Dolby";
4338 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4340 mix_unsup = "Dolby Pro Logic II";
4342 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4344 mix_unsup = "6 Channel";
4348 message = g_strdup_printf(
4349 "The source audio does not support %s mixdown.\n\n"
4350 "You should choose a different mixdown.\n"
4351 "If you continue, one will be chosen for you.", mix_unsup);
4352 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4358 mix = ghb_get_best_mix(titleindex, track, codec, mix);
4359 value = get_amix_value(mix);
4360 ghb_settings_take_value(asettings, "AudioMixdown", value);
4367 ghb_validate_vquality(GValue *settings)
4373 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4374 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4376 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4377 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4381 case HB_VCODEC_X264:
4387 case HB_VCODEC_FFMPEG:
4393 case HB_VCODEC_THEORA:
4405 if (vquality < min || vquality > max)
4407 message = g_strdup_printf(
4408 "Interesting video quality choise: %d\n\n"
4409 "Typical values range from %d to %d.\n"
4410 "Are you sure you wish to use this setting?",
4411 (gint)vquality, min, max);
4412 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4413 "Cancel", "Continue"))
4425 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4430 static gchar *x264opts;
4432 gboolean tweaks = FALSE;
4433 gchar *detel_str = NULL;
4434 gchar *decomb_str = NULL;
4435 gchar *deint_str = NULL;
4436 gchar *deblock_str = NULL;
4437 gchar *denoise_str = NULL;
4438 gchar *dest_str = NULL;
4440 g_debug("add_job()\n");
4441 if (h == NULL) return;
4442 list = hb_get_titles( h );
4443 if( !hb_list_count( list ) )
4445 /* No valid title, stop right there */
4449 title = hb_list_item( list, titleindex );
4450 if (title == NULL) return;
4452 /* Set job settings */
4454 if (job == NULL) return;
4456 job->angle = ghb_settings_get_int(js, "angle");
4457 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4458 if (job->start_at_preview)
4460 job->seek_points = ghb_settings_get_int(js, "preview_count");
4461 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4464 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4465 job->mux = ghb_settings_combo_int(js, "FileFormat");
4466 if (job->mux == HB_MUX_MP4)
4468 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4469 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4473 job->largeFileSize = FALSE;
4474 job->mp4_optimize = FALSE;
4476 if (!job->start_at_preview)
4479 gint num_chapters = hb_list_count(title->list_chapter);
4480 gint duration = title->duration / 90000;
4481 job->chapter_start = 1;
4482 job->chapter_end = num_chapters;
4484 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4486 start = ghb_settings_get_int(js, "start_point");
4487 end = ghb_settings_get_int(js, "end_point");
4488 job->chapter_start = MIN( num_chapters, start );
4489 job->chapter_end = MAX( job->chapter_start, end );
4492 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4494 job->chapter_start = 1;
4495 job->chapter_end = num_chapters;
4496 start = ghb_settings_get_int(js, "start_point");
4497 end = ghb_settings_get_int(js, "end_point");
4498 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4499 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4502 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4504 job->chapter_start = 1;
4505 job->chapter_end = num_chapters;
4506 start = ghb_settings_get_int(js, "start_point");
4507 end = ghb_settings_get_int(js, "end_point");
4509 max_frames = (gint64)duration * title->rate / title->rate_base;
4510 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4511 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4512 job->frame_to_start;
4514 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4515 if (job->chapter_start == job->chapter_end)
4516 job->chapter_markers = 0;
4517 if ( job->chapter_markers )
4524 chapters = ghb_settings_get_value(js, "chapter_list");
4525 count = ghb_array_len(chapters);
4526 for(chap = 0; chap < count; chap++)
4528 hb_chapter_t * chapter_s;
4532 chapter = ghb_array_get_nth(chapters, chap);
4533 name = ghb_value_string(chapter);
4536 name = g_strdup_printf ("Chapter %2d", chap+1);
4538 chapter_s = hb_list_item( job->title->list_chapter, chap);
4539 strncpy(chapter_s->title, name, 1023);
4540 chapter_s->title[1023] = '\0';
4545 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4546 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4547 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4548 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4551 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4552 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4553 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4555 job->deinterlace = (deint != 0) ? 1 : 0;
4557 job->deinterlace = 0;
4558 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4560 gboolean keep_aspect;
4561 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4562 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4563 job->modulus = ghb_settings_combo_int(js, "PictureModulus");
4564 if (job->anamorphic.mode)
4566 job->anamorphic.par_width = title->pixel_aspect_width;
4567 job->anamorphic.par_height = title->pixel_aspect_height;
4568 job->anamorphic.dar_width = 0;
4569 job->anamorphic.dar_height = 0;
4571 if (job->anamorphic.mode == 3 && !keep_aspect)
4573 job->anamorphic.keep_display_aspect = 0;
4574 job->anamorphic.par_width =
4575 ghb_settings_get_int(js, "PicturePARWidth");
4576 job->anamorphic.par_height =
4577 ghb_settings_get_int(js, "PicturePARHeight");
4581 job->anamorphic.keep_display_aspect = 1;
4585 /* Add selected filters */
4586 job->filters = hb_list_init();
4587 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4592 if (detel_opts.map[detel].svalue != NULL)
4593 detel_str = g_strdup(detel_opts.map[detel].svalue);
4596 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4597 hb_filter_detelecine.settings = detel_str;
4598 hb_list_add( job->filters, &hb_filter_detelecine );
4600 if ( decomb_deint && decomb )
4604 if (decomb_opts.map[decomb].svalue != NULL)
4605 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4608 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4609 hb_filter_decomb.settings = decomb_str;
4610 hb_list_add( job->filters, &hb_filter_decomb );
4612 if( job->deinterlace )
4616 if (deint_opts.map[deint].svalue != NULL)
4617 deint_str = g_strdup(deint_opts.map[deint].svalue);
4620 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4621 hb_filter_deinterlace.settings = deint_str;
4622 hb_list_add( job->filters, &hb_filter_deinterlace );
4624 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4627 deblock_str = g_strdup_printf("%d", deblock);
4628 hb_filter_deblock.settings = deblock_str;
4629 hb_list_add( job->filters, &hb_filter_deblock );
4631 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4636 if (denoise_opts.map[denoise].svalue != NULL)
4637 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4640 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4641 hb_filter_denoise.settings = denoise_str;
4642 hb_list_add( job->filters, &hb_filter_denoise );
4644 job->width = ghb_settings_get_int(js, "scale_width");
4645 job->height = ghb_settings_get_int(js, "scale_height");
4647 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4648 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4650 // mp4/theora combination is not supported.
4651 job->vcodec = HB_VCODEC_FFMPEG;
4653 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4655 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4657 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4660 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4661 job->vquality = vquality;
4664 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4666 job->vquality = -1.0;
4667 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4670 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4673 job->vrate = title->rate;
4674 job->vrate_base = title->rate_base;
4679 job->vrate = 27000000;
4680 job->vrate_base = vrate;
4681 gboolean pfr = ghb_settings_get_boolean(js, "VideoFrameratePFR");
4688 const GValue *audio_list;
4692 audio_list = ghb_settings_get_value(js, "audio_list");
4693 count = ghb_array_len(audio_list);
4694 for (ii = 0; ii < count; ii++)
4697 hb_audio_config_t audio;
4698 hb_audio_config_t *taudio;
4700 hb_audio_config_init(&audio);
4701 asettings = ghb_array_get_nth(audio_list, ii);
4702 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4703 audio.out.track = tcount;
4704 audio.out.codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4705 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4706 title->list_audio, audio.in.track );
4707 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4709 if (!(taudio->in.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)))
4712 // AC3/DTS is passthrough only, so input must be AC3/DTS
4713 if (job->mux == HB_MUX_MKV)
4715 audio.out.codec = HB_ACODEC_LAME;
4719 audio.out.codec = HB_ACODEC_FAAC;
4724 audio.out.codec &= taudio->in.codec;
4727 if ((job->mux == HB_MUX_MP4) &&
4728 ((audio.out.codec & HB_ACODEC_DCA) ||
4729 (audio.out.codec & HB_ACODEC_VORBIS)))
4731 // mp4/mp3|dts|vorbis combination is not supported.
4732 audio.out.codec = HB_ACODEC_FAAC;
4734 audio.out.dynamic_range_compression =
4735 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4736 if (audio.out.dynamic_range_compression < 1.0)
4737 audio.out.dynamic_range_compression = 0.0;
4739 // It would be better if this were done in libhb for us, but its not yet.
4740 if (audio.out.codec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
4742 audio.out.mixdown = 0;
4748 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4749 if (audio.out.mixdown == HB_AMIXDOWN_MONO)
4751 else if (audio.out.mixdown == HB_AMIXDOWN_6CH)
4756 // Make sure the mixdown is valid and pick a new one if not.
4757 audio.out.mixdown = ghb_get_best_mix(titleindex,
4758 audio.in.track, audio.out.codec, audio.out.mixdown);
4760 ghb_settings_combo_int(asettings, "AudioBitrate");
4761 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4762 if (srate == 0) // 0 is same as source
4763 audio.out.samplerate = taudio->in.samplerate;
4765 audio.out.samplerate = srate;
4767 audio.out.bitrate = ghb_get_best_audio_bitrate(
4768 audio.out.codec, audio.out.bitrate, channels);
4771 // Add it to the jobs audio list
4772 hb_audio_add( job, &audio );
4775 // I was tempted to move this up with the reset of the video quality
4776 // settings, but I suspect the settings above need to be made
4777 // first in order for hb_calc_bitrate to be accurate.
4778 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4782 size = ghb_settings_get_int(js, "VideoTargetSize");
4783 job->vbitrate = hb_calc_bitrate( job, size );
4784 job->vquality = -1.0;
4787 dest_str = ghb_settings_get_string(js, "destination");
4788 job->file = dest_str;
4790 const GValue *subtitle_list;
4792 gboolean force, burned, def, one_burned = FALSE;
4794 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4795 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4796 count = ghb_array_len(subtitle_list);
4797 for (ii = 0; ii < count; ii++)
4802 ssettings = ghb_array_get_nth(subtitle_list, ii);
4804 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4805 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4806 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4807 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4809 if (source == SRTSUB)
4811 hb_subtitle_config_t sub_config;
4812 gchar *filename, *lang, *code;
4814 filename = ghb_settings_get_string(ssettings, "SrtFile");
4815 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4819 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4820 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4821 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4822 strncpy(sub_config.src_filename, filename, 128);
4823 strncpy(sub_config.src_codeset, code, 40);
4824 sub_config.force = 0;
4825 sub_config.dest = PASSTHRUSUB;
4826 sub_config.default_track = def;
4828 hb_srt_add( job, &sub_config, lang);
4836 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4841 job->select_subtitle_config.dest = PASSTHRUSUB;
4845 // Only allow one subtitle to be burned into the video
4848 job->select_subtitle_config.dest = RENDERSUB;
4851 job->select_subtitle_config.force = force;
4852 job->select_subtitle_config.default_track = def;
4853 job->indepth_scan = 1;
4854 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4856 else if (subtitle >= 0)
4858 hb_subtitle_t * subt;
4859 hb_subtitle_config_t sub_config;
4861 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4864 sub_config = subt->config;
4865 if (!burned && subt->format == PICTURESUB)
4867 sub_config.dest = PASSTHRUSUB;
4869 else if ( burned && subt->format == PICTURESUB )
4871 // Only allow one subtitle to be burned into the video
4876 sub_config.force = force;
4877 sub_config.default_track = def;
4878 hb_subtitle_add( job, &sub_config, subtitle );
4883 // TODO: libhb holds onto a reference to the x264opts and is not
4884 // finished with it until encoding the job is done. But I can't
4885 // find a way to get at the job before it is removed in order to
4886 // free up the memory I am allocating here.
4887 // The short story is THIS LEAKS.
4888 x264opts = ghb_build_x264opts_string(js);
4890 if( *x264opts == '\0' )
4896 if (job->indepth_scan == 1)
4898 // Subtitle scan. Look for subtitle matching audio language
4901 * When subtitle scan is enabled do a fast pre-scan job
4902 * which will determine which subtitles to enable, if any.
4905 job->indepth_scan = 1;
4906 job->x264opts = NULL;
4909 * Add the pre-scan job
4911 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4915 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4916 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4919 * If subtitle_scan is enabled then only turn it on
4920 * for the second pass and then off again for the
4924 job->indepth_scan = 0;
4927 * If turbo options have been selected then append them
4928 * to the x264opts now (size includes one ':' and the '\0')
4930 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4932 gchar *tmp_x264opts;
4936 badapt = ghb_lookup_badapt(x264opts);
4939 extra_opts = g_strdup_printf("%s", turbo_opts);
4943 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4948 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4953 * No x264opts to modify, but apply the turbo options
4954 * anyway as they may be modifying defaults
4956 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4960 job->x264opts = tmp_x264opts;
4964 job->x264opts = x264opts;
4966 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4968 //if (job->x264opts != NULL)
4969 // g_free(job->x264opts);
4973 * On the second pass we turn off subtitle scan so that we
4974 * can actually encode using any subtitles that were auto
4975 * selected in the first pass (using the whacky select-subtitle
4976 * attribute of the job).
4978 job->indepth_scan = 0;
4979 job->x264opts = x264opts;
4980 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4982 //if (job->x264opts != NULL)
4983 // g_free(job->x264opts);
4987 job->x264opts = x264opts;
4988 job->indepth_scan = 0;
4990 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4992 //if (job->x264opts != NULL)
4993 // g_free(job->x264opts);
4996 // clean up audio list
4997 gint num_audio_tracks = hb_list_count(job->list_audio);
4998 for(ii = 0; ii < num_audio_tracks; ii++)
5000 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
5001 hb_list_rem(job->list_audio, audio);
5005 // clean up subtitle list
5006 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
5007 for(ii = 0; ii < num_subtitle_tracks; ii++)
5009 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
5010 hb_list_rem(job->list_subtitle, subtitle);
5014 if (detel_str) g_free(detel_str);
5015 if (decomb_str) g_free(decomb_str);
5016 if (deint_str) g_free(deint_str);
5017 if (deblock_str) g_free(deblock_str);
5018 if (denoise_str) g_free(denoise_str);
5019 if (dest_str) g_free(dest_str);
5023 ghb_add_job(GValue *js, gint unique_id)
5025 // Since I'm doing a scan of the single title I want just prior
5026 // to adding the job, there is only the one title to choose from.
5027 add_job(h_queue, js, unique_id, 0);
5031 ghb_add_live_job(GValue *js, gint unique_id)
5033 // Since I'm doing a scan of the single title I want just prior
5034 // to adding the job, there is only the one title to choose from.
5035 gint titleindex = ghb_settings_combo_int(js, "title");
5036 add_job(h_scan, js, unique_id, titleindex);
5040 ghb_remove_job(gint unique_id)
5045 // Multiples passes all get the same id
5047 // Go backwards through list, so reordering doesn't screw me.
5048 ii = hb_count(h_queue) - 1;
5049 while ((job = hb_job(h_queue, ii--)) != NULL)
5051 if ((job->sequence_id & 0xFFFFFF) == unique_id)
5052 hb_rem(h_queue, job);
5059 hb_start( h_queue );
5069 ghb_start_live_encode()
5075 ghb_stop_live_encode()
5084 hb_get_state2( h_queue, &s );
5086 if( s.state == HB_STATE_PAUSED )
5088 hb_status.queue.state &= ~GHB_STATE_PAUSED;
5089 hb_resume( h_queue );
5093 hb_status.queue.state |= GHB_STATE_PAUSED;
5094 hb_pause( h_queue );
5109 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5112 gint channels = gdk_pixbuf_get_n_channels (pb);
5113 gint stride = gdk_pixbuf_get_rowstride (pb);
5115 for (jj = 0; jj < width; jj++)
5117 dst = pixels + y * stride + (x+jj) * channels;
5118 for (ii = 0; ii < len; ii++)
5139 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5142 gint channels = gdk_pixbuf_get_n_channels (pb);
5143 gint stride = gdk_pixbuf_get_rowstride (pb);
5145 for (jj = 0; jj < width; jj++)
5147 dst = pixels + (y+jj) * stride + x * channels;
5148 for (ii = 0; ii < len; ii++)
5169 gint line_width = 8;
5176 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
5181 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
5183 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
5189 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
5191 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
5197 ghb_get_preview_image(
5200 signal_user_data_t *ud,
5208 settings = ud->settings;
5209 list = hb_get_titles( h_scan );
5210 if( !hb_list_count( list ) )
5212 /* No valid title, stop right there */
5215 title = hb_list_item( list, titleindex );
5216 if (title == NULL) return NULL;
5217 if (title->job == NULL) return NULL;
5218 set_preview_job_settings(title->job, settings);
5220 // hb_get_preview doesn't compensate for anamorphic, so lets
5221 // calculate scale factors
5222 gint width, height, par_width = 1, par_height = 1;
5223 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5226 hb_set_anamorphic_size( title->job, &width, &height,
5227 &par_width, &par_height );
5230 // Make sure we have a big enough buffer to receive the image from libhb
5231 gint dstWidth = title->job->width;
5232 gint dstHeight= title->job->height;
5234 static guint8 *buffer = NULL;
5235 static gint bufferSize = 0;
5238 newSize = dstWidth * dstHeight * 4;
5239 if( bufferSize < newSize )
5241 bufferSize = newSize;
5242 buffer = (guint8*) g_realloc( buffer, bufferSize );
5244 hb_get_preview( h_scan, title, index, buffer );
5246 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5247 // libhb's format something suitable.
5249 // The image data returned by hb_get_preview is 4 bytes per pixel,
5250 // BGRA format. Alpha is ignored.
5252 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5253 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5255 guint32 *src = (guint32*)buffer;
5256 guint8 *dst = pixels;
5259 gint channels = gdk_pixbuf_get_n_channels (preview);
5260 gint stride = gdk_pixbuf_get_rowstride (preview);
5263 for (ii = 0; ii < dstHeight; ii++)
5266 for (jj = 0; jj < dstWidth; jj++)
5268 tmp[0] = src[0] >> 16;
5269 tmp[1] = src[0] >> 8;
5270 tmp[2] = src[0] >> 0;
5276 gint w = ghb_settings_get_int(settings, "scale_width");
5277 gint h = ghb_settings_get_int(settings, "scale_height");
5278 ghb_par_scale(ud, &w, &h, par_width, par_height);
5280 gint c0, c1, c2, c3;
5281 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5282 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5283 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5284 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5286 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5287 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5289 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5292 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5296 gint orig_w, orig_h;
5299 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5303 ss = gdk_screen_get_default();
5304 s_w = gdk_screen_get_width(ss);
5305 s_h = gdk_screen_get_height(ss);
5309 if (dstWidth > s_w * factor / 100)
5311 dstWidth = s_w * factor / 100;
5312 dstHeight = dstHeight * dstWidth / orig_w;
5314 if (dstHeight > s_h * factor / 100)
5316 dstHeight = s_h * factor / 100;
5317 dstWidth = dstWidth * dstHeight / orig_h;
5319 xscale *= (gdouble)dstWidth / orig_w;
5320 yscale *= (gdouble)dstHeight / orig_h;
5321 w *= (gdouble)dstWidth / orig_w;
5322 h *= (gdouble)dstHeight / orig_h;
5324 GdkPixbuf *scaled_preview;
5325 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5326 if (ghb_settings_get_boolean(settings, "show_crop"))
5333 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5335 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5337 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5339 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5341 g_object_unref (preview);
5342 return scaled_preview;
5346 sanitize_volname(gchar *name)
5371 ghb_dvd_volname(const gchar *device)
5374 name = hb_dvd_name((gchar*)device);
5375 if (name != NULL && name[0] != 0)
5377 name = g_strdup(name);
5378 sanitize_volname(name);