Advertisement
Guest User

vf_duration.patch

a guest
Oct 22nd, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.25 KB | None | 0 0
  1. diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
  2. index 992122c..5903d5c 100644
  3. --- a/libavcodec/libvpxenc.c
  4. +++ b/libavcodec/libvpxenc.c
  5. @@ -898,8 +898,10 @@ static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt,
  6.              flags |= VPX_EFLAG_FORCE_KF;
  7.      }
  8.  
  9. +    av_log(avctx, AV_LOG_WARNING, "duration: (%d)\n", frame->pkt_duration);
  10.      res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
  11. -                           avctx->ticks_per_frame, flags, ctx->deadline);
  12. +                           frame->pkt_duration || avctx->ticks_per_frame,
  13. +                           flags, ctx->deadline);
  14.      if (res != VPX_CODEC_OK) {
  15.          log_encoder_error(avctx, "Error encoding frame");
  16.          return AVERROR_INVALIDDATA;
  17. diff --git a/libavfilter/Makefile b/libavfilter/Makefile
  18. index a095a10..95cc658 100644
  19. --- a/libavfilter/Makefile
  20. +++ b/libavfilter/Makefile
  21. @@ -131,6 +131,7 @@ OBJS-$(CONFIG_DRAWBOX_FILTER)                += vf_drawbox.o
  22.  OBJS-$(CONFIG_DRAWGRAPH_FILTER)              += f_drawgraph.o
  23.  OBJS-$(CONFIG_DRAWGRID_FILTER)               += vf_drawbox.o
  24.  OBJS-$(CONFIG_DRAWTEXT_FILTER)               += vf_drawtext.o
  25. +OBJS-$(CONFIG_DURATION_FILTER)               += vf_duration.o
  26.  OBJS-$(CONFIG_ELBG_FILTER)                   += vf_elbg.o
  27.  OBJS-$(CONFIG_EDGEDETECT_FILTER)             += vf_edgedetect.o
  28.  OBJS-$(CONFIG_EQ_FILTER)                     += vf_eq.o
  29. diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
  30. index 3ab9a48..91c8ad5 100644
  31. --- a/libavfilter/allfilters.c
  32. +++ b/libavfilter/allfilters.c
  33. @@ -153,6 +153,7 @@ void avfilter_register_all(void)
  34.      REGISTER_FILTER(DRAWGRAPH,      drawgraph,      vf);
  35.      REGISTER_FILTER(DRAWGRID,       drawgrid,       vf);
  36.      REGISTER_FILTER(DRAWTEXT,       drawtext,       vf);
  37. +    REGISTER_FILTER(DURATION,       duration,       vf);
  38.      REGISTER_FILTER(EDGEDETECT,     edgedetect,     vf);
  39.      REGISTER_FILTER(ELBG,           elbg,           vf);
  40.      REGISTER_FILTER(EQ,             eq,             vf);
  41. diff --git a/libavfilter/vf_duration.c b/libavfilter/vf_duration.c
  42. new file mode 100644
  43. index 0000000..bbc40b7
  44. --- /dev/null
  45. +++ b/libavfilter/vf_duration.c
  46. @@ -0,0 +1,105 @@
  47. +/*
  48. + * This file is part of FFmpeg.
  49. + *
  50. + * FFmpeg is free software; you can redistribute it and/or
  51. + * modify it under the terms of the GNU Lesser General Public
  52. + * License as published by the Free Software Foundation; either
  53. + * version 2.1 of the License, or (at your option) any later version.
  54. + *
  55. + * FFmpeg is distributed in the hope that it will be useful,
  56. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  57. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  58. + * Lesser General Public License for more details.
  59. + *
  60. + * You should have received a copy of the GNU Lesser General Public
  61. + * License along with FFmpeg; if not, write to the Free Software
  62. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  63. + */
  64. +
  65. +/**
  66. + * @file vf_duration filter, fill frame->pkt_duration field
  67. + */
  68. +
  69. +#include "libavutil/internal.h"
  70. +#include "avfilter.h"
  71. +#include "internal.h"
  72. +#include "video.h"
  73. +
  74. +typedef struct {
  75. +    const AVClass *class;
  76. +    AVFrame *prev;
  77. +} DurationContext;
  78. +
  79. +static const AVFilterPad avfilter_vf_duration_inputs[] = {
  80. +    {
  81. +        .name = "default",
  82. +        .type = AVMEDIA_TYPE_VIDEO,
  83. +    },
  84. +    { NULL }
  85. +};
  86. +
  87. +static const AVFilterPad avfilter_vf_duration_outputs[] = {
  88. +    {
  89. +        .name = "default",
  90. +        .type = AVMEDIA_TYPE_VIDEO,
  91. +    },
  92. +    { NULL }
  93. +};
  94. +
  95. +static av_cold void init(AVFilterContext *ctx)
  96. +{
  97. +    DurationContext *duration = ctx->priv;
  98. +    duration->prev = 0;
  99. +    //return ff_filter_frame(outlink, duration->prev);
  100. +    return 0;
  101. +};
  102. +
  103. +static av_cold void uninit(AVFilterContext *ctx)
  104. +{
  105. +    DurationContext *duration = ctx->priv;
  106. +    //return ff_filter_frame(outlink, duration->prev);
  107. +    return 0;
  108. +};
  109. +
  110. +static int filter_frame(AVFilterLink *inlink, AVFrame *in)
  111. +{
  112. +    DurationContext *duration = inlink->dst->priv;
  113. +    int ret;
  114. +
  115. +    if (duration->prev) {
  116. +        AVFilterLink *outlink = inlink->dst->outputs[0];
  117. +        AVFrame *out = ff_get_video_buffer(outlink, in->width, in->height);
  118. +        if (!out) {
  119. +            av_frame_free(&duration->prev);
  120. +            av_frame_free(&in);
  121. +            return AVERROR(ENOMEM);
  122. +        }
  123. +        av_frame_copy_props(out, duration->prev);
  124. +        av_frame_copy(out, duration->prev);
  125. +        out->pkt_duration = in->pts - out->pts;
  126. +        av_frame_free(&duration->prev);
  127. +        duration->prev = in;
  128. +        return ff_filter_frame(outlink, out);
  129. +    };
  130. +    duration->prev = in;
  131. +    return 0;
  132. +};
  133. +
  134. +static const AVFilterPad duration_inputs[] = {
  135. +    {
  136. +        .name         = "default",
  137. +        .type         = AVMEDIA_TYPE_VIDEO,
  138. +        .filter_frame = filter_frame,
  139. +    },
  140. +    { NULL }
  141. +};
  142. +
  143. +AVFilter ff_vf_duration = {
  144. +    .name        = "duration",
  145. +    .description = NULL_IF_CONFIG_SMALL("Fill frame display duraion field."),
  146. +    .init          = init,
  147. +    .uninit        = uninit,
  148. +    .priv_size   = sizeof(DurationContext),
  149. +    .inputs      = duration_inputs,
  150. +    .outputs     = avfilter_vf_duration_outputs,
  151. +};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement