[Ffmpeg-devel] diff patch for libavformat/movenc.c

Guillaume POIRIER poirierg
Mon Nov 21 20:54:40 CET 2005


Hi,

Cleaned up version attached (no cosmetics).
BTW: nice commented code, congratulations!

Guillaume
--
Remember, if you ever need a helping hand, it's
at the end of your arm, as you get older, remember
you have another hand:
The first is to help yourself,
the second is to help others.
-- Audrey Hepburn
-------------- next part --------------
Index: ffmpeg/libavformat/movenc.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/movenc.c,v
retrieving revision 1.44
diff -u -r1.44 movenc.c
--- ffmpeg/libavformat/movenc.c	6 Sep 2005 21:25:35 -0000	1.44
+++ ffmpeg/libavformat/movenc.c	21 Nov 2005 05:56:12 -0000
@@ -16,6 +16,12 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Changelog:
+ *
+ *   [PR-2005-11] Added support for PSP meta info and some info about PSP uuid->USMT MTDT blocks
+ *         All Rights for code added, including copyright, hereby transfered to the FFmpeg project
+ *
  */
 #include "avformat.h"
 #include "avi.h"
@@ -799,6 +805,120 @@
     return 0x34;
 }
 
+
+/*********
+
+     PSP USMT->MTDT meta info block format  (some guessing)
+     
+        - Note that clips play fine without this block.
+     
+     int32    : size of MTDT block
+     char[4]  : "MTDT"
+     int16    : Number of sub-data blocks (payloads)
+                    0x0001 EOT markers have 1 block
+                    0x0004 is the most I've seen in an information block (title, date, etc)
+     
+     Some number of data blocks, which take the form of:
+     
+        int16   : size of sub-data block
+        int32   : block type ID  (possibly 2 int16s:  unk & type )
+                    0x01 = Title
+                    0x03 = Timestamp (date format = "+%Y-%m-%d %k:%M:%S")
+                    0x04 = Creator Name
+                    0x0A = End of Track Marker
+                    0x0B = UNKNOWN (appears in info MTDT blocks)
+        int16   : ?flags? - generally 0x55c4 or 0x15c7, seen 0x2a0e, possibly font or language?)
+                    - Timestamp seems to always have 0x55c4
+        int16   : type of payload that follows?  (int, string, etc..?)
+                    - Unicode strings have 0x0001
+                    - short[] data has 0x0000
+        data[]  : Payload (strings are UTF16-BE short[] with 0x0000 terminator)
+        
+        
+        BLOCK IDs
+        
+           0x000A - Appear at end of tracks
+                
+                - flags always = 0x55c4
+                - Payload looks like: 0x0000 0x0100 0x0000 0x0000
+                
+           0x000B - Appears in meta data
+                - Payload looks like: 0x0000 0x?????  
+                - (0x???? probably flags- seen 0x1c02, 0x5cfe.  Maybe something with aspect ratio or frame rate?)
+        
+********/
+
+// PSP uses this atom to store some attributes including creator, title, and timestamp in BE UTF16(?)
+static int mov_write_uuid_tag_pspmeta_text(ByteIOContext *pb, int type, int flags, char *text) {
+
+    int size=12; /* Size of everything except the string */
+    char *cp=text;
+
+    /* Figure out size. Can't use updateSize because we need to put_be16.  Assume no string.h */
+    while(*cp!=0x00) {size+=2;cp++;}
+    
+    put_be16(pb,size); /* size placeholder */
+    
+    put_be32(pb,type);
+    put_be16(pb,flags);
+    put_be16(pb,0x0001);  /* UTF16 BE string */
+    
+    while(*text!=0x00) {
+        put_be16(pb,(0x0000|*text));
+        text++;
+    }
+    put_be16(pb,0x00); /* terminator */
+
+return size;
+}
+
+static int mov_write_uuid_tag_pspmeta(ByteIOContext *pb, MOVContext* mov, AVFormatContext *s)
+{
+    int pos, posMTDT;
+    
+    pos = url_ftell(pb);
+    put_be32(pb,0);   /* size placeholder for uuid atom size */
+
+    put_tag(pb, "uuid");  /* uuid atom tag */
+    put_tag(pb, "USMT");  /* uuid type is USMT */
+    
+    put_be32(pb, 0x21d24fce);  /* These three values are the same as the end-of-track USMT */
+    put_be32(pb, 0xbb88695c);  /* and are part of the MP4 uuid extended type.  They are    */
+    put_be32(pb, 0xfac9c740);  /* actually char[16], starting with "USMT"                  */
+    
+    posMTDT = url_ftell(pb);
+    put_be32(pb,0);  /* size placeholder for MTDT child */
+    
+    put_tag(pb, "MTDT");
+    put_be16(pb, 0x0003);  /* We're going to write 3 blocks: Title, Creator, and mysterious 0xB block */
+    
+    /* Here we begin the actual meta text info data */
+  
+    /* Title */
+    if(s->title[0]) mov_write_uuid_tag_pspmeta_text(pb,0x01,0x15c7,s->title);
+    else  mov_write_uuid_tag_pspmeta_text(pb,0x01,0x15c7,s->filename);
+    
+    /* Created by */
+    mov_write_uuid_tag_pspmeta_text(pb,0x04,0x15c7,"FFmpeg <http://ffpmeg.sourceforge.net>");
+    
+    /* Timestamp in ascii format - SKIP - because PSP seems to ignore in preference to filesystem timestamp */
+    /* mov_write_uuid_tag_pspmeta_text(pb,0x03,0x15c7,"TIMESTAMP");*/ /* Timestamp */
+
+
+    /* Write type 0x0B tag... don't know what it does */
+    put_be16(pb, 0x0c);   /* size is 12 bytes */
+    put_be32(pb, 0x0b);   /* Type is 0x0b */
+    put_be16(pb, 0x55c4); /* flags always seems to be 0x55c3 */
+    put_be16(pb, 0x0000); /* shorts follow? */
+    put_be16(pb, 0x5cfe); /* don't know what this does - probably more flags */
+    
+    
+    updateSize(pb, posMTDT);
+    
+    return updateSize(pb, pos);
+
+}
+
 static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
 {
     int pos = url_ftell(pb);
@@ -1210,7 +1330,11 @@
         }
     }
 
-    mov_write_udta_tag(pb, mov, s);
+    if(mov->mode == MODE_PSP)            // PSP uses a uuid->USMT atom (MTDT) to store meta-info
+        mov_write_uuid_tag_pspmeta(pb, mov, s);
+    else                                 // PSP does not use the udta tag
+        mov_write_udta_tag(pb, mov, s);
+
 
     return updateSize(pb, pos);
 }




More information about the ffmpeg-devel mailing list