summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-10-09 15:56:55 +0100
committerCarl Hetherington <cth@carlh.net>2012-10-09 15:56:55 +0100
commitb5828ccf20a0e0c4365854ac19a05d5a4783e254 (patch)
tree338fd3dfc1b7f74edf4fb2615ed6d1136942f4d8 /src
parent9b0d04f34424c9aeddaf07007838f2c8c0113093 (diff)
Make subtitle addition optional.
Diffstat (limited to 'src')
-rw-r--r--src/lib/decoder.h1
-rw-r--r--src/lib/ffmpeg_decoder.cc7
-rw-r--r--src/lib/ffmpeg_decoder.h1
-rw-r--r--src/lib/film.cc8
-rw-r--r--src/lib/film.h12
-rw-r--r--src/lib/film_state.cc6
-rw-r--r--src/lib/film_state.h5
-rw-r--r--src/lib/imagemagick_decoder.h4
-rw-r--r--src/lib/tiff_decoder.h3
-rw-r--r--src/wx/film_editor.cc32
-rw-r--r--src/wx/film_editor.h3
11 files changed, 80 insertions, 2 deletions
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 7ca9bb1df..9a4c7695e 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -66,6 +66,7 @@ public:
/** @return format of audio samples */
virtual AVSampleFormat audio_sample_format () const = 0;
virtual int64_t audio_channel_layout () const = 0;
+ virtual bool has_subtitles () const = 0;
void process_begin ();
bool pass ();
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 808e5ac9b..7bc579ba6 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -249,7 +249,7 @@ FFmpegDecoder::do_pass ()
process_audio (_frame->data[0], data_size);
}
- } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream) {
+ } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _fs->with_subtitles) {
if (_have_subtitle) {
avsubtitle_free (&_subtitle);
@@ -453,3 +453,8 @@ FFmpegDecoder::overlay (shared_ptr<Image> image) const
}
}
+bool
+FFmpegDecoder::has_subtitles () const
+{
+ return (_subtitle_stream != -1);
+}
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index 18c2e2aeb..59ec7573d 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -63,6 +63,7 @@ public:
int audio_sample_rate () const;
AVSampleFormat audio_sample_format () const;
int64_t audio_channel_layout () const;
+ bool has_subtitles () const;
private:
diff --git a/src/lib/film.cc b/src/lib/film.cc
index e2b3d4bc3..96dc3d3a4 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -217,6 +217,7 @@ Film::set_content (string c)
_state.audio_channels = d->audio_channels ();
_state.audio_sample_rate = d->audio_sample_rate ();
_state.audio_sample_format = d->audio_sample_format ();
+ _state.has_subtitles = d->has_subtitles ();
_state.content_digest = md5_digest (s->content_path ());
_state.content = c;
@@ -658,3 +659,10 @@ Film::encoded_frames () const
return N;
}
+
+void
+Film::set_with_subtitles (bool w)
+{
+ _state.with_subtitles = w;
+ signal_changed (WITH_SUBTITLES);
+}
diff --git a/src/lib/film.h b/src/lib/film.h
index cd3b1b8a8..919cecc22 100644
--- a/src/lib/film.h
+++ b/src/lib/film.h
@@ -119,6 +119,10 @@ public:
int still_duration () const {
return _state.still_duration;
}
+
+ bool with_subtitles () const {
+ return _state.with_subtitles;
+ }
void set_filters (std::vector<Filter const *> const &);
@@ -144,6 +148,7 @@ public:
void set_audio_gain (float);
void set_audio_delay (int);
void set_still_duration (int);
+ void set_with_subtitles (bool);
/** @return size, in pixels, of the source (ignoring cropping) */
Size size () const {
@@ -174,6 +179,10 @@ public:
AVSampleFormat audio_sample_format () const {
return _state.audio_sample_format;
}
+
+ bool has_subtitles () const {
+ return _state.has_subtitles;
+ }
std::string j2k_dir () const;
@@ -218,7 +227,8 @@ public:
FRAMES_PER_SECOND,
AUDIO_CHANNELS,
AUDIO_SAMPLE_RATE,
- STILL_DURATION
+ STILL_DURATION,
+ WITH_SUBTITLES,
};
boost::shared_ptr<FilmState> state_copy () const;
diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc
index 3cd7091ca..1872d9e76 100644
--- a/src/lib/film_state.cc
+++ b/src/lib/film_state.cc
@@ -80,6 +80,7 @@ FilmState::write_metadata (ofstream& f) const
f << "audio_gain " << audio_gain << "\n";
f << "audio_delay " << audio_delay << "\n";
f << "still_duration " << still_duration << "\n";
+ f << "with_subtitles " << with_subtitles << "\n";
/* Cached stuff; this is information about our content; we could
look it up each time, but that's slow.
@@ -94,6 +95,7 @@ FilmState::write_metadata (ofstream& f) const
f << "audio_sample_rate " << audio_sample_rate << "\n";
f << "audio_sample_format " << audio_sample_format_to_string (audio_sample_format) << "\n";
f << "content_digest " << content_digest << "\n";
+ f << "has_subtitles " << has_subtitles << "\n";
}
/** Read state from a key / value pair.
@@ -142,6 +144,8 @@ FilmState::read_metadata (string k, string v)
audio_delay = atoi (v.c_str ());
} else if (k == "still_duration") {
still_duration = atoi (v.c_str ());
+ } else if (k == "with_subtitles") {
+ with_subtitles = (v == "1");
}
/* Cached stuff */
@@ -165,6 +169,8 @@ FilmState::read_metadata (string k, string v)
audio_sample_format = audio_sample_format_from_string (v);
} else if (k == "content_digest") {
content_digest = v;
+ } else if (k == "has_subtitles") {
+ has_subtitles = (v == "1");
}
}
diff --git a/src/lib/film_state.h b/src/lib/film_state.h
index 16a1b0508..2b792694c 100644
--- a/src/lib/film_state.h
+++ b/src/lib/film_state.h
@@ -62,10 +62,12 @@ public:
, audio_gain (0)
, audio_delay (0)
, still_duration (10)
+ , with_subtitles (false)
, length (0)
, audio_channels (0)
, audio_sample_rate (0)
, audio_sample_format (AV_SAMPLE_FMT_NONE)
+ , has_subtitles (false)
{}
std::string file (std::string f) const;
@@ -126,6 +128,7 @@ public:
int audio_delay;
/** Duration to make still-sourced films (in seconds) */
int still_duration;
+ bool with_subtitles;
/* Data which is cached to speed things up */
@@ -143,6 +146,8 @@ public:
AVSampleFormat audio_sample_format;
/** MD5 digest of our content file */
std::string content_digest;
+ /** true if the source has subtitles */
+ bool has_subtitles;
private:
std::string thumb_file_for_frame (int) const;
diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h
index aca91ef55..05dc7f113 100644
--- a/src/lib/imagemagick_decoder.h
+++ b/src/lib/imagemagick_decoder.h
@@ -35,6 +35,10 @@ public:
return 0;
}
+ bool has_subtitles () const {
+ return false;
+ }
+
static float static_frames_per_second () {
return 24;
}
diff --git a/src/lib/tiff_decoder.h b/src/lib/tiff_decoder.h
index d9b5b3969..b9849a259 100644
--- a/src/lib/tiff_decoder.h
+++ b/src/lib/tiff_decoder.h
@@ -53,6 +53,9 @@ public:
int audio_sample_rate () const;
AVSampleFormat audio_sample_format () const;
int64_t audio_channel_layout () const;
+ bool has_subtitles () const {
+ return false;
+ }
private:
bool do_pass ();
diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc
index 3b26a5537..bc7414c41 100644
--- a/src/wx/film_editor.cc
+++ b/src/wx/film_editor.cc
@@ -130,6 +130,11 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
_sizer->Add (s);
}
+ _with_subtitles = new wxCheckBox (this, wxID_ANY, wxT("With Subtitles"));
+ video_control (_with_subtitles);
+ _sizer->Add (_with_subtitles, 1);
+ _sizer->AddSpacer (0);
+
video_control (add_label_to_sizer (_sizer, this, "Frames Per Second"));
_frames_per_second = new wxStaticText (this, wxID_ANY, wxT (""));
_sizer->Add (video_control (_frames_per_second), 1, wxALIGN_CENTER_VERTICAL);
@@ -292,6 +297,7 @@ FilmEditor::content_changed (wxCommandEvent &)
setup_visibility ();
setup_formats ();
+ setup_subtitle_button ();
}
/** Called when the DCP A/B switch has been toggled */
@@ -340,6 +346,7 @@ FilmEditor::film_changed (Film::Property p)
_content->SetPath (std_to_wx (_film->content ()));
setup_visibility ();
setup_formats ();
+ setup_subtitle_button ();
break;
case Film::FORMAT:
{
@@ -437,6 +444,9 @@ FilmEditor::film_changed (Film::Property p)
case Film::STILL_DURATION:
_still_duration->SetValue (_film->still_duration ());
break;
+ case Film::WITH_SUBTITLES:
+ _with_subtitles->SetValue (_film->with_subtitles ());
+ break;
}
}
@@ -702,3 +712,25 @@ FilmEditor::setup_formats ()
_sizer->Layout ();
}
+
+void
+FilmEditor::with_subtitles_toggled (wxCommandEvent &)
+{
+ if (!_film) {
+ return;
+ }
+
+ _ignore_changes = Film::WITH_SUBTITLES;
+ _film->set_with_subtitles (_with_subtitles->GetValue ());
+ _ignore_changes = Film::NONE;
+}
+
+void
+FilmEditor::setup_subtitle_button ()
+{
+ _with_subtitles->Enable (_film->has_subtitles ());
+ if (!_film->has_subtitles ()) {
+ _with_subtitles->SetValue (false);
+ }
+}
+
diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h
index c599cd285..720e71902 100644
--- a/src/wx/film_editor.h
+++ b/src/wx/film_editor.h
@@ -58,6 +58,7 @@ private:
void audio_gain_changed (wxCommandEvent &);
void audio_gain_calculate_button_clicked (wxCommandEvent &);
void audio_delay_changed (wxCommandEvent &);
+ void with_subtitles_toggled (wxCommandEvent &);
void still_duration_changed (wxCommandEvent &);
/* Handle changes to the model */
@@ -69,6 +70,7 @@ private:
void set_things_sensitive (bool);
void setup_formats ();
+ void setup_subtitle_button ();
wxControl* video_control (wxControl *);
wxControl* still_control (wxControl *);
@@ -103,6 +105,7 @@ private:
wxButton* _audio_gain_calculate_button;
/** The Film's audio delay */
wxSpinCtrl* _audio_delay;
+ wxCheckBox* _with_subtitles;
/** The Film's DCP content type */
wxComboBox* _dcp_content_type;
/** The Film's frames per second */