vtl: draw cross if info-request fails in open-video preview.
[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::clear_preview_image ()
352 {
353         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
354         video_draw_cross(imgbuf);
355         preview_image->set(imgbuf);
356         preview_image->show();
357 }
358
359 void
360 AddVideoDialog::set_action_ok (bool yn)
361 {
362         if (yn) {
363                 ok_button->set_sensitive(true);
364         } else {
365                 preview_path = "";
366                 pi_tcin.set_text("-");
367                 pi_tcout.set_text("-");
368                 pi_aspect.set_text("-");
369                 pi_fps.set_text("-");
370                 ok_button->set_sensitive(false);
371                 clear_preview_image();
372         }
373 }
374
375 void
376 AddVideoDialog::file_selection_changed ()
377 {
378         if (chooser.get_filename().size() > 0) {
379                 std::string path = chooser.get_filename();
380                 bool ok =
381                                 check_video_file_extension(path)
382                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
383                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
384                 set_action_ok(ok);
385                 if (ok) {
386                         seek_slider.set_value(0);
387                         request_preview(video_map_path(video_get_docroot(Config), path));
388                 }
389         } else {
390                 set_action_ok(false);
391         }
392 }
393
394 void
395 AddVideoDialog::file_activated ()
396 {
397         if (chooser.get_filename().size() > 0) {
398                 std::string path = chooser.get_filename();
399                 // TODO check docroot -> set import options
400                 bool ok =
401                                 check_video_file_extension(path)
402                                 &&  Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
403                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
404                 if (ok) {
405                         Gtk::Dialog::response(RESPONSE_ACCEPT);
406                 }
407         }
408 }
409
410 /**** Tree List Interaction ***/
411
412 void
413 AddVideoDialog::harvid_list_view_selected () {
414         Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
415         // TODO check docroot -> set import options, xjadeo
416         if(!iter) {
417                 set_action_ok(false);
418                 return;
419         }
420         if ((std::string)((*iter)[harvid_list_columns.id]) == Stock::DIRECTORY.id) {
421                 set_action_ok(false);
422         } else {
423                 set_action_ok(true);
424                 seek_slider.set_value(0);
425                 request_preview((*iter)[harvid_list_columns.uri]);
426         }
427 }
428
429 void
430 AddVideoDialog::harvid_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*) {
431         Gtk::TreeModel::iterator iter = harvid_list->get_iter(path);
432         if (!iter) return;
433         std::string type = (*iter)[harvid_list_columns.id];
434         std::string url = (*iter)[harvid_list_columns.uri];
435
436 #if 0
437         printf ("A: %s %s %s\n",
438                         ((std::string)((*iter)[harvid_list_columns.id])).c_str(),
439                         ((std::string)((*iter)[harvid_list_columns.uri])).c_str(),
440                         ((std::string)((*iter)[harvid_list_columns.filename])).c_str());
441 #endif
442
443         if (type == Gtk::Stock::DIRECTORY.id) {
444                 harvid_request(url.c_str());
445         } else {
446                 Gtk::Dialog::response(RESPONSE_ACCEPT);
447         }
448 }
449
450 void
451 AddVideoDialog::harvid_load_docroot() {
452         set_action_ok(false);
453
454         std::string video_server_url = video_get_server_url(Config);
455         char url[2048];
456         snprintf(url, sizeof(url), "%s%sindex/"
457                 , video_server_url.c_str()
458                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/");
459         harvid_request(url);
460         harvid_initialized = true;
461 }
462
463 bool
464 AddVideoDialog::page_switch() {
465         if (notebook.get_current_page () == 1 || Config->get_video_advanced_setup()) {
466                 file_selection_changed();
467                 return true;
468         }
469
470         if (harvid_initialized) {
471                 harvid_list_view_selected();
472         } else {
473                 harvid_load_docroot();
474         }
475         return true;
476 }
477
478 /**** Harvid HTTP interface ***/
479 void
480 AddVideoDialog::harvid_request(std::string u)
481 {
482         char url[2048];
483         int status;
484         snprintf(url, sizeof(url), "%s?format=csv", u.c_str());
485
486         harvid_list->clear();
487
488         char *res = curl_http_get(url, &status);
489         if (status != 200) {
490                 printf("request failed\n"); // XXX
491                 harvid_path.set_text(" - request failed -");
492                 free(res);
493                 return;
494         }
495
496         /* add up-to-parent */
497         size_t se = u.find_last_of("/", u.size()-2);
498         size_t ss = u.find("/index/");
499         if (se != string::npos && ss != string::npos && se > ss) {
500                 TreeModel::iterator new_row = harvid_list->append();
501                 TreeModel::Row row = *new_row;
502                 row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
503                 row[harvid_list_columns.uri     ] = u.substr(0, se + 1);
504                 row[harvid_list_columns.filename] = X_("..");
505         }
506         if (se != string::npos) {
507                 int plen;
508                 std::string path = u.substr(ss + 6);
509                 CURL *curl;
510                 curl = curl_easy_init();
511                 char *ue = curl_easy_unescape(curl, path.c_str(), path.length(), &plen);
512                 harvid_path.set_text(std::string(ue));
513                 curl_easy_cleanup(curl);
514                 curl_free(ue);
515         } else {
516                 harvid_path.set_text(" ??? ");
517         }
518
519         if (!res) return;
520
521         std::vector<std::vector<std::string> > lines;
522         ParseCSV(std::string(res), lines);
523         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
524                 TreeModel::iterator new_row = harvid_list->append();
525                 TreeModel::Row row = *new_row;
526
527                 if (i->at(0) == X_("D")) {
528                         row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
529                         row[harvid_list_columns.uri     ] = i->at(1).c_str();
530                         row[harvid_list_columns.filename] = i->at(2).c_str();
531                 } else {
532                         row[harvid_list_columns.id      ] = Gtk::Stock::MEDIA_PLAY.id;
533                         row[harvid_list_columns.uri     ] = i->at(2).c_str();
534                         row[harvid_list_columns.filename] = i->at(3).c_str();
535                 }
536         }
537
538         free(res);
539 }
540
541 void
542 AddVideoDialog::seek_preview()
543 {
544         if (preview_path.size() > 0)
545                 request_preview(preview_path);
546 }
547
548 void
549 AddVideoDialog::request_preview(std::string u)
550 {
551         std::string video_server_url = video_get_server_url(Config);
552
553         double video_file_fps;
554         long long int video_duration;
555         double video_start_offset;
556         double video_aspect_ratio;
557
558         int clip_width = PREVIEW_WIDTH;
559         int clip_height = PREVIEW_HEIGHT;
560         int clip_xoff, clip_yoff;
561
562         if (!video_query_info(video_server_url, u,
563                         video_file_fps, video_duration, video_start_offset, video_aspect_ratio))
564         {
565                 printf("image preview info request failed\n");
566                 // set_action_ok(false); // XXX only if docroot mismatch
567                 preview_path = "";
568                 pi_tcin.set_text("-");
569                 pi_tcout.set_text("-");
570                 pi_aspect.set_text("-");
571                 pi_fps.set_text("-");
572
573                 clear_preview_image();
574                 return;
575         }
576
577         if ((PREVIEW_WIDTH / (double)PREVIEW_HEIGHT) > video_aspect_ratio ) {
578                 clip_width = MIN(PREVIEW_WIDTH, rint(clip_height * video_aspect_ratio));
579         } else {
580                 clip_height = MIN(PREVIEW_HEIGHT, rint(clip_width / video_aspect_ratio));
581         }
582
583         pi_tcin.set_text(Timecode::timecode_format_sampletime(
584                                 video_start_offset, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
585         pi_tcout.set_text(Timecode::timecode_format_sampletime(
586                                 video_start_offset + video_duration, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
587
588         /* todo break out this code -> re-usability */
589         const int arc = rint(video_aspect_ratio*100);
590
591         switch (arc) {
592                 case 100:
593                         pi_aspect.set_text(X_(" 1:1"));  // square (large format stills)
594                         break;
595                 case 125:
596                         pi_aspect.set_text(X_(" 5:4"));
597                         break;
598                 case 133:
599                         pi_aspect.set_text(X_(" 4:3"));
600                         break;
601                 case 134:
602                         pi_aspect.set_text(X_(" 47:35")); // 752x560, Super8-scans
603                         break;
604                 case 137:
605                 case 138:
606                         pi_aspect.set_text(X_(" 1.37:1")); // 'Academy ratio' <= 1953
607                         break;
608                 case 141:
609                         pi_aspect.set_text(X_(" 1.41:1")); //  Lichtenberg ratio
610                         break;
611                 case 150:
612                         pi_aspect.set_text(X_(" 3:2"));  // classic 35mm
613                         break;
614                 case 160:
615                         pi_aspect.set_text(X_(" 8:5"));  // credit-card size
616                         break;
617                 case 162:
618                         pi_aspect.set_text(X_(" 16:10")); // golden ratio 1.61803..
619                         break;
620                 case 166:
621                 case 167:
622                         pi_aspect.set_text(X_(" 5:3")); // Super16, EU-widescreen
623                         break;
624                 case 177:
625                 case 178:
626                         pi_aspect.set_text(X_(" 16:9")); // HD video
627                         break;
628                 case 180:
629                         pi_aspect.set_text(X_(" 9:5"));
630                         break;
631                 case 185:
632                         pi_aspect.set_text(X_(" 1.85:1")); // US widescreen cinema
633                         break;
634                 case 200:
635                         pi_aspect.set_text(X_(" 2:1"));
636                         break;
637                 case 239:
638                 case 240:
639                         pi_aspect.set_text(X_(" 2.40:1")); // Anamorphic
640                         break;
641                 case 266:
642                 case 267:
643                         pi_aspect.set_text(X_(" 2.66:1")); // CinemaScope
644                         break;
645                 case 275:
646                         pi_aspect.set_text(X_(" 2.75:1")); // Ultra Panavision
647                         break;
648                 case 400:
649                         pi_aspect.set_text(X_(" 4.00:1")); // three 35mm 1.33:1 polyvision
650                         break;
651                 default:
652                         pi_aspect.set_text(string_compose(X_(" %1:1"), video_aspect_ratio));
653                 break;
654         }
655
656         pi_fps.set_text(string_compose(_(" %1 fps"), video_file_fps));
657
658         clip_xoff = (PREVIEW_WIDTH - clip_width)/2;
659         clip_yoff = (PREVIEW_HEIGHT - clip_height)/2;
660
661         char url[2048];
662         snprintf(url, sizeof(url), "%s%s?frame=%lli&w=%d&h=%di&file=%s&format=rgb"
663                 , video_server_url.c_str()
664                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/"
665                 , (long long) (video_duration * seek_slider.get_value() / 1000.0)
666                 , clip_width, clip_height, u.c_str());
667
668         char *data = curl_http_get(url, NULL);
669         if (!data) {
670                 printf("image preview request failed %s\n", url);
671                 imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
672                 video_draw_cross(imgbuf);
673                 preview_path = "";
674         } else {
675                 Glib::RefPtr<Gdk::Pixbuf> tmp;
676                 tmp = Gdk::Pixbuf::create_from_data ((guint8*) data, Gdk::COLORSPACE_RGB, false, 8, clip_width, clip_height, clip_width*3);
677                 if (clip_width != PREVIEW_WIDTH || clip_height != PREVIEW_HEIGHT) {
678                         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
679                 }
680                 tmp->copy_area (0, 0, clip_width, clip_height, imgbuf, clip_xoff, clip_yoff);
681                 preview_path = u;
682                 free(data);
683         }
684         preview_image->set(imgbuf);
685         preview_image->show();
686 }
687
688 #endif /* WITH_VIDEOTIMELINE */