diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-11-19 19:30:49 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-11-19 20:18:03 +0100 |
commit | be44856483303d1af3cef1fc7a52db1fc0f49bd3 (patch) | |
tree | a0cf114add80bf3ed741959abe7139372b634654 /libavformat/avienc.c | |
parent | 33bc81e437419d3e99c67826afdd0f4cf7621c0a (diff) | |
download | ffmpeg-be44856483303d1af3cef1fc7a52db1fc0f49bd3.tar.gz |
avformat/avienc: factor frame skip code out
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/avienc.c')
-rw-r--r-- | libavformat/avienc.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/libavformat/avienc.c b/libavformat/avienc.c index e05e02281d..35f4d02d31 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -70,6 +70,8 @@ typedef struct { AVIIndex indexes; } AVIStream; +static int avi_write_packet(AVFormatContext *s, AVPacket *pkt); + static inline AVIIentry *avi_get_ientry(const AVIIndex *idx, int ent_id) { int cl = ent_id / AVI_INDEX_CLUSTER_SIZE; @@ -565,6 +567,32 @@ static int avi_write_idx1(AVFormatContext *s) 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) { unsigned char tag[5]; @@ -575,29 +603,17 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) AVIOContext *pb = s->pb; AVIStream *avist = s->streams[stream_index]->priv_data; 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) { - 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) 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) { - av_log(s, AV_LOG_ERROR, "Too large number of skipped frames %"PRId64" > 60000\n", pkt->dts - avist->packet_count); - return AVERROR(EINVAL); - } + if ((ret = write_skip_frames(s, stream_index, pkt->dts)) < 0) + return ret; - 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++; // Make sure to put an OpenDML chunk when the file size exceeds the limits |