From: Gyan Doshi <ffmpeg@gyani.pro>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v2 1/2] avformat/flvenc: add option meta_period
Date: Thu, 2 Feb 2023 21:37:07 +0530
Message-ID: <20230202160708.29461-1-ffmpeg@gyani.pro> (raw)
Allows to re-emit global metadata. Useful for dynamic metadata.
Accepts values:
at_start or 0, for insertion only at start
at_keyframes or 1, for insertion at each video keyframe
every_packet or 2, for insertion with all video packets
---
doc/muxers.texi | 20 ++++++++++++++++++++
libavformat/flvenc.c | 22 +++++++++++++++++++---
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index ed5341be39..02ecddf186 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -535,6 +535,26 @@ at the end of stream. (Be used to non-seekable living stream).
@item add_keyframe_index
Used to facilitate seeking; particularly for HTTP pseudo streaming.
@end table
+
+@item meta_period
+Set interval at which to re-emit metadata.
+
+Possible values:
+
+@table @samp
+
+@item at_start
+Only once, in the header at the start. (@var{default})
+
+@item at_keyframes
+With each video keyframe.
+
+@item every_packet
+With every video packet.
+
+@end table
+Note that metadata will always be re-emitted if a metadata update event is signalled.
+
@end table
@anchor{framecrc}
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 128ae8ebc0..d1c7a493d1 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -71,6 +71,12 @@ typedef enum {
FLV_NO_DURATION_FILESIZE = (1 << 4),
} FLVFlags;
+typedef enum {
+ FLV_META_ONCE_AT_START = 0,
+ FLV_META_AT_KF,
+ FLV_META_EVERY_PACKET,
+} FLVMetaPeriod;
+
typedef struct FLVFileposition {
int64_t keyframe_position;
double keyframe_timestamp;
@@ -117,6 +123,7 @@ typedef struct FLVContext {
AVCodecParameters *data_par;
int flags;
+ int meta_period;
} FLVContext;
typedef struct FLVStreamContext {
@@ -822,7 +829,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
unsigned ts;
int size = pkt->size;
uint8_t *data = NULL;
- int flags = -1, flags_size, ret = 0;
+ int flags = -1, flags_size, ret = 0, meta_upd_flag;
int64_t cur_offset = avio_tell(pb);
if (par->codec_type == AVMEDIA_TYPE_AUDIO && !pkt->size) {
@@ -868,9 +875,14 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
ts = pkt->dts;
- if (s->event_flags & AVSTREAM_EVENT_FLAG_METADATA_UPDATED) {
+ meta_upd_flag = s->event_flags & AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
+
+ if (meta_upd_flag ||
+ (flv->meta_period == FLV_META_AT_KF && par->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY)) ||
+ (flv->meta_period == FLV_META_EVERY_PACKET && par->codec_type == AVMEDIA_TYPE_VIDEO )) {
write_metadata(s, ts);
- s->event_flags &= ~AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
+ if (meta_upd_flag)
+ s->event_flags &= ~AVSTREAM_EVENT_FLAG_METADATA_UPDATED;
}
avio_write_marker(pb, av_rescale(ts, AV_TIME_BASE, 1000),
@@ -1050,6 +1062,10 @@ static const AVOption options[] = {
{ "no_metadata", "disable metadata for FLV", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_NO_METADATA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
{ "no_duration_filesize", "disable duration and filesize zero value metadata for FLV", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_NO_DURATION_FILESIZE}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
{ "add_keyframe_index", "Add keyframe index metadata", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_ADD_KEYFRAME_INDEX}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
+ { "meta_period", "metadata insertion period", offsetof(FLVContext, meta_period), AV_OPT_TYPE_INT, {.i64 = FLV_META_ONCE_AT_START}, FLV_META_ONCE_AT_START, FLV_META_EVERY_PACKET, AV_OPT_FLAG_ENCODING_PARAM, "meta_period" },
+ { "at_start", "only once at start", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_META_ONCE_AT_START}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "meta_period" },
+ { "at_keyframes", "with every video keyframe", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_META_AT_KF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "meta_period" },
+ { "every_packet", "with every video packet", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_META_EVERY_PACKET}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "meta_period" },
{ NULL },
};
--
2.39.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-02-02 16:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 16:07 Gyan Doshi [this message]
2023-02-02 16:07 ` [FFmpeg-devel] [PATCH v2 2/2] avformat/flvenc: add option to read metadata from file Gyan Doshi
2023-02-03 15:34 ` Andreas Rheinhardt
2023-02-04 10:11 ` Gyan Doshi
2023-02-04 10:16 ` Paul B Mahol
2023-02-04 10:24 ` Gyan Doshi
2023-02-04 10:32 ` Paul B Mahol
2023-02-04 10:42 ` Gyan Doshi
2023-02-05 10:01 ` Gyan Doshi
2023-02-05 10:09 ` Paul B Mahol
2023-02-05 10:37 ` Anton Khirnov
2023-02-05 11:05 ` Gyan Doshi
2023-02-07 8:57 ` Gyan Doshi
2023-02-09 15:45 ` Anton Khirnov
2023-02-09 16:14 ` Gyan Doshi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230202160708.29461-1-ffmpeg@gyani.pro \
--to=ffmpeg@gyani.pro \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git