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 {"Quit Handbrake", "quit", 4, "4"},
90 {"Put Computer To Sleep", "sleep", 2, "2"},
91 {"Shutdown Computer", "shutdown", 3, "3"},
93 combo_opts_t when_complete_opts =
95 sizeof(d_when_complete_opts)/sizeof(options_map_t),
99 static options_map_t d_par_opts[] =
101 {"Off", "0", 0, "0"},
102 {"Strict", "1", 1, "1"},
103 {"Loose", "2", 2, "2"},
104 {"Custom", "3", 3, "3"},
106 combo_opts_t par_opts =
108 sizeof(d_par_opts)/sizeof(options_map_t),
112 static options_map_t d_alignment_opts[] =
117 {"16", "16", 16, "16"},
119 combo_opts_t alignment_opts =
121 sizeof(d_alignment_opts)/sizeof(options_map_t),
125 static options_map_t d_logging_opts[] =
131 combo_opts_t logging_opts =
133 sizeof(d_logging_opts)/sizeof(options_map_t),
137 static options_map_t d_log_longevity_opts[] =
139 {"Week", "week", 7, "7"},
140 {"Month", "month", 30, "30"},
141 {"Year", "year", 365, "365"},
142 {"Immortal", "immortal", 366, "366"},
144 combo_opts_t log_longevity_opts =
146 sizeof(d_log_longevity_opts)/sizeof(options_map_t),
150 static options_map_t d_appcast_update_opts[] =
152 {"Never", "never", 0, "never"},
153 {"Daily", "daily", 1, "daily"},
154 {"Weekly", "weekly", 2, "weekly"},
155 {"Monthly", "monthly", 3, "monthly"},
157 combo_opts_t appcast_update_opts =
159 sizeof(d_appcast_update_opts)/sizeof(options_map_t),
160 d_appcast_update_opts
163 static options_map_t d_vqual_granularity_opts[] =
165 {"0.2", "0.2", 0.2, "0.2"},
166 {"0.25", "0.25", 0.25, "0.25"},
167 {"0.5", "0.5", 0.5, "0.5"},
170 combo_opts_t vqual_granularity_opts =
172 sizeof(d_vqual_granularity_opts)/sizeof(options_map_t),
173 d_vqual_granularity_opts
176 static options_map_t d_container_opts[] =
178 {"MKV", "mkv", HB_MUX_MKV, "mkv"},
179 {"MP4", "mp4", HB_MUX_MP4, "mp4"},
181 combo_opts_t container_opts =
183 sizeof(d_container_opts)/sizeof(options_map_t),
187 static options_map_t d_detel_opts[] =
189 {"Off", "off", 0, ""},
190 {"Custom", "custom", 1, ""},
191 {"Default","default",2, NULL},
193 combo_opts_t detel_opts =
195 sizeof(d_detel_opts)/sizeof(options_map_t),
199 static options_map_t d_decomb_opts[] =
201 {"Off", "off", 0, ""},
202 {"Custom", "custom", 1, ""},
203 {"Default","default",2, NULL},
205 combo_opts_t decomb_opts =
207 sizeof(d_decomb_opts)/sizeof(options_map_t),
211 static options_map_t d_deint_opts[] =
213 {"Off", "off", 0, ""},
214 {"Custom", "custom", 1, ""},
215 {"Fast", "fast", 2, "-1:-1:-1:0:1"},
216 {"Slow", "slow", 3, "2:-1:-1:0:1"},
217 {"Slower", "slower", 4, "0:-1:-1:0:1"},
219 combo_opts_t deint_opts =
221 sizeof(d_deint_opts)/sizeof(options_map_t),
225 static options_map_t d_denoise_opts[] =
227 {"Off", "off", 0, ""},
228 {"Custom", "custom", 1, ""},
229 {"Weak", "weak", 2, "2:1:2:3"},
230 {"Medium", "medium", 3, "3:2:2:3"},
231 {"Strong", "strong", 4, "7:7:5:5"},
233 combo_opts_t denoise_opts =
235 sizeof(d_denoise_opts)/sizeof(options_map_t),
239 static options_map_t d_vcodec_opts[] =
241 {"H.264 (x264)", "x264", HB_VCODEC_X264, ""},
242 {"MPEG-4 (FFmpeg)", "ffmpeg", HB_VCODEC_FFMPEG, ""},
243 {"VP3 (Theora)", "theora", HB_VCODEC_THEORA, ""},
245 combo_opts_t vcodec_opts =
247 sizeof(d_vcodec_opts)/sizeof(options_map_t),
251 static options_map_t d_acodec_opts[] =
253 {"AAC (faac)", "faac", HB_ACODEC_FAAC, "faac"},
254 {"MP3 (lame)", "lame", HB_ACODEC_LAME, "lame"},
255 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, "vorbis"},
256 {"AC3 (ffmpeg)", "ac3", HB_ACODEC_AC3, "ac3"},
257 {"AC3 (pass-thru)", "ac3pass", HB_ACODEC_AC3_PASS, "ac3pass"},
258 {"DTS (pass-thru)", "dtspass", HB_ACODEC_DCA_PASS, "dtspass"},
259 {"Choose For Me", "auto", HB_ACODEC_ANY, "auto"},
261 combo_opts_t acodec_opts =
263 sizeof(d_acodec_opts)/sizeof(options_map_t),
267 static options_map_t d_direct_opts[] =
269 {"None", "none", 0, "none"},
270 {"Spatial", "spatial", 1, "spatial"},
271 {"Temporal", "temporal", 2, "temporal"},
272 {"Automatic", "auto", 3, "auto"},
274 combo_opts_t direct_opts =
276 sizeof(d_direct_opts)/sizeof(options_map_t),
280 static options_map_t d_badapt_opts[] =
282 {"Off", "0", 0, "0"},
283 {"Fast", "1", 1, "1"},
284 {"Optimal", "2", 2, "2"},
286 combo_opts_t badapt_opts =
288 sizeof(d_badapt_opts)/sizeof(options_map_t),
292 static options_map_t d_bpyramid_opts[] =
294 {"Off", "none", 0, "none"},
295 {"Strict", "strict", 1, "strict"},
296 {"Normal", "normal", 2, "normal"},
298 combo_opts_t bpyramid_opts =
300 sizeof(d_bpyramid_opts)/sizeof(options_map_t),
304 static options_map_t d_weightp_opts[] =
306 {"Off", "0", 0, "0"},
307 {"Blind", "1", 1, "1"},
308 {"Smart", "2", 2, "2"},
310 combo_opts_t weightp_opts =
312 sizeof(d_weightp_opts)/sizeof(options_map_t),
316 static options_map_t d_me_opts[] =
318 {"Diamond", "dia", 0, "dia"},
319 {"Hexagon", "hex", 1, "hex"},
320 {"Uneven Multi-Hexagon", "umh", 2, "umh"},
321 {"Exhaustive", "esa", 3, "esa"},
322 {"Hadamard Exhaustive", "tesa", 4, "tesa"},
324 combo_opts_t me_opts =
326 sizeof(d_me_opts)/sizeof(options_map_t),
330 static options_map_t d_subme_opts[] =
332 {"0: SAD, no subpel", "0", 0, "0"},
333 {"1: SAD, qpel", "1", 1, "1"},
334 {"2: SATD, qpel", "2", 2, "2"},
335 {"3: SATD: multi-qpel", "3", 3, "3"},
336 {"4: SATD, qpel on all", "4", 4, "4"},
337 {"5: SATD, multi-qpel on all", "5", 5, "5"},
338 {"6: RD in I/P-frames", "6", 6, "6"},
339 {"7: RD in all frames", "7", 7, "7"},
340 {"8: RD refine in I/P-frames", "8", 8, "8"},
341 {"9: RD refine in all frames", "9", 9, "9"},
342 {"10: QPRD in all frames", "10", 10, "10"},
344 combo_opts_t subme_opts =
346 sizeof(d_subme_opts)/sizeof(options_map_t),
350 static options_map_t d_analyse_opts[] =
352 {"Most", "p8x8,b8x8,i8x8,i4x4", 0, "p8x8,b8x8,i8x8,i4x4"},
353 {"None", "none", 1, "none"},
354 {"Some", "i4x4,i8x8", 2, "i4x4,i8x8"},
355 {"All", "all", 3, "all"},
356 {"Custom", "custom", 4, "all"},
358 combo_opts_t analyse_opts =
360 sizeof(d_analyse_opts)/sizeof(options_map_t),
364 static options_map_t d_trellis_opts[] =
366 {"Off", "0", 0, "0"},
367 {"Encode only", "1", 1, "1"},
368 {"Always", "2", 2, "2"},
370 combo_opts_t trellis_opts =
372 sizeof(d_trellis_opts)/sizeof(options_map_t),
376 combo_opts_t subtitle_opts =
382 combo_opts_t title_opts =
388 combo_opts_t audio_track_opts =
400 combo_name_map_t combo_name_map[] =
402 {"PtoPType", &point_to_point_opts},
403 {"WhenComplete", &when_complete_opts},
404 {"PicturePAR", &par_opts},
405 {"PictureModulus", &alignment_opts},
406 {"LoggingLevel", &logging_opts},
407 {"LogLongevity", &log_longevity_opts},
408 {"check_updates", &appcast_update_opts},
409 {"VideoQualityGranularity", &vqual_granularity_opts},
410 {"FileFormat", &container_opts},
411 {"PictureDeinterlace", &deint_opts},
412 {"PictureDecomb", &decomb_opts},
413 {"PictureDetelecine", &detel_opts},
414 {"PictureDenoise", &denoise_opts},
415 {"VideoEncoder", &vcodec_opts},
416 {"AudioEncoder", &acodec_opts},
417 {"AudioEncoderActual", &acodec_opts},
418 {"x264_direct", &direct_opts},
419 {"x264_b_adapt", &badapt_opts},
420 {"x264_bpyramid", &bpyramid_opts},
421 {"x264_weighted_pframes", &weightp_opts},
422 {"x264_me", &me_opts},
423 {"x264_subme", &subme_opts},
424 {"x264_analyse", &analyse_opts},
425 {"x264_trellis", &trellis_opts},
426 {"SubtitleTrack", &subtitle_opts},
427 {"title", &title_opts},
428 {"AudioTrack", &audio_track_opts},
432 const gchar *srt_codeset_table[] =
471 #define SRT_TABLE_SIZE (sizeof(srt_codeset_table)/ sizeof(char*)-1)
474 typedef struct iso639_lang_t
476 char * eng_name; /* Description in English */
477 char * native_name; /* Description in native language */
478 char * iso639_1; /* ISO-639-1 (2 characters) code */
479 char * iso639_2; /* ISO-639-2/t (3 character) code */
480 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
484 const iso639_lang_t ghb_language_table[] =
486 { "Any", "", "zz", "und" },
487 { "Afar", "", "aa", "aar" },
488 { "Abkhazian", "", "ab", "abk" },
489 { "Afrikaans", "", "af", "afr" },
490 { "Akan", "", "ak", "aka" },
491 { "Albanian", "", "sq", "sqi", "alb" },
492 { "Amharic", "", "am", "amh" },
493 { "Arabic", "", "ar", "ara" },
494 { "Aragonese", "", "an", "arg" },
495 { "Armenian", "", "hy", "hye", "arm" },
496 { "Assamese", "", "as", "asm" },
497 { "Avaric", "", "av", "ava" },
498 { "Avestan", "", "ae", "ave" },
499 { "Aymara", "", "ay", "aym" },
500 { "Azerbaijani", "", "az", "aze" },
501 { "Bashkir", "", "ba", "bak" },
502 { "Bambara", "", "bm", "bam" },
503 { "Basque", "", "eu", "eus", "baq" },
504 { "Belarusian", "", "be", "bel" },
505 { "Bengali", "", "bn", "ben" },
506 { "Bihari", "", "bh", "bih" },
507 { "Bislama", "", "bi", "bis" },
508 { "Bosnian", "", "bs", "bos" },
509 { "Breton", "", "br", "bre" },
510 { "Bulgarian", "", "bg", "bul" },
511 { "Burmese", "", "my", "mya", "bur" },
512 { "Catalan", "", "ca", "cat" },
513 { "Chamorro", "", "ch", "cha" },
514 { "Chechen", "", "ce", "che" },
515 { "Chinese", "", "zh", "zho", "chi" },
516 { "Church Slavic", "", "cu", "chu" },
517 { "Chuvash", "", "cv", "chv" },
518 { "Cornish", "", "kw", "cor" },
519 { "Corsican", "", "co", "cos" },
520 { "Cree", "", "cr", "cre" },
521 { "Czech", "", "cs", "ces", "cze" },
522 { "Danish", "Dansk", "da", "dan" },
523 { "German", "Deutsch", "de", "deu", "ger" },
524 { "Divehi", "", "dv", "div" },
525 { "Dzongkha", "", "dz", "dzo" },
526 { "English", "English", "en", "eng" },
527 { "Spanish", "Espanol", "es", "spa" },
528 { "Esperanto", "", "eo", "epo" },
529 { "Estonian", "", "et", "est" },
530 { "Ewe", "", "ee", "ewe" },
531 { "Faroese", "", "fo", "fao" },
532 { "Fijian", "", "fj", "fij" },
533 { "French", "Francais", "fr", "fra", "fre" },
534 { "Western Frisian", "", "fy", "fry" },
535 { "Fulah", "", "ff", "ful" },
536 { "Georgian", "", "ka", "kat", "geo" },
537 { "Gaelic (Scots)", "", "gd", "gla" },
538 { "Irish", "", "ga", "gle" },
539 { "Galician", "", "gl", "glg" },
540 { "Manx", "", "gv", "glv" },
541 { "Greek, Modern", "", "el", "ell", "gre" },
542 { "Guarani", "", "gn", "grn" },
543 { "Gujarati", "", "gu", "guj" },
544 { "Haitian", "", "ht", "hat" },
545 { "Hausa", "", "ha", "hau" },
546 { "Hebrew", "", "he", "heb" },
547 { "Herero", "", "hz", "her" },
548 { "Hindi", "", "hi", "hin" },
549 { "Hiri Motu", "", "ho", "hmo" },
550 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
551 { "Igbo", "", "ig", "ibo" },
552 { "Ido", "", "io", "ido" },
553 { "Icelandic", "Islenska", "is", "isl", "ice" },
554 { "Sichuan Yi", "", "ii", "iii" },
555 { "Inuktitut", "", "iu", "iku" },
556 { "Interlingue", "", "ie", "ile" },
557 { "Interlingua", "", "ia", "ina" },
558 { "Indonesian", "", "id", "ind" },
559 { "Inupiaq", "", "ik", "ipk" },
560 { "Italian", "Italiano", "it", "ita" },
561 { "Javanese", "", "jv", "jav" },
562 { "Japanese", "", "ja", "jpn" },
563 { "Kalaallisut", "", "kl", "kal" },
564 { "Kannada", "", "kn", "kan" },
565 { "Kashmiri", "", "ks", "kas" },
566 { "Kanuri", "", "kr", "kau" },
567 { "Kazakh", "", "kk", "kaz" },
568 { "Central Khmer", "", "km", "khm" },
569 { "Kikuyu", "", "ki", "kik" },
570 { "Kinyarwanda", "", "rw", "kin" },
571 { "Kirghiz", "", "ky", "kir" },
572 { "Komi", "", "kv", "kom" },
573 { "Kongo", "", "kg", "kon" },
574 { "Korean", "", "ko", "kor" },
575 { "Kuanyama", "", "kj", "kua" },
576 { "Kurdish", "", "ku", "kur" },
577 { "Lao", "", "lo", "lao" },
578 { "Latin", "", "la", "lat" },
579 { "Latvian", "", "lv", "lav" },
580 { "Limburgan", "", "li", "lim" },
581 { "Lingala", "", "ln", "lin" },
582 { "Lithuanian", "", "lt", "lit" },
583 { "Luxembourgish", "", "lb", "ltz" },
584 { "Luba-Katanga", "", "lu", "lub" },
585 { "Ganda", "", "lg", "lug" },
586 { "Macedonian", "", "mk", "mkd", "mac" },
587 { "Hungarian", "Magyar", "hu", "hun" },
588 { "Marshallese", "", "mh", "mah" },
589 { "Malayalam", "", "ml", "mal" },
590 { "Maori", "", "mi", "mri", "mao" },
591 { "Marathi", "", "mr", "mar" },
592 { "Malay", "", "ms", "msa", "msa" },
593 { "Malagasy", "", "mg", "mlg" },
594 { "Maltese", "", "mt", "mlt" },
595 { "Moldavian", "", "mo", "mol" },
596 { "Mongolian", "", "mn", "mon" },
597 { "Nauru", "", "na", "nau" },
598 { "Navajo", "", "nv", "nav" },
599 { "Dutch", "Nederlands", "nl", "nld", "dut" },
600 { "Ndebele, South", "", "nr", "nbl" },
601 { "Ndebele, North", "", "nd", "nde" },
602 { "Ndonga", "", "ng", "ndo" },
603 { "Nepali", "", "ne", "nep" },
604 { "Norwegian", "Norsk", "no", "nor" },
605 { "Norwegian Nynorsk", "", "nn", "nno" },
606 { "Norwegian Bokmål", "", "nb", "nob" },
607 { "Chichewa; Nyanja", "", "ny", "nya" },
608 { "Occitan", "", "oc", "oci" },
609 { "Ojibwa", "", "oj", "oji" },
610 { "Oriya", "", "or", "ori" },
611 { "Oromo", "", "om", "orm" },
612 { "Ossetian", "", "os", "oss" },
613 { "Panjabi", "", "pa", "pan" },
614 { "Persian", "", "fa", "fas", "per" },
615 { "Pali", "", "pi", "pli" },
616 { "Polish", "", "pl", "pol" },
617 { "Portuguese", "Portugues", "pt", "por" },
618 { "Pushto", "", "ps", "pus" },
619 { "Quechua", "", "qu", "que" },
620 { "Romansh", "", "rm", "roh" },
621 { "Romanian", "", "ro", "ron", "rum" },
622 { "Rundi", "", "rn", "run" },
623 { "Russian", "", "ru", "rus" },
624 { "Sango", "", "sg", "sag" },
625 { "Sanskrit", "", "sa", "san" },
626 { "Serbian", "", "sr", "srp", "scc" },
627 { "Sinhala", "", "si", "sin" },
628 { "Slovak", "", "sk", "slk", "slo" },
629 { "Slovenian", "", "sl", "slv" },
630 { "Northern Sami", "", "se", "sme" },
631 { "Samoan", "", "sm", "smo" },
632 { "Shona", "", "sn", "sna" },
633 { "Sindhi", "", "sd", "snd" },
634 { "Somali", "", "so", "som" },
635 { "Sotho, Southern", "", "st", "sot" },
636 { "Sardinian", "", "sc", "srd" },
637 { "Swati", "", "ss", "ssw" },
638 { "Sundanese", "", "su", "sun" },
639 { "Finnish", "Suomi", "fi", "fin" },
640 { "Swahili", "", "sw", "swa" },
641 { "Swedish", "Svenska", "sv", "swe" },
642 { "Tahitian", "", "ty", "tah" },
643 { "Tamil", "", "ta", "tam" },
644 { "Tatar", "", "tt", "tat" },
645 { "Telugu", "", "te", "tel" },
646 { "Tajik", "", "tg", "tgk" },
647 { "Tagalog", "", "tl", "tgl" },
648 { "Thai", "", "th", "tha" },
649 { "Tibetan", "", "bo", "bod", "tib" },
650 { "Tigrinya", "", "ti", "tir" },
651 { "Tonga", "", "to", "ton" },
652 { "Tswana", "", "tn", "tsn" },
653 { "Tsonga", "", "ts", "tso" },
654 { "Turkmen", "", "tk", "tuk" },
655 { "Turkish", "", "tr", "tur" },
656 { "Twi", "", "tw", "twi" },
657 { "Uighur", "", "ug", "uig" },
658 { "Ukrainian", "", "uk", "ukr" },
659 { "Urdu", "", "ur", "urd" },
660 { "Uzbek", "", "uz", "uzb" },
661 { "Venda", "", "ve", "ven" },
662 { "Vietnamese", "", "vi", "vie" },
663 { "Volapük", "", "vo", "vol" },
664 { "Welsh", "", "cy", "cym", "wel" },
665 { "Walloon", "", "wa", "wln" },
666 { "Wolof", "", "wo", "wol" },
667 { "Xhosa", "", "xh", "xho" },
668 { "Yiddish", "", "yi", "yid" },
669 { "Yoruba", "", "yo", "yor" },
670 { "Zhuang", "", "za", "zha" },
671 { "Zulu", "", "zu", "zul" },
672 {NULL, NULL, NULL, NULL}
674 #define LANG_TABLE_SIZE (sizeof(ghb_language_table)/ sizeof(iso639_lang_t)-1)
676 static void audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name);
679 del_tree(const gchar *name, gboolean del_top)
683 if (g_file_test(name, G_FILE_TEST_IS_DIR))
685 GDir *gdir = g_dir_open(name, 0, NULL);
686 file = g_dir_read_name(gdir);
690 path = g_strdup_printf("%s/%s", name, file);
691 del_tree(path, TRUE);
693 file = g_dir_read_name(gdir);
708 return hb_get_version(NULL);
713 signal_user_data_t *ud,
721 gint vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
730 *step = ghb_settings_combo_double(ud->settings,
731 "VideoQualityGranularity");
732 if (*step == 0.2 || *step == 0.5)
734 else if (*step == 0.25)
739 case HB_VCODEC_FFMPEG:
747 case HB_VCODEC_THEORA:
766 find_combo_entry(combo_opts_t *opts, const GValue *gval)
770 if (G_VALUE_TYPE(gval) == G_TYPE_STRING)
773 str = ghb_value_string(gval);
774 for (ii = 0; ii < opts->count; ii++)
776 if (strcmp(opts->map[ii].shortOpt, str) == 0)
784 else if (G_VALUE_TYPE(gval) == G_TYPE_DOUBLE)
787 val = ghb_value_double(gval);
788 for (ii = 0; ii < opts->count; ii++)
790 if (opts->map[ii].ivalue == val)
797 else if (G_VALUE_TYPE(gval) == G_TYPE_INT ||
798 G_VALUE_TYPE(gval) == G_TYPE_BOOLEAN ||
799 G_VALUE_TYPE(gval) == G_TYPE_INT64)
802 val = ghb_value_int64(gval);
803 for (ii = 0; ii < opts->count; ii++)
805 if ((gint64)opts->map[ii].ivalue == val)
816 lookup_generic_string(combo_opts_t *opts, const GValue *gval)
819 const gchar *result = "";
821 ii = find_combo_entry(opts, gval);
822 if (ii < opts->count)
824 result = opts->map[ii].svalue;
830 lookup_generic_int(combo_opts_t *opts, const GValue *gval)
835 ii = find_combo_entry(opts, gval);
836 if (ii < opts->count)
838 result = opts->map[ii].ivalue;
844 lookup_generic_double(combo_opts_t *opts, const GValue *gval)
849 ii = find_combo_entry(opts, gval);
850 if (ii < opts->count)
852 result = opts->map[ii].ivalue;
858 lookup_generic_option(combo_opts_t *opts, const GValue *gval)
861 const gchar *result = "";
863 ii = find_combo_entry(opts, gval);
864 if (ii < opts->count)
866 result = opts->map[ii].option;
872 lookup_mix_int(const GValue *mix)
878 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
880 gchar * str = ghb_value_string(mix);
881 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
883 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
885 result = hb_audio_mixdowns[ii].amixdown;
891 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
892 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
893 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
895 gint val = ghb_value_int(mix);
896 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
898 if (hb_audio_mixdowns[ii].amixdown == val)
900 result = hb_audio_mixdowns[ii].amixdown;
909 lookup_mix_option(const GValue *mix)
912 gchar *result = "None";
915 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
917 gchar *str = ghb_value_string(mix);
918 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
920 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
922 result = hb_audio_mixdowns[ii].human_readable_name;
928 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
929 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
930 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
932 gint val = ghb_value_int(mix);
933 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
935 if (hb_audio_mixdowns[ii].amixdown == val)
937 result = hb_audio_mixdowns[ii].human_readable_name;
946 lookup_mix_string(const GValue *mix)
949 gchar *result = "None";
952 if (G_VALUE_TYPE(mix) == G_TYPE_STRING)
954 gchar *str = ghb_value_string(mix);
955 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
957 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
959 result = hb_audio_mixdowns[ii].short_name;
965 else if (G_VALUE_TYPE(mix) == G_TYPE_INT ||
966 G_VALUE_TYPE(mix) == G_TYPE_INT64 ||
967 G_VALUE_TYPE(mix) == G_TYPE_DOUBLE)
969 gint val = ghb_value_int(mix);
970 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
972 if (hb_audio_mixdowns[ii].amixdown == val)
974 result = hb_audio_mixdowns[ii].short_name;
983 lookup_video_rate_int(const GValue *vrate)
989 str = ghb_value_string(vrate);
990 for (ii = 0; ii < hb_video_rates_count; ii++)
992 if (strcmp(hb_video_rates[ii].string, str) == 0)
994 result = hb_video_rates[ii].rate;
999 // Default to "same as source"
1004 lookup_video_rate_option(const GValue *vrate)
1008 const gchar *result = "Same as source";
1010 str = ghb_value_string(vrate);
1011 for (ii = 0; ii < hb_video_rates_count; ii++)
1013 if (strcmp(hb_video_rates[ii].string, str) == 0)
1015 result = hb_video_rates[ii].string;
1020 // Default to "same as source"
1025 lookup_audio_rate_int(const GValue *rate)
1030 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1032 // Coincidentally, the string "source" will return 0
1033 // which is our flag to use "same as source"
1034 gchar * str = ghb_value_string(rate);
1035 for (ii = 0; ii < hb_audio_rates_count; ii++)
1037 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1039 result = hb_audio_rates[ii].rate;
1045 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1046 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1047 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1049 for (ii = 0; ii < hb_audio_rates_count; ii++)
1051 gint val = ghb_value_int(rate);
1052 if (val == hb_audio_rates[ii].rate)
1054 result = hb_audio_rates[ii].rate;
1063 lookup_audio_rate_option(const GValue *rate)
1066 const gchar *result = "Same as source";
1068 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1070 // Coincidentally, the string "source" will return 0
1071 // which is our flag to use "same as source"
1072 gchar *str = ghb_value_string(rate);
1073 for (ii = 0; ii < hb_audio_rates_count; ii++)
1075 if (strcmp(hb_audio_rates[ii].string, str) == 0)
1077 result = hb_audio_rates[ii].string;
1083 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1084 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1085 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1087 for (ii = 0; ii < hb_audio_rates_count; ii++)
1089 gint val = ghb_value_int(rate);
1090 if (val == hb_audio_rates[ii].rate)
1092 result = hb_audio_rates[ii].string;
1101 ghb_find_closest_audio_rate(gint rate)
1107 for (ii = 0; ii < hb_audio_rates_count; ii++)
1109 if (rate <= hb_audio_rates[ii].rate)
1111 result = hb_audio_rates[ii].rate;
1118 hb_rate_t *ghb_audio_bitrates;
1119 int ghb_audio_bitrates_count;
1122 lookup_audio_bitrate_int(const GValue *rate)
1127 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1129 // Coincidentally, the string "source" will return 0
1130 // which is our flag to use "same as source"
1131 gchar *str = ghb_value_string(rate);
1132 for (ii = 0; ii < ghb_audio_bitrates_count; ii++)
1134 if (strcmp(ghb_audio_bitrates[ii].string, str) == 0)
1136 result = ghb_audio_bitrates[ii].rate;
1142 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1143 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1144 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1146 gint val = ghb_value_int(rate);
1147 for (ii = 0; ii < ghb_audio_bitrates_count; ii++)
1149 if (ghb_audio_bitrates[ii].rate == val)
1151 result = ghb_audio_bitrates[ii].rate;
1160 lookup_audio_bitrate_option(const GValue *rate)
1163 const gchar *result = "Same as source";
1165 if (G_VALUE_TYPE(rate) == G_TYPE_STRING)
1167 // Coincidentally, the string "source" will return 0
1168 // which is our flag to use "same as source"
1169 gchar *str = ghb_value_string(rate);
1170 for (ii = 0; ii < ghb_audio_bitrates_count; ii++)
1172 if (strcmp(ghb_audio_bitrates[ii].string, str) == 0)
1174 result = ghb_audio_bitrates[ii].string;
1180 else if (G_VALUE_TYPE(rate) == G_TYPE_INT ||
1181 G_VALUE_TYPE(rate) == G_TYPE_INT64 ||
1182 G_VALUE_TYPE(rate) == G_TYPE_DOUBLE)
1184 gint val = ghb_value_int(rate);
1185 for (ii = 0; ii < ghb_audio_bitrates_count; ii++)
1187 if (ghb_audio_bitrates[ii].rate == val)
1189 result = ghb_audio_bitrates[ii].string;
1198 lookup_audio_lang_int(const GValue *rate)
1204 // Coincidentally, the string "source" will return 0
1205 // which is our flag to use "same as source"
1206 str = ghb_value_string(rate);
1207 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1209 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1220 lookup_audio_lang_option(const GValue *rate)
1224 const gchar *result = "Same as source";
1226 // Coincidentally, the string "source" will return 0
1227 // which is our flag to use "same as source"
1228 str = ghb_value_string(rate);
1229 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1231 if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
1233 if (ghb_language_table[ii].native_name[0] != 0)
1234 result = ghb_language_table[ii].native_name;
1236 result = ghb_language_table[ii].eng_name;
1245 ghb_lookup_acodec_value(gint val)
1247 GValue *value = NULL;
1250 for (ii = 0; ii < acodec_opts.count; ii++)
1252 if ((int)acodec_opts.map[ii].ivalue == val)
1254 value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
1258 value = ghb_string_value_new("auto");
1263 get_amix_value(gint val)
1265 GValue *value = NULL;
1268 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1270 if (hb_audio_mixdowns[ii].amixdown == val)
1272 value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
1279 // Handle for libhb. Gets set by ghb_backend_init()
1280 static hb_handle_t * h_scan = NULL;
1281 static hb_handle_t * h_queue = NULL;
1283 extern void hb_get_temporary_directory(char path[512]);
1290 hb_get_temporary_directory(dir);
1291 return g_strdup(dir);
1295 ghb_hb_cleanup(gboolean partial)
1299 hb_get_temporary_directory(dir);
1300 del_tree(dir, !partial);
1304 ghb_subtitle_track_source(signal_user_data_t *ud, gint track)
1312 titleindex = ghb_settings_combo_int(ud->settings, "title");
1318 hb_subtitle_t * sub;
1320 if (h_scan == NULL) return VOBSUB;
1321 list = hb_get_titles( h_scan );
1322 if( !hb_list_count( list ) )
1324 /* No valid title, stop right there */
1327 title = hb_list_item( list, titleindex );
1328 if (title == NULL) return VOBSUB; // Bad titleindex
1329 sub = hb_list_item( title->list_subtitle, track);
1337 ghb_subtitle_source_name(gint source)
1339 const gchar * name = "Unknown";
1368 ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
1371 const gchar * name = "Unknown";
1384 titleindex = ghb_settings_combo_int(ud->settings, "title");
1390 hb_subtitle_t * sub;
1394 list = hb_get_titles( h_scan );
1395 if( !hb_list_count( list ) )
1398 title = hb_list_item( list, titleindex );
1402 sub = hb_list_item( title->list_subtitle, track);
1405 name = ghb_subtitle_source_name(sub->source);
1413 ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
1417 titleindex = ghb_settings_combo_int(ud->settings, "title");
1421 return ghb_get_user_audio_lang(ud, titleindex, 0);
1427 hb_subtitle_t * sub;
1432 list = hb_get_titles( h_scan );
1433 if( !hb_list_count( list ) )
1435 /* No valid title, stop right there */
1438 title = hb_list_item( list, titleindex );
1439 if (title == NULL) // Bad titleindex
1441 sub = hb_list_item( title->list_subtitle, track);
1443 return g_strdup(sub->iso639_2);
1446 return g_strdup("und");
1450 ghb_get_title_number(gint titleindex)
1455 if (h_scan == NULL) return 1;
1456 list = hb_get_titles( h_scan );
1457 if( !hb_list_count( list ) )
1459 /* No valid title, stop right there */
1462 title = hb_list_item( list, titleindex );
1463 if (title == NULL) return 1; // Bad titleindex
1464 return title->index;
1467 static hb_audio_config_t*
1468 get_hb_audio(hb_handle_t *h, gint titleindex, gint track)
1472 hb_audio_config_t *audio = NULL;
1474 if (h == NULL) return NULL;
1475 list = hb_get_titles( h );
1476 if( !hb_list_count( list ) )
1478 /* No valid title, stop right there */
1481 title = hb_list_item( list, titleindex );
1482 if (title == NULL) return NULL; // Bad titleindex
1483 if (!hb_list_count(title->list_audio))
1487 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
1492 search_rates(hb_rate_t *rates, gint rate, gint count)
1495 for (ii = 0; ii < count; ii++)
1497 if (rates[ii].rate == rate)
1503 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
1505 static GtkListStore*
1506 get_combo_box_store(GtkBuilder *builder, const gchar *name)
1509 GtkListStore *store;
1511 g_debug("get_combo_box_store() %s\n", name);
1512 // First modify the combobox model to allow greying out of options
1513 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1514 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
1519 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
1521 GtkListStore *store;
1524 store = get_combo_box_store(builder, name);
1525 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
1527 gtk_list_store_set(store, &iter,
1534 ghb_grey_combo_options(GtkBuilder *builder)
1537 gint container, track, titleindex, acodec;
1538 hb_audio_config_t *aconfig = NULL;
1541 widget = GHB_WIDGET (builder, "title");
1542 gval = ghb_widget_value(widget);
1543 titleindex = ghb_lookup_combo_int("title", gval);
1544 ghb_value_free(gval);
1545 widget = GHB_WIDGET (builder, "AudioTrack");
1546 gval = ghb_widget_value(widget);
1547 track = ghb_lookup_combo_int("AudioTrack", gval);
1548 ghb_value_free(gval);
1549 aconfig = get_hb_audio(h_scan, titleindex, track);
1550 widget = GHB_WIDGET (builder, "FileFormat");
1551 gval = ghb_widget_value(widget);
1552 container = ghb_lookup_combo_int("FileFormat", gval);
1553 ghb_value_free(gval);
1555 grey_combo_box_item(builder, "x264_analyse", 4, TRUE);
1556 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
1557 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
1558 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
1560 gboolean allow_dca = TRUE;
1561 allow_dca = (container != HB_MUX_MP4);
1563 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3_PASS, FALSE);
1565 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, FALSE);
1567 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, TRUE);
1569 if (aconfig && aconfig->in.codec != HB_ACODEC_AC3)
1571 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3_PASS, TRUE);
1573 if (aconfig && aconfig->in.codec != HB_ACODEC_DCA)
1575 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA_PASS, TRUE);
1577 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
1579 widget = GHB_WIDGET (builder, "AudioEncoder");
1580 gval = ghb_widget_value(widget);
1581 acodec = ghb_lookup_combo_int("AudioEncoder", gval);
1582 ghb_value_free(gval);
1583 grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
1584 if (container == HB_MUX_MP4)
1586 grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
1587 grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
1590 gboolean allow_mono = TRUE;
1591 gboolean allow_stereo = TRUE;
1592 gboolean allow_dolby = TRUE;
1593 gboolean allow_dpl2 = TRUE;
1594 gboolean allow_6ch = TRUE;
1596 allow_6ch = acodec & ~HB_ACODEC_LAME;
1599 gint layout = aconfig->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1601 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1603 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1604 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1605 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1606 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1607 allow_6ch = allow_6ch &&
1608 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1609 (aconfig->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1611 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_MONO, !allow_mono);
1612 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_STEREO, !allow_stereo);
1613 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBY, !allow_dolby);
1614 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
1615 grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch);
1619 ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix)
1622 layout = aconfig ? aconfig->in.channel_layout :
1623 HB_INPUT_CH_LAYOUT_3F2R | HB_INPUT_CH_LAYOUT_HAS_LFE;
1624 return hb_get_best_mixdown( acodec, layout, mix );
1627 // Set up the model for the combo box
1629 init_combo_box(GtkBuilder *builder, const gchar *name)
1632 GtkListStore *store;
1633 GtkCellRenderer *cell;
1635 g_debug("init_combo_box() %s\n", name);
1636 // First modify the combobox model to allow greying out of options
1637 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1641 // 1 - String to display
1642 // 2 - bool indicating whether the entry is selectable (grey or not)
1643 // 3 - String that is used for presets
1644 // 4 - Int value determined by backend
1645 // 5 - String value determined by backend
1646 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1647 G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING);
1648 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1650 if (GTK_WIDGET_TYPE(combo) == GTK_TYPE_COMBO_BOX)
1652 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1653 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1654 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1655 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1656 "markup", 0, "sensitive", 1, NULL);
1659 { // Combo box entry
1660 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1665 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1668 GtkListStore *store;
1672 g_debug("audio_samplerate_opts_set ()\n");
1673 store = get_combo_box_store(builder, name);
1674 gtk_list_store_clear(store);
1675 // Add an item for "Same As Source"
1676 gtk_list_store_append(store, &iter);
1677 gtk_list_store_set(store, &iter,
1678 0, "<small>Same as source</small>",
1684 for (ii = 0; ii < count; ii++)
1686 gtk_list_store_append(store, &iter);
1687 str = g_strdup_printf("<small>%s</small>", rates[ii].string);
1688 gtk_list_store_set(store, &iter,
1691 2, rates[ii].string,
1692 3, (gdouble)rates[ii].rate,
1693 4, rates[ii].string,
1700 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1703 GtkListStore *store;
1706 g_debug("video_rate_opts_set ()\n");
1707 store = get_combo_box_store(builder, name);
1708 gtk_list_store_clear(store);
1709 // Add an item for "Same As Source"
1710 gtk_list_store_append(store, &iter);
1711 gtk_list_store_set(store, &iter,
1712 0, "Same as source",
1718 for (ii = 0; ii < count; ii++)
1722 if (strcmp(rates[ii].string, "23.976") == 0)
1724 desc = "(NTSC Film)";
1726 else if (strcmp(rates[ii].string, "25") == 0)
1728 desc = "(PAL Film/Video)";
1730 else if (strcmp(rates[ii].string, "29.97") == 0)
1732 desc = "(NTSC Video)";
1734 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1735 gtk_list_store_append(store, &iter);
1736 gtk_list_store_set(store, &iter,
1739 2, rates[ii].string,
1740 3, (gdouble)rates[ii].rate,
1741 4, rates[ii].string,
1748 mix_opts_set(GtkBuilder *builder, const gchar *name)
1751 GtkListStore *store;
1755 g_debug("mix_opts_set ()\n");
1756 store = get_combo_box_store(builder, name);
1757 gtk_list_store_clear(store);
1758 gtk_list_store_append(store, &iter);
1759 gtk_list_store_set(store, &iter,
1760 0, "<small>None</small>",
1766 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1768 gtk_list_store_append(store, &iter);
1769 str = g_strdup_printf("<small>%s</small>",
1770 hb_audio_mixdowns[ii].human_readable_name);
1771 gtk_list_store_set(store, &iter,
1774 2, hb_audio_mixdowns[ii].short_name,
1775 3, (gdouble)hb_audio_mixdowns[ii].amixdown,
1776 4, hb_audio_mixdowns[ii].internal_name,
1783 srt_codeset_opts_set(GtkBuilder *builder, const gchar *name)
1786 GtkListStore *store;
1789 g_debug("srt_codeset_opts_set ()\n");
1790 store = get_combo_box_store(builder, name);
1791 gtk_list_store_clear(store);
1792 for (ii = 0; ii < SRT_TABLE_SIZE; ii++)
1794 gtk_list_store_append(store, &iter);
1795 gtk_list_store_set(store, &iter,
1796 0, srt_codeset_table[ii],
1798 2, srt_codeset_table[ii],
1800 4, srt_codeset_table[ii],
1803 GtkComboBoxEntry *cbe;
1805 cbe = GTK_COMBO_BOX_ENTRY(GHB_WIDGET(builder, name));
1806 //gtk_combo_box_entry_set_text_column(cbe, 0);
1810 language_opts_set(GtkBuilder *builder, const gchar *name)
1813 GtkListStore *store;
1816 g_debug("language_opts_set ()\n");
1817 store = get_combo_box_store(builder, name);
1818 gtk_list_store_clear(store);
1819 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1823 if (ghb_language_table[ii].native_name[0] != 0)
1824 lang = ghb_language_table[ii].native_name;
1826 lang = ghb_language_table[ii].eng_name;
1828 gtk_list_store_append(store, &iter);
1829 gtk_list_store_set(store, &iter,
1832 2, ghb_language_table[ii].iso639_2,
1834 4, ghb_language_table[ii].iso639_1,
1839 static gchar **titles = NULL;
1842 title_opts_set(GtkBuilder *builder, const gchar *name)
1845 GtkListStore *store;
1846 hb_list_t * list = NULL;
1847 hb_title_t * title = NULL;
1851 g_debug("title_opts_set ()\n");
1852 store = get_combo_box_store(builder, name);
1853 gtk_list_store_clear(store);
1856 list = hb_get_titles( h_scan );
1857 count = hb_list_count( list );
1858 if (count > 100) count = 100;
1860 if (titles) g_strfreev(titles);
1861 if (title_opts.map) g_free(title_opts.map);
1864 title_opts.count = count;
1865 title_opts.map = g_malloc(count*sizeof(options_map_t));
1866 titles = g_malloc((count+1) * sizeof(gchar*));
1870 title_opts.count = 1;
1871 title_opts.map = g_malloc(sizeof(options_map_t));
1876 // No titles. Fill in a default.
1877 gtk_list_store_append(store, &iter);
1878 gtk_list_store_set(store, &iter,
1885 title_opts.map[0].option = "No Titles";
1886 title_opts.map[0].shortOpt = "none";
1887 title_opts.map[0].ivalue = -1;
1888 title_opts.map[0].svalue = "none";
1891 for (ii = 0; ii < count; ii++)
1893 title = (hb_title_t*)hb_list_item(list, ii);
1894 if (title->type == HB_STREAM_TYPE)
1896 if (title->duration != 0)
1898 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds - %s",
1899 title->index, title->hours, title->minutes, title->seconds,
1904 titles[ii] = g_strdup_printf ("%d - %s",
1905 title->index, title->name);
1910 if (title->duration != 0)
1912 titles[ii] = g_strdup_printf ("%d - %02dh%02dm%02ds",
1913 title->index, title->hours, title->minutes, title->seconds);
1917 titles[ii] = g_strdup_printf ("%d - Unknown Length",
1921 gtk_list_store_append(store, &iter);
1922 gtk_list_store_set(store, &iter,
1929 title_opts.map[ii].option = titles[ii];
1930 title_opts.map[ii].shortOpt = titles[ii];
1931 title_opts.map[ii].ivalue = ii;
1932 title_opts.map[ii].svalue = titles[ii];
1938 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1941 gboolean foundit = FALSE;
1943 if (gtk_tree_model_get_iter_first (store, iter))
1947 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1948 if (value == (gint)ivalue)
1953 } while (gtk_tree_model_iter_next (store, iter));
1959 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1962 GtkListStore *store;
1963 hb_list_t * list = NULL;
1964 hb_title_t * title = NULL;
1965 hb_audio_config_t * audio;
1970 g_debug("audio_track_opts_set ()\n");
1971 store = get_combo_box_store(builder, name);
1972 gtk_list_store_clear(store);
1975 list = hb_get_titles( h_scan );
1976 title = (hb_title_t*)hb_list_item( list, titleindex );
1979 count = hb_list_count( title->list_audio );
1982 if (count > 100) count = 100;
1983 if (audio_track_opts.map) g_free(audio_track_opts.map);
1986 audio_track_opts.count = count;
1987 audio_track_opts.map = g_malloc(count*sizeof(options_map_t));
1991 audio_track_opts.count = 1;
1992 audio_track_opts.map = g_malloc(sizeof(options_map_t));
1996 // No audio. set some default
1997 gtk_list_store_append(store, &iter);
1998 gtk_list_store_set(store, &iter,
1999 0, "<small>No Audio</small>",
2005 audio_track_opts.map[0].option = "No Audio";
2006 audio_track_opts.map[0].shortOpt = "none";
2007 audio_track_opts.map[0].ivalue = -1;
2008 audio_track_opts.map[0].svalue = "none";
2011 index_str_init(count-1);
2012 for (ii = 0; ii < count; ii++)
2014 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
2015 gtk_list_store_append(store, &iter);
2016 str = g_strdup_printf("<small>%s</small>", audio->lang.description);
2017 gtk_list_store_set(store, &iter,
2025 audio_track_opts.map[ii].option = audio->lang.description,
2026 audio_track_opts.map[ii].shortOpt = index_str[ii];
2027 audio_track_opts.map[ii].ivalue = ii;
2028 audio_track_opts.map[ii].svalue = index_str[ii];
2033 subtitle_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
2036 GtkListStore *store;
2037 hb_list_t * list = NULL;
2038 hb_title_t * title = NULL;
2039 hb_subtitle_t * subtitle;
2041 static char ** options = NULL;
2043 g_debug("subtitle_track_opts_set ()\n");
2044 store = get_combo_box_store(builder, name);
2045 gtk_list_store_clear(store);
2048 list = hb_get_titles( h_scan );
2049 title = (hb_title_t*)hb_list_item( list, titleindex );
2052 count = hb_list_count( title->list_subtitle );
2055 if (count > 100) count = 100;
2056 if (subtitle_opts.map) g_free(subtitle_opts.map);
2059 subtitle_opts.count = count+1;
2060 subtitle_opts.map = g_malloc((count+1)*sizeof(options_map_t));
2064 subtitle_opts.count = LANG_TABLE_SIZE+1;
2065 subtitle_opts.map = g_malloc((LANG_TABLE_SIZE+1)*sizeof(options_map_t));
2067 gtk_list_store_append(store, &iter);
2068 gtk_list_store_set(store, &iter,
2069 0, "Foreign Audio Search",
2075 subtitle_opts.map[0].option = "Foreign Audio Search";
2076 subtitle_opts.map[0].shortOpt = "-1";
2077 subtitle_opts.map[0].ivalue = -1;
2078 subtitle_opts.map[0].svalue = "auto";
2081 if (options != NULL)
2082 g_strfreev(options);
2083 options = g_malloc((count+1)*sizeof(gchar*));
2084 index_str_init(count-1);
2085 for (ii = 0; ii < count; ii++)
2087 subtitle = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
2088 options[ii] = g_strdup_printf("%d - %s (%s)", ii+1,
2090 ghb_subtitle_source_name(subtitle->source));
2091 subtitle_opts.map[ii+1].option = options[ii];
2092 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2093 subtitle_opts.map[ii+1].ivalue = ii;
2094 subtitle_opts.map[ii+1].svalue = subtitle->iso639_2;
2095 gtk_list_store_append(store, &iter);
2096 gtk_list_store_set(store, &iter,
2101 4, subtitle->iso639_2,
2104 options[count] = NULL;
2108 index_str_init(LANG_TABLE_SIZE-1);
2109 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
2113 if (ghb_language_table[ii].native_name[0] != 0)
2114 lang = ghb_language_table[ii].native_name;
2116 lang = ghb_language_table[ii].eng_name;
2118 subtitle_opts.map[ii+1].option = lang;
2119 subtitle_opts.map[ii+1].shortOpt = index_str[ii];
2120 subtitle_opts.map[ii+1].ivalue = ii;
2121 subtitle_opts.map[ii+1].svalue = ghb_language_table[ii].iso639_2;
2122 gtk_list_store_append(store, &iter);
2123 gtk_list_store_set(store, &iter,
2128 4, ghb_language_table[ii].iso639_2,
2141 gint titleindex = 0;
2144 g_debug("ghb_longest_title ()\n");
2145 if (h_scan == NULL) return 0;
2146 list = hb_get_titles( h_scan );
2147 count = hb_list_count( list );
2148 if (count > 100) count = 100;
2149 if (count < 1) return 0;
2150 title = (hb_title_t*)hb_list_item(list, 0);
2151 feature = title->job->feature;
2152 for (ii = 0; ii < count; ii++)
2154 title = (hb_title_t*)hb_list_item(list, ii);
2155 if (title->index == feature)
2164 ghb_get_source_audio_lang(gint titleindex, gint track)
2168 hb_audio_config_t * audio;
2171 g_debug("ghb_lookup_1st_audio_lang ()\n");
2174 list = hb_get_titles( h_scan );
2175 title = (hb_title_t*)hb_list_item( list, titleindex );
2178 if (hb_list_count( title->list_audio ) <= track)
2181 audio = hb_list_audio_config_item(title->list_audio, track);
2185 lang = g_strdup(audio->lang.iso639_2);
2190 get_track_used(gint acodec, GHashTable *track_indices, gint count)
2194 used = g_hash_table_lookup(track_indices, &acodec);
2199 used = g_malloc0(count * sizeof(gboolean));
2200 key = g_malloc(sizeof(gint));
2202 g_hash_table_insert(track_indices, key, used);
2208 ghb_find_audio_track(
2212 gint fallback_acodec,
2213 GHashTable *track_indices)
2217 hb_audio_config_t * audio;
2222 gboolean *used = NULL;
2223 gboolean *passthru_used;
2225 gint passthru_acodec;
2229 g_debug("find_audio_track ()\n");
2230 if (h_scan == NULL) return -1;
2231 list = hb_get_titles( h_scan );
2232 title = (hb_title_t*)hb_list_item( list, titleindex );
2235 count = hb_list_count( title->list_audio );
2237 if (count > 10) count = 10;
2238 // Try to find an item that matches the preferred language and
2239 // the passthru codec type
2241 passthru = (acodec & HB_ACODEC_PASS_FLAG) != 0;
2244 for (ii = 0; ii < count; ii++)
2246 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2247 title->list_audio, ii );
2248 passthru_acodec = acodec & audio->in.codec;
2249 // Is the source track use a passthru capable codec?
2250 if (passthru_acodec == 0)
2252 used = get_track_used(passthru_acodec, track_indices, count);
2253 // Has the track already been used with this codec?
2257 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2258 audio->in.channel_layout);
2259 // Find a track that is not visually impaired or dirctor's
2260 // commentary, and has the highest channel count.
2261 if ((audio->lang.type < 2) &&
2262 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2263 (strcmp(lang, "und") == 0)))
2265 if (channels > max_chan)
2268 max_chan = channels;
2272 try_acodec = fallback_acodec;
2276 try_acodec = acodec;
2283 // Try to find an item that matches the preferred language
2285 used = get_track_used(try_acodec, track_indices, count);
2286 for (ii = 0; ii < count; ii++)
2288 // Has the track already been used with this codec?
2291 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2292 title->list_audio, ii );
2293 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2294 if (passthru_acodec && passthru)
2296 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2297 // Has the track already been used with this codec for passthru?
2298 if (passthru_used[ii])
2301 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2302 audio->in.channel_layout);
2303 // Find a track that is not visually impaired or dirctor's commentary
2304 if ((audio->lang.type < 2) &&
2305 ((strcmp(lang, audio->lang.iso639_2) == 0) ||
2306 (strcmp(lang, "und") == 0)))
2308 if (channels > max_chan)
2311 max_chan = channels;
2320 // Try to fine an item that does not match the preferred language and
2321 // matches the passthru codec type
2325 for (ii = 0; ii < count; ii++)
2327 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2328 title->list_audio, ii );
2329 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2330 // Is the source track use a passthru capable codec?
2331 if (passthru_acodec == 0)
2333 used = get_track_used(passthru_acodec, track_indices, count);
2334 // Has the track already been used with this codec?
2338 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2339 audio->in.channel_layout);
2340 // Find a track that is not visually impaired or dirctor's
2341 // commentary, and has the highest channel count.
2342 if (audio->lang.type < 2)
2344 if (channels > max_chan)
2347 max_chan = channels;
2351 try_acodec = fallback_acodec;
2355 try_acodec = acodec;
2362 // Try to fine an item that does not match the preferred language
2364 used = get_track_used(try_acodec, track_indices, count);
2365 for (ii = 0; ii < count; ii++)
2367 // Has the track already been used with this codec?
2370 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2371 title->list_audio, ii );
2372 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2373 channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT(
2374 audio->in.channel_layout);
2375 if (passthru_acodec && passthru)
2377 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2378 // Has the track already been used with this codec for passthru?
2379 if (passthru_used[ii])
2382 // Find a track that is not visually impaired or dirctor's commentary
2383 if (audio->lang.type < 2)
2385 if (channels > max_chan)
2388 max_chan = channels;
2397 // Last ditch, anything goes
2398 for (ii = 0; ii < count; ii++)
2400 audio = (hb_audio_config_t*)hb_list_audio_config_item(
2401 title->list_audio, ii );
2402 passthru_acodec = HB_ACODEC_PASS_MASK & audio->in.codec;
2403 if (passthru_acodec && passthru)
2405 passthru_used = get_track_used(passthru_acodec, track_indices, count);
2406 // Has the track already been used with this codec for passthru?
2407 if (passthru_used[ii])
2410 // Has the track already been used with this codec?
2425 ghb_find_pref_subtitle_track(const gchar *lang)
2428 count = subtitle_opts.count;
2429 for (ii = 0; ii < count; ii++)
2431 if (strcmp(lang, subtitle_opts.map[ii].svalue) == 0)
2433 return subtitle_opts.map[ii].ivalue;
2440 ghb_find_cc_track(gint titleindex)
2444 hb_subtitle_t * subtitle;
2447 g_debug("ghb_find_cc_track ()\n");
2448 if (h_scan == NULL) return -2;
2449 list = hb_get_titles( h_scan );
2450 title = (hb_title_t*)hb_list_item( list, titleindex );
2453 count = hb_list_count( title->list_subtitle );
2454 // Try to find an item that matches the preferred language
2455 for (ii = 0; ii < count; ii++)
2457 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2458 if (subtitle->source == CC608SUB || subtitle->source == CC708SUB)
2466 canForce(int source)
2468 return (source == VOBSUB);
2474 return (source == VOBSUB || source == SSASUB);
2478 ghb_find_subtitle_track(
2484 GHashTable * track_indices)
2488 hb_subtitle_t * subtitle;
2492 g_debug("find_subtitle_track ()\n");
2493 if (strcmp(lang, "auto") == 0)
2495 if (h_scan == NULL) return -1;
2496 list = hb_get_titles( h_scan );
2497 title = (hb_title_t*)hb_list_item( list, titleindex );
2500 count = hb_list_count( title->list_subtitle );
2501 used = g_hash_table_lookup(track_indices, lang);
2504 used = g_malloc0(count * sizeof(gboolean));
2505 g_hash_table_insert(track_indices, g_strdup(lang), used);
2507 // Try to find an item that matches the preferred language and source
2508 for (ii = 0; ii < count; ii++)
2513 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2514 if (source == subtitle->source &&
2515 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2516 (strcmp(lang, "und") == 0)))
2522 // Try to find an item that matches the preferred language
2523 for (ii = 0; ii < count; ii++)
2528 subtitle = (hb_subtitle_t*)hb_list_item( title->list_subtitle, ii );
2529 if (((!force || (force && canForce(subtitle->source))) &&
2530 (!burn || (burn && canBurn(subtitle->source)))) &&
2531 ((strcmp(lang, subtitle->iso639_2) == 0) ||
2532 (strcmp(lang, "und") == 0)))
2543 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2546 GtkListStore *store;
2549 g_debug("generic_opts_set ()\n");
2550 if (name == NULL || opts == NULL) return;
2551 store = get_combo_box_store(builder, name);
2552 gtk_list_store_clear(store);
2553 for (ii = 0; ii < opts->count; ii++)
2555 gtk_list_store_append(store, &iter);
2556 gtk_list_store_set(store, &iter,
2557 0, opts->map[ii].option,
2559 2, opts->map[ii].shortOpt,
2560 3, opts->map[ii].ivalue,
2561 4, opts->map[ii].svalue,
2567 small_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
2570 GtkListStore *store;
2574 g_debug("small_opts_set ()\n");
2575 if (name == NULL || opts == NULL) return;
2576 store = get_combo_box_store(builder, name);
2577 gtk_list_store_clear(store);
2578 for (ii = 0; ii < opts->count; ii++)
2580 gtk_list_store_append(store, &iter);
2581 str = g_strdup_printf("<small>%s</small>", opts->map[ii].option);
2582 gtk_list_store_set(store, &iter,
2585 2, opts->map[ii].shortOpt,
2586 3, opts->map[ii].ivalue,
2587 4, opts->map[ii].svalue,
2594 find_combo_table(const gchar *name)
2598 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2600 if (strcmp(name, combo_name_map[ii].name) == 0)
2602 return combo_name_map[ii].opts;
2609 ghb_lookup_combo_int(const gchar *name, const GValue *gval)
2613 if (strcmp(name, "AudioBitrate") == 0)
2614 return lookup_audio_bitrate_int(gval);
2615 else if (strcmp(name, "AudioSamplerate") == 0)
2616 return lookup_audio_rate_int(gval);
2617 else if (strcmp(name, "VideoFramerate") == 0)
2618 return lookup_video_rate_int(gval);
2619 else if (strcmp(name, "AudioMixdown") == 0)
2620 return lookup_mix_int(gval);
2621 else if (strcmp(name, "SrtLanguage") == 0)
2622 return lookup_audio_lang_int(gval);
2623 else if (strcmp(name, "PreferredLanguage") == 0)
2624 return lookup_audio_lang_int(gval);
2627 return lookup_generic_int(find_combo_table(name), gval);
2629 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2634 ghb_lookup_combo_double(const gchar *name, const GValue *gval)
2638 if (strcmp(name, "AudioBitrate") == 0)
2639 return lookup_audio_bitrate_int(gval);
2640 else if (strcmp(name, "AudioSamplerate") == 0)
2641 return lookup_audio_rate_int(gval);
2642 else if (strcmp(name, "VideoFramerate") == 0)
2643 return lookup_video_rate_int(gval);
2644 else if (strcmp(name, "AudioMixdown") == 0)
2645 return lookup_mix_int(gval);
2646 else if (strcmp(name, "SrtLanguage") == 0)
2647 return lookup_audio_lang_int(gval);
2648 else if (strcmp(name, "PreferredLanguage") == 0)
2649 return lookup_audio_lang_int(gval);
2652 return lookup_generic_double(find_combo_table(name), gval);
2654 g_warning("ghb_lookup_combo_double() couldn't find %s", name);
2659 ghb_lookup_combo_option(const gchar *name, const GValue *gval)
2663 if (strcmp(name, "AudioBitrate") == 0)
2664 return lookup_audio_bitrate_option(gval);
2665 else if (strcmp(name, "AudioSamplerate") == 0)
2666 return lookup_audio_rate_option(gval);
2667 else if (strcmp(name, "VideoFramerate") == 0)
2668 return lookup_video_rate_option(gval);
2669 else if (strcmp(name, "AudioMixdown") == 0)
2670 return lookup_mix_option(gval);
2671 else if (strcmp(name, "SrtLanguage") == 0)
2672 return lookup_audio_lang_option(gval);
2673 else if (strcmp(name, "PreferredLanguage") == 0)
2674 return lookup_audio_lang_option(gval);
2677 return lookup_generic_option(find_combo_table(name), gval);
2679 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2684 ghb_lookup_combo_string(const gchar *name, const GValue *gval)
2688 if (strcmp(name, "AudioBitrate") == 0)
2689 return lookup_audio_bitrate_option(gval);
2690 else if (strcmp(name, "AudioSamplerate") == 0)
2691 return lookup_audio_rate_option(gval);
2692 else if (strcmp(name, "VideoFramerate") == 0)
2693 return lookup_video_rate_option(gval);
2694 else if (strcmp(name, "AudioMixdown") == 0)
2695 return lookup_mix_string(gval);
2696 else if (strcmp(name, "SrtLanguage") == 0)
2697 return lookup_audio_lang_option(gval);
2698 else if (strcmp(name, "PreferredLanguage") == 0)
2699 return lookup_audio_lang_option(gval);
2702 return lookup_generic_string(find_combo_table(name), gval);
2704 g_warning("ghb_lookup_combo_int() couldn't find %s", name);
2709 ghb_update_ui_combo_box(
2710 signal_user_data_t *ud,
2715 GtkComboBox *combo = NULL;
2717 gint handler_id = 0;
2721 g_debug("ghb_update_ui_combo_box() %s\n", name);
2722 // Clearing a combo box causes a rash of "changed" events, even when
2723 // the active item is -1 (inactive). To control things, I'm disabling
2724 // the event till things are settled down.
2725 combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
2726 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
2729 // Valid signal id found. This should always succeed.
2730 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
2731 signal_id, 0, 0, 0, 0);
2734 // This should also always succeed
2735 g_signal_handler_block ((gpointer)combo, handler_id);
2741 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2742 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2743 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2744 mix_opts_set(ud->builder, "AudioMixdown");
2745 language_opts_set(ud->builder, "SrtLanguage");
2746 language_opts_set(ud->builder, "PreferredLanguage");
2747 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2748 title_opts_set(ud->builder, "title");
2749 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2750 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2751 generic_opts_set(ud->builder, "VideoQualityGranularity", &vqual_granularity_opts);
2752 generic_opts_set(ud->builder, "PtoPType", &point_to_point_opts);
2753 generic_opts_set(ud->builder, "WhenComplete", &when_complete_opts);
2754 generic_opts_set(ud->builder, "PicturePAR", &par_opts);
2755 generic_opts_set(ud->builder, "PictureModulus", &alignment_opts);
2756 generic_opts_set(ud->builder, "LoggingLevel", &logging_opts);
2757 generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts);
2758 generic_opts_set(ud->builder, "check_updates", &appcast_update_opts);
2759 generic_opts_set(ud->builder, "FileFormat", &container_opts);
2760 generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts);
2761 generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts);
2762 generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts);
2763 generic_opts_set(ud->builder, "PictureDenoise", &denoise_opts);
2764 generic_opts_set(ud->builder, "VideoEncoder", &vcodec_opts);
2765 small_opts_set(ud->builder, "AudioEncoder", &acodec_opts);
2766 small_opts_set(ud->builder, "x264_direct", &direct_opts);
2767 small_opts_set(ud->builder, "x264_b_adapt", &badapt_opts);
2768 small_opts_set(ud->builder, "x264_bpyramid", &bpyramid_opts);
2769 small_opts_set(ud->builder, "x264_weighted_pframes", &weightp_opts);
2770 small_opts_set(ud->builder, "x264_me", &me_opts);
2771 small_opts_set(ud->builder, "x264_subme", &subme_opts);
2772 small_opts_set(ud->builder, "x264_analyse", &analyse_opts);
2773 small_opts_set(ud->builder, "x264_trellis", &trellis_opts);
2777 if (strcmp(name, "AudioBitrate") == 0)
2778 audio_bitrate_opts_set(ud->builder, "AudioBitrate");
2779 else if (strcmp(name, "AudioSamplerate") == 0)
2780 audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count);
2781 else if (strcmp(name, "VideoFramerate") == 0)
2782 video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count);
2783 else if (strcmp(name, "AudioMixdown") == 0)
2784 mix_opts_set(ud->builder, "AudioMixdown");
2785 else if (strcmp(name, "SrtLanguage") == 0)
2786 language_opts_set(ud->builder, "SrtLanguage");
2787 else if (strcmp(name, "PreferredLanguage") == 0)
2788 language_opts_set(ud->builder, "PreferredLanguage");
2789 else if (strcmp(name, "SrtCodeset") == 0)
2790 srt_codeset_opts_set(ud->builder, "SrtCodeset");
2791 else if (strcmp(name, "title") == 0)
2792 title_opts_set(ud->builder, "title");
2793 else if (strcmp(name, "SubtitleTrack") == 0)
2794 subtitle_track_opts_set(ud->builder, "SubtitleTrack", user_data);
2795 else if (strcmp(name, "AudioTrack") == 0)
2796 audio_track_opts_set(ud->builder, "AudioTrack", user_data);
2798 generic_opts_set(ud->builder, name, find_combo_table(name));
2802 g_signal_handler_unblock ((gpointer)combo, handler_id);
2807 init_ui_combo_boxes(GtkBuilder *builder)
2811 init_combo_box(builder, "AudioBitrate");
2812 init_combo_box(builder, "AudioSamplerate");
2813 init_combo_box(builder, "VideoFramerate");
2814 init_combo_box(builder, "AudioMixdown");
2815 init_combo_box(builder, "SrtLanguage");
2816 init_combo_box(builder, "PreferredLanguage");
2817 init_combo_box(builder, "SrtCodeset");
2818 init_combo_box(builder, "title");
2819 init_combo_box(builder, "AudioTrack");
2820 for (ii = 0; combo_name_map[ii].name != NULL; ii++)
2822 init_combo_box(builder, combo_name_map[ii].name);
2826 static const char * turbo_opts =
2827 "ref=1:subme=2:me=dia:analyse=none:trellis=0:"
2828 "no-fast-pskip=0:8x8dct=0";
2830 // Construct the x264 options string
2831 // The result is allocated, so someone must free it at some point.
2833 ghb_build_x264opts_string(GValue *settings)
2836 gchar *opts = ghb_settings_get_string(settings, "x264Option");
2843 result = g_strdup("");
2849 ghb_part_duration(gint tt, gint sc, gint ec, gint *hh, gint *mm, gint *ss)
2853 hb_chapter_t * chapter;
2857 *hh = *mm = *ss = 0;
2858 if (h_scan == NULL) return;
2859 list = hb_get_titles( h_scan );
2860 title = (hb_title_t*)hb_list_item( list, tt );
2861 if (title == NULL) return;
2864 *mm = title->minutes;
2865 *ss = title->seconds;
2867 count = hb_list_count(title->list_chapter);
2868 if (sc > count) sc = count;
2869 if (ec > count) ec = count;
2871 if (sc == 1 && ec == count)
2875 for (c = sc; c <= ec; c++)
2877 chapter = hb_list_item(title->list_chapter, c-1);
2878 duration += chapter->duration;
2881 *hh = duration / 90000 / 3600;
2882 *mm = ((duration / 90000) % 3600) / 60;
2883 *ss = (duration / 90000) % 60;
2887 ghb_get_chapter_duration(gint ti, gint ii, gint *hh, gint *mm, gint *ss)
2891 hb_chapter_t * chapter;
2894 g_debug("ghb_get_chapter_duration (title = %d)\n", ti);
2895 *hh = *mm = *ss = 0;
2896 if (h_scan == NULL) return;
2897 list = hb_get_titles( h_scan );
2898 title = (hb_title_t*)hb_list_item( list, ti );
2899 if (title == NULL) return;
2900 count = hb_list_count( title->list_chapter );
2901 if (ii >= count) return;
2902 chapter = hb_list_item(title->list_chapter, ii);
2903 if (chapter == NULL) return;
2904 *hh = chapter->hours;
2905 *mm = chapter->minutes;
2906 *ss = chapter->seconds;
2910 ghb_get_chapters(gint titleindex)
2914 hb_chapter_t * chapter;
2916 GValue *chapters = NULL;
2918 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
2919 if (h_scan == NULL) return NULL;
2920 list = hb_get_titles( h_scan );
2921 title = (hb_title_t*)hb_list_item( list, titleindex );
2922 if (title == NULL) return NULL;
2923 count = hb_list_count( title->list_chapter );
2924 chapters = ghb_array_value_new(count);
2925 for (ii = 0; ii < count; ii++)
2927 chapter = hb_list_item(title->list_chapter, ii);
2928 if (chapter == NULL) break;
2929 if (chapter->title == NULL || chapter->title[0] == 0)
2932 str = g_strdup_printf ("Chapter %2d", ii+1);
2933 ghb_array_append(chapters, ghb_string_value_new(str));
2938 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
2945 ghb_ac3_in_audio_list(const GValue *audio_list)
2949 count = ghb_array_len(audio_list);
2950 for (ii = 0; ii < count; ii++)
2955 asettings = ghb_array_get_nth(audio_list, ii);
2956 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
2957 if (acodec & HB_ACODEC_AC3)
2964 audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
2967 GtkListStore *store;
2970 g_debug("audio_bitrate_opts_add ()\n");
2972 if (rate < 8) return;
2974 if (ghb_audio_bitrates[hb_audio_bitrates_count].string)
2976 g_free(ghb_audio_bitrates[hb_audio_bitrates_count].string);
2978 ghb_audio_bitrates[hb_audio_bitrates_count].rate = rate;
2979 ghb_audio_bitrates[hb_audio_bitrates_count].string =
2980 g_strdup_printf("%d", rate);
2981 ghb_audio_bitrates_count = hb_audio_bitrates_count + 1;
2983 store = get_combo_box_store(builder, name);
2984 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
2986 str = g_strdup_printf ("<small>%d</small>", rate);
2987 gtk_list_store_append(store, &iter);
2988 gtk_list_store_set(store, &iter,
2991 2, ghb_audio_bitrates[hb_audio_bitrates_count].string,
2993 4, ghb_audio_bitrates[hb_audio_bitrates_count].string,
3000 audio_bitrate_opts_clean(
3001 GtkBuilder *builder,
3007 GtkListStore *store;
3009 gboolean done = FALSE;
3011 guint last = (guint)last_rate;
3012 guint first = (guint)first_rate;
3014 ghb_audio_bitrates_count = hb_audio_bitrates_count;
3016 g_debug("audio_bitrate_opts_clean ()\n");
3017 store = get_combo_box_store(builder, name);
3018 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
3022 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
3024 ghb_audio_bitrates, ivalue, ghb_audio_bitrates_count) < 0)
3026 done = !gtk_list_store_remove(store, &iter);
3028 else if (ivalue < first || ivalue > last)
3031 gtk_list_store_set(store, &iter, 1, FALSE, -1);
3032 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3037 gtk_list_store_set(store, &iter, 1, TRUE, -1);
3038 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
3045 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name)
3048 GtkListStore *store;
3052 ghb_audio_bitrates_count = hb_audio_bitrates_count;
3053 ghb_audio_bitrates = calloc(hb_audio_bitrates_count+1, sizeof(hb_rate_t));
3055 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
3057 ghb_audio_bitrates[ii] = hb_audio_bitrates[ii];
3060 g_debug("audio_bitrate_opts_set ()\n");
3061 store = get_combo_box_store(builder, name);
3062 gtk_list_store_clear(store);
3063 for (ii = 0; ii < ghb_audio_bitrates_count; ii++)
3065 gtk_list_store_append(store, &iter);
3066 str = g_strdup_printf ("<small>%s</small>",
3067 ghb_audio_bitrates[ii].string);
3068 gtk_list_store_set(store, &iter,
3071 2, ghb_audio_bitrates[ii].string,
3072 3, (gdouble)ghb_audio_bitrates[ii].rate,
3073 4, ghb_audio_bitrates[ii].string,
3080 ghb_set_passthru_bitrate_opts(GtkBuilder *builder, gint bitrate)
3082 audio_bitrate_opts_add(builder, "AudioBitrate", bitrate);
3086 ghb_set_default_bitrate_opts(
3087 GtkBuilder *builder,
3091 audio_bitrate_opts_clean(builder, "AudioBitrate", first_rate, last_rate);
3094 static ghb_status_t hb_status;
3097 ghb_combo_init(signal_user_data_t *ud)
3099 // Set up the list model for the combos
3100 init_ui_combo_boxes(ud->builder);
3101 // Populate all the combos
3102 ghb_update_ui_combo_box(ud, NULL, 0, TRUE);
3106 ghb_backend_init(gint debug)
3109 h_scan = hb_init( debug, 0 );
3110 h_queue = hb_init( debug, 0 );
3121 void ghb_backend_scan_stop()
3123 hb_scan_stop( h_scan );
3127 ghb_backend_scan(const gchar *path, gint titleindex, gint preview_count, uint64_t min_duration)
3129 hb_scan( h_scan, path, titleindex, preview_count, 1, min_duration );
3130 hb_status.scan.state |= GHB_STATE_SCANNING;
3131 // initialize count and cur to something that won't cause FPE
3132 // when computing progress
3133 hb_status.scan.title_count = 1;
3134 hb_status.scan.title_cur = 0;
3138 ghb_backend_queue_scan(const gchar *path, gint titlenum)
3140 g_debug("ghb_backend_queue_scan()");
3141 hb_scan( h_queue, path, titlenum, 10, 0, 0 );
3142 hb_status.queue.state |= GHB_STATE_SCANNING;
3146 ghb_get_scan_state()
3148 return hb_status.scan.state;
3152 ghb_get_queue_state()
3154 return hb_status.queue.state;
3158 ghb_clear_scan_state(gint state)
3160 hb_status.scan.state &= ~state;
3164 ghb_clear_queue_state(gint state)
3166 hb_status.queue.state &= ~state;
3170 ghb_set_scan_state(gint state)
3172 hb_status.scan.state |= state;
3176 ghb_set_queue_state(gint state)
3178 hb_status.queue.state |= state;
3182 ghb_get_status(ghb_status_t *status)
3184 memcpy(status, &hb_status, sizeof(ghb_status_t));
3193 if (h_scan == NULL) return;
3194 hb_get_state( h_scan, &s_scan );
3195 switch( s_scan.state )
3197 #define p s_scan.param.scanning
3198 case HB_STATE_SCANNING:
3200 hb_status.scan.state |= GHB_STATE_SCANNING;
3201 hb_status.scan.title_count = p.title_count;
3202 hb_status.scan.title_cur = p.title_cur;
3206 case HB_STATE_SCANDONE:
3208 hb_status.scan.state &= ~GHB_STATE_SCANNING;
3209 hb_status.scan.state |= GHB_STATE_SCANDONE;
3212 #define p s_scan.param.working
3213 case HB_STATE_WORKING:
3214 hb_status.scan.state |= GHB_STATE_WORKING;
3215 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3216 hb_status.scan.job_cur = p.job_cur;
3217 hb_status.scan.job_count = p.job_count;
3218 hb_status.scan.progress = p.progress;
3219 hb_status.scan.rate_cur = p.rate_cur;
3220 hb_status.scan.rate_avg = p.rate_avg;
3221 hb_status.scan.hours = p.hours;
3222 hb_status.scan.minutes = p.minutes;
3223 hb_status.scan.seconds = p.seconds;
3224 hb_status.scan.unique_id = p.sequence_id & 0xFFFFFF;
3228 case HB_STATE_PAUSED:
3229 hb_status.scan.state |= GHB_STATE_PAUSED;
3232 case HB_STATE_MUXING:
3234 hb_status.scan.state |= GHB_STATE_MUXING;
3237 #define p s_scan.param.workdone
3238 case HB_STATE_WORKDONE:
3242 hb_status.scan.state |= GHB_STATE_WORKDONE;
3243 hb_status.scan.state &= ~GHB_STATE_MUXING;
3244 hb_status.scan.state &= ~GHB_STATE_PAUSED;
3245 hb_status.scan.state &= ~GHB_STATE_WORKING;
3249 hb_status.scan.error = GHB_ERROR_NONE;
3251 case HB_ERROR_CANCELED:
3252 hb_status.scan.error = GHB_ERROR_CANCELED;
3255 hb_status.scan.error = GHB_ERROR_FAIL;
3258 // Delete all remaining jobs of this encode.
3259 // An encode can be composed of multiple associated jobs.
3260 // When a job is stopped, libhb removes it from the job list,
3261 // but does not remove other jobs that may be associated with it.
3262 // Associated jobs are taged in the sequence id.
3263 while ((job = hb_job(h_scan, 0)) != NULL)
3264 hb_rem( h_scan, job );
3268 hb_get_state( h_queue, &s_queue );
3269 switch( s_queue.state )
3271 #define p s_queue.param.scanning
3272 case HB_STATE_SCANNING:
3274 hb_status.queue.state |= GHB_STATE_SCANNING;
3275 hb_status.queue.title_count = p.title_count;
3276 hb_status.queue.title_cur = p.title_cur;
3280 case HB_STATE_SCANDONE:
3282 hb_status.queue.state &= ~GHB_STATE_SCANNING;
3283 hb_status.queue.state |= GHB_STATE_SCANDONE;
3286 #define p s_queue.param.working
3287 case HB_STATE_WORKING:
3288 hb_status.queue.state |= GHB_STATE_WORKING;
3289 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3290 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3291 hb_status.queue.job_cur = p.job_cur;
3292 hb_status.queue.job_count = p.job_count;
3293 hb_status.queue.progress = p.progress;
3294 hb_status.queue.rate_cur = p.rate_cur;
3295 hb_status.queue.rate_avg = p.rate_avg;
3296 hb_status.queue.hours = p.hours;
3297 hb_status.queue.minutes = p.minutes;
3298 hb_status.queue.seconds = p.seconds;
3299 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3302 case HB_STATE_SEARCHING:
3303 hb_status.queue.state |= GHB_STATE_SEARCHING;
3304 hb_status.queue.state &= ~GHB_STATE_WORKING;
3305 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3306 hb_status.queue.job_cur = p.job_cur;
3307 hb_status.queue.job_count = p.job_count;
3308 hb_status.queue.progress = p.progress;
3309 hb_status.queue.rate_cur = p.rate_cur;
3310 hb_status.queue.rate_avg = p.rate_avg;
3311 hb_status.queue.hours = p.hours;
3312 hb_status.queue.minutes = p.minutes;
3313 hb_status.queue.seconds = p.seconds;
3314 hb_status.queue.unique_id = p.sequence_id & 0xFFFFFF;
3318 case HB_STATE_PAUSED:
3319 hb_status.queue.state |= GHB_STATE_PAUSED;
3322 case HB_STATE_MUXING:
3324 hb_status.queue.state |= GHB_STATE_MUXING;
3327 #define p s_queue.param.workdone
3328 case HB_STATE_WORKDONE:
3332 hb_status.queue.state |= GHB_STATE_WORKDONE;
3333 hb_status.queue.state &= ~GHB_STATE_MUXING;
3334 hb_status.queue.state &= ~GHB_STATE_PAUSED;
3335 hb_status.queue.state &= ~GHB_STATE_WORKING;
3336 hb_status.queue.state &= ~GHB_STATE_SEARCHING;
3340 hb_status.queue.error = GHB_ERROR_NONE;
3342 case HB_ERROR_CANCELED:
3343 hb_status.queue.error = GHB_ERROR_CANCELED;
3346 hb_status.queue.error = GHB_ERROR_FAIL;
3349 // Delete all remaining jobs of this encode.
3350 // An encode can be composed of multiple associated jobs.
3351 // When a job is stopped, libhb removes it from the job list,
3352 // but does not remove other jobs that may be associated with it.
3353 // Associated jobs are taged in the sequence id.
3354 while ((job = hb_job(h_queue, 0)) != NULL)
3355 hb_rem( h_queue, job );
3362 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
3367 if (h_scan == NULL) return FALSE;
3368 list = hb_get_titles( h_scan );
3369 if( !hb_list_count( list ) )
3371 /* No valid title, stop right there */
3375 title = hb_list_item( list, titleindex );
3376 if (title == NULL) return FALSE; // Bad titleindex
3377 tinfo->index = titleindex;
3378 tinfo->width = title->width;
3379 tinfo->height = title->height;
3380 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
3381 // Don't allow crop to 0
3382 if (title->crop[0] + title->crop[1] >= title->height)
3383 title->crop[0] = title->crop[1] = 0;
3384 if (title->crop[2] + title->crop[3] >= title->width)
3385 title->crop[2] = title->crop[3] = 0;
3386 tinfo->num_chapters = hb_list_count(title->list_chapter);
3387 tinfo->rate_base = title->rate_base;
3388 tinfo->rate = title->rate;
3389 tinfo->interlaced = title->detected_interlacing;
3390 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
3391 title->width * title->pixel_aspect_width,
3392 title->height * title->pixel_aspect_height);
3393 tinfo->hours = title->hours;
3394 tinfo->minutes = title->minutes;
3395 tinfo->seconds = title->seconds;
3396 tinfo->duration = title->duration;
3398 tinfo->angle_count = title->angle_count;
3399 tinfo->path = title->path;
3400 tinfo->name = title->name;
3401 tinfo->type = title->type;
3406 ghb_get_scan_audio_info(gint titleindex, gint audioindex)
3408 hb_audio_config_t *aconfig;
3410 aconfig = get_hb_audio(h_scan, titleindex, audioindex);
3415 ghb_audio_is_passthru(gint acodec)
3417 g_debug("ghb_audio_is_passthru () \n");
3418 return (acodec & HB_ACODEC_PASS_FLAG) != 0;
3422 ghb_audio_can_passthru(gint acodec)
3424 g_debug("ghb_audio_can_passthru () \n");
3425 return (acodec & HB_ACODEC_PASS_MASK) != 0;
3429 ghb_get_default_acodec()
3431 return HB_ACODEC_FAAC;
3435 picture_settings_deps(signal_user_data_t *ud)
3437 gboolean autoscale, keep_aspect, enable_keep_aspect;
3438 gboolean enable_scale_width, enable_scale_height;
3439 gboolean enable_disp_width, enable_disp_height, enable_par;
3443 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3446 ghb_ui_update(ud, "autoscale", ghb_boolean_value(TRUE));
3447 ghb_ui_update(ud, "PictureModulus", ghb_int_value(2));
3448 ghb_ui_update(ud, "PictureLooseCrop", ghb_boolean_value(TRUE));
3450 enable_keep_aspect = (pic_par != 1 && pic_par != 2);
3451 if (!enable_keep_aspect)
3453 ghb_ui_update(ud, "PictureKeepRatio", ghb_boolean_value(TRUE));
3455 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3456 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3458 enable_scale_width = !autoscale && (pic_par != 1);
3459 enable_scale_height = !autoscale && (pic_par != 1);
3460 enable_disp_width = (pic_par == 3) && !keep_aspect;
3461 enable_par = (pic_par == 3) && !keep_aspect;
3462 enable_disp_height = FALSE;
3464 widget = GHB_WIDGET(ud->builder, "PictureModulus");
3465 gtk_widget_set_sensitive(widget, pic_par != 1);
3466 widget = GHB_WIDGET(ud->builder, "PictureLooseCrop");
3467 gtk_widget_set_sensitive(widget, pic_par != 1);
3468 widget = GHB_WIDGET(ud->builder, "scale_width");
3469 gtk_widget_set_sensitive(widget, enable_scale_width);
3470 widget = GHB_WIDGET(ud->builder, "scale_height");
3471 gtk_widget_set_sensitive(widget, enable_scale_height);
3472 widget = GHB_WIDGET(ud->builder, "PictureDisplayWidth");
3473 gtk_widget_set_sensitive(widget, enable_disp_width);
3474 widget = GHB_WIDGET(ud->builder, "PictureDisplayHeight");
3475 gtk_widget_set_sensitive(widget, enable_disp_height);
3476 widget = GHB_WIDGET(ud->builder, "PicturePARWidth");
3477 gtk_widget_set_sensitive(widget, enable_par);
3478 widget = GHB_WIDGET(ud->builder, "PicturePARHeight");
3479 gtk_widget_set_sensitive(widget, enable_par);
3480 widget = GHB_WIDGET(ud->builder, "PictureKeepRatio");
3481 gtk_widget_set_sensitive(widget, enable_keep_aspect);
3482 widget = GHB_WIDGET(ud->builder, "autoscale");
3483 gtk_widget_set_sensitive(widget, pic_par != 1);
3487 ghb_set_scale(signal_user_data_t *ud, gint mode)
3492 gboolean keep_aspect;
3494 gboolean autocrop, autoscale, noscale;
3495 gint crop[4], width, height, par_width, par_height;
3496 gint crop_width, crop_height;
3497 gint aspect_n, aspect_d;
3498 gboolean keep_width = (mode & GHB_PIC_KEEP_WIDTH);
3499 gboolean keep_height = (mode & GHB_PIC_KEEP_HEIGHT);
3504 gint max_height = 0;
3506 g_debug("ghb_set_scale ()\n");
3507 picture_settings_deps(ud);
3508 if (h_scan == NULL) return;
3509 list = hb_get_titles( h_scan );
3510 if( !hb_list_count( list ) )
3512 /* No valid title, stop right there */
3517 titleindex = ghb_settings_combo_int(ud->settings, "title");
3518 title = hb_list_item( list, titleindex );
3519 if (title == NULL) return;
3521 if (job == NULL) return;
3523 if (ud->scale_busy) return;
3524 ud->scale_busy = TRUE;
3526 // First configure widgets
3527 mod = ghb_settings_combo_int(ud->settings, "PictureModulus");
3528 pic_par = ghb_settings_combo_int(ud->settings, "PicturePAR");
3529 keep_aspect = ghb_settings_get_boolean(ud->settings, "PictureKeepRatio");
3530 autocrop = ghb_settings_get_boolean(ud->settings, "PictureAutoCrop");
3531 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
3532 // "Noscale" is a flag that says we prefer to crop extra to satisfy
3533 // alignment constraints rather than scaling to satisfy them.
3534 noscale = ghb_settings_get_boolean(ud->settings, "PictureLooseCrop");
3535 // Align dimensions to either 16 or 2 pixels
3536 // The scaler crashes if the dimensions are not divisible by 2
3537 // x264 also will not accept dims that are not multiple of 2
3541 keep_height = FALSE;
3543 // Step needs to be at least 2 because odd widths cause scaler crash
3545 widget = GHB_WIDGET (ud->builder, "scale_width");
3546 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3547 widget = GHB_WIDGET (ud->builder, "scale_height");
3548 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3551 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3552 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3553 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3554 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3555 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3556 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3557 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3558 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
3562 widget = GHB_WIDGET (ud->builder, "PictureTopCrop");
3563 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3564 widget = GHB_WIDGET (ud->builder, "PictureBottomCrop");
3565 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3566 widget = GHB_WIDGET (ud->builder, "PictureLeftCrop");
3567 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3568 widget = GHB_WIDGET (ud->builder, "PictureRightCrop");
3569 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), 1, 16);
3571 ghb_title_info_t tinfo;
3572 ghb_get_title_info (&tinfo, titleindex);
3575 crop[0] = tinfo.crop[0];
3576 crop[1] = tinfo.crop[1];
3577 crop[2] = tinfo.crop[2];
3578 crop[3] = tinfo.crop[3];
3579 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3580 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3581 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3582 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3586 crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
3587 crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
3588 crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
3589 crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
3595 // Adjust the cropping to accomplish the desired width and height
3596 crop_width = tinfo.width - crop[2] - crop[3];
3597 crop_height = tinfo.height - crop[0] - crop[1];
3598 width = MOD_DOWN(crop_width, mod);
3599 height = MOD_DOWN(crop_height, mod);
3601 need1 = (crop_height - height) / 2;
3602 need2 = crop_height - height - need1;
3605 need1 = (crop_width - width) / 2;
3606 need2 = crop_width - width - need1;
3609 ghb_ui_update(ud, "PictureTopCrop", ghb_int64_value(crop[0]));
3610 ghb_ui_update(ud, "PictureBottomCrop", ghb_int64_value(crop[1]));
3611 ghb_ui_update(ud, "PictureLeftCrop", ghb_int64_value(crop[2]));
3612 ghb_ui_update(ud, "PictureRightCrop", ghb_int64_value(crop[3]));
3614 hb_reduce(&aspect_n, &aspect_d,
3615 title->width * title->pixel_aspect_width,
3616 title->height * title->pixel_aspect_height);
3617 crop_width = title->width - crop[2] - crop[3];
3618 crop_height = title->height - crop[0] - crop[1];
3622 height = crop_height;
3626 width = ghb_settings_get_int(ud->settings, "scale_width");
3627 height = ghb_settings_get_int(ud->settings, "scale_height");
3628 if (mode & GHB_PIC_USE_MAX)
3630 max_width = MOD_DOWN(
3631 ghb_settings_get_int(ud->settings, "PictureWidth"), mod);
3632 max_height = MOD_DOWN(
3633 ghb_settings_get_int(ud->settings, "PictureHeight"), mod);
3636 g_debug("max_width %d, max_height %d\n", max_width, max_height);
3639 width = title->width - crop[2] - crop[3];
3641 height = title->height - crop[0] - crop[1];
3643 width = MOD_ROUND(width, mod);
3644 height = MOD_ROUND(height, mod);
3646 job->anamorphic.mode = pic_par;
3649 // The scaler crashes if the dimensions are not divisible by 2
3650 // Align mod 2. And so does something in x264_encoder_headers()
3652 job->anamorphic.par_width = title->pixel_aspect_width;
3653 job->anamorphic.par_height = title->pixel_aspect_height;
3654 job->anamorphic.dar_width = 0;
3655 job->anamorphic.dar_height = 0;
3657 if (keep_height && pic_par == 2)
3658 width = ((double)height * crop_width / crop_height);
3660 job->height = height;
3661 job->maxWidth = max_width;
3662 job->maxHeight = max_height;
3663 job->crop[0] = crop[0]; job->crop[1] = crop[1];
3664 job->crop[2] = crop[2]; job->crop[3] = crop[3];
3665 if (job->anamorphic.mode == 3 && !keep_aspect)
3667 job->anamorphic.keep_display_aspect = 0;
3668 if (mode & GHB_PIC_KEEP_PAR)
3670 job->anamorphic.par_width =
3671 ghb_settings_get_int(ud->settings, "PicturePARWidth");
3672 job->anamorphic.par_height =
3673 ghb_settings_get_int(ud->settings, "PicturePARHeight");
3677 job->anamorphic.dar_width =
3678 ghb_settings_get_int(ud->settings,
3679 "PictureDisplayWidth");
3680 job->anamorphic.dar_height = height;
3685 job->anamorphic.keep_display_aspect = 1;
3687 // hb_set_anamorphic_size will adjust par, dar, and width/height
3688 // to conform to job parameters that have been set, including
3689 // maxWidth and maxHeight
3690 hb_set_anamorphic_size( job, &width, &height,
3691 &par_width, &par_height );
3692 if (job->anamorphic.mode == 3 && !keep_aspect &&
3693 mode & GHB_PIC_KEEP_PAR)
3695 // hb_set_anamorphic_size reduces the par, which we
3696 // don't want in this case because the user is
3697 // explicitely specifying it.
3698 par_width = ghb_settings_get_int(ud->settings,
3700 par_height = ghb_settings_get_int(ud->settings,
3701 "PicturePARHeight");
3706 // Adjust dims according to max values
3708 height = MIN(height, max_height);
3710 width = MIN(width, max_width);
3715 gint new_width, new_height;
3717 // Compute pixel aspect ration.
3718 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
3719 // Must scale so that par becomes 1:1
3720 // Try to keep largest dimension
3721 new_height = (crop_height * ((gdouble)width/crop_width) / par);
3722 new_width = (crop_width * ((gdouble)height/crop_height) * par);
3724 if (max_width && new_width > max_width)
3726 height = new_height;
3728 else if (max_height && new_height > max_height)
3732 else if (keep_width)
3734 height = new_height;
3736 else if (keep_height)
3740 else if (width > new_width)
3742 height = new_height;
3748 g_debug("new w %d h %d\n", width, height);
3750 width = MOD_ROUND(width, mod);
3751 height = MOD_ROUND(height, mod);
3753 height = MIN(height, max_height);
3755 width = MIN(width, max_width);
3756 par_width = par_height = 1;
3758 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
3759 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
3761 gint disp_width, dar_width, dar_height;
3764 disp_width = (gdouble)(width * par_width / par_height) + 0.5;
3765 hb_reduce(&dar_width, &dar_height, disp_width, height);
3767 gint iaspect = dar_width * 9 / dar_height;
3768 if (dar_width > 2 * dar_height)
3770 str = g_strdup_printf("%.2f : 1", (gdouble)dar_width / dar_height);
3772 else if (iaspect <= 16 && iaspect >= 15)
3774 str = g_strdup_printf("%.2f : 9", (gdouble)dar_width * 9 / dar_height);
3776 else if (iaspect <= 12 && iaspect >= 11)
3778 str = g_strdup_printf("%.2f : 3", (gdouble)dar_width * 3 / dar_height);
3782 str = g_strdup_printf("%d : %d", dar_width, dar_height);
3784 ghb_ui_update(ud, "display_aspect", ghb_string_value(str));
3786 ghb_ui_update(ud, "PicturePARWidth", ghb_int64_value(par_width));
3787 ghb_ui_update(ud, "PicturePARHeight", ghb_int64_value(par_height));
3788 ghb_ui_update(ud, "PictureDisplayWidth", ghb_int64_value(disp_width));
3789 ghb_ui_update(ud, "PictureDisplayHeight", ghb_int64_value(height));
3790 ud->scale_busy = FALSE;
3794 set_preview_job_settings(hb_job_t *job, GValue *settings)
3796 job->crop[0] = ghb_settings_get_int(settings, "PictureTopCrop");
3797 job->crop[1] = ghb_settings_get_int(settings, "PictureBottomCrop");
3798 job->crop[2] = ghb_settings_get_int(settings, "PictureLeftCrop");
3799 job->crop[3] = ghb_settings_get_int(settings, "PictureRightCrop");
3801 job->anamorphic.mode = ghb_settings_combo_int(settings, "PicturePAR");
3803 ghb_settings_combo_int(settings, "PictureModulus");
3804 job->width = ghb_settings_get_int(settings, "scale_width");
3805 job->height = ghb_settings_get_int(settings, "scale_height");
3806 if (ghb_settings_get_boolean(settings, "show_crop"))
3808 gdouble xscale = (gdouble)job->width /
3809 (gdouble)(job->title->width - job->crop[2] - job->crop[3]);
3810 gdouble yscale = (gdouble)job->height /
3811 (gdouble)(job->title->height - job->crop[0] - job->crop[1]);
3813 job->width += xscale * (job->crop[2] + job->crop[3]);
3814 job->height += yscale * (job->crop[0] + job->crop[1]);
3822 gboolean decomb_deint = ghb_settings_get_boolean(settings, "PictureDecombDeinterlace");
3825 gint decomb = ghb_settings_combo_int(settings, "PictureDecomb");
3826 job->deinterlace = (decomb == 0) ? 0 : 1;
3830 gint deint = ghb_settings_combo_int(settings, "PictureDeinterlace");
3831 job->deinterlace = (deint == 0) ? 0 : 1;
3834 gboolean keep_aspect;
3835 keep_aspect = ghb_settings_get_boolean(settings, "PictureKeepRatio");
3836 if (job->anamorphic.mode)
3838 job->anamorphic.par_width = job->title->pixel_aspect_width;
3839 job->anamorphic.par_height = job->title->pixel_aspect_height;
3840 job->anamorphic.dar_width = 0;
3841 job->anamorphic.dar_height = 0;
3843 if (job->anamorphic.mode == 3 && !keep_aspect)
3845 job->anamorphic.keep_display_aspect = 0;
3846 job->anamorphic.par_width =
3847 ghb_settings_get_int(settings, "PicturePARWidth");
3848 job->anamorphic.par_height =
3849 ghb_settings_get_int(settings, "PicturePARHeight");
3853 job->anamorphic.keep_display_aspect = 1;
3859 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
3866 if (h_scan == NULL) return 1500;
3867 list = hb_get_titles( h_scan );
3868 title = hb_list_item( list, titleindex );
3869 if (title == NULL) return 1500;
3871 if (job == NULL) return 1500;
3872 size = ghb_settings_get_int(settings, "VideoTargetSize");
3873 return hb_calc_bitrate( job, size );
3877 ghb_validate_filter_string(const gchar *str, gint max_fields)
3883 if (str == NULL || *str == 0) return TRUE;
3886 val = g_strtod(str, &end);
3888 { // Found a numeric value
3890 // negative max_fields means infinate
3891 if (max_fields >= 0 && fields > max_fields) return FALSE;
3905 ghb_validate_filters(signal_user_data_t *ud)
3911 gboolean decomb_deint = ghb_settings_get_boolean(ud->settings, "PictureDecombDeinterlace");
3913 index = ghb_settings_combo_int(ud->settings, "PictureDeinterlace");
3914 if (!decomb_deint && index == 1)
3916 str = ghb_settings_get_string(ud->settings, "PictureDeinterlaceCustom");
3917 if (!ghb_validate_filter_string(str, -1))
3919 message = g_strdup_printf(
3920 "Invalid Deinterlace Settings:\n\n%s\n",
3922 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3930 index = ghb_settings_combo_int(ud->settings, "PictureDetelecine");
3933 str = ghb_settings_get_string(ud->settings, "PictureDetelecineCustom");
3934 if (!ghb_validate_filter_string(str, -1))
3936 message = g_strdup_printf(
3937 "Invalid Detelecine Settings:\n\n%s\n",
3939 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3947 index = ghb_settings_combo_int(ud->settings, "PictureDecomb");
3948 if (decomb_deint && index == 1)
3950 str = ghb_settings_get_string(ud->settings, "PictureDecombCustom");
3951 if (!ghb_validate_filter_string(str, -1))
3953 message = g_strdup_printf(
3954 "Invalid Decomb Settings:\n\n%s\n",
3956 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3964 index = ghb_settings_combo_int(ud->settings, "PictureDenoise");
3967 str = ghb_settings_get_string(ud->settings, "PictureDenoiseCustom");
3968 if (!ghb_validate_filter_string(str, -1))
3970 message = g_strdup_printf(
3971 "Invalid Denoise Settings:\n\n%s\n",
3973 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
3984 ghb_validate_video(signal_user_data_t *ud)
3989 mux = ghb_settings_combo_int(ud->settings, "FileFormat");
3990 vcodec = ghb_settings_combo_int(ud->settings, "VideoEncoder");
3991 if ((mux == HB_MUX_MP4) && (vcodec == HB_VCODEC_THEORA))
3993 // mp4/theora combination is not supported.
3994 message = g_strdup_printf(
3995 "Theora is not supported in the MP4 container.\n\n"
3996 "You should choose a different video codec or container.\n"
3997 "If you continue, FFMPEG will be chosen for you.");
3998 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4004 vcodec = HB_VCODEC_FFMPEG;
4005 ghb_ui_update(ud, "VideoEncoder", ghb_int64_value(vcodec));
4011 ghb_validate_subtitles(signal_user_data_t *ud)
4017 if (h_scan == NULL) return FALSE;
4018 list = hb_get_titles( h_scan );
4019 if( !hb_list_count( list ) )
4021 /* No valid title, stop right there */
4022 g_message("No title found.\n");
4028 titleindex = ghb_settings_combo_int(ud->settings, "title");
4029 title = hb_list_item( list, titleindex );
4030 if (title == NULL) return FALSE;
4032 const GValue *slist, *settings;
4033 gint count, ii, source;
4034 gboolean burned, one_burned = FALSE;
4036 slist = ghb_settings_get_value(ud->settings, "subtitle_list");
4037 count = ghb_array_len(slist);
4038 for (ii = 0; ii < count; ii++)
4040 settings = ghb_array_get_nth(slist, ii);
4041 source = ghb_settings_get_int(settings, "SubtitleSource");
4042 burned = ghb_settings_get_boolean(settings, "SubtitleBurned");
4043 if (burned && one_burned)
4045 // MP4 can only handle burned vobsubs. make sure there isn't
4046 // already something burned in the list
4047 message = g_strdup_printf(
4048 "Only one subtitle may be burned into the video.\n\n"
4049 "You should change your subtitle selections.\n"
4050 "If you continue, some subtitles will be lost.");
4051 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4063 if (source == SRTSUB)
4067 filename = ghb_settings_get_string(settings, "SrtFile");
4068 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4070 message = g_strdup_printf(
4071 "Srt file does not exist or not a regular file.\n\n"
4072 "You should choose a valid file.\n"
4073 "If you continue, this subtitle will be ignored.");
4074 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message,
4075 "Cancel", "Continue"))
4089 ghb_select_audio_codec(GValue *settings, hb_audio_config_t *aconfig, gint acodec)
4091 gint mux = ghb_settings_combo_int(settings, "FileFormat");
4093 guint32 in_codec = aconfig ? aconfig->in.codec : HB_ACODEC_MASK;
4094 if (mux == HB_MUX_MP4)
4096 if ((acodec & in_codec & HB_ACODEC_AC3))
4098 return acodec & (in_codec | HB_ACODEC_PASS_FLAG);
4100 else if (acodec & HB_ACODEC_AC3)
4102 return HB_ACODEC_AC3;
4104 else if (acodec & HB_ACODEC_FAAC)
4106 return HB_ACODEC_FAAC;
4110 return HB_ACODEC_FAAC;
4115 if ((acodec & in_codec & HB_ACODEC_PASS_MASK))
4117 return acodec & (in_codec | HB_ACODEC_PASS_FLAG);
4119 else if (acodec & HB_ACODEC_AC3)
4121 return HB_ACODEC_AC3;
4123 else if (acodec & HB_ACODEC_VORBIS)
4125 return HB_ACODEC_VORBIS;
4127 else if (acodec & HB_ACODEC_LAME)
4129 return HB_ACODEC_LAME;
4131 else if (acodec & HB_ACODEC_FAAC)
4133 return HB_ACODEC_FAAC;
4137 return HB_ACODEC_LAME;
4143 ghb_validate_audio(signal_user_data_t *ud)
4150 if (h_scan == NULL) return FALSE;
4151 list = hb_get_titles( h_scan );
4152 if( !hb_list_count( list ) )
4154 /* No valid title, stop right there */
4155 g_message("No title found.\n");
4161 titleindex = ghb_settings_combo_int(ud->settings, "title");
4162 title = hb_list_item( list, titleindex );
4163 if (title == NULL) return FALSE;
4164 gint mux = ghb_settings_combo_int(ud->settings, "FileFormat");
4166 const GValue *audio_list;
4169 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
4170 count = ghb_array_len(audio_list);
4171 for (ii = 0; ii < count; ii++)
4174 hb_audio_config_t *aconfig;
4176 asettings = ghb_array_get_nth(audio_list, ii);
4177 gint track = ghb_settings_combo_int(asettings, "AudioTrack");
4178 gint codec = ghb_settings_combo_int(asettings, "AudioEncoder");
4179 if (codec == HB_ACODEC_ANY)
4182 aconfig = (hb_audio_config_t *) hb_list_audio_config_item(
4183 title->list_audio, track );
4184 if ( ghb_audio_is_passthru(codec) &&
4185 !(ghb_audio_can_passthru(aconfig->in.codec) &&
4186 (aconfig->in.codec & codec)))
4188 // Not supported. AC3 is passthrough only, so input must be AC3
4189 message = g_strdup_printf(
4190 "The source does not support Pass-Thru.\n\n"
4191 "You should choose a different audio codec.\n"
4192 "If you continue, one will be chosen for you.");
4193 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4199 if ((codec & HB_ACODEC_AC3) ||
4200 aconfig->in.codec == HB_ACODEC_DCA)
4202 codec = HB_ACODEC_AC3;
4204 else if (mux == HB_MUX_MKV)
4206 codec = HB_ACODEC_LAME;
4210 codec = HB_ACODEC_FAAC;
4212 value = ghb_lookup_acodec_value(codec);
4213 ghb_settings_take_value(asettings, "AudioEncoder", value);
4215 gchar *a_unsup = NULL;
4216 gchar *mux_s = NULL;
4217 if (mux == HB_MUX_MP4)
4220 // mp4/vorbis|DTS combination is not supported.
4221 if (codec == HB_ACODEC_VORBIS)
4224 codec = HB_ACODEC_FAAC;
4226 if (codec == HB_ACODEC_DCA)
4229 codec = HB_ACODEC_AC3;
4234 message = g_strdup_printf(
4235 "%s is not supported in the %s container.\n\n"
4236 "You should choose a different audio codec.\n"
4237 "If you continue, one will be chosen for you.", a_unsup, mux_s);
4238 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4244 value = ghb_lookup_acodec_value(codec);
4245 ghb_settings_take_value(asettings, "AudioEncoder", value);
4247 gint mix = ghb_settings_combo_int (asettings, "AudioMixdown");
4248 gboolean allow_mono = TRUE;
4249 gboolean allow_stereo = TRUE;
4250 gboolean allow_dolby = TRUE;
4251 gboolean allow_dpl2 = TRUE;
4252 gboolean allow_6ch = TRUE;
4254 gint layout = aconfig->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
4256 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
4258 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
4259 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
4260 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
4261 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
4263 (codec & ~HB_ACODEC_LAME) &&
4264 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
4265 (aconfig->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
4267 gchar *mix_unsup = NULL;
4268 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
4272 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
4274 mix_unsup = "stereo";
4276 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
4278 mix_unsup = "Dolby";
4280 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
4282 mix_unsup = "Dolby Pro Logic II";
4284 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
4286 mix_unsup = "6 Channel";
4290 message = g_strdup_printf(
4291 "The source audio does not support %s mixdown.\n\n"
4292 "You should choose a different mixdown.\n"
4293 "If you continue, one will be chosen for you.", mix_unsup);
4294 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
4300 mix = ghb_get_best_mix(aconfig, codec, mix);
4301 value = get_amix_value(mix);
4302 ghb_settings_take_value(asettings, "AudioMixdown", value);
4309 ghb_validate_vquality(GValue *settings)
4315 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
4316 vcodec = ghb_settings_combo_int(settings, "VideoEncoder");
4318 vquality = ghb_settings_get_double(settings, "VideoQualitySlider");
4319 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
4323 case HB_VCODEC_X264:
4329 case HB_VCODEC_FFMPEG:
4335 case HB_VCODEC_THEORA:
4347 if (vquality < min || vquality > max)
4349 message = g_strdup_printf(
4350 "Interesting video quality choise: %d\n\n"
4351 "Typical values range from %d to %d.\n"
4352 "Are you sure you wish to use this setting?",
4353 (gint)vquality, min, max);
4354 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
4355 "Cancel", "Continue"))
4367 add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex)
4372 static gchar *x264opts;
4374 gboolean tweaks = FALSE;
4375 gchar *detel_str = NULL;
4376 gchar *decomb_str = NULL;
4377 gchar *deint_str = NULL;
4378 gchar *deblock_str = NULL;
4379 gchar *denoise_str = NULL;
4380 gchar *dest_str = NULL;
4382 g_debug("add_job()\n");
4383 if (h == NULL) return;
4384 list = hb_get_titles( h );
4385 if( !hb_list_count( list ) )
4387 /* No valid title, stop right there */
4391 title = hb_list_item( list, titleindex );
4392 if (title == NULL) return;
4394 /* Set job settings */
4396 if (job == NULL) return;
4398 job->angle = ghb_settings_get_int(js, "angle");
4399 job->start_at_preview = ghb_settings_get_int(js, "start_frame") + 1;
4400 if (job->start_at_preview)
4402 job->seek_points = ghb_settings_get_int(js, "preview_count");
4403 job->pts_to_stop = ghb_settings_get_int(js, "live_duration") * 90000LL;
4406 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
4407 job->mux = ghb_settings_combo_int(js, "FileFormat");
4408 if (job->mux == HB_MUX_MP4)
4410 job->largeFileSize = ghb_settings_get_boolean(js, "Mp4LargeFile");
4411 job->mp4_optimize = ghb_settings_get_boolean(js, "Mp4HttpOptimize");
4415 job->largeFileSize = FALSE;
4416 job->mp4_optimize = FALSE;
4418 if (!job->start_at_preview)
4421 gint num_chapters = hb_list_count(title->list_chapter);
4422 gint duration = title->duration / 90000;
4423 job->chapter_start = 1;
4424 job->chapter_end = num_chapters;
4426 if (ghb_settings_combo_int(js, "PtoPType") == 0)
4428 start = ghb_settings_get_int(js, "start_point");
4429 end = ghb_settings_get_int(js, "end_point");
4430 job->chapter_start = MIN( num_chapters, start );
4431 job->chapter_end = MAX( job->chapter_start, end );
4434 if (ghb_settings_combo_int(js, "PtoPType") == 1)
4436 job->chapter_start = 1;
4437 job->chapter_end = num_chapters;
4438 start = ghb_settings_get_int(js, "start_point");
4439 end = ghb_settings_get_int(js, "end_point");
4440 job->pts_to_start = (int64_t)MIN(duration-1, start) * 90000;
4441 job->pts_to_stop = (int64_t)MAX(start+1, end) * 90000 -
4444 if (ghb_settings_combo_int(js, "PtoPType") == 2)
4446 job->chapter_start = 1;
4447 job->chapter_end = num_chapters;
4448 start = ghb_settings_get_int(js, "start_point");
4449 end = ghb_settings_get_int(js, "end_point");
4451 max_frames = (gint64)duration * title->rate / title->rate_base;
4452 job->frame_to_start = (int64_t)MIN(max_frames-1, start-1);
4453 job->frame_to_stop = (int64_t)MAX(start, end-1) -
4454 job->frame_to_start;
4456 job->chapter_markers = ghb_settings_get_boolean(js, "ChapterMarkers");
4457 if (job->chapter_start == job->chapter_end)
4458 job->chapter_markers = 0;
4459 if ( job->chapter_markers )
4466 chapters = ghb_settings_get_value(js, "chapter_list");
4467 count = ghb_array_len(chapters);
4468 for(chap = 0; chap < count; chap++)
4470 hb_chapter_t * chapter_s;
4474 chapter = ghb_array_get_nth(chapters, chap);
4475 name = ghb_value_string(chapter);
4478 name = g_strdup_printf ("Chapter %2d", chap+1);
4480 chapter_s = hb_list_item( job->title->list_chapter, chap);
4481 strncpy(chapter_s->title, name, 1023);
4482 chapter_s->title[1023] = '\0';
4487 job->crop[0] = ghb_settings_get_int(js, "PictureTopCrop");
4488 job->crop[1] = ghb_settings_get_int(js, "PictureBottomCrop");
4489 job->crop[2] = ghb_settings_get_int(js, "PictureLeftCrop");
4490 job->crop[3] = ghb_settings_get_int(js, "PictureRightCrop");
4493 gboolean decomb_deint = ghb_settings_get_boolean(js, "PictureDecombDeinterlace");
4494 gint decomb = ghb_settings_combo_int(js, "PictureDecomb");
4495 gint deint = ghb_settings_combo_int(js, "PictureDeinterlace");
4497 job->deinterlace = (deint != 0) ? 1 : 0;
4499 job->deinterlace = 0;
4500 job->grayscale = ghb_settings_get_boolean(js, "VideoGrayScale");
4502 gboolean keep_aspect;
4503 keep_aspect = ghb_settings_get_boolean(js, "PictureKeepRatio");
4504 job->anamorphic.mode = ghb_settings_combo_int(js, "PicturePAR");
4505 job->modulus = ghb_settings_combo_int(js, "PictureModulus");
4506 if (job->anamorphic.mode)
4508 job->anamorphic.par_width = title->pixel_aspect_width;
4509 job->anamorphic.par_height = title->pixel_aspect_height;
4510 job->anamorphic.dar_width = 0;
4511 job->anamorphic.dar_height = 0;
4513 if (job->anamorphic.mode == 3 && !keep_aspect)
4515 job->anamorphic.keep_display_aspect = 0;
4516 job->anamorphic.par_width =
4517 ghb_settings_get_int(js, "PicturePARWidth");
4518 job->anamorphic.par_height =
4519 ghb_settings_get_int(js, "PicturePARHeight");
4523 job->anamorphic.keep_display_aspect = 1;
4527 /* Add selected filters */
4528 job->filters = hb_list_init();
4529 gint detel = ghb_settings_combo_int(js, "PictureDetelecine");
4534 if (detel_opts.map[detel].svalue != NULL)
4535 detel_str = g_strdup(detel_opts.map[detel].svalue);
4538 detel_str = ghb_settings_get_string(js, "PictureDetelecineCustom");
4539 hb_filter_detelecine.settings = detel_str;
4540 hb_list_add( job->filters, &hb_filter_detelecine );
4542 if ( decomb_deint && decomb )
4546 if (decomb_opts.map[decomb].svalue != NULL)
4547 decomb_str = g_strdup(decomb_opts.map[decomb].svalue);
4550 decomb_str = ghb_settings_get_string(js, "PictureDecombCustom");
4551 hb_filter_decomb.settings = decomb_str;
4552 hb_list_add( job->filters, &hb_filter_decomb );
4554 if( job->deinterlace )
4558 if (deint_opts.map[deint].svalue != NULL)
4559 deint_str = g_strdup(deint_opts.map[deint].svalue);
4562 deint_str = ghb_settings_get_string(js, "PictureDeinterlaceCustom");
4563 hb_filter_deinterlace.settings = deint_str;
4564 hb_list_add( job->filters, &hb_filter_deinterlace );
4566 gint deblock = ghb_settings_get_int(js, "PictureDeblock");
4569 deblock_str = g_strdup_printf("%d", deblock);
4570 hb_filter_deblock.settings = deblock_str;
4571 hb_list_add( job->filters, &hb_filter_deblock );
4573 gint denoise = ghb_settings_combo_int(js, "PictureDenoise");
4578 if (denoise_opts.map[denoise].svalue != NULL)
4579 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
4582 denoise_str = ghb_settings_get_string(js, "PictureDenoiseCustom");
4583 hb_filter_denoise.settings = denoise_str;
4584 hb_list_add( job->filters, &hb_filter_denoise );
4586 job->width = ghb_settings_get_int(js, "scale_width");
4587 job->height = ghb_settings_get_int(js, "scale_height");
4589 job->vcodec = ghb_settings_combo_int(js, "VideoEncoder");
4590 if ((job->mux == HB_MUX_MP4 ) && (job->vcodec == HB_VCODEC_THEORA))
4592 // mp4/theora combination is not supported.
4593 job->vcodec = HB_VCODEC_FFMPEG;
4595 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
4597 job->ipod_atom = ghb_settings_get_boolean(js, "Mp4iPodCompatible");
4599 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
4602 vquality = ghb_settings_get_double(js, "VideoQualitySlider");
4603 job->vquality = vquality;
4606 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
4608 job->vquality = -1.0;
4609 job->vbitrate = ghb_settings_get_int(js, "VideoAvgBitrate");
4612 gint vrate = ghb_settings_combo_int(js, "VideoFramerate");
4615 job->vrate = title->rate;
4616 job->vrate_base = title->rate_base;
4621 job->vrate = 27000000;
4622 job->vrate_base = vrate;
4623 gboolean pfr = ghb_settings_get_boolean(js, "VideoFrameratePFR");
4630 const GValue *audio_list;
4634 audio_list = ghb_settings_get_value(js, "audio_list");
4635 count = ghb_array_len(audio_list);
4636 for (ii = 0; ii < count; ii++)
4639 hb_audio_config_t audio;
4640 hb_audio_config_t *aconfig;
4643 hb_audio_config_init(&audio);
4644 asettings = ghb_array_get_nth(audio_list, ii);
4645 audio.in.track = ghb_settings_get_int(asettings, "AudioTrack");
4646 audio.out.track = tcount;
4648 aconfig = (hb_audio_config_t *) hb_list_audio_config_item(
4649 title->list_audio, audio.in.track );
4651 acodec = ghb_settings_combo_int(asettings, "AudioEncoder");
4652 audio.out.codec = ghb_select_audio_codec(js, aconfig, acodec);
4654 audio.out.dynamic_range_compression =
4655 ghb_settings_get_double(asettings, "AudioTrackDRCSlider");
4656 if (audio.out.dynamic_range_compression < 1.0)
4657 audio.out.dynamic_range_compression = 0.0;
4659 // It would be better if this were done in libhb for us, but its not yet.
4660 if (ghb_audio_is_passthru(audio.out.codec))
4662 audio.out.mixdown = 0;
4666 audio.out.mixdown = ghb_settings_combo_int(asettings, "AudioMixdown");
4667 // Make sure the mixdown is valid and pick a new one if not.
4668 audio.out.mixdown = ghb_get_best_mix(aconfig, audio.out.codec,
4671 ghb_settings_combo_int(asettings, "AudioBitrate");
4672 gint srate = ghb_settings_combo_int(asettings, "AudioSamplerate");
4673 if (srate == 0) // 0 is same as source
4674 audio.out.samplerate = aconfig->in.samplerate;
4676 audio.out.samplerate = srate;
4678 audio.out.bitrate = hb_get_best_audio_bitrate(
4679 audio.out.codec, audio.out.bitrate,
4680 audio.out.samplerate, audio.out.mixdown);
4683 // Add it to the jobs audio list
4684 hb_audio_add( job, &audio );
4687 // I was tempted to move this up with the reset of the video quality
4688 // settings, but I suspect the settings above need to be made
4689 // first in order for hb_calc_bitrate to be accurate.
4690 if (ghb_settings_get_boolean(js, "vquality_type_target"))
4694 size = ghb_settings_get_int(js, "VideoTargetSize");
4695 job->vbitrate = hb_calc_bitrate( job, size );
4696 job->vquality = -1.0;
4699 dest_str = ghb_settings_get_string(js, "destination");
4700 job->file = dest_str;
4702 const GValue *subtitle_list;
4704 gboolean force, burned, def, one_burned = FALSE;
4706 ghb_settings_set_boolean(js, "subtitle_scan", FALSE);
4707 subtitle_list = ghb_settings_get_value(js, "subtitle_list");
4708 count = ghb_array_len(subtitle_list);
4709 for (ii = 0; ii < count; ii++)
4714 ssettings = ghb_array_get_nth(subtitle_list, ii);
4716 force = ghb_settings_get_boolean(ssettings, "SubtitleForced");
4717 burned = ghb_settings_get_boolean(ssettings, "SubtitleBurned");
4718 def = ghb_settings_get_boolean(ssettings, "SubtitleDefaultTrack");
4719 source = ghb_settings_get_int(ssettings, "SubtitleSource");
4721 if (source == SRTSUB)
4723 hb_subtitle_config_t sub_config;
4724 gchar *filename, *lang, *code;
4726 filename = ghb_settings_get_string(ssettings, "SrtFile");
4727 if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
4731 sub_config.offset = ghb_settings_get_int(ssettings, "SrtOffset");
4732 lang = ghb_settings_get_string(ssettings, "SrtLanguage");
4733 code = ghb_settings_get_string(ssettings, "SrtCodeset");
4734 strncpy(sub_config.src_filename, filename, 128);
4735 strncpy(sub_config.src_codeset, code, 40);
4736 sub_config.force = 0;
4737 sub_config.dest = PASSTHRUSUB;
4738 sub_config.default_track = def;
4740 hb_srt_add( job, &sub_config, lang);
4748 subtitle = ghb_settings_get_int(ssettings, "SubtitleTrack");
4753 job->select_subtitle_config.dest = PASSTHRUSUB;
4757 // Only allow one subtitle to be burned into the video
4760 job->select_subtitle_config.dest = RENDERSUB;
4763 job->select_subtitle_config.force = force;
4764 job->select_subtitle_config.default_track = def;
4765 job->indepth_scan = 1;
4766 ghb_settings_set_boolean(js, "subtitle_scan", TRUE);
4768 else if (subtitle >= 0)
4770 hb_subtitle_t * subt;
4771 hb_subtitle_config_t sub_config;
4773 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, subtitle);
4776 sub_config = subt->config;
4779 sub_config.dest = PASSTHRUSUB;
4781 else if ( burned && canBurn(subt->source) )
4783 // Only allow one subtitle to be burned into the video
4786 sub_config.dest = RENDERSUB;
4789 sub_config.force = force;
4790 sub_config.default_track = def;
4791 hb_subtitle_add( job, &sub_config, subtitle );
4796 // TODO: libhb holds onto a reference to the x264opts and is not
4797 // finished with it until encoding the job is done. But I can't
4798 // find a way to get at the job before it is removed in order to
4799 // free up the memory I am allocating here.
4800 // The short story is THIS LEAKS.
4801 x264opts = ghb_build_x264opts_string(js);
4803 if( *x264opts == '\0' )
4809 if (job->indepth_scan == 1)
4811 // Subtitle scan. Look for subtitle matching audio language
4814 * When subtitle scan is enabled do a fast pre-scan job
4815 * which will determine which subtitles to enable, if any.
4818 job->indepth_scan = 1;
4819 job->x264opts = NULL;
4822 * Add the pre-scan job
4824 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4828 if( ghb_settings_get_boolean(js, "VideoTwoPass") &&
4829 !ghb_settings_get_boolean(js, "vquality_type_constant"))
4832 * If subtitle_scan is enabled then only turn it on
4833 * for the second pass and then off again for the
4837 job->indepth_scan = 0;
4840 * If turbo options have been selected then append them
4841 * to the x264opts now (size includes one ':' and the '\0')
4843 if( ghb_settings_get_boolean(js, "VideoTurboTwoPass") )
4845 gchar *tmp_x264opts;
4849 badapt = ghb_lookup_badapt(x264opts);
4852 extra_opts = g_strdup_printf("%s", turbo_opts);
4856 extra_opts = g_strdup_printf("%s:weightb=0", turbo_opts);
4861 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, extra_opts);
4866 * No x264opts to modify, but apply the turbo options
4867 * anyway as they may be modifying defaults
4869 tmp_x264opts = g_strdup_printf("%s", extra_opts);
4873 job->x264opts = tmp_x264opts;
4877 job->x264opts = x264opts;
4879 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4881 //if (job->x264opts != NULL)
4882 // g_free(job->x264opts);
4886 * On the second pass we turn off subtitle scan so that we
4887 * can actually encode using any subtitles that were auto
4888 * selected in the first pass (using the whacky select-subtitle
4889 * attribute of the job).
4891 job->indepth_scan = 0;
4892 job->x264opts = x264opts;
4893 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4895 //if (job->x264opts != NULL)
4896 // g_free(job->x264opts);
4900 job->x264opts = x264opts;
4901 job->indepth_scan = 0;
4903 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
4905 //if (job->x264opts != NULL)
4906 // g_free(job->x264opts);
4909 // clean up audio list
4910 gint num_audio_tracks = hb_list_count(job->list_audio);
4911 for(ii = 0; ii < num_audio_tracks; ii++)
4913 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
4914 hb_list_rem(job->list_audio, audio);
4918 // clean up subtitle list
4919 gint num_subtitle_tracks = hb_list_count(job->list_subtitle);
4920 for(ii = 0; ii < num_subtitle_tracks; ii++)
4922 hb_subtitle_t *subtitle = hb_list_item(job->list_subtitle, 0);
4923 hb_list_rem(job->list_subtitle, subtitle);
4927 if (detel_str) g_free(detel_str);
4928 if (decomb_str) g_free(decomb_str);
4929 if (deint_str) g_free(deint_str);
4930 if (deblock_str) g_free(deblock_str);
4931 if (denoise_str) g_free(denoise_str);
4932 if (dest_str) g_free(dest_str);
4936 ghb_add_job(GValue *js, gint unique_id)
4938 // Since I'm doing a scan of the single title I want just prior
4939 // to adding the job, there is only the one title to choose from.
4940 add_job(h_queue, js, unique_id, 0);
4944 ghb_add_live_job(GValue *js, gint unique_id)
4946 // Since I'm doing a scan of the single title I want just prior
4947 // to adding the job, there is only the one title to choose from.
4948 gint titleindex = ghb_settings_combo_int(js, "title");
4949 add_job(h_scan, js, unique_id, titleindex);
4953 ghb_remove_job(gint unique_id)
4958 // Multiples passes all get the same id
4960 // Go backwards through list, so reordering doesn't screw me.
4961 ii = hb_count(h_queue) - 1;
4962 while ((job = hb_job(h_queue, ii--)) != NULL)
4964 if ((job->sequence_id & 0xFFFFFF) == unique_id)
4965 hb_rem(h_queue, job);
4972 hb_start( h_queue );
4982 ghb_start_live_encode()
4988 ghb_stop_live_encode()
4997 hb_get_state2( h_queue, &s );
4999 if( s.state == HB_STATE_PAUSED )
5001 hb_status.queue.state &= ~GHB_STATE_PAUSED;
5002 hb_resume( h_queue );
5006 hb_status.queue.state |= GHB_STATE_PAUSED;
5007 hb_pause( h_queue );
5022 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5025 gint channels = gdk_pixbuf_get_n_channels (pb);
5026 gint stride = gdk_pixbuf_get_rowstride (pb);
5028 for (jj = 0; jj < width; jj++)
5030 dst = pixels + y * stride + (x+jj) * channels;
5031 for (ii = 0; ii < len; ii++)
5052 guint8 *pixels = gdk_pixbuf_get_pixels (pb);
5055 gint channels = gdk_pixbuf_get_n_channels (pb);
5056 gint stride = gdk_pixbuf_get_rowstride (pb);
5058 for (jj = 0; jj < width; jj++)
5060 dst = pixels + (y+jj) * stride + x * channels;
5061 for (ii = 0; ii < len; ii++)
5082 gint line_width = 8;
5089 {{0x80, 0x80, 0x80},{0xC0, 0x80, 0x70},{0x80, 0xA0, 0x80},{0x70, 0x80, 0xA0}};
5094 for (ii = x, jj = 0; ii+line_width < x+w; ii += step, jj++)
5096 vert_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, ii, y, h, line_width);
5102 for (ii = y, jj = 0; ii+line_width < y+h; ii += step, jj++)
5104 horz_line(pb, c[jj&3].r, c[jj&3].g, c[jj&3].b, x, ii, w, line_width);
5110 ghb_get_preview_image(
5113 signal_user_data_t *ud,
5121 settings = ud->settings;
5122 list = hb_get_titles( h_scan );
5123 if( !hb_list_count( list ) )
5125 /* No valid title, stop right there */
5128 title = hb_list_item( list, titleindex );
5129 if (title == NULL) return NULL;
5130 if (title->job == NULL) return NULL;
5131 set_preview_job_settings(title->job, settings);
5133 // hb_get_preview doesn't compensate for anamorphic, so lets
5134 // calculate scale factors
5135 gint width, height, par_width = 1, par_height = 1;
5136 gint pic_par = ghb_settings_combo_int(settings, "PicturePAR");
5139 hb_set_anamorphic_size( title->job, &width, &height,
5140 &par_width, &par_height );
5143 // Make sure we have a big enough buffer to receive the image from libhb
5144 gint dstWidth = title->job->width;
5145 gint dstHeight= title->job->height;
5147 static guint8 *buffer = NULL;
5148 static gint bufferSize = 0;
5151 newSize = dstWidth * dstHeight * 4;
5152 if( bufferSize < newSize )
5154 bufferSize = newSize;
5155 buffer = (guint8*) g_realloc( buffer, bufferSize );
5157 hb_get_preview( h_scan, title, index, buffer );
5159 // Create an GdkPixbuf and copy the libhb image into it, converting it from
5160 // libhb's format something suitable.
5162 // The image data returned by hb_get_preview is 4 bytes per pixel,
5163 // BGRA format. Alpha is ignored.
5165 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
5166 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
5168 guint32 *src = (guint32*)buffer;
5169 guint8 *dst = pixels;
5172 gint channels = gdk_pixbuf_get_n_channels (preview);
5173 gint stride = gdk_pixbuf_get_rowstride (preview);
5176 for (ii = 0; ii < dstHeight; ii++)
5179 for (jj = 0; jj < dstWidth; jj++)
5181 tmp[0] = src[0] >> 16;
5182 tmp[1] = src[0] >> 8;
5183 tmp[2] = src[0] >> 0;
5189 gint w = ghb_settings_get_int(settings, "scale_width");
5190 gint h = ghb_settings_get_int(settings, "scale_height");
5191 ghb_par_scale(ud, &w, &h, par_width, par_height);
5193 gint c0, c1, c2, c3;
5194 c0 = ghb_settings_get_int(settings, "PictureTopCrop");
5195 c1 = ghb_settings_get_int(settings, "PictureBottomCrop");
5196 c2 = ghb_settings_get_int(settings, "PictureLeftCrop");
5197 c3 = ghb_settings_get_int(settings, "PictureRightCrop");
5199 gdouble xscale = (gdouble)w / (gdouble)(title->width - c2 - c3);
5200 gdouble yscale = (gdouble)h / (gdouble)(title->height - c0 - c1);
5202 ghb_par_scale(ud, &dstWidth, &dstHeight, par_width, par_height);
5205 if (ghb_settings_get_boolean(settings, "reduce_hd_preview"))
5209 gint orig_w, orig_h;
5212 if (ghb_settings_get_boolean(settings, "preview_fullscreen"))
5216 ss = gdk_screen_get_default();
5217 s_w = gdk_screen_get_width(ss);
5218 s_h = gdk_screen_get_height(ss);
5222 if (dstWidth > s_w * factor / 100)
5224 dstWidth = s_w * factor / 100;
5225 dstHeight = dstHeight * dstWidth / orig_w;
5227 if (dstHeight > s_h * factor / 100)
5229 dstHeight = s_h * factor / 100;
5230 dstWidth = dstWidth * dstHeight / orig_h;
5232 xscale *= (gdouble)dstWidth / orig_w;
5233 yscale *= (gdouble)dstHeight / orig_h;
5234 w *= (gdouble)dstWidth / orig_w;
5235 h *= (gdouble)dstHeight / orig_h;
5237 GdkPixbuf *scaled_preview;
5238 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
5239 if (ghb_settings_get_boolean(settings, "show_crop"))
5246 hash_pixbuf(scaled_preview, c2, 0, w, c0, 32, 0);
5248 hash_pixbuf(scaled_preview, c2, dstHeight-c1, w, c1, 32, 0);
5250 hash_pixbuf(scaled_preview, 0, c0, c2, h, 32, 1);
5252 hash_pixbuf(scaled_preview, dstWidth-c3, c0, c3, h, 32, 1);
5254 g_object_unref (preview);
5255 return scaled_preview;
5259 sanitize_volname(gchar *name)
5284 ghb_dvd_volname(const gchar *device)
5287 name = hb_dvd_name((gchar*)device);
5288 if (name != NULL && name[0] != 0)
5290 name = g_strdup(name);
5291 sanitize_volname(name);