[PATCH 3/3] Define ff_nut_raw_video_pixel_format_tags and make nut muxer and demuxer recognize the extended nut tags associated to rawvideo pixel formats.
Stefano Sabatini
stefano.sabatini-lala
Mon Mar 22 23:22:40 CET 2010
---
libavformat/nut.c | 21 +++++++++++++++++++++
libavformat/nut.h | 3 +++
libavformat/nutdec.c | 13 ++++++++++++-
libavformat/nutenc.c | 20 +++++++++++++++++---
4 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/libavformat/nut.c b/libavformat/nut.c
index d969bbc..5de3642 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -22,6 +22,27 @@
#include "libavutil/tree.h"
#include "nut.h"
+const PixelFormatTag ff_nut_raw_video_pixel_format_tags[] = {
+ { PIX_FMT_RGB555LE, MKTAG('R', 'G', 'B', 15) },
+ { PIX_FMT_BGR555LE, MKTAG('B', 'G', 'R', 15) },
+ { PIX_FMT_RGB565LE, MKTAG('R', 'G', 'B', 16) },
+ { PIX_FMT_BGR565LE, MKTAG('B', 'G', 'R', 16) },
+
+ { PIX_FMT_RGB555BE, MKTAG( 15, 'B', 'G', 'R') },
+ { PIX_FMT_BGR555BE, MKTAG( 15, 'R', 'G', 'B') },
+ { PIX_FMT_RGB565BE, MKTAG( 16, 'B', 'G', 'R') },
+ { PIX_FMT_BGR565BE, MKTAG( 16, 'R', 'G', 'B') },
+
+ { PIX_FMT_RGBA, MKTAG('R', 'G', 'B', 'A') },
+ { PIX_FMT_BGRA, MKTAG('B', 'G', 'R', 'A') },
+ { PIX_FMT_ABGR, MKTAG('A', 'B', 'G', 'R') },
+ { PIX_FMT_ARGB, MKTAG('A', 'R', 'G', 'B') },
+ { PIX_FMT_RGB24, MKTAG('R', 'G', 'B', 24) },
+ { PIX_FMT_BGR24, MKTAG('B', 'G', 'R', 24) },
+
+ { PIX_FMT_NONE, 0 },
+};
+
const AVCodecTag ff_nut_subtitle_tags[] = {
{ CODEC_ID_TEXT , MKTAG('U', 'T', 'F', '8') },
{ CODEC_ID_SSA , MKTAG('S', 'S', 'A', 0 ) },
diff --git a/libavformat/nut.h b/libavformat/nut.h
index 8d96952..4e9f9ca 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -25,6 +25,7 @@
//#include <limits.h>
//#include "libavutil/adler32.h"
//#include "libavcodec/mpegaudio.h"
+#include "libavcodec/raw.h"
#include "avformat.h"
#include "riff.h"
#include "metadata.h"
@@ -98,6 +99,8 @@ typedef struct {
struct AVTreeNode *syncpoints;
} NUTContext;
+extern const PixelFormatTag ff_nut_raw_video_pixel_format_tags[];
+
extern const AVCodecTag ff_nut_subtitle_tags[];
typedef struct {
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 6a2d2f8..39188e2 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -316,7 +316,18 @@ static int decode_stream_header(NUTContext *nut){
{
case 0:
st->codec->codec_type = CODEC_TYPE_VIDEO;
- st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp);
+ if (!(st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp))) {
+ const PixelFormatTag *tags = ff_nut_raw_video_pixel_format_tags;
+ while (tags->pix_fmt >= 0) {
+ if (tmp == tags->fourcc) {
+ st->codec->pix_fmt = tags->pix_fmt;
+ break;
+ }
+ tags++;
+ }
+ if (st->codec->pix_fmt != PIX_FMT_NONE)
+ st->codec->codec_id = CODEC_ID_RAWVIDEO;
+ }
break;
case 1:
st->codec->codec_type = CODEC_TYPE_AUDIO;
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index e06a85f..d46bc1b 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -392,6 +392,8 @@ static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, int i){
AVCodecContext *codec = st->codec;
+ int codec_tag;
+
put_v(bc, i);
switch(codec->codec_type){
case CODEC_TYPE_VIDEO: put_v(bc, 0); break;
@@ -400,9 +402,21 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st,
default : put_v(bc, 3); break;
}
put_v(bc, 4);
- if (codec->codec_tag){
- put_le32(bc, codec->codec_tag);
- }else
+ if (!(codec_tag = codec->codec_tag)) {
+ if (codec->codec_type == CODEC_TYPE_VIDEO) {
+ const PixelFormatTag *tags = ff_nut_raw_video_pixel_format_tags;
+ while (tags->pix_fmt >= 0) {
+ if (tags->pix_fmt == codec->pix_fmt) {
+ codec_tag = tags->fourcc;
+ break;
+ }
+ tags++;
+ }
+ }
+ }
+ if (codec_tag)
+ put_le32(bc, codec_tag);
+ else
return -1;
put_v(bc, nut->stream[i].time_base - nut->time_base);
--
1.7.0
--V0207lvV8h4k8FAm--
More information about the ffmpeg-devel
mailing list