Commit 2744ca9a authored by Roman Shaposhnik's avatar Roman Shaposhnik

* providing MPEG codecs with a generic fields in AVFrame to use.

    * fixing YUV4MPEG format.

    * fixing a bug in DV codec where coded_frame was not set.

Originally committed as revision 2396 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent a573cc27
...@@ -608,8 +608,11 @@ static void do_video_out(AVFormatContext *s, ...@@ -608,8 +608,11 @@ static void do_video_out(AVFormatContext *s,
/* raw pictures are written as AVPicture structure to /* raw pictures are written as AVPicture structure to
avoid any copies. We support temorarily the older avoid any copies. We support temorarily the older
method. */ method. */
AVFrame* old_frame = enc->coded_frame;
enc->coded_frame = dec->coded_frame;
av_write_frame(s, ost->index, av_write_frame(s, ost->index,
(uint8_t *)final_picture, sizeof(AVPicture)); (uint8_t *)final_picture, sizeof(AVPicture));
enc->coded_frame = old_frame;
} else { } else {
AVFrame big_picture; AVFrame big_picture;
......
...@@ -399,6 +399,20 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG, ...@@ -399,6 +399,20 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
* \ * \
*/\ */\
int qscale_type;\ int qscale_type;\
\
/**\
* The content of the picture is interlaced.\
* - encoding: set by user\
* - decoding: set by lavc (default 0)\
*/\
int interlaced_frame;\
\
/**\
* if the content is interlaced, is bottom field displayed first.\
* - encoding: set by user\
* - decoding: set by lavc (default 0)\
*/\
int bottom_field_first;\
#define FF_QSCALE_TYPE_MPEG1 0 #define FF_QSCALE_TYPE_MPEG1 0
#define FF_QSCALE_TYPE_MPEG2 1 #define FF_QSCALE_TYPE_MPEG2 1
......
...@@ -149,6 +149,7 @@ static int dvvideo_init(AVCodecContext *avctx) ...@@ -149,6 +149,7 @@ static int dvvideo_init(AVCodecContext *avctx)
/* FIXME: I really don't think this should be here */ /* FIXME: I really don't think this should be here */
if (dv_codec_profile(avctx)) if (dv_codec_profile(avctx))
avctx->pix_fmt = dv_codec_profile(avctx)->pix_fmt; avctx->pix_fmt = dv_codec_profile(avctx)->pix_fmt;
avctx->coded_frame = &s->picture;
return 0; return 0;
} }
...@@ -853,6 +854,8 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, ...@@ -853,6 +854,8 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
fprintf(stderr, "get_buffer() failed\n"); fprintf(stderr, "get_buffer() failed\n");
return -1; return -1;
} }
s->picture.interlaced_frame = 1;
s->picture.bottom_field_first = 1;
/* for each DIF segment */ /* for each DIF segment */
mb_pos_ptr = s->sys->video_place; mb_pos_ptr = s->sys->video_place;
......
...@@ -23,94 +23,51 @@ ...@@ -23,94 +23,51 @@
#define Y4M_LINE_MAX 256 #define Y4M_LINE_MAX 256
#ifdef CONFIG_ENCODERS #ifdef CONFIG_ENCODERS
static int yuv4_write_header(AVFormatContext *s)
static struct { int n; int d;} SAR[] = {{10, 11}, /* 4:3 NTSC */
{59, 54}, /* 4:3 PAL */
{40, 33}, /* 16:9 NTSC */
{118, 81}, /* 16:9 PAL */
{ 1, 1}};/* should always be the last */
static int yuv4_generate_header(AVFormatContext *s, char* buf)
{ {
AVStream *st; AVStream *st;
int width, height; int width, height;
int raten, rated, aspectn, aspectd, n; int raten, rated, aspectn, aspectd, n, i;
char buf[Y4M_LINE_MAX+1]; char inter;
if (s->nb_streams != 1)
return -EIO;
st = s->streams[0]; st = s->streams[0];
width = st->codec.width; width = st->codec.width;
height = st->codec.height; height = st->codec.height;
#if 1
//this is identical to the code below for exact fps
av_reduce(&raten, &rated, st->codec.frame_rate, st->codec.frame_rate_base, (1UL<<31)-1); av_reduce(&raten, &rated, st->codec.frame_rate, st->codec.frame_rate_base, (1UL<<31)-1);
#else
{ for (i=0; i<sizeof(SAR)/sizeof(SAR[0])-1; i++) {
int gcd, fps, fps1; if (ABS(st->codec.aspect_ratio -
(float)SAR[i].n/SAR[i].d * (float)width/height) < 0.05)
fps = st->codec.frame_rate;
fps1 = (((float)fps / st->codec.frame_rate_base) * 1000);
/* Sorry about this messy code, but mpeg2enc is very picky about
* the framerates it accepts. */
switch(fps1) {
case 23976:
raten = 24000; /* turn the framerate into a ratio */
rated = 1001;
break;
case 29970:
raten = 30000;
rated = 1001;
break;
case 25000:
raten = 25;
rated = 1;
break;
case 30000:
raten = 30;
rated = 1;
break;
case 24000:
raten = 24;
rated = 1;
break;
case 50000:
raten = 50;
rated = 1;
break;
case 59940:
raten = 60000;
rated = 1001;
break;
case 60000:
raten = 60;
rated = 1;
break;
default:
raten = st->codec.frame_rate; /* this setting should work, but often doesn't */
rated = st->codec.frame_rate_base;
gcd= av_gcd(raten, rated);
raten /= gcd;
rated /= gcd;
break; break;
} }
} aspectn = SAR[i].n;
#endif aspectd = SAR[i].d;
aspectn = 1; inter = 'p'; /* progressive is the default */
aspectd = 1; /* ffmpeg always uses a 1:1 aspect ratio */ //FIXME not true anymore if (st->codec.coded_frame && st->codec.coded_frame->interlaced_frame) {
inter = st->codec.coded_frame->bottom_field_first ? 'b' : 't';
}
/* construct stream header, if this is the first frame */ /* construct stream header, if this is the first frame */
n = snprintf(buf, sizeof(buf), "%s W%d H%d F%d:%d I%s A%d:%d\n", n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
Y4M_MAGIC, Y4M_MAGIC,
width, width,
height, height,
raten, rated, raten, rated,
"p", /* ffmpeg seems to only output progressive video */ inter,
aspectn, aspectd); aspectn, aspectd,
if (n < 0) { (st->codec.pix_fmt == PIX_FMT_YUV411P) ? " XYSCSS=411" : "");
fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
return -EIO; return n;
} else {
put_buffer(&s->pb, buf, strlen(buf));
}
return 0;
} }
static int yuv4_write_packet(AVFormatContext *s, int stream_index, static int yuv4_write_packet(AVFormatContext *s, int stream_index,
...@@ -119,14 +76,28 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index, ...@@ -119,14 +76,28 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index,
AVStream *st = s->streams[stream_index]; AVStream *st = s->streams[stream_index];
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
AVPicture *picture; AVPicture *picture;
int* first_pkt = s->priv_data;
int width, height; int width, height;
int i, m; int i, m;
char buf2[Y4M_LINE_MAX+1];
char buf1[20]; char buf1[20];
uint8_t *ptr, *ptr1, *ptr2; uint8_t *ptr, *ptr1, *ptr2;
picture = (AVPicture *)buf; picture = (AVPicture *)buf;
/* for the first packet we have to output the header as well */
if (*first_pkt) {
*first_pkt = 0;
if (yuv4_generate_header(s, buf2) < 0) {
fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
return -EIO;
} else {
put_buffer(pb, buf2, strlen(buf2));
}
}
/* construct frame header */ /* construct frame header */
m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC); m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
put_buffer(pb, buf1, strlen(buf1)); put_buffer(pb, buf1, strlen(buf1));
...@@ -155,6 +126,25 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index, ...@@ -155,6 +126,25 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index,
return 0; return 0;
} }
static int yuv4_write_header(AVFormatContext *s)
{
int* first_pkt = s->priv_data;
if (s->nb_streams != 1)
return -EIO;
if (s->streams[0]->codec.pix_fmt == PIX_FMT_YUV411P) {
fprintf(stderr, "Warning: generating non-standard 4:1:1 YUV stream, some mjpegtools might not work.\n");
}
else if (s->streams[0]->codec.pix_fmt != PIX_FMT_YUV420P) {
fprintf(stderr, "ERROR: yuv4mpeg only handles 4:2:0, 4:1:1 YUV data. Use -pix_fmt to select one.\n");
return -EIO;
}
*first_pkt = 1;
return 0;
}
static int yuv4_write_trailer(AVFormatContext *s) static int yuv4_write_trailer(AVFormatContext *s)
{ {
return 0; return 0;
...@@ -165,7 +155,7 @@ AVOutputFormat yuv4mpegpipe_oformat = { ...@@ -165,7 +155,7 @@ AVOutputFormat yuv4mpegpipe_oformat = {
"YUV4MPEG pipe format", "YUV4MPEG pipe format",
"", "",
"yuv4mpeg", "yuv4mpeg",
0, sizeof(int),
CODEC_ID_NONE, CODEC_ID_NONE,
CODEC_ID_RAWVIDEO, CODEC_ID_RAWVIDEO,
yuv4_write_header, yuv4_write_header,
......
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