diff options
Diffstat (limited to 'ffmpeg/libavformat/flvenc.c')
| -rw-r--r-- | ffmpeg/libavformat/flvenc.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/ffmpeg/libavformat/flvenc.c b/ffmpeg/libavformat/flvenc.c index 502da0f..fb36f66 100644 --- a/ffmpeg/libavformat/flvenc.c +++ b/ffmpeg/libavformat/flvenc.c @@ -212,6 +212,11 @@ static int flv_write_header(AVFormatContext *s) } else { framerate = 1 / av_q2d(s->streams[i]->codec->time_base); } + if (video_enc) { + av_log(s, AV_LOG_ERROR, + "at most one video stream is supported in flv\n"); + return AVERROR(EINVAL); + } video_enc = enc; if (enc->codec_tag == 0) { av_log(s, AV_LOG_ERROR, "Video codec '%s' for stream %d is not compatible with FLV\n", @@ -220,6 +225,11 @@ static int flv_write_header(AVFormatContext *s) } break; case AVMEDIA_TYPE_AUDIO: + if (audio_enc) { + av_log(s, AV_LOG_ERROR, + "at most one audio stream is supported in flv\n"); + return AVERROR(EINVAL); + } audio_enc = enc; if (get_audio_flags(s, enc) < 0) return AVERROR_INVALIDDATA; @@ -450,8 +460,8 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) uint8_t *data = NULL; int flags = -1, flags_size, ret; - if (enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_VP6F || - enc->codec_id == AV_CODEC_ID_VP6A || enc->codec_id == AV_CODEC_ID_AAC) + if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A || + enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_AAC) flags_size = 2; else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) flags_size = 5; @@ -493,10 +503,13 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) return ret; } else if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { + if (!s->streams[pkt->stream_index]->nb_frames) { av_log(s, AV_LOG_ERROR, "Malformed AAC bitstream detected: " "use audio bitstream filter 'aac_adtstoasc' to fix it " "('-bsf:a aac_adtstoasc' option with ffmpeg)\n"); return AVERROR_INVALIDDATA; + } + av_log(s, AV_LOG_WARNING, "aac bitstream error\n"); } if (flv->delay == AV_NOPTS_VALUE) @@ -526,7 +539,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if (enc->codec_type == AVMEDIA_TYPE_DATA) { int data_size; - int metadata_size_pos = avio_tell(pb); + 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); @@ -550,13 +563,17 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_w8(pb,flags); if (enc->codec_id == AV_CODEC_ID_VP6) avio_w8(pb,0); - if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A) - avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0); - else if (enc->codec_id == AV_CODEC_ID_AAC) - avio_w8(pb,1); // AAC raw + 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 || enc->codec_id == AV_CODEC_ID_MPEG4) { - avio_w8(pb,1); // AVC NALU - avio_wb24(pb,pkt->pts - pkt->dts); + avio_w8(pb, 1); // AVC NALU + avio_wb24(pb, pkt->pts - pkt->dts); } avio_write(pb, data ? data : pkt->data, size); @@ -566,7 +583,6 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) pkt->pts + flv->delay + pkt->duration); } - avio_flush(pb); av_free(data); return pb->error; |
