virtual int64_t audio_channel_layout () const = 0;
virtual bool has_subtitles () const = 0;
+ /** @return amount of extra unwanted audio at the start (or -ve for unwanted video) in milliseconds */
+ virtual int audio_to_discard () const {
+ return 0;
+ }
+
void process_begin ();
bool pass ();
void process_end ();
#include "decoder.h"
#include "imagemagick_encoder.h"
#include "transcoder.h"
+#include "log.h"
using namespace std;
using namespace boost;
_decoder = decoder_factory (fs, o, this, _log, true, true);
_decoder->go ();
- fs->set_length (last_video_frame ());
+
+ fs->set_length (_decoder->last_video_frame ());
+ fs->set_audio_delay (-_decoder->audio_to_discard ());
+
+ _log->log (String::compose ("Video length is %1 frames", _decoder->last_video_frame()));
+ _log->log (String::compose ("%1ms of audio to discard", _decoder->audio_to_discard()));
ascend ();
, _audio_codec (0)
, _subtitle_codec_context (0)
, _subtitle_codec (0)
+ , _first_video_pts (-1)
{
setup_general ();
setup_video ();
_packet.data = 0;
_packet.size = 0;
+ /* XXX: should we reset _packet.data and size after each *_decode_* call? */
+
int frame_finished;
while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
int frame_finished;
if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ if (_first_video_pts == -1) {
+ _first_video_pts = _packet.pts;
+ }
process_video (_frame);
}
return n.str ();
}
+
+int
+FFmpegDecoder::audio_to_discard () const
+{
+ AVStream* v = _format_context->streams[_video_stream];
+ AVStream* a = _format_context->streams[_audio_stream];
+
+ assert (v->time_base.num == a->time_base.num);
+ assert (v->time_base.den == a->time_base.den);
+
+ return rint (av_q2d (v->time_base) * 1000 * (_first_video_pts - _first_audio_pts));
+}
int64_t audio_channel_layout () const;
bool has_subtitles () const;
int bytes_per_audio_sample () const;
+ int audio_to_discard () const;
std::vector<AudioStream> audio_streams () const;
std::vector<SubtitleStream> subtitle_streams () const;
AVCodec* _subtitle_codec; ///< may be 0 if there is no subtitle
AVPacket _packet;
+
+ int64_t _first_video_pts;
+ int64_t _first_audio_pts;
};