summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-11-04 02:12:12 +0000
committerCarl Hetherington <cth@carlh.net>2012-11-04 02:12:12 +0000
commite193babcec6a26bc1ee83d99d009bd5a3751a5bc (patch)
tree813d9e4c224a800ab60c5134dfa340168ed989f9 /src
parentfad1998b907232b01a46369a49b55129149613bb (diff)
Untested trim of start and end.
Diffstat (limited to 'src')
-rw-r--r--src/lib/decoder.cc23
-rw-r--r--src/lib/decoder.h4
-rw-r--r--src/lib/ffmpeg_decoder.cc2
-rw-r--r--src/lib/ffmpeg_decoder.h2
-rw-r--r--src/lib/film.cc35
-rw-r--r--src/lib/film.h20
-rw-r--r--src/lib/imagemagick_decoder.cc2
-rw-r--r--src/lib/imagemagick_decoder.h2
-rw-r--r--src/lib/tiff_decoder.cc2
-rw-r--r--src/lib/tiff_decoder.h2
-rw-r--r--src/wx/dcp_range_dialog.cc78
-rw-r--r--src/wx/dcp_range_dialog.h15
-rw-r--r--src/wx/film_editor.cc33
-rw-r--r--src/wx/film_editor.h2
-rw-r--r--src/wx/properties_dialog.cc3
15 files changed, 87 insertions, 138 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc
index 32d0bab64..6da45a788 100644
--- a/src/lib/decoder.cc
+++ b/src/lib/decoder.cc
@@ -142,27 +142,13 @@ Decoder::go ()
while (pass () == false) {
if (_job && _film->dcp_length()) {
- _job->set_progress (float (_video_frame_index) / _film->dcp_length().get());
+ _job->set_progress (float ((_video_frame_index - _film->dcp_trim_start())) / _film->dcp_length().get());
}
}
process_end ();
}
-/** Run one pass. This may or may not generate any actual video / audio data;
- * some decoders may require several passes to generate a single frame.
- * @return true if we have finished processing all data; otherwise false.
- */
-bool
-Decoder::pass ()
-{
- if (!_ignore_length && _video_frame_index >= _film->dcp_length()) {
- return true;
- }
-
- return do_pass ();
-}
-
/** Called by subclasses to tell the world that some audio data is ready
* @param data Audio data, in Film::audio_sample_format.
* @param size Number of bytes of data.
@@ -265,6 +251,8 @@ Decoder::emit_audio (uint8_t* data, int size)
void
Decoder::process_video (AVFrame* frame)
{
+ assert (_film->length());
+
if (_minimal) {
++_video_frame_index;
return;
@@ -282,6 +270,11 @@ Decoder::process_video (AVFrame* frame)
return;
}
+ if (_film->dcp_trim_start() > _video_frame_index || (_film->length().get() - _film->dcp_trim_end()) < _video_frame_index) {
+ ++_video_frame_index;
+ return;
+ }
+
shared_ptr<FilterGraph> graph;
list<shared_ptr<FilterGraph> >::iterator i = _filter_graphs.begin();
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 6cd7757b6..e8e73cc9f 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -76,7 +76,7 @@ public:
virtual int sample_aspect_ratio_denominator () const = 0;
void process_begin ();
- bool pass ();
+ virtual bool pass () = 0;
void process_end ();
void go ();
@@ -105,8 +105,6 @@ public:
protected:
- /** perform a single pass at our content */
- virtual bool do_pass () = 0;
virtual PixelFormat pixel_format () const = 0;
void process_video (AVFrame *);
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 09f699543..198925bd3 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -218,7 +218,7 @@ FFmpegDecoder::setup_subtitle ()
bool
-FFmpegDecoder::do_pass ()
+FFmpegDecoder::pass ()
{
int r = av_read_frame (_format_context, &_packet);
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index c04dba5b3..3f96c1632 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -69,7 +69,7 @@ public:
private:
- bool do_pass ();
+ bool pass ();
PixelFormat pixel_format () const;
int time_base_numerator () const;
int time_base_denominator () const;
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 70c8f7db2..b2abe4759 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -82,6 +82,8 @@ Film::Film (string d, bool must_exist)
, _dcp_content_type (0)
, _format (0)
, _scaler (Scaler::from_id ("bicubic"))
+ , _dcp_trim_start (0)
+ , _dcp_trim_end (0)
, _dcp_ab (false)
, _audio_stream (-1)
, _audio_gain (0)
@@ -141,7 +143,8 @@ Film::Film (Film const & o)
, _crop (o._crop)
, _filters (o._filters)
, _scaler (o._scaler)
- , _dcp_frames (o._dcp_frames)
+ , _dcp_trim_start (o._dcp_trim_start)
+ , _dcp_trim_end (o._dcp_trim_end)
, _dcp_ab (o._dcp_ab)
, _audio_stream (o._audio_stream)
, _audio_gain (o._audio_gain)
@@ -402,7 +405,8 @@ Film::write_metadata () const
f << "filter " << (*i)->id () << "\n";
}
f << "scaler " << _scaler->id () << "\n";
- f << "dcp_frames " << _dcp_frames.get_value_or(0) << "\n";
+ f << "dcp_trim_start " << _dcp_trim_start << "\n";
+ f << "dcp_trim_end " << _dcp_trim_end << "\n";
f << "dcp_ab " << (_dcp_ab ? "1" : "0") << "\n";
f << "selected_audio_stream " << _audio_stream << "\n";
f << "audio_gain " << _audio_gain << "\n";
@@ -481,11 +485,10 @@ Film::read_metadata ()
_filters.push_back (Filter::from_id (v));
} else if (k == "scaler") {
_scaler = Scaler::from_id (v);
- } else if (k == "dcp_frames") {
- int const vv = atoi (v.c_str ());
- if (vv) {
- _dcp_frames = vv;
- }
+ } else if (k == "dcp_trim_start") {
+ _dcp_trim_start = atoi (v.c_str ());
+ } else if (k == "dcp_trim_end") {
+ _dcp_trim_end = atoi (v.c_str ());
} else if (k == "dcp_ab") {
_dcp_ab = (v == "1");
} else if (k == "selected_audio_stream") {
@@ -699,11 +702,7 @@ Film::dcp_length () const
return boost::optional<int> ();
}
- if (dcp_frames()) {
- return min (dcp_frames().get(), length().get());
- }
-
- return length();
+ return length().get() - dcp_trim_start() - dcp_trim_end();
}
/** @return a DCI-compliant name for a DCP of this film */
@@ -1012,23 +1011,23 @@ Film::set_scaler (Scaler const * s)
}
void
-Film::set_dcp_frames (int f)
+Film::set_dcp_trim_start (int t)
{
{
boost::mutex::scoped_lock lm (_state_mutex);
- _dcp_frames = f;
+ _dcp_trim_start = t;
}
- signal_changed (DCP_FRAMES);
+ signal_changed (DCP_TRIM_START);
}
void
-Film::unset_dcp_frames ()
+Film::set_dcp_trim_end (int t)
{
{
boost::mutex::scoped_lock lm (_state_mutex);
- _dcp_frames = boost::none;
+ _dcp_trim_end = t;
}
- signal_changed (DCP_FRAMES);
+ signal_changed (DCP_TRIM_END);
}
void
diff --git a/src/lib/film.h b/src/lib/film.h
index ff312fcb5..eeaae2acd 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -117,7 +117,8 @@ public:
CROP,
FILTERS,
SCALER,
- DCP_FRAMES,
+ DCP_TRIM_START,
+ DCP_TRIM_END,
DCP_AB,
AUDIO_STREAM,
AUDIO_GAIN,
@@ -186,11 +187,16 @@ public:
return _scaler;
}
- boost::optional<int> dcp_frames () const {
+ int dcp_trim_start () const {
boost::mutex::scoped_lock lm (_state_mutex);
- return _dcp_frames;
+ return _dcp_trim_start;
}
+ int dcp_trim_end () const {
+ boost::mutex::scoped_lock lm (_state_mutex);
+ return _dcp_trim_end;
+ }
+
bool dcp_ab () const {
boost::mutex::scoped_lock lm (_state_mutex);
return _dcp_ab;
@@ -344,8 +350,8 @@ public:
void set_bottom_crop (int);
void set_filters (std::vector<Filter const *>);
void set_scaler (Scaler const *);
- void set_dcp_frames (int);
- void unset_dcp_frames ();
+ void set_dcp_trim_start (int);
+ void set_dcp_trim_end (int);
void set_dcp_ab (bool);
void set_audio_stream (int);
void set_audio_gain (float);
@@ -416,8 +422,8 @@ private:
std::vector<Filter const *> _filters;
/** Scaler algorithm to use */
Scaler const * _scaler;
- /** Maximum number of frames to put in the DCP, if applicable */
- boost::optional<int> _dcp_frames;
+ int _dcp_trim_start;
+ int _dcp_trim_end;
/** true to create an A/B comparison DCP, where the left half of the image
is the video without any filters or post-processing, and the right half
has the specified filters and post-processing.
diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc
index 76d89b7d8..8abefdbb9 100644
--- a/src/lib/imagemagick_decoder.cc
+++ b/src/lib/imagemagick_decoder.cc
@@ -41,7 +41,7 @@ ImageMagickDecoder::native_size () const
}
bool
-ImageMagickDecoder::do_pass ()
+ImageMagickDecoder::pass ()
{
using namespace MagickCore;
diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h
index 13b53b685..c8e47d47d 100644
--- a/src/lib/imagemagick_decoder.h
+++ b/src/lib/imagemagick_decoder.h
@@ -59,7 +59,7 @@ public:
}
protected:
- bool do_pass ();
+ bool pass ();
PixelFormat pixel_format () const;
int time_base_numerator () const {
diff --git a/src/lib/tiff_decoder.cc b/src/lib/tiff_decoder.cc
index 9058fcc2a..e75f2c482 100644
--- a/src/lib/tiff_decoder.cc
+++ b/src/lib/tiff_decoder.cc
@@ -131,7 +131,7 @@ TIFFDecoder::audio_channel_layout () const
}
bool
-TIFFDecoder::do_pass ()
+TIFFDecoder::pass ()
{
if (_iter == _files.end ()) {
return true;
diff --git a/src/lib/tiff_decoder.h b/src/lib/tiff_decoder.h
index 1c287ee06..7bbff7dfe 100644
--- a/src/lib/tiff_decoder.h
+++ b/src/lib/tiff_decoder.h
@@ -56,7 +56,7 @@ public:
}
private:
- bool do_pass ();
+ bool pass ();
PixelFormat pixel_format () const;
int time_base_numerator () const;
int time_base_denominator () const;
diff --git a/src/wx/dcp_range_dialog.cc b/src/wx/dcp_range_dialog.cc
index 5ecd3168e..e249f6fc6 100644
--- a/src/wx/dcp_range_dialog.cc
+++ b/src/wx/dcp_range_dialog.cc
@@ -27,36 +27,23 @@ DCPRangeDialog::DCPRangeDialog (wxWindow* p, shared_ptr<Film> f)
: wxDialog (p, wxID_ANY, wxString (_("DCP Range")))
, _film (f)
{
- wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
+ wxFlexGridSizer* table = new wxFlexGridSizer (3, 6, 6);
- _whole = new wxRadioButton (this, wxID_ANY, _("Whole film"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
- table->Add (_whole, 1);
- table->AddSpacer (0);
-
- _first = new wxRadioButton (this, wxID_ANY, _("First"));
- table->Add (_first);
- {
- wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
- _n_frames = new wxSpinCtrl (this, wxID_ANY);
- s->Add (_n_frames);
- add_label_to_sizer (s, this, "frames");
- table->Add (s);
- }
+ add_label_to_sizer (table, this, "Trim start");
+ _trim_start = new wxSpinCtrl (this, wxID_ANY);
+ table->Add (_trim_start, 1);
+ add_label_to_sizer (table, this, "frames");
- _n_frames->SetRange (1, INT_MAX - 1);
- if (_film->dcp_frames()) {
- _whole->SetValue (false);
- _first->SetValue (true);
- _n_frames->SetValue (_film->dcp_frames().get());
- } else {
- _whole->SetValue (true);
- _first->SetValue (false);
- _n_frames->SetValue (24);
- }
+ add_label_to_sizer (table, this, "Trim end");
+ _trim_end = new wxSpinCtrl (this, wxID_ANY);
+ table->Add (_trim_end, 1);
+ add_label_to_sizer (table, this, "frames");
- _whole->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::whole_toggled), 0, this);
- _first->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::first_toggled), 0, this);
- _n_frames->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (DCPRangeDialog::n_frames_changed), 0, this);
+ _trim_start->SetValue (_film->dcp_trim_start());
+ _trim_end->SetValue (_film->dcp_trim_end());
+
+ _trim_start->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (DCPRangeDialog::emit_changed), 0, this);
+ _trim_end->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (DCPRangeDialog::emit_changed), 0, this);
wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
overall_sizer->Add (table, 0, wxALL, 6);
@@ -68,43 +55,10 @@ DCPRangeDialog::DCPRangeDialog (wxWindow* p, shared_ptr<Film> f)
SetSizer (overall_sizer);
overall_sizer->SetSizeHints (this);
-
- set_sensitivity ();
-}
-
-void
-DCPRangeDialog::whole_toggled (wxCommandEvent &)
-{
- set_sensitivity ();
- emit_changed ();
}
void
-DCPRangeDialog::first_toggled (wxCommandEvent &)
+DCPRangeDialog::emit_changed (wxCommandEvent &)
{
- set_sensitivity ();
- emit_changed ();
-}
-
-void
-DCPRangeDialog::set_sensitivity ()
-{
- _n_frames->Enable (_first->GetValue ());
-}
-
-void
-DCPRangeDialog::n_frames_changed (wxCommandEvent &)
-{
- emit_changed ();
-}
-
-void
-DCPRangeDialog::emit_changed ()
-{
- int frames = 0;
- if (!_whole->GetValue ()) {
- frames = _n_frames->GetValue ();
- }
-
- Changed (frames);
+ Changed (_trim_start->GetValue(), _trim_end->GetValue());
}
diff --git a/src/wx/dcp_range_dialog.h b/src/wx/dcp_range_dialog.h
index e3f875e51..2196c2611 100644
--- a/src/wx/dcp_range_dialog.h
+++ b/src/wx/dcp_range_dialog.h
@@ -28,18 +28,15 @@ class DCPRangeDialog : public wxDialog
public:
DCPRangeDialog (wxWindow *, boost::shared_ptr<Film>);
- boost::signals2::signal<void (int)> Changed;
+ boost::signals2::signal<void (int, int)> Changed;
private:
- void whole_toggled (wxCommandEvent &);
- void first_toggled (wxCommandEvent &);
- void n_frames_changed (wxCommandEvent &);
+ void trim_start_changed (wxCommandEvent &);
+ void trim_end_changed (wxCommandEvent &);
- void set_sensitivity ();
- void emit_changed ();
+ void emit_changed (wxCommandEvent &);
boost::shared_ptr<Film> _film;
- wxRadioButton* _whole;
- wxRadioButton* _first;
- wxSpinCtrl* _n_frames;
+ wxSpinCtrl* _trim_start;
+ wxSpinCtrl* _trim_end;
};
diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc
index 8bcbd2beb..7038a18b0 100644
--- a/src/wx/film_editor.cc
+++ b/src/wx/film_editor.cc
@@ -502,20 +502,23 @@ FilmEditor::film_changed (Film::Property p)
break;
case Film::THUMBS:
break;
- case Film::DCP_FRAMES:
- if (!_film->dcp_frames()) {
- _dcp_range->SetLabel (wxT ("Whole film"));
- } else {
- _dcp_range->SetLabel (std_to_wx (String::compose ("First %1 frames", _film->dcp_frames().get())));
- }
- _sizer->Layout ();
- break;
case Film::DCP_AB:
_dcp_ab->SetValue (_film->dcp_ab ());
break;
case Film::SCALER:
_scaler->SetSelection (Scaler::as_index (_film->scaler ()));
break;
+ case Film::DCP_TRIM_START:
+ case Film::DCP_TRIM_END:
+ if (_film->dcp_trim_start() == 0 && _film->dcp_trim_end() == 0) {
+ _dcp_range->SetLabel (wxT ("Whole film"));
+ } else {
+ _dcp_range->SetLabel (
+ std_to_wx (String::compose ("Trim %1 frames from start and %2 frames from end", _film->dcp_trim_start(), _film->dcp_trim_end()))
+ );
+ }
+ _sizer->Layout ();
+ break;
case Film::AUDIO_GAIN:
_audio_gain->SetValue (_film->audio_gain ());
break;
@@ -616,7 +619,8 @@ FilmEditor::set_film (shared_ptr<Film> f)
film_changed (Film::FORMAT);
film_changed (Film::CROP);
film_changed (Film::FILTERS);
- film_changed (Film::DCP_FRAMES);
+ film_changed (Film::DCP_TRIM_START);
+ film_changed (Film::DCP_TRIM_END);
film_changed (Film::DCP_AB);
film_changed (Film::SIZE);
film_changed (Film::LENGTH);
@@ -764,18 +768,15 @@ void
FilmEditor::change_dcp_range_clicked (wxCommandEvent &)
{
DCPRangeDialog* d = new DCPRangeDialog (this, _film);
- d->Changed.connect (bind (&FilmEditor::dcp_range_changed, this, _1));
+ d->Changed.connect (bind (&FilmEditor::dcp_range_changed, this, _1, _2));
d->ShowModal ();
}
void
-FilmEditor::dcp_range_changed (int frames)
+FilmEditor::dcp_range_changed (int start, int end)
{
- if (frames == 0) {
- _film->unset_dcp_frames ();
- } else {
- _film->set_dcp_frames (frames);
- }
+ _film->set_dcp_trim_start (start);
+ _film->set_dcp_trim_end (end);
}
void
diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h
index 936dd7d6b..e9f8d35e5 100644
--- a/src/wx/film_editor.h
+++ b/src/wx/film_editor.h
@@ -54,7 +54,7 @@ private:
void bottom_crop_changed (wxCommandEvent &);
void content_changed (wxCommandEvent &);
void format_changed (wxCommandEvent &);
- void dcp_range_changed (int);
+ void dcp_range_changed (int, int);
void dcp_content_type_changed (wxCommandEvent &);
void dcp_ab_toggled (wxCommandEvent &);
void scaler_changed (wxCommandEvent &);
diff --git a/src/wx/properties_dialog.cc b/src/wx/properties_dialog.cc
index 0ffbd06cb..61e1f34f0 100644
--- a/src/wx/properties_dialog.cc
+++ b/src/wx/properties_dialog.cc
@@ -92,7 +92,8 @@ PropertiesDialog::frames_already_encoded () const
}
if (_film->dcp_length()) {
- u << " (" << (_film->encoded_frames() * 100 / _film->dcp_length().get()) << "%)";
+ /* XXX: encoded_frames() should check which frames have been encoded */
+ u << " (" << ((_film->encoded_frames() - _film->dcp_trim_start()) * 100 / _film->dcp_length().get()) << "%)";
}
return u.str ();
}