]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flvenc.c
rtpproto: Add an option for writing return packets to the address of the last receive...
[ffmpeg] / libavformat / flvenc.c
index 57e7aac23e022873206f3a01b51051ab0f86e29b..37f37773a06c8140a20c9d9e228ce9d81cb546cc 100644 (file)
@@ -208,6 +208,11 @@ static int flv_write_header(AVFormatContext *s)
             } else {
                 framerate = 1 / av_q2d(s->streams[i]->codec->time_base);
             }
+            if (video_enc) {
+                av_log(s, AV_LOG_ERROR,
+                       "at most one video stream is supported in flv\n");
+                return AVERROR(EINVAL);
+            }
             video_enc = enc;
             if (enc->codec_tag == 0) {
                 av_log(s, AV_LOG_ERROR, "video codec not compatible with flv\n");
@@ -215,6 +220,11 @@ static int flv_write_header(AVFormatContext *s)
             }
             break;
         case AVMEDIA_TYPE_AUDIO:
+            if (audio_enc) {
+                av_log(s, AV_LOG_ERROR,
+                       "at most one audio stream is supported in flv\n");
+                return AVERROR(EINVAL);
+            }
             audio_enc = enc;
             if (get_audio_flags(s, enc) < 0)
                 return AVERROR_INVALIDDATA;
@@ -403,10 +413,14 @@ static int flv_write_trailer(AVFormatContext *s)
     file_size = avio_tell(pb);
 
     /* update information */
-    avio_seek(pb, flv->duration_offset, SEEK_SET);
-    put_amf_double(pb, flv->duration / (double)1000);
-    avio_seek(pb, flv->filesize_offset, SEEK_SET);
-    put_amf_double(pb, file_size);
+    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;
@@ -421,10 +435,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
     unsigned ts;
     int size = pkt->size;
     uint8_t *data = NULL;
-    int flags, flags_size;
-
-    // av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n",
-    //        enc->codec_type, timestamp, size);
+    int flags = 0, flags_size;
 
     if (enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_VP6F ||
         enc->codec_id == AV_CODEC_ID_AAC)