1 /***************************************************************************
4 * Fri Mar 28 10:38:44 2008
5 * Copyright 2008 John Stebbins
6 * <john at stebbins dot name>
7 ****************************************************************************/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
29 #include <glib/gstdio.h>
30 #include "hb-backend.h"
32 #include "callbacks.h"
33 #include "subtitlehandler.h"
34 #include "audiohandler.h"
35 #include "x264handler.h"
43 const gchar *shortOpt;
54 static gchar **index_str = NULL;
55 static gint index_str_size = 0;
58 index_str_init(gint max_index)
62 if (max_index+1 > index_str_size)
64 index_str = realloc(index_str, (max_index+1) * sizeof(char*));
65 for (ii = index_str_size; ii <= max_index; ii++)
67 index_str[ii] = g_strdup_printf("%d", ii);
69 index_str_size = max_index + 1;
73 static options_map_t d_point_to_point_opts[] =
75 {"Chapters:", "chapter", 0, "0"},
76 {"Seconds:", "time", 1, "1"},
77 {"Frames:", "frame", 2, "2"},
79 combo_opts_t point_to_point_opts =
81 sizeof(d_point_to_point_opts)/sizeof(options_map_t),
85 static options_map_t d_when_complete_opts[] =
87 {"Do Nothing", "nothing", 0, "0"},
88 {"Show Notification", "notify", 1, "1"},
89 {"Put Computer To Sleep", "sleep", 2, "2"},
90 {"Shutdown Computer", "shutdown", 3, "3"},
92 combo_opts_t when_complete_opts =
94 sizeof(d_when_complete_opts)/sizeof(options_map_t),
98 static options_map_t d_par_opts[] =
100 {"Off", "0", 0, "0"},
101 {"Strict", "1", 1, "1"},
102 {"Loose", "2", 2, "2"},
103 {"Custom", "3", 3, "3"},
105 combo_opts_t par_opts =
107 sizeof(d_par_opts)/sizeof(options_map_t),
111 static options_map_t d_alignment_opts[] =
116 {"16", "16", 16, "16"},
118 combo_opts_t alignment_opts =
120 sizeof(d_alignment_opts)/sizeof(options_map_t),
124 static options_map_t d_logging_opts[] =
130 combo_opts_t logging_opts =
132 sizeof(d_logging_opts)/sizeof(options_map_t),
136 static options_map_t d_log_longevity_opts[] =
138 {"Week", "week", 7, "7"},
139 {"Month", "month", 30, "30"},
140 {"Year", "year", 365, "365"},
141 {"Immortal", "immortal", 366, "366"},
143 combo_opts_t log_longevity_opts =
145 sizeof(d_log_longevity_opts)/sizeof(options_map_t),
149 static options_map_t d_appcast_update_opts[] =
151 {"Never", "never", 0, "never"},
152 {"Daily", "daily", 1, "daily"},
153 {"Weekly", "weekly", 2, "weekly"},
154 {"Monthly", "monthly", 3, "monthly"},
156 combo_opts_t appcast_update_opts =
158 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
159 d_appcast_update_opts
162 static options_map_t d_vqual_granularity_opts[] =
164 {"0.2", "0.2", 0.2, "0.2"},
165 {"0.25", "0.25", 0.25, "0.25"},
166 {"0.5", "0.5", 0.5, "0.5"},
169 combo_opts_t vqual_granularity_opts =
171 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
172 d_vqual_granularity_opts
175 static options_map_t d_container_opts[] =
177 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
178 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
180 combo_opts_t container_opts =
182 sizeof(d_container_opts)/sizeof(options_map_t),
186 static options_map_t d_detel_opts[] =
188 {"Off", "off", 0, ""},
189 {"Custom", "custom", 1, ""},
190 {"Default","default",2, NULL},
192 combo_opts_t detel_opts =
194 sizeof(d_detel_opts)/sizeof(options_map_t),
198 static options_map_t d_decomb_opts[] =
200 {"Off", "off", 0, ""},
201 {"Custom", "custom", 1, ""},
202 {"Default","default",2, NULL},
204 combo_opts_t decomb_opts =
206 sizeof(d_decomb_opts)/sizeof(options_map_t),
210 static options_map_t d_deint_opts[] =
212 {"Off", "off", 0, ""},
213 {"Custom", "custom", 1, ""},
214 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
215 {"Slow", "slow", 3, "2:-1:-1:0:1"},
216 {"Slower", "slower", 4, "0:-1:-1:0:1"},
218 combo_opts_t deint_opts =
220 sizeof(d_deint_opts)/sizeof(options_map_t),
224 static options_map_t d_denoise_opts[] =
226 {"Off", "off", 0, ""},
227 {"Custom", "custom", 1, ""},
228 {"Weak", "weak", 2, "2:1:2:3"},
229 {"Medium", "medium", 3, "3:2:2:3"},
230 {"Strong", "strong", 4, "7:7:5:5"},
232 combo_opts_t denoise_opts =
234 sizeof(d_denoise_opts)/sizeof(options_map_t),
238 static options_map_t d_vcodec_opts[] =
240 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
241 {"MPEG-4 (FFmpeg)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
242 {"VP3 (Theora)", "theora", HB_VCODEC_THEORA, ""},
244 combo_opts_t vcodec_opts =
246 sizeof(d_vcodec_opts)/sizeof(options_map_t),
250 static options_map_t d_acodec_opts[] =
252 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
253 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
254 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
255 {"AC3 (ffmpeg)", "ac3", HB_ACODEC_AC3, "ac3"},
256 {"AC3 (pass-thru)", "ac3pass", HB_ACODEC_AC3_PASS, "ac3pass"},
257 {"DTS (pass-thru)", "dtspass", HB_ACODEC_DCA_PASS, "dtspass"},
258 {"Choose For Me", "auto", HB_ACODEC_ANY, "auto"},
260 combo_opts_t acodec_opts =
262 sizeof(d_acodec_opts)/sizeof(options_map_t),
266 static options_map_t d_direct_opts[] =
268 {"None", "none", 0, "none"},
269 {"Spatial", "spatial", 1, "spatial"},
270 {"Temporal", "temporal", 2, "temporal"},
271 {"Automatic", "auto", 3, "auto"},
273 combo_opts_t direct_opts =
275 sizeof(d_direct_opts)/sizeof(options_map_t),
279 static options_map_t d_badapt_opts[] =
281 {"Off", "0", 0, "0"},
282 {"Fast", "1", 1, "1"},
283 {"Optimal", "2", 2, "2"},
285 combo_opts_t badapt_opts =
287 sizeof(d_badapt_opts)/sizeof(options_map_t),
291 static options_map_t d_bpyramid_opts[] =
293 {"Off", "none", 0, "none"},
294 {"Strict", "strict", 1, "strict"},
295 {"Normal", "normal", 2, "normal"},
297 combo_opts_t bpyramid_opts =
299 sizeof(d_bpyramid_opts)/sizeof(options_map_t),
303 static options_map_t d_weightp_opts[] =
305 {"Off", "0", 0, "0"},
306 {"Blind", "1", 1, "1"},
307 {"Smart", "2", 2, "2"},
309 combo_opts_t weightp_opts =
311 sizeof(d_weightp_opts)/sizeof(options_map_t),
315 static options_map_t d_me_opts[] =
317 {"Diamond", "dia", 0, "dia"},
318 {"Hexagon", "hex", 1, "hex"},
319 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
320 {"Exhaustive", "esa", 3, "esa"},
321 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
323 combo_opts_t me_opts =
325 sizeof(d_me_opts)/sizeof(options_map_t),
329 static options_map_t d_subme_opts[] =
331 {"0: SAD, no subpel", "0", 0, "0"},
332 {"1: SAD, qpel", "1", 1, "1"},
333 {"2: SATD, qpel", "2", 2, "2"},
334 {"3: SATD: multi-qpel", "3", 3, "3"},
335 {"4: SATD, qpel on all", "4", 4, "4"},
336 {"5: SATD, multi-qpel on all", "5", 5, "5"},
337 {"6: RD in I/P-frames", "6", 6, "6"},
338 {"7: RD in all frames", "7", 7, "7"},
339 {"8: RD refine in I/P-frames", "8", 8, "8"},
340 {"9: RD refine in all frames", "9", 9, "9"},
341 {"10: QPRD in all frames", "10", 10, "10"},
343 combo_opts_t subme_opts =
345 sizeof(d_subme_opts)/sizeof(options_map_t),
349 static options_map_t d_analyse_opts[] =
351 {"Most", "p8x8,b8x8,i8x8,i4x4", 0, "p8x8,b8x8,i8x8,i4x4"},
352 {"None", "none", 1, "none"},
353 {"Some", "i4x4,i8x8", 2, "i4x4,i8x8"},
354 {"All", "all", 3, "all"},
355 {"Custom", "custom", 4, "all"},
357 combo_opts_t analyse_opts =
359 sizeof(d_analyse_opts)/sizeof(options_map_t),
363 static options_map_t d_trellis_opts[] =
365 {"Off", "0", 0, "0"},
366 {"Encode only", "1", 1, "1"},
367 {"Always", "2", 2, "2"},
369 combo_opts_t trellis_opts =
371 sizeof(d_trellis_opts)/sizeof(options_map_t),
375 combo_opts_t subtitle_opts =
381 combo_opts_t title_opts =
387 combo_opts_t audio_track_opts =
399 combo_name_map_t combo_name_map[] =
401 {"PtoPType", &point_to_point_opts},
402 {"WhenComplete", &when_complete_opts},
403 {"PicturePAR", &par_opts},
404 {"PictureModulus", &alignment_opts},
405 {"LoggingLevel", &logging_opts},
406 {"LogLongevity", &log_longevity_opts},
407 {"check_updates", &appcast_update_opts},
408 {"VideoQualityGranularity", &vqual_granularity_opts},
409 {"FileFormat", &container_opts},
410 {"PictureDeinterlace", &deint_opts},
411 {"PictureDecomb", &decomb_opts},
412 {"PictureDetelecine", &detel_opts},
413 {"PictureDenoise", &denoise_opts},
414 {"VideoEncoder", &vcodec_opts},
415 {"AudioEncoder", &acodec_opts},
416 {"x264_direct", &direct_opts},
417 {"x264_b_adapt", &badapt_opts},
418 {"x264_bpyramid", &bpyramid_opts},
419 {"x264_weighted_pframes", &weightp_opts},
420 {"x264_me", &me_opts},
421 {"x264_subme", &subme_opts},
422 {"x264_analyse", &analyse_opts},
423 {"x264_trellis", &trellis_opts},
424 {"SubtitleTrack", &subtitle_opts},
425 {"title", &title_opts},
426 {"AudioTrack", &audio_track_opts},
430 const gchar *srt_codeset_table[] =
469 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
472 typedef struct iso639_lang_t
474 char * eng_name; /* Description in English */
475 char * native_name; /* Description in native language */
476 char * iso639_1; /* ISO-639-1 (2 characters) code */
477 char * iso639_2; /* ISO-639-2/t (3 character) code */
478 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
482 const iso639_lang_t ghb_language_table[] =
484 { "Any", "", "zz", "und" },
485 { "Afar", "", "aa", "aar" },
486 { "Abkhazian", "", "ab", "abk" },
487 { "Afrikaans", "", "af", "afr" },
488 { "Akan", "", "ak", "aka" },
489 { "Albanian", "", "sq", "sqi", "alb" },
490 { "Amharic", "", "am", "amh" },
491 { "Arabic", "", "ar", "ara" },
492 { "Aragonese", "", "an", "arg" },
493 { "Armenian", "", "hy", "hye", "arm" },
494 { "Assamese", "", "as", "asm" },
495 { "Avaric", "", "av", "ava" },
496 { "Avestan", "", "ae", "ave" },
497 { "Aymara", "", "ay", "aym" },
498 { "Azerbaijani", "", "az", "aze" },
499 { "Bashkir", "", "ba", "bak" },
500 { "Bambara", "", "bm", "bam" },
501 { "Basque", "", "eu", "eus", "baq" },
502 { "Belarusian", "", "be", "bel" },
503 { "Bengali", "", "bn", "ben" },
504 { "Bihari", "", "bh", "bih" },
505 { "Bislama", "", "bi", "bis" },
506 { "Bosnian", "", "bs", "bos" },
507 { "Breton", "", "br", "bre" },
508 { "Bulgarian", "", "bg", "bul" },
509 { "Burmese", "", "my", "mya", "bur" },
510 { "Catalan", "", "ca", "cat" },
511 { "Chamorro", "", "ch", "cha" },
512 { "Chechen", "", "ce", "che" },
513 { "Chinese", "", "zh", "zho", "chi" },
514 { "Church Slavic", "", "cu", "chu" },
515 { "Chuvash", "", "cv", "chv" },
516 { "Cornish", "", "kw", "cor" },
517 { "Corsican", "", "co", "cos" },
518 { "Cree", "", "cr", "cre" },
519 { "Czech", "", "cs", "ces", "cze" },
520 { "Danish", "Dansk", "da", "dan" },
521 { "German", "Deutsch", "de", "deu", "ger" },
522 { "Divehi", "", "dv", "div" },
523 { "Dzongkha", "", "dz", "dzo" },
524 { "English", "English", "en", "eng" },
525 { "Spanish", "Espanol", "es", "spa" },
526 { "Esperanto", "", "eo", "epo" },
527 { "Estonian", "", "et", "est" },
528 { "Ewe", "", "ee", "ewe" },
529 { "Faroese", "", "fo", "fao" },
530 { "Fijian", "", "fj", "fij" },
531 { "French", "Francais", "fr", "fra", "fre" },
532 { "Western Frisian", "", "fy", "fry" },
533 { "Fulah", "", "ff", "ful" },
534 { "Georgian", "", "ka", "kat", "geo" },
535 { "Gaelic (Scots)", "", "gd", "gla" },
536 { "Irish", "", "ga", "gle" },
537 { "Galician", "", "gl", "glg" },
538 { "Manx", "", "gv", "glv" },
539 { "Greek, Modern", "", "el", "ell", "gre" },
540 { "Guarani", "", "gn", "grn" },
541 { "Gujarati", "", "gu", "guj" },
542 { "Haitian", "", "ht", "hat" },
543 { "Hausa", "", "ha", "hau" },
544 { "Hebrew", "", "he", "heb" },
545 { "Herero", "", "hz", "her" },
546 { "Hindi", "", "hi", "hin" },
547 { "Hiri Motu", "", "ho", "hmo" },
548 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
549 { "Igbo", "", "ig", "ibo" },
550 { "Ido", "", "io", "ido" },
551 { "Icelandic", "Islenska", "is", "isl", "ice" },
552 { "Sichuan Yi", "", "ii", "iii" },
553 { "Inuktitut", "", "iu", "iku" },
554 { "Interlingue", "", "ie", "ile" },
555 { "Interlingua", "", "ia", "ina" },
556 { "Indonesian", "", "id", "ind" },
557 { "Inupiaq", "", "ik", "ipk" },
558 { "Italian", "Italiano", "it", "ita" },
559 { "Javanese", "", "jv", "jav" },
560 { "Japanese", "", "ja", "jpn" },
561 { "Kalaallisut", "", "kl", "kal" },
562 { "Kannada", "", "kn", "kan" },
563 { "Kashmiri", "", "ks", "kas" },
564 { "Kanuri", "", "kr", "kau" },
565 { "Kazakh", "", "kk", "kaz" },
566 { "Central Khmer", "", "km", "khm" },
567 { "Kikuyu", "", "ki", "kik" },
568 { "Kinyarwanda", "", "rw", "kin" },
569 { "Kirghiz", "", "ky", "kir" },
570 { "Komi", "", "kv", "kom" },
571 { "Kongo", "", "kg", "kon" },
572 { "Korean", "", "ko", "kor" },
573 { "Kuanyama", "", "kj", "kua" },
574 { "Kurdish", "", "ku", "kur" },
575 { "Lao", "", "lo", "lao" },
576 { "Latin", "", "la", "lat" },
577 { "Latvian", "", "lv", "lav" },
578 { "Limburgan", "", "li", "lim" },
579 { "Lingala", "", "ln", "lin" },
580 { "Lithuanian", "", "lt", "lit" },
581 { "Luxembourgish", "", "lb", "ltz" },
582 { "Luba-Katanga", "", "lu", "lub" },
583 { "Ganda", "", "lg", "lug" },
584 { "Macedonian", "", "mk", "mkd", "mac" },
585 { "Hungarian", "Magyar", "hu", "hun" },
586 { "Marshallese", "", "mh", "mah" },
587 { "Malayalam", "", "ml", "mal" },
588 { "Maori", "", "mi", "mri", "mao" },
589 { "Marathi", "", "mr", "mar" },
590 { "Malay", "", "ms", "msa", "msa" },
591 { "Malagasy", "", "mg", "mlg" },
592 { "Maltese", "", "mt", "mlt" },
593 { "Moldavian", "", "mo", "mol" },
594 { "Mongolian", "", "mn", "mon" },
595 { "Nauru", "", "na", "nau" },
596 { "Navajo", "", "nv", "nav" },
597 { "Dutch", "Nederlands", "nl", "nld", "dut" },
598 { "Ndebele, South", "", "nr", "nbl" },
599 { "Ndebele, North", "", "nd", "nde" },
600 { "Ndonga", "", "ng", "ndo" },
601 { "Nepali", "", "ne", "nep" },
602 { "Norwegian", "Norsk", "no", "nor" },
603 { "Norwegian Nynorsk", "", "nn", "nno" },
604 { "Norwegian Bokmål", "", "nb", "nob" },
605 { "Chichewa; Nyanja", "", "ny", "nya" },
606 { "Occitan", "", "oc", "oci" },
607 { "Ojibwa", "", "oj", "oji" },
608 { "Oriya", "", "or", "ori" },
609 { "Oromo", "", "om", "orm" },
610 { "Ossetian", "", "os", "oss" },
611 { "Panjabi", "", "pa", "pan" },
612 { "Persian", "", "fa", "fas", "per" },
613 { "Pali", "", "pi", "pli" },
614 { "Polish", "", "pl", "pol" },
615 { "Portuguese", "Portugues", "pt", "por" },
616 { "Pushto", "", "ps", "pus" },
617 { "Quechua", "", "qu", "que" },
618 { "Romansh", "", "rm", "roh" },
619 { "Romanian", "", "ro", "ron", "rum" },
620 { "Rundi", "", "rn", "run" },
621 { "Russian", "", "ru", "rus" },
622 { "Sango", "", "sg", "sag" },
623 { "Sanskrit", "", "sa", "san" },
624 { "Serbian", "", "sr", "srp", "scc" },
625 { "Sinhala", "", "si", "sin" },
626 { "Slovak", "", "sk", "slk", "slo" },
627 { "Slovenian", "", "sl", "slv" },
628 { "Northern Sami", "", "se", "sme" },
629 { "Samoan", "", "sm", "smo" },
630 { "Shona", "", "sn", "sna" },
631 { "Sindhi", "", "sd", "snd" },
632 { "Somali", "", "so", "som" },
633 { "Sotho, Southern", "", "st", "sot" },
634 { "Sardinian", "", "sc", "srd" },
635 { "Swati", "", "ss", "ssw" },
636 { "Sundanese", "", "su", "sun" },
637 { "Finnish", "Suomi", "fi", "fin" },
638 { "Swahili", "", "sw", "swa" },
639 { "Swedish", "Svenska", "sv", "swe" },
640 { "Tahitian", "", "ty", "tah" },
641 { "Tamil", "", "ta", "tam" },
642 { "Tatar", "", "tt", "tat" },
643 { "Telugu", "", "te", "tel" },
644 { "Tajik", "", "tg", "tgk" },
645 { "Tagalog", "", "tl", "tgl" },
646 { "Thai", "", "th", "tha" },
647 { "Tibetan", "", "bo", "bod", "tib" },
648 { "Tigrinya", "", "ti", "tir" },
649 { "Tonga", "", "to", "ton" },
650 { "Tswana", "", "tn", "tsn" },
651 { "Tsonga", "", "ts", "tso" },
652 { "Turkmen", "", "tk", "tuk" },
653 { "Turkish", "", "tr", "tur" },
654 { "Twi", "", "tw", "twi" },
655 { "Uighur", "", "ug", "uig" },
656 { "Ukrainian", "", "uk", "ukr" },
657 { "Urdu", "", "ur", "urd" },
658 { "Uzbek", "", "uz", "uzb" },
659 { "Venda", "", "ve", "ven" },
660 { "Vietnamese", "", "vi", "vie" },
661 { "Volapük", "", "vo", "vol" },
662 { "Welsh", "", "cy", "cym", "wel" },
663 { "Walloon", "", "wa", "wln" },
664 { "Wolof", "", "wo", "wol" },
665 { "Xhosa", "", "xh", "xho" },
666 { "Yiddish", "", "yi", "yid" },
667 { "Yoruba", "", "yo", "yor" },
668 { "Zhuang", "", "za", "zha" },
669 { "Zulu", "", "zu", "zul" },
670 {NULL, NULL, NULL, NULL}
672 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
674 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
677 del_tree(const gchar *name, gboolean del_top)
681 if (g_file_test(name, G_FILE_TEST_IS_DIR))
683 GDir *gdir = g_dir_open(name, 0, NULL);
684 file = g_dir_read_name(gdir);
688 path = g_strdup_printf("%s/%s", name, file);
689 del_tree(path, TRUE);
691 file = g_dir_read_name(gdir);
706 return hb_get_version(NULL);
711 signal_user_data_t *ud,
719 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
728 *step = ghb_settings_combo_double(ud->settings,
729 "VideoQualityGranularity");
730 if (*step == 0.2 || *step == 0.5)
732 else if (*step == 0.25)
737 case HB_VCODEC_FFMPEG:
745 case HB_VCODEC_THEORA:
764 find_combo_entry(combo_opts_t *opts, const GValue *gval)
768 if (G_VALUE_TYPE(gval) == G_TYPE_STRING)
771 str = ghb_value_string(gval);
772 for (ii = 0; ii < opts->count; ii++)
774 if (strcmp(opts->map[ii].shortOpt, str) == 0)
782 else if (G_VALUE_TYPE(gval) == G_TYPE_DOUBLE)
785 val = ghb_value_double(gval);
786 for (ii = 0; ii < opts->count; ii++)
788 if (opts->map[ii].ivalue == val)
795 else if (G_VALUE_TYPE(gval) == G_TYPE_INT ||
796 G_VALUE_TYPE(gval) == G_TYPE_BOOLEAN ||
797 G_VALUE_TYPE(gval) == G_TYPE_INT64)
800 val = ghb_value_int64(gval);
801 for (ii = 0; ii < opts->count; ii++)
803 if ((gint64)opts->map[ii].ivalue == val)
814 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
817 const gchar *result = "";
819 ii = find_combo_entry(opts, gval);
820 if (ii < opts->count)
822 result = opts->map[ii].svalue;
828 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
833 ii = find_combo_entry(opts, gval);
834 if (ii < opts->count)
836 result = opts->map[ii].ivalue;
842 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
847 ii = find_combo_entry(opts, gval);
848 if (ii < opts->count)
850 result = opts->map[ii].ivalue;
856 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
859 const gchar *result = "";
861 ii = find_combo_entry(opts, gval);
862 if (ii < opts->count)
864 result = opts->map[ii].option;
870 lookup_mix_int(const GValue *mix)
876 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
878 gchar * str = ghb_value_string(mix);
879 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
881 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
883 result = hb_audio_mixdowns[ii].amixdown;
889 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
890 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
891 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
893 gint val = ghb_value_int(mix);
894 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
896 if (hb_audio_mixdowns[ii].amixdown == val)
898 result = hb_audio_mixdowns[ii].amixdown;
907 lookup_mix_option(const GValue *mix)
910 gchar *result = "None";
913 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
915 gchar *str = ghb_value_string(mix);
916 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
918 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
920 result = hb_audio_mixdowns[ii].human_readable_name;
926 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
927 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
928 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
930 gint val = ghb_value_int(mix);
931 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
933 if (hb_audio_mixdowns[ii].amixdown == val)
935 result = hb_audio_mixdowns[ii].human_readable_name;
944 lookup_mix_string(const GValue *mix)
947 gchar *result = "None";
950 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
952 gchar *str = ghb_value_string(mix);
953 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
955 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
957 result = hb_audio_mixdowns[ii].short_name;
963 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
964 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
965 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
967 gint val = ghb_value_int(mix);
968 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
970 if (hb_audio_mixdowns[ii].amixdown == val)
972 result = hb_audio_mixdowns[ii].short_name;
981 lookup_video_rate_int(const GValue *vrate)
987 str = ghb_value_string(vrate);
988 for (ii = 0; ii < hb_video_rates_count; ii++)
990 if (strcmp(hb_video_rates[ii].string, str) == 0)
992 result = hb_video_rates[ii].rate;
997 // Default to "same as source"
1002 lookup_video_rate_option(const GValue *vrate)
1006 const gchar *result = "Same as source";
1008 str = ghb_value_string(vrate);
1009 for (ii = 0; ii < hb_video_rates_count; ii++)
1011 if (strcmp(hb_video_rates[ii].string, str) == 0)
1013 result = hb_video_rates[ii].string;
1018 // Default to "same as source"
1023 lookup_audio_rate_int(const GValue *rate)
1028 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1030 // Coincidentally, the string "source" will return 0
1031 // which is our flag to use "same as source"
1032 gchar * str = ghb_value_string(rate);
1033 for (ii = 0; ii < hb_audio_rates_count; ii++)
1035 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1037 result = hb_audio_rates[ii].rate;
1043 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1044 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1045 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1047 for (ii = 0; ii < hb_audio_rates_count; ii++)
1049 gint val = ghb_value_int(rate);
1050 if (val == hb_audio_rates[ii].rate)
1052 result = hb_audio_rates[ii].rate;
1061 lookup_audio_rate_option(const GValue *rate)
1064 const gchar *result = "Same as source";
1066 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1068 // Coincidentally, the string "source" will return 0
1069 // which is our flag to use "same as source"
1070 gchar *str = ghb_value_string(rate);
1071 for (ii = 0; ii < hb_audio_rates_count; ii++)
1073 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1075 result = hb_audio_rates[ii].string;
1081 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1082 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1083 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1085 for (ii = 0; ii < hb_audio_rates_count; ii++)
1087 gint val = ghb_value_int(rate);
1088 if (val == hb_audio_rates[ii].rate)
1090 result = hb_audio_rates[ii].string;
1099 ghb_find_closest_audio_rate(gint rate)
1105 for (ii = 0; ii < hb_audio_rates_count; ii++)
1107 if (rate <= hb_audio_rates[ii].rate)
1109 result = hb_audio_rates[ii].rate;
1117 lookup_audio_bitrate_int(const GValue *rate)
1122 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1124 // Coincidentally, the string "source" will return 0
1125 // which is our flag to use "same as source"
1126 gchar *str = ghb_value_string(rate);
1127 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1129 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1131 result = hb_audio_bitrates[ii].rate;
1137 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1138 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1139 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1141 gint val = ghb_value_int(rate);
1142 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1144 if (hb_audio_bitrates[ii].rate == val)
1146 result = hb_audio_bitrates[ii].rate;
1155 lookup_audio_bitrate_option(const GValue *rate)
1158 const gchar *result = "Same as source";
1160 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1162 // Coincidentally, the string "source" will return 0
1163 // which is our flag to use "same as source"
1164 gchar *str = ghb_value_string(rate);
1165 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1167 if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
1169 result = hb_audio_bitrates[ii].string;
1175 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1176 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1177 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1179 gint val = ghb_value_int(rate);
1180 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
1182 if (hb_audio_bitrates[ii].rate == val)
1184 result = hb_audio_bitrates[ii].string;
1193 lookup_audio_lang_int(const GValue *rate)
1199 // Coincidentally, the string "source" will return 0
1200 // which is our flag to use "same as source"
1201 str = ghb_value_string(rate);
1202 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1204 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1215 lookup_audio_lang_option(const GValue *rate)
1219 const gchar *result = "Same as source";
1221 // Coincidentally, the string "source" will return 0
1222 // which is our flag to use "same as source"
1223 str = ghb_value_string(rate);
1224 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1226 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1228 if (ghb_language_table[ii].native_name[0] != 0)
1229 result = ghb_language_table[ii].native_name;
1231 result = ghb_language_table[ii].eng_name;
1240 ghb_lookup_acodec_value(gint val)
1242 GValue *value = NULL;
1245 for (ii = 0; ii < acodec_opts.count; ii++)
1247 if ((int)acodec_opts.map[ii].ivalue == val)
1249 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1253 value = ghb_string_value_new("auto");
1258 get_amix_value(gint val)
1260 GValue *value = NULL;
1263 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1265 if (hb_audio_mixdowns[ii].amixdown == val)
1267 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1274 // Handle for libhb. Gets set by ghb_backend_init()
1275 static hb_handle_t * h_scan = NULL;
1276 static hb_handle_t * h_queue = NULL;
1278 extern void hb_get_temporary_directory(char path[512]);
1285 hb_get_temporary_directory(dir);
1286 return g_strdup(dir);
1290 ghb_hb_cleanup(gboolean partial)
1294 hb_get_temporary_directory(dir);
1295 del_tree(dir, !partial);
1299 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1307 titleindex = ghb_settings_combo_int(ud->settings, "title");
1313 hb_subtitle_t * sub;
1315 if (h_scan == NULL) return VOBSUB;
1316 list = hb_get_titles( h_scan );
1317 if( !hb_list_count( list ) )
1319 /* No valid title, stop right there */
1322 title = hb_list_item( list, titleindex );
1323 if (title == NULL) return VOBSUB; // Bad titleindex
1324 sub = hb_list_item( title->list_subtitle, track);
1332 ghb_subtitle_source_name(gint source)
1334 const gchar * name = "Unknown";
1363 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1366 const gchar * name = "Unknown";
1379 titleindex = ghb_settings_combo_int(ud->settings, "title");
1385 hb_subtitle_t * sub;
1389 list = hb_get_titles( h_scan );
1390 if( !hb_list_count( list ) )
1393 title = hb_list_item( list, titleindex );
1397 sub = hb_list_item( title->list_subtitle, track);
1400 name = ghb_subtitle_source_name(sub->source);
1408 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1412 titleindex = ghb_settings_combo_int(ud->settings, "title");
1416 return ghb_get_user_audio_lang(ud, titleindex, 0);
1422 hb_subtitle_t * sub;
1427 list = hb_get_titles( h_scan );
1428 if( !hb_list_count( list ) )
1430 /* No valid title, stop right there */
1433 title = hb_list_item( list, titleindex );
1434 if (title == NULL) // Bad titleindex
1436 sub = hb_list_item( title->list_subtitle, track);
1438 return g_strdup(sub->iso639_2);
1441 return g_strdup("und");
1445 ghb_get_title_number(gint titleindex)
1450 if (h_scan == NULL) return 1;
1451 list = hb_get_titles( h_scan );
1452 if( !hb_list_count( list ) )
1454 /* No valid title, stop right there */
1457 title = hb_list_item( list, titleindex );
1458 if (title == NULL) return 1; // Bad titleindex
1459 return title->index;
1462 static hb_audio_config_t*
1463 get_hb_audio(gint titleindex, gint track)
1467 hb_audio_config_t *audio = NULL;
1469 if (h_scan == NULL) return NULL;
1470 list = hb_get_titles( h_scan );
1471 if( !hb_list_count( list ) )
1473 /* No valid title, stop right there */
1476 title = hb_list_item( list, titleindex );
1477 if (title == NULL) return NULL; // Bad titleindex
1478 if (!hb_list_count(title->list_audio))
1482 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1487 search_rates(hb_rate_t *rates, gint rate, gint count)
1490 for (ii = 0; ii < count; ii++)
1492 if (rates[ii].rate == rate)
1498 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1500 static GtkListStore*
1501 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1504 GtkListStore *store;
1506 g_debug("get_combo_box_store() %s\n", name);
1507 // First modify the combobox model to allow greying out of options
1508 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1509 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1514 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1516 GtkListStore *store;
1519 store = get_combo_box_store(builder, name);
1520 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1522 gtk_list_store_set(store, &iter,
1529 ghb_grey_combo_options(GtkBuilder *builder)
1532 gint container, track, titleindex, acodec;
1533 hb_audio_config_t *audio = NULL;
1536 widget = GHB_WIDGET (builder, "title");
1537 gval = ghb_widget_value(widget);
1538 titleindex = ghb_lookup_combo_int("title", gval);
1539 ghb_value_free(gval);
1540 widget = GHB_WIDGET (builder, "AudioTrack");
1541 gval = ghb_widget_value(widget);
1542 track = ghb_lookup_combo_int("AudioTrack", gval);
1543 ghb_value_free(gval);
1544 audio = get_hb_audio(titleindex, track);
1545 widget = GHB_WIDGET (builder, "FileFormat");
1546 gval = ghb_widget_value(widget);
1547 container = ghb_lookup_combo_int("FileFormat", gval);
1548 ghb_value_free(gval);
1550 grey_combo_box_item(builder, "x264_analyse", 4, TRUE);
1551 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1552 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1553 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1555 gboolean allow_dca = TRUE;
1556 allow_dca = (container != HB_MUX_MP4);
1558 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3_PASS, FALSE);
1560 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, FALSE);
1562 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, TRUE);
1564 if (audio && audio->in.codec != HB_ACODEC_AC3)
1566 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3_PASS, TRUE);
1568 if (audio && audio->in.codec != HB_ACODEC_DCA)
1570 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, TRUE);
1572 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1574 widget = GHB_WIDGET (builder, "AudioEncoder");
1575 gval = ghb_widget_value(widget);
1576 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1577 ghb_value_free(gval);
1578 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1579 if (container == HB_MUX_MP4)
1581 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1582 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1585 gboolean allow_mono = TRUE;
1586 gboolean allow_stereo = TRUE;
1587 gboolean allow_dolby = TRUE;
1588 gboolean allow_dpl2 = TRUE;
1589 gboolean allow_6ch = TRUE;
1591 allow_6ch = acodec & ~HB_ACODEC_LAME;
1594 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1596 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1598 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1599 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1600 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1601 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1602 allow_6ch = allow_6ch &&
1603 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1604 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1606 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1607 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1608 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1609 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1610 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1614 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
1616 hb_audio_config_t *audio = NULL;
1617 gboolean allow_mono = TRUE;
1618 gboolean allow_stereo = TRUE;
1619 gboolean allow_dolby = TRUE;
1620 gboolean allow_dpl2 = TRUE;
1621 gboolean allow_6ch = TRUE;
1623 if (acodec & HB_ACODEC_PASS_FLAG)
1625 // Audio codec pass-thru. No mixdown
1628 audio = get_hb_audio(titleindex, track);
1632 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1634 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1636 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1637 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1638 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1639 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1641 (acodec & ~HB_ACODEC_LAME) &&
1642 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1643 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1645 gboolean greater = FALSE;
1648 // If no mix is specified, select the best available.
1649 mix = HB_AMIXDOWN_6CH;
1651 if (mix == HB_AMIXDOWN_6CH)
1654 if (allow_6ch) return HB_AMIXDOWN_6CH;
1656 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1659 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1661 if (mix == HB_AMIXDOWN_DOLBY || greater)
1664 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1666 if (mix == HB_AMIXDOWN_STEREO || greater)
1669 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1671 if (mix == HB_AMIXDOWN_MONO || greater)
1674 if (allow_mono) return HB_AMIXDOWN_MONO;
1676 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1677 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1678 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1679 if (allow_6ch) return HB_AMIXDOWN_6CH;
1683 // Set up the model for the combo box
1685 init_combo_box(GtkBuilder *builder, const gchar *name)
1688 GtkListStore *store;
1689 GtkCellRenderer *cell;
1691 g_debug("init_combo_box() %s\n", name);
1692 // First modify the combobox model to allow greying out of options
1693 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1697 // 1 - String to display
1698 // 2 - bool indicating whether the entry is selectable (grey or not)
1699 // 3 - String that is used for presets
1700 // 4 - Int value determined by backend
1701 // 5 - String value determined by backend
1702 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1703 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1704 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1706 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1708 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1709 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1710 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1711 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1712 "markup", 0, "sensitive", 1, NULL);
1715 { // Combo box entry
1716 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1721 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1724 GtkListStore *store;
1728 g_debug("audio_samplerate_opts_set ()\n");
1729 store = get_combo_box_store(builder, name);
1730 gtk_list_store_clear(store);
1731 // Add an item for "Same As Source"
1732 gtk_list_store_append(store, &iter);
1733 gtk_list_store_set(store, &iter,
1734 0, "<small>Same as source</small>",
1740 for (ii = 0; ii < count; ii++)
1742 gtk_list_store_append(store, &iter);
1743 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1744 gtk_list_store_set(store, &iter,
1747 2, rates[ii].string,
1748 3, (gdouble)rates[ii].rate,
1749 4, rates[ii].string,
1756 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1759 GtkListStore *store;
1762 g_debug("video_rate_opts_set ()\n");
1763 store = get_combo_box_store(builder, name);
1764 gtk_list_store_clear(store);
1765 // Add an item for "Same As Source"
1766 gtk_list_store_append(store, &iter);
1767 gtk_list_store_set(store, &iter,
1768 0, "Same as source",
1774 for (ii = 0; ii < count; ii++)
1778 if (strcmp(rates[ii].string, "23.976") == 0)
1780 desc = "(NTSC Film)";
1782 else if (strcmp(rates[ii].string, "25") == 0)
1784 desc = "(PAL Film/Video)";
1786 else if (strcmp(rates[ii].string, "29.97") == 0)
1788 desc = "(NTSC Video)";
1790 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1791 gtk_list_store_append(store, &iter);
1792 gtk_list_store_set(store, &iter,
1795 2, rates[ii].string,
1796 3, (gdouble)rates[ii].rate,
1797 4, rates[ii].string,
1804 mix_opts_set(GtkBuilder *builder, const gchar *name)
1807 GtkListStore *store;
1811 g_debug("mix_opts_set ()\n");
1812 store = get_combo_box_store(builder, name);
1813 gtk_list_store_clear(store);
1814 gtk_list_store_append(store, &iter);
1815 gtk_list_store_set(store, &iter,
1816 0, "<small>None</small>",
1822 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1824 gtk_list_store_append(store, &iter);
1825 str = g_strdup_printf("<small>%s</small>",
1826 hb_audio_mixdowns[ii].human_readable_name);
1827 gtk_list_store_set(store, &iter,
1830 2, hb_audio_mixdowns[ii].short_name,
1831 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1832 4, hb_audio_mixdowns[ii].internal_name,
1839 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1842 GtkListStore *store;
1845 g_debug("srt_codeset_opts_set ()\n");
1846 store = get_combo_box_store(builder, name);
1847 gtk_list_store_clear(store);
1848 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1850 gtk_list_store_append(store, &iter);
1851 gtk_list_store_set(store, &iter,
1852 0, srt_codeset_table[ii],
1854 2, srt_codeset_table[ii],
1856 4, srt_codeset_table[ii],
1859 GtkComboBoxEntry *cbe;
1861 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1862 //gtk_combo_box_entry_set_text_column(cbe, 0);
1866 language_opts_set(GtkBuilder *builder, const gchar *name)
1869 GtkListStore *store;
1872 g_debug("language_opts_set ()\n");
1873 store = get_combo_box_store(builder, name);
1874 gtk_list_store_clear(store);
1875 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1879 if (ghb_language_table[ii].native_name[0] != 0)
1880 lang = ghb_language_table[ii].native_name;
1882 lang = ghb_language_table[ii].eng_name;
1884 gtk_list_store_append(store, &iter);
1885 gtk_list_store_set(store, &iter,
1888 2, ghb_language_table[ii].iso639_2,
1890 4, ghb_language_table[ii].iso639_1,
1895 static gchar **titles = NULL;
1898 title_opts_set(GtkBuilder *builder, const gchar *name)
1901 GtkListStore *store;
1902 hb_list_t * list = NULL;
1903 hb_title_t * title = NULL;
1907 g_debug("title_opts_set ()\n");
1908 store = get_combo_box_store(builder, name);
1909 gtk_list_store_clear(store);
1912 list = hb_get_titles( h_scan );
1913 count = hb_list_count( list );
1914 if (count > 100) count = 100;
1916 if (titles) g_strfreev(titles);
1917 if (title_opts.map) g_free(title_opts.map);
1920 title_opts.count = count;
1921 title_opts.map = g_malloc(count*sizeof(options_map_t));
1922 titles = g_malloc((count+1) * sizeof(gchar*));
1926 title_opts.count = 1;
1927 title_opts.map = g_malloc(sizeof(options_map_t));
1932 // No titles. Fill in a default.
1933 gtk_list_store_append(store, &iter);
1934 gtk_list_store_set(store, &iter,
1941 title_opts.map[0].option = "No Titles";
1942 title_opts.map[0].shortOpt = "none";
1943 title_opts.map[0].ivalue = -1;
1944 title_opts.map[0].svalue = "none";
1947 for (ii = 0; ii < count; ii++)
1949 title = (hb_title_t*)hb_list_item(list, ii);
1950 if (title->type == HB_STREAM_TYPE)
1952 if (title->duration != 0)
1954 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
1955 title->index, title->hours, title->minutes, title->seconds,
1960 titles[ii] = g_strdup_printf ("%d - %s",
1961 title->index, title->name);
1966 if (title->duration != 0)
1968 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1969 title->index, title->hours, title->minutes, title->seconds);
1973 titles[ii] = g_strdup_printf ("%d - Unknown Length",
1977 gtk_list_store_append(store, &iter);
1978 gtk_list_store_set(store, &iter,
1985 title_opts.map[ii].option = titles[ii];
1986 title_opts.map[ii].shortOpt = titles[ii];
1987 title_opts.map[ii].ivalue = ii;
1988 title_opts.map[ii].svalue = titles[ii];
1994 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1997 gboolean foundit = FALSE;
1999 if (gtk_tree_model_get_iter_first (store, iter))
2003 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
2004 if (value == (gint)ivalue)
2009 } while (gtk_tree_model_iter_next (store, iter));
2015 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2018 GtkListStore *store;
2019 hb_list_t * list = NULL;
2020 hb_title_t * title = NULL;
2021 hb_audio_config_t * audio;
2026 g_debug("audio_track_opts_set ()\n");
2027 store = get_combo_box_store(builder, name);
2028 gtk_list_store_clear(store);
2031 list = hb_get_titles( h_scan );
2032 title = (hb_title_t*)hb_list_item( list, titleindex );
2035 count = hb_list_count( title->list_audio );
2038 if (count > 100) count = 100;
2039 if (audio_track_opts.map) g_free(audio_track_opts.map);
2042 audio_track_opts.count = count;
2043 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
2047 audio_track_opts.count = 1;
2048 audio_track_opts.map = g_malloc(sizeof(options_map_t));
2052 // No audio. set some default
2053 gtk_list_store_append(store, &iter);
2054 gtk_list_store_set(store, &iter,
2055 0, "<small>No Audio</small>",
2061 audio_track_opts.map[0].option = "No Audio";
2062 audio_track_opts.map[0].shortOpt = "none";
2063 audio_track_opts.map[0].ivalue = -1;
2064 audio_track_opts.map[0].svalue = "none";
2067 index_str_init(count-1);
2068 for (ii = 0; ii < count; ii++)
2070 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
2071 gtk_list_store_append(store, &iter);
2072 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
2073 gtk_list_store_set(store, &iter,
2081 audio_track_opts.map[ii].option = audio->lang.description,
2082 audio_track_opts.map[ii].shortOpt = index_str[ii];
2083 audio_track_opts.map[ii].ivalue = ii;
2084 audio_track_opts.map[ii].svalue = index_str[ii];
2089 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2092 GtkListStore *store;
2093 hb_list_t * list = NULL;
2094 hb_title_t * title = NULL;
2095 hb_subtitle_t * subtitle;
2097 static char ** options = NULL;
2099 g_debug("subtitle_track_opts_set ()\n");
2100 store = get_combo_box_store(builder, name);
2101 gtk_list_store_clear(store);
2104 list = hb_get_titles( h_scan );
2105 title = (hb_title_t*)hb_list_item( list, titleindex );
2108 count = hb_list_count( title->list_subtitle );
2111 if (count > 100) count = 100;
2112 if (subtitle_opts.map) g_free(subtitle_opts.map);
2115 subtitle_opts.count = count+1;
2116 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
2120 subtitle_opts.count = LANG_TABLE_SIZE+1;
2121 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
2123 gtk_list_store_append(store, &iter);
2124 gtk_list_store_set(store, &iter,
2125 0, "Foreign Audio Search",
2131 subtitle_opts.map[0].option = "Foreign Audio Search";
2132 subtitle_opts.map[0].shortOpt = "-1";
2133 subtitle_opts.map[0].ivalue = -1;
2134 subtitle_opts.map[0].svalue = "auto";
2137 if (options != NULL)
2138 g_strfreev(options);
2139 options = g_malloc((count+1)*sizeof(gchar*));
2140 index_str_init(count-1);
2141 for (ii = 0; ii < count; ii++)
2143 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
2144 options[ii] = g_strdup_printf("%d - %s (%s)", ii+1,
2146 ghb_subtitle_source_name(subtitle->source));
2147 subtitle_opts.map[ii+1].option = options[ii];
2148 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2149 subtitle_opts.map[ii+1].ivalue = ii;
2150 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
2151 gtk_list_store_append(store, &iter);
2152 gtk_list_store_set(store, &iter,
2157 4, subtitle->iso639_2,
2160 options[count] = NULL;
2164 index_str_init(LANG_TABLE_SIZE-1);
2165 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
2169 if (ghb_language_table[ii].native_name[0] != 0)
2170 lang = ghb_language_table[ii].native_name;
2172 lang = ghb_language_table[ii].eng_name;
2174 subtitle_opts.map[ii+1].option = lang;
2175 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2176 subtitle_opts.map[ii+1].ivalue = ii;
2177 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
2178 gtk_list_store_append(store, &iter);
2179 gtk_list_store_set(store, &iter,
2184 4, ghb_language_table[ii].iso639_2,
2197 gint titleindex = 0;
2200 g_debug("ghb_longest_title ()\n");
2201 if (h_scan == NULL) return 0;
2202 list = hb_get_titles( h_scan );
2203 count = hb_list_count( list );
2204 if (count > 100) count = 100;
2205 if (count < 1) return 0;
2206 title = (hb_title_t*)hb_list_item(list, 0);
2207 feature = title->job->feature;
2208 for (ii = 0; ii < count; ii++)
2210 title = (hb_title_t*)hb_list_item(list, ii);
2211 if (title->index == feature)
2220 ghb_get_source_audio_lang(gint titleindex, gint track)
2224 hb_audio_config_t * audio;
2227 g_debug("ghb_lookup_1st_audio_lang ()\n");
2230 list = hb_get_titles( h_scan );
2231 title = (hb_title_t*)hb_list_item( list, titleindex );
2234 if (hb_list_count( title->list_audio ) <= track)
2237 audio = hb_list_audio_config_item(title->list_audio, track);
2241 lang = g_strdup(audio->lang.iso639_2);
2246 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2250 used = g_hash_table_lookup(track_indices, &acodec);
2255 used = g_malloc0(count * sizeof(gboolean));
2256 key = g_malloc(sizeof(gint));
2258 g_hash_table_insert(track_indices, key, used);
2264 ghb_find_audio_track(
2268 gint fallback_acodec,
2269 GHashTable *track_indices)
2273 hb_audio_config_t * audio;
2278 gboolean *used = NULL;
2279 gboolean *passthru_used;
2281 gint passthru_acodec;
2285 g_debug("find_audio_track ()\n");
2286 if (h_scan == NULL) return -1;
2287 list = hb_get_titles( h_scan );
2288 title = (hb_title_t*)hb_list_item( list, titleindex );
2291 count = hb_list_count( title->list_audio );
2293 if (count > 10) count = 10;
2294 // Try to find an item that matches the preferred language and
2295 // the passthru codec type
2297 passthru = (acodec & HB_ACODEC_PASS_FLAG) != 0;
2300 for (ii = 0; ii < count; ii++)
2302 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2303 title->list_audio, ii );
2304 passthru_acodec = acodec & audio->in.codec;
2305 // Is the source track use a passthru capable codec?
2306 if (passthru_acodec == 0)
2308 used = get_track_used(passthru_acodec, track_indices, count);
2309 // Has the track already been used with this codec?
2313 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2314 audio->in.channel_layout);
2315 // Find a track that is not visually impaired or dirctor's
2316 // commentary, and has the highest channel count.
2317 if ((audio->lang.type < 2) &&
2318 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2319 (strcmp(lang, "und") == 0)))
2321 if (channels > max_chan)
2324 max_chan = channels;
2328 try_acodec = fallback_acodec;
2332 try_acodec = acodec;
2339 // Try to find an item that matches the preferred language
2341 used = get_track_used(try_acodec, track_indices, count);
2342 for (ii = 0; ii < count; ii++)
2344 // Has the track already been used with this codec?
2347 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2348 title->list_audio, ii );
2349 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2350 if (passthru_acodec && passthru)
2352 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2353 // Has the track already been used with this codec for passthru?
2354 if (passthru_used[ii])
2357 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2358 audio->in.channel_layout);
2359 // Find a track that is not visually impaired or dirctor's commentary
2360 if ((audio->lang.type < 2) &&
2361 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2362 (strcmp(lang, "und") == 0)))
2364 if (channels > max_chan)
2367 max_chan = channels;
2376 // Try to fine an item that does not match the preferred language and
2377 // matches the passthru codec type
2381 for (ii = 0; ii < count; ii++)
2383 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2384 title->list_audio, ii );
2385 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2386 // Is the source track use a passthru capable codec?
2387 if (passthru_acodec == 0)
2389 used = get_track_used(passthru_acodec, track_indices, count);
2390 // Has the track already been used with this codec?
2394 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2395 audio->in.channel_layout);
2396 // Find a track that is not visually impaired or dirctor's
2397 // commentary, and has the highest channel count.
2398 if (audio->lang.type < 2)
2400 if (channels > max_chan)
2403 max_chan = channels;
2407 try_acodec = fallback_acodec;
2411 try_acodec = acodec;
2418 // Try to fine an item that does not match the preferred language
2420 used = get_track_used(try_acodec, track_indices, count);
2421 for (ii = 0; ii < count; ii++)
2423 // Has the track already been used with this codec?
2426 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2427 title->list_audio, ii );
2428 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2429 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2430 audio->in.channel_layout);
2431 if (passthru_acodec && passthru)
2433 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2434 // Has the track already been used with this codec for passthru?
2435 if (passthru_used[ii])
2438 // Find a track that is not visually impaired or dirctor's commentary
2439 if (audio->lang.type < 2)
2441 if (channels > max_chan)
2444 max_chan = channels;
2453 // Last ditch, anything goes
2454 for (ii = 0; ii < count; ii++)
2456 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2457 title->list_audio, ii );
2458 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2459 if (passthru_acodec && passthru)
2461 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2462 // Has the track already been used with this codec for passthru?
2463 if (passthru_used[ii])
2466 // Has the track already been used with this codec?
2481 ghb_find_pref_subtitle_track(const gchar *lang)
2484 count = subtitle_opts.count;
2485 for (ii = 0; ii < count; ii++)
2487 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2489 return subtitle_opts.map[ii].ivalue;
2496 ghb_find_cc_track(gint titleindex)
2500 hb_subtitle_t * subtitle;
2503 g_debug("ghb_find_cc_track ()\n");
2504 if (h_scan == NULL) return -2;
2505 list = hb_get_titles( h_scan );
2506 title = (hb_title_t*)hb_list_item( list, titleindex );
2509 count = hb_list_count( title->list_subtitle );
2510 // Try to find an item that matches the preferred language
2511 for (ii = 0; ii < count; ii++)
2513 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2514 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2522 canForce(int source)
2524 return (source == VOBSUB);
2530 return (source == VOBSUB || source == SSASUB);
2534 ghb_find_subtitle_track(
2540 GHashTable * track_indices)
2544 hb_subtitle_t * subtitle;
2548 g_debug("find_subtitle_track ()\n");
2549 if (strcmp(lang, "auto") == 0)
2551 if (h_scan == NULL) return -1;
2552 list = hb_get_titles( h_scan );
2553 title = (hb_title_t*)hb_list_item( list, titleindex );
2556 count = hb_list_count( title->list_subtitle );
2557 used = g_hash_table_lookup(track_indices, lang);
2560 used = g_malloc0(count * sizeof(gboolean));
2561 g_hash_table_insert(track_indices, g_strdup(lang), used);
2563 // Try to find an item that matches the preferred language and source
2564 for (ii = 0; ii < count; ii++)
2569 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2570 if (source == subtitle->source &&
2571 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2572 (strcmp(lang, "und") == 0)))
2578 // Try to find an item that matches the preferred language
2579 for (ii = 0; ii < count; ii++)
2584 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2585 if (((!force || (force && canForce(subtitle->source))) &&
2586 (!burn || (burn && canBurn(subtitle->source)))) &&
2587 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2588 (strcmp(lang, "und") == 0)))
2599 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2602 GtkListStore *store;
2605 g_debug("generic_opts_set ()\n");
2606 if (name == NULL || opts == NULL) return;
2607 store = get_combo_box_store(builder, name);
2608 gtk_list_store_clear(store);
2609 for (ii = 0; ii < opts->count; ii++)
2611 gtk_list_store_append(store, &iter);
2612 gtk_list_store_set(store, &iter,
2613 0, opts->map[ii].option,
2615 2, opts->map[ii].shortOpt,
2616 3, opts->map[ii].ivalue,
2617 4, opts->map[ii].svalue,
2623 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2626 GtkListStore *store;
2630 g_debug("small_opts_set ()\n");
2631 if (name == NULL || opts == NULL) return;
2632 store = get_combo_box_store(builder, name);
2633 gtk_list_store_clear(store);
2634 for (ii = 0; ii < opts->count; ii++)
2636 gtk_list_store_append(store, &iter);
2637 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2638 gtk_list_store_set(store, &iter,
2641 2, opts->map[ii].shortOpt,
2642 3, opts->map[ii].ivalue,
2643 4, opts->map[ii].svalue,
2650 find_combo_table(const gchar *name)
2654 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2656 if (strcmp(name, combo_name_map[ii].name) == 0)
2658 return combo_name_map[ii].opts;
2665 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2669 if (strcmp(name, "AudioBitrate") == 0)
2670 return lookup_audio_bitrate_int(gval);
2671 else if (strcmp(name, "AudioSamplerate") == 0)
2672 return lookup_audio_rate_int(gval);
2673 else if (strcmp(name, "VideoFramerate") == 0)
2674 return lookup_video_rate_int(gval);
2675 else if (strcmp(name, "AudioMixdown") == 0)
2676 return lookup_mix_int(gval);
2677 else if (strcmp(name, "SrtLanguage") == 0)
2678 return lookup_audio_lang_int(gval);
2679 else if (strcmp(name, "PreferredLanguage") == 0)
2680 return lookup_audio_lang_int(gval);
2683 return lookup_generic_int(find_combo_table(name), gval);
2685 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2690 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2694 if (strcmp(name, "AudioBitrate") == 0)
2695 return lookup_audio_bitrate_int(gval);
2696 else if (strcmp(name, "AudioSamplerate") == 0)
2697 return lookup_audio_rate_int(gval);
2698 else if (strcmp(name, "VideoFramerate") == 0)
2699 return lookup_video_rate_int(gval);
2700 else if (strcmp(name, "AudioMixdown") == 0)
2701 return lookup_mix_int(gval);
2702 else if (strcmp(name, "SrtLanguage") == 0)
2703 return lookup_audio_lang_int(gval);
2704 else if (strcmp(name, "PreferredLanguage") == 0)
2705 return lookup_audio_lang_int(gval);
2708 return lookup_generic_double(find_combo_table(name), gval);
2710 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2715 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2719 if (strcmp(name, "AudioBitrate") == 0)
2720 return lookup_audio_bitrate_option(gval);
2721 else if (strcmp(name, "AudioSamplerate") == 0)
2722 return lookup_audio_rate_option(gval);
2723 else if (strcmp(name, "VideoFramerate") == 0)
2724 return lookup_video_rate_option(gval);
2725 else if (strcmp(name, "AudioMixdown") == 0)
2726 return lookup_mix_option(gval);
2727 else if (strcmp(name, "SrtLanguage") == 0)
2728 return lookup_audio_lang_option(gval);
2729 else if (strcmp(name, "PreferredLanguage") == 0)
2730 return lookup_audio_lang_option(gval);
2733 return lookup_generic_option(find_combo_table(name), gval);
2735 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2740 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2744 if (strcmp(name, "AudioBitrate") == 0)
2745 return lookup_audio_bitrate_option(gval);
2746 else if (strcmp(name, "AudioSamplerate") == 0)
2747 return lookup_audio_rate_option(gval);
2748 else if (strcmp(name, "VideoFramerate") == 0)
2749 return lookup_video_rate_option(gval);
2750 else if (strcmp(name, "AudioMixdown") == 0)
2751 return lookup_mix_string(gval);
2752 else if (strcmp(name, "SrtLanguage") == 0)
2753 return lookup_audio_lang_option(gval);
2754 else if (strcmp(name, "PreferredLanguage") == 0)
2755 return lookup_audio_lang_option(gval);
2758 return lookup_generic_string(find_combo_table(name), gval);
2760 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2765 ghb_update_ui_combo_box(
2766 signal_user_data_t *ud,
2771 GtkComboBox *combo = NULL;
2773 gint handler_id = 0;
2777 g_debug("ghb_update_ui_combo_box() %s\n", name);
2778 // Clearing a combo box causes a rash of "changed" events, even when
2779 // the active item is -1 (inactive). To control things, I'm disabling
2780 // the event till things are settled down.
2781 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2782 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2785 // Valid signal id found. This should always succeed.
2786 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2787 signal_id, 0, 0, 0, 0);
2790 // This should also always succeed
2791 g_signal_handler_block ((gpointer)combo, handler_id);
2797 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2798 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2799 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2800 mix_opts_set(ud->builder, "AudioMixdown");
2801 language_opts_set(ud->builder, "SrtLanguage");
2802 language_opts_set(ud->builder, "PreferredLanguage");
2803 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2804 title_opts_set(ud->builder, "title");
2805 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2806 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2807 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2808 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2809 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2810 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2811 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2812 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2813 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2814 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2815 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2816 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2817 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2818 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2819 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2820 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2821 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2822 small_opts_set(ud->builder, "x264_direct", &direct_opts);
2823 small_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2824 small_opts_set(ud->builder, "x264_bpyramid", &bpyramid_opts);
2825 small_opts_set(ud->builder, "x264_weighted_pframes", &weightp_opts);
2826 small_opts_set(ud->builder, "x264_me", &me_opts);
2827 small_opts_set(ud->builder, "x264_subme", &subme_opts);
2828 small_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2829 small_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2833 if (strcmp(name, "AudioBitrate") == 0)
2834 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2835 else if (strcmp(name, "AudioSamplerate") == 0)
2836 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2837 else if (strcmp(name, "VideoFramerate") == 0)
2838 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2839 else if (strcmp(name, "AudioMixdown") == 0)
2840 mix_opts_set(ud->builder, "AudioMixdown");
2841 else if (strcmp(name, "SrtLanguage") == 0)
2842 language_opts_set(ud->builder, "SrtLanguage");
2843 else if (strcmp(name, "PreferredLanguage") == 0)
2844 language_opts_set(ud->builder, "PreferredLanguage");
2845 else if (strcmp(name, "SrtCodeset") == 0)
2846 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2847 else if (strcmp(name, "title") == 0)
2848 title_opts_set(ud->builder, "title");
2849 else if (strcmp(name, "SubtitleTrack") == 0)
2850 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2851 else if (strcmp(name, "AudioTrack") == 0)
2852 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2854 generic_opts_set(ud->builder, name, find_combo_table(name));
2858 g_signal_handler_unblock ((gpointer)combo, handler_id);
2863 init_ui_combo_boxes(GtkBuilder *builder)
2867 init_combo_box(builder, "AudioBitrate");
2868 init_combo_box(builder, "AudioSamplerate");
2869 init_combo_box(builder, "VideoFramerate");
2870 init_combo_box(builder, "AudioMixdown");
2871 init_combo_box(builder, "SrtLanguage");
2872 init_combo_box(builder, "PreferredLanguage");
2873 init_combo_box(builder, "SrtCodeset");
2874 init_combo_box(builder, "title");
2875 init_combo_box(builder, "AudioTrack");
2876 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2878 init_combo_box(builder, combo_name_map[ii].name);
2882 static const char * turbo_opts =
2883 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2884 "no-fast-pskip=0:8x8dct=0";
2886 // Construct the x264 options string
2887 // The result is allocated, so someone must free it at some point.
2889 ghb_build_x264opts_string(GValue *settings)
2892 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2899 result = g_strdup("");
2905 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2909 hb_chapter_t * chapter;
2913 *hh = *mm = *ss = 0;
2914 if (h_scan == NULL) return;
2915 list = hb_get_titles( h_scan );
2916 title = (hb_title_t*)hb_list_item( list, tt );
2917 if (title == NULL) return;
2920 *mm = title->minutes;
2921 *ss = title->seconds;
2923 count = hb_list_count(title->list_chapter);
2924 if (sc > count) sc = count;
2925 if (ec > count) ec = count;
2927 if (sc == 1 && ec == count)
2931 for (c = sc; c <= ec; c++)
2933 chapter = hb_list_item(title->list_chapter, c-1);
2934 duration += chapter->duration;
2937 *hh = duration / 90000 / 3600;
2938 *mm = ((duration / 90000) % 3600) / 60;
2939 *ss = (duration / 90000) % 60;
2943 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2947 hb_chapter_t * chapter;
2950 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2951 *hh = *mm = *ss = 0;
2952 if (h_scan == NULL) return;
2953 list = hb_get_titles( h_scan );
2954 title = (hb_title_t*)hb_list_item( list, ti );
2955 if (title == NULL) return;
2956 count = hb_list_count( title->list_chapter );
2957 if (ii >= count) return;
2958 chapter = hb_list_item(title->list_chapter, ii);
2959 if (chapter == NULL) return;
2960 *hh = chapter->hours;
2961 *mm = chapter->minutes;
2962 *ss = chapter->seconds;
2966 ghb_get_chapters(gint titleindex)
2970 hb_chapter_t * chapter;
2972 GValue *chapters = NULL;
2974 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2975 if (h_scan == NULL) return NULL;
2976 list = hb_get_titles( h_scan );
2977 title = (hb_title_t*)hb_list_item( list, titleindex );
2978 if (title == NULL) return NULL;
2979 count = hb_list_count( title->list_chapter );
2980 chapters = ghb_array_value_new(count);
2981 for (ii = 0; ii < count; ii++)
2983 chapter = hb_list_item(title->list_chapter, ii);
2984 if (chapter == NULL) break;
2985 if (chapter->title == NULL || chapter->title[0] == 0)
2988 str = g_strdup_printf ("Chapter %2d", ii+1);
2989 ghb_array_append(chapters, ghb_string_value_new(str));
2994 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
3001 ghb_ac3_in_audio_list(const GValue *audio_list)
3005 count = ghb_array_len(audio_list);
3006 for (ii = 0; ii < count; ii++)
3011 asettings = ghb_array_get_nth(audio_list, ii);
3012 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
3013 if (acodec & HB_ACODEC_AC3)
3020 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
3023 GtkListStore *store;
3026 g_debug("audio_bitrate_opts_add ()\n");
3028 if (rate < 8) return;
3030 store = get_combo_box_store(builder, name);
3031 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
3033 str = g_strdup_printf ("<small>%d</small>", rate);
3034 gtk_list_store_append(store, &iter);
3035 gtk_list_store_set(store, &iter,
3047 audio_bitrate_opts_clean(
3048 GtkBuilder *builder,
3054 GtkListStore *store;
3056 gboolean done = FALSE;
3058 guint last = (guint)last_rate;
3059 guint first = (guint)first_rate;
3061 g_debug("audio_bitrate_opts_clean ()\n");
3062 store = get_combo_box_store(builder, name);
3063 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
3067 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
3069 hb_audio_bitrates, ivalue, hb_audio_bitrates_count) < 0)
3071 done = !gtk_list_store_remove(store, &iter);
3073 else if (ivalue < first || ivalue > last)
3076 gtk_list_store_set(store, &iter, 1, FALSE, -1);
3077 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3082 gtk_list_store_set(store, &iter, 1, TRUE, -1);
3083 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3090 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
3093 GtkListStore *store;
3097 g_debug("audio_bitrate_opts_set ()\n");
3098 store = get_combo_box_store(builder, name);
3099 gtk_list_store_clear(store);
3100 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
3102 gtk_list_store_append(store, &iter);
3103 str = g_strdup_printf ("<small>%s</small>",
3104 hb_audio_bitrates[ii].string);
3105 gtk_list_store_set(store, &iter,
3108 2, hb_audio_bitrates[ii].string,
3109 3, (gdouble)hb_audio_bitrates[ii].rate,
3110 4, hb_audio_bitrates[ii].string,
3117 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
3119 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
3123 ghb_set_default_bitrate_opts(
3124 GtkBuilder *builder,
3128 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
3131 static ghb_status_t hb_status;
3134 ghb_combo_init(signal_user_data_t *ud)
3136 // Set up the list model for the combos
3137 init_ui_combo_boxes(ud->builder);
3138 // Populate all the combos
3139 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
3143 ghb_backend_init(gint debug)
3146 h_scan = hb_init( debug, 0 );
3147 h_queue = hb_init( debug, 0 );
3158 void ghb_backend_scan_stop()
3160 hb_scan_stop( h_scan );
3164 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count, uint64_t min_duration)
3166 hb_scan( h_scan, path, titleindex, preview_count, 1, min_duration );
3167 hb_status.scan.state |= GHB_STATE_SCANNING;
3168 // initialize count and cur to something that won't cause FPE
3169 // when computing progress
3170 hb_status.scan.title_count = 1;
3171 hb_status.scan.title_cur = 0;
3175 ghb_backend_queue_scan(const gchar *path, gint titlenum)
3177 g_debug("ghb_backend_queue_scan()");
3178 hb_scan( h_queue, path, titlenum, 10, 0, 0 );
3179 hb_status.queue.state |= GHB_STATE_SCANNING;
3183 ghb_get_scan_state()
3185 return hb_status.scan.state;
3189 ghb_get_queue_state()
3191 return hb_status.queue.state;
3195 ghb_clear_scan_state(gint state)
3197 hb_status.scan.state &= ~state;
3201 ghb_clear_queue_state(gint state)
3203 hb_status.queue.state &= ~state;
3207 ghb_set_scan_state(gint state)
3209 hb_status.scan.state |= state;
3213 ghb_set_queue_state(gint state)
3215 hb_status.queue.state |= state;
3219 ghb_get_status(ghb_status_t *status)
3221 memcpy(status, &hb_status, sizeof(ghb_status_t));
3230 if (h_scan == NULL) return;
3231 hb_get_state( h_scan, &s_scan );
3232 switch( s_scan.state )
3234 #define p s_scan.param.scanning
3235 case HB_STATE_SCANNING:
3237 hb_status.scan.state |= GHB_STATE_SCANNING;
3238 hb_status.scan.title_count = p.title_count;
3239 hb_status.scan.title_cur = p.title_cur;
3243 case HB_STATE_SCANDONE:
3245 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3246 hb_status.scan.state |= GHB_STATE_SCANDONE;
3249 #define p s_scan.param.working
3250 case HB_STATE_WORKING:
3251 hb_status.scan.state |= GHB_STATE_WORKING;
3252 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3253 hb_status.scan.job_cur = p.job_cur;
3254 hb_status.scan.job_count = p.job_count;
3255 hb_status.scan.progress = p.progress;
3256 hb_status.scan.rate_cur = p.rate_cur;
3257 hb_status.scan.rate_avg = p.rate_avg;
3258 hb_status.scan.hours = p.hours;
3259 hb_status.scan.minutes = p.minutes;
3260 hb_status.scan.seconds = p.seconds;
3261 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3265 case HB_STATE_PAUSED:
3266 hb_status.scan.state |= GHB_STATE_PAUSED;
3269 case HB_STATE_MUXING:
3271 hb_status.scan.state |= GHB_STATE_MUXING;
3274 #define p s_scan.param.workdone
3275 case HB_STATE_WORKDONE:
3279 hb_status.scan.state |= GHB_STATE_WORKDONE;
3280 hb_status.scan.state &= ~GHB_STATE_MUXING;
3281 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3282 hb_status.scan.state &= ~GHB_STATE_WORKING;
3286 hb_status.scan.error = GHB_ERROR_NONE;
3288 case HB_ERROR_CANCELED:
3289 hb_status.scan.error = GHB_ERROR_CANCELED;
3292 hb_status.scan.error = GHB_ERROR_FAIL;
3295 // Delete all remaining jobs of this encode.
3296 // An encode can be composed of multiple associated jobs.
3297 // When a job is stopped, libhb removes it from the job list,
3298 // but does not remove other jobs that may be associated with it.
3299 // Associated jobs are taged in the sequence id.
3300 while ((job = hb_job(h_scan, 0)) != NULL)
3301 hb_rem( h_scan, job );
3305 hb_get_state( h_queue, &s_queue );
3306 switch( s_queue.state )
3308 #define p s_queue.param.scanning
3309 case HB_STATE_SCANNING:
3311 hb_status.queue.state |= GHB_STATE_SCANNING;
3312 hb_status.queue.title_count = p.title_count;
3313 hb_status.queue.title_cur = p.title_cur;
3317 case HB_STATE_SCANDONE:
3319 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3320 hb_status.queue.state |= GHB_STATE_SCANDONE;
3323 #define p s_queue.param.working
3324 case HB_STATE_WORKING:
3325 hb_status.queue.state |= GHB_STATE_WORKING;
3326 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3327 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3328 hb_status.queue.job_cur = p.job_cur;
3329 hb_status.queue.job_count = p.job_count;
3330 hb_status.queue.progress = p.progress;
3331 hb_status.queue.rate_cur = p.rate_cur;
3332 hb_status.queue.rate_avg = p.rate_avg;
3333 hb_status.queue.hours = p.hours;
3334 hb_status.queue.minutes = p.minutes;
3335 hb_status.queue.seconds = p.seconds;
3336 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3339 case HB_STATE_SEARCHING:
3340 hb_status.queue.state |= GHB_STATE_SEARCHING;
3341 hb_status.queue.state &= ~GHB_STATE_WORKING;
3342 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3343 hb_status.queue.job_cur = p.job_cur;
3344 hb_status.queue.job_count = p.job_count;
3345 hb_status.queue.progress = p.progress;
3346 hb_status.queue.rate_cur = p.rate_cur;
3347 hb_status.queue.rate_avg = p.rate_avg;
3348 hb_status.queue.hours = p.hours;
3349 hb_status.queue.minutes = p.minutes;
3350 hb_status.queue.seconds = p.seconds;
3351 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3355 case HB_STATE_PAUSED:
3356 hb_status.queue.state |= GHB_STATE_PAUSED;
3359 case HB_STATE_MUXING:
3361 hb_status.queue.state |= GHB_STATE_MUXING;
3364 #define p s_queue.param.workdone
3365 case HB_STATE_WORKDONE:
3369 hb_status.queue.state |= GHB_STATE_WORKDONE;
3370 hb_status.queue.state &= ~GHB_STATE_MUXING;
3371 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3372 hb_status.queue.state &= ~GHB_STATE_WORKING;
3373 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3377 hb_status.queue.error = GHB_ERROR_NONE;
3379 case HB_ERROR_CANCELED:
3380 hb_status.queue.error = GHB_ERROR_CANCELED;
3383 hb_status.queue.error = GHB_ERROR_FAIL;
3386 // Delete all remaining jobs of this encode.
3387 // An encode can be composed of multiple associated jobs.
3388 // When a job is stopped, libhb removes it from the job list,
3389 // but does not remove other jobs that may be associated with it.
3390 // Associated jobs are taged in the sequence id.
3391 while ((job = hb_job(h_queue, 0)) != NULL)
3392 hb_rem( h_queue, job );
3399 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3404 if (h_scan == NULL) return FALSE;
3405 list = hb_get_titles( h_scan );
3406 if( !hb_list_count( list ) )
3408 /* No valid title, stop right there */
3412 title = hb_list_item( list, titleindex );
3413 if (title == NULL) return FALSE; // Bad titleindex
3414 tinfo->index = titleindex;
3415 tinfo->width = title->width;
3416 tinfo->height = title->height;
3417 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3418 // Don't allow crop to 0
3419 if (title->crop[0] + title->crop[1] >= title->height)
3420 title->crop[0] = title->crop[1] = 0;
3421 if (title->crop[2] + title->crop[3] >= title->width)
3422 title->crop[2] = title->crop[3] = 0;
3423 tinfo->num_chapters = hb_list_count(title->list_chapter);
3424 tinfo->rate_base = title->rate_base;
3425 tinfo->rate = title->rate;
3426 tinfo->interlaced = title->detected_interlacing;
3427 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3428 title->width * title->pixel_aspect_width,
3429 title->height * title->pixel_aspect_height);
3430 tinfo->hours = title->hours;
3431 tinfo->minutes = title->minutes;
3432 tinfo->seconds = title->seconds;
3433 tinfo->duration = title->duration;
3435 tinfo->angle_count = title->angle_count;
3436 tinfo->path = title->path;
3437 tinfo->name = title->name;
3438 tinfo->type = title->type;
3443 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
3445 hb_audio_config_t *audio;
3447 audio = get_hb_audio(titleindex, audioindex);
3448 if (audio == NULL) return FALSE; // Bad audioindex
3449 ainfo->codec = audio->in.codec;
3450 ainfo->bitrate = audio->in.bitrate;
3451 ainfo->samplerate = audio->in.samplerate;
3456 ghb_audio_is_passthru(gint acodec)
3458 g_debug("ghb_audio_is_passthru () \n");
3459 return (acodec & HB_ACODEC_PASS_FLAG) != 0;
3463 ghb_audio_can_passthru(gint acodec)
3465 g_debug("ghb_audio_can_passthru () \n");
3466 return (acodec & HB_ACODEC_PASS_MASK) != 0;
3470 ghb_get_default_acodec()
3472 return HB_ACODEC_FAAC;
3476 picture_settings_deps(signal_user_data_t *ud)
3478 gboolean autoscale, keep_aspect, enable_keep_aspect;
3479 gboolean enable_scale_width, enable_scale_height;
3480 gboolean enable_disp_width, enable_disp_height, enable_par;
3484 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3487 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3488 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3489 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3491 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3492 if (!enable_keep_aspect)
3494 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3496 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3497 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3499 enable_scale_width = !autoscale && (pic_par != 1);
3500 enable_scale_height = !autoscale && (pic_par != 1);
3501 enable_disp_width = (pic_par == 3) && !keep_aspect;
3502 enable_par = (pic_par == 3) && !keep_aspect;
3503 enable_disp_height = FALSE;
3505 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3506 gtk_widget_set_sensitive(widget, pic_par != 1);
3507 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3508 gtk_widget_set_sensitive(widget, pic_par != 1);
3509 widget = GHB_WIDGET(ud->builder, "scale_width");
3510 gtk_widget_set_sensitive(widget, enable_scale_width);
3511 widget = GHB_WIDGET(ud->builder, "scale_height");
3512 gtk_widget_set_sensitive(widget, enable_scale_height);
3513 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3514 gtk_widget_set_sensitive(widget, enable_disp_width);
3515 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3516 gtk_widget_set_sensitive(widget, enable_disp_height);
3517 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3518 gtk_widget_set_sensitive(widget, enable_par);
3519 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3520 gtk_widget_set_sensitive(widget, enable_par);
3521 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3522 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3523 widget = GHB_WIDGET(ud->builder, "autoscale");
3524 gtk_widget_set_sensitive(widget, pic_par != 1);
3528 ghb_set_scale(signal_user_data_t *ud, gint mode)
3533 gboolean keep_aspect;
3535 gboolean autocrop, autoscale, noscale;
3536 gint crop[4], width, height, par_width, par_height;
3537 gint crop_width, crop_height;
3538 gint aspect_n, aspect_d;
3539 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3540 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3545 gint max_height = 0;
3547 g_debug("ghb_set_scale ()\n");
3548 picture_settings_deps(ud);
3549 if (h_scan == NULL) return;
3550 list = hb_get_titles( h_scan );
3551 if( !hb_list_count( list ) )
3553 /* No valid title, stop right there */
3558 titleindex = ghb_settings_combo_int(ud->settings, "title");
3559 title = hb_list_item( list, titleindex );
3560 if (title == NULL) return;
3562 if (job == NULL) return;
3564 if (ud->scale_busy) return;
3565 ud->scale_busy = TRUE;
3567 // First configure widgets
3568 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3569 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3570 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3571 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3572 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3573 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3574 // alignment constraints rather than scaling to satisfy them.
3575 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3576 // Align dimensions to either 16 or 2 pixels
3577 // The scaler crashes if the dimensions are not divisible by 2
3578 // x264 also will not accept dims that are not multiple of 2
3582 keep_height = FALSE;
3584 // Step needs to be at least 2 because odd widths cause scaler crash
3586 widget = GHB_WIDGET (ud->builder, "scale_width");
3587 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3588 widget = GHB_WIDGET (ud->builder, "scale_height");
3589 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3592 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3593 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3594 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3595 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3596 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3597 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3598 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3599 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3603 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3604 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3605 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3606 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3607 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3608 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3609 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3610 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3612 ghb_title_info_t tinfo;
3613 ghb_get_title_info (&tinfo, titleindex);
3616 crop[0] = tinfo.crop[0];
3617 crop[1] = tinfo.crop[1];
3618 crop[2] = tinfo.crop[2];
3619 crop[3] = tinfo.crop[3];
3620 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3621 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3622 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3623 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3627 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3628 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3629 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3630 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3636 // Adjust the cropping to accomplish the desired width and height
3637 crop_width = tinfo.width - crop[2] - crop[3];
3638 crop_height = tinfo.height - crop[0] - crop[1];
3639 width = MOD_DOWN(crop_width, mod);
3640 height = MOD_DOWN(crop_height, mod);
3642 need1 = (crop_height - height) / 2;
3643 need2 = crop_height - height - need1;
3646 need1 = (crop_width - width) / 2;
3647 need2 = crop_width - width - need1;
3650 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3651 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3652 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3653 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3655 hb_reduce(&aspect_n, &aspect_d,
3656 title->width * title->pixel_aspect_width,
3657 title->height * title->pixel_aspect_height);
3658 crop_width = title->width - crop[2] - crop[3];
3659 crop_height = title->height - crop[0] - crop[1];
3663 height = crop_height;
3667 width = ghb_settings_get_int(ud->settings, "scale_width");
3668 height = ghb_settings_get_int(ud->settings, "scale_height");
3669 if (mode & GHB_PIC_USE_MAX)
3671 max_width = MOD_DOWN(
3672 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3673 max_height = MOD_DOWN(
3674 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3677 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3680 width = title->width - crop[2] - crop[3];
3682 height = title->height - crop[0] - crop[1];
3684 width = MOD_ROUND(width, mod);
3685 height = MOD_ROUND(height, mod);
3687 job->anamorphic.mode = pic_par;
3690 // The scaler crashes if the dimensions are not divisible by 2
3691 // Align mod 2. And so does something in x264_encoder_headers()
3693 job->anamorphic.par_width = title->pixel_aspect_width;
3694 job->anamorphic.par_height = title->pixel_aspect_height;
3695 job->anamorphic.dar_width = 0;
3696 job->anamorphic.dar_height = 0;
3698 if (keep_height && pic_par == 2)
3699 width = ((double)height * crop_width / crop_height);
3701 job->height = height;
3702 job->maxWidth = max_width;
3703 job->maxHeight = max_height;
3704 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3705 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3706 if (job->anamorphic.mode == 3 && !keep_aspect)
3708 job->anamorphic.keep_display_aspect = 0;
3709 if (mode & GHB_PIC_KEEP_PAR)
3711 job->anamorphic.par_width =
3712 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3713 job->anamorphic.par_height =
3714 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3718 job->anamorphic.dar_width =
3719 ghb_settings_get_int(ud->settings,
3720 "PictureDisplayWidth");
3721 job->anamorphic.dar_height = height;
3726 job->anamorphic.keep_display_aspect = 1;
3728 // hb_set_anamorphic_size will adjust par, dar, and width/height
3729 // to conform to job parameters that have been set, including
3730 // maxWidth and maxHeight
3731 hb_set_anamorphic_size( job, &width, &height,
3732 &par_width, &par_height );
3733 if (job->anamorphic.mode == 3 && !keep_aspect &&
3734 mode & GHB_PIC_KEEP_PAR)
3736 // hb_set_anamorphic_size reduces the par, which we
3737 // don't want in this case because the user is
3738 // explicitely specifying it.
3739 par_width = ghb_settings_get_int(ud->settings,
3741 par_height = ghb_settings_get_int(ud->settings,
3742 "PicturePARHeight");
3747 // Adjust dims according to max values
3749 height = MIN(height, max_height);
3751 width = MIN(width, max_width);
3756 gint new_width, new_height;
3758 // Compute pixel aspect ration.
3759 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3760 // Must scale so that par becomes 1:1
3761 // Try to keep largest dimension
3762 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3763 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3765 if (max_width && new_width > max_width)
3767 height = new_height;
3769 else if (max_height && new_height > max_height)
3773 else if (keep_width)
3775 height = new_height;
3777 else if (keep_height)
3781 else if (width > new_width)
3783 height = new_height;
3789 g_debug("new w %d h %d\n", width, height);
3791 width = MOD_ROUND(width, mod);
3792 height = MOD_ROUND(height, mod);
3794 height = MIN(height, max_height);
3796 width = MIN(width, max_width);
3797 par_width = par_height = 1;
3799 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3800 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3802 gint disp_width, dar_width, dar_height;
3805 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3806 hb_reduce(&dar_width, &dar_height, disp_width, height);
3808 gint iaspect = dar_width * 9 / dar_height;
3809 if (dar_width > 2 * dar_height)
3811 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3813 else if (iaspect <= 16 && iaspect >= 15)
3815 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3817 else if (iaspect <= 12 && iaspect >= 11)
3819 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3823 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3825 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3827 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3828 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3829 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3830 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3831 ud->scale_busy = FALSE;
3835 set_preview_job_settings(hb_job_t *job, GValue *settings)
3837 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3838 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3839 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3840 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3842 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3844 ghb_settings_combo_int(settings, "PictureModulus");
3845 job->width = ghb_settings_get_int(settings, "scale_width");
3846 job->height = ghb_settings_get_int(settings, "scale_height");
3847 if (ghb_settings_get_boolean(settings, "show_crop"))
3849 gdouble xscale = (gdouble)job->width /
3850 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3851 gdouble yscale = (gdouble)job->height /
3852 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3854 job->width += xscale * (job->crop[2] + job->crop[3]);
3855 job->height += yscale * (job->crop[0] + job->crop[1]);
3863 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3866 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3867 job->deinterlace = (decomb == 0) ? 0 : 1;
3871 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3872 job->deinterlace = (deint == 0) ? 0 : 1;
3875 gboolean keep_aspect;
3876 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3877 if (job->anamorphic.mode)
3879 job->anamorphic.par_width = job->title->pixel_aspect_width;
3880 job->anamorphic.par_height = job->title->pixel_aspect_height;
3881 job->anamorphic.dar_width = 0;
3882 job->anamorphic.dar_height = 0;
3884 if (job->anamorphic.mode == 3 && !keep_aspect)
3886 job->anamorphic.keep_display_aspect = 0;
3887 job->anamorphic.par_width =
3888 ghb_settings_get_int(settings, "PicturePARWidth");
3889 job->anamorphic.par_height =
3890 ghb_settings_get_int(settings, "PicturePARHeight");
3894 job->anamorphic.keep_display_aspect = 1;
3900 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3907 if (h_scan == NULL) return 1500;
3908 list = hb_get_titles( h_scan );
3909 title = hb_list_item( list, titleindex );
3910 if (title == NULL) return 1500;
3912 if (job == NULL) return 1500;
3913 size = ghb_settings_get_int(settings, "VideoTargetSize");
3914 return hb_calc_bitrate( job, size );
3918 ghb_validate_filter_string(const gchar *str, gint max_fields)
3924 if (str == NULL || *str == 0) return TRUE;
3927 val = g_strtod(str, &end);
3929 { // Found a numeric value
3931 // negative max_fields means infinate
3932 if (max_fields >= 0 && fields > max_fields) return FALSE;
3946 ghb_validate_filters(signal_user_data_t *ud)
3952 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3954 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3955 if (!decomb_deint && index == 1)
3957 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3958 if (!ghb_validate_filter_string(str, -1))
3960 message = g_strdup_printf(
3961 "Invalid Deinterlace Settings:\n\n%s\n",
3963 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3971 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3974 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3975 if (!ghb_validate_filter_string(str, -1))
3977 message = g_strdup_printf(
3978 "Invalid Detelecine Settings:\n\n%s\n",
3980 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3988 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3989 if (decomb_deint && index == 1)
3991 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3992 if (!ghb_validate_filter_string(str, -1))
3994 message = g_strdup_printf(
3995 "Invalid Decomb Settings:\n\n%s\n",
3997 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4005 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
4008 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
4009 if (!ghb_validate_filter_string(str, -1))
4011 message = g_strdup_printf(
4012 "Invalid Denoise Settings:\n\n%s\n",
4014 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
4025 ghb_validate_video(signal_user_data_t *ud)
4030 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4031 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
4032 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
4034 // mp4/theora combination is not supported.
4035 message = g_strdup_printf(
4036 "Theora is not supported in the MP4 container.\n\n"
4037 "You should choose a different video codec or container.\n"
4038 "If you continue, FFMPEG will be chosen for you.");
4039 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4045 vcodec = HB_VCODEC_FFMPEG;
4046 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
4052 ghb_validate_subtitles(signal_user_data_t *ud)
4058 if (h_scan == NULL) return FALSE;
4059 list = hb_get_titles( h_scan );
4060 if( !hb_list_count( list ) )
4062 /* No valid title, stop right there */
4063 g_message("No title found.\n");
4069 titleindex = ghb_settings_combo_int(ud->settings, "title");
4070 title = hb_list_item( list, titleindex );
4071 if (title == NULL) return FALSE;
4073 const GValue *slist, *settings;
4074 gint count, ii, source;
4075 gboolean burned, one_burned = FALSE;
4077 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
4078 count = ghb_array_len(slist);
4079 for (ii = 0; ii < count; ii++)
4081 settings = ghb_array_get_nth(slist, ii);
4082 source = ghb_settings_get_int(settings, "SubtitleSource");
4083 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
4084 if (burned && one_burned)
4086 // MP4 can only handle burned vobsubs. make sure there isn't
4087 // already something burned in the list
4088 message = g_strdup_printf(
4089 "Only one subtitle may be burned into the video.\n\n"
4090 "You should change your subtitle selections.\n"
4091 "If you continue, some subtitles will be lost.");
4092 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4104 if (source == SRTSUB)
4108 filename = ghb_settings_get_string(settings, "SrtFile");
4109 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4111 message = g_strdup_printf(
4112 "Srt file does not exist or not a regular file.\n\n"
4113 "You should choose a valid file.\n"
4114 "If you continue, this subtitle will be ignored.");
4115 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
4116 "Cancel", "Continue"))
4130 ghb_select_audio_codec(GValue *settings, gint acodec, gint track)
4134 hb_audio_config_t *audio;
4136 if (h_scan == NULL) return -1;
4137 list = hb_get_titles( h_scan );
4138 if( !hb_list_count( list ) )
4145 titleindex = ghb_settings_combo_int(settings, "title");
4146 title = hb_list_item( list, titleindex );
4147 if (title == NULL) return -1;
4149 gint mux = ghb_settings_combo_int(settings, "FileFormat");
4151 if (track < 0 || track >= hb_list_count(title->list_audio))
4154 audio = (hb_audio_config_t *) hb_list_audio_config_item(
4155 title->list_audio, track );
4157 if (mux == HB_MUX_MP4)
4159 if ((acodec & audio->in.codec & HB_ACODEC_AC3))
4161 return acodec & (audio->in.codec | HB_ACODEC_PASS_FLAG);
4163 else if (acodec & HB_ACODEC_AC3)
4165 return HB_ACODEC_AC3;
4167 else if (acodec & HB_ACODEC_FAAC)
4169 return HB_ACODEC_FAAC;
4173 return HB_ACODEC_FAAC;
4178 if ((acodec & audio->in.codec & HB_ACODEC_PASS_MASK))
4180 return acodec & (audio->in.codec | HB_ACODEC_PASS_FLAG);
4182 else if (acodec & HB_ACODEC_AC3)
4184 return HB_ACODEC_AC3;
4186 else if (acodec & HB_ACODEC_VORBIS)
4188 return HB_ACODEC_VORBIS;
4190 else if (acodec & HB_ACODEC_LAME)
4192 return HB_ACODEC_LAME;
4196 return HB_ACODEC_LAME;
4202 ghb_select_audio_codec_str(GValue *settings, gint icodec, gint track)
4206 acodec = ghb_select_audio_codec(settings, icodec, track);
4207 for (ii = 0; ii < acodec_opts.count; ii++)
4209 if (acodec_opts.map[ii].ivalue == acodec)
4210 return acodec_opts.map[ii].option;
4216 ghb_validate_audio(signal_user_data_t *ud)
4223 if (h_scan == NULL) return FALSE;
4224 list = hb_get_titles( h_scan );
4225 if( !hb_list_count( list ) )
4227 /* No valid title, stop right there */
4228 g_message("No title found.\n");
4234 titleindex = ghb_settings_combo_int(ud->settings, "title");
4235 title = hb_list_item( list, titleindex );
4236 if (title == NULL) return FALSE;
4237 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4239 const GValue *audio_list;
4242 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
4243 count = ghb_array_len(audio_list);
4244 for (ii = 0; ii < count; ii++)
4247 hb_audio_config_t *taudio;
4249 asettings = ghb_array_get_nth(audio_list, ii);
4250 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4251 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4252 if (codec == HB_ACODEC_ANY)
4255 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4256 title->list_audio, track );
4257 if ( ghb_audio_is_passthru(codec) &&
4258 !(ghb_audio_can_passthru(taudio->in.codec) &&
4259 (taudio->in.codec & codec)))
4261 // Not supported. AC3 is passthrough only, so input must be AC3
4262 message = g_strdup_printf(
4263 "The source does not support Pass-Thru.\n\n"
4264 "You should choose a different audio codec.\n"
4265 "If you continue, one will be chosen for you.");
4266 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4272 if ((codec & HB_ACODEC_AC3) ||
4273 taudio->in.codec == HB_ACODEC_DCA)
4275 codec = HB_ACODEC_AC3;
4277 else if (mux == HB_MUX_MKV)
4279 codec = HB_ACODEC_LAME;
4283 codec = HB_ACODEC_FAAC;
4285 value = ghb_lookup_acodec_value(codec);
4286 ghb_settings_take_value(asettings, "AudioEncoder", value);
4288 gchar *a_unsup = NULL;
4289 gchar *mux_s = NULL;
4290 if (mux == HB_MUX_MP4)
4293 // mp4/vorbis|DTS combination is not supported.
4294 if (codec == HB_ACODEC_VORBIS)
4297 codec = HB_ACODEC_FAAC;
4299 if (codec == HB_ACODEC_DCA)
4302 codec = HB_ACODEC_AC3;
4307 message = g_strdup_printf(
4308 "%s is not supported in the %s container.\n\n"
4309 "You should choose a different audio codec.\n"
4310 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4311 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4317 value = ghb_lookup_acodec_value(codec);
4318 ghb_settings_take_value(asettings, "AudioEncoder", value);
4320 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4321 gboolean allow_mono = TRUE;
4322 gboolean allow_stereo = TRUE;
4323 gboolean allow_dolby = TRUE;
4324 gboolean allow_dpl2 = TRUE;
4325 gboolean allow_6ch = TRUE;
4327 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4329 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4331 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4332 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4333 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4334 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4336 (codec & ~HB_ACODEC_LAME) &&
4337 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4338 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4340 gchar *mix_unsup = NULL;
4341 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4345 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4347 mix_unsup = "stereo";
4349 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4351 mix_unsup = "Dolby";
4353 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4355 mix_unsup = "Dolby Pro Logic II";
4357 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4359 mix_unsup = "6 Channel";
4363 message = g_strdup_printf(
4364 "The source audio does not support %s mixdown.\n\n"
4365 "You should choose a different mixdown.\n"
4366 "If you continue, one will be chosen for you.", mix_unsup);
4367 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4373 mix = ghb_get_best_mix(titleindex, track, codec, mix);
4374 value = get_amix_value(mix);
4375 ghb_settings_take_value(asettings, "AudioMixdown", value);
4382 ghb_validate_vquality(GValue *settings)
4388 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4389 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4391 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4392 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4396 case HB_VCODEC_X264:
4402 case HB_VCODEC_FFMPEG:
4408 case HB_VCODEC_THEORA:
4420 if (vquality < min || vquality > max)
4422 message = g_strdup_printf(
4423 "Interesting video quality choise: %d\n\n"
4424 "Typical values range from %d to %d.\n"
4425 "Are you sure you wish to use this setting?",
4426 (gint)vquality, min, max);
4427 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4428 "Cancel", "Continue"))
4440 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4445 static gchar *x264opts;
4447 gboolean tweaks = FALSE;
4448 gchar *detel_str = NULL;
4449 gchar *decomb_str = NULL;
4450 gchar *deint_str = NULL;
4451 gchar *deblock_str = NULL;
4452 gchar *denoise_str = NULL;
4453 gchar *dest_str = NULL;
4455 g_debug("add_job()\n");
4456 if (h == NULL) return;
4457 list = hb_get_titles( h );
4458 if( !hb_list_count( list ) )
4460 /* No valid title, stop right there */
4464 title = hb_list_item( list, titleindex );
4465 if (title == NULL) return;
4467 /* Set job settings */
4469 if (job == NULL) return;
4471 job->angle = ghb_settings_get_int(js, "angle");
4472 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4473 if (job->start_at_preview)
4475 job->seek_points = ghb_settings_get_int(js, "preview_count");
4476 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4479 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4480 job->mux = ghb_settings_combo_int(js, "FileFormat");
4481 if (job->mux == HB_MUX_MP4)
4483 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4484 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4488 job->largeFileSize = FALSE;
4489 job->mp4_optimize = FALSE;
4491 if (!job->start_at_preview)
4494 gint num_chapters = hb_list_count(title->list_chapter);
4495 gint duration = title->duration / 90000;
4496 job->chapter_start = 1;
4497 job->chapter_end = num_chapters;
4499 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4501 start = ghb_settings_get_int(js, "start_point");
4502 end = ghb_settings_get_int(js, "end_point");
4503 job->chapter_start = MIN( num_chapters, start );
4504 job->chapter_end = MAX( job->chapter_start, end );
4507 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4509 job->chapter_start = 1;
4510 job->chapter_end = num_chapters;
4511 start = ghb_settings_get_int(js, "start_point");
4512 end = ghb_settings_get_int(js, "end_point");
4513 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4514 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4517 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4519 job->chapter_start = 1;
4520 job->chapter_end = num_chapters;
4521 start = ghb_settings_get_int(js, "start_point");
4522 end = ghb_settings_get_int(js, "end_point");
4524 max_frames = (gint64)duration * title->rate / title->rate_base;
4525 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4526 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4527 job->frame_to_start;
4529 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4530 if (job->chapter_start == job->chapter_end)
4531 job->chapter_markers = 0;
4532 if ( job->chapter_markers )
4539 chapters = ghb_settings_get_value(js, "chapter_list");
4540 count = ghb_array_len(chapters);
4541 for(chap = 0; chap < count; chap++)
4543 hb_chapter_t * chapter_s;
4547 chapter = ghb_array_get_nth(chapters, chap);
4548 name = ghb_value_string(chapter);
4551 name = g_strdup_printf ("Chapter %2d", chap+1);
4553 chapter_s = hb_list_item( job->title->list_chapter, chap);
4554 strncpy(chapter_s->title, name, 1023);
4555 chapter_s->title[1023] = '\0';
4560 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4561 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4562 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4563 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4566 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4567 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4568 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4570 job->deinterlace = (deint != 0) ? 1 : 0;
4572 job->deinterlace = 0;
4573 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4575 gboolean keep_aspect;
4576 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4577 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4578 job->modulus = ghb_settings_combo_int(js, "PictureModulus");
4579 if (job->anamorphic.mode)
4581 job->anamorphic.par_width = title->pixel_aspect_width;
4582 job->anamorphic.par_height = title->pixel_aspect_height;
4583 job->anamorphic.dar_width = 0;
4584 job->anamorphic.dar_height = 0;
4586 if (job->anamorphic.mode == 3 && !keep_aspect)
4588 job->anamorphic.keep_display_aspect = 0;
4589 job->anamorphic.par_width =
4590 ghb_settings_get_int(js, "PicturePARWidth");
4591 job->anamorphic.par_height =
4592 ghb_settings_get_int(js, "PicturePARHeight");
4596 job->anamorphic.keep_display_aspect = 1;
4600 /* Add selected filters */
4601 job->filters = hb_list_init();
4602 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4607 if (detel_opts.map[detel].svalue != NULL)
4608 detel_str = g_strdup(detel_opts.map[detel].svalue);
4611 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4612 hb_filter_detelecine.settings = detel_str;
4613 hb_list_add( job->filters, &hb_filter_detelecine );
4615 if ( decomb_deint && decomb )
4619 if (decomb_opts.map[decomb].svalue != NULL)
4620 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4623 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4624 hb_filter_decomb.settings = decomb_str;
4625 hb_list_add( job->filters, &hb_filter_decomb );
4627 if( job->deinterlace )
4631 if (deint_opts.map[deint].svalue != NULL)
4632 deint_str = g_strdup(deint_opts.map[deint].svalue);
4635 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4636 hb_filter_deinterlace.settings = deint_str;
4637 hb_list_add( job->filters, &hb_filter_deinterlace );
4639 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4642 deblock_str = g_strdup_printf("%d", deblock);
4643 hb_filter_deblock.settings = deblock_str;
4644 hb_list_add( job->filters, &hb_filter_deblock );
4646 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4651 if (denoise_opts.map[denoise].svalue != NULL)
4652 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4655 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4656 hb_filter_denoise.settings = denoise_str;
4657 hb_list_add( job->filters, &hb_filter_denoise );
4659 job->width = ghb_settings_get_int(js, "scale_width");
4660 job->height = ghb_settings_get_int(js, "scale_height");
4662 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4663 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4665 // mp4/theora combination is not supported.
4666 job->vcodec = HB_VCODEC_FFMPEG;
4668 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4670 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4672 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4675 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4676 job->vquality = vquality;
4679 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4681 job->vquality = -1.0;
4682 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4685 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4688 job->vrate = title->rate;
4689 job->vrate_base = title->rate_base;
4694 job->vrate = 27000000;
4695 job->vrate_base = vrate;
4696 gboolean pfr = ghb_settings_get_boolean(js, "VideoFrameratePFR");
4703 const GValue *audio_list;
4707 audio_list = ghb_settings_get_value(js, "audio_list");
4708 count = ghb_array_len(audio_list);
4709 for (ii = 0; ii < count; ii++)
4712 hb_audio_config_t audio;
4713 hb_audio_config_t *taudio;
4716 hb_audio_config_init(&audio);
4717 asettings = ghb_array_get_nth(audio_list, ii);
4718 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4719 audio.out.track = tcount;
4720 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
4721 audio.out.codec = ghb_select_audio_codec(js, acodec, audio.in.track);
4723 taudio = (hb_audio_config_t *) hb_list_audio_config_item(
4724 title->list_audio, audio.in.track );
4725 audio.out.dynamic_range_compression =
4726 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4727 if (audio.out.dynamic_range_compression < 1.0)
4728 audio.out.dynamic_range_compression = 0.0;
4730 // It would be better if this were done in libhb for us, but its not yet.
4731 if (ghb_audio_is_passthru(audio.out.codec))
4733 audio.out.mixdown = 0;
4737 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4738 // Make sure the mixdown is valid and pick a new one if not.
4739 audio.out.mixdown = ghb_get_best_mix(titleindex,
4740 audio.in.track, audio.out.codec, audio.out.mixdown);
4742 ghb_settings_combo_int(asettings, "AudioBitrate");
4743 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4744 if (srate == 0) // 0 is same as source
4745 audio.out.samplerate = taudio->in.samplerate;
4747 audio.out.samplerate = srate;
4749 audio.out.bitrate = hb_get_best_audio_bitrate(
4750 audio.out.codec, audio.out.bitrate,
4751 audio.out.samplerate, audio.out.mixdown);
4754 // Add it to the jobs audio list
4755 hb_audio_add( job, &audio );
4758 // I was tempted to move this up with the reset of the video quality
4759 // settings, but I suspect the settings above need to be made
4760 // first in order for hb_calc_bitrate to be accurate.
4761 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4765 size = ghb_settings_get_int(js, "VideoTargetSize");
4766 job->vbitrate = hb_calc_bitrate( job, size );
4767 job->vquality = -1.0;
4770 dest_str = ghb_settings_get_string(js, "destination");
4771 job->file = dest_str;
4773 const GValue *subtitle_list;
4775 gboolean force, burned, def, one_burned = FALSE;
4777 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4778 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4779 count = ghb_array_len(subtitle_list);
4780 for (ii = 0; ii < count; ii++)
4785 ssettings = ghb_array_get_nth(subtitle_list, ii);
4787 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4788 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4789 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4790 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4792 if (source == SRTSUB)
4794 hb_subtitle_config_t sub_config;
4795 gchar *filename, *lang, *code;
4797 filename = ghb_settings_get_string(ssettings, "SrtFile");
4798 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4802 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4803 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4804 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4805 strncpy(sub_config.src_filename, filename, 128);
4806 strncpy(sub_config.src_codeset, code, 40);
4807 sub_config.force = 0;
4808 sub_config.dest = PASSTHRUSUB;
4809 sub_config.default_track = def;
4811 hb_srt_add( job, &sub_config, lang);
4819 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4824 job->select_subtitle_config.dest = PASSTHRUSUB;
4828 // Only allow one subtitle to be burned into the video
4831 job->select_subtitle_config.dest = RENDERSUB;
4834 job->select_subtitle_config.force = force;
4835 job->select_subtitle_config.default_track = def;
4836 job->indepth_scan = 1;
4837 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4839 else if (subtitle >= 0)
4841 hb_subtitle_t * subt;
4842 hb_subtitle_config_t sub_config;
4844 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4847 sub_config = subt->config;
4850 sub_config.dest = PASSTHRUSUB;
4852 else if ( burned && canBurn(subt->source) )
4854 // Only allow one subtitle to be burned into the video
4857 sub_config.dest = RENDERSUB;
4860 sub_config.force = force;
4861 sub_config.default_track = def;
4862 hb_subtitle_add( job, &sub_config, subtitle );
4867 // TODO: libhb holds onto a reference to the x264opts and is not
4868 // finished with it until encoding the job is done. But I can't
4869 // find a way to get at the job before it is removed in order to
4870 // free up the memory I am allocating here.
4871 // The short story is THIS LEAKS.
4872 x264opts = ghb_build_x264opts_string(js);
4874 if( *x264opts == '\0' )
4880 if (job->indepth_scan == 1)
4882 // Subtitle scan. Look for subtitle matching audio language
4885 * When subtitle scan is enabled do a fast pre-scan job
4886 * which will determine which subtitles to enable, if any.
4889 job->indepth_scan = 1;
4890 job->x264opts = NULL;
4893 * Add the pre-scan job
4895 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4899 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4900 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4903 * If subtitle_scan is enabled then only turn it on
4904 * for the second pass and then off again for the
4908 job->indepth_scan = 0;
4911 * If turbo options have been selected then append them
4912 * to the x264opts now (size includes one ':' and the '\0')
4914 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4916 gchar *tmp_x264opts;
4920 badapt = ghb_lookup_badapt(x264opts);
4923 extra_opts = g_strdup_printf("%s", turbo_opts);
4927 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4932 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4937 * No x264opts to modify, but apply the turbo options
4938 * anyway as they may be modifying defaults
4940 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4944 job->x264opts = tmp_x264opts;
4948 job->x264opts = x264opts;
4950 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4952 //if (job->x264opts != NULL)
4953 // g_free(job->x264opts);
4957 * On the second pass we turn off subtitle scan so that we
4958 * can actually encode using any subtitles that were auto
4959 * selected in the first pass (using the whacky select-subtitle
4960 * attribute of the job).
4962 job->indepth_scan = 0;
4963 job->x264opts = x264opts;
4964 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4966 //if (job->x264opts != NULL)
4967 // g_free(job->x264opts);
4971 job->x264opts = x264opts;
4972 job->indepth_scan = 0;
4974 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4976 //if (job->x264opts != NULL)
4977 // g_free(job->x264opts);
4980 // clean up audio list
4981 gint num_audio_tracks = hb_list_count(job->list_audio);
4982 for(ii = 0; ii < num_audio_tracks; ii++)
4984 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4985 hb_list_rem(job->list_audio, audio);
4989 // clean up subtitle list
4990 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4991 for(ii = 0; ii < num_subtitle_tracks; ii++)
4993 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4994 hb_list_rem(job->list_subtitle, subtitle);
4998 if (detel_str) g_free(detel_str);
4999 if (decomb_str) g_free(decomb_str);
5000 if (deint_str) g_free(deint_str);
5001 if (deblock_str) g_free(deblock_str);
5002 if (denoise_str) g_free(denoise_str);
5003 if (dest_str) g_free(dest_str);
5007 ghb_add_job(GValue *js, gint unique_id)
5009 // Since I'm doing a scan of the single title I want just prior
5010 // to adding the job, there is only the one title to choose from.
5011 add_job(h_queue, js, unique_id, 0);
5015 ghb_add_live_job(GValue *js, gint unique_id)
5017 // Since I'm doing a scan of the single title I want just prior
5018 // to adding the job, there is only the one title to choose from.
5019 gint titleindex = ghb_settings_combo_int(js, "title");
5020 add_job(h_scan, js, unique_id, titleindex);
5024 ghb_remove_job(gint unique_id)
5029 // Multiples passes all get the same id
5031 // Go backwards through list, so reordering doesn't screw me.
5032 ii = hb_count(h_queue) - 1;
5033 while ((job = hb_job(h_queue, ii--)) != NULL)
5035 if ((job->sequence_id & 0xFFFFFF) == unique_id)
5036 hb_rem(h_queue, job);
5043 hb_start( h_queue );
5053 ghb_start_live_encode()
5059 ghb_stop_live_encode()
5068 hb_get_state2( h_queue, &s );
5070 if( s.state == HB_STATE_PAUSED )
5072 hb_status.queue.state &= ~GHB_STATE_PAUSED;
5073 hb_resume( h_queue );
5077 hb_status.queue.state |= GHB_STATE_PAUSED;
5078 hb_pause( h_queue );
5093 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5096 gint channels = gdk_pixbuf_get_n_channels (pb);
5097 gint stride = gdk_pixbuf_get_rowstride (pb);
5099 for (jj = 0; jj < width; jj++)
5101 dst = pixels + y * stride + (x+jj) * channels;
5102 for (ii = 0; ii < len; ii++)
5123 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5126 gint channels = gdk_pixbuf_get_n_channels (pb);
5127 gint stride = gdk_pixbuf_get_rowstride (pb);
5129 for (jj = 0; jj < width; jj++)
5131 dst = pixels + (y+jj) * stride + x * channels;
5132 for (ii = 0; ii < len; ii++)
5153 gint line_width = 8;
5160 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
5165 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
5167 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
5173 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
5175 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
5181 ghb_get_preview_image(
5184 signal_user_data_t *ud,
5192 settings = ud->settings;
5193 list = hb_get_titles( h_scan );
5194 if( !hb_list_count( list ) )
5196 /* No valid title, stop right there */
5199 title = hb_list_item( list, titleindex );
5200 if (title == NULL) return NULL;
5201 if (title->job == NULL) return NULL;
5202 set_preview_job_settings(title->job, settings);
5204 // hb_get_preview doesn't compensate for anamorphic, so lets
5205 // calculate scale factors
5206 gint width, height, par_width = 1, par_height = 1;
5207 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5210 hb_set_anamorphic_size( title->job, &width, &height,
5211 &par_width, &par_height );
5214 // Make sure we have a big enough buffer to receive the image from libhb
5215 gint dstWidth = title->job->width;
5216 gint dstHeight= title->job->height;
5218 static guint8 *buffer = NULL;
5219 static gint bufferSize = 0;
5222 newSize = dstWidth * dstHeight * 4;
5223 if( bufferSize < newSize )
5225 bufferSize = newSize;
5226 buffer = (guint8*) g_realloc( buffer, bufferSize );
5228 hb_get_preview( h_scan, title, index, buffer );
5230 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5231 // libhb's format something suitable.
5233 // The image data returned by hb_get_preview is 4 bytes per pixel,
5234 // BGRA format. Alpha is ignored.
5236 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5237 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5239 guint32 *src = (guint32*)buffer;
5240 guint8 *dst = pixels;
5243 gint channels = gdk_pixbuf_get_n_channels (preview);
5244 gint stride = gdk_pixbuf_get_rowstride (preview);
5247 for (ii = 0; ii < dstHeight; ii++)
5250 for (jj = 0; jj < dstWidth; jj++)
5252 tmp[0] = src[0] >> 16;
5253 tmp[1] = src[0] >> 8;
5254 tmp[2] = src[0] >> 0;
5260 gint w = ghb_settings_get_int(settings, "scale_width");
5261 gint h = ghb_settings_get_int(settings, "scale_height");
5262 ghb_par_scale(ud, &w, &h, par_width, par_height);
5264 gint c0, c1, c2, c3;
5265 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5266 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5267 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5268 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5270 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5271 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5273 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5276 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5280 gint orig_w, orig_h;
5283 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5287 ss = gdk_screen_get_default();
5288 s_w = gdk_screen_get_width(ss);
5289 s_h = gdk_screen_get_height(ss);
5293 if (dstWidth > s_w * factor / 100)
5295 dstWidth = s_w * factor / 100;
5296 dstHeight = dstHeight * dstWidth / orig_w;
5298 if (dstHeight > s_h * factor / 100)
5300 dstHeight = s_h * factor / 100;
5301 dstWidth = dstWidth * dstHeight / orig_h;
5303 xscale *= (gdouble)dstWidth / orig_w;
5304 yscale *= (gdouble)dstHeight / orig_h;
5305 w *= (gdouble)dstWidth / orig_w;
5306 h *= (gdouble)dstHeight / orig_h;
5308 GdkPixbuf *scaled_preview;
5309 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5310 if (ghb_settings_get_boolean(settings, "show_crop"))
5317 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5319 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5321 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5323 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5325 g_object_unref (preview);
5326 return scaled_preview;
5330 sanitize_volname(gchar *name)
5355 ghb_dvd_volname(const gchar *device)
5358 name = hb_dvd_name((gchar*)device);
5359 if (name != NULL && name[0] != 0)
5361 name = g_strdup(name);
5362 sanitize_volname(name);