class DCPVideoFrame
{
public:
- DCPVideoFrame (boost::shared_ptr<Image>, boost::shared_ptr<Subtitle>, Size, int, int, float, Scaler const *, int, float, std::string, int, int, Log *);
+ DCPVideoFrame (boost::shared_ptr<const Image>, boost::shared_ptr<Subtitle>, Size, int, int, float, Scaler const *, int, float, std::string, int, int, Log *);
virtual ~DCPVideoFrame ();
boost::shared_ptr<EncodedData> encode_locally ();
void create_openjpeg_container ();
void write_encoded (boost::shared_ptr<const Options>, uint8_t *, int);
- boost::shared_ptr<Image> _input; ///< the input image
+ boost::shared_ptr<const Image> _input; ///< the input image
boost::shared_ptr<Subtitle> _subtitle; ///< any subtitle that should be on the image
Size _out_size; ///< the required size of the output, in pixels
int _padding;
, _video_stream (-1)
, _audio_stream (-1)
, _subtitle_stream (-1)
- , _last_video_frame (-1)
- , _this_video_frame (0)
- , _audio_frame (0)
+ , _frame (0)
, _video_codec_context (0)
, _video_codec (0)
, _audio_codec_context (0)
, _subtitle_codec_context (0)
, _subtitle_codec (0)
{
- for (int i = 0; i < 2; ++i) {
- _video_frame[i] = 0;
- }
-
setup_general ();
setup_video ();
setup_audio ();
avcodec_close (_subtitle_codec_context);
}
- for (int i = 0; i < 2; ++i) {
- av_free (_video_frame[i]);
- }
-
- av_free (_audio_frame);
+ av_free (_frame);
avformat_close_input (&_format_context);
}
throw DecodeError ("could not find video stream");
}
- for (int i = 0; i < 2; ++i) {
- _video_frame[i] = avcodec_alloc_frame ();
- if (_video_frame[i] == 0) {
- throw DecodeError ("could not allocate frame");
- }
- }
-
- _audio_frame = avcodec_alloc_frame ();
- if (_audio_frame == 0) {
+ _frame = avcodec_alloc_frame ();
+ if (_frame == 0) {
throw DecodeError ("could not allocate frame");
}
}
int frame_finished;
- while (avcodec_decode_video2 (_video_codec_context, _video_frame[_this_video_frame], &frame_finished, &_packet) >= 0 && frame_finished) {
- process_video (_video_frame[_this_video_frame]);
+ while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ process_video (_frame);
}
if (_audio_stream >= 0 && _opt->decode_audio) {
- while (avcodec_decode_audio4 (_audio_codec_context, _audio_frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ while (avcodec_decode_audio4 (_audio_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
int const data_size = av_samples_get_buffer_size (
- 0, _audio_codec_context->channels, _audio_frame->nb_samples, audio_sample_format (), 1
+ 0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1
);
assert (_audio_codec_context->channels == _film->audio_channels());
- process_audio (_audio_frame->data[0], data_size);
+ process_audio (_frame->data[0], data_size);
}
}
double const pts_seconds = av_q2d (_format_context->streams[_packet.stream_index]->time_base) * _packet.pts;
+ avcodec_get_frame_defaults (_frame);
+
if (_packet.stream_index == _video_stream) {
- avcodec_get_frame_defaults (_video_frame[_this_video_frame]);
-
if (!_first_video) {
_first_video = pts_seconds;
}
int frame_finished;
- if (avcodec_decode_video2 (_video_codec_context, _video_frame[_this_video_frame], &frame_finished, &_packet) >= 0 && frame_finished) {
+ if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
/* Where we are in the output, in seconds */
double const out_pts_seconds = video_frame_index() / frames_per_second();
double const delta = pts_seconds - out_pts_seconds;
double const one_frame = 1 / frames_per_second();
- /* Insert the last frame if we have one, otherwise just use this one */
- int const insert_frame = _last_video_frame == -1 ? _this_video_frame : _last_video_frame;
-
/* 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) {
- _film->log()->log (String::compose ("Extra frame inserted at %1s", out_pts_seconds));
- process_video (_video_frame[insert_frame]);
+ repeat_last_video ();
+ _film->log()->log (
+ String::compose (
+ "Extra frame inserted at %1s; DCP frame %2, packet PTS %3",
+ out_pts_seconds, video_frame_index(), pts_seconds
+ )
+ );
}
}
if (delta > -one_frame) {
/* Process this frame */
- process_video (_video_frame[_this_video_frame]);
+ process_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));
}
-
- /* Swap over so that we use the alternate video frames next time */
- _this_video_frame = 1 - _this_video_frame;
- _last_video_frame = 1 - _this_video_frame;
}
} else if (_audio_stream >= 0 && _packet.stream_index == _audio_stream && _opt->decode_audio && _first_video && _first_video.get() <= pts_seconds) {
}
int frame_finished;
- if (avcodec_decode_audio4 (_audio_codec_context, _audio_frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ if (avcodec_decode_audio4 (_audio_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
int const data_size = av_samples_get_buffer_size (
- 0, _audio_codec_context->channels, _audio_frame->nb_samples, audio_sample_format (), 1
+ 0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1
);
assert (_audio_codec_context->channels == _film->audio_channels());
- process_audio (_audio_frame->data[0], data_size);
+ process_audio (_frame->data[0], data_size);
}
} else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _opt->decode_subtitles && _first_video) {