#include "util.h"
#include "log.h"
#include "ffmpeg_decoder.h"
+#include "subtitle_decoder.h"
#include "ffmpeg_audio_stream.h"
#include "ffmpeg_subtitle_stream.h"
#include "video_filter_graph.h"
#include "audio_buffers.h"
#include "ffmpeg_content.h"
#include "raw_image_proxy.h"
+#include "video_decoder.h"
#include "film.h"
#include "md5_digester.h"
+#include "audio_decoder.h"
#include "compose.hpp"
#include <dcp/subtitle_string.h>
#include <sub/ssa_reader.h>
using std::min;
using std::pair;
using std::max;
+using std::map;
using boost::shared_ptr;
using boost::is_any_of;
using boost::split;
using dcp::Size;
FFmpegDecoder::FFmpegDecoder (shared_ptr<const FFmpegContent> c, shared_ptr<Log> log, bool fast)
- : VideoDecoder (c)
- , AudioDecoder (c, fast)
- , SubtitleDecoder (c)
- , FFmpeg (c)
+ : FFmpeg (c)
, _log (log)
- , _pts_offset (pts_offset (c->ffmpeg_audio_streams(), c->first_video(), c->video_frame_rate()))
{
+ if (c->video) {
+ video.reset (new VideoDecoder (this, c, log));
+ _pts_offset = pts_offset (c->ffmpeg_audio_streams(), c->first_video(), c->active_video_frame_rate());
+ } else {
+ _pts_offset = ContentTime ();
+ }
+
+ if (c->audio) {
+ audio.reset (new AudioDecoder (this, c->audio, fast, log));
+ }
+ if (c->subtitle) {
+ subtitle.reset (
+ new SubtitleDecoder (
+ this,
+ c->subtitle,
+ bind (&FFmpegDecoder::image_subtitles_during, this, _1, _2),
+ bind (&FFmpegDecoder::text_subtitles_during, this, _1, _2)
+ )
+ );
+ }
}
void
while (decode_video_packet ()) {}
decode_audio_packet ();
- AudioDecoder::flush ();
+ audio->flush ();
}
bool
int const si = _packet.stream_index;
shared_ptr<const FFmpegContent> fc = _ffmpeg_content;
- if (si == _video_stream && !_ignore_video && (accurate || reason != PASS_REASON_SUBTITLE)) {
+ if (_video_stream && si == _video_stream.get() && !video->ignore_video() && (accurate || reason != PASS_REASON_SUBTITLE)) {
decode_video_packet ();
} else if (fc->subtitle_stream() && fc->subtitle_stream()->uses_index (_format_context, si)) {
decode_subtitle_packet ();
decode_audio_packet ();
}
- av_free_packet (&_packet);
+ av_packet_unref (&_packet);
return false;
}
}
break;
+ case AV_SAMPLE_FMT_S32P:
+ {
+ int32_t** p = reinterpret_cast<int32_t **> (_frame->data);
+ for (int i = 0; i < stream->channels(); ++i) {
+ for (int j = 0; j < frames; ++j) {
+ audio->data(i)[j] = static_cast<float>(p[i][j]) / (1 << 31);
+ }
+ }
+ }
+ break;
+
case AV_SAMPLE_FMT_FLT:
{
float* p = reinterpret_cast<float*> (_frame->data[0]);
void
FFmpegDecoder::seek (ContentTime time, bool accurate)
{
- VideoDecoder::seek (time, accurate);
- AudioDecoder::seek (time, accurate);
- SubtitleDecoder::seek (time, accurate);
+ video->seek (time, accurate);
+ audio->seek (time, accurate);
+ subtitle->seek (time, accurate);
/* If we are doing an `accurate' seek, we need to use pre-roll, as
we don't really know what the seek will give us.
http://www.mjbshaw.com/2012/04/seeking-in-ffmpeg-know-your-timestamp.html
*/
+ DCPOMATIC_ASSERT (_video_stream);
+
ContentTime u = time - _pts_offset;
if (u < ContentTime ()) {
u = ContentTime ();
}
- av_seek_frame (_format_context, _video_stream, u.seconds() / av_q2d (_format_context->streams[_video_stream]->time_base), AVSEEK_FLAG_BACKWARD);
+ av_seek_frame (
+ _format_context,
+ _video_stream.get(),
+ u.seconds() / av_q2d (_format_context->streams[_video_stream.get()]->time_base),
+ AVSEEK_FLAG_BACKWARD
+ );
avcodec_flush_buffers (video_codec_context());
}
if (data->frames() > 0) {
- audio (*stream, data, ct);
+ audio->audio (*stream, data, ct);
}
}
bool
FFmpegDecoder::decode_video_packet ()
{
+ DCPOMATIC_ASSERT (_video_stream);
+
int frame_finished;
if (avcodec_decode_video2 (video_codec_context(), _frame, &frame_finished, &_packet) < 0 || !frame_finished) {
return false;
shared_ptr<Image> image = i->first;
if (i->second != AV_NOPTS_VALUE) {
- double const pts = i->second * av_q2d (_format_context->streams[_video_stream]->time_base) + _pts_offset.seconds ();
- video (
+ double const pts = i->second * av_q2d (_format_context->streams[_video_stream.get()]->time_base) + _pts_offset.seconds ();
+ video->video (
shared_ptr<ImageProxy> (new RawImageProxy (image)),
- llrint (pts * _ffmpeg_content->video_frame_rate ())
+ llrint (pts * _ffmpeg_content->active_video_frame_rate ())
);
} else {
LOG_WARNING_NC ("Dropping frame without PTS");
*/
shared_ptr<Image> image (new Image (AV_PIX_FMT_RGBA, dcp::Size (rect->w, rect->h), true));
+#ifdef DCPOMATIC_HAVE_AVSUBTITLERECT_PICT
/* Start of the first line in the subtitle */
uint8_t* sub_p = rect->pict.data[0];
/* sub_p looks up into a BGRA palette which is here
(i.e. first byte B, second G, third R, fourth A)
*/
uint32_t const * palette = (uint32_t *) rect->pict.data[1];
+#else
+ /* Start of the first line in the subtitle */
+ uint8_t* sub_p = rect->data[0];
+ /* sub_p looks up into a BGRA palette which is here
+ (i.e. first byte B, second G, third R, fourth A)
+ */
+ uint32_t const * palette = (uint32_t *) rect->data[1];
+#endif
+ /* And the stream has a map of those palette colours to colours
+ chosen by the user; created a `mapped' palette from those settings.
+ */
+ map<RGBA, RGBA> colour_map = ffmpeg_content()->subtitle_stream()->colours ();
+ vector<RGBA> mapped_palette (rect->nb_colors);
+ for (int i = 0; i < rect->nb_colors; ++i) {
+ RGBA c ((palette[i] & 0xff0000) >> 16, (palette[i] & 0xff00) >> 8, palette[i] & 0xff, (palette[i] & 0xff000000) >> 24);
+ map<RGBA, RGBA>::const_iterator j = colour_map.find (c);
+ if (j != colour_map.end ()) {
+ mapped_palette[i] = j->second;
+ } else {
+ /* This colour was not found in the FFmpegSubtitleStream's colour map; probably because
+ it is from a project that was created before this stuff was added. Just use the
+ colour straight from the original palette.
+ */
+ mapped_palette[i] = c;
+ }
+ }
+
/* Start of the output data */
uint32_t* out_p = (uint32_t *) image->data()[0];
uint8_t* sub_line_p = sub_p;
uint32_t* out_line_p = out_p;
for (int x = 0; x < rect->w; ++x) {
- uint32_t const p = palette[*sub_line_p++];
- *out_line_p++ = ((p & 0xff) << 16) | (p & 0xff00) | ((p & 0xff0000) >> 16) | (p & 0xff000000);
+ RGBA const p = mapped_palette[*sub_line_p++];
+ /* XXX: this seems to be wrong to me (isn't the output image RGBA?) but it looks right on screen */
+ *out_line_p++ = (p.a << 24) | (p.r << 16) | (p.g << 8) | p.b;
}
+#ifdef DCPOMATIC_HAVE_AVSUBTITLERECT_PICT
sub_p += rect->pict.linesize[0];
+#else
+ sub_p += rect->linesize[0];
+#endif
out_p += image->stride()[0] / sizeof (uint32_t);
}
- dcp::Size const vs = _ffmpeg_content->video_size ();
+ dcp::Size const vs = _ffmpeg_content->video->size ();
dcpomatic::Rect<double> const scaled_rect (
static_cast<double> (rect->x) / vs.width,
static_cast<double> (rect->y) / vs.height,
static_cast<double> (rect->h) / vs.height
);
- image_subtitle (period, image, scaled_rect);
+ subtitle->image_subtitle (period, image, scaled_rect);
}
void
dcp::SubtitleString (
boost::optional<string> (),
k.italic,
+ k.bold,
dcp::Colour (255, 255, 255),
/* 48pt is 1/22nd of the screen height */
48,
*/
1.015 - ((1 + highest - j.vertical_position.line.get()) * 1.5 / 22),
dcp::VALIGN_TOP,
+ dcp::DIRECTION_LTR,
k.text,
static_cast<dcp::Effect> (0),
dcp::Colour (255, 255, 255),
}
}
- text_subtitle (period, ss);
+ subtitle->text_subtitle (period, ss);
}