# HG changeset patch # User michaelni # Date 1060075951 0 # Node ID 2438e76dde67de1ccb2e9a1c017d3f7c736ce3f6 # Parent b3b056122bd8bc7ec9cc9c6b6dd2847697d6a28c yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III ) diff -r b3b056122bd8 -r 2438e76dde67 allformats.c --- a/allformats.c Thu Jul 24 23:37:40 2003 +0000 +++ b/allformats.c Tue Aug 05 09:32:31 2003 +0000 @@ -54,7 +54,7 @@ #ifdef AMR_NB amr_init(); #endif - av_register_output_format(&yuv4mpegpipe_oformat); + yuv4mpeg_init(); #ifdef CONFIG_VORBIS ogg_init(); diff -r b3b056122bd8 -r 2438e76dde67 avformat.h --- a/avformat.h Thu Jul 24 23:37:40 2003 +0000 +++ b/avformat.h Tue Aug 05 09:32:31 2003 +0000 @@ -328,6 +328,9 @@ /* raw.c */ int raw_init(void); +/* yuv4mpeg.c */ +int yuv4mpeg_init(void); + /* ogg.c */ int ogg_init(void); diff -r b3b056122bd8 -r 2438e76dde67 yuv4mpeg.c --- a/yuv4mpeg.c Thu Jul 24 23:37:40 2003 +0000 +++ b/yuv4mpeg.c Tue Aug 05 09:32:31 2003 +0000 @@ -173,4 +173,101 @@ .flags = AVFMT_RAWPICTURE, }; +#define MAX_YUV4_HEADER 50 +#define MAX_FRAME_HEADER 10 +static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + char header[MAX_YUV4_HEADER+1]; + int i; + ByteIOContext *pb = &s->pb; + int width, height, raten, rated, aspectn, aspectd; + char lacing; + AVStream *st; + + for (i=0; istreams[0]; + st->codec.width = width; + st->codec.height = height; + av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1); + st->codec.frame_rate = raten; + st->codec.frame_rate_base = rated; + st->codec.pix_fmt = PIX_FMT_YUV420P; + st->codec.codec_type = CODEC_TYPE_VIDEO; + st->codec.codec_id = CODEC_ID_RAWVIDEO; + + return 0; +} + +static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + int i; + char header[MAX_FRAME_HEADER+1]; + int packet_size, ret, width, height; + AVStream *st = s->streams[0]; + + for (i=0; ipb); + if (header[i] == '\n') { + header[i+1] = 0; + break; + } + } + if (i == MAX_FRAME_HEADER) return -1; + if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1; + + width = st->codec.width; + height = st->codec.height; + + packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); + if (packet_size < 0) + av_abort(); + + if (av_new_packet(pkt, packet_size) < 0) + return -EIO; + + pkt->stream_index = 0; + ret = get_buffer(&s->pb, pkt->data, pkt->size); + if (ret != pkt->size) { + av_free_packet(pkt); + return -EIO; + } else { + return 0; + } +} + +static int yuv4_read_close(AVFormatContext *s) +{ + return 0; +} + +AVInputFormat yuv4mpegpipe_iformat = { + "yuv4mpegpipe", + "YUV4MPEG pipe format", + 0, + NULL, + yuv4_read_header, + yuv4_read_packet, + yuv4_read_close, + .extensions = "yuv4mpeg" +}; + +int yuv4mpeg_init(void) +{ + av_register_input_format(&yuv4mpegpipe_iformat); + av_register_output_format(&yuv4mpegpipe_oformat); + return 0; +} +