---
libavformat/output-example.c | 43 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/libavformat/output-example.c b/libavformat/output-example.c
index 27db78c..1a0a6db 100644
--- a/libavformat/output-example.c
+++ b/libavformat/output-example.c
@@ -416,6 +416,44 @@ static void close_video(AVFormatContext *oc, AVStream *st)
av_free(video_outbuf);
}
+static AVStream *add_data_stream(AVFormatContext *oc, enum CodecID codec_id)
+{
+ AVCodecContext *c;
+ AVStream *st;
+
+ st = av_new_stream(oc, 0);
+ if (!st) {
+ fprintf(stderr, "Could not alloc stream\n");
+ exit(1);
+ }
+
+ c = st->codec;
+ c->codec_id = codec_id;
+ c->codec_type = AVMEDIA_TYPE_DATA;
+
+ c->time_base.den = STREAM_FRAME_RATE;
+ c->time_base.num = 1;
+
+ // some formats want stream headers to be separate
+ if(oc->oformat->flags & AVFMT_GLOBALHEADER)
+ c->flags |= CODEC_FLAG_GLOBAL_HEADER;
+
+ return st;
+}
+
+static void write_data_frame(AVFormatContext *oc, AVStream *st, char *text)
+{
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.flags |= AV_PKT_FLAG_KEY;
+ pkt.stream_index= st->index;
+ pkt.data = text;
+ pkt.size= strlen(text);
+
+ av_interleaved_write_frame(oc, &pkt);
+}
+
+
/**************************************************************/
/* media file output */
@@ -424,7 +462,7 @@ int main(int argc, char **argv)
const char *filename;
AVOutputFormat *fmt;
AVFormatContext *oc;
- AVStream *audio_st, *video_st;
+ AVStream *audio_st, *video_st, *data_st;
double audio_pts, video_pts;
int i;
@@ -474,6 +512,8 @@ int main(int argc, char **argv)
audio_st = add_audio_stream(oc, fmt->audio_codec);
}
+ data_st = add_data_stream(oc, CODEC_ID_TEXT);
+
/* set the output parameters (must be done even if no
parameters). */
if (av_set_parameters(oc, NULL) < 0) {
@@ -522,6 +562,7 @@ int main(int argc, char **argv)
write_audio_frame(oc, audio_st);
} else {
write_video_frame(oc, video_st);
+ write_data_frame(oc, data_st, "Test");
}
}
--
1.7.4.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel