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
44 };
45
58 };
59
65 int64_t
delay;
///< first dts delay (needed for AVC & Speex)
67
69 int64_t
last_ts;
///< last timestamp for each stream
71
73 {
76
83 "FLV only supports wideband (16kHz) Speex audio\n");
85 }
89 }
91 } else {
93 case 44100:
95 break;
96 case 22050:
98 break;
99 case 11025:
101 break;
102 case 16000: // nellymoser only
103 case 8000: // nellymoser only
104 case 5512: // not MP3
107 break;
108 }
109 default:
111 "FLV does not support sample rate %d, "
112 "choose from (44100, 22050, 11025)\n", enc->
sample_rate);
114 }
115 }
116
119
123 break;
126 break;
129 break;
132 break;
135 break;
141 else
143 break;
146 break;
149 break;
150 case 0:
152 break;
153 default:
157 }
158
160 }
161
163 {
164 size_t len = strlen(str);
167 }
168
170 {
173 avio_wb24(pb, ts);
/* lower 24 bits of timestamp in ms */
174 avio_w8(pb, (ts >> 24) & 0x7F);
/* MSB of ts in ms */
176 avio_w8(pb, 23);
/* ub[4] FrameType = 1, ub[4] CodecId = 7 */
177 avio_w8(pb, 2);
/* AVC end of sequence */
178 avio_wb24(pb, 0);
/* Always 0 for AVC EOS. */
180 }
181
183 {
186 }
187
189 {
192 }
193
195 {
198 AVCodecContext *audio_enc = NULL, *video_enc = NULL, *data_enc = NULL;
199 int i, metadata_count = 0;
200 double framerate = 0.0;
201 int64_t metadata_size_pos, data_size, metadata_count_pos;
203
212 } else {
214 }
215 if (video_enc) {
217 "at most one video stream is supported in flv\n");
219 }
220 video_enc = enc;
222 av_log(s,
AV_LOG_ERROR,
"Video codec '%s' for stream %d is not compatible with FLV\n",
225 }
226 break;
228 if (audio_enc) {
230 "at most one audio stream is supported in flv\n");
232 }
233 audio_enc = enc;
236 break;
242 }
243 data_enc = enc;
244 break;
245 default:
249 }
251
253 if (!sc)
257 }
258
260
267
270 avio_w8(pb, 8);
// message type
276 }
277
278 /* write meta_tag */
279 avio_w8(pb, 18);
// tag type META
281 avio_wb24(pb, 0);
// size of data part (sum of all parts below)
284
285 /* now data of data_size size */
286
287 /* first event name as a string */
290
291 /* mixed array (hash) with size and string/type/data tuples */
294 metadata_count = 5 * !!video_enc +
295 5 * !!audio_enc +
296 1 * !!data_enc +
297 2; // +2 for duration and file size
298
300
303
304 // fill in the guessed duration, it'll be corrected later if incorrect
306
307 if (video_enc) {
310
313
316
319
322 }
323
324 if (audio_enc) {
327
330
333
336
339 }
340
341 if (data_enc) {
344 }
345
347 if( !strcmp(tag->
key,
"width")
348 ||!strcmp(tag->
key,
"height")
349 ||!strcmp(tag->
key,
"videodatarate")
350 ||!strcmp(tag->
key,
"framerate")
351 ||!strcmp(tag->
key,
"videocodecid")
352 ||!strcmp(tag->
key,
"audiodatarate")
353 ||!strcmp(tag->
key,
"audiosamplerate")
354 ||!strcmp(tag->
key,
"audiosamplesize")
355 ||!strcmp(tag->
key,
"stereo")
356 ||!strcmp(tag->
key,
"audiocodecid")
357 ||!strcmp(tag->
key,
"duration")
358 ||!strcmp(tag->
key,
"onMetaData")
359 ){
361 continue;
362 }
366 metadata_count++;
367 }
368
372
375
376 /* write total size of tag */
377 data_size =
avio_tell(pb) - metadata_size_pos - 10;
378
379 avio_seek(pb, metadata_count_pos, SEEK_SET);
381
382 avio_seek(pb, metadata_size_pos, SEEK_SET);
386
390 int64_t pos;
400 avio_w8(pb, 0);
// AAC sequence header
402 } else {
404 avio_w8(pb, 0);
// AVC sequence header
407 }
409 avio_seek(pb, -data_size - 10, SEEK_CUR);
412 avio_wb32(pb, data_size + 11);
// previous tag size
413 }
414 }
415
416 return 0;
417 }
418
420 {
421 int64_t file_size;
422
425 int i;
426
427 /* Add EOS tag */
434 }
435
437
438 /* update information */
441 else
445 else
447
449 return 0;
450 }
451
453 {
458 unsigned ts;
462
465 flags_size = 2;
467 flags_size = 5;
468 else
469 flags_size = 1;
470
474
476 if (flags == 0) {
478 "Video codec '%s' is not compatible with FLV\n",
481 }
482
484 break;
487
489
491 break;
494 break;
495 default:
497 }
498
500 /* check if extradata looks like mp4 formated */
508 "use audio bitstream filter 'aac_adtstoasc' to fix it "
509 "('-bsf:a aac_adtstoasc' option with ffmpeg)\n");
511 }
513 }
514
517
520 "Packets are not in the proper order with respect to DTS\n");
522 }
523
524 ts = pkt->
dts + flv->
delay;
// add delay to force positive dts
525
526 /* check Speex packet duration */
529 "8 frames per packet. Adobe Flash "
530 "Player cannot handle this!\n");
531
534
537 avio_w8(pb, (ts >> 24) & 0x7F);
// timestamps are 32 bits _signed_
539
541 int data_size;
555 /* write total size of tag */
556 data_size =
avio_tell(pb) - metadata_size_pos;
557 avio_seek(pb, metadata_size_pos - 10, SEEK_SET);
559 avio_seek(pb, data_size + 10 - 3, SEEK_CUR);
561 } else {
573 }
574
576
577 avio_wb32(pb, size + flags_size + 11);
// previous tag size
580 }
581
583
585 }
586
590 .mime_type = "video/x-flv",
591 .extensions = "flv",
600 },
603 };