diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-12-16 16:26:37 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-12-16 16:26:37 +0000 |
| commit | aabc7a911b874d8e5e0929c7c031d06029fe96b5 (patch) | |
| tree | 2b32b7908e251699e52829022caa44c5b4419467 /src/lib | |
| parent | 1fe3f08c50ba230c2eb2506d51287878679bdcb7 (diff) | |
Various hacks to subtitles etc.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 16 | ||||
| -rw-r--r-- | src/lib/image.cc | 33 | ||||
| -rw-r--r-- | src/lib/image.h | 20 | ||||
| -rw-r--r-- | src/lib/video_decoder.cc | 2 |
4 files changed, 61 insertions, 10 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 136843190..52848d3fc 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -79,6 +79,10 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<Film> f, shared_ptr<const DecodeOptions setup_subtitle (); _film_connection = f->Changed.connect (bind (&FFmpegDecoder::film_changed, this, _1)); + + if (!o->video_sync) { + _first_video = 0; + } } FFmpegDecoder::~FFmpegDecoder () @@ -254,7 +258,7 @@ FFmpegDecoder::pass () avcodec_get_frame_defaults (_frame); shared_ptr<FFmpegAudioStream> ffa = dynamic_pointer_cast<FFmpegAudioStream> (_audio_stream); - + if (_packet.stream_index == _video_stream) { int frame_finished; @@ -516,6 +520,7 @@ FFmpegDecoder::set_subtitle_stream (shared_ptr<SubtitleStream> s) { VideoDecoder::set_subtitle_stream (s); setup_subtitle (); + OutputChanged (); } void @@ -551,9 +556,14 @@ FFmpegDecoder::filter_and_emit_video (AVFrame* frame) 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()); - int const r = av_seek_frame (_format_context, _video_stream, t, 0); + int64_t const vt = static_cast<int64_t>(f) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second()); + int const r = av_seek_frame (_format_context, _video_stream, vt, 0); + avcodec_flush_buffers (_video_codec_context); + if (_subtitle_codec_context) { + avcodec_flush_buffers (_subtitle_codec_context); + } + return r < 0; } diff --git a/src/lib/image.cc b/src/lib/image.cc index 748e9ae4b..2e4c18323 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -228,7 +228,7 @@ Image::make_black () } void -Image::alpha_blend (shared_ptr<Image> other, Position position) +Image::alpha_blend (shared_ptr<const Image> other, Position position) { /* Only implemented for RGBA onto RGB24 so far */ assert (_pixel_format == PIX_FMT_RGB24 && other->pixel_format() == PIX_FMT_RGBA); @@ -376,7 +376,7 @@ AlignedImage::AlignedImage (AVPixelFormat f, Size s) } -AlignedImage::AlignedImage (shared_ptr<Image> im) +AlignedImage::AlignedImage (shared_ptr<const Image> im) : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 32)) { assert (components() == im->components()); @@ -402,7 +402,7 @@ CompactImage::CompactImage (AVPixelFormat f, Size s) } -CompactImage::CompactImage (shared_ptr<Image> im) +CompactImage::CompactImage (shared_ptr<const Image> im) : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 1)) { assert (components() == im->components()); @@ -459,3 +459,30 @@ FilterBufferImage::size () const return Size (_buffer->video->w, _buffer->video->h); } +RGBPlusAlphaImage::RGBPlusAlphaImage (shared_ptr<const Image> im) + : SimpleImage (im->pixel_format(), im->size(), boost::bind (stride_round_up, _1, _2, 1)) +{ + assert (im->pixel_format() == PIX_FMT_RGBA); + + _alpha = (uint8_t *) av_malloc (im->size().width * im->size().height); + + uint8_t* in = im->data()[0]; + uint8_t* out = data()[0]; + uint8_t* out_alpha = _alpha; + for (int y = 0; y < im->size().height; ++y) { + uint8_t* in_r = in; + for (int x = 0; x < im->size().width; ++x) { + *out++ = *in_r++; + *out++ = *in_r++; + *out++ = *in_r++; + *out_alpha++ = *in_r++; + } + + in += im->stride()[0]; + } +} + +RGBPlusAlphaImage::~RGBPlusAlphaImage () +{ + av_free (_alpha); +} diff --git a/src/lib/image.h b/src/lib/image.h index 7c118f338..0cd38da11 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -72,7 +72,7 @@ public: boost::shared_ptr<Image> scale_and_convert_to_rgb (Size, int, Scaler const *) const; boost::shared_ptr<Image> scale (Size, Scaler const *) const; boost::shared_ptr<Image> post_process (std::string) const; - void alpha_blend (boost::shared_ptr<Image> image, Position pos); + void alpha_blend (boost::shared_ptr<const Image> image, Position pos); void make_black (); @@ -134,7 +134,7 @@ class AlignedImage : public SimpleImage { public: AlignedImage (AVPixelFormat, Size); - AlignedImage (boost::shared_ptr<Image>); + AlignedImage (boost::shared_ptr<const Image>); }; /** @class CompactImage @@ -144,7 +144,21 @@ class CompactImage : public SimpleImage { public: CompactImage (AVPixelFormat, Size); - CompactImage (boost::shared_ptr<Image>); + CompactImage (boost::shared_ptr<const Image>); +}; + +class RGBPlusAlphaImage : public SimpleImage +{ +public: + RGBPlusAlphaImage (boost::shared_ptr<const Image>); + ~RGBPlusAlphaImage (); + + uint8_t* alpha () const { + return _alpha; + } + +private: + uint8_t* _alpha; }; #endif diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc index d3b441fbf..cb55b4d18 100644 --- a/src/lib/video_decoder.cc +++ b/src/lib/video_decoder.cc @@ -44,7 +44,7 @@ void VideoDecoder::emit_video (shared_ptr<Image> image, SourceFrame f) { shared_ptr<Subtitle> sub; - if (_timed_subtitle && _timed_subtitle->displayed_at (double (video_frame()) / _film->frames_per_second())) { + if (_timed_subtitle && _timed_subtitle->displayed_at (f / _film->frames_per_second())) { sub = _timed_subtitle->subtitle (); } |
