Guest User

Untitled

a guest
Sep 21st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.51 KB | None | 0 0
  1.     diff --git a/ffmpeg.c b/ffmpeg.c
  2. index b962d5e..bd7e488 100644
  3. --- a/ffmpeg.c
  4. +++ b/ffmpeg.c
  5. @@ -506,10 +506,8 @@ static void ffmpeg_cleanup(int ret)
  6.          if (!ost)
  7.              continue;
  8.  
  9. -        for (j = 0; j < ost->nb_bitstream_filters; j++)
  10. -            av_bsf_free(&ost->bsf_ctx[j]);
  11. +        av_bsf_free(&ost->bsf_ctx);
  12.          av_freep(&ost->bsf_ctx);
  13. -        av_freep(&ost->bitstream_filters);
  14.  
  15.          av_frame_free(&ost->filtered_frame);
  16.          av_frame_free(&ost->last_frame);
  17. @@ -675,6 +673,20 @@ static void write_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
  18.          }
  19.      }
  20.  
  21. +    if (ost->nb_bitstream_filters)
  22. +        if (!ost->bsf_extradata_updated) {
  23. +            if(ost->bsf_ctx->par_out->extradata_size) {
  24. +                av_freep(&ost->st->codecpar->extradata);
  25. +                ost->st->codecpar->extradata_size = 0;
  26. +                ost->st->codecpar->extradata = av_mallocz(ost->bsf_ctx->par_out->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
  27. +                if (!ost->st->codecpar->extradata)
  28. +                     exit_program(1);
  29. +                memcpy(ost->st->codecpar->extradata, ost->bsf_ctx->par_out->extradata, ost->bsf_ctx->par_out->extradata_size);
  30. +                ost->st->codecpar->extradata_size = ost->bsf_ctx->par_out->extradata_size;
  31. +            }
  32. +            ost->bsf_extradata_updated = 1;
  33. +        }
  34. +
  35.      if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
  36.          if (pkt->dts != AV_NOPTS_VALUE &&
  37.              pkt->pts != AV_NOPTS_VALUE &&
  38. @@ -755,29 +767,20 @@ static void output_packet(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
  39.      if (ost->nb_bitstream_filters) {
  40.          int idx;
  41.  
  42. -        ret = av_bsf_send_packet(ost->bsf_ctx[0], pkt);
  43. +        ret = av_bsf_send_packet(ost->bsf_ctx, pkt);
  44.          if (ret < 0)
  45.              goto finish;
  46.  
  47.          idx = 1;
  48. -        while (idx) {
  49. +        while (1) {
  50.              /* get a packet from the previous filter up the chain */
  51. -            ret = av_bsf_receive_packet(ost->bsf_ctx[idx - 1], pkt);
  52. +            ret = av_bsf_receive_packet(ost->bsf_ctx, pkt);
  53.              if (ret == AVERROR(EAGAIN)) {
  54.                  ret = 0;
  55. -                idx--;
  56. -                continue;
  57. +                break;
  58.              } else if (ret < 0)
  59. -                goto finish;
  60. -
  61. -            /* send it to the next filter down the chain or to the muxer */
  62. -            if (idx < ost->nb_bitstream_filters) {
  63. -                ret = av_bsf_send_packet(ost->bsf_ctx[idx], pkt);
  64. -                if (ret < 0)
  65. -                    goto finish;
  66. -                idx++;
  67. -            } else
  68. -                write_packet(s, pkt, ost);
  69. +                break;
  70. +            write_packet(s, pkt, ost);
  71.          }
  72.      } else
  73.          write_packet(s, pkt, ost);
  74. @@ -2617,34 +2620,20 @@ static int init_output_bsfs(OutputStream *ost)
  75.      if (!ost->nb_bitstream_filters)
  76.          return 0;
  77.  
  78. -    ost->bsf_ctx = av_mallocz_array(ost->nb_bitstream_filters, sizeof(*ost->bsf_ctx));
  79. -    if (!ost->bsf_ctx)
  80. -        return AVERROR(ENOMEM);
  81. -
  82. -    for (i = 0; i < ost->nb_bitstream_filters; i++) {
  83. -        ret = av_bsf_alloc(ost->bitstream_filters[i], &ctx);
  84. -        if (ret < 0) {
  85. -            av_log(NULL, AV_LOG_ERROR, "Error allocating a bistream filter context\n");
  86. -            return ret;
  87. -        }
  88. -        ost->bsf_ctx[i] = ctx;
  89. -
  90. -        ret = avcodec_parameters_copy(ctx->par_in,
  91. -                                      i ? ost->bsf_ctx[i - 1]->par_out : ost->st->codecpar);
  92. +        ret = avcodec_parameters_copy(ost->bsf_ctx->par_in,
  93. +                                      ost->st->codecpar);
  94.          if (ret < 0)
  95.              return ret;
  96.  
  97. -        ctx->time_base_in = i ? ost->bsf_ctx[i - 1]->time_base_out : ost->st->time_base;
  98. +        ost->bsf_ctx->time_base_in = ost->st->time_base;
  99.  
  100. -        ret = av_bsf_init(ctx);
  101. +        ret = av_bsf_init(ost->bsf_ctx);
  102.          if (ret < 0) {
  103. -            av_log(NULL, AV_LOG_ERROR, "Error initializing bistream filter: %s\n",
  104. -                   ost->bitstream_filters[i]->name);
  105. +            av_log(NULL, AV_LOG_ERROR, "Error initializing bistream filters");
  106.              return ret;
  107.          }
  108. -    }
  109.  
  110. -    ctx = ost->bsf_ctx[ost->nb_bitstream_filters - 1];
  111. +    ctx = ost->bsf_ctx;
  112.      ret = avcodec_parameters_copy(ost->st->codecpar, ctx->par_out);
  113.      if (ret < 0)
  114.          return ret;
  115. diff --git a/ffmpeg.h b/ffmpeg.h
  116. index 87cec30..c4f4325 100644
  117. --- a/ffmpeg.h
  118. +++ b/ffmpeg.h
  119. @@ -417,9 +417,9 @@ typedef struct OutputStream {
  120.      /* dts of the last packet sent to the muxer */
  121.      int64_t last_mux_dts;
  122.  
  123. +    int                   bsf_extradata_updated;
  124.      int                    nb_bitstream_filters;
  125. -    const AVBitStreamFilter **bitstream_filters;
  126. -    AVBSFContext            **bsf_ctx;
  127. +    AVBSFContext            *bsf_ctx;
  128.  
  129.      AVCodecContext *enc_ctx;
  130.      AVCodecParameters *ref_par; /* associated input codec parameters with encoders options applied */
  131. diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
  132. index c9cc6bc..ee9249b 100644
  133. --- a/ffmpeg_opt.c
  134. +++ b/ffmpeg_opt.c
  135. @@ -1320,31 +1320,13 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
  136.      MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
  137.  
  138.      MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
  139. -    while (bsfs && *bsfs) {
  140. -        const AVBitStreamFilter *filter;
  141. -        char *bsf;
  142. -
  143. -        bsf = av_get_token(&bsfs, ",");
  144. -        if (!bsf)
  145. -            exit_program(1);
  146. -
  147. -        filter = av_bsf_get_by_name(bsf);
  148. -        if (!filter) {
  149. -            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
  150. +    if (bsfs && *bsfs) {
  151. +        ost->bsf_ctx = av_mallocz(sizeof(*ost->bsf_ctx));
  152. +        if (av_bsf_list_parse_str(bsfs, &ost->bsf_ctx) < 0) {
  153. +            av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsfs);
  154.              exit_program(1);
  155.          }
  156. -        av_freep(&bsf);
  157. -
  158. -        ost->bitstream_filters = av_realloc_array(ost->bitstream_filters,
  159. -                                                  ost->nb_bitstream_filters + 1,
  160. -                                                  sizeof(*ost->bitstream_filters));
  161. -        if (!ost->bitstream_filters)
  162. -            exit_program(1);
  163. -
  164. -        ost->bitstream_filters[ost->nb_bitstream_filters++] = filter;
  165. -
  166. -        if (*bsfs)
  167. -            bsfs++;
  168. +        ost->nb_bitstream_filters = 1;
  169.      }
  170.  
  171.      MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
Add Comment
Please, Sign In to add comment