Merge branch 'master' of git.ardour.org:ardour/ardour
[ardour.git] / gtk2_ardour / add_video_dialog.cc
1 /*
2     Copyright (C) 2010-2013 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #ifdef WITH_VIDEOTIMELINE
21
22 #include <cstdio>
23 #include <cmath>
24
25 #include <sigc++/bind.h>
26 #include <curl/curl.h>
27
28 #include "pbd/error.h"
29 #include "pbd/convert.h"
30 #include "gtkmm2ext/utils.h"
31 #include "gtkmm2ext/rgb_macros.h"
32 #include "ardour/session_directory.h"
33 #include "ardour/profile.h"
34 #include "ardour/template_utils.h"
35 #include "ardour/session.h"
36 #include "ardour_ui.h"
37
38 #include "utils.h"
39 #include "add_video_dialog.h"
40 #include "utils_videotl.h"
41 #include "i18n.h"
42
43 using namespace Gtk;
44 using namespace std;
45 using namespace PBD;
46 using namespace ARDOUR;
47
48 #define PREVIEW_WIDTH (240)
49 #define PREVIEW_HEIGHT (180)
50
51 #ifndef MIN
52 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
53 #endif
54
55 AddVideoDialog::AddVideoDialog (Session* s)
56         : ArdourDialog (_("Set Video Track"))
57         , seek_slider (0,1000,1)
58         , preview_path ("")
59         , pi_tcin ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
60         , pi_tcout ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
61         , pi_aspect ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
62         , pi_fps ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
63         , chooser (FILE_CHOOSER_ACTION_OPEN)
64         , xjadeo_checkbox (_("Launch External Video Monitor"))
65         , set_session_fps_checkbox (_("Adjust Session Framerate to Match Video Framerate"))
66         , harvid_path ("")
67         , harvid_reset (_("Reload docroot"))
68         , harvid_list (ListStore::create(harvid_list_columns))
69         , harvid_list_view (harvid_list)
70 {
71         set_session (s);
72         set_name ("AddVideoDialog");
73         set_position (Gtk::WIN_POS_MOUSE);
74         set_modal (true);
75         set_skip_taskbar_hint (true);
76         set_resizable (true);
77         set_size_request (800, -1);
78
79         harvid_initialized = false;
80         std::string dstdir = video_dest_dir(_session->session_directory().video_path(), video_get_docroot(Config));
81
82         if (Config->get_video_advanced_setup()) {
83
84                 /* Harvid Browser */
85                 harvid_list_view.append_column("", pixBufRenderer);
86                 harvid_list_view.append_column(_("Filename"), harvid_list_columns.filename);
87
88                 harvid_list_view.get_column(0)->set_alignment(0.5);
89                 harvid_list_view.get_column(0)->add_attribute(pixBufRenderer, "stock-id", harvid_list_columns.id);
90                 harvid_list_view.get_column(1)->set_expand(true);
91                 harvid_list_view.get_column(1)->set_sort_column(harvid_list_columns.filename);
92                 harvid_list_view.set_enable_search(true);
93                 harvid_list_view.set_search_column(1);
94
95                 harvid_list_view.get_selection()->set_mode (SELECTION_SINGLE);
96
97                 harvid_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::harvid_list_view_selected));
98                 harvid_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_list_view_activated));
99
100                 VBox* vbox = manage (new VBox);
101                 Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
102                 scroll->add(harvid_list_view);
103                 scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
104
105                 HBox* hbox = manage (new HBox);
106                 harvid_path.set_alignment (0, 0.5);
107                 hbox->pack_start (harvid_path, true, true);
108                 hbox->pack_start (harvid_reset, false, false);
109
110                 vbox->pack_start (*hbox, false, false);
111                 vbox->pack_start (*scroll, true, true);
112
113                 notebook.append_page (*vbox, _("VideoServerIndex"));
114         } else {
115                 /* dummy entry */
116                 VBox* vbox = manage (new VBox);
117                 notebook.append_page (*vbox, _("VideoServerIndex"));
118         }
119
120         /* file chooser */
121         chooser.set_border_width (4);
122 #ifdef GTKOSX
123         /* some broken redraw behaviour - this is a bandaid */
124         chooser.signal_selection_changed().connect (mem_fun (chooser, &Widget::queue_draw));
125 #endif
126         chooser.set_current_folder (dstdir);
127
128         Gtk::FileFilter video_filter;
129         Gtk::FileFilter matchall_filter;
130         video_filter.add_custom (FILE_FILTER_FILENAME, mem_fun(*this, &AddVideoDialog::on_video_filter));
131         video_filter.set_name (_("Video files"));
132
133         matchall_filter.add_pattern ("*.*");
134         matchall_filter.set_name (_("All files"));
135
136         chooser.add_filter (video_filter);
137         chooser.add_filter (matchall_filter);
138         chooser.set_select_multiple (false);
139
140         VBox* vboxfb = manage (new VBox);
141         vboxfb->pack_start (chooser, true, true, 0);
142
143         if (video_get_docroot(Config).size() > 0 &&
144                         Config->get_video_advanced_setup()) {
145                 notebook.append_page (*vboxfb, _("Browse Files"));
146         }
147
148         /* Global Options*/
149         Gtk::Label* l;
150         VBox* options_box = manage (new VBox);
151
152         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
153         l->set_use_markup ();
154
155         options_box->pack_start (*l, false, true, 4);
156         options_box->pack_start (xjadeo_checkbox, false, true, 2);
157         options_box->pack_start (set_session_fps_checkbox, false, true, 2);
158
159         /* preview pane */
160         VBox* previewpane = manage (new VBox);
161         Gtk::Table *table = manage(new Table(5,2));
162
163         table->set_row_spacings(2);
164         table->set_col_spacings(4);
165
166         l = manage (new Label (_("<b>Video Information</b>"), Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, false));
167         l->set_use_markup ();
168         table->attach (*l, 0, 2, 0, 1, FILL, FILL);
169         l = manage (new Label (_("Start:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
170         table->attach (*l, 0, 1, 1, 2, FILL, FILL);
171         table->attach (pi_tcin, 1, 2, 1, 2, FILL, FILL);
172         l = manage (new Label (_("End:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
173         table->attach (*l, 0, 1, 2, 3, FILL, FILL);
174         table->attach (pi_tcout, 1, 2, 2, 3, FILL, FILL);
175         l = manage (new Label (_("Frame rate:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
176         table->attach (*l, 0, 1, 3, 4, FILL, FILL);
177         table->attach (pi_fps, 1, 2, 3, 4, FILL, FILL);
178         l = manage (new Label (_("Aspect Ratio:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
179         table->attach (*l, 0, 1, 4, 5, FILL, FILL);
180         table->attach (pi_aspect, 1, 2, 4, 5, FILL, FILL);
181
182         preview_image = manage(new Gtk::Image);
183
184         imgbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, PREVIEW_WIDTH, PREVIEW_HEIGHT);
185         imgbuf->fill(RGBA_TO_UINT(127,0,0,255));
186         preview_image->set(imgbuf);
187         seek_slider.set_draw_value(false);
188
189         HBox* hbox = manage (new HBox);
190         hbox->pack_start (*table, true, false);
191
192         Gtk::Alignment *al = manage(new Gtk::Alignment());
193         al->set_size_request(-1, 20);
194
195         previewpane->pack_start (*preview_image, false, false);
196         previewpane->pack_start (seek_slider, false, false);
197         previewpane->pack_start (*al, false, false);
198         previewpane->pack_start (*hbox, true, true, 6);
199
200         /* Overall layout */
201         hbox = manage (new HBox);
202         if (Config->get_video_advanced_setup()) {
203                 hbox->pack_start (notebook, true, true);
204         } else {
205                 hbox->pack_start (*vboxfb, true, true);
206         }
207         hbox->pack_start (*previewpane, false, false);
208
209         get_vbox()->set_spacing (4);
210         get_vbox()->pack_start (*hbox, true, true);
211         get_vbox()->pack_start (*options_box, false, false);
212
213
214         /* xjadeo checkbox */
215         if (ARDOUR_UI::instance()->video_timeline->found_xjadeo()
216                         /* TODO xjadeo setup w/ xjremote */
217                         && video_get_docroot(Config).size() > 0) {
218                 xjadeo_checkbox.set_active(true);  /* set in ardour_ui.cpp ?! */
219         } else {
220                 printf("xjadeo was not found or video-server docroot is unset (remote video-server)\n");
221                 xjadeo_checkbox.set_active(false);
222                 xjadeo_checkbox.set_sensitive(false);
223         }
224
225         /* FPS checkbox */
226         set_session_fps_checkbox.set_active(true);
227
228         /* Buttons */
229         add_button (Stock::CANCEL, RESPONSE_CANCEL);
230         ok_button = add_button (Stock::OK, RESPONSE_ACCEPT);
231         //ok_button->set_sensitive(false);
232         set_action_ok(false);
233
234         /* connect signals after eveything has been initialized */
235         chooser.signal_selection_changed().connect (mem_fun (*this, &AddVideoDialog::file_selection_changed));
236         chooser.signal_file_activated().connect (mem_fun (*this, &AddVideoDialog::file_activated));
237         //chooser.signal_update_preview().connect(sigc::mem_fun(*this, &AddVideoDialog::update_preview));
238         notebook.signal_switch_page().connect (sigc::hide_return (sigc::hide (sigc::hide (sigc::mem_fun (*this, &AddVideoDialog::page_switch)))));
239         seek_slider.signal_value_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::seek_preview));
240         harvid_reset.signal_clicked().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_load_docroot));
241
242         show_all_children ();
243 }
244
245 AddVideoDialog::~AddVideoDialog ()
246 {
247 }
248
249 void
250 AddVideoDialog::on_show ()
251 {
252         Dialog::on_show ();
253 }
254
255 static bool check_video_file_extension(std::string file)
256 {
257         const char* suffixes[] = {
258                 ".avi"     , ".AVI"     ,
259                 ".mov"     , ".MOV"     ,
260                 ".ogg"     , ".OGG"     ,
261                 ".ogv"     , ".OGV"     ,
262                 ".mpg"     , ".MPG"     ,
263                 ".mov"     , ".MOV"     ,
264                 ".mp4"     , ".MP4"     ,
265                 ".mkv"     , ".MKV"     ,
266                 ".vob"     , ".VOB"     ,
267                 ".asf"     , ".ASF"     ,
268                 ".avs"     , ".AVS"     ,
269                 ".dts"     , ".DTS"     ,
270                 ".flv"     , ".FLV"     ,
271                 ".m4v"     , ".M4V"     ,
272                 ".matroska", ".MATROSKA",
273                 ".h264"    , ".H264"    ,
274                 ".dv"      , ".DV"      ,
275                 ".dirac"   , ".DIRAC"   ,
276                 ".webm"    , ".WEBM"    ,
277         };
278
279         for (size_t n = 0; n < sizeof(suffixes)/sizeof(suffixes[0]); ++n) {
280                 if (file.rfind (suffixes[n]) == file.length() - strlen (suffixes[n])) {
281                         return true;
282                 }
283         }
284
285         return false;
286 }
287
288 bool
289 AddVideoDialog::on_video_filter (const FileFilter::Info& filter_info)
290 {
291         return check_video_file_extension(filter_info.filename);
292 }
293
294 std::string
295 AddVideoDialog::file_name (bool &local_file)
296 {
297         int n = notebook.get_current_page ();
298         if (n == 1 || ! Config->get_video_advanced_setup()) {
299                 local_file = true;
300                 return chooser.get_filename();
301         } else {
302                 local_file = false;
303                 Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
304                 if(!iter) return "";
305
306                 std::string uri = (*iter)[harvid_list_columns.uri];
307                 std::string video_server_url = video_get_server_url(Config);
308
309                 /* check if video server is running locally */
310                 if (video_get_docroot(Config).size() > 0
311                                 && !video_server_url.compare(0, 16, "http://localhost"))
312                 {
313                         /* check if the file can be accessed */
314                         int plen;
315                         CURL *curl;
316                         curl = curl_easy_init();
317                         char *ue = curl_easy_unescape(curl, uri.c_str(), uri.length(), &plen);
318                         std::string path = video_get_docroot(Config) + ue;
319                         if (!::access(path.c_str(), R_OK)) {
320                                 uri = path;
321                                 local_file = true;
322                         }
323                         curl_easy_cleanup(curl);
324                         curl_free(ue);
325                 }
326                 return uri;
327         }
328 }
329
330 enum VtlImportOption
331 AddVideoDialog::import_option ()
332 {
333         int n = notebook.get_current_page ();
334         if (n == 0 && Config->get_video_advanced_setup()) { return VTL_IMPORT_NONE; }
335         return VTL_IMPORT_TRANSCODE;
336 }
337
338 bool
339 AddVideoDialog::launch_xjadeo ()
340 {
341         return xjadeo_checkbox.get_active();
342 }
343
344 bool
345 AddVideoDialog::auto_set_session_fps ()
346 {
347         return set_session_fps_checkbox.get_active();
348 }
349
350 void
351 AddVideoDialog::set_action_ok (bool yn)
352 {
353         if (yn) {
354                 ok_button->set_sensitive(true);
355         } else {
356                 preview_path = "";
357                 pi_tcin.set_text("-");
358                 pi_tcout.set_text("-");
359                 pi_aspect.set_text("-");
360                 pi_fps.set_text("-");
361                 ok_button->set_sensitive(false);
362                 imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
363                 video_draw_cross(imgbuf);
364                 preview_image->set(imgbuf);
365                 preview_image->show();
366         }
367 }
368
369 void
370 AddVideoDialog::file_selection_changed ()
371 {
372         if (chooser.get_filename().size() > 0) {
373                 std::string path = chooser.get_filename();
374                 bool ok =
375                                 check_video_file_extension(path)
376                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
377                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
378                 set_action_ok(ok);
379                 if (ok) {
380                         seek_slider.set_value(0);
381                         request_preview(video_map_path(video_get_docroot(Config), path));
382                 }
383         } else {
384                 set_action_ok(false);
385         }
386 }
387
388 void
389 AddVideoDialog::file_activated ()
390 {
391         if (chooser.get_filename().size() > 0) {
392                 std::string path = chooser.get_filename();
393                 // TODO check docroot -> set import options
394                 bool ok =
395                                 check_video_file_extension(path)
396                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
397                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
398                 if (ok) {
399                         Gtk::Dialog::response(RESPONSE_ACCEPT);
400                 }
401         }
402 }
403
404 /**** Tree List Interaction ***/
405
406 void
407 AddVideoDialog::harvid_list_view_selected () {
408         Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
409         // TODO check docroot -> set import options, xjadeo
410         if(!iter) {
411                 set_action_ok(false);
412                 return;
413         }
414         if ((std::string)((*iter)[harvid_list_columns.id]) == Stock::DIRECTORY.id) {
415                 set_action_ok(false);
416         } else {
417                 set_action_ok(true);
418                 seek_slider.set_value(0);
419                 request_preview((*iter)[harvid_list_columns.uri]);
420         }
421 }
422
423 void
424 AddVideoDialog::harvid_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*) {
425         Gtk::TreeModel::iterator iter = harvid_list->get_iter(path);
426         if (!iter) return;
427         std::string type = (*iter)[harvid_list_columns.id];
428         std::string url = (*iter)[harvid_list_columns.uri];
429
430 #if 0
431         printf ("A: %s %s %s\n",
432                         ((std::string)((*iter)[harvid_list_columns.id])).c_str(),
433                         ((std::string)((*iter)[harvid_list_columns.uri])).c_str(),
434                         ((std::string)((*iter)[harvid_list_columns.filename])).c_str());
435 #endif
436
437         if (type == Gtk::Stock::DIRECTORY.id) {
438                 harvid_request(url.c_str());
439         } else {
440                 Gtk::Dialog::response(RESPONSE_ACCEPT);
441         }
442 }
443
444 void
445 AddVideoDialog::harvid_load_docroot() {
446         set_action_ok(false);
447
448         std::string video_server_url = video_get_server_url(Config);
449         char url[2048];
450         snprintf(url, sizeof(url), "%s%sindex/"
451                 , video_server_url.c_str()
452                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/");
453         harvid_request(url);
454         harvid_initialized = true;
455 }
456
457 bool
458 AddVideoDialog::page_switch() {
459         if (notebook.get_current_page () == 1 || Config->get_video_advanced_setup()) {
460                 file_selection_changed();
461                 return true;
462         }
463
464         if (harvid_initialized) {
465                 harvid_list_view_selected();
466         } else {
467                 harvid_load_docroot();
468         }
469         return true;
470 }
471
472 /**** Harvid HTTP interface ***/
473 void
474 AddVideoDialog::harvid_request(std::string u)
475 {
476         char url[2048];
477         int status;
478         snprintf(url, sizeof(url), "%s?format=csv", u.c_str());
479
480         harvid_list->clear();
481
482         char *res = curl_http_get(url, &status);
483         if (status != 200) {
484                 printf("request failed\n"); // XXX
485                 harvid_path.set_text(" - request failed -");
486                 free(res);
487                 return;
488         }
489
490         /* add up-to-parent */
491         size_t se = u.find_last_of("/", u.size()-2);
492         size_t ss = u.find("/index/");
493         if (se != string::npos && ss != string::npos && se > ss) {
494                 TreeModel::iterator new_row = harvid_list->append();
495                 TreeModel::Row row = *new_row;
496                 row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
497                 row[harvid_list_columns.uri     ] = u.substr(0, se + 1);
498                 row[harvid_list_columns.filename] = X_("..");
499         }
500         if (se != string::npos) {
501                 int plen;
502                 std::string path = u.substr(ss + 6);
503                 CURL *curl;
504                 curl = curl_easy_init();
505                 char *ue = curl_easy_unescape(curl, path.c_str(), path.length(), &plen);
506                 harvid_path.set_text(std::string(ue));
507                 curl_easy_cleanup(curl);
508                 curl_free(ue);
509         } else {
510                 harvid_path.set_text(" ??? ");
511         }
512
513         if (!res) return;
514
515         std::vector<std::vector<std::string> > lines;
516         ParseCSV(std::string(res), lines);
517         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
518                 TreeModel::iterator new_row = harvid_list->append();
519                 TreeModel::Row row = *new_row;
520
521                 if (i->at(0) == X_("D")) {
522                         row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
523                         row[harvid_list_columns.uri     ] = i->at(1).c_str();
524                         row[harvid_list_columns.filename] = i->at(2).c_str();
525                 } else {
526                         row[harvid_list_columns.id      ] = Gtk::Stock::MEDIA_PLAY.id;
527                         row[harvid_list_columns.uri     ] = i->at(2).c_str();
528                         row[harvid_list_columns.filename] = i->at(3).c_str();
529                 }
530         }
531
532         free(res);
533 }
534
535 void
536 AddVideoDialog::seek_preview()
537 {
538         if (preview_path.size() > 0)
539                 request_preview(preview_path);
540 }
541
542 void
543 AddVideoDialog::request_preview(std::string u)
544 {
545         std::string video_server_url = video_get_server_url(Config);
546
547         double video_file_fps;
548         long long int video_duration;
549         double video_start_offset;
550         double video_aspect_ratio;
551
552         int clip_width = PREVIEW_WIDTH;
553         int clip_height = PREVIEW_HEIGHT;
554         int clip_xoff, clip_yoff;
555
556         if (!video_query_info(video_server_url, u,
557                         video_file_fps, video_duration, video_start_offset, video_aspect_ratio))
558         {
559                 printf("image preview info request failed\n");
560                 // set_action_ok(false); // XXX only if docroot mismatch
561                 preview_path = "";
562                 pi_tcin.set_text("-");
563                 pi_tcout.set_text("-");
564                 pi_aspect.set_text("-");
565                 pi_fps.set_text("-");
566                 return;
567         }
568
569         if ((PREVIEW_WIDTH / (double)PREVIEW_HEIGHT) > video_aspect_ratio ) {
570                 clip_width = MIN(PREVIEW_WIDTH, rint(clip_height * video_aspect_ratio));
571         } else {
572                 clip_height = MIN(PREVIEW_HEIGHT, rint(clip_width / video_aspect_ratio));
573         }
574
575         pi_tcin.set_text(Timecode::timecode_format_sampletime(
576                                 video_start_offset, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
577         pi_tcout.set_text(Timecode::timecode_format_sampletime(
578                                 video_start_offset + video_duration, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
579
580         /* todo break out this code -> re-usability */
581         const int arc = rint(video_aspect_ratio*100);
582
583         switch (arc) {
584                 case 100:
585                         pi_aspect.set_text(X_(" 1:1"));  // square (large format stills)
586                         break;
587                 case 125:
588                         pi_aspect.set_text(X_(" 5:4"));
589                         break;
590                 case 133:
591                         pi_aspect.set_text(X_(" 4:3"));
592                         break;
593                 case 134:
594                         pi_aspect.set_text(X_(" 47:35")); // 752x560, Super8-scans
595                         break;
596                 case 137:
597                 case 138:
598                         pi_aspect.set_text(X_(" 1.37:1")); // 'Academy ratio' <= 1953
599                         break;
600                 case 141:
601                         pi_aspect.set_text(X_(" 1.41:1")); //  Lichtenberg ratio
602                         break;
603                 case 150:
604                         pi_aspect.set_text(X_(" 3:2"));  // classic 35mm
605                         break;
606                 case 160:
607                         pi_aspect.set_text(X_(" 8:5"));  // credit-card size
608                         break;
609                 case 162:
610                         pi_aspect.set_text(X_(" 16:10")); // golden ratio 1.61803..
611                         break;
612                 case 166:
613                 case 167:
614                         pi_aspect.set_text(X_(" 5:3")); // Super16, EU-widescreen
615                         break;
616                 case 177:
617                 case 178:
618                         pi_aspect.set_text(X_(" 16:9")); // HD video
619                         break;
620                 case 180:
621                         pi_aspect.set_text(X_(" 9:5"));
622                         break;
623                 case 185:
624                         pi_aspect.set_text(X_(" 1.85:1")); // US widescreen cinema
625                         break;
626                 case 200:
627                         pi_aspect.set_text(X_(" 2:1"));
628                         break;
629                 case 239:
630                 case 240:
631                         pi_aspect.set_text(X_(" 2.40:1")); // Anamorphic
632                         break;
633                 case 266:
634                 case 267:
635                         pi_aspect.set_text(X_(" 2.66:1")); // CinemaScope
636                         break;
637                 case 275:
638                         pi_aspect.set_text(X_(" 2.75:1")); // Ultra Panavision
639                         break;
640                 case 400:
641                         pi_aspect.set_text(X_(" 4.00:1")); // three 35mm 1.33:1 polyvision
642                         break;
643                 default:
644                         pi_aspect.set_text(string_compose(X_(" %1:1"), video_aspect_ratio));
645                 break;
646         }
647
648         pi_fps.set_text(string_compose(_(" %1 fps"), video_file_fps));
649
650         clip_xoff = (PREVIEW_WIDTH - clip_width)/2;
651         clip_yoff = (PREVIEW_HEIGHT - clip_height)/2;
652
653         char url[2048];
654         snprintf(url, sizeof(url), "%s%s?frame=%lli&w=%d&h=%di&file=%s&format=rgb"
655                 , video_server_url.c_str()
656                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/"
657                 , (long long) (video_duration * seek_slider.get_value() / 1000.0)
658                 , clip_width, clip_height, u.c_str());
659
660         char *data = curl_http_get(url, NULL);
661         if (!data) {
662                 printf("image preview request failed %s\n", url);
663                 imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
664                 video_draw_cross(imgbuf);
665                 preview_path = "";
666         } else {
667                 Glib::RefPtr<Gdk::Pixbuf> tmp;
668                 tmp = Gdk::Pixbuf::create_from_data ((guint8*) data, Gdk::COLORSPACE_RGB, false, 8, clip_width, clip_height, clip_width*3);
669                 if (clip_width != PREVIEW_WIDTH || clip_height != PREVIEW_HEIGHT) {
670                         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
671                 }
672                 tmp->copy_area (0, 0, clip_width, clip_height, imgbuf, clip_xoff, clip_yoff);
673                 preview_path = u;
674                 free(data);
675         }
676         preview_image->set(imgbuf);
677         preview_image->show();
678 }
679
680 #endif /* WITH_VIDEOTIMELINE */