1 /*
2 * FLV muxer
3 * Copyright (c) 2003 The FFmpeg Project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * 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 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
31
32
43 };
44
57 };
58
64 int64_t
delay;
///< first dts delay (needed for AVC & Speex)
66
68 int64_t
last_ts;
///< last timestamp for each stream
70
72 {
75
82 "FLV only supports wideband (16kHz) Speex audio\n");
84 }
88 }
90 } else {
92 case 44100:
94 break;
95 case 22050:
97 break;
98 case 11025:
100 break;
101 case 16000: // nellymoser only
102 case 8000: // nellymoser only
103 case 5512: // not MP3
106 break;
107 }
108 default:
110 "FLV does not support sample rate %d, "
111 "choose from (44100, 22050, 11025)\n", enc->
sample_rate);
113 }
114 }
115
118
122 break;
125 break;
128 break;
131 break;
134 break;
140 else
142 break;
145 break;
148 break;
149 case 0:
151 break;
152 default:
156 }
157
159 }
160
162 {
163 size_t len = strlen(str);
166 }
167
169 {
172 avio_wb24(pb, ts);
/* lower 24 bits of timestamp in ms */
173 avio_w8(pb, (ts >> 24) & 0x7F);
/* MSB of ts in ms */
175 avio_w8(pb, 23);
/* ub[4] FrameType = 1, ub[4] CodecId = 7 */
176 avio_w8(pb, 2);
/* AVC end of sequence */
177 avio_wb24(pb, 0);
/* Always 0 for AVC EOS. */
179 }
180
182 {
185 }
186
188 {
191 }
192
194 {
197 AVCodecContext *audio_enc = NULL, *video_enc = NULL, *data_enc = NULL;
198 int i, metadata_count = 0;
199 double framerate = 0.0;
200 int64_t metadata_size_pos, data_size, metadata_count_pos;
202
211 } else {
213 }
214 if (video_enc) {
216 "at most one video stream is supported in flv\n");
218 }
219 video_enc = enc;
221 av_log(s,
AV_LOG_ERROR,
"Video codec '%s' for stream %d is not compatible with FLV\n",
224 }
225 break;
227 if (audio_enc) {
229 "at most one audio stream is supported in flv\n");
231 }
232 audio_enc = enc;
235 break;
241 }
242 data_enc = enc;
243 break;
244 default:
248 }
250
252 if (!sc)
256 }
257
259
266
269 avio_w8(pb, 8);
// message type
275 }
276
277 /* write meta_tag */
278 avio_w8(pb, 18);
// tag type META
280 avio_wb24(pb, 0);
// size of data part (sum of all parts below)
283
284 /* now data of data_size size */
285
286 /* first event name as a string */
289
290 /* mixed array (hash) with size and string/type/data tuples */
293 metadata_count = 5 * !!video_enc +
294 5 * !!audio_enc +
295 1 * !!data_enc +
296 2; // +2 for duration and file size
297
299
302
303 // fill in the guessed duration, it'll be corrected later if incorrect
305
306 if (video_enc) {
309
312
315
318
321 }
322
323 if (audio_enc) {
326
329
332
335
338 }
339
340 if (data_enc) {
343 }
344
346 if( !strcmp(tag->
key,
"width")
347 ||!strcmp(tag->
key,
"height")
348 ||!strcmp(tag->
key,
"videodatarate")
349 ||!strcmp(tag->
key,
"framerate")
350 ||!strcmp(tag->
key,
"videocodecid")
351 ||!strcmp(tag->
key,
"audiodatarate")
352 ||!strcmp(tag->
key,
"audiosamplerate")
353 ||!strcmp(tag->
key,
"audiosamplesize")
354 ||!strcmp(tag->
key,
"stereo")
355 ||!strcmp(tag->
key,
"audiocodecid")
356 ||!strcmp(tag->
key,
"duration")
357 ||!strcmp(tag->
key,
"onMetaData")
358 ){
360 continue;
361 }
365 metadata_count++;
366 }
367
371
374
375 /* write total size of tag */
376 data_size =
avio_tell(pb) - metadata_size_pos - 10;
377
378 avio_seek(pb, metadata_count_pos, SEEK_SET);
380
381 avio_seek(pb, metadata_size_pos, SEEK_SET);
385
389 int64_t pos;
399 avio_w8(pb, 0);
// AAC sequence header
401 } else {
403 avio_w8(pb, 0);
// AVC sequence header
406 }
408 avio_seek(pb, -data_size - 10, SEEK_CUR);
411 avio_wb32(pb, data_size + 11);
// previous tag size
412 }
413 }
414
415 return 0;
416 }
417
419 {
420 int64_t file_size;
421
424 int i;
425
426 /* Add EOS tag */
433 }
434
436
437 /* update information */
440 else
444 else
446
448 return 0;
449 }
450
452 {
457 unsigned ts;
461
464 flags_size = 2;
466 flags_size = 5;
467 else
468 flags_size = 1;
469
473
475 if (flags == 0) {
477 "Video codec '%s' is not compatible with FLV\n",
480 }
481
483 break;
486
488
490 break;
493 break;
494 default:
496 }
497
499 /* check if extradata looks like mp4 formated */
507 "use audio bitstream filter 'aac_adtstoasc' to fix it "
508 "('-bsf:a aac_adtstoasc' option with ffmpeg)\n");
510 }
512 }
513
516
519 "Packets are not in the proper order with respect to DTS\n");
521 }
522
523 ts = pkt->
dts + flv->
delay;
// add delay to force positive dts
524
525 /* check Speex packet duration */
528 "8 frames per packet. Adobe Flash "
529 "Player cannot handle this!\n");
530
533
536 avio_w8(pb, (ts >> 24) & 0x7F);
// timestamps are 32 bits _signed_
538
540 int data_size;
554 /* write total size of tag */
555 data_size =
avio_tell(pb) - metadata_size_pos;
556 avio_seek(pb, metadata_size_pos - 10, SEEK_SET);
558 avio_seek(pb, data_size + 10 - 3, SEEK_CUR);
560 } else {
566 else
574 }
575
577
578 avio_wb32(pb, size + flags_size + 11);
// previous tag size
581 }
582
584
586 }
587
591 .mime_type = "video/x-flv",
592 .extensions = "flv",
601 },
604 };