]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flvenc.c
oggenc: return error value from ogg_build_flac_headers()
[ffmpeg] / libavformat / flvenc.c
index b65c1b19a767aed82831112818f6b548fbc67e05..3ca1874cf1e122972ae2fd84a02742156a2754c2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * FLV muxer
- * Copyright (c) 2003 The FFmpeg Project.
+ * Copyright (c) 2003 The FFmpeg Project
  *
  * This file is part of FFmpeg.
  *
@@ -200,7 +200,7 @@ static int flv_write_header(AVFormatContext *s)
 
     /* mixed array (hash) with size and string/type/data tuples */
     put_byte(pb, AMF_DATA_TYPE_MIXEDARRAY);
-    put_be32(pb, 5*!!video_enc + 4*!!audio_enc + 2); // +2 for duration and file size
+    put_be32(pb, 5*!!video_enc + 5*!!audio_enc + 2); // +2 for duration and file size
 
     put_amf_string(pb, "duration");
     flv->duration_offset= url_ftell(pb);
@@ -214,7 +214,7 @@ static int flv_write_header(AVFormatContext *s)
         put_amf_double(pb, video_enc->height);
 
         put_amf_string(pb, "videodatarate");
-        put_amf_double(pb, s->bit_rate / 1024.0);
+        put_amf_double(pb, video_enc->bit_rate / 1024.0);
 
         put_amf_string(pb, "framerate");
         put_amf_double(pb, framerate);
@@ -224,6 +224,9 @@ static int flv_write_header(AVFormatContext *s)
     }
 
     if(audio_enc){
+        put_amf_string(pb, "audiodatarate");
+        put_amf_double(pb, audio_enc->bit_rate / 1024.0);
+
         put_amf_string(pb, "audiosamplerate");
         put_amf_double(pb, audio_enc->sample_rate);
 
@@ -309,6 +312,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
     FLVContext *flv = s->priv_data;
     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);
@@ -341,6 +345,11 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (enc->codec_id == CODEC_ID_H264) {
+        /* check if extradata looks like mp4 formated */
+        if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
+            if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
+                return -1;
+        }
         if (!flv->delay && pkt->dts < 0)
             flv->delay = -pkt->dts;
     }
@@ -361,17 +370,16 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
         put_byte(pb,1); // AVC NALU
         put_be24(pb,pkt->pts - pkt->dts);
     }
-    if (enc->codec_id == CODEC_ID_H264 &&
-        /* check if extradata looks like mp4 formated */
-        enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
-        ff_avc_parse_nal_units(pb, pkt->data, pkt->size);
-    } else {
-        put_buffer(pb, pkt->data, size);
-    }
+
+    put_buffer(pb, data ? data : pkt->data, size);
+
     put_be32(pb,size+flags_size+11); // previous tag size
     flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
 
     put_flush_packet(pb);
+
+    av_free(data);
+
     return 0;
 }