From 48375f1b11fa903519ef677c1f118510635c0a3b Mon Sep 17 00:00:00 2001 From: Good Guy Date: Thu, 2 Jul 2015 14:51:18 -0600 Subject: [PATCH] add ffmpeg dvd render option, fix undo deadlock, fix a few plugin interface gaffs --- cinelerra-5.0/cinelerra/batchrender.C | 110 ++++++++++++++++++-------- cinelerra-5.0/cinelerra/batchrender.h | 11 +++ cinelerra-5.0/cinelerra/ffmpeg.C | 7 ++ cinelerra-5.0/cinelerra/filempeg.C | 1 - cinelerra-5.0/cinelerra/mwindow.C | 8 ++ cinelerra-5.0/cinelerra/mwindowedit.C | 3 +- cinelerra-5.0/mpeg2enc/Makefile | 3 +- cinelerra-5.0/plugins/Makefile | 11 ++- 8 files changed, 112 insertions(+), 42 deletions(-) diff --git a/cinelerra-5.0/cinelerra/batchrender.C b/cinelerra-5.0/cinelerra/batchrender.C index 16d02ba1..6b8373bb 100644 --- a/cinelerra-5.0/cinelerra/batchrender.C +++ b/cinelerra-5.0/cinelerra/batchrender.C @@ -1354,6 +1354,7 @@ CreateDVD_Thread::CreateDVD_Thread(MWindow *mwindow) this->use_wide_audio = 0; this->use_wide_aspect = 0; this->use_label_chapters = 0; + this->use_ffmpeg = 0; } CreateDVD_Thread::~CreateDVD_Thread() @@ -1419,8 +1420,10 @@ int CreateDVD_Thread::create_dvd_jobs(ArrayList *jobs, fprintf(fp,"#!/bin/bash\n"); fprintf(fp,"echo \"running %s\" $# $*\n", script_filename); fprintf(fp,"\n"); - fprintf(fp,"mplex -f 8 -o $1/dvd.mpg $1/dvd.m2v $1/dvd.ac3\n"); - fprintf(fp,"\n"); + if( !use_ffmpeg ) { + fprintf(fp,"mplex -f 8 -o $1/dvd.mpg $1/dvd.m2v $1/dvd.ac3\n"); + fprintf(fp,"\n"); + } fprintf(fp,"rm -rf $1/iso\n"); fprintf(fp,"mkdir -p $1/iso\n"); fprintf(fp,"\n"); @@ -1515,43 +1518,71 @@ int CreateDVD_Thread::create_dvd_jobs(ArrayList *jobs, strcpy(&job->edl_path[0], xml_filename); Asset *asset = job->asset; - sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir); - asset->video_data = 1; - asset->format = FILE_VMPEG; asset->layers = DVD_STREAMS; asset->frame_rate = session->frame_rate; asset->width = session->output_w; asset->height = session->output_h; asset->aspect_ratio = session->aspect_w / session->aspect_h; - asset->vmpeg_cmodel = BC_YUV420P; - asset->vmpeg_fix_bitrate = 1; - asset->vmpeg_bitrate = vid_bitrate; - asset->vmpeg_quantization = 15; - asset->vmpeg_iframe_distance = 15; - asset->vmpeg_progressive = 0; - asset->vmpeg_denoise = 0; - asset->vmpeg_seq_codes = 0; - asset->vmpeg_derivative = 2; - asset->vmpeg_preset = 8; - asset->vmpeg_field_order = 0; - asset->vmpeg_pframe_distance = 0; - job = new BatchRenderJob(mwindow->preferences); - jobs->append(job); - strcpy(&job->edl_path[0], xml_filename); - asset = job->asset; - - sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir); - asset->audio_data = 1; - asset->format = FILE_AC3; - asset->channels = session->audio_channels; - asset->sample_rate = session->sample_rate; - asset->bits = 16; - asset->byte_order = 0; - asset->signed_ = 1; - asset->header = 0; - asset->dither = 0; - asset->ac3_bitrate = DVD_KAUDIO_RATE; + if( use_ffmpeg ) { + char option_path[BCTEXTLEN]; + sprintf(&asset->path[0],"%s/dvd.mpg", asset_dir); + asset->format = FILE_FFMPEG; + strcpy(asset->fformat, "dvd"); + + asset->audio_data = 1; + strcpy(asset->acodec, "dvd.dvd"); + FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec); + FFMPEG::load_options(option_path, asset->ff_audio_options, + sizeof(asset->ff_audio_options)); + asset->ff_audio_bitrate = DVD_KAUDIO_RATE * 1000; + + asset->video_data = 1; + strcpy(asset->vcodec, "dvd.dvd"); + FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec); + FFMPEG::load_options(option_path, asset->ff_video_options, + sizeof(asset->ff_video_options)); + asset->ff_video_bitrate = vid_bitrate; + asset->ff_video_quality = 0; + + int len = strlen(asset->ff_video_options); + char *cp = asset->ff_video_options + len; + snprintf(cp, sizeof(asset->ff_video_options)-len-1, + "aspect %.5f\n", asset->aspect_ratio); + } + else { + sprintf(&asset->path[0],"%s/dvd.m2v", asset_dir); + asset->video_data = 1; + asset->format = FILE_VMPEG; + asset->vmpeg_cmodel = BC_YUV420P; + asset->vmpeg_fix_bitrate = 1; + asset->vmpeg_bitrate = vid_bitrate; + asset->vmpeg_quantization = 15; + asset->vmpeg_iframe_distance = 15; + asset->vmpeg_progressive = 0; + asset->vmpeg_denoise = 0; + asset->vmpeg_seq_codes = 0; + asset->vmpeg_derivative = 2; + asset->vmpeg_preset = 8; + asset->vmpeg_field_order = 0; + asset->vmpeg_pframe_distance = 0; + job = new BatchRenderJob(mwindow->preferences); + jobs->append(job); + strcpy(&job->edl_path[0], xml_filename); + asset = job->asset; + + sprintf(&asset->path[0],"%s/dvd.ac3", asset_dir); + asset->audio_data = 1; + asset->format = FILE_AC3; + asset->channels = session->audio_channels; + asset->sample_rate = session->sample_rate; + asset->bits = 16; + asset->byte_order = 0; + asset->signed_ = 1; + asset->header = 0; + asset->dither = 0; + asset->ac3_bitrate = DVD_KAUDIO_RATE; + } job = new BatchRenderJob(mwindow->preferences); jobs->append(job); @@ -1635,6 +1666,7 @@ BC_Window* CreateDVD_Thread::new_gui() use_wide_audio = 0; use_wide_aspect = 0; use_label_chapters = 0; + use_ffmpeg = 0; option_presets(); int scr_x = mwindow->gui->get_screen_x(0, -1); int scr_w = mwindow->gui->get_screen_w(0, -1); @@ -1858,6 +1890,16 @@ CreateDVD_WideAspect::~CreateDVD_WideAspect() { } +CreateDVD_UseFFMpeg::CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y) + : BC_CheckBox(x, y, &gui->thread->use_ffmpeg, "Use FFMPEG") +{ + this->gui = gui; +} + +CreateDVD_UseFFMpeg::~CreateDVD_UseFFMpeg() +{ +} + @@ -1915,6 +1957,8 @@ void CreateDVD_GUI::create_objects() int x1 = x + 150, x2 = x1 + 150; need_inverse_telecine = new CreateDVD_InverseTelecine(this, x1, y); add_subwindow(need_inverse_telecine); + need_use_ffmpeg = new CreateDVD_UseFFMpeg(this, x2, y); + add_subwindow(need_use_ffmpeg); y += need_deinterlace->get_h() + pady/2; need_scale = new CreateDVD_Scale(this, x, y); add_subwindow(need_scale); diff --git a/cinelerra-5.0/cinelerra/batchrender.h b/cinelerra-5.0/cinelerra/batchrender.h index a95ab589..3fa7418b 100644 --- a/cinelerra-5.0/cinelerra/batchrender.h +++ b/cinelerra-5.0/cinelerra/batchrender.h @@ -343,6 +343,7 @@ public: int use_scale, use_resize_tracks; int use_wide_audio, use_wide_aspect; int use_histogram, use_label_chapters; + int use_ffmpeg; }; class CreateDVD_OK : public BC_OKButton @@ -472,6 +473,15 @@ public: CreateDVD_GUI *gui; }; +class CreateDVD_UseFFMpeg : public BC_CheckBox +{ +public: + CreateDVD_UseFFMpeg(CreateDVD_GUI *gui, int x, int y); + ~CreateDVD_UseFFMpeg(); + + CreateDVD_GUI *gui; +}; + class CreateDVD_GUI : public BC_Window { public: @@ -494,6 +504,7 @@ public: CreateDVD_Deinterlace *need_deinterlace; CreateDVD_InverseTelecine *need_inverse_telecine; CreateDVD_Scale *need_scale; + CreateDVD_UseFFMpeg *need_use_ffmpeg; CreateDVD_ResizeTracks *need_resize_tracks; CreateDVD_Histogram *need_histogram; CreateDVD_WideAudio *need_wide_audio; diff --git a/cinelerra-5.0/cinelerra/ffmpeg.C b/cinelerra-5.0/cinelerra/ffmpeg.C index 16d6fe05..af0c5486 100644 --- a/cinelerra-5.0/cinelerra/ffmpeg.C +++ b/cinelerra-5.0/cinelerra/ffmpeg.C @@ -931,10 +931,15 @@ AVRational FFMPEG::check_frame_rate(AVCodec *codec, double frame_rate) AVRational FFMPEG::to_sample_aspect_ratio(double aspect_ratio) { +#if 1 int height = 1000000, width = height * aspect_ratio; float w, h; MWindow::create_aspect_ratio(w, h, width, height); return (AVRational){(int)w, (int)h}; +#else +// square pixels + return (AVRational){1, 1}; +#endif } AVRational FFMPEG::to_time_base(int sample_rate) @@ -1428,6 +1433,7 @@ int FFMPEG::open_encoder(const char *type, const char *spec) break; } if( asset->ff_audio_bitrate > 0 ) { + ctx->bit_rate = asset->ff_audio_bitrate; char arg[BCSTRLEN]; sprintf(arg, "%d", asset->ff_audio_bitrate); av_dict_set(&sopts, "b", arg, 0); @@ -1473,6 +1479,7 @@ int FFMPEG::open_encoder(const char *type, const char *spec) break; } if( asset->ff_video_bitrate > 0 ) { + ctx->bit_rate = asset->ff_video_bitrate; char arg[BCSTRLEN]; sprintf(arg, "%d", asset->ff_video_bitrate); av_dict_set(&sopts, "b", arg, 0); diff --git a/cinelerra-5.0/cinelerra/filempeg.C b/cinelerra-5.0/cinelerra/filempeg.C index 37913225..6e5da23a 100644 --- a/cinelerra-5.0/cinelerra/filempeg.C +++ b/cinelerra-5.0/cinelerra/filempeg.C @@ -518,7 +518,6 @@ int FileMPEG::open_file(int rd, int wr) append_vcommand_line("-q"); append_vcommand_line(quant_string); } - append_vcommand_line(!asset->vmpeg_fix_bitrate ? quant_string : ""); append_vcommand_line("-n"); append_vcommand_line(iframe_string); append_vcommand_line(asset->vmpeg_progressive ? "-p" : ""); diff --git a/cinelerra-5.0/cinelerra/mwindow.C b/cinelerra-5.0/cinelerra/mwindow.C index e992fe1d..c528a4ab 100644 --- a/cinelerra-5.0/cinelerra/mwindow.C +++ b/cinelerra-5.0/cinelerra/mwindow.C @@ -2662,8 +2662,16 @@ static inline int gcd(int m, int n) int MWindow::create_aspect_ratio(float &w, float &h, int width, int height) { + w = 1; h = 1; if(!width || !height) return 1; double ar = (double)width / height; +// square-ish pixels + if( EQUIV(ar, 1.0000) ) return 0; + if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; } + if( EQUIV(ar, 1.7777) ) { w = 16; h = 9; return 0; } + if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; } + if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; } + if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; } int ww = width, hh = height; // numerator, denominator must be under mx int mx = 255, n = gcd(ww, hh); diff --git a/cinelerra-5.0/cinelerra/mwindowedit.C b/cinelerra-5.0/cinelerra/mwindowedit.C index 883efa79..a8f798df 100644 --- a/cinelerra-5.0/cinelerra/mwindowedit.C +++ b/cinelerra-5.0/cinelerra/mwindowedit.C @@ -2475,8 +2475,7 @@ void MWindow::undo_entry(BC_WindowBase *calling_window_gui) cwindow->update(1, 1, 1, 1, 1); - if (calling_window_gui != cwindow->gui) - cwindow->gui->unlock_window(); + cwindow->gui->unlock_window(); for(int i = 0; i < vwindows.size(); i++) { diff --git a/cinelerra-5.0/mpeg2enc/Makefile b/cinelerra-5.0/mpeg2enc/Makefile index a6184f9f..540920a8 100644 --- a/cinelerra-5.0/mpeg2enc/Makefile +++ b/cinelerra-5.0/mpeg2enc/Makefile @@ -68,7 +68,7 @@ LIBS = \ $(EXTRA_LIBS) HVEG2LIB = $(OBJDIR)/hveg2enc.a -HVEG2ENC = $(PLUGIN_DIR)/hveg2enc.plugin +HVEG2ENC = $(OBJDIR)/hveg2enc HVEG2ENC_G = $(OBJDIR)/hveg2enc_g $(shell echo $(CFLAGS) > $(OBJDIR)/c_flags) @@ -87,7 +87,6 @@ OUTPUT = $(HVEG2LIB) $(HVEG2ENC) all: $(OUTPUT) clean: - rm -f $(HVEG2ENC) rm -rf $(OBJDIR) install: $(OUTPUT) diff --git a/cinelerra-5.0/plugins/Makefile b/cinelerra-5.0/plugins/Makefile index deaaf1ab..da618f42 100644 --- a/cinelerra-5.0/plugins/Makefile +++ b/cinelerra-5.0/plugins/Makefile @@ -132,16 +132,20 @@ DIRS = \ # findobject \ DATA = $(PLUGIN_DIR)/fonts $(PLUGIN_DIR)/shapes -MPEG2ENC = $(BINDIR)/mpeg2enc.plugin +MPEG2ENC = $(PLUGIN_DIR)/mpeg2enc.plugin +HVEG2ENC = $(PLUGIN_DIR)/hveg2enc.plugin LADSPA = $(PLUGIN_DIR)/ladspa -all: $(DIRS) $(DATA) $(MPEG2ENC) $(LADSPA) +all: $(DIRS) $(DATA) $(MPEG2ENC) $(HVEG2ENC) $(LADSPA) $(DATA): cp -a $(notdir $@) $(PLUGIN_DIR)/. $(MPEG2ENC): - cp ../thirdparty/mjpegtools*/mpeg2enc/mpeg2enc $@ + cp -a ../thirdparty/mjpegtools*/mpeg2enc/mpeg2enc $@ + +$(HVEG2ENC): + cp -a ../mpeg2enc/$(OBJDIR)/hveg2enc $@ $(LADSPA): mkdir -p $@ @@ -157,7 +161,6 @@ $(DIRS): clean: rm -rf $(foreach d,$(DIRS),$(d)/$(OBJDIR)) rm -rf $(PLUGIN_DIR) - rm -f $(MPEG2ENC) install: -- 2.26.2