4 * Copyright (C) 2015 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "audiodevice.h"
24 #include "bcsignals.h"
29 #include "edlsession.h"
32 #include "filesystem.h"
33 #include "formattools.h"
35 #include "mainerror.h"
36 #include "mainindexes.h"
37 #include "mainprogress.h"
41 #include "mwindowgui.h"
42 #include "overlayframe.h"
43 #include "preferences.h"
45 #include "renderengine.h"
47 #include "transportque.h"
51 #define HEIGHT yS(400)
54 ProxyMenuItem::ProxyMenuItem(MWindow *mwindow)
55 : BC_MenuItem(_("Proxy settings..."), _("Alt-r"), 'r')
57 this->mwindow = mwindow;
61 ProxyMenuItem::~ProxyMenuItem()
66 void ProxyMenuItem::create_objects()
68 dialog = new ProxyDialog(mwindow);
71 int ProxyMenuItem::handle_event()
73 mwindow->gui->unlock_window();
75 mwindow->gui->lock_window("ProxyMenuItem::handle_event");
80 ProxyDialog::ProxyDialog(MWindow *mwindow)
82 this->mwindow = mwindow;
86 // quicker than some, not as good as others
87 asset->format = FILE_FFMPEG;
88 strcpy(asset->fformat, "mpeg");
89 strcpy(asset->vcodec, "mpeg.mpeg");
90 asset->ff_video_bitrate = 2000000;
91 asset->video_data = 1;
93 bzero(size_text, sizeof(char*) * MAX_SIZES);
94 bzero(size_factors, sizeof(int) * MAX_SIZES);
95 size_text[0] = cstrdup(_("off"));
96 size_text[1] = cstrdup(_("1"));
102 ProxyDialog::~ProxyDialog()
105 for( int i=0; i<MAX_SIZES; ++i ) delete [] size_text[i];
106 asset->remove_user();
109 BC_Window* ProxyDialog::new_gui()
111 asset->format = FILE_FFMPEG;
112 asset->load_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0);
113 mwindow->gui->lock_window("ProxyDialog::new_gui");
115 mwindow->gui->get_abs_cursor(cx, cy);
116 gui = new ProxyWindow(mwindow, this, cx - WIDTH/2, cy - HEIGHT/2);
117 gui->create_objects();
118 mwindow->gui->unlock_window();
122 void ProxyDialog::scale_to_text(char *string, int scale)
124 strcpy(string, size_text[0]);
125 for( int i = 0; i < total_sizes; i++ ) {
126 if( scale == size_factors[i] ) {
127 strcpy(string, size_text[i]);
134 void ProxyDialog::calculate_sizes()
136 for( int i=2; i<total_sizes; ++i ) {
137 delete [] size_text[i];
144 // w,h should stay even for yuv
145 int ow = orig_w, oh = orig_h;
146 if( BC_CModels::is_yuv(mwindow->edl->session->color_model) ) {
149 for( int i=2; i<MAX_SCALE; ++i ) {
150 if( (ow % i) != 0 ) continue;
151 if( (oh % i) != 0 ) continue;
152 size_factors[total_sizes++] = i;
156 size_factors[total_sizes++] = 2; size_factors[total_sizes++] = 3;
157 size_factors[total_sizes++] = 8; size_factors[total_sizes++] = 12;
158 size_factors[total_sizes++] = 16; size_factors[total_sizes++] = 24;
159 size_factors[total_sizes++] = 32;
161 for( int i=2; i<total_sizes; ++i ) {
162 char string[BCTEXTLEN];
163 sprintf(string, "1/%d", size_factors[i]);
164 size_text[i] = cstrdup(string);
168 void ProxyDialog::handle_close_event(int result)
172 if( !File::renders_video(asset) ) {
173 eprintf(_("Specified format does not render video"));
176 mwindow->edl->session->proxy_auto_scale = auto_scale;
177 mwindow->edl->session->proxy_beep = beeper_volume;
178 asset->save_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0);
179 result = mwindow->to_proxy(asset, new_scale, use_scaler);
180 if( result >= 0 && beeper_on && beeper_volume > 0 && new_scale >= 1 ) {
182 mwindow->beep(4000., 0.5, beeper_volume);
184 mwindow->beep(1000., 0.5, beeper_volume);
186 mwindow->beep(4000., 0.5, beeper_volume);
189 mwindow->beep(2000., 2.0, beeper_volume);
191 mwindow->edl->session->proxy_disabled_scale = 1;
192 mwindow->gui->lock_window("ProxyDialog::handle_close_event");
193 mwindow->update_project(LOADMODE_REPLACE);
194 mwindow->gui->unlock_window();
197 void ProxyRender::to_proxy_path(char *new_path, Indexable *indexable, int scale)
199 // path is already a proxy
200 if( strstr(indexable->path, ".proxy") ) return;
201 if( !indexable->is_asset ) {
202 char *ifn = indexable->path, *cp = strrchr(ifn, '/');
204 char proxy_path[BCTEXTLEN];
205 File::getenv_path(proxy_path,
206 mwindow->preferences->nested_proxy_path);
207 sprintf(new_path, "%s/%s", proxy_path, ifn);
210 strcpy(new_path, indexable->path);
212 int n = sprintf(prxy, ".proxy%d", scale);
213 // insert proxy, path.sfx => path.proxy#-sfx.ext
214 char *ep = new_path + strlen(new_path);
215 char *sfx = strrchr(new_path, '.');
217 char *bp = ep, *cp = (ep += n);
218 while( --bp > sfx ) *--cp = *bp;
224 for( char *cp=prxy; --n>=0; ++cp ) *sfx++ = *cp;
226 const char *ext = indexable->get_video_frames() < 0 ? "png" :
227 format_asset->format == FILE_FFMPEG ?
228 format_asset->fformat :
229 File::get_tag(format_asset->format);
230 while( *ext ) *ep++ = *ext++;
232 //printf("ProxyRender::to_proxy_path %d %s %s\n", __LINE__, new_path), asset->path);
235 int ProxyRender::from_proxy_path(char *new_path, Asset *asset, int scale)
237 char prxy[BCTEXTLEN];
238 int n = sprintf(prxy, ".proxy%d", scale);
239 strcpy(new_path, asset->path);
240 char *ptr = strstr(new_path, prxy);
241 if( !ptr || (ptr[n] != '-' && ptr[n] != '.') ) return 1;
242 // remove proxy, path.proxy#-sfx.ext => path.sfx
243 char *ext = strrchr(ptr, '.');
244 if( !ext ) ext = ptr + strlen(ptr);
246 for( *cp='.'; cp<ext; ++cp ) *ptr++ = *cp;
248 if( asset->proxy_edl ) {
249 if( (cp = strrchr(new_path, '/')) != 0 ) {
250 for( ptr=new_path; *++cp; ) *ptr++ = *cp;
257 ProxyRender::ProxyRender(MWindow *mwindow, Asset *format_asset, int asset_scale)
259 this->mwindow = mwindow;
260 this->format_asset = format_asset;
261 this->asset_scale = asset_scale;
263 counter_lock = new Mutex("ProxyDialog::counter_lock");
265 failed = 0; canceled = 0;
268 ProxyRender::~ProxyRender()
273 for( int i=0,n=orig_idxbls.size(); i<n; ++i ) orig_idxbls[i]->remove_user();
274 for( int i=0,n=orig_proxies.size(); i<n; ++i ) orig_proxies[i]->remove_user();
275 for( int i=0,n=needed_idxbls.size(); i<n; ++i ) needed_idxbls[i]->remove_user();
276 for( int i=0,n=needed_proxies.size(); i<n; ++i ) needed_proxies[i]->remove_user();
279 Asset *ProxyRender::add_original(Indexable *idxbl, int new_scale)
281 if( !idxbl->have_video() ) return 0;
282 // don't proxy proxies
283 if( strstr(idxbl->path,".proxy") ) return 0;
284 char new_path[BCTEXTLEN];
285 to_proxy_path(new_path, idxbl, new_scale);
286 // don't proxy if not readable, or proxy_path not writable
287 if( idxbl->is_asset && access(idxbl->path, R_OK) ) return 0;
288 int ret = access(new_path, W_OK);
290 int fd = ::open(new_path,O_WRONLY);
291 if( fd < 0 ) fd = open(new_path,O_WRONLY+O_CREAT,0666);
292 if( fd >= 0 ) { close(fd); ret = 0; }
295 eprintf(_("bad proxy path: %s\n"), new_path);
298 // add to orig_idxbls & orig_proxies if it isn't already there.
300 for( int i = 0; !got_it && i<orig_proxies.size(); ++i )
301 got_it = !strcmp(orig_proxies[i]->path, new_path);
302 if( got_it ) return 0;
303 Assets *edl_assets = mwindow->edl->assets;
304 Asset *proxy = edl_assets->get_asset(new_path);
306 proxy = new Asset(new_path);
307 // new compression parameters
308 int64_t video_frames = idxbl->get_video_frames();
309 if( video_frames < 0 ) {
310 proxy->format = FILE_PNG;
311 proxy->png_use_alpha = 1;
312 proxy->video_length = -1;
315 proxy->copy_format(format_asset, 0);
316 proxy->video_length = video_frames;
318 proxy->folder_no = AW_PROXY_FOLDER;
319 proxy->proxy_edl = !idxbl->is_asset ? 1 : 0;
320 proxy->audio_data = 0;
321 proxy->video_data = 1;
323 proxy->width = idxbl->get_w() / new_scale;
324 if( proxy->width & 1 ) ++proxy->width;
325 proxy->actual_width = proxy->width;
326 proxy->height = idxbl->get_h() / new_scale;
327 if( proxy->height & 1 ) ++proxy->height;
328 proxy->actual_height = proxy->height;
329 proxy->frame_rate = idxbl->get_frame_rate();
331 orig_proxies.append(proxy);
333 orig_idxbls.append(idxbl);
337 void ProxyRender::add_needed(Indexable *idxbl, Asset *proxy)
339 needed_idxbls.append(idxbl);
341 needed_proxies.append(proxy);
345 void ProxyRender::update_progress()
347 counter_lock->lock();
349 counter_lock->unlock();
350 progress->update(total_rendered);
353 int ProxyRender::is_canceled()
355 return progress->is_cancelled();
358 int ProxyRender::create_needed_proxies(int new_scale)
360 if( !needed_proxies.size() ) return 0;
362 failed = 0; canceled = 0;
364 // create proxy assets which don't already exist
365 int64_t total_len = 0;
366 for( int i = 0; i < needed_idxbls.size(); i++ ) {
367 total_len += needed_idxbls[i]->get_video_frames();
370 // start progress bar. MWindow is locked inside this
371 mwindow->gui->lock_window("ProxyRender::create_needed_proxies");
372 progress = mwindow->mainprogress->
373 start_progress(_("Creating proxy files..."), total_len);
374 mwindow->gui->unlock_window();
376 ProxyFarm engine(mwindow, this, &needed_idxbls, &needed_proxies);
377 engine.process_packages();
378 printf("proxy: failed=%d canceled=%d\n", failed, progress->is_cancelled());
381 canceled = progress->is_cancelled();
382 progress->stop_progress();
383 delete progress; progress = 0;
385 if( failed && !canceled ) {
386 eprintf(_("Error making proxy."));
388 return !failed && !canceled ? 0 : 1;
392 ProxyWindow::ProxyWindow(MWindow *mwindow, ProxyDialog *dialog, int x, int y)
393 : BC_Window(_(PROGRAM_NAME ": Proxy settings"), x, y, WIDTH, HEIGHT,
396 this->mwindow = mwindow;
397 this->dialog = dialog;
399 // *** CONTEXT_HELP ***
400 context_help_set_keyword("Proxy");
403 ProxyWindow::~ProxyWindow()
405 lock_window("ProxyWindow::~ProxyWindow");
411 void ProxyWindow::create_objects()
413 lock_window("ProxyWindow::create_objects");
414 int margin = mwindow->theme->widget_border;
415 int xs10 = xS(10), x1 = xS(50);
416 int lmargin = margin + xs10;
417 int x = lmargin, y = margin+yS(10);
419 dialog->use_scaler = mwindow->edl->session->proxy_use_scaler;
420 dialog->orig_scale = mwindow->edl->session->proxy_scale;
421 dialog->auto_scale = mwindow->edl->session->proxy_auto_scale;
422 dialog->beeper_on = mwindow->edl->session->proxy_beep > 0 ? 1 : 0;
423 dialog->beeper_volume = mwindow->edl->session->proxy_beep;
424 dialog->new_scale = mwindow->edl->session->proxy_state != PROXY_INACTIVE ?
425 dialog->orig_scale : 0;
426 dialog->orig_w = mwindow->edl->session->output_w;
427 dialog->orig_h = mwindow->edl->session->output_h;
428 if( !dialog->use_scaler ) {
429 dialog->orig_w *= dialog->orig_scale;
430 dialog->orig_h *= dialog->orig_scale;
433 add_subwindow(title_bar1 = new BC_TitleBar(xs10, y, get_w()-xS(30), xS(20), xs10,
434 _("Scaling options")));
435 y += title_bar1->get_h() + 3*margin;
439 add_subwindow(text = new BC_Title(x, y, _("Scale factor:")));
440 int popupmenu_w = BC_PopupMenu::calculate_w(get_text_width(MEDIUMFONT, dialog->size_text[0])+xS(25));
441 x += text->get_w() + 2*margin;
442 add_subwindow(scale_factor = new ProxyMenu(mwindow, this, x, y, popupmenu_w, ""));
443 scale_factor->update_sizes();
444 x += popupmenu_w + margin;
445 ProxyTumbler *tumbler;
446 add_subwindow(tumbler = new ProxyTumbler(mwindow, this, x, y));
447 y += tumbler->get_h() + margin;
450 add_subwindow(text = new BC_Title(x, y, _("Media size: ")));
451 x += text->get_w() + margin;
452 add_subwindow(new_dimensions = new BC_Title(x, y, ""));
453 y += new_dimensions->get_h() + margin;
456 add_subwindow(text = new BC_Title(x, y, _("Active Scale: ")));
457 x += text->get_w() + margin;
458 add_subwindow(active_scale = new BC_Title(x, y, ""));
460 add_subwindow(text = new BC_Title(x, y, _("State: ")));
461 x += text->get_w() + margin;
462 add_subwindow(active_state = new BC_Title(x, y, ""));
463 y += active_scale->get_h() + margin;
465 add_subwindow(use_scaler = new ProxyUseScaler(this, x1, y));
466 y += use_scaler->get_h() + margin;
467 add_subwindow(auto_scale = new ProxyAutoScale(this, x1, y));
468 y += auto_scale->get_h() + 2*margin;
470 x = lmargin; y += yS(15);
471 format_tools = new ProxyFormatTools(mwindow, this, dialog->asset);
472 format_tools->create_objects(x, y, 0, 1, 0, 0, 0, 1, 0, 1, // skip the path
476 add_subwindow(title_bar2 = new BC_TitleBar(xs10, y, get_w()-xS(30), xS(20), xs10,
478 y += title_bar2->get_h() + 3*margin;
481 add_subwindow(text = new BC_Title(x, y, _("Volume:")));
482 x += text->get_w() + 2*margin;
483 add_subwindow(beep_on_done = new ProxyBeepOnDone(this, x, y));
484 x += beep_on_done->get_w() + margin + xS(10);
485 add_subwindow(beep_volume = new ProxyBeepVolume(this, x, y));
489 add_subwindow(new BC_OKButton(this));
490 add_subwindow(new BC_CancelButton(this));
495 ProxyFormatTools::ProxyFormatTools(MWindow *mwindow, ProxyWindow *pwindow, Asset *asset)
496 : FormatTools(mwindow, pwindow, asset)
498 this->pwindow = pwindow;
501 void ProxyFormatTools::update_format()
503 asset->save_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0);
504 FormatTools::update_format();
505 pwindow->use_scaler->update();
508 void ProxyWindow::update()
510 char string[BCSTRLEN];
511 dialog->scale_to_text(string, dialog->new_scale);
512 scale_factor->set_text(string);
513 int new_scale = dialog->new_scale;
514 if( new_scale < 1 ) new_scale = 1;
515 int new_w = dialog->orig_w / new_scale;
516 if( new_w & 1 ) ++new_w;
517 int new_h = dialog->orig_h / new_scale;
518 if( new_h & 1 ) ++new_h;
519 sprintf(string, "%dx%d", new_w, new_h);
520 new_dimensions->update(string);
521 use_scaler->update();
522 auto_scale->update();
523 int scale = mwindow->edl->session->proxy_state == PROXY_ACTIVE ?
524 mwindow->edl->session->proxy_scale :
525 mwindow->edl->session->proxy_state == PROXY_DISABLED ?
526 mwindow->edl->session->proxy_disabled_scale : 1;
527 sprintf(string, scale>1 ? "1/%d" : "%d", scale);
528 active_scale->update(string);
529 const char *state = "";
530 switch( mwindow->edl->session->proxy_state ) {
531 case PROXY_INACTIVE: state = _("Off"); break;
532 case PROXY_ACTIVE: state = _("Active"); break;
533 case PROXY_DISABLED: state = _("Disabled"); break;
535 active_state->update(state);
536 beep_on_done->update(dialog->beeper_on);
537 beep_volume->update(dialog->beeper_volume*100.f);
541 ProxyUseScaler::ProxyUseScaler(ProxyWindow *pwindow, int x, int y)
542 : BC_CheckBox(x, y, pwindow->dialog->use_scaler, _("Rescaled to project size (FFMPEG only)"))
544 this->pwindow = pwindow;
547 void ProxyUseScaler::update()
549 ProxyDialog *dialog = pwindow->dialog;
550 if( dialog->asset->format != FILE_FFMPEG ) dialog->use_scaler = 0;
551 BC_CheckBox::update(dialog->use_scaler);
552 int scaler_avail = dialog->asset->format == FILE_FFMPEG ? 1 : 0;
553 if( !scaler_avail && enabled ) disable();
554 if( scaler_avail && !enabled ) enable();
557 int ProxyUseScaler::handle_event()
559 pwindow->dialog->new_scale = 1;
560 pwindow->dialog->use_scaler = get_value();
561 pwindow->scale_factor->update_sizes();
566 ProxyAutoScale::ProxyAutoScale(ProxyWindow *pwindow, int x, int y)
567 : BC_CheckBox(x, y, pwindow->dialog->auto_scale, _("Creation of proxy on media loading"))
569 this->pwindow = pwindow;
572 void ProxyAutoScale::update()
574 ProxyDialog *dialog = pwindow->dialog;
575 int can_auto_scale = dialog->new_scale >= 1 ? 1 : 0;
576 if( !can_auto_scale ) dialog->auto_scale = 0;
577 BC_CheckBox::update(dialog->auto_scale);
578 if( !can_auto_scale && enabled ) disable();
579 if( can_auto_scale && !enabled ) enable();
582 int ProxyAutoScale::handle_event()
584 pwindow->dialog->auto_scale = get_value();
589 ProxyBeepOnDone::ProxyBeepOnDone(ProxyWindow *pwindow, int x, int y)
590 : BC_CheckBox(x, y, pwindow->dialog->beeper_on)
592 this->pwindow = pwindow;
595 int ProxyBeepOnDone::handle_event()
597 pwindow->dialog->beeper_on = get_value();
601 ProxyBeepVolume::ProxyBeepVolume(ProxyWindow *pwindow, int x, int y)
602 : BC_FSlider(x, y, 0, xS(160), xS(160), 0.f, 100.f,
603 pwindow->dialog->beeper_volume*100.f, 0)
605 this->pwindow = pwindow;
608 int ProxyBeepVolume::handle_event()
610 pwindow->dialog->beeper_volume = get_value()/100.f;
611 pwindow->dialog->beeper_on = pwindow->dialog->beeper_volume>0 ? 1 : 0;
617 ProxyMenu::ProxyMenu(MWindow *mwindow, ProxyWindow *pwindow,
618 int x, int y, int w, const char *text)
619 : BC_PopupMenu(x, y, w, text, 1)
621 this->mwindow = mwindow;
622 this->pwindow = pwindow;
625 void ProxyMenu::update_sizes()
627 while( total_items() > 0 ) del_item(0);
628 ProxyDialog *dialog = pwindow->dialog;
629 dialog->calculate_sizes();
630 for( int i=0; i < dialog->total_sizes; i++ )
631 add_item(new BC_MenuItem(dialog->size_text[i]));
634 int ProxyMenu::handle_event()
636 ProxyDialog *dialog = pwindow->dialog;
637 for( int i = 0; i < dialog->total_sizes; i++ ) {
638 if( !strcmp(get_text(), pwindow->dialog->size_text[i]) ) {
639 dialog->new_scale = pwindow->dialog->size_factors[i];
648 ProxyTumbler::ProxyTumbler(MWindow *mwindow, ProxyWindow *pwindow, int x, int y)
649 : BC_Tumbler(x, y, 0)
651 this->mwindow = mwindow;
652 this->pwindow = pwindow;
655 int ProxyTumbler::handle_up_event()
657 if( pwindow->dialog->new_scale > 1 ) {
659 for( i = 0; i < pwindow->dialog->total_sizes; i++ ) {
660 if( pwindow->dialog->new_scale == pwindow->dialog->size_factors[i] ) {
662 pwindow->dialog->new_scale = pwindow->dialog->size_factors[i];
672 int ProxyTumbler::handle_down_event()
675 for( i = 0; i < pwindow->dialog->total_sizes - 1; i++ ) {
676 if( pwindow->dialog->new_scale == pwindow->dialog->size_factors[i] ) {
678 pwindow->dialog->new_scale = pwindow->dialog->size_factors[i];
689 ProxyPackage::ProxyPackage()
694 ProxyClient::ProxyClient(MWindow *mwindow,
695 ProxyRender *proxy_render, ProxyFarm *server)
698 this->mwindow = mwindow;
699 this->proxy_render = proxy_render;
704 ProxyClient::~ProxyClient()
706 delete render_engine;
708 video_cache->remove_user();
712 void ProxyClient::process_package(LoadPackage *ptr)
714 if( proxy_render->failed ) return;
715 if( proxy_render->is_canceled() ) return;
717 EDL *edl = mwindow->edl;
718 Preferences *preferences = mwindow->preferences;
719 ProxyPackage *package = (ProxyPackage*)ptr;
720 Indexable *orig = package->orig_idxbl;
721 Asset *proxy = package->proxy_asset;
722 //printf("%s %s\n", orig->path, proxy->path);
723 VRender *vrender = 0;
724 int jobs = proxy_render->needed_proxies.size();
725 int processors = preferences->project_smp / jobs + 1, result = 0;
727 // each cpu should process at least about 1 MB, or it thrashes
728 int size = edl->session->output_w * edl->session->output_h * 4;
729 int cpus = size / 0x100000 + 1;
730 if( processors > cpus ) processors = cpus;
732 if( orig->is_asset ) {
734 src_file->set_processors(processors);
735 src_file->set_preload(edl->session->playback_preload);
736 src_file->set_subtitle(edl->session->decode_subtitles ?
737 edl->session->subtitle_number : -1);
738 src_file->set_interpolate_raw(edl->session->interpolate_raw);
739 src_file->set_white_balance_raw(edl->session->white_balance_raw);
740 if( src_file->open_file(preferences, (Asset*)orig, 1, 0) != FILE_OK )
744 TransportCommand command(preferences);
745 command.command = CURRENT_FRAME;
746 command.get_edl()->copy_all((EDL *)orig);
747 command.change_type = CHANGE_ALL;
748 command.realtime = 0;
749 render_engine = new RenderEngine(0, preferences, 0, 0);
750 render_engine->set_vcache(video_cache = new CICache(preferences));
751 render_engine->arm_command(&command);
752 if( !(vrender = render_engine->vrender) )
756 // go to the next asset if the reader fails
757 // proxy_render->failed = 1;
762 dst_file.set_processors(processors);
763 result = dst_file.open_file(preferences, proxy, 0, 1);
765 proxy_render->failed = 1;
766 ::remove(proxy->path);
770 dst_file.start_video_thread(1, edl->session->color_model,
771 processors > 1 ? 2 : 1, 0);
773 int src_w = orig->get_w(), src_h = orig->get_h();
774 VFrame src_frame(src_w,src_h, edl->session->color_model);
776 OverlayFrame scaler(processors);
777 int64_t video_length = orig->get_video_frames();
778 if( video_length < 0 ) video_length = 1;
780 for( int64_t i=0; i<video_length &&
781 !proxy_render->failed && !proxy_render->is_canceled(); ++i ) {
782 if( orig->is_asset ) {
783 src_file->set_video_position(i, 0);
784 result = src_file->read_frame(&src_frame);
787 result = vrender->process_buffer(&src_frame, i, 0);
788 //printf("result=%d\n", result);
791 // go to the next asset if the reader fails
792 // proxy_render->failed = 1;
796 // have to write after getting the video buffer or it locks up
797 VFrame ***dst_frames = dst_file.get_video_buffer();
798 VFrame *dst_frame = dst_frames[0][0];
799 int dst_w = dst_frame->get_w(), dst_h = dst_frame->get_h();
800 scaler.overlay(dst_frame, &src_frame,
801 0,0, src_w,src_h, 0,0, dst_w,dst_h,
802 1.0, TRANSFER_REPLACE, NEAREST_NEIGHBOR);
803 result = dst_file.write_video_buffer(1);
805 // only fail if the writer fails
806 proxy_render->failed = 1;
809 proxy_render->update_progress();
811 if( !proxy_render->failed && !proxy_render->is_canceled() ) {
812 Asset *asset = edl->assets->update(proxy);
813 asset->proxy_scale = proxy_render->asset_scale;
814 int scale = asset->proxy_scale;
815 if( !scale ) scale = 1;
816 asset->width = asset->actual_width * scale;
817 asset->height = asset->actual_height * scale;
818 mwindow->mainindexes->add_indexable(asset);
819 mwindow->mainindexes->start_build();
822 ::remove(proxy->path);
826 ProxyFarm::ProxyFarm(MWindow *mwindow, ProxyRender *proxy_render,
827 ArrayList<Indexable*> *orig_idxbls,
828 ArrayList<Asset*> *proxy_assets)
829 : LoadServer(MIN(mwindow->preferences->processors, proxy_assets->size()),
830 proxy_assets->size())
832 this->mwindow = mwindow;
833 this->proxy_render = proxy_render;
834 this->orig_idxbls = orig_idxbls;
835 this->proxy_assets = proxy_assets;
838 void ProxyFarm::init_packages()
840 for( int i = 0; i < get_total_packages(); i++ ) {
841 ProxyPackage *package = (ProxyPackage*)get_package(i);
842 package->proxy_asset = proxy_assets->get(i);
843 package->orig_idxbl = orig_idxbls->get(i);
847 LoadClient* ProxyFarm::new_client()
849 return new ProxyClient(mwindow, proxy_render, this);
852 LoadPackage* ProxyFarm::new_package()
854 return new ProxyPackage;