diff options
author | Benjamin Larsson <banan@ludd.ltu.se> | 2006-01-24 08:03:42 +0000 |
---|---|---|
committer | Benjamin Larsson <banan@ludd.ltu.se> | 2006-01-24 08:03:42 +0000 |
commit | dcfdb046eec3e72457311721a09404c3fd724609 (patch) | |
tree | a30a296478dcdbb8bcdcf52851504289730f0d07 | |
parent | 29f7ae79e739b70a70cf1931a8bdf9224859d539 (diff) | |
download | ffmpeg-dcfdb046eec3e72457311721a09404c3fd724609.tar.gz |
Fix for title field in PSP compatible mp4 files. Patch by
Olivier, oandrieu <at> gmail.com.
Originally committed as revision 4889 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavformat/movenc.c | 130 | ||||
-rw-r--r-- | tests/ffmpeg.regression.ref | 2 | ||||
-rwxr-xr-x | tests/regression.sh | 8 | ||||
-rw-r--r-- | tests/rotozoom.regression.ref | 2 |
4 files changed, 96 insertions, 46 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f58d764f73..8aed24857e 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -433,28 +433,6 @@ static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic { int decoderSpecificInfoLen; offset_t 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 = (uint8_t *) PSPAACData; - } - - if (track->enc->codec_id == CODEC_ID_MPEG4) - { - track->vosLen = 28; - track->vosData = (uint8_t *) PSPMP4Data; - } - } decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0; @@ -497,8 +475,6 @@ static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic put_buffer(pb, track->vosData, track->vosLen); } - track->vosData = vosDataBackup; - track->vosLen = vosLenBackup; // SL descriptor putDescr(pb, 0x06, 1); @@ -1182,6 +1158,68 @@ static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov, return updateSize(pb, pos); } + +static size_t ascii_to_wc (ByteIOContext *pb, char *b, size_t n) +{ + size_t i; + unsigned char c; + for (i = 0; i < n - 1; i++) { + c = b[i]; + if (! (0x20 <= c && c <= 0x7f )) + c = 0x3f; /* '?' */ + put_be16(pb, c); + } + put_be16(pb, 0x00); + return 2*n; +} + +static uint16_t language_code (char *str) +{ + return ((((str[0]-'a') & 0x1F)<<10) + (((str[1]-'a') & 0x1F)<<5) + ((str[2]-'a') & 0x1F)); +} + +static int mov_write_uuidusmt_tag (ByteIOContext *pb, AVFormatContext *s) +{ + size_t len, size; + offset_t pos, curpos; + + size = 0; + if (s->title[0]) { + pos = url_ftell(pb); + put_be32(pb, 0); /* size placeholder*/ + put_tag(pb, "uuid"); + put_tag(pb, "USMT"); + put_be32(pb, 0x21d24fce ); /* 96 bit UUID */ + put_be32(pb, 0xbb88695c ); + put_be32(pb, 0xfac9c740 ); + size += 24; + + put_be32(pb, 0); /* size placeholder*/ + put_tag(pb, "MTDT"); + put_be16(pb, 1); + size += 10; + + // Title + len = strlen(s->title)+1; + put_be16(pb, len*2+10); /* size */ + put_be32(pb, 0x01); /* type */ + put_be16(pb, language_code("und")); /* language */ + put_be16(pb, 0x01); /* ? */ + ascii_to_wc (pb, s->title, len); + size += len*2+10; + + // size + curpos = url_ftell(pb); + url_fseek(pb, pos, SEEK_SET); + put_be32(pb, size); + url_fseek(pb, pos+24, SEEK_SET); + put_be32(pb, size-24); + url_fseek(pb, curpos, SEEK_SET); + } + + return size; +} + static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov, AVFormatContext *s) { @@ -1224,6 +1262,9 @@ static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov, } } + if (mov->mode == MODE_PSP) + mov_write_uuidusmt_tag(pb, s); + else mov_write_udta_tag(pb, mov, s); return updateSize(pb, pos); @@ -1241,7 +1282,7 @@ int mov_write_mdat_tag(ByteIOContext *pb, MOVContext* mov) } /* TODO: This needs to be more general */ -int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s) +static void mov_write_ftyp_tag (ByteIOContext *pb, AVFormatContext *s) { MOVContext *mov = s->priv_data; @@ -1267,17 +1308,14 @@ int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s) 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->time_base.den) * (0x10000))/ (s->streams[0]->codec->time_base.num); - - //printf("audiorate = %d\n",AudioRate); - //printf("framerate = %d / %d = 0x%x\n",s->streams[0]->codec->time_base.den,s->streams[0]->codec->time_base.num,FrameRate); + AVCodecContext *VideoCodec = s->streams[0]->codec; + AVCodecContext *AudioCodec = s->streams[1]->codec; + int AudioRate = AudioCodec->sample_rate; + int FrameRate = ((VideoCodec->time_base.den) * (0x10000))/ (VideoCodec->time_base.num); put_be32(pb, 0x94 ); /* size */ put_tag(pb, "uuid"); @@ -1299,29 +1337,29 @@ static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s) put_be32(pb, 0x2c ); /* size */ put_tag(pb, "APRF"); /* audio */ put_be32(pb, 0x0 ); - put_be32(pb, 0x2 ); + put_be32(pb, 0x2 ); /* TrackID */ 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, AudioCodec->bit_rate / 1000); + put_be32(pb, AudioCodec->bit_rate / 1000); + put_be32(pb, AudioRate ); + put_be32(pb, AudioCodec->channels ); put_be32(pb, 0x34 ); /* size */ put_tag(pb, "VPRF"); /* video */ put_be32(pb, 0x0 ); - put_be32(pb, 0x1 ); + put_be32(pb, 0x1 ); /* TrackID */ 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 ); + put_be32(pb, VideoCodec->bit_rate / 1000); + put_be32(pb, VideoCodec->bit_rate / 1000); + put_be32(pb, FrameRate); + put_be32(pb, FrameRate); + put_be16(pb, VideoCodec->width); + put_be16(pb, VideoCodec->height); + put_be32(pb, 0x010001); /* ? */ } static int mov_write_header(AVFormatContext *s) @@ -1567,7 +1605,7 @@ static AVOutputFormat psp_oformat = { mov_write_header, mov_write_packet, mov_write_trailer, -// .flags = AVFMT_GLOBALHEADER, + .flags = AVFMT_GLOBALHEADER, }; static AVOutputFormat _3g2_oformat = { diff --git a/tests/ffmpeg.regression.ref b/tests/ffmpeg.regression.ref index 0e91f54be7..a309659afe 100644 --- a/tests/ffmpeg.regression.ref +++ b/tests/ffmpeg.regression.ref @@ -75,6 +75,8 @@ stddev: 12.32 PSNR:26.31 bytes:7602176 899452 ./data/a-mpeg4-Q.avi af59c063ed644c7dc4151a0a2debbddd *./data/out.yuv stddev: 5.69 PSNR:33.00 bytes:7602176 +cf8be7607ebef72bbe3c6c40467cb741 *./data/a-mpeg4-PSP.mp4 +407373 ./data/a-mpeg4-PSP.mov dd193b592a02864d612c64cbbf5e1258 *./data/a-error-mpeg4-adv.avi 766682 ./data/a-error-mpeg4-adv.avi e90b201e20563ec7817f5dc4276902ed *./data/out.yuv diff --git a/tests/regression.sh b/tests/regression.sh index 5f053cf644..76678127a9 100755 --- a/tests/regression.sh +++ b/tests/regression.sh @@ -56,6 +56,7 @@ else do_h263=y do_h263p=y do_mpeg4=y + do_mp4psp=y do_huffyuv=y do_mjpeg=y do_ljpeg=y @@ -339,6 +340,13 @@ do_ffmpeg $raw_dst -y -i $file -f rawvideo $raw_dst fi ################################### +if [ -n "$do_mp4psp" ] ; then +# mp4 PSP style +file=${outfile}mpeg4-PSP.mp4 +do_ffmpeg $file -y -b 768 -s 320x240 -f psp -ar 24000 -ab 32 -i $raw_src $file +fi + +################################### if [ -n "$do_error" ] ; then # damaged mpeg4 file=${outfile}error-mpeg4-adv.avi diff --git a/tests/rotozoom.regression.ref b/tests/rotozoom.regression.ref index 58bcb7cbda..42f008facf 100644 --- a/tests/rotozoom.regression.ref +++ b/tests/rotozoom.regression.ref @@ -75,6 +75,8 @@ bb7f7889f0694a1c499041f3ee5e234d *./data/a-mpeg4-Q.avi 164998 ./data/a-mpeg4-Q.avi b078f22c66083f0537bd3581509684d8 *./data/out.yuv stddev: 4.01 PSNR:36.05 bytes:7602176 +5eb32583799d9ea27d364e381f19f022 *./data/a-mpeg4-PSP.mp4 +321946 ./data/a-mpeg4-PSP.mov 74b9ddde044f90c8ee25042e9faaef68 *./data/a-error-mpeg4-adv.avi 177212 ./data/a-error-mpeg4-adv.avi 9fa0943825f364d6fb700dc75cf5d8bb *./data/out.yuv |