- if ((enc->codec_id == CODEC_ID_VP6) || (enc->codec_id == CODEC_ID_VP6F))
- put_be24(pb,size+2); // include the extra byte needed for VP6 in flv and flags
- else
- put_be24(pb,size+1); // include flags
- put_be24(pb,pkt->pts);
- put_be32(pb,flv->reserved);
- put_byte(pb,flags);
- if (enc->codec_id == CODEC_ID_VP6)
- put_byte(pb,0);
- if (enc->codec_id == CODEC_ID_VP6F)
- put_byte(pb, enc->extradata_size ? enc->extradata[0] : 0);
- put_buffer(pb, pkt->data, size);
- put_be32(pb,size+1+11); // previous tag size
- flv->duration = pkt->pts + pkt->duration;
-
- put_flush_packet(pb);
- return 0;
+ if (enc->codec_id == AV_CODEC_ID_H264)
+ /* check if extradata looks like MP4 */
+ 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 == AV_NOPTS_VALUE)
+ flv->delay = -pkt->dts;
+
+ if (pkt->dts < -flv->delay) {
+ av_log(s, AV_LOG_WARNING,
+ "Packets are not in the proper order with respect to DTS\n");
+ return AVERROR(EINVAL);
+ }
+
+ ts = pkt->dts + flv->delay; // add delay to force positive dts
+
+ /* check Speex packet duration */
+ if (enc->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160)
+ av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than "
+ "8 frames per packet. Adobe Flash "
+ "Player cannot handle this!\n");
+
+ if (sc->last_ts < ts)
+ sc->last_ts = ts;
+
+ avio_wb24(pb, size + flags_size);
+ avio_wb24(pb, ts);
+ avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_
+ avio_wb24(pb, flv->reserved);
+
+ if (enc->codec_type == AVMEDIA_TYPE_DATA) {
+ int data_size;
+ int64_t metadata_size_pos = avio_tell(pb);
+ avio_w8(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, "onTextData");
+ avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
+ avio_wb32(pb, 2);
+ put_amf_string(pb, "type");
+ avio_w8(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, "Text");
+ put_amf_string(pb, "text");
+ avio_w8(pb, AMF_DATA_TYPE_STRING);
+ put_amf_string(pb, pkt->data);
+ put_amf_string(pb, "");
+ avio_w8(pb, AMF_END_OF_OBJECT);
+ /* write total size of tag */
+ data_size = avio_tell(pb) - metadata_size_pos;
+ avio_seek(pb, metadata_size_pos - 10, SEEK_SET);
+ avio_wb24(pb, data_size);
+ avio_seek(pb, data_size + 10 - 3, SEEK_CUR);
+ avio_wb32(pb, data_size + 11);
+ } else {
+ avio_w8(pb,flags);
+ if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A) {
+ if (enc->extradata_size)
+ avio_w8(pb, enc->extradata[0]);
+ else
+ avio_w8(pb, ((FFALIGN(enc->width, 16) - enc->width) << 4) |
+ (FFALIGN(enc->height, 16) - enc->height));
+ } else if (enc->codec_id == AV_CODEC_ID_AAC)
+ avio_w8(pb, 1); // AAC raw
+ else if (enc->codec_id == AV_CODEC_ID_H264) {
+ avio_w8(pb, 1); // AVC NALU
+ avio_wb24(pb, pkt->pts - pkt->dts);
+ }
+
+ avio_write(pb, data ? data : pkt->data, size);
+
+ avio_wb32(pb, size + flags_size + 11); // previous tag size
+ flv->duration = FFMAX(flv->duration,
+ pkt->pts + flv->delay + pkt->duration);
+ }
+
+ av_free(data);
+
+ return pb->error;