#include "avformat.h"
#include "avi.h"
#include "riff.h"
+#include "libavutil/intreadwrite.h"
/*
* TODO:
int64_t frames_hdr_strm;
int audio_strm_length;
int packet_count;
+ int entry;
AVIIndex indexes;
} AVIStream ;
return loff;
}
-static char* avi_stream2fourcc(char* tag, int index, enum CodecType type)
+static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type)
{
tag[0] = '0';
tag[1] = '0' + index;
- if (type == CODEC_TYPE_VIDEO) {
+ if (type == AVMEDIA_TYPE_VIDEO) {
tag[2] = 'd';
tag[3] = 'c';
- } else if (type == CODEC_TYPE_SUBTITLE) {
+ } else if (type == AVMEDIA_TYPE_SUBTITLE) {
// note: this is not an official code
tag[2] = 's';
tag[3] = 'b';
}
}
-static void avi_write_info_tag2(AVFormatContext *s, const char *fourcc, const char *key1, const char *key2)
-{
- AVMetadataTag *tag= av_metadata_get(s->metadata, key1, NULL, 0);
- if(!tag && key2)
- tag= av_metadata_get(s->metadata, key2, NULL, 0);
- if(tag)
- avi_write_info_tag(s->pb, fourcc, tag->value);
-}
-
static int avi_write_counters(AVFormatContext* s, int riff_id)
{
ByteIOContext *pb = s->pb;
} else {
put_le32(pb, avist->audio_strm_length / au_ssize);
}
- if(stream->codec_type == CODEC_TYPE_VIDEO)
+ if(stream->codec_type == AVMEDIA_TYPE_VIDEO)
nb_frames = FFMAX(nb_frames, avist->packet_count);
}
if(riff_id == 1) {
int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
AVCodecContext *stream, *video_enc;
int64_t list1, list2, strh, strf;
+ AVMetadataTag *t = NULL;
for(n=0;n<s->nb_streams;n++) {
s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream));
for(n=0;n<s->nb_streams;n++) {
stream = s->streams[n]->codec;
bitrate += stream->bit_rate;
- if (stream->codec_type == CODEC_TYPE_VIDEO)
+ if (stream->codec_type == AVMEDIA_TYPE_VIDEO)
video_enc = stream;
}
/* stream generic header */
strh = ff_start_tag(pb, "strh");
switch(stream->codec_type) {
- case CODEC_TYPE_SUBTITLE:
+ case AVMEDIA_TYPE_SUBTITLE:
// XSUB subtitles behave like video tracks, other subtitles
// are not (yet) supported.
- if (stream->codec_id != CODEC_ID_XSUB) break;
- case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break;
- case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break;
-// case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break;
- case CODEC_TYPE_DATA : put_tag(pb, "dats"); break;
+ if (stream->codec_id != CODEC_ID_XSUB) {
+ av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
+ return AVERROR_PATCHWELCOME;
+ }
+ case AVMEDIA_TYPE_VIDEO: put_tag(pb, "vids"); break;
+ case AVMEDIA_TYPE_AUDIO: put_tag(pb, "auds"); break;
+// case AVMEDIA_TYPE_TEXT : put_tag(pb, "txts"); break;
+ case AVMEDIA_TYPE_DATA : put_tag(pb, "dats"); break;
}
- if(stream->codec_type == CODEC_TYPE_VIDEO ||
+ if(stream->codec_type == AVMEDIA_TYPE_VIDEO ||
stream->codec_id == CODEC_ID_XSUB)
put_le32(pb, stream->codec_tag);
else
put_le32(pb, 0); /* length, XXX: filled later */
/* suggested buffer size */ //FIXME set at the end to largest chunk
- if(stream->codec_type == CODEC_TYPE_VIDEO)
+ if(stream->codec_type == AVMEDIA_TYPE_VIDEO)
put_le32(pb, 1024 * 1024);
- else if(stream->codec_type == CODEC_TYPE_AUDIO)
+ else if(stream->codec_type == AVMEDIA_TYPE_AUDIO)
put_le32(pb, 12 * 1024);
else
put_le32(pb, 0);
put_le16(pb, stream->height);
ff_end_tag(pb, strh);
- if(stream->codec_type != CODEC_TYPE_DATA){
+ if(stream->codec_type != AVMEDIA_TYPE_DATA){
strf = ff_start_tag(pb, "strf");
switch(stream->codec_type) {
- case CODEC_TYPE_SUBTITLE:
+ case AVMEDIA_TYPE_SUBTITLE:
// XSUB subtitles behave like video tracks, other subtitles
// are not (yet) supported.
if (stream->codec_id != CODEC_ID_XSUB) break;
- case CODEC_TYPE_VIDEO:
+ case AVMEDIA_TYPE_VIDEO:
ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0);
break;
- case CODEC_TYPE_AUDIO:
+ case AVMEDIA_TYPE_AUDIO:
if (ff_put_wav_header(pb, stream) < 0) {
return -1;
}
return -1;
}
ff_end_tag(pb, strf);
+ if ((t = av_metadata_get(s->streams[i]->metadata, "strn", NULL, 0))) {
+ avi_write_info_tag(s->pb, t->key, t->value);
+ t = NULL;
+ }
+ //FIXME a limitation of metadata conversion system
+ else if ((t = av_metadata_get(s->streams[i]->metadata, "INAM", NULL, 0))) {
+ avi_write_info_tag(s->pb, "strn", t->value);
+ t = NULL;
+ }
}
if (!url_is_streamed(pb)) {
ff_end_tag(pb, avist->indexes.indx_start);
}
- if( stream->codec_type == CODEC_TYPE_VIDEO
+ if( stream->codec_type == AVMEDIA_TYPE_VIDEO
&& s->streams[i]->sample_aspect_ratio.num>0
&& s->streams[i]->sample_aspect_ratio.den>0){
int vprp= ff_start_tag(pb, "vprp");
list2 = ff_start_tag(pb, "LIST");
put_tag(pb, "INFO");
- avi_write_info_tag2(s, "INAM", "Title", NULL);
- avi_write_info_tag2(s, "IART", "Artist", "Author");
- avi_write_info_tag2(s, "ICOP", "Copyright", NULL);
- avi_write_info_tag2(s, "ICMT", "Comment", NULL);
- avi_write_info_tag2(s, "IPRD", "Album", NULL);
- avi_write_info_tag2(s, "IGNR", "Genre", NULL);
- avi_write_info_tag2(s, "IPRT", "Track", NULL);
- if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
- avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT);
+ for (i = 0; *ff_avi_tags[i]; i++) {
+ if ((t = av_metadata_get(s->metadata, ff_avi_tags[i], NULL, AV_METADATA_MATCH_CASE)))
+ avi_write_info_tag(s->pb, t->key, t->value);
+ }
ff_end_tag(pb, list2);
/* some padding for easier tag editing */
char tag[5];
if (!url_is_streamed(pb)) {
+ AVIStream *avist;
AVIIentry* ie = 0, *tie;
- int entry[MAX_STREAMS];
int empty, stream_id = -1;
idx_chunk = ff_start_tag(pb, "idx1");
- memset(&entry[0], 0, sizeof(entry));
+ for(i=0; i<s->nb_streams; i++){
+ avist= s->streams[i]->priv_data;
+ avist->entry=0;
+ }
+
do {
empty = 1;
for (i=0; i<s->nb_streams; i++) {
- AVIStream *avist= s->streams[i]->priv_data;
- if (avist->indexes.entry <= entry[i])
+ avist= s->streams[i]->priv_data;
+ if (avist->indexes.entry <= avist->entry)
continue;
- tie = avi_get_ientry(&avist->indexes, entry[i]);
+ tie = avi_get_ientry(&avist->indexes, avist->entry);
if (empty || tie->pos < ie->pos) {
ie = tie;
stream_id = i;
empty = 0;
}
if (!empty) {
+ avist= s->streams[stream_id]->priv_data;
avi_stream2fourcc(&tag[0], stream_id,
s->streams[stream_id]->codec->codec_type);
put_tag(pb, &tag[0]);
put_le32(pb, ie->flags);
put_le32(pb, ie->pos);
put_le32(pb, ie->len);
- entry[stream_id]++;
+ avist->entry++;
}
} while (!empty);
ff_end_tag(pb, idx_chunk);
}
avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
- if(pkt->flags&PKT_FLAG_KEY)
+ if(pkt->flags&AV_PKT_FLAG_KEY)
flags = 0x10;
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
avist->audio_strm_length += size;
}
AVCodecContext *stream = s->streams[n]->codec;
AVIStream *avist= s->streams[n]->priv_data;
- if (stream->codec_type == CODEC_TYPE_VIDEO) {
+ if (stream->codec_type == AVMEDIA_TYPE_VIDEO) {
if (nb_frames < avist->packet_count)
nb_frames = avist->packet_count;
} else {
avi_write_trailer,
.codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
.flags= AVFMT_VARIABLE_FPS,
+ .metadata_conv = ff_avi_metadata_conv,
};