From 328cb789bec2048b23fc731cf4eae860dbacd2b6 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Sat, 27 Jun 2015 17:45:16 -0600 Subject: [PATCH] ffmpeg load_defaults, create default codec file def --- cinelerra-5.0/cinelerra/ffmpeg.C | 15 +++++++++++- cinelerra-5.0/cinelerra/ffmpeg.h | 1 + cinelerra-5.0/cinelerra/fileffmpeg.C | 20 +++------------ cinelerra-5.0/cinelerra/formattools.C | 35 ++++++++++++++++++++++----- cinelerra-5.0/cinelerra/formattools.h | 4 +++ cinelerra-5.0/db/tdb.h | 4 +++ cinelerra-5.0/ffmpeg/audio/dvd | 5 +--- cinelerra-5.0/ffmpeg/audio/dvd.dvd | 4 +++ cinelerra-5.0/ffmpeg/audio/mp3 | 2 +- cinelerra-5.0/ffmpeg/audio/mp3.mp3 | 1 + cinelerra-5.0/ffmpeg/audio/mp4 | 1 + cinelerra-5.0/ffmpeg/audio/qt | 1 + cinelerra-5.0/ffmpeg/video/dvd | 10 +------- cinelerra-5.0/ffmpeg/video/dvd.dvd | 9 +++++++ cinelerra-5.0/ffmpeg/video/mp4 | 1 + cinelerra-5.0/ffmpeg/video/mpeg | 2 +- cinelerra-5.0/ffmpeg/video/mpeg.mpeg | 1 + cinelerra-5.0/ffmpeg/video/qt | 1 + 18 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 cinelerra-5.0/ffmpeg/audio/dvd.dvd create mode 100644 cinelerra-5.0/ffmpeg/audio/mp3.mp3 create mode 100644 cinelerra-5.0/ffmpeg/audio/mp4 create mode 100644 cinelerra-5.0/ffmpeg/audio/qt create mode 100644 cinelerra-5.0/ffmpeg/video/dvd.dvd create mode 100644 cinelerra-5.0/ffmpeg/video/mp4 create mode 100644 cinelerra-5.0/ffmpeg/video/mpeg.mpeg create mode 100644 cinelerra-5.0/ffmpeg/video/qt diff --git a/cinelerra-5.0/cinelerra/ffmpeg.C b/cinelerra-5.0/cinelerra/ffmpeg.C index 96b09314..26ed21a4 100644 --- a/cinelerra-5.0/cinelerra/ffmpeg.C +++ b/cinelerra-5.0/cinelerra/ffmpeg.C @@ -963,7 +963,7 @@ void FFMPEG::get_option_path(char *path, const char *type, const char *spec) int FFMPEG::get_format(char *format, const char *path, char *spec) { - char option_path[BCTEXTLEN], line[BCTEXTLEN], codec[BCSTRLEN]; + char option_path[BCTEXTLEN], line[BCTEXTLEN], codec[BCTEXTLEN]; get_option_path(option_path, path, spec); FILE *fp = fopen(option_path,"r"); if( !fp ) return 1; @@ -1104,6 +1104,19 @@ int FFMPEG::load_options(const char *options, AVDictionary *&opts) return read_options(option_path, opts); } +int FFMPEG::load_options(const char *path, char *bfr, int len) +{ + *bfr = 0; + FILE *fp = fopen(path, "r"); + if( !fp ) return 1; + fgets(bfr, len, fp); // skip hdr + len = fread(bfr, 1, len-1, fp); + if( len < 0 ) len = 0; + bfr[len] = 0; + fclose(fp); + return 0; +} + void FFMPEG::set_loglevel(const char *ap) { if( !ap || !*ap ) return; diff --git a/cinelerra-5.0/cinelerra/ffmpeg.h b/cinelerra-5.0/cinelerra/ffmpeg.h index ff924c1e..003d5583 100644 --- a/cinelerra-5.0/cinelerra/ffmpeg.h +++ b/cinelerra-5.0/cinelerra/ffmpeg.h @@ -243,6 +243,7 @@ public: int scan_options(const char *options, AVDictionary *&opts); int read_options(FILE *fp, const char *options, AVDictionary *&opts); int load_options(const char *options, AVDictionary *&opts); + static int load_options(const char *path, char *bfr, int len); void set_loglevel(const char *ap); static double to_secs(int64_t time, AVRational time_base); int info(char *text, int len); diff --git a/cinelerra-5.0/cinelerra/fileffmpeg.C b/cinelerra-5.0/cinelerra/fileffmpeg.C index bfe0a107..fdcf3297 100644 --- a/cinelerra-5.0/cinelerra/fileffmpeg.C +++ b/cinelerra-5.0/cinelerra/fileffmpeg.C @@ -318,18 +318,6 @@ int FileFFMPEG::get_best_colormodel(Asset *asset, int driver) return BC_YUV420P; } -static void load_options(const char *path, char *bfr, int len) -{ - *bfr = 0; - FILE *fp = fopen(path, "r"); - if( !fp ) return; - fgets(bfr, len, fp); // skip hdr - len = fread(bfr, 1, len-1, fp); - if( len < 0 ) len = 0; - bfr[len] = 0; - fclose(fp); -} - //====== extern void get_exe_path(char *result); // from main.C @@ -400,7 +388,7 @@ void FFMPEGConfigAudio::create_objects() y += 25; if( !asset->ff_audio_options[0] && asset->acodec[0] ) { FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec); - load_options(option_path, asset->ff_audio_options, + FFMPEG::load_options(option_path, asset->ff_audio_options, sizeof(asset->ff_audio_options)); } add_subwindow(audio_options = new FFAudioOptions(this, x, y, get_w()-x-20, 10, @@ -444,7 +432,7 @@ int FFMPEGConfigAudioPopup::handle_event() Asset *asset = popup->asset; char option_path[BCTEXTLEN]; FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec); - load_options(option_path, asset->ff_audio_options, + FFMPEG::load_options(option_path, asset->ff_audio_options, sizeof(asset->ff_audio_options)); popup->audio_options->update(asset->ff_audio_options); return 1; @@ -545,7 +533,7 @@ void FFMPEGConfigVideo::create_objects() y += 25; if( !asset->ff_video_options[0] && asset->vcodec[0] ) { FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec); - load_options(option_path, asset->ff_video_options, + FFMPEG::load_options(option_path, asset->ff_video_options, sizeof(asset->ff_video_options)); } add_subwindow(video_options = new FFVideoOptions(this, x, y, get_w()-x-20, 10, @@ -593,7 +581,7 @@ int FFMPEGConfigVideoPopup::handle_event() Asset *asset = popup->asset; char option_path[BCTEXTLEN]; FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec); - load_options(option_path, asset->ff_video_options, + FFMPEG::load_options(option_path, asset->ff_video_options, sizeof(asset->ff_video_options)); popup->video_options->update(asset->ff_video_options); return 1; diff --git a/cinelerra-5.0/cinelerra/formattools.C b/cinelerra-5.0/cinelerra/formattools.C index e5f8c9ad..a8f3f6bf 100644 --- a/cinelerra-5.0/cinelerra/formattools.C +++ b/cinelerra-5.0/cinelerra/formattools.C @@ -364,7 +364,6 @@ void FormatTools::update_driver(int driver) void FormatTools::update_format() { if( do_audio && prompt_audio && audio_switch ) { - asset->audio_data = File::supports_audio(asset->format); audio_switch->update(asset->audio_data); if( !asset->audio_data ) audio_switch->disable(); @@ -372,7 +371,6 @@ void FormatTools::update_format() audio_switch->enable(); } if( do_video && prompt_video && video_switch ) { - asset->video_data = File::supports_video(asset->format); video_switch->update(asset->video_data); if( !asset->video_data ) video_switch->disable(); @@ -828,7 +826,10 @@ int FormatFormat::handle_event() int new_format = File::strtoformat(format->plugindb, get_selection(0, 0)->get_text()); // if(new_format != format->asset->format) { - format->asset->format = new_format; + Asset *asset = format->asset; + asset->format = new_format; + asset->audio_data = File::supports_audio(asset->format); + asset->video_data = File::supports_video(asset->format); format->format_text->update(selection->get_text()); format->update_extension(); format->close_format_windows(); @@ -849,15 +850,37 @@ FormatFFMPEG::~FormatFFMPEG() { } +int FormatFFMPEG::load_defaults(const char *path, const char *type, + char *codec, char *codec_options, int len) +{ + char default_file[BCTEXTLEN]; + FFMPEG::set_option_path(default_file, "%s/%s", path, type); + FILE *fp = fopen(default_file,"r"); + if( !fp ) return 1; + char default_codec[BCSTRLEN]; + fgets(default_codec, sizeof(default_codec), fp); + fclose(fp); + char *cp=codec, *dp=default_codec; + while( *dp && *dp!='\n' ) *cp++ = *dp++; + *cp = 0; + FFMPEG::set_option_path(default_file, "%s/%s", path, codec); + return FFMPEG::load_options(default_file, codec_options, len); +} + int FormatFFMPEG::handle_event() { BC_ListBoxItem *selection = get_selection(0, 0); if( selection ) { char *text = get_selection(0, 0)->get_text(); format->ffmpeg_type->update(text); - strcpy(format->asset->fformat, text); - strcpy(format->asset->ff_audio_options, ""); - strcpy(format->asset->ff_video_options, ""); + Asset *asset = format->asset; + strcpy(asset->fformat, text); + strcpy(asset->ff_audio_options, ""); + strcpy(asset->ff_video_options, ""); + asset->audio_data = !load_defaults("audio", text, asset->acodec, + asset->ff_audio_options, sizeof(asset->ff_audio_options)); + asset->video_data = !load_defaults("video", text, asset->vcodec, + asset->ff_video_options, sizeof(asset->ff_video_options)); format->update_extension(); format->close_format_windows(); format->update_format(); diff --git a/cinelerra-5.0/cinelerra/formattools.h b/cinelerra-5.0/cinelerra/formattools.h index 7c626bf1..4bd4221b 100644 --- a/cinelerra-5.0/cinelerra/formattools.h +++ b/cinelerra-5.0/cinelerra/formattools.h @@ -28,6 +28,7 @@ #include "browsebutton.h" #include "compresspopup.h" #include "file.inc" +#include "ffmpeg.h" #include "formatpopup.h" #include "mwindow.inc" @@ -164,6 +165,9 @@ public: int handle_event(); FormatTools *format; + static int load_defaults(const char *path, const char *type, + char *codec, char *codec_options, int len); + // squash show/hide window int show_window(int flush=1) { return 0; } int hide_window(int flush=1) { return 0; } diff --git a/cinelerra-5.0/db/tdb.h b/cinelerra-5.0/db/tdb.h index 452ea7e6..f7472038 100644 --- a/cinelerra-5.0/db/tdb.h +++ b/cinelerra-5.0/db/tdb.h @@ -14,9 +14,13 @@ #define entityNmIndex indecies[entityNmIdx] #define noThrow std::nothrow +#ifndef likely #define likely(x) (__builtin_constant_p(x) ? !!(x) : __builtin_expect(!!(x), 1)) #define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __builtin_expect(!!(x), 0)) +#endif +#ifndef lengthof #define lengthof(x) ((int)(sizeof(x)/sizeof(x[0]))) +#endif #if 0 inline void *operator new(size_t n) { void *vp = malloc(n); bzero(vp,n); return vp; } diff --git a/cinelerra-5.0/ffmpeg/audio/dvd b/cinelerra-5.0/ffmpeg/audio/dvd index 174a56ac..e07391db 100644 --- a/cinelerra-5.0/ffmpeg/audio/dvd +++ b/cinelerra-5.0/ffmpeg/audio/dvd @@ -1,4 +1 @@ -dvd ac3 -maxrate 9000000 -minrate 0 -bufsize 1835008 +dvd.dvd diff --git a/cinelerra-5.0/ffmpeg/audio/dvd.dvd b/cinelerra-5.0/ffmpeg/audio/dvd.dvd new file mode 100644 index 00000000..174a56ac --- /dev/null +++ b/cinelerra-5.0/ffmpeg/audio/dvd.dvd @@ -0,0 +1,4 @@ +dvd ac3 +maxrate 9000000 +minrate 0 +bufsize 1835008 diff --git a/cinelerra-5.0/ffmpeg/audio/mp3 b/cinelerra-5.0/ffmpeg/audio/mp3 index c0ff7a90..7cb71f6e 100644 --- a/cinelerra-5.0/ffmpeg/audio/mp3 +++ b/cinelerra-5.0/ffmpeg/audio/mp3 @@ -1 +1 @@ -mp3 libmp3lame +mp3.mp3 diff --git a/cinelerra-5.0/ffmpeg/audio/mp3.mp3 b/cinelerra-5.0/ffmpeg/audio/mp3.mp3 new file mode 100644 index 00000000..c0ff7a90 --- /dev/null +++ b/cinelerra-5.0/ffmpeg/audio/mp3.mp3 @@ -0,0 +1 @@ +mp3 libmp3lame diff --git a/cinelerra-5.0/ffmpeg/audio/mp4 b/cinelerra-5.0/ffmpeg/audio/mp4 new file mode 100644 index 00000000..ca4ccd77 --- /dev/null +++ b/cinelerra-5.0/ffmpeg/audio/mp4 @@ -0,0 +1 @@ +h265.mp4 diff --git a/cinelerra-5.0/ffmpeg/audio/qt b/cinelerra-5.0/ffmpeg/audio/qt new file mode 100644 index 00000000..ff748545 --- /dev/null +++ b/cinelerra-5.0/ffmpeg/audio/qt @@ -0,0 +1 @@ +mp4.qt diff --git a/cinelerra-5.0/ffmpeg/video/dvd b/cinelerra-5.0/ffmpeg/video/dvd index a5a9ceec..e07391db 100644 --- a/cinelerra-5.0/ffmpeg/video/dvd +++ b/cinelerra-5.0/ffmpeg/video/dvd @@ -1,9 +1 @@ -dvd mpeg2video -s 720x480 -r 30000/1001 -pix_fmt yuv420p -g 18 -maxrate 9000000 -minrate 0 -bufsize 1835008 -packetsize 2048 +dvd.dvd diff --git a/cinelerra-5.0/ffmpeg/video/dvd.dvd b/cinelerra-5.0/ffmpeg/video/dvd.dvd new file mode 100644 index 00000000..a5a9ceec --- /dev/null +++ b/cinelerra-5.0/ffmpeg/video/dvd.dvd @@ -0,0 +1,9 @@ +dvd mpeg2video +s 720x480 +r 30000/1001 +pix_fmt yuv420p +g 18 +maxrate 9000000 +minrate 0 +bufsize 1835008 +packetsize 2048 diff --git a/cinelerra-5.0/ffmpeg/video/mp4 b/cinelerra-5.0/ffmpeg/video/mp4 new file mode 100644 index 00000000..ca4ccd77 --- /dev/null +++ b/cinelerra-5.0/ffmpeg/video/mp4 @@ -0,0 +1 @@ +h265.mp4 diff --git a/cinelerra-5.0/ffmpeg/video/mpeg b/cinelerra-5.0/ffmpeg/video/mpeg index c3570c40..f6f83891 100644 --- a/cinelerra-5.0/ffmpeg/video/mpeg +++ b/cinelerra-5.0/ffmpeg/video/mpeg @@ -1 +1 @@ -mpeg mpeg2video +mpeg.mpeg diff --git a/cinelerra-5.0/ffmpeg/video/mpeg.mpeg b/cinelerra-5.0/ffmpeg/video/mpeg.mpeg new file mode 100644 index 00000000..c3570c40 --- /dev/null +++ b/cinelerra-5.0/ffmpeg/video/mpeg.mpeg @@ -0,0 +1 @@ +mpeg mpeg2video diff --git a/cinelerra-5.0/ffmpeg/video/qt b/cinelerra-5.0/ffmpeg/video/qt new file mode 100644 index 00000000..ff748545 --- /dev/null +++ b/cinelerra-5.0/ffmpeg/video/qt @@ -0,0 +1 @@ +mp4.qt -- 2.26.2