mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-12 01:40:04 +01:00
avformat: Add and use helper function to add attachment streams
All instances of adding attached pictures to a stream or adding a stream and an attached packet to said stream have several things in common like setting the index and flags of the packet, setting the stream disposition etc. This commit therefore factors this out. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -474,6 +474,36 @@ int avformat_queue_attached_pictures(AVFormatContext *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
|
||||
AVBufferRef **buf, int size)
|
||||
{
|
||||
AVPacket *pkt;
|
||||
int ret;
|
||||
|
||||
if (!st && !(st = avformat_new_stream(s, NULL)))
|
||||
return AVERROR(ENOMEM);
|
||||
pkt = &st->attached_pic;
|
||||
if (buf) {
|
||||
av_assert1(*buf);
|
||||
av_packet_unref(pkt);
|
||||
pkt->buf = *buf;
|
||||
pkt->data = (*buf)->data;
|
||||
pkt->size = (*buf)->size - AV_INPUT_BUFFER_PADDING_SIZE;
|
||||
*buf = NULL;
|
||||
} else {
|
||||
ret = av_get_packet(pb, pkt, size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
|
||||
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||
|
||||
pkt->stream_index = st->index;
|
||||
pkt->flags |= AV_PKT_FLAG_KEY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int update_stream_avctx(AVFormatContext *s)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
Reference in New Issue
Block a user