Browse code

avformat/flvenc: fix ticket 5976 and use old commit

mythtv have problem with non-seekable dont write duration and filesize
and there have problem with some other server and player with 0 value
duation and filesize.
So add a flv flags to fix the ticket and make a choose for users.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>

Steven Liu authored on 2016/11/26 09:52:19
Showing 2 changed files
... ...
@@ -151,6 +151,10 @@ Disable sequence end tag.
151 151
 @item no_metadata
152 152
 Disable metadata tag.
153 153
 
154
+@item no_duration_filesize
155
+Disable duration and filesize in metadata when they are equal to zero
156
+at the end of stream. (Be used to non-seekable living stream).
157
+
154 158
 @item add_keyframe_index
155 159
 Used to facilitate seeking; particularly for HTTP pseudo streaming.
156 160
 @end table
... ...
@@ -68,6 +68,7 @@ typedef enum {
68 68
     FLV_NO_SEQUENCE_END = (1 << 1),
69 69
     FLV_ADD_KEYFRAME_INDEX = (1 << 2),
70 70
     FLV_NO_METADATA = (1 << 3),
71
+    FLV_NO_DURATION_FILESIZE = (1 << 4),
71 72
 } FLVFlags;
72 73
 
73 74
 typedef struct FLVFileposition {
... ...
@@ -269,6 +270,7 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
269 269
 {
270 270
     AVIOContext *pb = s->pb;
271 271
     FLVContext *flv = s->priv_data;
272
+    int write_duration_filesize = !(flv->flags & FLV_NO_DURATION_FILESIZE);
272 273
     int metadata_count = 0;
273 274
     int64_t metadata_count_pos;
274 275
     AVDictionaryEntry *tag = NULL;
... ...
@@ -292,12 +294,12 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
292 292
     metadata_count = 4 * !!flv->video_par +
293 293
                      5 * !!flv->audio_par +
294 294
                      1 * !!flv->data_par;
295
-    if (pb->seekable) {
295
+    if (write_duration_filesize) {
296 296
         metadata_count += 2; // +2 for duration and file size
297 297
     }
298 298
     avio_wb32(pb, metadata_count);
299 299
 
300
-    if (pb->seekable) {
300
+    if (write_duration_filesize) {
301 301
         put_amf_string(pb, "duration");
302 302
         flv->duration_offset = avio_tell(pb);
303 303
         // fill in the guessed duration, it'll be corrected later if incorrect
... ...
@@ -378,7 +380,7 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
378 378
         metadata_count++;
379 379
     }
380 380
 
381
-    if (pb->seekable) {
381
+    if (write_duration_filesize) {
382 382
         put_amf_string(pb, "filesize");
383 383
         flv->filesize_offset = avio_tell(pb);
384 384
         put_amf_double(pb, 0); // delayed write
... ...
@@ -844,7 +846,7 @@ end:
844 844
         avio_seek(pb, flv->datasize_offset, SEEK_SET);
845 845
         put_amf_double(pb, flv->datasize);
846 846
     }
847
-    if (pb->seekable) {
847
+    if (!(flv->flags & FLV_NO_DURATION_FILESIZE)) {
848 848
         /* update information */
849 849
         if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0) {
850 850
             av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n");
... ...
@@ -1061,6 +1063,7 @@ static const AVOption options[] = {
1061 1061
     { "aac_seq_header_detect", "Put AAC sequence header based on stream data", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_AAC_SEQ_HEADER_DETECT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
1062 1062
     { "no_sequence_end", "disable sequence end for FLV", 0, AV_OPT_TYPE_CONST, {.i64 = FLV_NO_SEQUENCE_END}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "flvflags" },
1063 1063
     { "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" },
1064
+    { "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" },
1064 1065
     { "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" },
1065 1066
     { NULL },
1066 1067
 };