Commit d9b43245 authored by michaelni's avatar michaelni

flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@2024 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent eb553459
......@@ -39,6 +39,7 @@ static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
{ CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
{ CODEC_ID_AC3, { 0x2000, 0 } },
{ CODEC_ID_MP2, { 0x50, 0x55, 0 } },
{ CODEC_ID_FLV1, { MKTAG('F', 'L', 'V', '1'), 0 } },
{ CODEC_ID_NONE, {0}}
};
......
......@@ -41,6 +41,7 @@ enum CodecID {
CODEC_ID_WMV2,
CODEC_ID_H263P,
CODEC_ID_H263I,
CODEC_ID_FLV1,
CODEC_ID_SVQ1,
CODEC_ID_SVQ3,
CODEC_ID_DVVIDEO,
......@@ -1226,6 +1227,7 @@ extern AVCodec oggvorbis_encoder;
extern AVCodec mpeg1video_encoder;
extern AVCodec h263_encoder;
extern AVCodec h263p_encoder;
extern AVCodec flv_encoder;
extern AVCodec rv10_encoder;
extern AVCodec mjpeg_encoder;
extern AVCodec ljpeg_encoder;
......@@ -1249,6 +1251,7 @@ extern AVCodec wmv1_decoder;
extern AVCodec wmv2_decoder;
extern AVCodec mpeg_decoder;
extern AVCodec h263i_decoder;
extern AVCodec flv_decoder;
extern AVCodec rv10_decoder;
extern AVCodec svq1_decoder;
extern AVCodec svq3_decoder;
......
This diff is collapsed.
......@@ -96,6 +96,9 @@ int ff_h263_decode_init(AVCodecContext *avctx)
case CODEC_ID_H263I:
s->h263_intel = 1;
break;
case CODEC_ID_FLV1:
s->h263_flv = 1;
break;
default:
return -1;
}
......@@ -451,6 +454,8 @@ retry:
s->low_delay=1;
} else if (s->h263_intel) {
ret = intel_h263_decode_picture_header(s);
} else if (s->h263_flv) {
ret = flv_h263_decode_picture_header(s);
} else {
ret = h263_decode_picture_header(s);
}
......@@ -793,3 +798,14 @@ AVCodec h263i_decoder = {
mpeg4_decoptions,
};
AVCodec flv_decoder = {
"flv",
CODEC_TYPE_VIDEO,
CODEC_ID_FLV1,
sizeof(MpegEncContext),
ff_h263_decode_init,
NULL,
ff_h263_decode_end,
ff_h263_decode_frame,
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1
};
......@@ -593,19 +593,19 @@ static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src,
{
const uint8_t *p, *p1;
uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
int x;
int w;
p1 = src->data[0];
lum1 = dst->data[0];
cb1 = dst->data[1];
cr1 = dst->data[2];
for(;height >= 2; height -= 2) {
for(;height >= 1; height -= 2) {
p = p1;
lum = lum1;
cb = cb1;
cr = cr1;
for(x=0;x<width;x+=2) {
for(w = width; w >= 2; w -= 2) {
lum[0] = p[0];
cb[0] = p[1];
lum[1] = p[2];
......@@ -615,18 +615,30 @@ static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src,
cb++;
cr++;
}
p1 += src->linesize[0];
lum1 += dst->linesize[0];
p = p1;
lum = lum1;
for(x=0;x<width;x+=2) {
if (w) {
lum[0] = p[0];
lum[1] = p[2];
p += 4;
lum += 2;
cb[0] = p[1];
cr[0] = p[3];
cb++;
cr++;
}
p1 += src->linesize[0];
lum1 += dst->linesize[0];
if (height>1) {
p = p1;
lum = lum1;
for(w = width; w >= 2; w -= 2) {
lum[0] = p[0];
lum[1] = p[2];
p += 4;
lum += 2;
}
if (w) {
lum[0] = p[0];
}
p1 += src->linesize[0];
lum1 += dst->linesize[0];
}
cb1 += dst->linesize[1];
cr1 += dst->linesize[2];
}
......
......@@ -670,6 +670,14 @@ int MPV_encode_init(AVCodecContext *avctx)
avctx->delay=0;
s->low_delay=1;
break;
case CODEC_ID_FLV1:
s->out_format = FMT_H263;
s->h263_flv = 2; /* format = 1; 11-bit codes */
s->unrestricted_mv = 1;
s->rtp_mode=0; /* don't allow GOB */
avctx->delay=0;
s->low_delay=1;
break;
case CODEC_ID_RV10:
s->out_format = FMT_H263;
s->h263_rv10 = 1;
......@@ -2997,6 +3005,7 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break;
case CODEC_ID_H263:
case CODEC_ID_H263P:
case CODEC_ID_FLV1:
case CODEC_ID_RV10:
h263_encode_mb(s, s->block, motion_x, motion_y); break;
#endif
......@@ -3348,6 +3357,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
break;
case CODEC_ID_H263:
case CODEC_ID_H263P:
case CODEC_ID_FLV1:
ff_clean_h263_qscales(s);
break;
}
......@@ -3427,11 +3437,17 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->last_mv_dir = 0;
#ifdef CONFIG_RISKY
if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P)
switch(s->codec_id){
case CODEC_ID_H263:
case CODEC_ID_H263P:
case CODEC_ID_FLV1:
s->gob_index = ff_h263_get_gob_height(s);
if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame)
ff_mpeg4_init_partitions(s);
break;
case CODEC_ID_MPEG4:
if(s->partitioned_frame)
ff_mpeg4_init_partitions(s);
break;
}
#endif
s->resync_mb_x=0;
......@@ -4439,6 +4455,16 @@ AVCodec h263p_encoder = {
MPV_encode_end,
};
AVCodec flv_encoder = {
"flv",
CODEC_TYPE_VIDEO,
CODEC_ID_FLV1,
sizeof(MpegEncContext),
MPV_encode_init,
MPV_encode_picture,
MPV_encode_end,
};
AVCodec rv10_encoder = {
"rv10",
CODEC_TYPE_VIDEO,
......
......@@ -269,6 +269,7 @@ typedef struct MpegEncContext {
int h263_rv10; ///< use RV10 variation for H263
int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)
int h263_intel; ///< use I263 intel h263 header
int h263_flv; ///< use flv h263 header
int codec_id; /* see CODEC_ID_xxx */
int fixed_qscale; ///< fixed qscale if non zero
......@@ -833,6 +834,7 @@ int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb);
int intel_h263_decode_picture_header(MpegEncContext *s);
int flv_h263_decode_picture_header(MpegEncContext *s);
int ff_h263_decode_mb(MpegEncContext *s,
DCTELEM block[6][64]);
int h263_get_picture_format(int width, int height);
......
......@@ -610,6 +610,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
case CODEC_ID_WMV2:
case CODEC_ID_H263P:
case CODEC_ID_H263I:
case CODEC_ID_FLV1:
case CODEC_ID_SVQ1:
for(i=0; i<MAX_PICTURE_COUNT; i++){
if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL
......
......@@ -14,7 +14,7 @@ PPOBJS=
# mux and demuxes
OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o raw.o rm.o \
avienc.o avidec.o wav.o swf.o au.o gif.o mov.o mpjpeg.o dv.o \
yuv4mpeg.o 4xm.o
yuv4mpeg.o 4xm.o flvenc.o flvdec.o
ifeq ($(CONFIG_RISKY),yes)
OBJS+= asf.o
......
......@@ -48,6 +48,8 @@ void av_register_all(void)
jpeg_init();
dv_init();
fourxm_init();
flvenc_init();
flvdec_init();
#ifdef AMR_NB
amr_init();
......
......@@ -304,6 +304,12 @@ int swf_init(void);
/* mov.c */
int mov_init(void);
/* flvenc.c */
int flvenc_init(void);
/* flvdec.c */
int flvdec_init(void);
/* jpeg.c */
int jpeg_init(void);
......
/*
* FLV encoder.
* Copyright (c) 2003 The FFmpeg Project.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "avformat.h"
unsigned int get_be24(ByteIOContext *s)
{
unsigned int val;
val = get_byte(s) << 16;
val |= get_byte(s) << 8;
val |= get_byte(s);
return val;
}
static int flv_probe(AVProbeData *p)
{
const uint8_t *d;
if (p->buf_size < 6)
return 0;
d = p->buf;
if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V') {
return 50;
}
return 0;
}
static int flv_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
int offset, flags;
AVStream *st;
av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
url_fskip(&s->pb, 4);
flags = get_byte(&s->pb);
if ((flags & 1)) {
st = av_new_stream(s, 0);
if (!st)
return AVERROR_NOMEM;
st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = CODEC_ID_FLV1;
}
if ((flags & 4)) {
st = av_new_stream(s, 1);
if (!st)
return AVERROR_NOMEM;
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = CODEC_ID_MP3LAME;
}
offset = get_be32(&s->pb);
url_fseek(&s->pb, offset, SEEK_SET);
return 0;
}
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, i, type, size, pts, flags;
AVStream *st;
redo:
url_fskip(&s->pb, 4); /* size of previous packet */
type = get_byte(&s->pb);
size = get_be24(&s->pb);
pts = get_be24(&s->pb);
if (url_feof(&s->pb))
return -EIO;
url_fskip(&s->pb, 4); /* reserved */
flags = 0;
if (type == 8) {
flags = get_byte(&s->pb);
size--;
if ((flags >> 4) != 2) { /* 0: uncompressed 1: ADPCM 2: mp3 5: Nellymoser 8kHz mono 6: Nellymoser*/
goto skip;
}
} else if (type == 9) {
flags = get_byte(&s->pb);
size--;
if ((flags & 0xF) != 2) { /* 2: only format */
goto skip;
}
} else {
skip:
/* skip packet */
printf("skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
url_fskip(&s->pb, size);
goto redo;
}
/* now find stream */
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->id == ((type == 9) ? 0 : 1))
goto found;
}
goto skip;
found:
if (av_new_packet(pkt, size) < 0)
return -EIO;
ret = get_buffer(&s->pb, pkt->data, size);
if (ret <= 0) {
av_free_packet(pkt);
return -EIO;
}
/* note: we need to modify the packet size here to handle the last
packet */
pkt->size = ret;
pkt->pts = pts;
pkt->stream_index = st->index;
return ret;
}
static int flv_read_close(AVFormatContext *s)
{
return 0;
}
AVInputFormat flv_iformat = {
"flv",
"flv format",
0,
flv_probe,
flv_read_header,
flv_read_packet,
flv_read_close,
.extensions = "flv",
.value = CODEC_ID_FLV1,
};
int flvdec_init(void)
{
av_register_input_format(&flv_iformat);
return 0;
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment