[FFmpeg-trac] #7750(undetermined:new): Using -f segment to produce avi files produces 'corrupted' avi files.

FFmpeg trac at avcodec.org
Fri Feb 22 21:07:30 EET 2019


#7750: Using -f segment to produce avi files produces 'corrupted' avi files.
-------------------------------------+-------------------------------------
             Reporter:  mhkohne      |                    Owner:
                 Type:  defect       |                   Status:  new
             Priority:  normal       |                Component:
                                     |  undetermined
              Version:  unspecified  |               Resolution:
             Keywords:               |               Blocked By:
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------

Comment (by mhkohne):

 I have insufficient time to work through the proper 29 item patch
 submission checklist, so I present here the patch I'm using locally, in
 the hopes that it will help someone.
 Do with it anything you like.
 It fixes the problem for me by making the AVI skip frame handling work
 relative to the first DTS seen, rather than relative to zero. I don't
 actually know enough about ffmpeg to know whether that's the right
 approach in the general case.

 diff --git a/libavformat/avienc.c b/libavformat/avienc.c
 index ac0f04c..c204e5a 100644
 --- a/libavformat/avienc.c
 +++ b/libavformat/avienc.c
 @@ -84,6 +84,7 @@ typedef struct AVIStream {
      int sample_requested;

      int64_t last_dts;
 +    int64_t first_dts;

      AVIIndex indexes;

 @@ -278,6 +279,8 @@ static int avi_write_header(AVFormatContext *s)
          s->streams[n]->priv_data = av_mallocz(sizeof(AVIStream));
          if (!s->streams[n]->priv_data)
              return AVERROR(ENOMEM);
 +        AVIStream *avist = s->streams[n]->priv_data;
 +        avist->first_dts = AV_NOPTS_VALUE;
      }

      /* header list */
 @@ -736,14 +739,23 @@ static int write_skip_frames(AVFormatContext *s, int
 stream_index, int64_t dts)
  {
      AVIStream *avist    = s->streams[stream_index]->priv_data;
      AVCodecParameters *par = s->streams[stream_index]->codecpar;
 +    int64_t reldts = dts;// relative to first_dts
 +
 +    if ((dts != AV_NOPTS_VALUE) && (avist->first_dts == AV_NOPTS_VALUE))
 +        avist->first_dts = dts;
 +
 +    if (dts != AV_NOPTS_VALUE)
 +        reldts = dts - avist->first_dts;
 +

      ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n",
 av_ts2str(dts), avist->packet_count, stream_index);
      while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&
 -           dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB
 && avist->packet_count) {
 +           reldts > avist->packet_count &&
 +           par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
          AVPacket empty_packet;

 -        if (dts - avist->packet_count > 60000) {
 -            av_log(s, AV_LOG_ERROR, "Too large number of skipped frames
 %"PRId64" > 60000\n", dts - avist->packet_count);
 +        if (reldts - avist->packet_count > 60000) {
 +            av_log(s, AV_LOG_ERROR, "Too large number of skipped frames
 %"PRId64" > 60000\n", reldts - avist->packet_count);
              return AVERROR(EINVAL);
          }

--
Ticket URL: <https://trac.ffmpeg.org/ticket/7750#comment:1>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list