[FFmpeg-user] av_interleaved_write_frame - Not able to handle non-interleaved data

Gajanan H grhegde09 at gmail.com
Fri Dec 18 16:54:18 CET 2015


Hi,

I am trying to run remuxing.c example for remuxing a TS file containing
h264, aac into FLV format. Initially I was getting an error due to ADTS
header in AAC. So I have added aac_adtstoasc filtering to audio stream. Now
I don't get that error any more.

The TS packets that are being fed are not properly interleaved. So I am
using 'av_interleaved_write_frame' function for muxing. Even then I am
getting the following error.

"[flv @ 0x7feab581d400] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 2464 >= 2379"

Here is the log snippet:

out: pts:2431 pts_time:2.431 dts:2398 dts_time:2.398 duration:33
> duration_time:0.033 stream_index:0
> in: pts:221793 pts_time:2.46437 dts:218790 dts_time:2.431 duration:3003
> duration_time:0.0333667 stream_index:0
> out: pts:2464 pts_time:2.464 dts:2431 dts_time:2.431 duration:33
> duration_time:0.033 stream_index:0
> in: pts:224796 pts_time:2.49773 dts:221793 dts_time:2.46437 duration:3003
> duration_time:0.0333667 stream_index:0
> out: pts:2498 pts_time:2.498 dts:2464 dts_time:2.464 duration:33
> duration_time:0.033 stream_index:0
> in: pts:214108 pts_time:2.37898 dts:214108 dts_time:2.37898 duration:2089
> duration_time:0.0232111 stream_index:1
> out: pts:2379 pts_time:2.379 dts:2379 dts_time:2.379 duration:23
> duration_time:0.023 stream_index:1
> [flv @ 0x7feab581d400] Application provided invalid, non monotonically
> increasing dts to muxer in stream 0: 2464 >= 2379
> in: pts:216198 pts_time:2.4022 dts:216198 dts_time:2.4022 duration:2089
> duration_time:0.0232111 stream_index:1
> out: pts:2402 pts_time:2.402 dts:2402 dts_time:2.402 duration:23
> duration_time:0.023 stream_index:1
> [flv @ 0x7feab581d400] Application provided invalid, non monotonically
> increasing dts to muxer in stream 0: 2464 >= 2402
> in: pts:218288 pts_time:2.42542 dts:218288 dts_time:2.42542 duration:2089
> duration_time:0.0232111 stream_index:1
> out: pts:2425 pts_time:2.425 dts:2425 dts_time:2.425 duration:23
> duration_time:0.023 stream_index:1
> [flv @ 0x7feab581d400] Application provided invalid, non monotonically
> increasing dts to muxer in stream 0: 2464 >= 2425
> in: pts:220378 pts_time:2.44864 dts:220378 dts_time:2.44864 duration:2089
> duration_time:0.0232111 stream_index:1
> out: pts:2449 pts_time:2.449 dts:2449 dts_time:2.449 duration:23
> duration_time:0.023 stream_index:1
> [flv @ 0x7feab581d400] Application provided invalid, non monotonically
> increasing dts to muxer in stream 0: 2464 >= 2449
> in: pts:222467 pts_time:2.47186 dts:222467 dts_time:2.47186 duration:2089
> duration_time:0.0232111 stream_index:1
> out: pts:2472 pts_time:2.472 dts:2472 dts_time:2.472 duration:23
> duration_time:0.023 stream_index:1
> in: pts:224557 pts_time:2.49508 dts:224557 dts_time:2.49508 duration:2089
> duration_time:0.0232111 stream_index:1




Here is my code snippet.

AVBitStreamFilterContext *bsfc = av_bitstream_filter_init("aac_adtstoasc");
  if (!bsfc) {
    printf("Error creating adtstoasc filter\n");
    goto end;
  }

  while (1) {
    AVStream *in_stream, *out_stream;

    ret = av_read_frame(ifmt_ctx, &pkt);
    if (ret < 0) break;

    in_stream = ifmt_ctx->streams[pkt.stream_index];
    out_stream = ofmt_ctx->streams[pkt.stream_index];

    log_packet(ifmt_ctx, &pkt, "in");

    /* copy packet */
    pkt.pts =
        av_rescale_q_rnd(pkt.pts, in_stream->time_base,
out_stream->time_base,
                         AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
    pkt.dts =
        av_rescale_q_rnd(pkt.dts, in_stream->time_base,
out_stream->time_base,
                         AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
    pkt.duration =
        av_rescale_q(pkt.duration, in_stream->time_base,
out_stream->time_base);
    pkt.pos = -1;
    log_packet(ofmt_ctx, &pkt, "out");

    if (out_stream->codec->codec_id == AV_CODEC_ID_AAC) {
      AVPacket newpacket = {0};
      int rc = av_bitstream_filter_filter(
          bsfc, out_stream->codec, NULL, &newpacket.data, &newpacket.size,
          pkt.data, pkt.size, pkt.flags & AV_PKT_FLAG_KEY);
      if (rc >= 0) {
        /*printf("Filter aac success\n");*/
        newpacket.pts = pkt.pts;
        newpacket.dts = pkt.dts;
        newpacket.duration = pkt.duration;
        newpacket.pos = -1;

        /*printf("calling av_interleaved_write_frame for audio:%d\n",
               pkt.stream_index);*/
        ret = av_write_frame(ofmt_ctx, &newpacket);
        /*printf("av_interleaved_write_frame success\n");*/
        av_free_packet(&newpacket);
      } else {
        printf("Error filtering aac packet\n");
        break;
      }
    } else {
      ret = av_interleaved_write_frame(ofmt_ctx, &pkt);
      if (ret < 0) {
        fprintf(stderr, "Error muxing packet\n");
        break;
      }
    }
    av_packet_unref(&pkt);
  }

  av_write_trailer(ofmt_ctx);

What am I doing wrong? Please help me.

Regards,
Gajanan


More information about the ffmpeg-user mailing list