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
28 #include "hbversion.h"
30 #include <glib/gstdio.h>
31 #include "hb-backend.h"
33 #include "callbacks.h"
39 const gchar *shortOpt;
51 static options_map_t d_container_opts[] =
53 {"MKV", "mkv", HB_MUX_MKV, 0.0, "mkv"},
54 {"MP4", "mp4", HB_MUX_MP4, 0.0, "mp4"},
55 {"M4V", "m4v", HB_MUX_MP4, 0.0, "m4v"},
56 {"AVI", "avi", HB_MUX_AVI, 0.0, "avi"},
57 {"OGM", "ogm", HB_MUX_OGM, 0.0, "ogm"},
59 combo_opts_t container_opts =
61 sizeof(d_container_opts)/sizeof(options_map_t),
65 static options_map_t d_deint_opts[] =
67 {"None", "none", 0, 0.0, ""},
68 {"Fast", "fast", 1, 0.0, "-1:-1:-1:0:1"},
69 {"Slow", "slow", 2, 0.0, "2:-1:-1:0:1"},
70 {"Slower", "slower", 3, 0.0, "0:-1:-1:0:1"},
72 combo_opts_t deint_opts =
74 sizeof(d_deint_opts)/sizeof(options_map_t),
78 static options_map_t d_denoise_opts[] =
80 {"None", "none", 0, 0.0, ""},
81 {"Weak", "weak", 1, 0.0, "2:1:2:3"},
82 {"Medium", "medium", 2, 0.0, "3:2:2:3"},
83 {"Strong", "strong", 3, 0.0, "7:7:5:5"},
85 combo_opts_t denoise_opts =
87 sizeof(d_denoise_opts)/sizeof(options_map_t),
91 static options_map_t d_vcodec_opts[] =
93 {"H.264 (x264)", "x264", HB_VCODEC_X264, 0.0, ""},
94 {"MPEG-4 (XviD)", "xvid", HB_VCODEC_XVID, 0.0, ""},
95 {"MPEG-4 (FFMPEG)", "ffmpeg", HB_VCODEC_FFMPEG, 0.0, ""},
96 {"Theora", "theora", HB_VCODEC_THEORA, 0.0, ""},
98 combo_opts_t vcodec_opts =
100 sizeof(d_vcodec_opts)/sizeof(options_map_t),
104 static options_map_t d_acodec_opts[] =
106 {"AAC (faac)", "faac", HB_ACODEC_FAAC, 0.0, "faac"},
107 {"MP3 (lame)", "lame", HB_ACODEC_LAME, 0.0, "lame"},
108 {"Vorbis", "vorbis", HB_ACODEC_VORBIS, 0.0, "vorbis"},
109 {"AC3 (pass-thru)", "ac3", HB_ACODEC_AC3, 0.0, "ac3"},
111 combo_opts_t acodec_opts =
113 sizeof(d_acodec_opts)/sizeof(options_map_t),
117 static options_map_t d_direct_opts[] =
119 {"None", "none", 0, 0.0, "none"},
120 {"Spatial", "spatial", 1, 0.0, "spatial"},
121 {"Temporal", "temporal", 2, 0.0, "temporal"},
122 {"Automatic", "auto", 3, 0.0, "auto"},
124 combo_opts_t direct_opts =
126 sizeof(d_direct_opts)/sizeof(options_map_t),
130 static options_map_t d_me_opts[] =
132 {"Diamond", "dia", 0, 0.0, "dia"},
133 {"Hexagon", "hex", 1, 0.0, "hex"},
134 {"Uneven Multi-Hexagon", "umh", 2, 0.0, "umh"},
135 {"Exhaustive", "esa", 3, 0.0, "esa"},
137 combo_opts_t me_opts =
139 sizeof(d_me_opts)/sizeof(options_map_t),
143 static options_map_t d_subme_opts[] =
145 {"1", "1", 1, 0.0, "1"},
146 {"2", "2", 2, 0.0, "2"},
147 {"3", "3", 3, 0.0, "3"},
148 {"4", "4", 4, 0.0, "4"},
149 {"5", "5", 5, 0.0, "5"},
150 {"6", "6", 6, 0.0, "6"},
151 {"7", "7", 7, 0.0, "7"},
153 combo_opts_t subme_opts =
155 sizeof(d_subme_opts)/sizeof(options_map_t),
159 static options_map_t d_analyse_opts[] =
161 {"Some", "some", 0, 0.0, "some"},
162 {"None", "none", 1, 0.0, "none"},
163 {"All", "all", 2, 0.0, "all"},
164 {"Custom", "custom", 3, 0.0, "all"},
166 combo_opts_t analyse_opts =
168 sizeof(d_analyse_opts)/sizeof(options_map_t),
172 static options_map_t d_trellis_opts[] =
174 {"Disabled", "0", 0, 0.0, "0"},
175 {"Final Macro Block", "1", 1, 0.0, "1"},
176 {"Always", "2", 2, 0.0, "2"},
178 combo_opts_t trellis_opts =
180 sizeof(d_trellis_opts)/sizeof(options_map_t),
184 typedef struct iso639_lang_t
186 char * eng_name; /* Description in English */
187 char * native_name; /* Description in native language */
188 char * iso639_1; /* ISO-639-1 (2 characters) code */
189 char * iso639_2; /* ISO-639-2/t (3 character) code */
190 char * iso639_2b; /* ISO-639-2/b code (if different from above) */
193 static const iso639_lang_t language_table[] =
195 { "Any", "", "zz", "und" },
196 { "Afar", "", "aa", "aar" },
197 { "Abkhazian", "", "ab", "abk" },
198 { "Afrikaans", "", "af", "afr" },
199 { "Akan", "", "ak", "aka" },
200 { "Albanian", "", "sq", "sqi", "alb" },
201 { "Amharic", "", "am", "amh" },
202 { "Arabic", "", "ar", "ara" },
203 { "Aragonese", "", "an", "arg" },
204 { "Armenian", "", "hy", "hye", "arm" },
205 { "Assamese", "", "as", "asm" },
206 { "Avaric", "", "av", "ava" },
207 { "Avestan", "", "ae", "ave" },
208 { "Aymara", "", "ay", "aym" },
209 { "Azerbaijani", "", "az", "aze" },
210 { "Bashkir", "", "ba", "bak" },
211 { "Bambara", "", "bm", "bam" },
212 { "Basque", "", "eu", "eus", "baq" },
213 { "Belarusian", "", "be", "bel" },
214 { "Bengali", "", "bn", "ben" },
215 { "Bihari", "", "bh", "bih" },
216 { "Bislama", "", "bi", "bis" },
217 { "Bosnian", "", "bs", "bos" },
218 { "Breton", "", "br", "bre" },
219 { "Bulgarian", "", "bg", "bul" },
220 { "Burmese", "", "my", "mya", "bur" },
221 { "Catalan", "", "ca", "cat" },
222 { "Chamorro", "", "ch", "cha" },
223 { "Chechen", "", "ce", "che" },
224 { "Chinese", "", "zh", "zho", "chi" },
225 { "Church Slavic", "", "cu", "chu" },
226 { "Chuvash", "", "cv", "chv" },
227 { "Cornish", "", "kw", "cor" },
228 { "Corsican", "", "co", "cos" },
229 { "Cree", "", "cr", "cre" },
230 { "Czech", "", "cs", "ces", "cze" },
231 { "Danish", "Dansk", "da", "dan" },
232 { "Divehi", "", "dv", "div" },
233 { "Dutch", "Nederlands", "nl", "nld", "dut" },
234 { "Dzongkha", "", "dz", "dzo" },
235 { "English", "English", "en", "eng" },
236 { "Esperanto", "", "eo", "epo" },
237 { "Estonian", "", "et", "est" },
238 { "Ewe", "", "ee", "ewe" },
239 { "Faroese", "", "fo", "fao" },
240 { "Fijian", "", "fj", "fij" },
241 { "Finnish", "Suomi", "fi", "fin" },
242 { "French", "Francais", "fr", "fra", "fre" },
243 { "Western Frisian", "", "fy", "fry" },
244 { "Fulah", "", "ff", "ful" },
245 { "Georgian", "", "ka", "kat", "geo" },
246 { "German", "Deutsch", "de", "deu", "ger" },
247 { "Gaelic (Scots)", "", "gd", "gla" },
248 { "Irish", "", "ga", "gle" },
249 { "Galician", "", "gl", "glg" },
250 { "Manx", "", "gv", "glv" },
251 { "Greek, Modern", "", "el", "ell", "gre" },
252 { "Guarani", "", "gn", "grn" },
253 { "Gujarati", "", "gu", "guj" },
254 { "Haitian", "", "ht", "hat" },
255 { "Hausa", "", "ha", "hau" },
256 { "Hebrew", "", "he", "heb" },
257 { "Herero", "", "hz", "her" },
258 { "Hindi", "", "hi", "hin" },
259 { "Hiri Motu", "", "ho", "hmo" },
260 { "Hungarian", "Magyar", "hu", "hun" },
261 { "Igbo", "", "ig", "ibo" },
262 { "Icelandic", "Islenska", "is", "isl", "ice" },
263 { "Ido", "", "io", "ido" },
264 { "Sichuan Yi", "", "ii", "iii" },
265 { "Inuktitut", "", "iu", "iku" },
266 { "Interlingue", "", "ie", "ile" },
267 { "Interlingua", "", "ia", "ina" },
268 { "Indonesian", "", "id", "ind" },
269 { "Inupiaq", "", "ik", "ipk" },
270 { "Italian", "Italiano", "it", "ita" },
271 { "Javanese", "", "jv", "jav" },
272 { "Japanese", "", "ja", "jpn" },
273 { "Kalaallisut", "", "kl", "kal" },
274 { "Kannada", "", "kn", "kan" },
275 { "Kashmiri", "", "ks", "kas" },
276 { "Kanuri", "", "kr", "kau" },
277 { "Kazakh", "", "kk", "kaz" },
278 { "Central Khmer", "", "km", "khm" },
279 { "Kikuyu", "", "ki", "kik" },
280 { "Kinyarwanda", "", "rw", "kin" },
281 { "Kirghiz", "", "ky", "kir" },
282 { "Komi", "", "kv", "kom" },
283 { "Kongo", "", "kg", "kon" },
284 { "Korean", "", "ko", "kor" },
285 { "Kuanyama", "", "kj", "kua" },
286 { "Kurdish", "", "ku", "kur" },
287 { "Lao", "", "lo", "lao" },
288 { "Latin", "", "la", "lat" },
289 { "Latvian", "", "lv", "lav" },
290 { "Limburgan", "", "li", "lim" },
291 { "Lingala", "", "ln", "lin" },
292 { "Lithuanian", "", "lt", "lit" },
293 { "Luxembourgish", "", "lb", "ltz" },
294 { "Luba-Katanga", "", "lu", "lub" },
295 { "Ganda", "", "lg", "lug" },
296 { "Macedonian", "", "mk", "mkd", "mac" },
297 { "Marshallese", "", "mh", "mah" },
298 { "Malayalam", "", "ml", "mal" },
299 { "Maori", "", "mi", "mri", "mao" },
300 { "Marathi", "", "mr", "mar" },
301 { "Malay", "", "ms", "msa", "msa" },
302 { "Malagasy", "", "mg", "mlg" },
303 { "Maltese", "", "mt", "mlt" },
304 { "Moldavian", "", "mo", "mol" },
305 { "Mongolian", "", "mn", "mon" },
306 { "Nauru", "", "na", "nau" },
307 { "Navajo", "", "nv", "nav" },
308 { "Ndebele, South", "", "nr", "nbl" },
309 { "Ndebele, North", "", "nd", "nde" },
310 { "Ndonga", "", "ng", "ndo" },
311 { "Nepali", "", "ne", "nep" },
312 { "Norwegian Nynorsk", "", "nn", "nno" },
313 { "Norwegian Bokmål", "", "nb", "nob" },
314 { "Norwegian", "Norsk", "no", "nor" },
315 { "Chichewa; Nyanja", "", "ny", "nya" },
316 { "Occitan", "", "oc", "oci" },
317 { "Ojibwa", "", "oj", "oji" },
318 { "Oriya", "", "or", "ori" },
319 { "Oromo", "", "om", "orm" },
320 { "Ossetian", "", "os", "oss" },
321 { "Panjabi", "", "pa", "pan" },
322 { "Persian", "", "fa", "fas", "per" },
323 { "Pali", "", "pi", "pli" },
324 { "Polish", "", "pl", "pol" },
325 { "Portuguese", "Portugues", "pt", "por" },
326 { "Pushto", "", "ps", "pus" },
327 { "Quechua", "", "qu", "que" },
328 { "Romansh", "", "rm", "roh" },
329 { "Romanian", "", "ro", "ron", "rum" },
330 { "Rundi", "", "rn", "run" },
331 { "Russian", "", "ru", "rus" },
332 { "Sango", "", "sg", "sag" },
333 { "Sanskrit", "", "sa", "san" },
334 { "Serbian", "", "sr", "srp", "scc" },
335 { "Croatian", "Hrvatski", "hr", "hrv", "scr" },
336 { "Sinhala", "", "si", "sin" },
337 { "Slovak", "", "sk", "slk", "slo" },
338 { "Slovenian", "", "sl", "slv" },
339 { "Northern Sami", "", "se", "sme" },
340 { "Samoan", "", "sm", "smo" },
341 { "Shona", "", "sn", "sna" },
342 { "Sindhi", "", "sd", "snd" },
343 { "Somali", "", "so", "som" },
344 { "Sotho, Southern", "", "st", "sot" },
345 { "Spanish", "Espanol", "es", "spa" },
346 { "Sardinian", "", "sc", "srd" },
347 { "Swati", "", "ss", "ssw" },
348 { "Sundanese", "", "su", "sun" },
349 { "Swahili", "", "sw", "swa" },
350 { "Swedish", "Svenska", "sv", "swe" },
351 { "Tahitian", "", "ty", "tah" },
352 { "Tamil", "", "ta", "tam" },
353 { "Tatar", "", "tt", "tat" },
354 { "Telugu", "", "te", "tel" },
355 { "Tajik", "", "tg", "tgk" },
356 { "Tagalog", "", "tl", "tgl" },
357 { "Thai", "", "th", "tha" },
358 { "Tibetan", "", "bo", "bod", "tib" },
359 { "Tigrinya", "", "ti", "tir" },
360 { "Tonga", "", "to", "ton" },
361 { "Tswana", "", "tn", "tsn" },
362 { "Tsonga", "", "ts", "tso" },
363 { "Turkmen", "", "tk", "tuk" },
364 { "Turkish", "", "tr", "tur" },
365 { "Twi", "", "tw", "twi" },
366 { "Uighur", "", "ug", "uig" },
367 { "Ukrainian", "", "uk", "ukr" },
368 { "Urdu", "", "ur", "urd" },
369 { "Uzbek", "", "uz", "uzb" },
370 { "Venda", "", "ve", "ven" },
371 { "Vietnamese", "", "vi", "vie" },
372 { "Volapük", "", "vo", "vol" },
373 { "Welsh", "", "cy", "cym", "wel" },
374 { "Walloon", "", "wa", "wln" },
375 { "Wolof", "", "wo", "wol" },
376 { "Xhosa", "", "xh", "xho" },
377 { "Yiddish", "", "yi", "yid" },
378 { "Yoruba", "", "yo", "yor" },
379 { "Zhuang", "", "za", "zha" },
380 { "Zulu", "", "zu", "zul" },
382 #define LANG_TABLE_SIZE (sizeof(language_table)/ sizeof(iso639_lang_t))
385 del_tree(const gchar *name, gboolean del_top)
389 if (g_file_test(name, G_FILE_TEST_IS_DIR))
391 GDir *gdir = g_dir_open(name, 0, NULL);
392 file = g_dir_read_name(gdir);
396 path = g_strdup_printf("%s/%s", name, file);
397 del_tree(path, TRUE);
399 file = g_dir_read_name(gdir);
418 ghb_vquality_range(signal_user_data_t *ud, gint *min, gint *max)
420 if (ghb_settings_get_boolean(ud->settings, "directqp"))
422 gint vcodec = ghb_settings_get_int(ud->settings, "video_codec");
423 // Only x264 and ffmpeg currently support direct qp/crf entry
424 if (vcodec == HB_VCODEC_X264)
429 else if (vcodec == HB_VCODEC_FFMPEG)
448 ghb_lookup_vrate(const GValue *vrate)
454 str = ghb_value_string(vrate);
455 for (ii = 0; ii < hb_video_rates_count; ii++)
457 if (strcmp(hb_video_rates[ii].string, str) == 0)
459 result = hb_video_rates[ii].rate;
463 // Default to "same as source"
468 ghb_lookup_vcodec(const GValue *vcodec)
472 gint result = HB_VCODEC_FFMPEG;
474 str = ghb_value_string(vcodec);
475 for (ii = 0; ii < vcodec_opts.count; ii++)
477 if (strcmp(vcodec_opts.map[ii].shortOpt, str) == 0)
479 result = vcodec_opts.map[ii].ivalue;
487 ghb_lookup_vcodec_option(const GValue *vcodec)
491 const gchar *result = "";
493 str = ghb_value_string(vcodec);
494 for (ii = 0; ii < vcodec_opts.count; ii++)
496 if (strcmp(vcodec_opts.map[ii].shortOpt, str) == 0)
498 result = vcodec_opts.map[ii].option;
506 ghb_lookup_container(const GValue *container)
512 str = ghb_value_string(container);
513 for (ii = 0; ii < container_opts.count; ii++)
515 if (strcmp(container_opts.map[ii].shortOpt, str) == 0)
517 result = container_opts.map[ii].ivalue;
525 ghb_lookup_container_option(const GValue *container)
529 const gchar *result = "";
531 str = ghb_value_string(container);
532 for (ii = 0; ii < container_opts.count; ii++)
534 if (strcmp(container_opts.map[ii].shortOpt, str) == 0)
536 result = container_opts.map[ii].option;
544 ghb_lookup_denoise(const GValue *denoise)
550 str = ghb_value_string(denoise);
551 for (ii = 0; ii < denoise_opts.count; ii++)
553 if (strcmp(denoise_opts.map[ii].shortOpt, str) == 0)
555 result = denoise_opts.map[ii].ivalue;
564 ghb_lookup_deint(const GValue *deint)
570 str = ghb_value_string(deint);
571 for (ii = 0; ii < deint_opts.count; ii++)
573 if (strcmp(deint_opts.map[ii].shortOpt, str) == 0)
575 result = deint_opts.map[ii].ivalue;
584 ghb_lookup_mux(const GValue *mux)
588 gint result = HB_MUX_MKV;
590 str = ghb_value_string(mux);
591 for (ii = 0; ii < container_opts.count; ii++)
593 if (strcmp(container_opts.map[ii].shortOpt, str) == 0)
595 result = container_opts.map[ii].ivalue;
603 ghb_lookup_acodec(const GValue *acodec)
607 gint result = HB_ACODEC_FAAC;
609 str = ghb_value_string(acodec);
610 for (ii = 0; ii < acodec_opts.count; ii++)
612 if (strcmp(acodec_opts.map[ii].shortOpt, str) == 0)
614 result = acodec_opts.map[ii].ivalue;
622 ghb_lookup_acodec_option(const GValue *acodec)
626 const gchar *result = "";
628 str = ghb_value_string(acodec);
629 for (ii = 0; ii < acodec_opts.count; ii++)
631 if (strcmp(acodec_opts.map[ii].shortOpt, str) == 0)
633 result = acodec_opts.map[ii].option;
641 ghb_lookup_mix_option(const GValue *mix)
645 gchar *result = "None";
648 str = ghb_value_string(mix);
649 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
651 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
653 result = hb_audio_mixdowns[ii].human_readable_name;
661 ghb_lookup_mix(const GValue *mix)
665 gint result = HB_AMIXDOWN_DOLBYPLII;
668 str = ghb_value_string(mix);
669 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
671 if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0)
673 result = hb_audio_mixdowns[ii].amixdown;
681 ghb_lookup_rate(const GValue *rate)
687 // Coincidentally, the string "source" will return 0
688 // which is our flag to use "same as source"
689 str = ghb_value_string(rate);
690 for (ii = 0; ii < hb_audio_rates_count; ii++)
692 if (strcmp(hb_audio_rates[ii].string, str) == 0)
694 result = hb_audio_rates[ii].rate;
703 ghb_lookup_bitrate(const gchar *bitrate)
707 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
709 if (strcmp(hb_audio_bitrates[ii].string, bitrate) == 0)
711 return hb_audio_bitrates[ii].rate;
718 ghb_lookup_drc(const gchar *drc)
721 dval = g_strtod(drc, NULL);
722 if (dval < 1.0) dval = 1.0;
723 if (dval > 4.0) dval = 4.0;
729 get_acodec_value(gint val)
731 GValue *value = NULL;
734 for (ii = 0; ii < acodec_opts.count; ii++)
736 if (acodec_opts.map[ii].ivalue == val)
738 value = ghb_combo_value_new(
740 acodec_opts.map[ii].option,
741 acodec_opts.map[ii].shortOpt,
742 acodec_opts.map[ii].svalue,
743 acodec_opts.map[ii].ivalue);
751 get_abitrate_value(gint val)
753 GValue *value = NULL;
756 for (ii = 0; ii < hb_audio_bitrates_count; ii++)
758 if (hb_audio_bitrates[ii].rate == val)
760 value = ghb_combo_value_new(
762 hb_audio_bitrates[ii].string,
763 hb_audio_bitrates[ii].string,
764 hb_audio_bitrates[ii].string,
765 hb_audio_bitrates[ii].rate);
773 get_amix_value(gint val)
775 GValue *value = NULL;
778 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
780 if (hb_audio_mixdowns[ii].amixdown == val)
782 value = ghb_combo_value_new(
784 hb_audio_mixdowns[ii].human_readable_name,
785 hb_audio_mixdowns[ii].short_name,
786 hb_audio_mixdowns[ii].internal_name,
787 hb_audio_mixdowns[ii].amixdown);
794 // Handle for libhb. Gets set by ghb_backend_init()
795 static hb_handle_t * h_scan = NULL;
796 static hb_handle_t * h_queue = NULL;
798 extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
801 ghb_hb_cleanup(gboolean partial)
805 hb_get_tempory_directory(h_scan, dir);
806 del_tree(dir, !partial);
810 ghb_get_title_number(gint titleindex)
815 if (h_scan == NULL) return 1;
816 list = hb_get_titles( h_scan );
817 if( !hb_list_count( list ) )
819 /* No valid title, stop right there */
822 title = hb_list_item( list, titleindex );
823 if (title == NULL) return 1; // Bad titleindex
827 static hb_audio_config_t*
828 get_hb_audio(gint titleindex, gint track)
832 hb_audio_config_t *audio = NULL;
834 if (h_scan == NULL) return NULL;
835 list = hb_get_titles( h_scan );
836 if( !hb_list_count( list ) )
838 /* No valid title, stop right there */
841 title = hb_list_item( list, titleindex );
842 if (title == NULL) return NULL; // Bad titleindex
843 if (!hb_list_count(title->list_audio))
847 audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
852 search_rates(hb_rate_t *rates, gint rate, gint count)
855 for (ii = 0; ii < count; ii++)
857 if (rates[ii].rate == rate)
863 static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
866 get_combo_box_store(GtkBuilder *builder, const gchar *name)
871 g_debug("get_combo_box_store() %s\n", name);
872 // First modify the combobox model to allow greying out of options
873 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
874 store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
879 grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
884 store = get_combo_box_store(builder, name);
885 if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
887 gtk_list_store_set(store, &iter,
894 ghb_grey_combo_options(GtkBuilder *builder)
897 gint container, track, titleindex, acodec;
899 hb_audio_config_t *audio = NULL;
901 widget = GHB_WIDGET (builder, "title");
902 titleindex = ghb_widget_int(widget);
903 widget = GHB_WIDGET (builder, "audio_track");
904 track = ghb_widget_int(widget);
905 audio = get_hb_audio(titleindex, track);
906 widget = GHB_WIDGET (builder, "container");
907 container = ghb_widget_int(widget);
908 widget = GHB_WIDGET (builder, "http_optimize_mp4");
909 httpopt = ghb_widget_int(widget);
911 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_FAAC, FALSE);
912 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_LAME, FALSE);
913 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_VORBIS, FALSE);
915 gboolean allow_ac3 = TRUE;
917 !(container == HB_MUX_MP4 && httpopt) &&
918 (container != HB_MUX_OGM);
922 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_AC3, FALSE);
926 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_AC3, TRUE);
928 if (audio && audio->in.codec != HB_ACODEC_AC3)
930 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_AC3, TRUE);
932 grey_combo_box_item(builder, "video_codec", HB_VCODEC_THEORA, FALSE);
934 widget = GHB_WIDGET (builder, "audio_codec");
935 acodec = ghb_widget_int(widget);
936 if (acodec != HB_ACODEC_AC3)
938 grey_combo_box_item(builder, "audio_mix", 0, TRUE);
940 if (container == HB_MUX_MP4)
942 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_LAME, TRUE);
943 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_VORBIS, TRUE);
944 grey_combo_box_item(builder, "video_codec", HB_VCODEC_THEORA, TRUE);
946 else if (container == HB_MUX_AVI)
948 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_FAAC, TRUE);
949 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_VORBIS, TRUE);
950 grey_combo_box_item(builder, "video_codec", HB_VCODEC_THEORA, TRUE);
952 else if (container == HB_MUX_OGM)
954 grey_combo_box_item(builder, "audio_codec", HB_ACODEC_FAAC, TRUE);
957 gboolean allow_mono = TRUE;
958 gboolean allow_stereo = TRUE;
959 gboolean allow_dolby = TRUE;
960 gboolean allow_dpl2 = TRUE;
961 gboolean allow_6ch = TRUE;
965 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
966 (acodec != HB_ACODEC_LAME);
967 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
969 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
971 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
972 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
973 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
974 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
976 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
977 (acodec != HB_ACODEC_LAME) &&
978 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
979 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
981 grey_combo_box_item(builder, "audio_mix", HB_AMIXDOWN_MONO, !allow_mono);
982 grey_combo_box_item(builder, "audio_mix", HB_AMIXDOWN_STEREO, !allow_stereo);
983 grey_combo_box_item(builder, "audio_mix", HB_AMIXDOWN_DOLBY, !allow_dolby);
984 grey_combo_box_item(builder, "audio_mix", HB_AMIXDOWN_DOLBYPLII, !allow_dpl2);
985 grey_combo_box_item(builder, "audio_mix", HB_AMIXDOWN_6CH, !allow_6ch);
989 ghb_get_best_mix(gint titleindex, gint track, gint acodec, gint mix)
991 hb_audio_config_t *audio = NULL;
992 gboolean allow_mono = TRUE;
993 gboolean allow_stereo = TRUE;
994 gboolean allow_dolby = TRUE;
995 gboolean allow_dpl2 = TRUE;
996 gboolean allow_6ch = TRUE;
998 if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))
1000 // Audio codec pass-thru. No mixdown
1003 audio = get_hb_audio(titleindex, track);
1007 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1008 (acodec != HB_ACODEC_LAME);
1009 gint layout = audio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
1011 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
1013 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
1014 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
1015 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
1016 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
1018 (audio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
1019 (acodec != HB_ACODEC_LAME) &&
1020 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
1021 (audio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
1023 gboolean greater = FALSE;
1026 // If no mix is specified, select the best available.
1027 mix = HB_AMIXDOWN_6CH;
1029 if (mix == HB_AMIXDOWN_6CH)
1032 if (allow_6ch) return HB_AMIXDOWN_6CH;
1034 if (mix == HB_AMIXDOWN_DOLBYPLII || greater)
1037 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1039 if (mix == HB_AMIXDOWN_DOLBY || greater)
1042 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1044 if (mix == HB_AMIXDOWN_STEREO || greater)
1047 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1049 if (mix == HB_AMIXDOWN_MONO || greater)
1052 if (allow_mono) return HB_AMIXDOWN_MONO;
1054 if (allow_stereo) return HB_AMIXDOWN_STEREO;
1055 if (allow_dolby) return HB_AMIXDOWN_DOLBY;
1056 if (allow_dpl2) return HB_AMIXDOWN_DOLBYPLII;
1057 if (allow_6ch) return HB_AMIXDOWN_6CH;
1061 // Set up the model for the combo box
1063 init_combo_box(GtkBuilder *builder, const gchar *name)
1066 GtkListStore *store;
1067 GtkCellRenderer *cell;
1069 g_debug("init_combo_box() %s\n", name);
1070 // First modify the combobox model to allow greying out of options
1071 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1073 // 1 - String to display
1074 // 2 - bool indicating whether the entry is selectable (grey or not)
1075 // 3 - String that is used for presets
1076 // 4 - Int value determined by backend
1077 // 5 - String value determined by backend
1078 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1079 G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1080 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1082 gtk_cell_layout_clear(GTK_CELL_LAYOUT(combo));
1083 cell = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());
1084 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
1085 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell,
1086 "text", 0, "sensitive", 1, NULL);
1089 // Set up the model for the combo box
1091 init_combo_box_entry(GtkBuilder *builder, const gchar *name)
1094 GtkListStore *store;
1096 g_debug("init_combo_box_entry() %s\n", name);
1097 // First modify the combobox model to allow greying out of options
1098 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1100 // 1 - String to display
1101 // 2 - bool indicating whether the entry is selectable (grey or not)
1102 // 3 - String that is used for presets
1103 // 4 - Int value determined by backend
1104 // 5 - String value determined by backend
1105 store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_BOOLEAN,
1106 G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1107 gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
1108 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
1112 audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1115 GtkListStore *store;
1118 g_debug("audio_bitrate_opts_set ()\n");
1119 store = get_combo_box_store(builder, name);
1120 gtk_list_store_clear(store);
1121 for (ii = 0; ii < count; ii++)
1123 gtk_list_store_append(store, &iter);
1124 gtk_list_store_set(store, &iter,
1125 0, rates[ii].string,
1127 2, rates[ii].string,
1129 4, rates[ii].string,
1135 audio_bitrate_opts_clean(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1138 GtkListStore *store;
1140 gboolean done = FALSE;
1141 gboolean changed = FALSE;
1143 g_debug("audio_bitrate_opts_clean ()\n");
1144 store = get_combo_box_store(builder, name);
1145 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter))
1149 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 3, &ivalue, -1);
1150 if (search_rates(rates, ivalue, count) < 0)
1152 done = !gtk_list_store_remove(store, &iter);
1157 done = !gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
1165 audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1168 GtkListStore *store;
1171 g_debug("audio_samplerate_opts_set ()\n");
1172 store = get_combo_box_store(builder, name);
1173 gtk_list_store_clear(store);
1174 // Add an item for "Same As Source"
1175 gtk_list_store_append(store, &iter);
1176 gtk_list_store_set(store, &iter,
1177 0, "Same as source",
1183 for (ii = 0; ii < count; ii++)
1185 gtk_list_store_append(store, &iter);
1186 gtk_list_store_set(store, &iter,
1187 0, rates[ii].string,
1189 2, rates[ii].string,
1191 4, rates[ii].string,
1197 video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count)
1200 GtkListStore *store;
1203 g_debug("video_rate_opts_set ()\n");
1204 store = get_combo_box_store(builder, name);
1205 gtk_list_store_clear(store);
1206 // Add an item for "Same As Source"
1207 gtk_list_store_append(store, &iter);
1208 gtk_list_store_set(store, &iter,
1209 0, "Same as source",
1215 for (ii = 0; ii < count; ii++)
1219 if (strcmp(rates[ii].string, "23.976") == 0)
1221 desc = "(NTSC Film)";
1223 else if (strcmp(rates[ii].string, "25") == 0)
1225 desc = "(PAL Film/Video)";
1227 else if (strcmp(rates[ii].string, "29.97") == 0)
1229 desc = "(NTSC Video)";
1231 option = g_strdup_printf ("%s %s", rates[ii].string, desc);
1232 gtk_list_store_append(store, &iter);
1233 gtk_list_store_set(store, &iter,
1236 2, rates[ii].string,
1238 4, rates[ii].string,
1245 mix_opts_set(GtkBuilder *builder, const gchar *name)
1248 GtkListStore *store;
1251 g_debug("mix_opts_set ()\n");
1252 store = get_combo_box_store(builder, name);
1253 gtk_list_store_clear(store);
1254 gtk_list_store_append(store, &iter);
1255 gtk_list_store_set(store, &iter,
1262 for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
1264 gtk_list_store_append(store, &iter);
1265 gtk_list_store_set(store, &iter,
1266 0, hb_audio_mixdowns[ii].human_readable_name,
1268 2, hb_audio_mixdowns[ii].short_name,
1269 3, hb_audio_mixdowns[ii].amixdown,
1270 4, hb_audio_mixdowns[ii].internal_name,
1276 language_opts_set(GtkBuilder *builder, const gchar *name)
1279 GtkListStore *store;
1282 g_debug("language_opts_set ()\n");
1283 store = get_combo_box_store(builder, name);
1284 gtk_list_store_clear(store);
1285 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1287 gtk_list_store_append(store, &iter);
1288 gtk_list_store_set(store, &iter,
1289 0, language_table[ii].eng_name,
1291 2, language_table[ii].iso639_2,
1293 4, language_table[ii].iso639_1,
1299 title_opts_set(GtkBuilder *builder, const gchar *name)
1302 GtkListStore *store;
1308 g_debug("title_opts_set ()\n");
1309 store = get_combo_box_store(builder, name);
1310 gtk_list_store_clear(store);
1313 list = hb_get_titles( h_scan );
1314 count = hb_list_count( list );
1315 if (count > 100) count = 100;
1319 // No titles. Fill in a default.
1320 gtk_list_store_append(store, &iter);
1321 gtk_list_store_set(store, &iter,
1330 for (ii = 0; ii < count; ii++)
1334 title = (hb_title_t*)hb_list_item(list, ii);
1335 if (title->duration != 0)
1337 option = g_strdup_printf ("%d - %02dh%02dm%02ds",
1338 title->index, title->hours, title->minutes, title->seconds);
1342 option = g_strdup_printf ("%d - Unknown Length", title->index);
1344 gtk_list_store_append(store, &iter);
1345 gtk_list_store_set(store, &iter,
1357 find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter)
1360 gboolean foundit = FALSE;
1362 if (gtk_tree_model_get_iter_first (store, iter))
1366 gtk_tree_model_get(store, iter, 3, &ivalue, -1);
1367 if (value == ivalue)
1372 } while (gtk_tree_model_iter_next (store, iter));
1378 audio_rate_opts_add(GtkBuilder *builder, const gchar *name, gint rate)
1381 GtkListStore *store;
1384 g_debug("audio_rate_opts_add ()\n");
1385 store = get_combo_box_store(builder, name);
1386 if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter))
1388 str = g_strdup_printf ("%d", rate);
1389 gtk_list_store_append(store, &iter);
1390 gtk_list_store_set(store, &iter,
1404 audio_track_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1407 GtkListStore *store;
1410 hb_audio_config_t * audio;
1414 g_debug("audio_track_opts_set ()\n");
1415 store = get_combo_box_store(builder, name);
1416 gtk_list_store_clear(store);
1419 list = hb_get_titles( h_scan );
1420 title = (hb_title_t*)hb_list_item( list, titleindex );
1423 count = hb_list_count( title->list_audio );
1426 if (count > 10) count = 10;
1429 // No audio. set some default
1430 gtk_list_store_append(store, &iter);
1431 gtk_list_store_set(store, &iter,
1440 for (ii = 0; ii < count; ii++)
1444 audio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, ii );
1445 gtk_list_store_append(store, &iter);
1446 str = g_strdup_printf("%d", ii);
1447 gtk_list_store_set(store, &iter,
1448 0, audio->lang.description,
1459 subtitle_opts_set(GtkBuilder *builder, const gchar *name, gint titleindex)
1462 GtkListStore *store;
1465 hb_subtitle_t * subtitle;
1469 g_debug("subtitle_opts_set ()\n");
1470 store = get_combo_box_store(builder, name);
1471 gtk_list_store_clear(store);
1474 list = hb_get_titles( h_scan );
1475 title = (hb_title_t*)hb_list_item( list, titleindex );
1478 count = hb_list_count( title->list_subtitle );
1481 if (count > 10) count = 10;
1482 // Add options for "none" and "autoselect"
1483 gtk_list_store_append(store, &iter);
1484 gtk_list_store_set(store, &iter,
1491 gtk_list_store_append(store, &iter);
1492 gtk_list_store_set(store, &iter,
1499 for (ii = 0; ii < count; ii++)
1501 subtitle = (hb_subtitle_t *) hb_list_item( title->list_subtitle, ii );
1502 gtk_list_store_append(store, &iter);
1503 gtk_list_store_set(store, &iter,
1506 2, subtitle->iso639_2,
1508 4, subtitle->iso639_2,
1511 if (titleindex == -1)
1513 for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
1515 gtk_list_store_append(store, &iter);
1516 gtk_list_store_set(store, &iter,
1517 0, language_table[ii].eng_name,
1519 2, language_table[ii].iso639_2,
1521 4, language_table[ii].iso639_2,
1534 guint64 longest = 0;
1535 gint titleindex = 0;
1537 g_debug("ghb_longest_title ()\n");
1538 if (h_scan == NULL) return 0;
1539 list = hb_get_titles( h_scan );
1540 count = hb_list_count( list );
1541 if (count > 100) count = 100;
1542 for (ii = 0; ii < count; ii++)
1544 title = (hb_title_t*)hb_list_item(list, ii);
1545 if (title->duration > longest)
1548 longest = title->duration;
1555 ghb_find_audio_track(gint titleindex, const gchar *lang, gint index)
1559 hb_audio_config_t * audio;
1565 g_debug("find_audio_track ()\n");
1568 list = hb_get_titles( h_scan );
1569 title = (hb_title_t*)hb_list_item( list, titleindex );
1572 count = hb_list_count( title->list_audio );
1575 if (count > 10) count = 10;
1576 for (ii = 0; ii < count; ii++)
1578 audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii );
1579 if ((strcmp(lang, audio->lang.iso639_2) == 0) ||
1580 (strcmp(lang, "und") == 0))
1594 generic_opts_set(GtkBuilder *builder, const gchar *name, combo_opts_t *opts)
1597 GtkListStore *store;
1600 g_debug("generic_opts_set ()\n");
1601 store = get_combo_box_store(builder, name);
1602 gtk_list_store_clear(store);
1603 for (ii = 0; ii < opts->count; ii++)
1605 gtk_list_store_append(store, &iter);
1606 gtk_list_store_set(store, &iter,
1607 0, opts->map[ii].option,
1609 2, opts->map[ii].shortOpt,
1610 3, opts->map[ii].ivalue,
1611 4, opts->map[ii].svalue,
1617 ghb_update_ui_combo_box(GtkBuilder *builder, const gchar *name, gint user_data, gboolean all)
1619 GtkComboBox *combo = NULL;
1621 gint handler_id = 0;
1623 g_debug("ghb_update_ui_combo_box() %s\n", name);
1626 // Clearing a combo box causes a rash of "changed" events, even when
1627 // the active item is -1 (inactive). To control things, I'm disabling
1628 // the event till things are settled down.
1629 combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
1630 signal_id = g_signal_lookup("changed", GTK_TYPE_COMBO_BOX);
1633 // Valid signal id found. This should always succeed.
1634 handler_id = g_signal_handler_find ((gpointer)combo, G_SIGNAL_MATCH_ID,
1635 signal_id, 0, 0, 0, 0);
1638 // This should also always succeed
1639 g_signal_handler_block ((gpointer)combo, handler_id);
1643 if (all || strcmp(name, "audio_bitrate") == 0)
1644 audio_bitrate_opts_set(builder, "audio_bitrate", hb_audio_bitrates, hb_audio_bitrates_count);
1645 if (all || strcmp(name, "audio_rate") == 0)
1646 audio_samplerate_opts_set(builder, "audio_rate", hb_audio_rates, hb_audio_rates_count);
1647 if (all || strcmp(name, "framerate") == 0)
1648 video_rate_opts_set(builder, "framerate", hb_video_rates, hb_video_rates_count);
1649 if (all || strcmp(name, "audio_mix") == 0)
1650 mix_opts_set(builder, "audio_mix");
1651 if (all || strcmp(name, "source_audio_lang") == 0)
1652 language_opts_set(builder, "source_audio_lang");
1653 if (all || strcmp(name, "subtitle_lang") == 0)
1654 subtitle_opts_set(builder, "subtitle_lang", user_data);
1655 if (all || strcmp(name, "title") == 0)
1656 title_opts_set(builder, "title");
1657 if (all || strcmp(name, "audio_track") == 0)
1658 audio_track_opts_set(builder, "audio_track", user_data);
1659 if (all || strcmp(name, "container") == 0)
1660 generic_opts_set(builder, "container", &container_opts);
1661 if (all || strcmp(name, "deinterlace") == 0)
1662 generic_opts_set(builder, "deinterlace", &deint_opts);
1663 if (all || strcmp(name, "tweak_deinterlace") == 0)
1664 generic_opts_set(builder, "tweak_deinterlace", &deint_opts);
1665 if (all || strcmp(name, "denoise") == 0)
1666 generic_opts_set(builder, "denoise", &denoise_opts);
1667 if (all || strcmp(name, "tweak_denoise") == 0)
1668 generic_opts_set(builder, "tweak_denoise", &denoise_opts);
1669 if (all || strcmp(name, "video_codec") == 0)
1670 generic_opts_set(builder, "video_codec", &vcodec_opts);
1671 if (all || strcmp(name, "audio_codec") == 0)
1672 generic_opts_set(builder, "audio_codec", &acodec_opts);
1673 if (all || strcmp(name, "x264_direct") == 0)
1674 generic_opts_set(builder, "x264_direct", &direct_opts);
1675 if (all || strcmp(name, "x264_me") == 0)
1676 generic_opts_set(builder, "x264_me", &me_opts);
1677 if (all || strcmp(name, "x264_subme") == 0)
1678 generic_opts_set(builder, "x264_subme", &subme_opts);
1679 if (all || strcmp(name, "x264_analyse") == 0)
1680 generic_opts_set(builder, "x264_analyse", &analyse_opts);
1681 if (all || strcmp(name, "x264_trellis") == 0)
1682 generic_opts_set(builder, "x264_trellis", &trellis_opts);
1685 g_signal_handler_unblock ((gpointer)combo, handler_id);
1690 init_ui_combo_boxes(GtkBuilder *builder)
1692 init_combo_box(builder, "audio_bitrate");
1693 init_combo_box(builder, "audio_rate");
1694 init_combo_box(builder, "framerate");
1695 init_combo_box(builder, "audio_mix");
1696 init_combo_box(builder, "source_audio_lang");
1697 init_combo_box(builder, "subtitle_lang");
1698 init_combo_box(builder, "title");
1699 init_combo_box(builder, "audio_track");
1700 init_combo_box(builder, "container");
1701 init_combo_box(builder, "deinterlace");
1702 init_combo_box_entry(builder, "tweak_deinterlace");
1703 init_combo_box(builder, "denoise");
1704 init_combo_box_entry(builder, "tweak_denoise");
1705 init_combo_box(builder, "video_codec");
1706 init_combo_box(builder, "audio_codec");
1707 init_combo_box(builder, "x264_direct");
1708 init_combo_box(builder, "x264_me");
1709 init_combo_box(builder, "x264_subme");
1710 init_combo_box(builder, "x264_analyse");
1711 init_combo_box(builder, "x264_trellis");
1714 static const char * turbo_opts =
1715 "ref=1:subme=1:me=dia:analyse=none:trellis=0:"
1716 "no-fast-pskip=0:8x8dct=0:weightb=0";
1718 // Construct the x264 options string
1719 // The result is allocated, so someone must free it at some point.
1721 ghb_build_x264opts_string(GValue *settings)
1724 gchar *opts = ghb_settings_get_string(settings, "x264_options");
1731 result = g_strdup("");
1737 ghb_get_chapters(gint titleindex)
1741 hb_chapter_t * chapter;
1743 GValue *chapters = NULL;
1745 g_debug("ghb_get_chapters (title = %d)\n", titleindex);
1746 if (h_scan == NULL) return NULL;
1747 list = hb_get_titles( h_scan );
1748 title = (hb_title_t*)hb_list_item( list, titleindex );
1749 if (title == NULL) return NULL;
1750 count = hb_list_count( title->list_chapter );
1751 chapters = ghb_array_value_new(count);
1752 for (ii = 0; ii < count; ii++)
1754 chapter = hb_list_item(title->list_chapter, ii);
1755 if (chapter == NULL) break;
1756 if (chapter->title == NULL || chapter->title[0] == 0)
1759 str = g_strdup_printf ("Chapter %2d", ii+1);
1760 ghb_array_append(chapters, ghb_string_value_new(str));
1765 ghb_array_append(chapters, ghb_string_value_new(chapter->title));
1772 ghb_ac3_in_audio_list(const GValue *audio_list)
1776 count = ghb_array_len(audio_list);
1777 for (ii = 0; ii < count; ii++)
1782 asettings = ghb_array_get_nth(audio_list, ii);
1783 acodec = ghb_settings_get_int(asettings, "audio_codec");
1784 if (acodec == HB_ACODEC_AC3)
1791 ghb_set_passthru_rate_opts(GtkBuilder *builder, gint bitrate)
1793 gboolean changed = FALSE;
1794 changed = audio_rate_opts_add(builder, "audio_bitrate", bitrate);
1799 ghb_set_default_rate_opts(GtkBuilder *builder)
1801 gboolean changed = FALSE;
1802 changed = audio_bitrate_opts_clean(builder, "audio_bitrate", hb_audio_bitrates, hb_audio_bitrates_count);
1806 static ghb_status_t hb_status;
1809 ghb_backend_init(GtkBuilder *builder, gint debug, gint update)
1812 h_scan = hb_init( debug, update );
1813 h_queue = hb_init( debug, 0 );
1814 // Set up the list model for the combos
1815 init_ui_combo_boxes(builder);
1816 // Populate all the combos
1817 ghb_update_ui_combo_box(builder, NULL, 0, TRUE);
1828 ghb_backend_scan(const gchar *path, gint titleindex)
1830 hb_scan( h_scan, path, titleindex );
1831 hb_status.state |= GHB_STATE_SCANNING;
1832 // initialize count and cur to something that won't cause FPE
1833 // when computing progress
1834 hb_status.title_count = 1;
1835 hb_status.title_cur = 0;
1839 ghb_backend_queue_scan(const gchar *path, gint titlenum)
1841 g_debug("ghb_backend_queue_scan()");
1842 hb_scan( h_queue, path, titlenum );
1843 hb_status.queue_state |= GHB_STATE_SCANNING;
1849 return hb_status.state;
1853 ghb_get_queue_state()
1855 return hb_status.queue_state;
1859 ghb_clear_state(gint state)
1861 hb_status.state &= ~state;
1865 ghb_clear_queue_state(gint state)
1867 hb_status.queue_state &= ~state;
1871 ghb_set_state(gint state)
1873 hb_status.state |= state;
1877 ghb_set_queue_state(gint state)
1879 hb_status.queue_state |= state;
1883 ghb_get_status(ghb_status_t *status)
1885 memcpy(status, &hb_status, sizeof(ghb_status_t));
1894 if (h_scan == NULL) return;
1895 hb_get_state( h_scan, &s );
1898 #define p s.param.scanning
1899 case HB_STATE_SCANNING:
1901 hb_status.state |= GHB_STATE_SCANNING;
1902 hb_status.title_count = p.title_count;
1903 hb_status.title_cur = p.title_cur;
1907 case HB_STATE_SCANDONE:
1909 hb_status.state &= ~GHB_STATE_SCANNING;
1910 hb_status.state |= GHB_STATE_SCANDONE;
1914 hb_get_state( h_queue, &s_queue );
1915 switch( s_queue.state )
1917 case HB_STATE_SCANNING:
1919 hb_status.queue_state |= GHB_STATE_SCANNING;
1922 case HB_STATE_SCANDONE:
1924 hb_status.queue_state &= ~GHB_STATE_SCANNING;
1925 hb_status.queue_state |= GHB_STATE_SCANDONE;
1928 #define p s_queue.param.working
1929 case HB_STATE_WORKING:
1930 hb_status.queue_state |= GHB_STATE_WORKING;
1931 hb_status.queue_state &= ~GHB_STATE_PAUSED;
1932 hb_status.job_cur = p.job_cur;
1933 hb_status.job_count = p.job_count;
1934 hb_status.progress = p.progress;
1935 hb_status.rate_cur = p.rate_cur;
1936 hb_status.rate_avg = p.rate_avg;
1937 hb_status.hours = p.hours;
1938 hb_status.minutes = p.minutes;
1939 hb_status.seconds = p.seconds;
1940 hb_status.unique_id = p.sequence_id & 0xFFFFFF;
1944 case HB_STATE_PAUSED:
1945 hb_status.queue_state |= GHB_STATE_PAUSED;
1948 case HB_STATE_MUXING:
1950 hb_status.queue_state |= GHB_STATE_MUXING;
1953 #define p s_queue.param.workdone
1954 case HB_STATE_WORKDONE:
1958 hb_status.queue_state |= GHB_STATE_WORKDONE;
1959 hb_status.queue_state &= ~GHB_STATE_MUXING;
1960 hb_status.queue_state &= ~GHB_STATE_PAUSED;
1961 hb_status.queue_state &= ~GHB_STATE_WORKING;
1965 hb_status.error = GHB_ERROR_NONE;
1966 case HB_ERROR_CANCELED:
1967 hb_status.error = GHB_ERROR_CANCELED;
1969 hb_status.error = GHB_ERROR_FAIL;
1971 hb_status.error = p.error;
1972 // Delete all remaining jobs of this encode.
1973 // An encode can be composed of multiple associated jobs.
1974 // When a job is stopped, libhb removes it from the job list,
1975 // but does not remove other jobs that may be associated with it.
1976 // Associated jobs are taged in the sequence id.
1977 while ((job = hb_job(h_queue, 0)) != NULL)
1978 hb_rem( h_queue, job );
1985 ghb_get_title_info(ghb_title_info_t *tinfo, gint titleindex)
1990 if (h_scan == NULL) return FALSE;
1991 list = hb_get_titles( h_scan );
1992 if( !hb_list_count( list ) )
1994 /* No valid title, stop right there */
1998 title = hb_list_item( list, titleindex );
1999 if (title == NULL) return FALSE; // Bad titleindex
2000 tinfo->width = title->width;
2001 tinfo->height = title->height;
2002 memcpy(tinfo->crop, title->crop, 4 * sizeof(int));
2003 // Don't allow crop to 0
2004 if (title->crop[0] + title->crop[1] >= title->height)
2005 title->crop[0] = title->crop[1] = 0;
2006 if (title->crop[2] + title->crop[3] >= title->width)
2007 title->crop[2] = title->crop[3] = 0;
2008 tinfo->num_chapters = hb_list_count(title->list_chapter);
2009 tinfo->rate_base = title->rate_base;
2010 tinfo->rate = title->rate;
2011 hb_reduce(&(tinfo->aspect_n), &(tinfo->aspect_d),
2012 title->width * title->pixel_aspect_width,
2013 title->height * title->pixel_aspect_height);
2014 tinfo->hours = title->hours;
2015 tinfo->minutes = title->minutes;
2016 tinfo->seconds = title->seconds;
2017 tinfo->duration = title->duration;
2022 ghb_get_audio_info(ghb_audio_info_t *ainfo, gint titleindex, gint audioindex)
2024 hb_audio_config_t *audio;
2026 audio = get_hb_audio(titleindex, audioindex);
2027 if (audio == NULL) return FALSE; // Bad audioindex
2028 ainfo->codec = audio->in.codec;
2029 ainfo->bitrate = audio->in.bitrate;
2030 ainfo->samplerate = audio->in.samplerate;
2035 ghb_audio_is_passthru(gint acodec)
2037 g_debug("ghb_audio_is_passthru () \n");
2038 g_debug("acodec %d\n", acodec);
2039 return (acodec == HB_ACODEC_AC3);
2043 ghb_get_default_acodec()
2045 return HB_ACODEC_FAAC;
2049 ghb_set_scale(signal_user_data_t *ud, gint mode)
2054 gboolean keep_aspect, round_dims, anamorphic;
2055 gboolean autocrop, autoscale, noscale;
2056 gint crop[4], width, height, par_width, par_height;
2057 gint crop_width, crop_height;
2058 gint aspect_n, aspect_d;
2059 gboolean keep_width = (mode == GHB_SCALE_KEEP_WIDTH);
2060 gboolean keep_height = (mode == GHB_SCALE_KEEP_HEIGHT);
2066 gint max_height = 0;
2068 g_debug("ghb_set_scale ()\n");
2070 if (h_scan == NULL) return;
2071 list = hb_get_titles( h_scan );
2072 if( !hb_list_count( list ) )
2074 /* No valid title, stop right there */
2077 gint titleindex = ghb_settings_get_int(ud->settings, "title");
2078 title = hb_list_item( list, titleindex );
2079 if (title == NULL) return;
2081 if (job == NULL) return;
2083 // First configure widgets
2084 round_dims = ghb_settings_get_boolean(ud->settings, "round_dimensions");
2085 anamorphic = ghb_settings_get_boolean(ud->settings, "anamorphic");
2086 keep_aspect = ghb_settings_get_boolean(ud->settings, "keep_aspect");
2087 autocrop = ghb_settings_get_boolean(ud->settings, "autocrop");
2088 autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
2089 // "Noscale" is a flag that says we prefer to crop extra to satisfy
2090 // alignment constraints rather than scaling to satisfy them.
2091 noscale = ghb_settings_get_boolean(ud->settings, "noscale");
2092 // Align dimensions to either 16 or 2 pixels
2093 // The scaler crashes if the dimensions are not divisible by 2
2094 // x264 also will not accept dims that are not multiple of 2
2095 modshift = round_dims ? 4 : 1;
2096 modround = round_dims ? 8 : 1;
2100 keep_height = FALSE;
2102 if (anamorphic || keep_aspect)
2104 keep_height = FALSE;
2106 // Step needs to be at least 2 because odd widths cause scaler crash
2107 step = round_dims ? 16 : 2;
2108 widget = GHB_WIDGET (ud->builder, "scale_width");
2109 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2110 widget = GHB_WIDGET (ud->builder, "scale_height");
2111 gtk_spin_button_set_increments (GTK_SPIN_BUTTON(widget), step, 16);
2114 ghb_title_info_t tinfo;
2116 if (ghb_get_title_info (&tinfo, titleindex))
2118 crop[0] = tinfo.crop[0];
2119 crop[1] = tinfo.crop[1];
2120 crop[2] = tinfo.crop[2];
2121 crop[3] = tinfo.crop[3];
2126 // Adjust the cropping to accomplish the desired width and height
2127 crop_width = tinfo.width - crop[2] - crop[3];
2128 crop_height = tinfo.height - crop[0] - crop[1];
2129 width = (crop_width >> modshift) << modshift;
2130 height = (crop_height >> modshift) << modshift;
2131 need1 = (crop_height - height) / 2;
2132 need2 = crop_height - height - need1;
2135 need1 = (crop_width - width) / 2;
2136 need2 = crop_width - width - need1;
2140 ghb_ui_update(ud, "crop_top", ghb_int64_value(crop[0]));
2141 ghb_ui_update(ud, "crop_bottom", ghb_int64_value(crop[1]));
2142 ghb_ui_update(ud, "crop_left", ghb_int64_value(crop[2]));
2143 ghb_ui_update(ud, "crop_right", ghb_int64_value(crop[3]));
2146 crop[0] = ghb_settings_get_int(ud->settings, "crop_top");
2147 crop[1] = ghb_settings_get_int(ud->settings, "crop_bottom");
2148 crop[2] = ghb_settings_get_int(ud->settings, "crop_left");
2149 crop[3] = ghb_settings_get_int(ud->settings, "crop_right");
2150 hb_reduce(&aspect_n, &aspect_d,
2151 title->width * title->pixel_aspect_width,
2152 title->height * title->pixel_aspect_height);
2153 crop_width = title->width - crop[2] - crop[3];
2154 crop_height = title->height - crop[0] - crop[1];
2158 height = crop_height;
2159 max_width = crop_width;
2160 max_height = crop_height;
2164 width = ghb_settings_get_int(ud->settings, "scale_width");
2165 height = ghb_settings_get_int(ud->settings, "scale_height");
2166 max_width = ghb_settings_get_int(ud->settings, "max_width");
2167 max_height = ghb_settings_get_int(ud->settings, "max_width");
2169 max_width = (max_width >> modshift) << modshift;
2170 max_height = (max_height >> modshift) << modshift;
2171 // Adjust dims according to max values
2174 max_height = crop_height;
2178 max_width = crop_width;
2180 height = MIN(height, max_height);
2181 width = MIN(width, max_width);
2182 g_debug("max_width %d, max_height %d\n", max_width, max_height);
2185 width = title->width - crop[2] - crop[3];
2187 height = title->height - crop[0] - crop[1];
2197 // The scaler crashes if the dimensions are not divisible by 2
2198 // Align mod 2. And so does something in x264_encoder_headers()
2203 job->maxHeight = max_height;
2204 job->crop[0] = crop[0]; job->crop[1] = crop[1];
2205 job->crop[2] = crop[2]; job->crop[3] = crop[3];
2206 hb_set_anamorphic_size( job, &width, &height, &par_width, &par_height );
2213 gint new_width, new_height;
2215 g_debug("kw %s kh %s\n", keep_width ? "y":"n", keep_height ? "y":"n");
2216 g_debug("w %d h %d\n", width, height);
2217 // Compute pixel aspect ration.
2218 par = (gdouble)(title->height * aspect_n) / (title->width * aspect_d);
2219 // Must scale so that par becomes 1:1
2220 // Try to keep largest dimension
2221 new_height = (crop_height * ((gdouble)width/crop_width) / par);
2222 new_width = (crop_width * ((gdouble)height/crop_height) * par);
2223 // Height and width are always multiples of 2, so do the rounding
2224 new_height = ((new_height + 1) >> 1) << 1;
2225 new_width = ((new_width + 1) >> 1) << 1;
2226 g_debug("max w %d, new w %d\n", max_width, new_width);
2227 if (max_width && (new_width > max_width))
2229 height = new_height;
2231 else if (max_height && (new_height > max_height))
2235 else if (keep_width)
2237 height = new_height;
2239 else if (keep_height)
2243 else if (width > new_width)
2245 height = new_height;
2251 g_debug("new w %d h %d\n", width, height);
2253 width = ((width + modround) >> modshift) << modshift;
2254 height = ((height + modround) >> modshift) << modshift;
2256 ghb_ui_update(ud, "scale_width", ghb_int64_value(width));
2257 ghb_ui_update(ud, "scale_height", ghb_int64_value(height));
2261 set_preview_job_settings(hb_job_t *job, GValue *settings)
2263 job->crop[0] = ghb_settings_get_int(settings, "crop_top");
2264 job->crop[1] = ghb_settings_get_int(settings, "crop_bottom");
2265 job->crop[2] = ghb_settings_get_int(settings, "crop_left");
2266 job->crop[3] = ghb_settings_get_int(settings, "crop_right");
2268 gboolean anamorphic, round_dimensions;
2269 anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
2270 round_dimensions = ghb_settings_get_boolean(settings, "round_dimensions");
2271 if (round_dimensions && anamorphic)
2274 job->pixel_ratio = 2;
2276 else if (anamorphic)
2279 job->pixel_ratio = 2;
2284 job->pixel_ratio = 0;
2286 job->width = ghb_settings_get_int(settings, "scale_width");
2287 job->height = ghb_settings_get_int(settings, "scale_height");
2288 gint deint = ghb_settings_get_int(settings, "deinterlace");
2289 gboolean decomb = ghb_settings_get_boolean(settings, "decomb");
2290 job->deinterlace = (!decomb && deint == 0) ? 0 : 1;
2294 ghb_calculate_target_bitrate(GValue *settings, gint titleindex)
2301 if (h_scan == NULL) return 2000;
2302 list = hb_get_titles( h_scan );
2303 title = hb_list_item( list, titleindex );
2304 if (title == NULL) return 2000;
2306 if (job == NULL) return 2000;
2307 size = ghb_settings_get_int(settings, "video_target_size");
2308 return hb_calc_bitrate( job, size );
2312 ghb_guess_bitrate(GValue *settings)
2315 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
2317 // This is really rough. I'm trying to err on the high
2318 // side since this is used to estimate if there is
2319 // sufficient disk space left
2323 vcodec = ghb_settings_get_int(settings, "video_codec");
2324 vquality = ghb_settings_get_double(settings, "video_quality")/100;
2325 if (vcodec == HB_VCODEC_X264 &&
2326 !ghb_settings_get_boolean(settings, "linear_vquality"))
2328 vquality = 51.0 - vquality * 51.0;
2329 // Convert log curve to linear
2330 vquality = exp2((vquality-12)/6);
2331 // Don't let it go to 0
2332 if (vquality >= 31) vquality = 30;
2333 vquality = (31 - vquality) / 31;
2335 // bitrate seems to be a log relasionship to quality
2336 // with typical source material
2337 // This is a real wag
2338 bitrate = 20*1024*1024*exp10(vquality*14)/exp10(14);
2339 // Add some bits for audio
2340 bitrate += 500*1024;
2344 // Add some fudge to the bitrate to leave breathing room
2345 bitrate = ghb_settings_get_int(settings, "video_bitrate")*1024;
2346 // Add some bits for audio
2347 bitrate += 500*1024;
2353 ghb_validate_filter_string(const gchar *str, gint max_fields)
2359 if (str == NULL || *str == 0) return TRUE;
2362 val = g_strtod(str, &end);
2364 { // Found a numeric value
2366 // negative max_fields means infinate
2367 if (max_fields >= 0 && fields > max_fields) return FALSE;
2381 ghb_validate_filters(signal_user_data_t *ud)
2389 tweaks = ghb_settings_get_boolean(ud->settings, "allow_tweaks");
2393 str = ghb_settings_get_string(ud->settings, "tweak_detelecine");
2394 enabled = ghb_settings_get_boolean(ud->settings, "detelecine");
2395 if (enabled && !ghb_validate_filter_string(str, 6))
2397 message = g_strdup_printf(
2398 "Invalid Detelecine Settings:\n\n%s\n",
2400 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2407 str = ghb_settings_get_string(ud->settings, "tweak_decomb");
2408 enabled = ghb_settings_get_boolean(ud->settings, "decomb");
2409 if (enabled && !ghb_validate_filter_string(str, 7))
2411 message = g_strdup_printf(
2412 "Invalid Decomb Settings:\n\n%s\n",
2414 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2421 index = ghb_settings_get_combo_index(ud->settings, "tweak_deinterlace");
2424 str = ghb_settings_get_string(ud->settings, "tweak_deinterlace");
2425 if (!ghb_validate_filter_string(str, 4))
2427 message = g_strdup_printf(
2428 "Invalid Deinterlace Settings:\n\n%s\n",
2430 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2438 // Deblock is being reworked
2440 str = ghb_settings_get_string(ud->settings, "tweak_deblock");
2441 enabled = ghb_settings_get_boolean(ud->settings, "deblock");
2442 if (enabled && !ghb_validate_filter_string(str, 2))
2444 message = g_strdup_printf(
2445 "Invalid Deblock Settings:\n\n%s\n",
2447 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2455 index = ghb_settings_get_combo_index(ud->settings, "tweak_denoise");
2458 str = ghb_settings_get_string(ud->settings, "tweak_denoise");
2459 if (!ghb_validate_filter_string(str, 4))
2461 message = g_strdup_printf(
2462 "Invalid Denoise Settings:\n\n%s\n",
2464 ghb_message_dialog(GTK_MESSAGE_ERROR, message, "Cancel", NULL);
2476 ghb_validate_video(signal_user_data_t *ud)
2481 mux = ghb_settings_get_int(ud->settings, "container");
2482 vcodec = ghb_settings_get_int(ud->settings, "video_codec");
2483 if ((mux == HB_MUX_MP4 || mux == HB_MUX_AVI) &&
2484 (vcodec == HB_VCODEC_THEORA))
2486 // mp4|avi/theora combination is not supported.
2487 message = g_strdup_printf(
2488 "Theora is not supported in the MP4 and AVI containers.\n\n"
2489 "You should choose a different video codec or container.\n"
2490 "If you continue, XviD will be chosen for you.");
2491 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2497 vcodec = HB_VCODEC_XVID;
2498 ghb_ui_update(ud, "video_codec", ghb_int64_value(vcodec));
2502 decomb = ghb_settings_get_boolean(ud->settings, "decomb");
2503 vfr = ghb_settings_get_boolean(ud->settings, "variable_frame_rate");
2506 message = g_strdup_printf(
2507 "Decomb is intended to be used in conjunction\n"
2508 "with variable frame rate.\n\n"
2509 "Would you like me to enable VFR for you?");
2510 if (ghb_message_dialog(GTK_MESSAGE_WARNING, message, "No", "Yes"))
2512 ghb_ui_update(ud, "variable_frame_rate", ghb_boolean_value(TRUE));
2520 ghb_validate_container(signal_user_data_t *ud)
2525 container = ghb_settings_get_int(ud->settings, "container");
2526 if (container == HB_MUX_MP4)
2528 const GValue *audio_list;
2531 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2532 httpopt = ghb_settings_get_boolean(ud->settings, "http_optimize_mp4");
2533 if (httpopt && ghb_ac3_in_audio_list(audio_list))
2535 message = g_strdup_printf(
2536 "AC3 audio in HTTP optimized MP4 is not supported.\n\n"
2537 "You should choose a different audio codec.\n"
2538 "If you continue, FAAC will be chosen for you.");
2539 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2548 count = ghb_array_len(audio_list);
2549 for (ii = 0; ii < count; ii++)
2553 asettings = ghb_array_get_nth(audio_list, ii);
2554 gint acodec = ghb_settings_get_int(asettings, "audio_codec");
2555 if (acodec == HB_ACODEC_AC3)
2558 value = get_acodec_value(HB_ACODEC_FAAC);
2559 ghb_settings_take_value(asettings, "audio_codec", value);
2560 value = get_abitrate_value(160);
2561 ghb_settings_take_value(asettings, "audio_bitrate", value);
2570 ghb_validate_audio(signal_user_data_t *ud)
2577 if (h_scan == NULL) return FALSE;
2578 list = hb_get_titles( h_scan );
2579 if( !hb_list_count( list ) )
2581 /* No valid title, stop right there */
2582 g_message("No title found.\n");
2586 gint titleindex = ghb_settings_get_int(ud->settings, "title");
2587 title = hb_list_item( list, titleindex );
2588 if (title == NULL) return FALSE;
2589 gint mux = ghb_settings_get_int(ud->settings, "container");
2591 const GValue *audio_list;
2594 audio_list = ghb_settings_get_value(ud->settings, "audio_list");
2595 count = ghb_array_len(audio_list);
2596 for (ii = 0; ii < count; ii++)
2599 hb_audio_config_t *taudio;
2601 asettings = ghb_array_get_nth(audio_list, ii);
2602 gint track = ghb_settings_get_int(asettings, "audio_track");
2603 gint codec = ghb_settings_get_int(asettings, "audio_codec");
2604 taudio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, track );
2605 if ((taudio->in.codec != HB_ACODEC_AC3) && (codec == HB_ACODEC_AC3))
2607 // Not supported. AC3 is passthrough only, so input must be AC3
2608 message = g_strdup_printf(
2609 "The source does not support AC3 Pass-Thru.\n\n"
2610 "You should choose a different audio codec.\n"
2611 "If you continue, one will be chosen for you.");
2612 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2618 if (mux == HB_MUX_AVI)
2620 codec = HB_ACODEC_LAME;
2624 codec = HB_ACODEC_FAAC;
2626 value = get_acodec_value(codec);
2627 ghb_settings_take_value(asettings, "audio_codec", value);
2629 gchar *a_unsup = NULL;
2630 gchar *mux_s = NULL;
2631 if (mux == HB_MUX_MP4)
2634 // mp4/mp3|vorbis combination is not supported.
2635 if (codec == HB_ACODEC_LAME)
2638 codec = HB_ACODEC_FAAC;
2640 if (codec == HB_ACODEC_VORBIS)
2643 codec = HB_ACODEC_FAAC;
2646 else if (mux == HB_MUX_AVI)
2649 // avi/faac|vorbis combination is not supported.
2650 if (codec == HB_ACODEC_FAAC)
2653 codec = HB_ACODEC_LAME;
2655 if (codec == HB_ACODEC_VORBIS)
2658 codec = HB_ACODEC_LAME;
2661 else if (mux == HB_MUX_OGM)
2664 // avi/faac|vorbis combination is not supported.
2665 if (codec == HB_ACODEC_FAAC)
2668 codec = HB_ACODEC_VORBIS;
2670 if (codec == HB_ACODEC_AC3)
2673 codec = HB_ACODEC_VORBIS;
2678 message = g_strdup_printf(
2679 "%s is not supported in the %s container.\n\n"
2680 "You should choose a different audio codec.\n"
2681 "If you continue, one will be chosen for you.", a_unsup, mux_s);
2682 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2688 value = get_acodec_value(codec);
2689 ghb_settings_take_value(asettings, "audio_codec", value);
2691 gint mix = ghb_settings_get_int (asettings, "audio_mix");
2692 gboolean allow_mono = TRUE;
2693 gboolean allow_stereo = TRUE;
2694 gboolean allow_dolby = TRUE;
2695 gboolean allow_dpl2 = TRUE;
2696 gboolean allow_6ch = TRUE;
2698 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2699 (codec != HB_ACODEC_LAME);
2700 gint layout = taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK;
2702 ((layout == HB_INPUT_CH_LAYOUT_MONO && !allow_mono) || layout >= HB_INPUT_CH_LAYOUT_STEREO);
2704 (layout == HB_INPUT_CH_LAYOUT_3F1R) ||
2705 (layout == HB_INPUT_CH_LAYOUT_3F2R) ||
2706 (layout == HB_INPUT_CH_LAYOUT_DOLBY);
2707 allow_dpl2 = (layout == HB_INPUT_CH_LAYOUT_3F2R);
2709 (taudio->in.codec & (HB_ACODEC_AC3|HB_ACODEC_DCA)) &&
2710 (codec != HB_ACODEC_LAME) &&
2711 (layout == HB_INPUT_CH_LAYOUT_3F2R) &&
2712 (taudio->in.channel_layout & HB_INPUT_CH_LAYOUT_HAS_LFE);
2714 gchar *mix_unsup = NULL;
2715 if (mix == HB_AMIXDOWN_MONO && !allow_mono)
2719 if (mix == HB_AMIXDOWN_STEREO && !allow_stereo)
2721 mix_unsup = "stereo";
2723 if (mix == HB_AMIXDOWN_DOLBY && !allow_dolby)
2725 mix_unsup = "Dolby";
2727 if (mix == HB_AMIXDOWN_DOLBYPLII && !allow_dpl2)
2729 mix_unsup = "Dolby Pro Logic II";
2731 if (mix == HB_AMIXDOWN_6CH && !allow_6ch)
2733 mix_unsup = "6 Channel";
2737 message = g_strdup_printf(
2738 "The source audio does not support %s mixdown.\n\n"
2739 "You should choose a different mixdown.\n"
2740 "If you continue, one will be chosen for you.", mix_unsup);
2741 if (!ghb_message_dialog(GTK_MESSAGE_WARNING, message, "Cancel", "Continue"))
2747 mix = ghb_get_best_mix(titleindex, track, codec, mix);
2748 value = get_amix_value(mix);
2749 ghb_settings_take_value(asettings, "audio_mix", value);
2756 ghb_validate_vquality(GValue *settings)
2762 if (ghb_settings_get_boolean(settings, "nocheckvquality")) return TRUE;
2763 vcodec = ghb_settings_get_int(settings, "video_codec");
2764 if (ghb_settings_get_boolean(settings, "vquality_type_constant"))
2766 if (!ghb_settings_get_boolean(settings, "directqp"))
2768 if (vcodec != HB_VCODEC_X264 ||
2769 ghb_settings_get_boolean(settings, "linear_vquality"))
2774 else if (vcodec == HB_VCODEC_X264)
2782 if (vcodec == HB_VCODEC_X264)
2787 else if (vcodec == HB_VCODEC_FFMPEG)
2798 gint vquality = ghb_settings_get_double(settings, "video_quality");
2799 if (vquality < min || vquality > max)
2801 message = g_strdup_printf(
2802 "Interesting video quality choise: %d\n\n"
2803 "Typical values range from %d to %d.\n"
2804 "Are you sure you wish to use this setting?",
2805 vquality, min, max);
2806 if (!ghb_message_dialog(GTK_MESSAGE_QUESTION, message,
2807 "Cancel", "Continue"))
2819 ghb_add_job(GValue *js, gint unique_id)
2824 static gchar *x264opts;
2826 gboolean tweaks = FALSE;
2827 gchar *detel_str = NULL;
2828 gchar *decomb_str = NULL;
2829 gchar *deint_str = NULL;
2830 gchar *deblock_str = NULL;
2831 gchar *denoise_str = NULL;
2832 gchar *dest_str = NULL;
2834 g_debug("ghb_add_job()\n");
2835 if (h_queue == NULL) return;
2836 list = hb_get_titles( h_queue );
2837 if( !hb_list_count( list ) )
2839 /* No valid title, stop right there */
2840 g_message("No title found.\n");
2844 // Since I'm doing a scan of the single title I want just prior
2845 // to adding the job, there is only the one title to choose from.
2846 //gint titleindex = ghb_settings_get_int(js, "title");
2847 gint titleindex = 0;
2848 title = hb_list_item( list, titleindex );
2849 if (title == NULL) return;
2851 /* Set job settings */
2853 if (job == NULL) return;
2855 tweaks = ghb_settings_get_boolean(js, "allow_tweaks");
2856 job->mux = ghb_lookup_mux(ghb_settings_get_value(js, "container"));
2857 if (job->mux == HB_MUX_MP4)
2859 job->largeFileSize = ghb_settings_get_boolean(js, "large_mp4");
2860 job->mp4_optimize = ghb_settings_get_boolean(js, "http_optimize_mp4");
2864 job->largeFileSize = FALSE;
2865 job->mp4_optimize = FALSE;
2867 gint chapter_start, chapter_end;
2868 chapter_start = ghb_settings_get_int(js, "start_chapter");
2869 chapter_end = ghb_settings_get_int(js, "end_chapter");
2870 gint num_chapters = hb_list_count(title->list_chapter);
2871 job->chapter_start = MIN( num_chapters, chapter_start );
2872 job->chapter_end = MAX( job->chapter_start, chapter_end );
2874 job->chapter_markers = ghb_settings_get_boolean(js, "chapter_markers");
2875 if ( job->chapter_markers )
2882 chapters = ghb_settings_get_value(js, "chapter_list");
2883 count = ghb_array_len(chapters);
2884 for(chap = chapter_start; chap <= chapter_end; chap++)
2886 hb_chapter_t * chapter_s;
2892 chapter = ghb_array_get_nth(chapters, chap-1);
2893 name = ghb_value_string(chapter);
2897 name = g_strdup_printf ("Chapter %2d", chap);
2899 chapter_s = hb_list_item( job->title->list_chapter, chap - 1);
2900 strncpy(chapter_s->title, name, 1023);
2901 chapter_s->title[1023] = '\0';
2905 job->crop[0] = ghb_settings_get_int(js, "crop_top");
2906 job->crop[1] = ghb_settings_get_int(js, "crop_bottom");
2907 job->crop[2] = ghb_settings_get_int(js, "crop_left");
2908 job->crop[3] = ghb_settings_get_int(js, "crop_right");
2911 gboolean decomb = ghb_settings_get_boolean(js, "decomb");
2912 gint deint = ghb_lookup_deint(
2913 ghb_settings_get_value(js, tweaks ? "tweak_deinterlace":"deinterlace"));
2915 job->deinterlace = (deint != 0) ? 1 : 0;
2917 job->deinterlace = 0;
2918 job->grayscale = ghb_settings_get_boolean(js, "grayscale");
2920 gboolean anamorphic = ghb_settings_get_boolean(js, "anamorphic");
2921 gboolean round_dimensions = ghb_settings_get_boolean(js, "round_dimensions");
2922 if (round_dimensions && anamorphic)
2924 job->pixel_ratio = 2;
2927 else if (anamorphic)
2929 // Huh! I thought I wanted to use pixel_ratio 1 for this case, but
2930 // when its 1, libhb discards the width and height and uses original
2931 // title dims - crop. Thats not what I want.
2932 // Also, x264 requires things to divisible by 2.
2933 job->pixel_ratio = 2;
2938 job->pixel_ratio = 0;
2941 job->vfr = ghb_settings_get_boolean(js, "variable_frame_rate");
2942 /* Add selected filters */
2943 job->filters = hb_list_init();
2944 if( ghb_settings_get_boolean(js, "detelecine" ) || job->vfr )
2946 hb_filter_detelecine.settings = NULL;
2949 detel_str = ghb_settings_get_string(js, "tweak_detelecine");
2950 if (detel_str && detel_str[0])
2952 hb_filter_detelecine.settings = detel_str;
2955 hb_list_add( job->filters, &hb_filter_detelecine );
2959 // Use default settings
2960 hb_filter_decomb.settings = NULL;
2963 decomb_str = ghb_settings_get_string(js, "tweak_decomb");
2964 if (decomb_str && decomb_str[0])
2966 hb_filter_decomb.settings = (gchar*)decomb_str;
2969 hb_list_add( job->filters, &hb_filter_decomb );
2971 if( job->deinterlace )
2974 deint_str = g_strdup(deint_opts.map[deint].svalue);
2976 deint_str = ghb_settings_get_string(js,
2977 tweaks ? "tweak_deinterlace" : "deinterlace");
2978 hb_filter_deinterlace.settings = deint_str;
2979 hb_list_add( job->filters, &hb_filter_deinterlace );
2981 gint deblock = ghb_settings_get_int(js, "deblock");
2984 deblock_str = g_strdup_printf("%d", deblock);
2985 hb_filter_deblock.settings = deblock_str;
2986 hb_list_add( job->filters, &hb_filter_deblock );
2988 gint denoise = ghb_lookup_denoise(
2989 ghb_settings_get_value(js, tweaks ? "tweak_denoise" : "denoise"));
2993 denoise_str = g_strdup(denoise_opts.map[denoise].svalue);
2995 denoise_str = (gchar*)ghb_settings_get_string(
2996 js, tweaks ? "tweak_denoise" : "denoise");
2997 hb_filter_denoise.settings = denoise_str;
2998 hb_list_add( job->filters, &hb_filter_denoise );
3000 job->width = ghb_settings_get_int(js, "scale_width");
3001 job->height = ghb_settings_get_int(js, "scale_height");
3003 job->vcodec = ghb_lookup_vcodec(ghb_settings_get_value(js, "video_codec"));
3004 if ((job->mux == HB_MUX_MP4 || job->mux == HB_MUX_AVI) &&
3005 (job->vcodec == HB_VCODEC_THEORA))
3007 // mp4|avi/theora combination is not supported.
3008 job->vcodec = HB_VCODEC_XVID;
3010 if ((job->vcodec == HB_VCODEC_X264) && (job->mux == HB_MUX_MP4))
3012 job->ipod_atom = ghb_settings_get_boolean(js, "ipod_file");
3014 if (ghb_settings_get_boolean(js, "vquality_type_constant"))
3017 vquality = ghb_settings_get_double(js, "video_quality");
3018 if (!ghb_settings_get_boolean(js, "directqp"))
3021 if (ghb_settings_get_boolean(js, "linear_vquality"))
3023 if (job->vcodec == HB_VCODEC_X264)
3025 // Adjust to same range as xvid and ffmpeg
3026 vquality = 31.0 - vquality * 31.0;
3029 // Convert linear to log curve
3030 vquality = 12 + 6 * log2(vquality);
3031 if (vquality > 51) vquality = 51;
3032 if (vquality < 1) vquality = 1;
3040 if (vquality == 0.0) vquality = 0.01;
3041 if (vquality == 1.0) vquality = 0.0;
3044 job->vquality = vquality;
3047 else if (ghb_settings_get_boolean(js, "vquality_type_bitrate"))
3049 job->vquality = -1.0;
3050 job->vbitrate = ghb_settings_get_int(js, "video_bitrate");
3052 // AVI container does not support variable frame rate.
3053 if (job->mux == HB_MUX_AVI)
3058 gint vrate = ghb_lookup_vrate(ghb_settings_get_value(js, "framerate"));
3059 if( vrate == 0 || job->vfr )
3061 job->vrate = title->rate;
3062 job->vrate_base = title->rate_base;
3067 job->vrate = 27000000;
3068 job->vrate_base = vrate;
3071 // First remove any audios that are already in the list
3072 // This happens if you are encoding the same title a second time.
3073 gint num_audio_tracks = hb_list_count(job->list_audio);
3075 for(ii = 0; ii < num_audio_tracks; ii++)
3077 hb_audio_t *audio = (hb_audio_t*)hb_list_item(job->list_audio, 0);
3078 hb_list_rem(job->list_audio, audio);
3081 const GValue *audio_list;
3085 audio_list = ghb_settings_get_value(js, "audio_list");
3086 count = ghb_array_len(audio_list);
3087 for (ii = 0; ii < count; ii++)
3090 hb_audio_config_t audio;
3091 hb_audio_config_t *taudio;
3093 hb_audio_config_init(&audio);
3094 asettings = ghb_array_get_nth(audio_list, ii);
3095 audio.in.track = ghb_settings_get_int(asettings, "audio_track");
3096 audio.out.track = tcount;
3097 audio.out.codec = ghb_lookup_acodec(
3098 ghb_settings_get_value(asettings, "audio_codec"));
3099 taudio = (hb_audio_config_t *) hb_list_audio_config_item( title->list_audio, audio.in.track );
3100 if ((taudio->in.codec != HB_ACODEC_AC3) && (audio.out.codec == HB_ACODEC_AC3))
3102 // Not supported. AC3 is passthrough only, so input must be AC3
3103 if (job->mux == HB_MUX_AVI)
3105 audio.out.codec = HB_ACODEC_LAME;
3109 audio.out.codec = HB_ACODEC_FAAC;
3112 if ((job->mux == HB_MUX_MP4) &&
3113 ((audio.out.codec == HB_ACODEC_LAME) ||
3114 (audio.out.codec == HB_ACODEC_VORBIS)))
3116 // mp4/mp3|vorbis combination is not supported.
3117 audio.out.codec = HB_ACODEC_FAAC;
3119 if ((job->mux == HB_MUX_AVI) &&
3120 ((audio.out.codec == HB_ACODEC_FAAC) ||
3121 (audio.out.codec == HB_ACODEC_VORBIS)))
3123 // avi/faac|vorbis combination is not supported.
3124 audio.out.codec = HB_ACODEC_LAME;
3126 if ((job->mux == HB_MUX_OGM) &&
3127 ((audio.out.codec == HB_ACODEC_FAAC) ||
3128 (audio.out.codec == HB_ACODEC_AC3)))
3130 // ogm/faac|ac3 combination is not supported.
3131 audio.out.codec = HB_ACODEC_VORBIS;
3133 audio.out.dynamic_range_compression =
3134 ghb_settings_get_double(asettings, "audio_drc");
3135 // It would be better if this were done in libhb for us, but its not yet.
3136 if (audio.out.codec == HB_ACODEC_AC3 || audio.out.codec == HB_ACODEC_DCA)
3138 audio.out.mixdown = 0;
3142 audio.out.mixdown = ghb_lookup_mix(
3143 ghb_settings_get_value (asettings, "audio_mix"));
3144 // Make sure the mixdown is valid and pick a new one if not.
3145 audio.out.mixdown = ghb_get_best_mix(titleindex,
3146 audio.in.track, audio.out.codec, audio.out.mixdown);
3148 ghb_settings_get_int(asettings, "audio_bitrate");
3149 gint srate = ghb_lookup_rate(
3150 ghb_settings_get_value(asettings, "audio_rate"));
3151 if (srate == 0) // 0 is same as source
3152 audio.out.samplerate = taudio->in.samplerate;
3154 audio.out.samplerate = srate;
3157 // Add it to the jobs audio list
3158 hb_audio_add( job, &audio );
3161 // I was tempted to move this up with the reset of the video quality
3162 // settings, but I suspect the settings above need to be made
3163 // first in order for hb_calc_bitrate to be accurate.
3164 if (ghb_settings_get_boolean(js, "vquality_type_target"))
3168 size = ghb_settings_get_int(js, "video_target_size");
3169 job->vbitrate = hb_calc_bitrate( job, size );
3170 job->vquality = -1.0;
3173 dest_str = ghb_settings_get_string(js, "destination");
3174 job->file = dest_str;
3175 job->crf = ghb_settings_get_boolean(js, "constant_rate_factor");
3176 // TODO: libhb holds onto a reference to the x264opts and is not
3177 // finished with it until encoding the job is done. But I can't
3178 // find a way to get at the job before it is removed in order to
3179 // free up the memory I am allocating here.
3180 // The short story is THIS LEAKS.
3181 x264opts = ghb_build_x264opts_string(js);
3183 if( x264opts != NULL && *x264opts != '\0' )
3185 job->x264opts = x264opts;
3187 else /*avoids a bus error crash when options aren't specified*/
3189 job->x264opts = NULL;
3192 gchar *slang = ghb_settings_get_string(js, "subtitle_lang");
3193 subtitle = -2; // default to none
3194 if (strcmp(slang, "auto") == 0)
3201 hb_subtitle_t * subt;
3203 scount = hb_list_count(title->list_subtitle);
3204 for (ii = 0; ii < scount; ii++)
3206 subt = (hb_subtitle_t *)hb_list_item(title->list_subtitle, ii);
3207 if (strcmp(slang, subt->iso639_2) == 0)
3214 gboolean forced_subtitles = ghb_settings_get_boolean(js, "forced_subtitles");
3215 job->subtitle_force = forced_subtitles;
3217 job->subtitle = subtitle;
3222 // Subtitle scan. Look for subtitle matching audio language
3226 * When subtitle scan is enabled do a fast pre-scan job
3227 * which will determine which subtitles to enable, if any.
3230 job->indepth_scan = 1;
3232 x264opts_tmp = job->x264opts;
3233 job->x264opts = NULL;
3235 job->select_subtitle = malloc(sizeof(hb_subtitle_t*));
3236 *(job->select_subtitle) = NULL;
3239 * Add the pre-scan job
3241 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3242 hb_add( h_queue, job );
3243 //if (job->x264opts != NULL)
3244 // g_free(job->x264opts);
3246 job->x264opts = x264opts_tmp;
3250 job->select_subtitle = NULL;
3252 if( ghb_settings_get_boolean(js, "two_pass") &&
3253 !ghb_settings_get_boolean(js, "vquality_type_constant"))
3256 * If subtitle_scan is enabled then only turn it on
3257 * for the second pass and then off again for the
3260 hb_subtitle_t **subtitle_tmp = job->select_subtitle;
3261 job->select_subtitle = NULL;
3263 job->indepth_scan = 0;
3264 gchar *x264opts2 = NULL;
3267 x264opts2 = g_strdup(x264opts);
3270 * If turbo options have been selected then append them
3271 * to the x264opts now (size includes one ':' and the '\0')
3273 if( ghb_settings_get_boolean(js, "turbo") )
3279 tmp_x264opts = g_strdup_printf("%s:%s", x264opts, turbo_opts);
3285 * No x264opts to modify, but apply the turbo options
3286 * anyway as they may be modifying defaults
3288 tmp_x264opts = g_strdup_printf("%s", turbo_opts);
3290 x264opts = tmp_x264opts;
3292 job->x264opts = x264opts;
3294 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3295 hb_add( h_queue, job );
3296 //if (job->x264opts != NULL)
3297 // g_free(job->x264opts);
3299 job->select_subtitle = subtitle_tmp;
3302 * On the second pass we turn off subtitle scan so that we
3303 * can actually encode using any subtitles that were auto
3304 * selected in the first pass (using the whacky select-subtitle
3305 * attribute of the job).
3307 job->indepth_scan = 0;
3308 job->x264opts = x264opts2;
3309 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3310 hb_add( h_queue, job );
3311 //if (job->x264opts != NULL)
3312 // g_free(job->x264opts);
3316 job->indepth_scan = 0;
3318 job->sequence_id = (unique_id & 0xFFFFFF) | (sub_id++ << 24);
3319 hb_add( h_queue, job );
3320 //if (job->x264opts != NULL)
3321 // g_free(job->x264opts);
3323 if (detel_str) g_free(detel_str);
3324 if (decomb_str) g_free(decomb_str);
3325 if (deint_str) g_free(deint_str);
3326 if (deblock_str) g_free(deblock_str);
3327 if (denoise_str) g_free(denoise_str);
3328 if (dest_str) g_free(dest_str);
3332 ghb_remove_job(gint unique_id)
3337 // Multiples passes all get the same id
3339 // Go backwards through list, so reordering doesn't screw me.
3340 ii = hb_count(h_queue) - 1;
3341 while ((job = hb_job(h_queue, ii--)) != NULL)
3343 if ((job->sequence_id & 0xFFFFFF) == unique_id)
3344 hb_rem(h_queue, job);
3351 hb_start( h_queue );
3364 hb_get_state2( h_queue, &s );
3366 if( s.state == HB_STATE_PAUSED )
3368 hb_resume( h_queue );
3372 hb_pause( h_queue );
3377 ghb_get_preview_image(
3386 list = hb_get_titles( h_scan );
3387 if( !hb_list_count( list ) )
3389 /* No valid title, stop right there */
3392 title = hb_list_item( list, titleindex );
3393 if (title == NULL) return NULL;
3394 if (title->job == NULL) return NULL;
3395 set_preview_job_settings(title->job, settings);
3397 // hb_get_preview can't handle sizes that are larger than the original title
3399 if (title->job->width > title->width)
3400 title->job->width = title->width;
3402 if (title->job->height > title->height)
3403 title->job->height = title->height;
3404 // And also creates artifacts if the width is not a multiple of 8
3405 //title->job->width = ((title->job->width + 4) >> 3) << 3;
3406 // And the height must be a multiple of 2
3407 //title->job->height = ((title->job->height + 1) >> 1) << 1;
3409 // Make sure we have a big enough buffer to receive the image from libhb. libhb
3410 // creates images with a one-pixel border around the original content. Hence we
3411 // add 2 pixels horizontally and vertically to the buffer size.
3412 gint srcWidth = title->width + 2;
3413 gint srcHeight= title->height + 2;
3414 gint dstWidth = title->width;
3415 gint dstHeight= title->height;
3417 gint borderLeft = 1;
3420 // |<---------- title->width ----------->|
3421 // | |<---- title->job->width ---->| |
3423 // .......................................
3424 // ....+-----------------------------+....
3425 // ....| |....<-- gray border
3428 // ....| |<------- image
3434 // ....+-----------------------------+....
3435 // .......................................
3436 dstWidth = title->job->width;
3437 dstHeight = title->job->height;
3438 borderTop = (srcHeight - dstHeight) / 2;
3439 borderLeft = (srcWidth - dstWidth) / 2;
3440 g_debug("boarders removed\n");
3443 g_debug("src %d x %d\n", srcWidth, srcHeight);
3444 g_debug("dst %d x %d\n", dstWidth, dstHeight);
3445 g_debug("job dim %d x %d\n", title->job->width, title->job->height);
3446 g_debug("title crop %d:%d:%d:%d\n",
3451 g_debug("job crop %d:%d:%d:%d\n",
3452 title->job->crop[0],
3453 title->job->crop[1],
3454 title->job->crop[2],
3455 title->job->crop[3]);
3456 static guint8 *buffer = NULL;
3457 static gint bufferSize = 0;
3460 newSize = srcWidth * srcHeight * 4;
3461 if( bufferSize < newSize )
3463 bufferSize = newSize;
3464 buffer = (guint8*) g_realloc( buffer, bufferSize );
3466 hb_get_preview( h_scan, title, index, buffer );
3468 // Create an GdkPixbuf and copy the libhb image into it, converting it from
3469 // libhb's format something suitable. Along the way, we'll strip off the
3470 // border around libhb's image.
3472 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
3473 // Alpha is ignored.
3475 GdkPixbuf *preview = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, dstWidth, dstHeight);
3476 guint8 *pixels = gdk_pixbuf_get_pixels (preview);
3478 guint32 *src = (guint32*)buffer;
3479 guint8 *dst = pixels;
3480 src += borderTop * srcWidth; // skip top rows in src to get to first row of dst
3481 src += borderLeft; // skip left pixels in src to get to first pixel of dst
3483 gint channels = gdk_pixbuf_get_n_channels (preview);
3484 gint stride = gdk_pixbuf_get_rowstride (preview);
3486 for (ii = 0; ii < dstHeight; ii++)
3489 for (jj = 0; jj < dstWidth; jj++)
3491 tmp[0] = src[0] >> 16;
3492 tmp[1] = src[0] >> 8;
3493 tmp[2] = src[0] >> 0;
3498 src += (srcWidth - dstWidth); // skip to next row in src
3500 // Got it, but hb_get_preview doesn't compensate for anamorphic, so lets
3502 gint width, height, par_width, par_height;
3503 gboolean anamorphic = ghb_settings_get_boolean(settings, "anamorphic");
3506 hb_set_anamorphic_size( title->job, &width, &height, &par_width, &par_height );
3507 if (par_width > par_height)
3508 dstWidth = dstWidth * par_width / par_height;
3510 dstHeight = dstHeight * par_height / par_width;
3513 g_debug("scaled %d x %d\n", dstWidth, dstHeight);
3514 GdkPixbuf *scaled_preview;
3515 scaled_preview = gdk_pixbuf_scale_simple(preview, dstWidth, dstHeight, GDK_INTERP_HYPER);
3516 g_object_unref (preview);
3517 return scaled_preview;
3521 sanitize_volname(gchar *name)
3546 ghb_dvd_volname(const gchar *device)
3549 name = hb_dvd_name((gchar*)device);
3552 sanitize_volname(name);
3553 return g_strdup(name);