#include "asset.h"
#include "bcwindowbase.h"
#include "bitspopup.h"
+#include "ctype.h"
#include "ffmpeg.h"
#include "filebase.h"
#include "file.h"
#include "fileffmpeg.h"
#include "filesystem.h"
#include "indexfile.h"
+#include "language.h"
#include "mainerror.h"
#include "mainprogress.h"
#include "mutex.h"
BC_TumbleTextBox::create_objects();
}
+int FFMpegConfigNum::update_text(const char *text)
+{
+ BC_TumbleTextBox::update(text);
+ return handle_event();
+}
+
int FFMpegConfigNum::handle_event()
{
*output = atol(get_text());
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)
FFMPEGConfigAudio *window = new FFMPEGConfigAudio(parent_window, asset);
format_window = window;
window->create_objects();
- window->run_window();
+ if( !window->run_window() )
+ set_parameters(asset->ff_audio_options, sizeof(asset->ff_audio_options),
+ window->audio_options->get_text());
delete window;
}
else if(video_options) {
FFMPEGConfigVideo *window = new FFMPEGConfigVideo(parent_window, asset);
format_window = window;
window->create_objects();
- window->run_window();
+ if( !window->run_window() )
+ set_parameters(asset->ff_video_options, sizeof(asset->ff_video_options),
+ window->video_options->get_text());
delete window;
}
}
int FileFFMPEG::get_best_colormodel(Asset *asset, int driver)
{
switch(driver) {
- case PLAYBACK_X11: return BC_RGB888;
- case PLAYBACK_X11_GL: return BC_YUV888;
+ case PLAYBACK_X11:
+ return BC_RGB888;
+ case PLAYBACK_X11_XV:
+ case PLAYBACK_ASYNCHRONOUS:
+ return BC_YUV888;
+ case PLAYBACK_X11_GL:
+ return BC_YUV888;
+ case PLAYBACK_DV1394:
+ case PLAYBACK_FIREWIRE:
+ return BC_YUV422P;
+ case VIDEO4LINUX2:
+ return BC_RGB888;
+ case VIDEO4LINUX2JPEG:
+ return BC_COMPRESSED;
+ case CAPTURE_DVB:
+ case VIDEO4LINUX2MPEG:
+ return BC_YUV422P;
+ case CAPTURE_JPEG_WEBCAM:
+ return BC_COMPRESSED;
+ case CAPTURE_YUYV_WEBCAM:
+ return BC_YUV422;
+ case CAPTURE_FIREWIRE:
+ case CAPTURE_IEC61883:
+ return BC_YUV422P;
+ }
+
+ 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 BC_YUV420P;
+ return 1;
}
//======
FFMPEG::load_options(option_path, asset->ff_audio_options,
sizeof(asset->ff_audio_options));
}
+
audio_options = new FFAudioOptions(this, x, y, get_w()-x-20, 10,
sizeof(asset->ff_audio_options)-1, asset->ff_audio_options);
audio_options->create_objects();
add_subwindow(new BC_OKButton(this));
-
+ add_subwindow(new BC_CancelButton(this));
+
+ char value[BCTEXTLEN];
+ if( !FileFFMPEG::get_ff_option("cin_bitrate", asset->ff_audio_options, value) )
+ bitrate->update_text(value);
+
show_window(1);
bitrate->handle_event();
unlock_window();
int FFMPEGConfigAudio::close_event()
{
- set_done(0);
+ set_done(1);
return 1;
}
-void FFMPEGConfigAudio::update_options()
-{
- audio_options->update(asset->ff_audio_options);
-}
-
FFAudioOptions::FFAudioOptions(FFMPEGConfigAudio *audio_popup,
int x, int y, int w, int rows, int size, char *text)
: BC_ScrollTextBox(audio_popup, x, y, w, rows, text, size)
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)
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);
+
+ char value[BCTEXTLEN];
+ if( !FileFFMPEG::get_ff_option("cin_bitrate", asset->ff_audio_options, value) )
+ popup->bitrate->update_text(value);
return 1;
}
FFMPEGConfigVideo::~FFMPEGConfigVideo()
{
+ delete ff_options_dialog;
lock_window("FFMPEGConfigVideo::~FFMPEGConfigVideo");
if(preset_popup) delete preset_popup;
presets.remove_all_objects();
video_options = new FFVideoOptions(this, x, y, get_w()-x-20, 10,
sizeof(asset->ff_video_options)-1, asset->ff_video_options);
video_options->create_objects();
-
add_subwindow(new BC_OKButton(this));
+ add_subwindow(new BC_CancelButton(this));
+
+ char value[BCTEXTLEN];
+ if( !FileFFMPEG::get_ff_option("cin_quality", asset->ff_video_options, value) )
+ quality->update_text(value);
+ if( !FileFFMPEG::get_ff_option("cin_bitrate", asset->ff_video_options, value) )
+ bitrate->update_text(value);
+
show_window(1);
if( asset->ff_video_bitrate )
quality->disable();
int FFMPEGConfigVideo::close_event()
{
- set_done(0);
+ set_done(1);
return 1;
}
-void FFMPEGConfigVideo::update_options()
-{
- video_options->update(asset->ff_video_options);
-}
-
FFVideoOptions::FFVideoOptions(FFMPEGConfigVideo *video_popup,
int x, int y, int w, int rows, int size, char *text)
: BC_ScrollTextBox(video_popup, x, y, w, rows, text, size)
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)
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);
+
+ char value[BCTEXTLEN];
+ if( !FileFFMPEG::get_ff_option("cin_quality", asset->ff_video_options, value) ) {
+ popup->quality->update_text(value);
+ }
+ if( !FileFFMPEG::get_ff_option("cin_bitrate", asset->ff_video_options, value) )
+ popup->bitrate->update_text(value);
return 1;
}
void FFOptions_OptPanel::create_objects()
{
- const char *cols[] = { "option", "value", };
+ const char *cols[] = { _("option"), _("value"), };
const int col1_w = 150;
int wids[] = { col1_w, get_w()-col1_w };
BC_ListBox::update(&items[0], &cols[0], &wids[0], sizeof(items)/sizeof(items[0]));
char *FFOptions_Opt::get(char *vp, int sz)
{
- char *cp = vp, *ep = vp+sz-1;
+ char *cp = vp;
*cp = 0;
if( !opt ) return cp;
cp = sz >= 0 ? strncpy(vp,val,sz) : strcpy(vp, val);
if( sz > 0 ) vp[sz-1] = 0;
av_freep(&bp);
- return cp;
}
- *vp = 0;
return cp;
}
void FFOptionsKind::set(int k)
{
this->kind = k;
- set_text(kinds[k]);
+ set_text(_(kinds[k]));
}
FFOptionsText::
panel->update();
}
+void FFOptions_OptPanel::show_tip(const char *tip)
+{
+ if( !tip ) return;
+ int len = strlen(tip);
+ if( len > (int)sizeof(tip_text)-1 ) len = sizeof(tip_text)-1;
+ strncpy(tip_text,tip,len);
+ tip_text[len] = 0;
+ int line_limit = 60;
+ int limit2 = line_limit/2;
+ int limit4 = line_limit/4-2;
+ char *cp = tip_text, *dp = cp+len;
+ int n; char *bp, *ep, *pp, *sp;
+ while( cp < dp ) {
+ for( ep=cp; ep<dp && *ep!='\n'; ++ep );
+ // target about half remaining line, constrain line_limit
+ if( (n=(ep-1-cp)/2) < limit2 || n > line_limit )
+ n = line_limit;
+ // search for last punct, last space before line_limit
+ for( bp=cp, pp=sp=0; --n>=0 && cp<ep; ++cp ) {
+ if( ispunct(*cp) && isspace(*(cp+1)) ) pp = cp;
+ else if( isspace(*cp) ) sp = cp;
+ }
+ // line not empty
+ if( cp < ep ) {
+ // first, after punctuation
+ if( pp && pp-bp >= limit4 )
+ cp = pp+1;
+ // then, on spaces
+ else if( sp ) {
+ cp = sp;
+ }
+ // last, on next space
+ else {
+ while( cp<dp && !isspace(*cp) ) ++cp;
+ }
+ // add new line
+ if( !*cp ) break;
+ *cp++ = '\n';
+ }
+ }
+ fwin->panel->set_tooltip(tip_text);
+ fwin->panel->show_tooltip();
+}
+
int FFOptions_OptPanel::selection_changed()
{
FFOptions_Opt *opt = 0;
opt = opt_name->opt;
}
fwin->update(opt);
- fwin->panel->set_tooltip(!opt ? 0 : opt->tip());
- fwin->panel->show_tooltip();
+ if( opt ) show_tip(opt->tip());
return 1;
}
{
const char *cp = "";
if( opt ) switch (opt->type) {
- case AV_OPT_TYPE_FLAGS: cp = "<flags>"; break;
- case AV_OPT_TYPE_INT: cp = "<int>"; break;
- case AV_OPT_TYPE_INT64: cp = "<int64>"; break;
- case AV_OPT_TYPE_DOUBLE: cp = "<double>"; break;
- case AV_OPT_TYPE_FLOAT: cp = "<float>"; break;
- case AV_OPT_TYPE_STRING: cp = "<string>"; break;
- case AV_OPT_TYPE_RATIONAL: cp = "<rational>"; break;
- case AV_OPT_TYPE_BINARY: cp = "<binary>"; break;
- case AV_OPT_TYPE_IMAGE_SIZE: cp = "<image_size>"; break;
- case AV_OPT_TYPE_VIDEO_RATE: cp = "<video_rate>"; break;
- case AV_OPT_TYPE_PIXEL_FMT: cp = "<pix_fmt>"; break;
- case AV_OPT_TYPE_SAMPLE_FMT: cp = "<sample_fmt>"; break;
- case AV_OPT_TYPE_DURATION: cp = "<duration>"; break;
- case AV_OPT_TYPE_COLOR: cp = "<color>"; break;
- case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = "<channel_layout>"; break;
- case AV_OPT_TYPE_BOOL: cp = "<bool>"; break;
- default: cp = "<undef>"; break;
+ case AV_OPT_TYPE_FLAGS: cp = N_("<flags>"); break;
+ case AV_OPT_TYPE_INT: cp = N_("<int>"); break;
+ case AV_OPT_TYPE_INT64: cp = N_("<int64>"); break;
+ case AV_OPT_TYPE_DOUBLE: cp = N_("<double>"); break;
+ case AV_OPT_TYPE_FLOAT: cp = N_("<float>"); break;
+ case AV_OPT_TYPE_STRING: cp = N_("<string>"); break;
+ case AV_OPT_TYPE_RATIONAL: cp = N_("<rational>"); break;
+ case AV_OPT_TYPE_BINARY: cp = N_("<binary>"); break;
+ case AV_OPT_TYPE_IMAGE_SIZE: cp = N_("<image_size>"); break;
+ case AV_OPT_TYPE_VIDEO_RATE: cp = N_("<video_rate>"); break;
+ case AV_OPT_TYPE_PIXEL_FMT: cp = N_("<pix_fmt>"); break;
+ case AV_OPT_TYPE_SAMPLE_FMT: cp = N_("<sample_fmt>"); break;
+ case AV_OPT_TYPE_DURATION: cp = N_("<duration>"); break;
+ case AV_OPT_TYPE_COLOR: cp = N_("<color>"); break;
+ case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = N_("<channel_layout>"); break;
+ case AV_OPT_TYPE_BOOL: cp = N_("<bool>"); break;
+ default: cp = N_("<undef>"); break;
}
- return sprintf(rp, "%s", cp);
+ return sprintf(rp, "%s", _(cp));
}
int FFOptions_Opt::scalar(double d, char *rp)
{
FFOptionsWindow::FFOptionsWindow(FFOptionsDialog *dialog)
- : BC_Window(PROGRAM_NAME ": Options", 60, 30, 640, 400)
+ : BC_Window(_(PROGRAM_NAME ": Options"), 60, 30, 640, 400)
{
this->dialog = dialog;
this->selected = 0;
void FFOptionsWindow::create_objects()
{
BC_Title *title;
- int x = 10, y = 10;
- add_subwindow(title = new BC_Title(x, y, dialog->codec_name));
- y += title->get_h() + 10;
- int x0 = x, y0 = y;
- add_subwindow(title = new BC_Title(x0, y0, _("Type: ")));
- x0 += title->get_w() + 8;
- add_subwindow(type = new BC_Title(x0, y0, (char *)""));
- x0 = x + 150;
- add_subwindow(title = new BC_Title(x0, y0, _("Range: ")));
- x0 += title->get_w() + 8;
- add_subwindow(range = new BC_Title(x0, y0, (char *)""));
- x0 = x;
- y += title->get_h() + 10;
- add_subwindow(units = new FFOptionsUnits(this, x0, y, 120));
- x0 += units->get_w() + 8;
+ int x0 = 10, y0 = 10;
+ int x = x0, y = y0;
+ add_subwindow(title = new BC_Title(x, y, _("Format: ")));
+ x += title->get_w();
+ add_subwindow(new BC_Title(x, y, dialog->format_name));
+ x = x0 + 150;
+ add_subwindow(title = new BC_Title(x, y, _("Codec: ")));
+ x += title->get_w();
+ add_subwindow(new BC_Title(x, y, dialog->codec_name));
+
+ x = x0; y += title->get_h() + 10; y0 = y;
+ add_subwindow(title = new BC_Title(x, y, _("Type: ")));
+ x += title->get_w() + 8;
+ add_subwindow(type = new BC_Title(x, y, (char *)""));
+ x = x0 + 150;
+ add_subwindow(title = new BC_Title(x, y, _("Range: ")));
+ x += title->get_w() + 8;
+ add_subwindow(range = new BC_Title(x, y, (char *)""));
+
+ x = x0; y += title->get_h() + 10;
+ add_subwindow(units = new FFOptionsUnits(this, x, y, 120));
+ x += units->get_w() + 8;
int x1 = get_w() - BC_GenericButton::calculate_w(this, _("Apply")) - 8;
- add_subwindow(text = new FFOptionsText(this, x0, y, x1-x0 - 8));
+ add_subwindow(text = new FFOptionsText(this, x, y, x1-x - 8));
add_subwindow(apply = new FFOptionsApply(this, x1, y));
y += units->get_h() + 10;
add_subwindow(kind = new FFOptionsKind(this, x1, y0, apply->get_w()));
const char *kind_text = _("Kind:");
x1 -= BC_Title::calculate_w(this, kind_text) + 8;
add_subwindow(kind_title = new BC_Title(x1, y0, kind_text));
+ y0 = y;
- panel_x = x; panel_y = y;
+ panel_x = x0; panel_y = y0;
panel_w = get_w()-10 - panel_x;
panel_h = get_h()-10 - panel_y - BC_OKButton::calculate_h();
panel = new FFOptions_OptPanel(this, panel_x, panel_y, panel_w, panel_h);
this->options_window = 0;
this->codec_name = 0;
this->codec = 0;
- this->ff_options = 0;
- this->ff_len = 0;
this->ff_opts = 0;
+ this->ff_len = 0;
}
FFOptionsDialog::~FFOptionsDialog()
delete [] codec_name;
}
-void FFOptionsDialog::load_options()
+void FFOptionsDialog::load_options(const char *bp, int len)
{
char line[BCTEXTLEN];
char key[BCSTRLEN], val[BCTEXTLEN];
- char *bp = ff_options, *dp = bp + ff_len-1;
+ const char *dp = bp + len-1;
int no = 0;
while( bp < dp && *bp != 0 ) {
++no;
}
}
-void FFOptionsDialog::store_options()
+void FFOptionsDialog::store_options(char *cp, int len)
{
- char *cp = ff_options, *ep = cp + ff_len-1;
+ char *ep = cp + len-1;
AVDictionaryEntry *elem = 0;
while( (elem=av_dict_get(ff_opts, "", elem, AV_DICT_IGNORE_SUFFIX)) != 0 ) {
if( elem->key[0] == '#' ) {
*cp = 0;
}
-void FFOptionsDialog::start(const char *codec_name, AVCodec *codec, char *options, int len)
+void FFOptionsDialog::start(const char *format_name, const char *codec_name,
+ AVCodec *codec, const char *options, int len)
{
if( options_window ) {
options_window->lock_window("FFOptionsDialog::start");
return;
}
+ this->format_name = cstrdup(format_name);
this->codec_name = cstrdup(codec_name);
this->codec = codec;
this->ff_opts = 0;
- this->ff_options = options;
this->ff_len = len;
- load_options();
+ load_options(options, len);
BC_DialogThread::start();
}
void FFOptionsDialog::handle_done_event(int result)
{
if( !result ) {
- store_options();
- update_options();
+ char options[ff_len];
+ store_options(options, ff_len);
+ update_options(options);
}
options_window = 0;
+ delete [] format_name; format_name = 0;
delete [] codec_name; codec_name = 0;
av_dict_free(&ff_opts);
}
FFOptionsAudioDialog::~FFOptionsAudioDialog()
{
+ close_window();
}
-void FFOptionsAudioDialog::update_options()
+void FFOptionsAudioDialog::update_options(const char *options)
{
- aud_config->update_options();
+ aud_config->audio_options->update(options);
}
FFOptionsVideoDialog::FFOptionsVideoDialog(FFMPEGConfigVideo *vid_config)
FFOptionsVideoDialog::~FFOptionsVideoDialog()
{
+ close_window();
}
-void FFOptionsVideoDialog::update_options()
+void FFOptionsVideoDialog::update_options(const char *options)
{
- vid_config->update_options();
+ vid_config->video_options->update(options);
}
int FFOptionsViewAudio::handle_event()
{
- AVCodec *codec = 0;
+ char audio_format[BCSTRLEN]; audio_format[0] = 0;
char audio_codec[BCSTRLEN]; audio_codec[0] = 0;
+ AVCodec *codec = 0;
Asset *asset = aud_config->asset;
const char *name = asset->acodec;
- if( !FFMPEG::get_codec(audio_codec, "audio", name) )
+ if( !FFMPEG::get_format(audio_format, "audio", name) &&
+ !FFMPEG::get_codec(audio_codec, "audio", name) )
codec = avcodec_find_encoder_by_name(audio_codec);
if( !codec ) {
eprintf(_("no codec named: %s: %s"), name, audio_codec);
return 1;
}
- aud_config->ff_options_dialog->start(audio_codec, codec,
- asset->ff_audio_options, sizeof(asset->ff_audio_options));
+ aud_config->ff_options_dialog->start(audio_format, audio_codec, codec,
+ asset->ff_audio_options, sizeof(asset->ff_audio_options));
return 1;
}
int FFOptionsViewVideo::handle_event()
{
- AVCodec *codec = 0;
+ char video_format[BCSTRLEN]; video_format[0] = 0;
char video_codec[BCSTRLEN]; video_codec[0] = 0;
+ AVCodec *codec = 0;
Asset *asset = vid_config->asset;
const char *name = asset->vcodec;
- if( !FFMPEG::get_codec(video_codec, "video", name) )
+ if( !FFMPEG::get_format(video_format, "video", name) &&
+ !FFMPEG::get_codec(video_codec, "video", name) )
codec = avcodec_find_encoder_by_name(video_codec);
if( !codec ) {
eprintf(_("no codec named: %s: %s"), name, video_codec);
return 1;
}
- vid_config->ff_options_dialog->start(video_codec, codec,
- asset->ff_video_options, sizeof(asset->ff_video_options));
+ vid_config->ff_options_dialog->start(video_format, video_codec, codec,
+ asset->ff_video_options, sizeof(asset->ff_video_options));
return 1;
}