diff --git a/app/decoder/ffmpeg/ffmpegdecoder.cpp b/app/decoder/ffmpeg/ffmpegdecoder.cpp index 1d2ae3c15..36661a702 100644 --- a/app/decoder/ffmpeg/ffmpegdecoder.cpp +++ b/app/decoder/ffmpeg/ffmpegdecoder.cpp @@ -167,8 +167,12 @@ FramePtr FFmpegDecoder::Retrieve(const rational &timecode, const rational &lengt return nullptr; } - //avcodec_flush_buffers(codec_ctx_); - //av_seek_frame(fmt_ctx_, avstream_->index, 0, AVSEEK_FLAG_BACKWARD); + // Convert timecode to AVStream timebase + int64_t target_ts = qFloor(timecode.toDouble() * rational(avstream_->time_base).flipped().toDouble()); + + // Seek to it + avcodec_flush_buffers(codec_ctx_); + av_seek_frame(fmt_ctx_, avstream_->index, target_ts, AVSEEK_FLAG_BACKWARD); // Allocate and init a packet for reading encoded data AVPacket pkt; @@ -186,6 +190,8 @@ FramePtr FFmpegDecoder::Retrieve(const rational &timecode, const rational &lengt // FFmpeg frame retrieve loop while ((ret = avcodec_receive_frame(codec_ctx_, dec_frame)) == AVERROR(EAGAIN) && !eof) { + av_frame_unref(dec_frame); + // Find next packet in the correct stream index do { // Free buffer in packet if there is one @@ -219,7 +225,7 @@ FramePtr FFmpegDecoder::Retrieve(const rational &timecode, const rational &lengt } } -// qDebug() << dec_frame->pts << ","; + //qDebug() << dec_frame->pts << ","; // Handle any errors received during the frame retrieve process if (ret < 0) { diff --git a/app/node/block/clip/clip.cpp b/app/node/block/clip/clip.cpp index 84ee8052b..4944bd807 100644 --- a/app/node/block/clip/clip.cpp +++ b/app/node/block/clip/clip.cpp @@ -61,19 +61,15 @@ NodeInput *ClipBlock::texture_input() void ClipBlock::Process(const rational &time) { - qDebug() << "Clip received time" << time.numerator() << "/" << time.denominator(); - // Run default node processing Block::Process(time); - // We convert the time given (timeline time) to media time -// rational media_time = time - in() + media_in_; - rational media_time = time - in(); + // If the time retrieved is within this block, get texture information + if (time >= in() && time < out()) { + // We convert the time given (timeline time) to media time + rational media_time = time - in() + media_in_; - qDebug() << "In time" << in().numerator() << "/" << in().denominator(); - qDebug() << "Media In time" << media_in_.numerator() << "/" << media_in_.denominator(); - qDebug() << "Media sent time" << media_time.numerator() << "/" << media_time.denominator(); - - // Retrieve texture - texture_output()->set_value(texture_input_->get_value(media_time)); + // Retrieve texture + texture_output()->set_value(texture_input_->get_value(media_time)); + } }