summaryrefslogtreecommitdiff
path: root/src/lib
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/lib
parentfad1998b907232b01a46369a49b55129149613bb (diff)
Untested trim of start and end.
Diffstat (limited to 'src/lib')
-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
10 files changed, 45 insertions, 49 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;