From: Good Guy Date: Wed, 25 Sep 2019 17:18:21 +0000 (-0600) Subject: rework proxy scaler, fix crop-gui coord, video_data tweak for proxy_format X-Git-Tag: 2019-09~4 X-Git-Url: https://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=ac8f3979437fb45effb135a1bb6bee871f52d635;p=goodguy%2Fcinelerra.git rework proxy scaler, fix crop-gui coord, video_data tweak for proxy_format --- diff --git a/cinelerra-5.1/cinelerra/asset.C b/cinelerra-5.1/cinelerra/asset.C index eebc6f27..48dfca3c 100644 --- a/cinelerra-5.1/cinelerra/asset.C +++ b/cinelerra-5.1/cinelerra/asset.C @@ -147,6 +147,7 @@ void Asset::reset_video() layers = 0; actual_width = width = 0; actual_height = height = 0; + proxy_scale = 0; // not a proxy video_length = 0; single_frame = 0; vmpeg_cmodel = BC_YUV420P; @@ -206,6 +207,7 @@ void Asset::copy_format(Asset *asset, int do_index) height = asset->height; actual_width = asset->actual_width; actual_height = asset->actual_height; + proxy_scale = asset->proxy_scale; strcpy(vcodec, asset->vcodec); strcpy(acodec, asset->acodec); @@ -479,6 +481,7 @@ int Asset::read_video(FileXML *file) actual_width = file->tag.get_property("ACTUAL_WIDTH", actual_width); height = file->tag.get_property("HEIGHT", height); width = file->tag.get_property("WIDTH", width); + proxy_scale = file->tag.get_property("PROXY_SCALE", 0); layers = file->tag.get_property("LAYERS", layers); program = file->tag.get_property("PROGRAM", program); // This is loaded from the index file after the EDL but this @@ -626,6 +629,7 @@ int Asset::write_video(FileXML *file) file->tag.set_property("ACTUAL_WIDTH", actual_width); file->tag.set_property("HEIGHT", height); file->tag.set_property("WIDTH", width); + file->tag.set_property("PROXY_SCALE", proxy_scale); file->tag.set_property("LAYERS", layers); file->tag.set_property("PROGRAM", program); file->tag.set_property("FRAMERATE", frame_rate); @@ -727,6 +731,7 @@ void Asset::load_defaults(BC_Hash *defaults, width = GET_DEFAULT("WIDTH", width); actual_height = GET_DEFAULT("ACTUAL_HEIGHT", actual_height); actual_width = GET_DEFAULT("ACTUAL_WIDTH", actual_width); + proxy_scale = GET_DEFAULT("PROXY_SCALE", proxy_scale); program = GET_DEFAULT("PROGRAM", program); layers = GET_DEFAULT("LAYERS", layers); if(EQUIV(frame_rate, 0)) frame_rate = GET_DEFAULT("FRAMERATE", frame_rate); @@ -885,6 +890,7 @@ void Asset::save_defaults(BC_Hash *defaults, UPDATE_DEFAULT("WIDTH", width); UPDATE_DEFAULT("ACTUAL_HEIGHT", actual_height); UPDATE_DEFAULT("ACTUAL_WIDTH", actual_width); + UPDATE_DEFAULT("PROXY_SCALE", proxy_scale); UPDATE_DEFAULT("PROGRAM", program); UPDATE_DEFAULT("LAYERS", layers); UPDATE_DEFAULT("FRAMERATE", frame_rate); @@ -925,9 +931,13 @@ int Asset::dump(FILE *fp) char string[BCTEXTLEN]; ilacemode_to_xmltext(string, interlace_mode); fprintf(fp," video_data %d program %d layers %d framerate %f width %d" - " height %d vcodec %4.4s aspect_ratio %f ilace_mode %s\n", + " height %d vcodec %s aspect_ratio %f ilace_mode %s\n", video_data, layers, program, frame_rate, width, height, vcodec, aspect_ratio,string); + fprintf(fp," actual_width %d actual_height %d proxy_scale %d" + " video_length %jd repeat %d\n", + actual_width, actual_height, proxy_scale, video_length, + single_frame); fprintf(fp," video_length %jd repeat %d\n", video_length, single_frame); fprintf(fp," mov_sphere=%d jpeg_sphere=%d\n", mov_sphere, jpeg_sphere); return 0; diff --git a/cinelerra-5.1/cinelerra/asset.h b/cinelerra-5.1/cinelerra/asset.h index 0a2372cb..80a29eb5 100644 --- a/cinelerra-5.1/cinelerra/asset.h +++ b/cinelerra-5.1/cinelerra/asset.h @@ -146,6 +146,8 @@ public: int actual_width, actual_height; int width, height; +// scale factor or 0 if not proxy + int proxy_scale; // String or FourCC describing compression char vcodec[BCTEXTLEN]; diff --git a/cinelerra-5.1/cinelerra/cwindowtool.C b/cinelerra-5.1/cinelerra/cwindowtool.C index e701b9d6..8ba0e3b2 100644 --- a/cinelerra-5.1/cinelerra/cwindowtool.C +++ b/cinelerra-5.1/cinelerra/cwindowtool.C @@ -360,7 +360,7 @@ CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, float value, int l } CWindowCoord::CWindowCoord(CWindowToolGUI *gui, int x, int y, int value) - : BC_TumbleTextBox(gui, (int64_t)value, (int64_t)-65536, (int64_t)65536, x, y, 70, 3) + : BC_TumbleTextBox(gui, (int64_t)value, (int64_t)-65536, (int64_t)65536, x, y, 70) { this->gui = gui; } diff --git a/cinelerra-5.1/cinelerra/edl.C b/cinelerra-5.1/cinelerra/edl.C index fd481cea..fc47bb3c 100644 --- a/cinelerra-5.1/cinelerra/edl.C +++ b/cinelerra-5.1/cinelerra/edl.C @@ -1627,39 +1627,31 @@ void EDL::rescale_proxy(int orig_scale, int new_scale) } } -void EDL::set_proxy(int new_scale, int use_scaler, +void EDL::set_proxy(int new_scale, int new_use_scaler, ArrayList *orig_assets, ArrayList *proxy_assets) { int orig_scale = session->proxy_scale; - int orig_use_scaler = session->proxy_use_scaler; - -// rescale to full size asset in read_frame session->proxy_scale = new_scale; - session->proxy_use_scaler = use_scaler; - - if( use_scaler ) { - for( int i=0; isize(); ++i ) { - Asset *proxy_asset = (Asset *)proxy_assets->get(i); - proxy_asset->width = orig_assets->get(i)->get_w(); - proxy_asset->height = orig_assets->get(i)->get_h(); - } - new_scale = 1; - } - - if( !orig_use_scaler ) - rescale_proxy(orig_scale, new_scale); - + int orig_use_scaler = session->proxy_use_scaler; + session->proxy_use_scaler = new_use_scaler; + if( orig_use_scaler ) orig_scale = 1; + int scale = new_use_scaler ? new_scale : 1; + int asset_scale = new_scale == 1 && !new_use_scaler ? 0 : scale; // change original assets to proxy assets - int folder_no = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER; + int folder_no = new_use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER; for( int i=0,n=proxy_assets->size(); iget(i); proxy_idxbl->folder_no = folder_no; if( !proxy_idxbl->is_asset ) continue; Asset *proxy_asset = assets->update((Asset *)proxy_idxbl); - if( proxy_asset == (Asset *)proxy_idxbl ) continue; - proxy_asset->width = proxy_idxbl->get_w(); - proxy_asset->height = proxy_idxbl->get_h(); + proxy_asset->width = proxy_asset->actual_width * scale; + proxy_asset->height = proxy_asset->actual_height * scale; + proxy_asset->proxy_scale = asset_scale; } +// rescale to full size asset in read_frame + if( new_use_scaler ) new_scale = 1; + rescale_proxy(orig_scale, new_scale); + // replace track contents for( Track *track=tracks->first; track; track=track->next ) { if( track->data_type != TRACK_VIDEO ) continue; @@ -1706,15 +1698,17 @@ void EDL::set_proxy(int new_scale, int use_scaler, } } -void EDL::add_proxy(int use_scaler, - ArrayList *orig_assets, ArrayList *proxy_assets) +void EDL::add_proxy(ArrayList *orig_assets, ArrayList *proxy_assets) { - if( use_scaler ) { - for( int i=0,n=proxy_assets->size(); iget(i); - proxy_asset->width = orig_assets->get(i)->get_w(); - proxy_asset->height = orig_assets->get(i)->get_h(); - } + int asset_scale = session->proxy_scale; + if( asset_scale == 1 ) asset_scale = 0; + int scale = !asset_scale ? 1 : asset_scale; +// update proxy geom using scale + for( int i=0; isize(); ++i ) { + Asset *proxy_asset = (Asset *)proxy_assets->get(i); + proxy_asset->proxy_scale = asset_scale; + proxy_asset->width = proxy_asset->actual_width * scale; + proxy_asset->height = proxy_asset->actual_height * scale; } // change original assets to proxy assets diff --git a/cinelerra-5.1/cinelerra/edl.h b/cinelerra-5.1/cinelerra/edl.h index b1c4fd3f..361996ca 100644 --- a/cinelerra-5.1/cinelerra/edl.h +++ b/cinelerra-5.1/cinelerra/edl.h @@ -269,8 +269,7 @@ public: void rescale_proxy(int orig_scale, int new_scale); void set_proxy(int new_scale, int use_scaler, ArrayList *orig_assets, ArrayList *proxy_assets); - void add_proxy(int use_scaler, - ArrayList *orig_assets, ArrayList *proxy_assets); + void add_proxy(ArrayList *orig_assets, ArrayList *proxy_assets); Asset *get_proxy_asset(); Track *add_new_track(int data_type); diff --git a/cinelerra-5.1/cinelerra/filelist.C b/cinelerra-5.1/cinelerra/filelist.C index f4f26dac..591cb811 100644 --- a/cinelerra-5.1/cinelerra/filelist.C +++ b/cinelerra-5.1/cinelerra/filelist.C @@ -131,12 +131,12 @@ int FileList::open_file(int rd, int wr) else result = 1; if( !result ) { - int width = asset->width; - int height = asset->height; asset->actual_width = asset->width; - if( width ) asset->width = width; asset->actual_height = asset->height; - if( height ) asset->height = height; + int scale = asset->proxy_scale; + if( !scale ) scale = 1; + asset->width = asset->actual_width * scale; + asset->height = asset->actual_height * scale; asset->layers = 1; if( !asset->frame_rate ) asset->frame_rate = 10; diff --git a/cinelerra-5.1/cinelerra/indexfile.C b/cinelerra-5.1/cinelerra/indexfile.C index aedbfbb8..3e1ce389 100644 --- a/cinelerra-5.1/cinelerra/indexfile.C +++ b/cinelerra-5.1/cinelerra/indexfile.C @@ -328,6 +328,11 @@ int IndexFile::open_source() FileSystem fs; asset->index_state->index_bytes = fs.get_size(asset->path); source_length = source->get_audio_length(); + int proxy_scale = asset->proxy_scale; + if( proxy_scale > 0 ) { + asset->width = asset->actual_width * proxy_scale; + asset->height = asset->actual_height * proxy_scale; + } } } else diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C index 35bd21e4..a99d3098 100644 --- a/cinelerra-5.1/cinelerra/mwindow.C +++ b/cinelerra-5.1/cinelerra/mwindow.C @@ -2275,9 +2275,8 @@ int MWindow::render_proxy(ArrayList &new_idxbls) Asset *format_asset = new Asset; format_asset->format = FILE_FFMPEG; format_asset->load_defaults(defaults, "PROXY_", 1, 1, 0, 0, 0); - ProxyRender proxy_render(this, format_asset); int new_scale = edl->session->proxy_scale; - int use_scaler = edl->session->proxy_use_scaler; + ProxyRender proxy_render(this, format_asset, new_scale); for( int i=0; i &new_idxbls) // render needed proxies int result = proxy_render.create_needed_proxies(new_scale); if( !result ) { - add_proxy(use_scaler, - &proxy_render.orig_idxbls, &proxy_render.orig_proxies); + add_proxy(&proxy_render.orig_idxbls, &proxy_render.orig_proxies); } format_asset->remove_user(); return !result ? proxy_render.needed_proxies.size() : -1; @@ -2344,7 +2342,9 @@ int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler) edl->Garbage::add_user(); save_backup(); undo_before(_("proxy"), this); - ProxyRender proxy_render(this, asset); + int asset_scale = new_scale == 1 ? 0 : + !new_use_scaler ? 1 : new_scale; + ProxyRender proxy_render(this, asset, asset_scale); // revert project to original size from current size // remove all session proxy assets at the at the current proxy_scale diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h index 6083242d..6eb384ce 100644 --- a/cinelerra-5.1/cinelerra/mwindow.h +++ b/cinelerra-5.1/cinelerra/mwindow.h @@ -522,9 +522,8 @@ public: int modify_pluginhandles(); void finish_modify_handles(); void rescale_proxy(EDL *clip, int orig_scale, int new_scale); - void add_proxy(int use_scaler, - ArrayList *orig_assets, - ArrayList *proxy_assets); + void add_proxy(ArrayList *orig_assets, + ArrayList *proxy_assets); int render_proxy(ArrayList &new_idxbls); void beep(double freq, double secs, double gain); int enable_proxy(); diff --git a/cinelerra-5.1/cinelerra/mwindowedit.C b/cinelerra-5.1/cinelerra/mwindowedit.C index 82c4f1e4..2d09eeb0 100644 --- a/cinelerra-5.1/cinelerra/mwindowedit.C +++ b/cinelerra-5.1/cinelerra/mwindowedit.C @@ -2457,10 +2457,9 @@ void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale) edl->rescale_proxy(orig_scale, new_scale); } -void MWindow::add_proxy(int use_scaler, - ArrayList *orig_assets, ArrayList *proxy_assets) +void MWindow::add_proxy(ArrayList *orig_assets, ArrayList *proxy_assets) { - edl->add_proxy(use_scaler, orig_assets, proxy_assets); + edl->add_proxy(orig_assets, proxy_assets); } void MWindow::cut_commercials() diff --git a/cinelerra-5.1/cinelerra/proxy.C b/cinelerra-5.1/cinelerra/proxy.C index fd1ba562..a0f5fa72 100644 --- a/cinelerra-5.1/cinelerra/proxy.C +++ b/cinelerra-5.1/cinelerra/proxy.C @@ -88,6 +88,7 @@ ProxyDialog::ProxyDialog(MWindow *mwindow) strcpy(asset->fformat, "mpeg"); strcpy(asset->vcodec, "mpeg.mpeg"); asset->ff_video_bitrate = 2000000; + asset->video_data = 1; bzero(size_text, sizeof(char*) * MAX_SIZES); bzero(size_factors, sizeof(int) * MAX_SIZES); @@ -230,10 +231,11 @@ int ProxyRender::from_proxy_path(char *new_path, Indexable *indexable, int scale return 0; } -ProxyRender::ProxyRender(MWindow *mwindow, Asset *format_asset) +ProxyRender::ProxyRender(MWindow *mwindow, Asset *format_asset, int asset_scale) { this->mwindow = mwindow; this->format_asset = format_asset; + this->asset_scale = asset_scale; progress = 0; counter_lock = new Mutex("ProxyDialog::counter_lock"); total_rendered = 0; @@ -442,6 +444,7 @@ ProxyFormatTools::ProxyFormatTools(MWindow *mwindow, ProxyWindow *pwindow, Asset void ProxyFormatTools::update_format() { + asset->save_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0); FormatTools::update_format(); pwindow->use_scaler->update(); } @@ -722,7 +725,12 @@ void ProxyClient::process_package(LoadPackage *ptr) proxy_render->update_progress(); } if( !proxy_render->failed && !proxy_render->is_canceled() ) { - Asset *asset = mwindow->edl->assets->update(proxy); + Asset *asset = edl->assets->update(proxy); + asset->proxy_scale = proxy_render->asset_scale; + int scale = asset->proxy_scale; + if( !scale ) scale = 1; + asset->width = asset->actual_width * scale; + asset->height = asset->actual_height * scale; mwindow->mainindexes->add_next_asset(0, asset); mwindow->mainindexes->start_build(); } diff --git a/cinelerra-5.1/cinelerra/proxy.h b/cinelerra-5.1/cinelerra/proxy.h index f48df968..7fa9fd26 100644 --- a/cinelerra-5.1/cinelerra/proxy.h +++ b/cinelerra-5.1/cinelerra/proxy.h @@ -64,7 +64,7 @@ public: class ProxyRender { public: - ProxyRender(MWindow *mwindow, Asset *format_asset); + ProxyRender(MWindow *mwindow, Asset *format_asset, int asset_scale); ~ProxyRender(); void to_proxy_path(char *new_path, Indexable *indexable, int scale); static int from_proxy_path(char *new_path, Indexable *indexable, int scale); @@ -88,6 +88,7 @@ public: Mutex *counter_lock; int total_rendered; int failed, canceled; + int asset_scale; }; class ProxyDialog : public BC_DialogThread