/*
* FLV muxer
- * Copyright (c) 2003 The FFmpeg Project.
+ * Copyright (c) 2003 The FFmpeg Project
*
* This file is part of FFmpeg.
*
typedef struct FLVContext {
int reserved;
- offset_t duration_offset;
- offset_t filesize_offset;
+ int64_t duration_offset;
+ int64_t filesize_offset;
int64_t duration;
int delay; ///< first dts delay for AVC
} FLVContext;
static int get_audio_flags(AVCodecContext *enc){
- int flags = (enc->bits_per_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
+ int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
if (enc->codec_id == CODEC_ID_AAC) // specs force these parameters
return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT;
break;
case CODEC_ID_NELLYMOSER:
- flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;
+ if (enc->sample_rate == 8000) {
+ flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
+ } else {
+ flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;
+ }
break;
case 0:
flags |= enc->codec_tag<<4;
/* 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);
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);
}
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);
for (i = 0; i < s->nb_streams; i++) {
AVCodecContext *enc = s->streams[i]->codec;
if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) {
- offset_t pos;
+ int64_t pos;
put_byte(pb, enc->codec_type == CODEC_TYPE_VIDEO ?
FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
put_be24(pb, 0); // size patched later
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);
put_byte(pb, FLV_TAG_TYPE_AUDIO);
}
- if (enc->codec_id == CODEC_ID_H264 &&
+ if (enc->codec_id == CODEC_ID_H264) {
/* check if extradata looks like mp4 formated */
- enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
- if (ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size) < 0)
- return -1;
- assert(pkt->size);
- size = pkt->size;
- /* cast needed to get negative value */
+ 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;
}
put_byte(pb,1); // AVC NALU
put_be24(pb,pkt->pts - pkt->dts);
}
- 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;
}
"video/x-flv",
"flv",
sizeof(FLVContext),
-#ifdef CONFIG_LIBMP3LAME
+#if CONFIG_LIBMP3LAME
CODEC_ID_MP3,
#else // CONFIG_LIBMP3LAME
CODEC_ID_ADPCM_SWF,
flv_write_packet,
flv_write_trailer,
.codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0},
- .flags= AVFMT_GLOBALHEADER,
+ .flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
};