]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/raw.c
* providing MPEG codecs with a generic fields in AVFrame to use.
[ffmpeg] / libavformat / raw.c
index f32f5eb59990db7b05eecf705243c18caa6bb85d..3ce79c49dacc08a39d47e6380690176da43e3db6 100644 (file)
@@ -18,6 +18,7 @@
  */
 #include "avformat.h"
 
+#ifdef CONFIG_ENCODERS
 /* simple formats */
 static int raw_write_header(struct AVFormatContext *s)
 {
@@ -25,7 +26,7 @@ static int raw_write_header(struct AVFormatContext *s)
 }
 
 static int raw_write_packet(struct AVFormatContext *s, int stream_index,
-                           unsigned char *buf, int size, int force_pts)
+                           const uint8_t *buf, int size, int64_t pts)
 {
     put_buffer(&s->pb, buf, size);
     put_flush_packet(&s->pb);
@@ -36,6 +37,7 @@ static int raw_write_trailer(struct AVFormatContext *s)
 {
     return 0;
 }
+#endif //CONFIG_ENCODERS
 
 /* raw input */
 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
@@ -61,9 +63,11 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
             st->codec.channels = ap->channels;
             break;
         case CODEC_TYPE_VIDEO:
-            st->codec.frame_rate = ap->frame_rate;
+            st->codec.frame_rate      = ap->frame_rate;
+            st->codec.frame_rate_base = ap->frame_rate_base;
             st->codec.width = ap->width;
             st->codec.height = ap->height;
+           st->codec.pix_fmt = ap->pix_fmt;
             break;
         default:
             return -1;
@@ -103,22 +107,6 @@ static int raw_read_close(AVFormatContext *s)
     return 0;
 }
 
-/* mp3 read */
-static int mp3_read_header(AVFormatContext *s,
-                           AVFormatParameters *ap)
-{
-    AVStream *st;
-
-    st = av_new_stream(s, 0);
-    if (!st)
-        return AVERROR_NOMEM;
-
-    st->codec.codec_type = CODEC_TYPE_AUDIO;
-    st->codec.codec_id = CODEC_ID_MP2;
-    /* the parameters will be extracted from the compressed bitstream */
-    return 0;
-}
-
 /* ac3 read */
 static int ac3_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
@@ -151,9 +139,11 @@ static int video_read_header(AVFormatContext *s,
     /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
     if (st->codec.codec_id == CODEC_ID_MJPEG || st->codec.codec_id == CODEC_ID_MPEG4) {
         if (ap) {
-            st->codec.frame_rate = ap->frame_rate;
+            st->codec.frame_rate      = ap->frame_rate;
+            st->codec.frame_rate_base = ap->frame_rate_base;
         } else {
-            st->codec.frame_rate = 25 * FRAME_RATE_BASE;
+            st->codec.frame_rate      = 25;
+            st->codec.frame_rate_base = 1;
         }
     }
     return 0;
@@ -190,30 +180,20 @@ static int mpegvideo_probe(AVProbeData *p)
     return 0;
 }
 
-AVInputFormat mp3_iformat = {
-    "mp3",
-    "MPEG audio",
-    0,
-    NULL,
-    mp3_read_header,
-    raw_read_packet,
-    raw_read_close,
-    .extensions = "mp2,mp3", /* XXX: use probe */
-};
-
-AVOutputFormat mp2_oformat = {
-    "mp2",
-    "MPEG audio layer 2",
-    "audio/x-mpeg",
-    "mp2,mp3",
-    0,
-    CODEC_ID_MP2,
-    0,
-    raw_write_header,
-    raw_write_packet,
-    raw_write_trailer,
-};
+static int h263_probe(AVProbeData *p)
+{
+    int code;
+    const uint8_t *d;
 
+    if (p->buf_size < 6)
+        return 0;
+    d = p->buf;
+    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
+    if (code == 0x20) {
+        return 50;
+    }
+    return 0;
+}
 
 AVInputFormat ac3_iformat = {
     "ac3",
@@ -226,6 +206,7 @@ AVInputFormat ac3_iformat = {
     .extensions = "ac3",
 };
 
+#ifdef CONFIG_ENCODERS
 AVOutputFormat ac3_oformat = {
     "ac3",
     "raw ac3",
@@ -238,7 +219,21 @@ AVOutputFormat ac3_oformat = {
     raw_write_packet,
     raw_write_trailer,
 };
+#endif //CONFIG_ENCODERS
+
+AVInputFormat h263_iformat = {
+    "h263",
+    "raw h263",
+    0,
+    h263_probe,
+    video_read_header,
+    raw_read_packet,
+    raw_read_close,
+//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
+    .value = CODEC_ID_H263,
+};
 
+#ifdef CONFIG_ENCODERS
 AVOutputFormat h263_oformat = {
     "h263",
     "raw h263",
@@ -251,6 +246,7 @@ AVOutputFormat h263_oformat = {
     raw_write_packet,
     raw_write_trailer,
 };
+#endif //CONFIG_ENCODERS
 
 AVInputFormat m4v_iformat = {
     "m4v",
@@ -264,6 +260,7 @@ AVInputFormat m4v_iformat = {
     .value = CODEC_ID_MPEG4,
 };
 
+#ifdef CONFIG_ENCODERS
 AVOutputFormat m4v_oformat = {
     "m4v",
     "raw MPEG4 video format",
@@ -276,6 +273,34 @@ AVOutputFormat m4v_oformat = {
     raw_write_packet,
     raw_write_trailer,
 };
+#endif //CONFIG_ENCODERS
+
+AVInputFormat h264_iformat = {
+    "h264",
+    "raw H264 video format",
+    0,
+    NULL /*mpegvideo_probe*/,
+    video_read_header,
+    raw_read_packet,
+    raw_read_close,
+    .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe
+    .value = CODEC_ID_H264,
+};
+
+#ifdef CONFIG_ENCODERS
+AVOutputFormat h264_oformat = {
+    "h264",
+    "raw H264 video format",
+    NULL,
+    "h264",
+    0,
+    CODEC_ID_NONE,
+    CODEC_ID_H264,
+    raw_write_header,
+    raw_write_packet,
+    raw_write_trailer,
+};
+#endif //CONFIG_ENCODERS
 
 AVInputFormat mpegvideo_iformat = {
     "mpegvideo",
@@ -288,6 +313,7 @@ AVInputFormat mpegvideo_iformat = {
     .value = CODEC_ID_MPEG1VIDEO,
 };
 
+#ifdef CONFIG_ENCODERS
 AVOutputFormat mpeg1video_oformat = {
     "mpeg1video",
     "MPEG video",
@@ -300,6 +326,7 @@ AVOutputFormat mpeg1video_oformat = {
     raw_write_packet,
     raw_write_trailer,
 };
+#endif //CONFIG_ENCODERS
 
 AVInputFormat mjpeg_iformat = {
     "mjpeg",
@@ -313,6 +340,7 @@ AVInputFormat mjpeg_iformat = {
     .value = CODEC_ID_MJPEG,
 };
 
+#ifdef CONFIG_ENCODERS
 AVOutputFormat mjpeg_oformat = {
     "mjpeg",
     "MJPEG video",
@@ -325,8 +353,25 @@ AVOutputFormat mjpeg_oformat = {
     raw_write_packet,
     raw_write_trailer,
 };
+#endif //CONFIG_ENCODERS
 
 /* pcm formats */
+#if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS)
+
+#define PCMDEF(name, long_name, ext, codec) \
+AVInputFormat pcm_ ## name ## _iformat = {\
+    #name,\
+    long_name,\
+    0,\
+    NULL,\
+    raw_read_header,\
+    raw_read_packet,\
+    raw_read_close,\
+    .extensions = ext,\
+    .value = codec,\
+};
+
+#else
 
 #define PCMDEF(name, long_name, ext, codec) \
 AVInputFormat pcm_ ## name ## _iformat = {\
@@ -353,6 +398,7 @@ AVOutputFormat pcm_ ## name ## _oformat = {\
     raw_write_packet,\
     raw_write_trailer,\
 };
+#endif //CONFIG_ENCODERS
 
 #ifdef WORDS_BIGENDIAN
 #define BE_DEF(s) s
@@ -395,21 +441,9 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
     width = st->codec.width;
     height = st->codec.height;
 
-    switch(st->codec.pix_fmt) {
-    case PIX_FMT_YUV420P:
-        packet_size = (width * height * 3) / 2;
-        break;
-    case PIX_FMT_YUV422:
-        packet_size = (width * height * 2);
-        break;
-    case PIX_FMT_BGR24:
-    case PIX_FMT_RGB24:
-        packet_size = (width * height * 3);
-        break;
-    default:
+    packet_size = avpicture_get_size(st->codec.pix_fmt, width, height);
+    if (packet_size < 0)
         av_abort();
-        break;
-    }
 
     if (av_new_packet(pkt, packet_size) < 0)
         return -EIO;
@@ -441,6 +475,7 @@ AVInputFormat rawvideo_iformat = {
     .value = CODEC_ID_RAWVIDEO,
 };
 
+#ifdef CONFIG_ENCODERS
 AVOutputFormat rawvideo_oformat = {
     "rawvideo",
     "raw video format",
@@ -453,10 +488,12 @@ AVOutputFormat rawvideo_oformat = {
     raw_write_packet,
     raw_write_trailer,
 };
+#endif //CONFIG_ENCODERS
 
+#ifdef CONFIG_ENCODERS
 static int null_write_packet(struct AVFormatContext *s, 
                              int stream_index,
-                             unsigned char *buf, int size, int force_pts)
+                             const uint8_t *buf, int size, int64_t pts)
 {
     return 0;
 }
@@ -478,19 +515,28 @@ AVOutputFormat null_oformat = {
     raw_write_trailer,
     .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE,
 };
+#endif //CONFIG_ENCODERS
+
+#ifndef CONFIG_ENCODERS
+#define av_register_output_format(format)
+#endif
+#ifndef CONFIG_DECODERS
+#define av_register_input_format(format)
+#endif
 
 int raw_init(void)
 {
-    av_register_input_format(&mp3_iformat);
-    av_register_output_format(&mp2_oformat);
-    
     av_register_input_format(&ac3_iformat);
     av_register_output_format(&ac3_oformat);
 
+    av_register_input_format(&h263_iformat);
     av_register_output_format(&h263_oformat);
     
     av_register_input_format(&m4v_iformat);
     av_register_output_format(&m4v_oformat);
+    
+    av_register_input_format(&h264_iformat);
+    av_register_output_format(&h264_oformat);
 
     av_register_input_format(&mpegvideo_iformat);
     av_register_output_format(&mpeg1video_oformat);