Statistics
| Branch: | Revision:

ffmpeg / libavformat / flvenc.c @ c5e1e982

History | View | Annotate | Download (13.6 KB)

1 d4f5d74a Garrick Meeker
/*
2 7fbde343 Aurelien Jacobs
 * FLV muxer
3 406792e7 Diego Biurrun
 * Copyright (c) 2003 The FFmpeg Project
4 d4f5d74a Garrick Meeker
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 d4f5d74a Garrick Meeker
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 d4f5d74a Garrick Meeker
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 d4f5d74a Garrick Meeker
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 d4f5d74a Garrick Meeker
 */
21
#include "avformat.h"
22 6cac3a3b Allan Hsu
#include "flv.h"
23 148c9bdb Allan Hsu
#include "riff.h"
24 f23496b5 Baptiste Coudurier
#include "avc.h"
25 d4f5d74a Garrick Meeker
26 068f2a22 Michael Niedermayer
#undef NDEBUG
27
#include <assert.h>
28
29 7caf0cc6 Michael Niedermayer
static const AVCodecTag flv_video_codec_ids[] = {
30 148c9bdb Allan Hsu
    {CODEC_ID_FLV1,    FLV_CODECID_H263  },
31
    {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
32 1b88277b Daniel Verkamp
    {CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2},
33 148c9bdb Allan Hsu
    {CODEC_ID_VP6F,    FLV_CODECID_VP6   },
34 09d8c0ae Benjamin Larsson
    {CODEC_ID_VP6,     FLV_CODECID_VP6   },
35 f23496b5 Baptiste Coudurier
    {CODEC_ID_H264,    FLV_CODECID_H264  },
36 148c9bdb Allan Hsu
    {CODEC_ID_NONE,    0}
37
};
38
39 7caf0cc6 Michael Niedermayer
static const AVCodecTag flv_audio_codec_ids[] = {
40 148c9bdb Allan Hsu
    {CODEC_ID_MP3,       FLV_CODECID_MP3    >> FLV_AUDIO_CODECID_OFFSET},
41 8e9efe43 Daniel Verkamp
    {CODEC_ID_PCM_U8,    FLV_CODECID_PCM    >> FLV_AUDIO_CODECID_OFFSET},
42 44de39f9 Michael Niedermayer
    {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM    >> FLV_AUDIO_CODECID_OFFSET},
43 148c9bdb Allan Hsu
    {CODEC_ID_PCM_S16LE, FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET},
44
    {CODEC_ID_ADPCM_SWF, FLV_CODECID_ADPCM  >> FLV_AUDIO_CODECID_OFFSET},
45 f23496b5 Baptiste Coudurier
    {CODEC_ID_AAC,       FLV_CODECID_AAC    >> FLV_AUDIO_CODECID_OFFSET},
46 b7d1cd02 Bartlomiej Wolowiec
    {CODEC_ID_NELLYMOSER, FLV_CODECID_NELLYMOSER >> FLV_AUDIO_CODECID_OFFSET},
47 046c4001 Justin Ruggles
    {CODEC_ID_SPEEX,     FLV_CODECID_SPEEX  >> FLV_AUDIO_CODECID_OFFSET},
48 148c9bdb Allan Hsu
    {CODEC_ID_NONE,      0}
49
};
50
51 d4f5d74a Garrick Meeker
typedef struct FLVContext {
52 11a8e425 Michael Niedermayer
    int reserved;
53 bc5c918e Diego Biurrun
    int64_t duration_offset;
54
    int64_t filesize_offset;
55 634b8cfa Baptiste Coudurier
    int64_t duration;
56 f23496b5 Baptiste Coudurier
    int delay; ///< first dts delay for AVC
57 d4f5d74a Garrick Meeker
} FLVContext;
58
59 37cdf93d Michael Niedermayer
static int get_audio_flags(AVCodecContext *enc){
60 dd1c8f3e Luca Abeni
    int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
61 37cdf93d Michael Niedermayer
62 f23496b5 Baptiste Coudurier
    if (enc->codec_id == CODEC_ID_AAC) // specs force these parameters
63
        return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
64 046c4001 Justin Ruggles
    else if (enc->codec_id == CODEC_ID_SPEEX) {
65
        if (enc->sample_rate != 16000) {
66
            av_log(enc, AV_LOG_ERROR, "flv only supports wideband (16kHz) Speex audio\n");
67
            return -1;
68
        }
69
        if (enc->channels != 1) {
70
            av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n");
71
            return -1;
72
        }
73
        if (enc->frame_size / 320 > 8) {
74 68677dd8 Justin Ruggles
            av_log(enc, AV_LOG_WARNING, "Warning: Speex stream has more than "
75
                                        "8 frames per packet. Adobe Flash "
76
                                        "Player cannot handle this!\n");
77 046c4001 Justin Ruggles
        }
78
        return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;
79
    } else {
80 37cdf93d Michael Niedermayer
    switch (enc->sample_rate) {
81
        case    44100:
82 6cac3a3b Allan Hsu
            flags |= FLV_SAMPLERATE_44100HZ;
83 37cdf93d Michael Niedermayer
            break;
84
        case    22050:
85 6cac3a3b Allan Hsu
            flags |= FLV_SAMPLERATE_22050HZ;
86 37cdf93d Michael Niedermayer
            break;
87
        case    11025:
88 6cac3a3b Allan Hsu
            flags |= FLV_SAMPLERATE_11025HZ;
89 37cdf93d Michael Niedermayer
            break;
90
        case     8000: //nellymoser only
91
        case     5512: //not mp3
92 4838727e Michael Niedermayer
            if(enc->codec_id != CODEC_ID_MP3){
93 ec627278 Michael Niedermayer
                flags |= FLV_SAMPLERATE_SPECIAL;
94
                break;
95 4838727e Michael Niedermayer
            }
96 37cdf93d Michael Niedermayer
        default:
97 755bfeab Diego Biurrun
            av_log(enc, AV_LOG_ERROR, "flv does not support that sample rate, choose from (44100, 22050, 11025).\n");
98 37cdf93d Michael Niedermayer
            return -1;
99
    }
100 f23496b5 Baptiste Coudurier
    }
101 37cdf93d Michael Niedermayer
102
    if (enc->channels > 1) {
103 6cac3a3b Allan Hsu
        flags |= FLV_STEREO;
104 37cdf93d Michael Niedermayer
    }
105 115329f1 Diego Biurrun
106 37cdf93d Michael Niedermayer
    switch(enc->codec_id){
107
    case CODEC_ID_MP3:
108 6cac3a3b Allan Hsu
        flags |= FLV_CODECID_MP3    | FLV_SAMPLESSIZE_16BIT;
109 37cdf93d Michael Niedermayer
        break;
110 8e9efe43 Daniel Verkamp
    case CODEC_ID_PCM_U8:
111 44de39f9 Michael Niedermayer
        flags |= FLV_CODECID_PCM    | FLV_SAMPLESSIZE_8BIT;
112 bb270c08 Diego Biurrun
        break;
113 923bd441 Alex Beregszaszi
    case CODEC_ID_PCM_S16BE:
114 44de39f9 Michael Niedermayer
        flags |= FLV_CODECID_PCM    | FLV_SAMPLESSIZE_16BIT;
115 bb270c08 Diego Biurrun
        break;
116 923bd441 Alex Beregszaszi
    case CODEC_ID_PCM_S16LE:
117 6cac3a3b Allan Hsu
        flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT;
118 bb270c08 Diego Biurrun
        break;
119 2fde8aae Alex Beregszaszi
    case CODEC_ID_ADPCM_SWF:
120 e9509536 Benjamin Larsson
        flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT;
121 bb270c08 Diego Biurrun
        break;
122 b7d1cd02 Bartlomiej Wolowiec
    case CODEC_ID_NELLYMOSER:
123 8ddd280d Alexander Wichers
        if (enc->sample_rate == 8000) {
124
            flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
125
        } else {
126
            flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;
127
        }
128 b7d1cd02 Bartlomiej Wolowiec
        break;
129 37cdf93d Michael Niedermayer
    case 0:
130
        flags |= enc->codec_tag<<4;
131
        break;
132
    default:
133 a254c574 Michael Niedermayer
        av_log(enc, AV_LOG_ERROR, "codec not compatible with flv\n");
134 37cdf93d Michael Niedermayer
        return -1;
135
    }
136 115329f1 Diego Biurrun
137 37cdf93d Michael Niedermayer
    return flags;
138
}
139
140 fd0fb306 Michael Niedermayer
static void put_amf_string(ByteIOContext *pb, const char *str)
141
{
142
    size_t len = strlen(str);
143
    put_be16(pb, len);
144
    put_buffer(pb, str, len);
145
}
146
147
static void put_amf_double(ByteIOContext *pb, double d)
148
{
149 6cac3a3b Allan Hsu
    put_byte(pb, AMF_DATA_TYPE_NUMBER);
150 fd0fb306 Michael Niedermayer
    put_be64(pb, av_dbl2int(d));
151
}
152
153 148c9bdb Allan Hsu
static void put_amf_bool(ByteIOContext *pb, int b) {
154
    put_byte(pb, AMF_DATA_TYPE_BOOL);
155
    put_byte(pb, !!b);
156
}
157
158 d4f5d74a Garrick Meeker
static int flv_write_header(AVFormatContext *s)
159
{
160 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
161 d4f5d74a Garrick Meeker
    FLVContext *flv = s->priv_data;
162 5366f15d Baptiste Coudurier
    AVCodecContext *audio_enc = NULL, *video_enc = NULL;
163
    int i;
164 fd0fb306 Michael Niedermayer
    double framerate = 0.0;
165
    int metadata_size_pos, data_size;
166 d4f5d74a Garrick Meeker
167 11a8e425 Michael Niedermayer
    for(i=0; i<s->nb_streams; i++){
168 01f4895c Michael Niedermayer
        AVCodecContext *enc = s->streams[i]->codec;
169 fd0fb306 Michael Niedermayer
        if (enc->codec_type == CODEC_TYPE_VIDEO) {
170
            if (s->streams[i]->r_frame_rate.den && s->streams[i]->r_frame_rate.num) {
171
                framerate = av_q2d(s->streams[i]->r_frame_rate);
172
            } else {
173
                framerate = 1/av_q2d(s->streams[i]->codec->time_base);
174
            }
175 5366f15d Baptiste Coudurier
            video_enc = enc;
176
            if(enc->codec_tag == 0) {
177 148c9bdb Allan Hsu
                av_log(enc, AV_LOG_ERROR, "video codec not compatible with flv\n");
178
                return -1;
179
            }
180 fd0fb306 Michael Niedermayer
        } else {
181 5366f15d Baptiste Coudurier
            audio_enc = enc;
182 c45388b1 Michael Niedermayer
            if(get_audio_flags(enc)<0)
183
                return -1;
184 fd0fb306 Michael Niedermayer
        }
185 254629b1 Baptiste Coudurier
        av_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
186 c45388b1 Michael Niedermayer
    }
187
    put_tag(pb,"FLV");
188
    put_byte(pb,1);
189 5366f15d Baptiste Coudurier
    put_byte(pb,   FLV_HEADER_FLAG_HASAUDIO * !!audio_enc
190
                 + FLV_HEADER_FLAG_HASVIDEO * !!video_enc);
191 c45388b1 Michael Niedermayer
    put_be32(pb,9);
192
    put_be32(pb,0);
193
194
    for(i=0; i<s->nb_streams; i++){
195
        if(s->streams[i]->codec->codec_tag == 5){
196 11a8e425 Michael Niedermayer
            put_byte(pb,8); // message type
197
            put_be24(pb,0); // include flags
198
            put_be24(pb,0); // time stamp
199
            put_be32(pb,0); // reserved
200
            put_be32(pb,11); // size
201
            flv->reserved=5;
202
        }
203
    }
204 d4f5d74a Garrick Meeker
205 fd0fb306 Michael Niedermayer
    /* write meta_tag */
206
    put_byte(pb, 18);         // tag type META
207
    metadata_size_pos= url_ftell(pb);
208
    put_be24(pb, 0);          // size of data part (sum of all parts below)
209
    put_be24(pb, 0);          // time stamp
210
    put_be32(pb, 0);          // reserved
211
212
    /* now data of data_size size */
213
214
    /* first event name as a string */
215 6cac3a3b Allan Hsu
    put_byte(pb, AMF_DATA_TYPE_STRING);
216 fd0fb306 Michael Niedermayer
    put_amf_string(pb, "onMetaData"); // 12 bytes
217
218
    /* mixed array (hash) with size and string/type/data tuples */
219 6cac3a3b Allan Hsu
    put_byte(pb, AMF_DATA_TYPE_MIXEDARRAY);
220 3f3f3ba7 Yoshihisa Uchida
    put_be32(pb, 5*!!video_enc + 5*!!audio_enc + 2); // +2 for duration and file size
221 fd0fb306 Michael Niedermayer
222 634b8cfa Baptiste Coudurier
    put_amf_string(pb, "duration");
223
    flv->duration_offset= url_ftell(pb);
224 c5e1e982 Justin Johnson
    put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed duration, it'll be corrected later if incorrect
225 fd0fb306 Michael Niedermayer
226 5366f15d Baptiste Coudurier
    if(video_enc){
227 fd0fb306 Michael Niedermayer
        put_amf_string(pb, "width");
228 5366f15d Baptiste Coudurier
        put_amf_double(pb, video_enc->width);
229 fd0fb306 Michael Niedermayer
230
        put_amf_string(pb, "height");
231 5366f15d Baptiste Coudurier
        put_amf_double(pb, video_enc->height);
232 fd0fb306 Michael Niedermayer
233
        put_amf_string(pb, "videodatarate");
234 426a6f34 Stefan de Konink
        put_amf_double(pb, video_enc->bit_rate / 1024.0);
235 fd0fb306 Michael Niedermayer
236
        put_amf_string(pb, "framerate");
237
        put_amf_double(pb, framerate);
238 148c9bdb Allan Hsu
239
        put_amf_string(pb, "videocodecid");
240 5366f15d Baptiste Coudurier
        put_amf_double(pb, video_enc->codec_tag);
241 fd0fb306 Michael Niedermayer
    }
242
243 5366f15d Baptiste Coudurier
    if(audio_enc){
244 426a6f34 Stefan de Konink
        put_amf_string(pb, "audiodatarate");
245
        put_amf_double(pb, audio_enc->bit_rate / 1024.0);
246
247 fd0fb306 Michael Niedermayer
        put_amf_string(pb, "audiosamplerate");
248 5366f15d Baptiste Coudurier
        put_amf_double(pb, audio_enc->sample_rate);
249 148c9bdb Allan Hsu
250
        put_amf_string(pb, "audiosamplesize");
251 8e9efe43 Daniel Verkamp
        put_amf_double(pb, audio_enc->codec_id == CODEC_ID_PCM_U8 ? 8 : 16);
252 148c9bdb Allan Hsu
253
        put_amf_string(pb, "stereo");
254 5366f15d Baptiste Coudurier
        put_amf_bool(pb, audio_enc->channels == 2);
255 148c9bdb Allan Hsu
256
        put_amf_string(pb, "audiocodecid");
257 5366f15d Baptiste Coudurier
        put_amf_double(pb, audio_enc->codec_tag);
258 fd0fb306 Michael Niedermayer
    }
259
260 634b8cfa Baptiste Coudurier
    put_amf_string(pb, "filesize");
261
    flv->filesize_offset= url_ftell(pb);
262
    put_amf_double(pb, 0); // delayed write
263 fd0fb306 Michael Niedermayer
264
    put_amf_string(pb, "");
265 6cac3a3b Allan Hsu
    put_byte(pb, AMF_END_OF_OBJECT);
266 fd0fb306 Michael Niedermayer
267
    /* write total size of tag */
268
    data_size= url_ftell(pb) - metadata_size_pos - 10;
269
    url_fseek(pb, metadata_size_pos, SEEK_SET);
270
    put_be24(pb, data_size);
271
    url_fseek(pb, data_size + 10 - 3, SEEK_CUR);
272
    put_be32(pb, data_size + 11);
273
274 f23496b5 Baptiste Coudurier
    for (i = 0; i < s->nb_streams; i++) {
275
        AVCodecContext *enc = s->streams[i]->codec;
276
        if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) {
277 bc5c918e Diego Biurrun
            int64_t pos;
278 f23496b5 Baptiste Coudurier
            put_byte(pb, enc->codec_type == CODEC_TYPE_VIDEO ?
279
                     FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
280
            put_be24(pb, 0); // size patched later
281
            put_be24(pb, 0); // ts
282
            put_byte(pb, 0); // ts ext
283
            put_be24(pb, 0); // streamid
284
            pos = url_ftell(pb);
285
            if (enc->codec_id == CODEC_ID_AAC) {
286
                put_byte(pb, get_audio_flags(enc));
287
                put_byte(pb, 0); // AAC sequence header
288
                put_buffer(pb, enc->extradata, enc->extradata_size);
289
            } else {
290
                put_byte(pb, enc->codec_tag | FLV_FRAME_KEY); // flags
291
                put_byte(pb, 0); // AVC sequence header
292
                put_be24(pb, 0); // composition time
293
                ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
294
            }
295
            data_size = url_ftell(pb) - pos;
296
            url_fseek(pb, -data_size - 10, SEEK_CUR);
297
            put_be24(pb, data_size);
298
            url_fseek(pb, data_size + 10 - 3, SEEK_CUR);
299
            put_be32(pb, data_size + 11); // previous tag size
300
        }
301
    }
302
303 d4f5d74a Garrick Meeker
    return 0;
304
}
305
306
static int flv_write_trailer(AVFormatContext *s)
307
{
308 14b32253 Michael Niedermayer
    int64_t file_size;
309
310 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
311 d4f5d74a Garrick Meeker
    FLVContext *flv = s->priv_data;
312
313 14b32253 Michael Niedermayer
    file_size = url_ftell(pb);
314 634b8cfa Baptiste Coudurier
315
    /* update informations */
316
    url_fseek(pb, flv->duration_offset, SEEK_SET);
317
    put_amf_double(pb, flv->duration / (double)1000);
318
    url_fseek(pb, flv->filesize_offset, SEEK_SET);
319
    put_amf_double(pb, file_size);
320
321 d4f5d74a Garrick Meeker
    url_fseek(pb, file_size, SEEK_SET);
322
    return 0;
323
}
324
325 e928649b Michael Niedermayer
static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
326 d4f5d74a Garrick Meeker
{
327 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
328 01f4895c Michael Niedermayer
    AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
329 d4f5d74a Garrick Meeker
    FLVContext *flv = s->priv_data;
330 f23496b5 Baptiste Coudurier
    unsigned ts;
331 e928649b Michael Niedermayer
    int size= pkt->size;
332 71e685b0 Baptiste Coudurier
    uint8_t *data= NULL;
333 f683dbdc Michael Niedermayer
    int flags, flags_size;
334 d4f5d74a Garrick Meeker
335 949b1a13 Steve L'Homme
//    av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", enc->codec_type, timestamp, size);
336 115329f1 Diego Biurrun
337 f23496b5 Baptiste Coudurier
    if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F ||
338
       enc->codec_id == CODEC_ID_AAC)
339 f683dbdc Michael Niedermayer
        flags_size= 2;
340 f23496b5 Baptiste Coudurier
    else if(enc->codec_id == CODEC_ID_H264)
341
        flags_size= 5;
342 f683dbdc Michael Niedermayer
    else
343
        flags_size= 1;
344
345 d4f5d74a Garrick Meeker
    if (enc->codec_type == CODEC_TYPE_VIDEO) {
346 6cac3a3b Allan Hsu
        put_byte(pb, FLV_TAG_TYPE_VIDEO);
347 09d8c0ae Benjamin Larsson
348 bb85077f Michael Niedermayer
        flags = enc->codec_tag;
349 09d8c0ae Benjamin Larsson
        if(flags == 0) {
350
            av_log(enc, AV_LOG_ERROR, "video codec %X not compatible with flv\n",enc->codec_id);
351
            return -1;
352
        }
353
354 6cac3a3b Allan Hsu
        flags |= pkt->flags & PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER;
355 75293f05 Michael Niedermayer
    } else {
356
        assert(enc->codec_type == CODEC_TYPE_AUDIO);
357 37cdf93d Michael Niedermayer
        flags = get_audio_flags(enc);
358 115329f1 Diego Biurrun
359 068f2a22 Michael Niedermayer
        assert(size);
360
361 6cac3a3b Allan Hsu
        put_byte(pb, FLV_TAG_TYPE_AUDIO);
362 75293f05 Michael Niedermayer
    }
363
364 7d637efa Baptiste Coudurier
    if (enc->codec_id == CODEC_ID_H264) {
365 71e685b0 Baptiste Coudurier
        /* check if extradata looks like mp4 formated */
366
        if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
367
            if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
368
                return -1;
369
        }
370 6f4eb12d Baptiste Coudurier
        if (!flv->delay && pkt->dts < 0)
371
            flv->delay = -pkt->dts;
372 f23496b5 Baptiste Coudurier
    }
373
374
    ts = pkt->dts + flv->delay; // add delay to force positive dts
375 f683dbdc Michael Niedermayer
    put_be24(pb,size + flags_size);
376 f23496b5 Baptiste Coudurier
    put_be24(pb,ts);
377 b83a00b8 Baptiste Coudurier
    put_byte(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_
378 018b6fb4 Alex Beregszaszi
    put_be24(pb,flv->reserved);
379 75293f05 Michael Niedermayer
    put_byte(pb,flags);
380 09d8c0ae Benjamin Larsson
    if (enc->codec_id == CODEC_ID_VP6)
381
        put_byte(pb,0);
382
    if (enc->codec_id == CODEC_ID_VP6F)
383
        put_byte(pb, enc->extradata_size ? enc->extradata[0] : 0);
384 f23496b5 Baptiste Coudurier
    else if (enc->codec_id == CODEC_ID_AAC)
385
        put_byte(pb,1); // AAC raw
386
    else if (enc->codec_id == CODEC_ID_H264) {
387
        put_byte(pb,1); // AVC NALU
388 6f4eb12d Baptiste Coudurier
        put_be24(pb,pkt->pts - pkt->dts);
389 f23496b5 Baptiste Coudurier
    }
390 71e685b0 Baptiste Coudurier
391
    put_buffer(pb, data ? data : pkt->data, size);
392
393 f683dbdc Michael Niedermayer
    put_be32(pb,size+flags_size+11); // previous tag size
394 f23496b5 Baptiste Coudurier
    flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
395 115329f1 Diego Biurrun
396 d4f5d74a Garrick Meeker
    put_flush_packet(pb);
397 71e685b0 Baptiste Coudurier
398
    av_free(data);
399
400 d4f5d74a Garrick Meeker
    return 0;
401
}
402
403 ff70e601 Måns Rullgård
AVOutputFormat flv_muxer = {
404 d4f5d74a Garrick Meeker
    "flv",
405 bde15e74 Stefano Sabatini
    NULL_IF_CONFIG_SMALL("FLV format"),
406 e817a73d Michael Niedermayer
    "video/x-flv",
407 d4f5d74a Garrick Meeker
    "flv",
408
    sizeof(FLVContext),
409 b250f9c6 Aurelien Jacobs
#if CONFIG_LIBMP3LAME
410 80783dc2 Fabrice Bellard
    CODEC_ID_MP3,
411 6ebe07fb Diego Biurrun
#else // CONFIG_LIBMP3LAME
412 964ff354 Alex Beregszaszi
    CODEC_ID_ADPCM_SWF,
413 6ebe07fb Diego Biurrun
#endif // CONFIG_LIBMP3LAME
414 d4f5d74a Garrick Meeker
    CODEC_ID_FLV1,
415
    flv_write_header,
416
    flv_write_packet,
417
    flv_write_trailer,
418 c1854592 Reimar Döffinger
    .codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0},
419 e458dd0b Michael Niedermayer
    .flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
420 d4f5d74a Garrick Meeker
};