Skip to content

Instantly share code, notes, and snippets.

Created October 22, 2015 11:23
Show Gist options
  • Save anonymous/aa0333d87831f9e64364 to your computer and use it in GitHub Desktop.
Save anonymous/aa0333d87831f9e64364 to your computer and use it in GitHub Desktop.
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 992122c..0962472 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -685,6 +685,7 @@ static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
int pict_type;
memcpy(pkt->data, cx_frame->buf, pkt->size);
pkt->pts = pkt->dts = cx_frame->pts;
+ pkt->duration = cx_frame->duration;
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->pts = cx_frame->pts;
@@ -863,6 +864,7 @@ static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt,
struct vpx_image *rawimg = NULL;
struct vpx_image *rawimg_alpha = NULL;
int64_t timestamp = 0;
+ int64_t duration = avctx->ticks_per_frame;
int res, coded_size;
vpx_enc_frame_flags_t flags = 0;
@@ -896,10 +898,12 @@ static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt,
timestamp = frame->pts;
if (frame->pict_type == AV_PICTURE_TYPE_I)
flags |= VPX_EFLAG_FORCE_KF;
+ if (frame->pkt_duration > 0)
+ duration = frame->pkt_duration;
}
res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding frame");
return AVERROR_INVALIDDATA;
@@ -907,7 +911,7 @@ static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt,
if (ctx->is_alpha) {
res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding alpha frame");
return AVERROR_INVALIDDATA;
diff --git a/libavfilter/vf_mpdecimate.c b/libavfilter/vf_mpdecimate.c
index 25efacf..3a13d2c 100644
--- a/libavfilter/vf_mpdecimate.c
+++ b/libavfilter/vf_mpdecimate.c
@@ -196,17 +196,22 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *cur)
{
DecimateContext *decimate = inlink->dst->priv;
AVFilterLink *outlink = inlink->dst->outputs[0];
+ AVFrame *out;
int ret;
if (decimate->ref && decimate_frame(inlink->dst, cur, decimate->ref)) {
decimate->drop_count = FFMAX(1, decimate->drop_count+1);
} else {
- av_frame_free(&decimate->ref);
+ if (decimate->ref) {
+ out = av_frame_clone(decimate->ref);
+ out->pkt_duration = cur->pts - out->pts;
+ av_frame_free(&decimate->ref);
+
+ if ((ret = ff_filter_frame(outlink, out)) < 0)
+ return ret;
+ }
decimate->ref = cur;
decimate->drop_count = FFMIN(-1, decimate->drop_count-1);
-
- if ((ret = ff_filter_frame(outlink, av_frame_clone(cur))) < 0)
- return ret;
}
av_log(inlink->dst, AV_LOG_DEBUG,
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 1fb39fe..2e111e0 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1676,7 +1676,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
side_data_size -= 8;
}
- if ((side_data_size && additional_id == 1) || discard_padding) {
+ if (1 || (side_data_size && additional_id == 1) || discard_padding) {
block_group = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, 0);
blockid = MATROSKA_ID_BLOCK;
}
@@ -1701,7 +1701,9 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
put_ebml_sint(pb, MATROSKA_ID_DISCARDPADDING, discard_padding);
}
- if (side_data_size && additional_id == 1) {
+ put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, pkt->duration);
+
+ if (1 || (side_data_size && additional_id == 1)) {
block_additions = start_ebml_master(pb, MATROSKA_ID_BLOCKADDITIONS, 0);
block_more = start_ebml_master(pb, MATROSKA_ID_BLOCKMORE, 0);
put_ebml_uint(pb, MATROSKA_ID_BLOCKADDID, 1);
@@ -1711,7 +1713,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
end_ebml_master(pb, block_more);
end_ebml_master(pb, block_additions);
}
- if ((side_data_size && additional_id == 1) || discard_padding) {
+ if (1 || (side_data_size && additional_id == 1) || discard_padding) {
end_ebml_master(pb, block_group);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment