aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Shaposhnik <roman@shaposhnik.org>2003-10-18 03:19:44 +0000
committerRoman Shaposhnik <roman@shaposhnik.org>2003-10-18 03:19:44 +0000
commit2744ca9ac919d63fb8a5948c21d2e943cdd04e3d (patch)
treeb5f7a6640f9ab5b09d059569e47714f1b932c08d
parenta573cc27f51ad93d8453bbe1d06f0e59ba49f838 (diff)
downloadffmpeg-2744ca9ac919d63fb8a5948c21d2e943cdd04e3d.tar.gz
* 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
-rw-r--r--ffmpeg.c3
-rw-r--r--libavcodec/avcodec.h14
-rw-r--r--libavcodec/dv.c3
-rw-r--r--libavformat/yuv4mpeg.c134
4 files changed, 82 insertions, 72 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index c5239d4a46..a160e8abd7 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -608,8 +608,11 @@ static void do_video_out(AVFormatContext *s,
/* raw pictures are written as AVPicture structure to
avoid any copies. We support temorarily the older
method. */
+ AVFrame* old_frame = enc->coded_frame;
+ enc->coded_frame = dec->coded_frame;
av_write_frame(s, ost->index,
(uint8_t *)final_picture, sizeof(AVPicture));
+ enc->coded_frame = old_frame;
} else {
AVFrame big_picture;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fe40ce90c7..90834f1ffe 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -399,6 +399,20 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
* \
*/\
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_MPEG2 1
diff --git a/libavcodec/dv.c b/libavcodec/dv.c
index b5ee875f64..419d2de524 100644
--- a/libavcodec/dv.c
+++ b/libavcodec/dv.c
@@ -149,6 +149,7 @@ static int dvvideo_init(AVCodecContext *avctx)
/* FIXME: I really don't think this should be here */
if (dv_codec_profile(avctx))
avctx->pix_fmt = dv_codec_profile(avctx)->pix_fmt;
+ avctx->coded_frame = &s->picture;
return 0;
}
@@ -853,6 +854,8 @@ static int dvvideo_decode_frame(AVCodecContext *avctx,
fprintf(stderr, "get_buffer() failed\n");
return -1;
}
+ s->picture.interlaced_frame = 1;
+ s->picture.bottom_field_first = 1;
/* for each DIF segment */
mb_pos_ptr = s->sys->video_place;
diff --git a/libavformat/yuv4mpeg.c b/libavformat/yuv4mpeg.c
index 3e712c9323..c6e062051b 100644
--- a/libavformat/yuv4mpeg.c
+++ b/libavformat/yuv4mpeg.c
@@ -23,94 +23,51 @@
#define Y4M_LINE_MAX 256
#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;
int width, height;
- int raten, rated, aspectn, aspectd, n;
- char buf[Y4M_LINE_MAX+1];
+ int raten, rated, aspectn, aspectd, n, i;
+ char inter;
- if (s->nb_streams != 1)
- return -EIO;
-
st = s->streams[0];
width = st->codec.width;
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);
-#else
- {
- int gcd, fps, fps1;
-
- 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;
- }
+
+ for (i=0; i<sizeof(SAR)/sizeof(SAR[0])-1; i++) {
+ if (ABS(st->codec.aspect_ratio -
+ (float)SAR[i].n/SAR[i].d * (float)width/height) < 0.05)
+ break;
}
-#endif
+ aspectn = SAR[i].n;
+ aspectd = SAR[i].d;
- aspectn = 1;
- aspectd = 1; /* ffmpeg always uses a 1:1 aspect ratio */ //FIXME not true anymore
+ inter = 'p'; /* progressive is the default */
+ 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 */
- 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,
width,
height,
raten, rated,
- "p", /* ffmpeg seems to only output progressive video */
- aspectn, aspectd);
- if (n < 0) {
- fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
- return -EIO;
- } else {
- put_buffer(&s->pb, buf, strlen(buf));
- }
- return 0;
+ inter,
+ aspectn, aspectd,
+ (st->codec.pix_fmt == PIX_FMT_YUV411P) ? " XYSCSS=411" : "");
+
+ return n;
}
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];
ByteIOContext *pb = &s->pb;
AVPicture *picture;
+ int* first_pkt = s->priv_data;
int width, height;
int i, m;
+ char buf2[Y4M_LINE_MAX+1];
char buf1[20];
uint8_t *ptr, *ptr1, *ptr2;
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 */
+
m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
put_buffer(pb, buf1, strlen(buf1));
@@ -155,6 +126,25 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index,
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)
{
return 0;
@@ -165,7 +155,7 @@ AVOutputFormat yuv4mpegpipe_oformat = {
"YUV4MPEG pipe format",
"",
"yuv4mpeg",
- 0,
+ sizeof(int),
CODEC_ID_NONE,
CODEC_ID_RAWVIDEO,
yuv4_write_header,