Correctly set the interlaced_frame and top_field_first fields.

patch by Luca Abeni, lucabe72 =at= email =dot= it

Originally committed as revision 4961 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Luca Abeni 2006-02-08 11:54:05 +00:00 committed by Diego Biurrun
parent 064cf25155
commit ad97e414e2
1 changed files with 21 additions and 7 deletions

View File

@ -24,6 +24,11 @@
#ifdef CONFIG_MUXERS #ifdef CONFIG_MUXERS
struct frame_attributes {
int interlaced_frame;
int top_field_first;
};
static int yuv4_generate_header(AVFormatContext *s, char* buf) static int yuv4_generate_header(AVFormatContext *s, char* buf)
{ {
AVStream *st; AVStream *st;
@ -191,9 +196,10 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
char *tokstart,*tokend,*header_end; char *tokstart,*tokend,*header_end;
int i; int i;
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0,interlaced_frame=0,top_field_first=0; int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0;
enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE; enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE;
AVStream *st; AVStream *st;
struct frame_attributes *s1 = s->priv_data;
for (i=0; i<MAX_YUV4_HEADER; i++) { for (i=0; i<MAX_YUV4_HEADER; i++) {
header[i] = get_byte(pb); header[i] = get_byte(pb);
@ -206,6 +212,8 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (i == MAX_YUV4_HEADER) return -1; if (i == MAX_YUV4_HEADER) return -1;
if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC))) return -1; if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC))) return -1;
s1->interlaced_frame = 0;
s1->top_field_first = 0;
header_end = &header[i+1]; // Include space header_end = &header[i+1]; // Include space
for(tokstart = &header[strlen(Y4M_MAGIC) + 1]; tokstart < header_end; tokstart++) { for(tokstart = &header[strlen(Y4M_MAGIC) + 1]; tokstart < header_end; tokstart++) {
if (*tokstart==0x20) continue; if (*tokstart==0x20) continue;
@ -247,15 +255,15 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
case '?': case '?':
break; break;
case 'p': case 'p':
interlaced_frame=0; s1->interlaced_frame=0;
break; break;
case 't': case 't':
interlaced_frame=1; s1->interlaced_frame=1;
top_field_first=1; s1->top_field_first=1;
break; break;
case 'b': case 'b':
interlaced_frame=1; s1->interlaced_frame=1;
top_field_first=0; s1->top_field_first=0;
break; break;
case 'm': case 'm':
av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed interlaced and non-interlaced frames.\n"); av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed interlaced and non-interlaced frames.\n");
@ -338,6 +346,7 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
char header[MAX_FRAME_HEADER+1]; char header[MAX_FRAME_HEADER+1];
int packet_size, width, height; int packet_size, width, height;
AVStream *st = s->streams[0]; AVStream *st = s->streams[0];
struct frame_attributes *s1 = s->priv_data;
for (i=0; i<MAX_FRAME_HEADER; i++) { for (i=0; i<MAX_FRAME_HEADER; i++) {
header[i] = get_byte(&s->pb); header[i] = get_byte(&s->pb);
@ -359,6 +368,11 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
if (av_get_packet(&s->pb, pkt, packet_size) != packet_size) if (av_get_packet(&s->pb, pkt, packet_size) != packet_size)
return AVERROR_IO; return AVERROR_IO;
if (s->streams[0]->codec->coded_frame) {
s->streams[0]->codec->coded_frame->interlaced_frame = s1->interlaced_frame;
s->streams[0]->codec->coded_frame->top_field_first = s1->top_field_first;
}
pkt->stream_index = 0; pkt->stream_index = 0;
return 0; return 0;
} }
@ -382,7 +396,7 @@ static int yuv4_probe(AVProbeData *pd)
AVInputFormat yuv4mpegpipe_iformat = { AVInputFormat yuv4mpegpipe_iformat = {
"yuv4mpegpipe", "yuv4mpegpipe",
"YUV4MPEG pipe format", "YUV4MPEG pipe format",
0, sizeof(struct frame_attributes),
yuv4_probe, yuv4_probe,
yuv4_read_header, yuv4_read_header,
yuv4_read_packet, yuv4_read_packet,