summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-12-16 12:51:00 +0000
committerCarl Hetherington <cth@carlh.net>2012-12-16 12:51:00 +0000
commitc726a221e619d22ad5253eaa6c3429bce557e111 (patch)
tree7ede9f30ca2801b8bb0fdb44cd3615f85e488a9a /src/lib
parent9c58fcdb6fd8131c17456dd71c5c277a6b0ae053 (diff)
Various fixes.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/decoder.cc2
-rw-r--r--src/lib/decoder.h5
-rw-r--r--src/lib/ffmpeg_decoder.cc92
-rw-r--r--src/lib/ffmpeg_decoder.h3
-rw-r--r--src/lib/image.cc2
-rw-r--r--src/lib/options.h3
6 files changed, 62 insertions, 45 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc
index 577894996..93ce2cdbb 100644
--- a/src/lib/decoder.cc
+++ b/src/lib/decoder.cc
@@ -57,7 +57,7 @@ Decoder::Decoder (boost::shared_ptr<Film> f, boost::shared_ptr<const Options> o,
}
-void
+bool
Decoder::seek (SourceFrame f)
{
throw DecodeError ("decoder does not support seek");
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 96d3a2014..e4693fb6d 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -58,7 +58,10 @@ public:
virtual ~Decoder () {}
virtual bool pass () = 0;
- virtual void seek (SourceFrame);
+ /** Seek.
+ * @return true on error.
+ */
+ virtual bool seek (SourceFrame);
protected:
/** our Film */
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index f4c7d3d85..c7c96ce68 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -270,46 +270,10 @@ FFmpegDecoder::pass ()
_film->log()->log (String::compose ("Used only %1 bytes of %2 in packet", r, _packet.size));
}
- /* Where we are in the output, in seconds */
- double const out_pts_seconds = video_frame() / frames_per_second();
-
- /* Where we are in the source, in seconds */
- double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base)
- * av_frame_get_best_effort_timestamp(_frame);
-
- _film->log()->log (
- String::compose ("Source video frame ready; source at %1, output at %2", source_pts_seconds, out_pts_seconds),
- Log::VERBOSE
- );
-
- if (!_first_video) {
- _first_video = source_pts_seconds;
- }
-
- /* Difference between where we are and where we should be */
- double const delta = source_pts_seconds - _first_video.get() - out_pts_seconds;
- double const one_frame = 1 / frames_per_second();
-
- /* Insert frames if required to get out_pts_seconds up to pts_seconds */
- if (delta > one_frame) {
- int const extra = rint (delta / one_frame);
- for (int i = 0; i < extra; ++i) {
- repeat_last_video ();
- _film->log()->log (
- String::compose (
- "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)",
- out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second()
- )
- );
- }
- }
-
- if (delta > -one_frame) {
- /* Process this frame */
- filter_and_emit_video (_frame);
+ if (_opt->decoder_alignment) {
+ out_careful ();
} else {
- /* Otherwise we are omitting a frame to keep things right */
- _film->log()->log (String::compose ("Frame removed at %1s", out_pts_seconds));
+ filter_and_emit_video (_frame);
}
}
@@ -584,12 +548,13 @@ FFmpegDecoder::filter_and_emit_video (AVFrame* frame)
}
}
-void
+bool
FFmpegDecoder::seek (SourceFrame f)
{
int64_t const t = static_cast<int64_t>(f) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second());
- av_seek_frame (_format_context, _video_stream, t, 0);
+ int const r = av_seek_frame (_format_context, _video_stream, t, 0);
avcodec_flush_buffers (_video_codec_context);
+ return r < 0;
}
shared_ptr<FFmpegAudioStream>
@@ -645,3 +610,48 @@ FFmpegAudioStream::to_string () const
}
+void
+FFmpegDecoder::out_careful ()
+{
+ /* Where we are in the output, in seconds */
+ double const out_pts_seconds = video_frame() / frames_per_second();
+
+ /* Where we are in the source, in seconds */
+ double const source_pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base)
+ * av_frame_get_best_effort_timestamp(_frame);
+
+ _film->log()->log (
+ String::compose ("Source video frame ready; source at %1, output at %2", source_pts_seconds, out_pts_seconds),
+ Log::VERBOSE
+ );
+
+ if (!_first_video) {
+ _first_video = source_pts_seconds;
+ }
+
+ /* Difference between where we are and where we should be */
+ double const delta = source_pts_seconds - _first_video.get() - out_pts_seconds;
+ double const one_frame = 1 / frames_per_second();
+
+ /* Insert frames if required to get out_pts_seconds up to pts_seconds */
+ if (delta > one_frame) {
+ int const extra = rint (delta / one_frame);
+ for (int i = 0; i < extra; ++i) {
+ repeat_last_video ();
+ _film->log()->log (
+ String::compose (
+ "Extra video frame inserted at %1s; source frame %2, source PTS %3 (at %4 fps)",
+ out_pts_seconds, video_frame(), source_pts_seconds, frames_per_second()
+ )
+ );
+ }
+ }
+
+ if (delta > -one_frame) {
+ /* Process this frame */
+ filter_and_emit_video (_frame);
+ } else {
+ /* Otherwise we are omitting a frame to keep things right */
+ _film->log()->log (String::compose ("Frame removed at %1s", out_pts_seconds));
+ }
+}
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index de0a6a67c..89e42f978 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -97,7 +97,7 @@ public:
void set_audio_stream (boost::shared_ptr<AudioStream>);
void set_subtitle_stream (boost::shared_ptr<SubtitleStream>);
- void seek (SourceFrame);
+ bool seek (SourceFrame);
private:
@@ -106,6 +106,7 @@ private:
AVSampleFormat audio_sample_format () const;
int bytes_per_audio_sample () const;
+ void out_careful ();
void filter_and_emit_video (AVFrame *);
void setup_general ();
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 72828ed46..748e9ae4b 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -125,7 +125,7 @@ Image::scale_and_convert_to_rgb (Size out_size, int padding, Scaler const * scal
Size content_size = out_size;
content_size.width -= (padding * 2);
- shared_ptr<Image> rgb (new AlignedImage (PIX_FMT_RGB24, content_size));
+ shared_ptr<Image> rgb (new CompactImage (PIX_FMT_RGB24, content_size));
struct SwsContext* scale_context = sws_getContext (
size().width, size().height, pixel_format(),
diff --git a/src/lib/options.h b/src/lib/options.h
index 29b3b71cd..65c7b9ebc 100644
--- a/src/lib/options.h
+++ b/src/lib/options.h
@@ -43,6 +43,7 @@ public:
, decode_video_skip (0)
, decode_audio (true)
, decode_subtitles (false)
+ , decoder_alignment (true)
, _frame_out_path (f)
, _frame_out_extension (e)
, _multichannel_audio_out_path (m)
@@ -110,6 +111,8 @@ public:
bool decode_audio; ///< true to decode audio, otherwise false
bool decode_subtitles;
+ bool decoder_alignment;
+
private:
/** Path of the directory to write video frames to */
std::string _frame_out_path;