#define MODE_MP4 0
#define MODE_MOV 1
#define MODE_3GP 2
+#define MODE_PSP 3 // example working PSP command line:
+// ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4
typedef struct MOVIentry {
unsigned int flags, pos, size;
MOVIentry** cluster;
} MOVTrack;
-typedef struct {
+typedef struct MOVContext {
int mode;
long time;
int nb_streams;
return updateSize (pb, pos);
}
+const CodecTag codec_movaudio_tags[] = {
+ { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') },
+ { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') },
+ { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') },
+ { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') },
+ { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') },
+ { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') },
+ { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') },
+ { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') },
+ { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') },
+ { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') },
+ { 0, 0 },
+};
+
static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track)
{
int pos = url_ftell(pb);
+ int tag;
+
put_be32(pb, 0); /* size */
- if(track->enc->codec_id == CODEC_ID_PCM_MULAW)
- put_tag(pb, "ulaw");
- else if(track->enc->codec_id == CODEC_ID_PCM_ALAW)
- put_tag(pb, "alaw");
- else if(track->enc->codec_id == CODEC_ID_ADPCM_IMA_QT)
- put_tag(pb, "ima4");
- else if(track->enc->codec_id == CODEC_ID_MACE3)
- put_tag(pb, "MAC3");
- else if(track->enc->codec_id == CODEC_ID_MACE6)
- put_tag(pb, "MAC6");
- else if(track->enc->codec_id == CODEC_ID_AAC)
- put_tag(pb, "mp4a");
- else if(track->enc->codec_id == CODEC_ID_AMR_NB)
- put_tag(pb, "samr");
- else
- put_tag(pb, " ");
+ tag = track->enc->codec_tag;
+ if (!tag)
+ tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id);
+ // if no mac fcc found, try with Microsoft tags
+ if (!tag)
+ {
+ int tmp = codec_get_tag(codec_wav_tags, track->enc->codec_id);
+ tag = MKTAG('m', 's', ((tmp >> 8) & 0xff), (tmp & 0xff));
+ }
+ put_le32(pb, tag); // store it byteswapped
put_be32(pb, 0); /* Reserved */
put_be16(pb, 0); /* Reserved */
/* TODO: Currently hard-coded to 16-bit, there doesn't seem
to be a good way to get number of bits of audio */
put_be16(pb, 0x10); /* Reserved */
- put_be16(pb, 0xfffe); /* compression ID (= 0) */
- put_be16(pb, 0xac); /* packet size (= 0) */
+
+ if(track->enc->codec_id == CODEC_ID_AAC ||
+ track->enc->codec_id == CODEC_ID_MP3)
+ {
+ put_be16(pb, 0xfffe); /* compression ID (vbr)*/
+ }
+ else
+ {
+ put_be16(pb, 0); /* compression ID (= 0) */
+ }
+ put_be16(pb, 0); /* packet size (= 0) */
put_be16(pb, track->timescale); /* Time scale */
put_be16(pb, 0); /* Reserved */
static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic
{
- int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
+ int decoderSpecificInfoLen;
int pos = url_ftell(pb);
+ void *vosDataBackup=track->vosData;
+ int vosLenBackup=track->vosLen;
+
+ // we should be able to have these passed in, via vosData, then we wouldn't need to attack this routine at all
+ static const char PSPAACData[]={0x13,0x10};
+ static const char PSPMP4Data[]={0x00,0x00,0x01,0xB0,0x03,0x00,0x00,0x01,0xB5,0x09,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x20,0x00,0x84,0x5D,0x4C,0x28,0x50,0x20,0xF0,0xA3,0x1F };
+
+
+ if (track->mode == MODE_PSP) // fails on psp if this is not here
+ {
+ if (track->enc->codec_id == CODEC_ID_AAC)
+ {
+ track->vosLen = 2;
+ track->vosData = PSPAACData;
+ }
+
+ if (track->enc->codec_id == CODEC_ID_MPEG4)
+ {
+ track->vosLen = 28;
+ track->vosData = PSPMP4Data;
+ }
+ }
+
+ decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0;
put_be32(pb, 0); // size
put_tag(pb, "esds");
put_be16(pb, 0x0dd2); // Buffersize DB
// TODO: find real values for these
- put_be32(pb, 0x0002e918); // maxbitrate
- put_be32(pb, 0x00017e6b); // avg bitrate
+ put_be32(pb, track->enc->bit_rate); // maxbitrate
+ put_be32(pb, track->enc->bit_rate); // avg bitrate
if (track->vosLen)
{
put_buffer(pb, track->vosData, track->vosLen);
}
+ track->vosData = vosDataBackup;
+ track->vosLen = vosLenBackup;
+
// SL descriptor
putDescr(pb, 0x06, 1);
put_byte(pb, 0x02);
return updateSize (pb, pos);
}
+const CodecTag codec_movvideo_tags[] = {
+ { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
+ { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
+ { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
+ { CODEC_ID_H263, MKTAG('s', '2', '6', '3') },
+ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
+ { 0, 0 },
+};
+
static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track)
{
int pos = url_ftell(pb);
+ char compressor_name[32];
+ int tag;
+
put_be32(pb, 0); /* size */
- if(track->enc->codec_id == CODEC_ID_SVQ1)
- put_tag(pb, "SVQ1");
- else if(track->enc->codec_id == CODEC_ID_SVQ3)
- put_tag(pb, "SVQ3");
- else if(track->enc->codec_id == CODEC_ID_MPEG4)
- put_tag(pb, "mp4v");
- else if(track->enc->codec_id == CODEC_ID_H263)
- put_tag(pb, "s263");
- else
- put_tag(pb, " "); /* Unknown tag */
+
+ tag = track->enc->codec_tag;
+ if (!tag)
+ tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id);
+ // if no mac fcc found, try with Microsoft tags
+ if (!tag)
+ tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id);
+ put_le32(pb, tag); // store it byteswapped
put_be32(pb, 0); /* Reserved */
put_be16(pb, 0); /* Reserved */
put_be16(pb, 1); /* Data-reference index */
- put_be32(pb, 0); /* Reserved (= 02000c) */
- put_be32(pb, 0); /* Reserved ("SVis")*/
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved (400)*/
+ put_be16(pb, 0); /* Codec stream version */
+ put_be16(pb, 0); /* Codec stream revision (=0) */
+ put_tag(pb, "FFMP"); /* Vendor */
+ if(track->enc->codec_id == CODEC_ID_RAWVIDEO) {
+ put_be32(pb, 0); /* Temporal Quality */
+ put_be32(pb, 0x400); /* Spatial Quality = lossless*/
+ } else {
+ put_be32(pb, 0x200); /* Temporal Quality = normal */
+ put_be32(pb, 0x200); /* Spatial Quality = normal */
+ }
put_be16(pb, track->enc->width); /* Video width */
put_be16(pb, track->enc->height); /* Video height */
- put_be32(pb, 0x00480000); /* Reserved */
- put_be32(pb, 0x00480000); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
-
- put_be16(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
+ put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */
+ put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */
+ put_be32(pb, 0); /* Data size (= 0) */
+ put_be16(pb, 1); /* Frame count (= 1) */
+
+ memset(compressor_name,0,32);
+ if (track->enc->codec && track->enc->codec->name)
+ strncpy(compressor_name,track->enc->codec->name,31);
+ put_byte(pb, strlen(compressor_name));
+ put_buffer(pb, compressor_name, 31);
+
put_be16(pb, 0x18); /* Reserved */
put_be16(pb, 0xffff); /* Reserved */
if(track->enc->codec_id == CODEC_ID_MPEG4)
return 0x14;
}
-static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "minf");
- if(track->enc->codec_type == CODEC_TYPE_VIDEO)
- mov_write_vmhd_tag(pb);
- else
- mov_write_smhd_tag(pb);
- mov_write_dinf_tag(pb);
- mov_write_stbl_tag(pb, track);
- return updateSize(pb, pos);
-}
-
static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
{
- char *str;
+ char *descr, *hdlr, *hdlr_type;
int pos = url_ftell(pb);
+
+ if (!track) { /* no media --> data handler */
+ hdlr = "dhlr";
+ hdlr_type = "url ";
+ descr = "DataHandler";
+ } else {
+ hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
+ if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
+ hdlr_type = "vide";
+ descr = "VideoHandler";
+ } else {
+ hdlr_type = "soun";
+ descr = "SoundHandler";
+ }
+ }
+
put_be32(pb, 0); /* size */
put_tag(pb, "hdlr");
put_be32(pb, 0); /* Version & flags */
- put_be32(pb, 0); /* reserved */
- if(track->enc->codec_type == CODEC_TYPE_VIDEO)
- put_tag(pb, "vide"); /* handler type */
- else
- put_tag(pb, "soun"); /* handler type */
+ put_buffer(pb, hdlr, 4); /* handler */
+ put_tag(pb, hdlr_type); /* handler type */
put_be32(pb ,0); /* reserved */
put_be32(pb ,0); /* reserved */
put_be32(pb ,0); /* reserved */
+ put_byte(pb, strlen(descr)); /* string counter */
+ put_buffer(pb, descr, strlen(descr)); /* handler description */
+ return updateSize(pb, pos);
+}
+
+static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
+{
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "minf");
if(track->enc->codec_type == CODEC_TYPE_VIDEO)
- str = "VideoHandler";
+ mov_write_vmhd_tag(pb);
else
- str = "SoundHandler";
- put_byte(pb, strlen(str)); /* string counter */
- put_buffer(pb, str, strlen(str));
+ mov_write_smhd_tag(pb);
+ if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */
+ mov_write_hdlr_tag(pb, NULL);
+ mov_write_dinf_tag(pb);
+ mov_write_stbl_tag(pb, track);
return updateSize(pb, pos);
}
return 0x5c;
}
+// This box seems important for the psp playback ... without it the movie seems to hang
+static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track)
+{
+ int64_t maxTrackLenTemp;
+ put_be32(pb, 0x24); /* size */
+ put_tag(pb, "edts");
+ put_be32(pb, 0x1c); /* size */
+ put_tag(pb, "elst");
+ put_be32(pb, 0x0);
+ put_be32(pb, 0x1);
+
+ maxTrackLenTemp = ((int64_t)globalTimescale*(int64_t)track->trackDuration)/(int64_t)track->timescale;
+ put_be32(pb, (long)maxTrackLenTemp); /* duration ... doesn't seem to effect psp */
+
+ put_be32(pb, 0x0);
+ put_be32(pb, 0x00010000);
+ return 0x24;
+}
+
+// goes at the end of each track! ... Critical for PSP playback ("Incompatible data" without it)
+static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov)
+{
+ put_be32(pb, 0x34); /* size ... reports as 28 in mp4box! */
+ put_tag(pb, "uuid");
+ put_tag(pb, "USMT");
+ put_be32(pb, 0x21d24fce);
+ put_be32(pb, 0xbb88695c);
+ put_be32(pb, 0xfac9c740);
+ put_be32(pb, 0x1c); // another size here!
+ put_tag(pb, "MTDT");
+ put_be32(pb, 0x00010012);
+ put_be32(pb, 0x0a);
+ put_be32(pb, 0x55c40000);
+ put_be32(pb, 0x1);
+ put_be32(pb, 0x0);
+ return 0x34;
+}
+
static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
{
int pos = url_ftell(pb);
put_be32(pb, 0); /* size */
put_tag(pb, "trak");
mov_write_tkhd_tag(pb, track);
+ if (track->mode == MODE_PSP)
+ mov_write_edts_tag(pb, track); // PSP Movies require edts box
mov_write_mdia_tag(pb, track);
+ if (track->mode == MODE_PSP)
+ mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box
return updateSize(pb, pos);
}
return 0x6c;
}
+static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "hdlr");
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+ put_tag(pb, "mdir");
+ put_tag(pb, "appl");
+ put_be32(pb, 0);
+ put_be32(pb, 0);
+ put_be16(pb, 0);
+ return updateSize(pb, pos);
+}
+
+/* helper function to write a data tag with the specified string as data */
+static int mov_write_string_data_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s, const char *data)
+{
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "data");
+ put_be32(pb, 1);
+ put_be32(pb, 0);
+ put_buffer(pb, data, strlen(data));
+ return updateSize(pb, pos);
+}
+
+/* iTunes name of the song/movie */
+static int mov_write_nam_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->title[0] ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251nam");
+ mov_write_string_data_tag(pb, mov, s, s->title);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes name of the artist/performer */
+static int mov_write_ART_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->author[0] ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251ART");
+ // we use the author here as this is the only thing that we have...
+ mov_write_string_data_tag(pb, mov, s, s->author);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes name of the writer */
+static int mov_write_wrt_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->author[0] ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251wrt");
+ mov_write_string_data_tag(pb, mov, s, s->author);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes name of the album */
+static int mov_write_alb_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->album[0] ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251alb");
+ mov_write_string_data_tag(pb, mov, s, s->album);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes year */
+static int mov_write_day_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ char year[5];
+ int size = 0;
+ if ( s->year ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251day");
+ snprintf(year, 5, "%04d", s->year);
+ mov_write_string_data_tag(pb, mov, s, year);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes tool used to create the file */
+static int mov_write_too_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251too");
+ mov_write_string_data_tag(pb, mov, s, LIBAVFORMAT_IDENT);
+ return updateSize(pb, pos);
+}
+
+/* iTunes comment */
+static int mov_write_cmt_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->comment[0] ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251cmt");
+ mov_write_string_data_tag(pb, mov, s, s->comment);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes custom genre */
+static int mov_write_gen_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->genre[0] ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "\251gen");
+ mov_write_string_data_tag(pb, mov, s, s->genre);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes track number */
+static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+ if ( s->track ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "trkn");
+ {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "data");
+ put_be32(pb, 0); // 8 bytes empty
+ put_be32(pb, 0);
+ put_be16(pb, 0); // empty
+ put_be16(pb, s->track); // track number
+ put_be16(pb, 0); // total track number
+ put_be16(pb, 0); // empty
+ updateSize(pb, pos);
+ }
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
+/* iTunes meta data list */
+static int mov_write_ilst_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "ilst");
+ mov_write_nam_tag(pb, mov, s);
+ mov_write_ART_tag(pb, mov, s);
+ mov_write_wrt_tag(pb, mov, s);
+ mov_write_alb_tag(pb, mov, s);
+ mov_write_day_tag(pb, mov, s);
+ mov_write_too_tag(pb, mov, s);
+ mov_write_cmt_tag(pb, mov, s);
+ mov_write_gen_tag(pb, mov, s);
+ mov_write_trkn_tag(pb, mov, s);
+ return updateSize(pb, pos);
+}
+
+/* iTunes meta data tag */
+static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov,
+ AVFormatContext *s)
+{
+ int size = 0;
+
+ // only save meta tag if required
+ if ( s->title[0] || s->author[0] || s->album[0] || s->year ||
+ s->comment[0] || s->genre[0] || s->track ) {
+ int pos = url_ftell(pb);
+ put_be32(pb, 0); /* size */
+ put_tag(pb, "meta");
+ put_be32(pb, 0);
+ mov_write_itunes_hdlr_tag(pb, mov, s);
+ mov_write_ilst_tag(pb, mov, s);
+ size = updateSize(pb, pos);
+ }
+ return size;
+}
+
static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov,
AVFormatContext *s)
{
put_be32(pb, 0); /* size */
put_tag(pb, "udta");
+ /* iTunes meta data */
+ mov_write_meta_tag(pb, mov, s);
+
/* Requirements */
for (i=0; i<MAX_STREAMS; i++) {
if(mov->tracks[i].entry <= 0) continue;
}
/* Encoder */
+ if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT))
{
int pos = url_ftell(pb);
put_be32(pb, 0); /* size */
if ( mov->mode == MODE_3GP )
put_tag(pb, "3gp4");
+ else if ( mov->mode == MODE_PSP )
+ put_tag(pb, "MSNV");
else
put_tag(pb, "isom");
if ( mov->mode == MODE_3GP )
put_tag(pb, "3gp4");
+ else if ( mov->mode == MODE_PSP )
+ put_tag(pb, "MSNV");
else
put_tag(pb, "mp41");
return 0x14;
}
+static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s)
+{
+ int AudioRate = s->streams[1]->codec.sample_rate;
+ int FrameRate = ((s->streams[0]->codec.frame_rate) * (0x10000))/ (s->streams[0]->codec.frame_rate_base);
+
+ //printf("audiorate = %d\n",AudioRate);
+ //printf("framerate = %d / %d = 0x%x\n",s->streams[0]->codec.frame_rate,s->streams[0]->codec.frame_rate_base,FrameRate);
+
+ put_be32(pb, 0x94 ); /* size */
+ put_tag(pb, "uuid");
+ put_tag(pb, "PROF");
+
+ put_be32(pb, 0x21d24fce ); /* 96 bit UUID */
+ put_be32(pb, 0xbb88695c );
+ put_be32(pb, 0xfac9c740 );
+
+ put_be32(pb, 0x0 ); /* ? */
+ put_be32(pb, 0x3 ); /* 3 sections ? */
+
+ put_be32(pb, 0x14 ); /* size */
+ put_tag(pb, "FPRF");
+ put_be32(pb, 0x0 ); /* ? */
+ put_be32(pb, 0x0 ); /* ? */
+ put_be32(pb, 0x0 ); /* ? */
+
+ put_be32(pb, 0x2c ); /* size */
+ put_tag(pb, "APRF"); /* audio */
+ put_be32(pb, 0x0 );
+ put_be32(pb, 0x2 );
+ put_tag(pb, "mp4a");
+ put_be32(pb, 0x20f );
+ put_be32(pb, 0x0 );
+ put_be32(pb, 0x40 );
+ put_be32(pb, 0x40 );
+ put_be32(pb, AudioRate ); //24000 ... audio rate?
+ put_be32(pb, 0x2 );
+
+ put_be32(pb, 0x34 ); /* size */
+ put_tag(pb, "VPRF"); /* video */
+ put_be32(pb, 0x0 );
+ put_be32(pb, 0x1 );
+ put_tag(pb, "mp4v");
+ put_be32(pb, 0x103 );
+ put_be32(pb, 0x0 );
+ put_be32(pb, 0xc0 );
+ put_be32(pb, 0xc0 );
+ put_be32(pb, FrameRate); // was 0xefc29
+ put_be32(pb, FrameRate ); // was 0xefc29
+ put_be16(pb, s->streams[0]->codec.width);
+ put_be16(pb, s->streams[0]->codec.height);
+ put_be32(pb, 0x010001 );
+}
+
static int mov_write_header(AVFormatContext *s)
{
ByteIOContext *pb = &s->pb;
MOVContext *mov = s->priv_data;
int i;
+ for(i=0; i<s->nb_streams; i++){
+ AVCodecContext *c= &s->streams[i]->codec;
+
+ if (c->codec_type == CODEC_TYPE_VIDEO){
+ if (!codec_get_tag(codec_movvideo_tags, c->codec_id)){
+ if(!codec_get_tag(codec_bmp_tags, c->codec_id))
+ return -1;
+ else
+ av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, the file may be unplayable!\n");
+ }
+ }else if(c->codec_type == CODEC_TYPE_AUDIO){
+ if (!codec_get_tag(codec_movaudio_tags, c->codec_id)){
+ if(!codec_get_tag(codec_wav_tags, c->codec_id))
+ return -1;
+ else
+ av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, the file may be unplayable!\n");
+ }
+ }
+ }
+
/* Default mode == MP4 */
mov->mode = MODE_MP4;
if (s->oformat != NULL) {
if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP;
else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV;
+ else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP;
- if ( mov->mode == MODE_3GP || mov->mode == MODE_MP4 )
+ if ( mov->mode == MODE_3GP || mov->mode == MODE_MP4 || mov->mode == MODE_PSP )
mov_write_ftyp_tag(pb,s);
+ if ( mov->mode == MODE_PSP ) {
+ if ( s->nb_streams != 2 ) {
+ av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n");
+ return -1;
+ }
+ mov_write_uuidprof_tag(pb,s);
+ }
}
for (i=0; i<MAX_STREAMS; i++) {
return 0;
}
-static int Timestamp(void) {
- return 1067949799U+(24107*86400); //its the modification time of this line :)
-}
-
-static int mov_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
+static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
{
MOVContext *mov = s->priv_data;
ByteIOContext *pb = &s->pb;
- AVCodecContext *enc = &s->streams[stream_index]->codec;
- MOVTrack* trk = &mov->tracks[stream_index];
+ AVCodecContext *enc = &s->streams[pkt->stream_index]->codec;
+ MOVTrack* trk = &mov->tracks[pkt->stream_index];
int cl, id;
unsigned int samplesInChunk = 0;
+ int size= pkt->size;
if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
if (!size) return 0; /* Discard 0 sized packets */
int len = 0;
while (len < size && samplesInChunk < 100) {
- len += packed_size[(buf[len] >> 3) & 0x0F];
+ len += packed_size[(pkt->data[len] >> 3) & 0x0F];
samplesInChunk++;
}
}
else if(enc->codec_id == CODEC_ID_PCM_ALAW) {
samplesInChunk = size/enc->channels;
}
+ else if(enc->codec_id == CODEC_ID_PCM_S16BE || enc->codec_id == CODEC_ID_PCM_S16LE) {
+ samplesInChunk = size/(2*enc->channels);
+ }
else {
samplesInChunk = 1;
}
if ((enc->codec_id == CODEC_ID_MPEG4 || enc->codec_id == CODEC_ID_AAC)
&& trk->vosLen == 0) {
- assert(enc->extradata_size);
+// assert(enc->extradata_size);
trk->vosLen = enc->extradata_size;
trk->vosData = av_malloc(trk->vosLen);
if (mov->mdat_written == 0) {
mov_write_mdat_tag(pb, mov);
mov->mdat_written = 1;
- mov->time = Timestamp();
+ mov->time = s->timestamp;
}
trk->cluster[cl][id].pos = url_ftell(pb);
trk->cluster[cl][id].size = size;
trk->cluster[cl][id].entries = samplesInChunk;
if(enc->codec_type == CODEC_TYPE_VIDEO) {
- trk->cluster[cl][id].key_frame = enc->coded_frame->key_frame;
- if(enc->coded_frame->pict_type == FF_I_TYPE)
+ trk->cluster[cl][id].key_frame = !!(pkt->flags & PKT_FLAG_KEY);
+ if(trk->cluster[cl][id].key_frame)
trk->hasKeyframes = 1;
}
trk->enc = enc;
trk->sampleCount += samplesInChunk;
trk->mdat_size += size;
- put_buffer(pb, buf, size);
+ put_buffer(pb, pkt->data, size);
put_flush_packet(pb);
return 0;
mov_write_trailer,
};
+static AVOutputFormat psp_oformat = {
+ "psp",
+ "psp mp4 format",
+ NULL,
+ "mp4,psp",
+ sizeof(MOVContext),
+ CODEC_ID_AAC,
+ CODEC_ID_MPEG4,
+ mov_write_header,
+ mov_write_packet,
+ mov_write_trailer,
+};
+
int movenc_init(void)
{
av_register_output_format(&mov_oformat);
av_register_output_format(&_3gp_oformat);
av_register_output_format(&mp4_oformat);
+ av_register_output_format(&psp_oformat);
return 0;
}