lock trace bug, missed optimize in dvd_create, cin_quality=-1, motion plugin gui...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / fileffmpeg.C
index f3df7a2eed6f23e84c9e7f4ab5657d4afacd9173..6c360da35bd2e8bd0ba50852c96660c24ede04a9 100644 (file)
@@ -59,6 +59,20 @@ void FFMpegConfigNum::create_objects()
        BC_TumbleTextBox::create_objects();
 }
 
+int FFMpegConfigNum::update_param(const char *param, const char *opts)
+{
+       char value[BCTEXTLEN];
+       if( !FileFFMPEG::get_ff_option(param, opts, value) ) {
+               if( (*output = atol(value)) < 0 ) {
+                       disable(1);
+                       return 0;
+               }
+               BC_TumbleTextBox::update(value);
+       }
+       enable();
+       return 1;
+}
+
 int FFMpegConfigNum::handle_event()
 {
        *output = atol(get_text());
@@ -105,6 +119,14 @@ int FFMpegVideoQuality::handle_event()
        return ret;
 }
 
+void FileFFMPEG::set_parameters(char *cp, int len, const char *bp)
+{
+       char *ep = cp + len-2, ch = 0;
+       while( cp < ep && *bp != 0 ) { ch = *bp++; *cp++ = ch; }
+       if( ch != '\n' ) *cp++ = '\n';
+       *cp = 0;
+}
+
 void FileFFMPEG::get_parameters(BC_WindowBase *parent_window,
                Asset *asset, BC_WindowBase *&format_window,
                int audio_options, int video_options)
@@ -114,7 +136,8 @@ void FileFFMPEG::get_parameters(BC_WindowBase *parent_window,
                format_window = window;
                window->create_objects();
                if( !window->run_window() )
-                       strcpy(asset->ff_audio_options, window->audio_options->get_text());
+                       set_parameters(asset->ff_audio_options, sizeof(asset->ff_audio_options),
+                                window->audio_options->get_text());
                delete window;
        }
        else if(video_options) {
@@ -122,7 +145,8 @@ void FileFFMPEG::get_parameters(BC_WindowBase *parent_window,
                format_window = window;
                window->create_objects();
                if( !window->run_window() )
-                       strcpy(asset->ff_video_options, window->video_options->get_text());
+                       set_parameters(asset->ff_video_options, sizeof(asset->ff_video_options),
+                                window->video_options->get_text());
                delete window;
        }
 }
@@ -343,6 +367,25 @@ int FileFFMPEG::get_best_colormodel(Asset *asset, int driver)
        return BC_RGB888;
 }
 
+
+int FileFFMPEG::get_ff_option(const char *nm, const char *options, char *value)
+{
+       for( const char *cp=options; *cp!=0; ) {
+               char line[BCTEXTLEN], *bp = line, *ep = bp+sizeof(line)-1;
+               while( bp < ep && *cp && *cp!='\n' ) *bp++ = *cp++;
+               if( *cp ) ++cp;
+               *bp = 0;
+               if( !line[0] || line[0] == '#' || line[0] == ';' ) continue;
+               char key[BCSTRLEN], val[BCTEXTLEN];
+               if( FFMPEG::scan_option_line(line, key, val) ) continue;
+               if( !strcmp(key, nm) ) {
+                       strcpy(value, val);
+                       return 0;
+               }
+       }
+       return 1;
+}
+
 //======
 
 FFMPEGConfigAudio::FFMPEGConfigAudio(BC_WindowBase *parent_window, Asset *asset)
@@ -429,6 +472,8 @@ void FFMPEGConfigAudio::create_objects()
        add_subwindow(new BC_OKButton(this));
        add_subwindow(new BC_CancelButton(this));
 
+       bitrate->update_param("cin_bitrate", asset->ff_audio_options);
+
        show_window(1);
        bitrate->handle_event();
        unlock_window();
@@ -447,12 +492,6 @@ FFAudioOptions::FFAudioOptions(FFMPEGConfigAudio *audio_popup,
        this->audio_popup = audio_popup;
 }
 
-int FFAudioOptions::handle_event()
-{
-       strcpy(audio_popup->asset->ff_audio_options, get_text());
-       return 1;
-}
-
 
 FFMPEGConfigAudioPopup::FFMPEGConfigAudioPopup(FFMPEGConfigAudio *popup, int x, int y)
  : BC_PopupTextBox(popup, &popup->presets, popup->asset->acodec, x, y, 300, 300)
@@ -469,6 +508,9 @@ int FFMPEGConfigAudioPopup::handle_event()
        FFMPEG::load_options(option_path, asset->ff_audio_options,
                         sizeof(asset->ff_audio_options));
        popup->audio_options->update(asset->ff_audio_options);
+       popup->audio_options->set_text_row(0);
+
+       popup->bitrate->update_param("cin_bitrate", asset->ff_audio_options);
        return 1;
 }
 
@@ -583,6 +625,9 @@ void FFMPEGConfigVideo::create_objects()
        add_subwindow(new BC_OKButton(this));
        add_subwindow(new BC_CancelButton(this));
 
+       bitrate->update_param("cin_bitrate", asset->ff_video_options);
+       quality->update_param("cin_quality", asset->ff_video_options);
+
        show_window(1);
        if( asset->ff_video_bitrate )
                quality->disable();
@@ -604,12 +649,6 @@ FFVideoOptions::FFVideoOptions(FFMPEGConfigVideo *video_popup,
        this->video_popup = video_popup;
 }
 
-int FFVideoOptions::handle_event()
-{
-       strcpy(video_popup->asset->ff_video_options, get_text());
-       return 1;
-}
-
 
 FFMPEGConfigVideoPopup::FFMPEGConfigVideoPopup(FFMPEGConfigVideo *popup, int x, int y)
  : BC_PopupTextBox(popup, &popup->presets, popup->asset->vcodec, x, y, 300, 300)
@@ -626,6 +665,10 @@ int FFMPEGConfigVideoPopup::handle_event()
        FFMPEG::load_options(option_path, asset->ff_video_options,
                         sizeof(asset->ff_video_options));
        popup->video_options->update(asset->ff_video_options);
+       popup->video_options->set_text_row(0);
+
+       popup->bitrate->update_param("cin_bitrate", asset->ff_video_options);
+       popup->quality->update_param("cin_quality", asset->ff_video_options);
        return 1;
 }