Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2 1/2] avformat/flvenc: add option meta_period
@ 2023-02-02 16:07 Gyan Doshi
  2023-02-02 16:07 ` [FFmpeg-devel] [PATCH v2 2/2] avformat/flvenc: add option to read metadata from file Gyan Doshi
  0 siblings, 1 reply; 15+ messages in thread
From: Gyan Doshi @ 2023-02-02 16:07 UTC (permalink / raw)
  To: ffmpeg-devel

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".

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-02-09 16:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 16:07 [FFmpeg-devel] [PATCH v2 1/2] avformat/flvenc: add option meta_period Gyan Doshi
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

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