Commit be448564 authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/avienc: factor frame skip code out

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 33bc81e4
...@@ -70,6 +70,8 @@ typedef struct { ...@@ -70,6 +70,8 @@ typedef struct {
AVIIndex indexes; AVIIndex indexes;
} AVIStream; } AVIStream;
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt);
static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id) static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id)
{ {
int cl = ent_id / AVI_INDEX_CLUSTER_SIZE; int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
...@@ -565,6 +567,32 @@ static int avi_write_idx1(AVFormatContext *s) ...@@ -565,6 +567,32 @@ static int avi_write_idx1(AVFormatContext *s)
return 0; return 0;
} }
static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
{
AVIStream *avist = s->streams[stream_index]->priv_data;
AVCodecContext *enc = s->streams[stream_index]->codec;
av_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index);
while (enc->block_align == 0 && dts != AV_NOPTS_VALUE &&
dts > avist->packet_count && enc->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);
return AVERROR(EINVAL);
}
av_init_packet(&empty_packet);
empty_packet.size = 0;
empty_packet.data = NULL;
empty_packet.stream_index = stream_index;
avi_write_packet(s, &empty_packet);
av_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(dts), avist->packet_count);
}
return 0;
}
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
{ {
unsigned char tag[5]; unsigned char tag[5];
...@@ -575,29 +603,17 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -575,29 +603,17 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
AVIStream *avist = s->streams[stream_index]->priv_data; AVIStream *avist = s->streams[stream_index]->priv_data;
AVCodecContext *enc = s->streams[stream_index]->codec; AVCodecContext *enc = s->streams[stream_index]->codec;
int ret;
if (enc->codec_id == AV_CODEC_ID_H264 && enc->codec_tag == MKTAG('H','2','6','4') && pkt->size) { if (enc->codec_id == AV_CODEC_ID_H264 && enc->codec_tag == MKTAG('H','2','6','4') && pkt->size) {
int ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt); ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
av_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(pkt->dts), avist->packet_count, stream_index);
while (enc->block_align == 0 && pkt->dts != AV_NOPTS_VALUE &&
pkt->dts > avist->packet_count && enc->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
AVPacket empty_packet;
if (pkt->dts - avist->packet_count > 60000) { if ((ret = write_skip_frames(s, stream_index, pkt->dts)) < 0)
av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", pkt->dts - avist->packet_count); return ret;
return AVERROR(EINVAL);
}
av_init_packet(&empty_packet);
empty_packet.size = 0;
empty_packet.data = NULL;
empty_packet.stream_index = stream_index;
avi_write_packet(s, &empty_packet);
av_dlog(s, "dup dts:%s packet_count:%d\n", av_ts2str(pkt->dts), avist->packet_count);
}
avist->packet_count++; avist->packet_count++;
// Make sure to put an OpenDML chunk when the file size exceeds the limits // Make sure to put an OpenDML chunk when the file size exceeds the limits
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment