Commit 148c9bdb authored by Allan Hsu's avatar Allan Hsu Committed by Benjamin Larsson

Patch for the FLV muxer to supply more complete metadata

in the onMetaData header. Patch by Allan Hsu <allan at counterpop dot net>.

Originally committed as revision 7382 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent e3113632
......@@ -20,10 +20,27 @@
*/
#include "avformat.h"
#include "flv.h"
#include "riff.h"
#undef NDEBUG
#include <assert.h>
static const CodecTag flv_video_codec_ids[] = {
{CODEC_ID_FLV1, FLV_CODECID_H263 },
{CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
{CODEC_ID_VP6F, FLV_CODECID_VP6 },
{CODEC_ID_NONE, 0}
};
static const CodecTag flv_audio_codec_ids[] = {
{CODEC_ID_MP3, FLV_CODECID_MP3 >> FLV_AUDIO_CODECID_OFFSET},
{CODEC_ID_PCM_S8, FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET},
{CODEC_ID_PCM_S16BE, FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET},
{CODEC_ID_PCM_S16LE, FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET},
{CODEC_ID_ADPCM_SWF, FLV_CODECID_ADPCM >> FLV_AUDIO_CODECID_OFFSET},
{CODEC_ID_NONE, 0}
};
typedef struct FLVContext {
int hasAudio;
int hasVideo;
......@@ -99,11 +116,16 @@ static void put_amf_double(ByteIOContext *pb, double d)
put_be64(pb, av_dbl2int(d));
}
static void put_amf_bool(ByteIOContext *pb, int b) {
put_byte(pb, AMF_DATA_TYPE_BOOL);
put_byte(pb, !!b);
}
static int flv_write_header(AVFormatContext *s)
{
ByteIOContext *pb = &s->pb;
FLVContext *flv = s->priv_data;
int i, width, height, samplerate;
int i, width, height, samplerate, samplesize, channels, audiocodecid, videocodecid;
double framerate = 0.0;
int metadata_size_pos, data_size;
......@@ -121,9 +143,20 @@ static int flv_write_header(AVFormatContext *s)
framerate = 1/av_q2d(s->streams[i]->codec->time_base);
}
flv->hasVideo=1;
videocodecid = codec_get_tag(flv_video_codec_ids, enc->codec_id);
if(videocodecid == 0) {
av_log(enc, AV_LOG_ERROR, "video codec not compatible with flv\n");
return -1;
}
} else {
flv->hasAudio=1;
samplerate = enc->sample_rate;
channels = enc->channels;
audiocodecid = codec_get_tag(flv_audio_codec_ids, enc->codec_id);
samplesize = (enc->codec_id == CODEC_ID_PCM_S8) ? 8 : 16;
if(get_audio_flags(enc)<0)
return -1;
}
......@@ -162,7 +195,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, 4*flv->hasVideo + flv->hasAudio + 2); // +2 for duration and file size
put_be32(pb, 5*flv->hasVideo + 4*flv->hasAudio + 2); // +2 for duration and file size
put_amf_string(pb, "duration");
flv->duration_offset= url_ftell(pb);
......@@ -180,11 +213,23 @@ static int flv_write_header(AVFormatContext *s)
put_amf_string(pb, "framerate");
put_amf_double(pb, framerate);
put_amf_string(pb, "videocodecid");
put_amf_double(pb, videocodecid);
}
if(flv->hasAudio){
put_amf_string(pb, "audiosamplerate");
put_amf_double(pb, samplerate);
put_amf_string(pb, "audiosamplesize");
put_amf_double(pb, samplesize);
put_amf_string(pb, "stereo");
put_amf_bool(pb, (channels == 2));
put_amf_string(pb, "audiocodecid");
put_amf_double(pb, audiocodecid);
}
put_amf_string(pb, "filesize");
......
......@@ -133,8 +133,8 @@ stddev: 20.00 PSNR:22.10 bytes:7602176
1454536 ./data/a-asv2.avi
0b310840a6d3970595983491687669df *./data/out.yuv
stddev: 18.82 PSNR:22.63 bytes:7602176
4478bd22d09ae383b5cff05100437727 *./data/a-flv.flv
649017 ./data/a-flv.flv
cbdb25fe5bb6a895baf9799b8ccb3038 *./data/a-flv.flv
649040 ./data/a-flv.flv
40281942d6ee254f7d3027b8593b19be *./data/out.yuv
stddev: 8.06 PSNR:29.99 bytes:7602176
f8f51fa737add17f7fecaefa118b57ed *./data/a-ffv1.avi
......
......@@ -133,8 +133,8 @@ stddev: 10.47 PSNR:27.72 bytes:7602176
789072 ./data/a-asv2.avi
74a78015b64b2cf8cb9da2e44f508a69 *./data/out.yuv
stddev: 10.28 PSNR:27.88 bytes:7602176
bd76377d9e167caff10ebaf381f01a82 *./data/a-flv.flv
131337 ./data/a-flv.flv
7163b470e93feb36b3f01e82168a3d31 *./data/a-flv.flv
131360 ./data/a-flv.flv
8999c8264fb0941561f64c4a736e9d88 *./data/out.yuv
stddev: 5.33 PSNR:33.58 bytes:7602176
d72b0960e162d4998b9acbabb07e99ab *./data/a-ffv1.avi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment