summaryrefslogtreecommitdiff
path: root/libavformat/flvenc.c
diff options
context:
space:
mode:
authorSteven Liu <lq@chinaffmpeg.org>2016-10-12 18:11:41 +0800
committerMichael Niedermayer <michael@niedermayer.cc>2016-10-20 18:07:24 +0200
commit5702416c57afb2bb062eb69d60fc42c31c91b674 (patch)
treeff45a82e05c2e0ad7f793d24a77d00237afb253c /libavformat/flvenc.c
parentc0e2846dcdc1a29de1c78886f5b7a05a252779e4 (diff)
downloadffmpeg-5702416c57afb2bb062eb69d60fc42c31c91b674.tar.gz
avformat/flvenc: do not attempt to write duration and filesize when not seekable
Its impossible to update the filesize & duration values if seekback is not possible as with live streams Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat/flvenc.c')
-rw-r--r--libavformat/flvenc.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 99903f5525..e50f8e4519 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -234,16 +234,18 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
metadata_count_pos = avio_tell(pb);
metadata_count = 4 * !!flv->video_par +
5 * !!flv->audio_par +
- 1 * !!flv->data_par +
- 2; // +2 for duration and file size
-
+ 1 * !!flv->data_par;
+ if (pb->seekable) {
+ metadata_count += 2; // +2 for duration and file size
+ }
avio_wb32(pb, metadata_count);
- put_amf_string(pb, "duration");
- flv->duration_offset = avio_tell(pb);
-
- // fill in the guessed duration, it'll be corrected later if incorrect
- put_amf_double(pb, s->duration / AV_TIME_BASE);
+ if (pb->seekable) {
+ put_amf_string(pb, "duration");
+ flv->duration_offset = avio_tell(pb);
+ // fill in the guessed duration, it'll be corrected later if incorrect
+ put_amf_double(pb, s->duration / AV_TIME_BASE);
+ }
if (flv->video_par) {
put_amf_string(pb, "width");
@@ -319,9 +321,11 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
metadata_count++;
}
- put_amf_string(pb, "filesize");
- flv->filesize_offset = avio_tell(pb);
- put_amf_double(pb, 0); // delayed write
+ if (pb->seekable) {
+ put_amf_string(pb, "filesize");
+ flv->filesize_offset = avio_tell(pb);
+ put_amf_double(pb, 0); // delayed write
+ }
put_amf_string(pb, "");
avio_w8(pb, AMF_END_OF_OBJECT);
@@ -543,16 +547,19 @@ static int flv_write_trailer(AVFormatContext *s)
file_size = avio_tell(pb);
- /* update information */
- if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0)
- av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n");
- else
- put_amf_double(pb, flv->duration / (double)1000);
- if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0)
- av_log(s, AV_LOG_WARNING, "Failed to update header with correct filesize.\n");
- else
- put_amf_double(pb, file_size);
-
+ if (pb->seekable) {
+ /* update information */
+ if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0) {
+ av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n");
+ } else {
+ put_amf_double(pb, flv->duration / (double)1000);
+ }
+ if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0) {
+ av_log(s, AV_LOG_WARNING, "Failed to update header with correct filesize.\n");
+ } else {
+ put_amf_double(pb, file_size);
+ }
+ }
avio_seek(pb, file_size, SEEK_SET);
return 0;
}