ffmpeg load_defaults, create default codec file def
authorGood Guy <[email protected]>
Sat, 27 Jun 2015 23:45:16 +0000 (17:45 -0600)
committerGood Guy <[email protected]>
Sat, 27 Jun 2015 23:45:16 +0000 (17:45 -0600)
18 files changed:
cinelerra-5.0/cinelerra/ffmpeg.C
cinelerra-5.0/cinelerra/ffmpeg.h
cinelerra-5.0/cinelerra/fileffmpeg.C
cinelerra-5.0/cinelerra/formattools.C
cinelerra-5.0/cinelerra/formattools.h
cinelerra-5.0/db/tdb.h
cinelerra-5.0/ffmpeg/audio/dvd
cinelerra-5.0/ffmpeg/audio/dvd.dvd [new file with mode: 0644]
cinelerra-5.0/ffmpeg/audio/mp3
cinelerra-5.0/ffmpeg/audio/mp3.mp3 [new file with mode: 0644]
cinelerra-5.0/ffmpeg/audio/mp4 [new file with mode: 0644]
cinelerra-5.0/ffmpeg/audio/qt [new file with mode: 0644]
cinelerra-5.0/ffmpeg/video/dvd
cinelerra-5.0/ffmpeg/video/dvd.dvd [new file with mode: 0644]
cinelerra-5.0/ffmpeg/video/mp4 [new file with mode: 0644]
cinelerra-5.0/ffmpeg/video/mpeg
cinelerra-5.0/ffmpeg/video/mpeg.mpeg [new file with mode: 0644]
cinelerra-5.0/ffmpeg/video/qt [new file with mode: 0644]

index 96b0931402cd4851765979dd1599cc3c18fbab4d..26ed21a44d23649e147aeae1e5e58ea8dcce67a7 100644 (file)
@@ -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;
index ff924c1ebc1d45bc01c818a64e6019592e95f453..003d55836e9037d43001b0d86781090b5c57d7da 100644 (file)
@@ -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);
index bfe0a107b0ab0145285bcb55337b8e9d6aeb2042..fdcf3297e6230916ec19b7810b6c10ca3125e516 100644 (file)
@@ -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;
index e5f8c9ade6eba22c70530a4aafbe5e21a9fe79fe..a8f3f6bf85da74f0e2b7d4c76568d728d980e37d 100644 (file)
@@ -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();
index 7c626bf13bfc0b2edf1b9abdc99478e4ec13e3d5..4bd4221b08d48d31c2f3169b642b5a2b18a62c31 100644 (file)
@@ -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; }
index 452ea7e658d05181fac059a38963119c57a37cb2..f7472038611df9cd25fdaff062f82eebb1a3d645 100644 (file)
 #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; }
index 174a56acb9ca09bf67a07f356b04dcf1152c5741..e07391db33ab870e3de82e9d6e0a6682bc72c7d8 100644 (file)
@@ -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 (file)
index 0000000..174a56a
--- /dev/null
@@ -0,0 +1,4 @@
+dvd ac3
+maxrate 9000000
+minrate 0
+bufsize 1835008
index c0ff7a906ad246b8928b531b1ac4c1e180be2590..7cb71f6e2ef2789ccccb56b77443435bfdf2d3a9 100644 (file)
@@ -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 (file)
index 0000000..c0ff7a9
--- /dev/null
@@ -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 (file)
index 0000000..ca4ccd7
--- /dev/null
@@ -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 (file)
index 0000000..ff74854
--- /dev/null
@@ -0,0 +1 @@
+mp4.qt
index a5a9ceec80b43b4e45f060e10b12679c94103f28..e07391db33ab870e3de82e9d6e0a6682bc72c7d8 100644 (file)
@@ -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 (file)
index 0000000..a5a9cee
--- /dev/null
@@ -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 (file)
index 0000000..ca4ccd7
--- /dev/null
@@ -0,0 +1 @@
+h265.mp4
index c3570c40d8913684f88352f814beffa820388ef0..f6f838914d56b24b3ac1861de188eb71397540e5 100644 (file)
@@ -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 (file)
index 0000000..c3570c4
--- /dev/null
@@ -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 (file)
index 0000000..ff74854
--- /dev/null
@@ -0,0 +1 @@
+mp4.qt