X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ffileffmpeg.C;h=27bd7de45daa2022ec46d38c2793d32b30cfd1ce;hp=4879ccc917153071fe50fc7a335868b4d165377e;hb=4b6c39e6cf4a3fd9c1b347db6de686ab55d6cac8;hpb=edb7995d395b7fe861bf79b002fac2f19b141f49 diff --git a/cinelerra-5.1/cinelerra/fileffmpeg.C b/cinelerra-5.1/cinelerra/fileffmpeg.C index 4879ccc9..27bd7de4 100644 --- a/cinelerra-5.1/cinelerra/fileffmpeg.C +++ b/cinelerra-5.1/cinelerra/fileffmpeg.C @@ -17,6 +17,7 @@ #include "fileffmpeg.h" #include "filesystem.h" #include "indexfile.h" +#include "language.h" #include "mainerror.h" #include "mainprogress.h" #include "mutex.h" @@ -39,8 +40,7 @@ FileFFMPEG::~FileFFMPEG() FFMpegConfigNum::FFMpegConfigNum(BC_Window *window, int x, int y, char *title_text, int *output) - : BC_TumbleTextBox(window, (int64_t)*output, - (int64_t)-1, (int64_t)25000000, 100, y, 100) + : BC_TumbleTextBox(window, *output, -1, INT_MAX, 100, y, 100) { this->window = window; this->x = x; this->y = y; @@ -58,9 +58,23 @@ 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 = atoi(value)) < 0 ) { + disable(1); + return 0; + } + } + BC_TumbleTextBox::update((int64_t)*output); + enable(); + return 1; +} + int FFMpegConfigNum::handle_event() { - *output = atol(get_text()); + *output = atoi(get_text()); return 1; } @@ -86,9 +100,9 @@ int FFMpegVideoBitrate::handle_event() { int ret = FFMpegVideoNum::handle_event(); Asset *asset = window()->asset; - if( asset->ff_video_bitrate ) + if( asset->ff_video_bitrate > 0 ) window()->quality->disable(); - else + else if( !window()->quality->get_textbox()->is_hidden() ) window()->quality->enable(); return ret; } @@ -97,13 +111,21 @@ int FFMpegVideoQuality::handle_event() { int ret = FFMpegVideoNum::handle_event(); Asset *asset = window()->asset; - if( asset->ff_video_quality ) + if( asset->ff_video_quality >= 0 ) window()->bitrate->disable(); - else + else if( !window()->bitrate->get_textbox()->is_hidden() ) window()->bitrate->enable(); 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) @@ -113,7 +135,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) { @@ -121,7 +144,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; } } @@ -186,7 +210,6 @@ int FileFFMPEG::select_video_stream(Asset *asset, int vstream) if( !ff || !asset->video_data ) return 1; asset->width = ff->ff_video_width(vstream); asset->height = ff->ff_video_height(vstream); - asset->video_length = ff->ff_video_frames(vstream); if( (asset->video_length = ff->ff_video_frames(vstream)) < 2 ) asset->video_length = asset->video_length < 0 ? 0 : -1; asset->frame_rate = ff->ff_frame_rate(vstream); @@ -217,6 +240,7 @@ int FileFFMPEG::open_file(int rd, int wr) asset->channels = audio_channels; asset->sample_rate = ff->ff_sample_rate(0); asset->audio_length = ff->ff_audio_samples(0); + strcpy(asset->acodec, ff->ff_audio_format(0)); } int video_layers = ff->ff_total_video_layers(); if( video_layers > 0 ) { @@ -230,6 +254,7 @@ int FileFFMPEG::open_file(int rd, int wr) (asset->video_length = ff->ff_video_frames(0)) < 2 ) asset->video_length = asset->video_length < 0 ? 0 : -1; if( !asset->frame_rate ) asset->frame_rate = ff->ff_frame_rate(0); + strcpy(asset->vcodec, ff->ff_video_format(0)); } IndexState *index_state = asset->index_state; index_state->read_markers(file->preferences->index_directory, asset->path); @@ -313,10 +338,52 @@ int FileFFMPEG::colormodel_supported(int colormodel) 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; } //====== @@ -383,6 +450,7 @@ void FFMPEGConfigAudio::create_objects() bitrate = new FFMpegAudioBitrate(this, x, y, _("Bitrate:"), &asset->ff_audio_bitrate); bitrate->create_objects(); bitrate->set_increment(1000); + bitrate->set_boundaries((int64_t)0, (int64_t)INT_MAX); y += bitrate->get_h() + 10; BC_Title *title = new BC_Title(x, y, _("Audio Options:")); @@ -404,9 +472,10 @@ void FFMPEGConfigAudio::create_objects() audio_options->create_objects(); add_subwindow(new BC_OKButton(this)); add_subwindow(new BC_CancelButton(this)); - show_window(1); - bitrate->handle_event(); + + bitrate->update_param("cin_bitrate", asset->ff_audio_options); + unlock_window(); } @@ -423,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) @@ -440,11 +503,15 @@ int FFMPEGConfigAudioPopup::handle_event() { strcpy(popup->asset->acodec, get_text()); Asset *asset = popup->asset; + asset->ff_audio_bitrate = 0; char option_path[BCTEXTLEN]; FFMPEG::set_option_path(option_path, "audio/%s", asset->acodec); 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; } @@ -523,20 +590,20 @@ void FFMPEGConfigVideo::create_objects() preset_popup = new FFMPEGConfigVideoPopup(this, x, y); preset_popup->create_objects(); - if( asset->ff_video_bitrate && asset->ff_video_quality ) { - asset->ff_video_bitrate = 0; - asset->ff_video_quality = 0; + if( asset->ff_video_bitrate > 0 && asset->ff_video_quality >= 0 ) { + asset->ff_video_bitrate = 0; asset->ff_video_quality = -1; } y += 50; bitrate = new FFMpegVideoBitrate(this, x, y, _("Bitrate:"), &asset->ff_video_bitrate); bitrate->create_objects(); bitrate->set_increment(100000); + bitrate->set_boundaries((int64_t)0, (int64_t)INT_MAX); y += bitrate->get_h() + 5; quality = new FFMpegVideoQuality(this, x, y, _("Quality:"), &asset->ff_video_quality); quality->create_objects(); quality->set_increment(1); - quality->set_boundaries((int64_t)0, (int64_t)31); + quality->set_boundaries((int64_t)-1, (int64_t)51); y += quality->get_h() + 10; BC_Title *title = new BC_Title(x, y, _("Video Options:")); @@ -558,12 +625,13 @@ void FFMPEGConfigVideo::create_objects() video_options->create_objects(); add_subwindow(new BC_OKButton(this)); add_subwindow(new BC_CancelButton(this)); - show_window(1); - if( asset->ff_video_bitrate ) - quality->disable(); - if( asset->ff_video_quality ) - bitrate->disable(); + + bitrate->update_param("cin_bitrate", asset->ff_video_options); + quality->update_param("cin_quality", asset->ff_video_options); + + if( asset->ff_video_bitrate > 0 ) quality->disable(); + else if( asset->ff_video_quality >= 0 ) bitrate->disable(); unlock_window(); } @@ -580,12 +648,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) @@ -598,10 +660,15 @@ int FFMPEGConfigVideoPopup::handle_event() strcpy(popup->asset->vcodec, get_text()); Asset *asset = popup->asset; char option_path[BCTEXTLEN]; + asset->ff_video_bitrate = 0; asset->ff_video_quality = -1; FFMPEG::set_option_path(option_path, "video/%s", asset->vcodec); 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; } @@ -717,7 +784,7 @@ FFOptions_OptPanel:: 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])); @@ -869,7 +936,7 @@ int FFOptionsKind::handle_event() void FFOptionsKind::set(int k) { this->kind = k; - set_text(kinds[k]); + set_text(_(kinds[k])); } FFOptionsText:: @@ -998,6 +1065,9 @@ void FFOptions::initialize(FFOptionsWindow *win, int kind) if( dupl ) continue; FFOptions_Opt *fopt = new FFOptions_Opt(this, opt, opt->name); append(fopt); + AVDictionaryEntry *elem = av_dict_get(win->dialog->ff_opts, + opt->name, 0, AV_DICT_IGNORE_SUFFIX); + if( elem && elem->value ) fopt->set(elem->value); char val[BCTEXTLEN], *vp = fopt->get(val, sizeof(val)); fopt->item_value->update(vp); } @@ -1145,25 +1215,25 @@ int FFOptions_Opt::types(char *rp) { const char *cp = ""; if( opt ) switch (opt->type) { - case AV_OPT_TYPE_FLAGS: cp = ""; break; - case AV_OPT_TYPE_INT: cp = ""; break; - case AV_OPT_TYPE_INT64: cp = ""; break; - case AV_OPT_TYPE_DOUBLE: cp = ""; break; - case AV_OPT_TYPE_FLOAT: cp = ""; break; - case AV_OPT_TYPE_STRING: cp = ""; break; - case AV_OPT_TYPE_RATIONAL: cp = ""; break; - case AV_OPT_TYPE_BINARY: cp = ""; break; - case AV_OPT_TYPE_IMAGE_SIZE: cp = ""; break; - case AV_OPT_TYPE_VIDEO_RATE: cp = ""; break; - case AV_OPT_TYPE_PIXEL_FMT: cp = ""; break; - case AV_OPT_TYPE_SAMPLE_FMT: cp = ""; break; - case AV_OPT_TYPE_DURATION: cp = ""; break; - case AV_OPT_TYPE_COLOR: cp = ""; break; - case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = ""; break; - case AV_OPT_TYPE_BOOL: cp = ""; break; - default: cp = ""; break; + case AV_OPT_TYPE_FLAGS: cp = N_(""); break; + case AV_OPT_TYPE_INT: cp = N_(""); break; + case AV_OPT_TYPE_INT64: cp = N_(""); break; + case AV_OPT_TYPE_DOUBLE: cp = N_(""); break; + case AV_OPT_TYPE_FLOAT: cp = N_(""); break; + case AV_OPT_TYPE_STRING: cp = N_(""); break; + case AV_OPT_TYPE_RATIONAL: cp = N_(""); break; + case AV_OPT_TYPE_BINARY: cp = N_(""); break; + case AV_OPT_TYPE_IMAGE_SIZE: cp = N_(""); break; + case AV_OPT_TYPE_VIDEO_RATE: cp = N_(""); break; + case AV_OPT_TYPE_PIXEL_FMT: cp = N_(""); break; + case AV_OPT_TYPE_SAMPLE_FMT: cp = N_(""); break; + case AV_OPT_TYPE_DURATION: cp = N_(""); break; + case AV_OPT_TYPE_COLOR: cp = N_(""); break; + case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = N_(""); break; + case AV_OPT_TYPE_BOOL: cp = N_(""); break; + default: cp = N_(""); break; } - return sprintf(rp, "%s", cp); + return sprintf(rp, "%s", _(cp)); } int FFOptions_Opt::scalar(double d, char *rp) { @@ -1281,7 +1351,7 @@ const char *FFOptions_Opt::tip() 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; @@ -1294,23 +1364,30 @@ FFOptionsWindow::~FFOptionsWindow() 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())); @@ -1318,8 +1395,9 @@ void FFOptionsWindow::create_objects() 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); @@ -1408,8 +1486,8 @@ void FFOptionsDialog::store_options(char *cp, int len) *cp = 0; } -void FFOptionsDialog::start(const char *codec_name, AVCodec *codec, - const 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"); @@ -1418,6 +1496,7 @@ void FFOptionsDialog::start(const char *codec_name, AVCodec *codec, return; } + this->format_name = cstrdup(format_name); this->codec_name = cstrdup(codec_name); this->codec = codec; this->ff_opts = 0; @@ -1442,6 +1521,7 @@ void FFOptionsDialog::handle_done_event(int result) update_options(options); } options_window = 0; + delete [] format_name; format_name = 0; delete [] codec_name; codec_name = 0; av_dict_free(&ff_opts); } @@ -1489,17 +1569,19 @@ FFOptionsViewAudio::~FFOptionsViewAudio() 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, + aud_config->ff_options_dialog->start(audio_format, audio_codec, codec, asset->ff_audio_options, sizeof(asset->ff_audio_options)); return 1; } @@ -1516,17 +1598,19 @@ FFOptionsViewVideo::~FFOptionsViewVideo() 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, + vid_config->ff_options_dialog->start(video_format, video_codec, codec, asset->ff_video_options, sizeof(asset->ff_video_options)); return 1; }