]> git.pld-linux.org Git - packages/php-ffmpeg.git/blob - tests-metadata-api.patch
add todo and notes
[packages/php-ffmpeg.git] / tests-metadata-api.patch
1 http://cakebox.homeunix.net/doc/ffmpeg/APIchanges
2
3 2009-03-01 - r17682 - lavf 52.31.0 - Generic metadata API
4   Introduce a new metadata API (see av_metadata_get() and friends).
5   The old API is now deprecated and should not be used anymore. This especially
6   includes the following structure fields:
7     - AVFormatContext.title
8     - AVFormatContext.author
9     - AVFormatContext.copyright
10     - AVFormatContext.comment
11     - AVFormatContext.album
12     - AVFormatContext.year
13     - AVFormatContext.track
14     - AVFormatContext.genre
15     - AVStream.language
16     - AVStream.filename
17     - AVProgram.provider_name
18     - AVProgram.name
19     - AVChapter.title
20
21 /usr/include/libavformat/avformat.h :
22 #if LIBAVFORMAT_VERSION_INT < (53<<16)
23     char title[512];
24     char author[512];
25     char copyright[512];
26     char comment[512];
27     char album[512];
28     int year;  /**< ID3 year, 0 if none */
29     int track; /**< track number, 0 if none */
30     char genre[32]; /**< ID3 genre */
31 #endif
32
33 // to dump tags:
34 AVMetadataTag *tag = NULL;
35 while((tag=av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX))) {
36     printf("  %-16s: %s\n", tag->key, tag->value);
37 }
38
39 --- ffmpeg-php-0.6.0//ffmpeg_movie.c    2011-01-05 21:48:29.247659645 +0200
40 +++ ffmpeg-php-metadata_api/ffmpeg_movie.c    2011-01-05 21:47:10.709759988 +0200
41 @@ -71,6 +71,7 @@
42  
43  typedef struct {
44      AVFormatContext *fmt_ctx;
45 +    AVMetadata *metadata;
46      AVCodecContext *codec_ctx[MAX_STREAMS];
47      int64_t last_pts;
48      int frame_number;
49 @@ -200,6 +201,7 @@
50      ffmovie_ctx = persistent ? malloc(sizeof(ff_movie_context)) : 
51                                 emalloc(sizeof(ff_movie_context));
52      ffmovie_ctx->fmt_ctx = NULL;
53 +    ffmovie_ctx->metadata = NULL;
54      ffmovie_ctx->frame_number = 0;
55  
56      for (i = 0; i < MAX_STREAMS; i++) {
57 @@ -268,6 +270,29 @@
58  }
59  /* }}} */
60  
61 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
62 +/* {{{ _php_get_metadata()
63 + */
64 +static char* _php_get_metadata_tag(ff_movie_context *ffmovie_ctx, const char *key)
65 +{
66 +    // on first access do av_metadata_conv
67 +    if (ffmovie_ctx->metadata == NULL) {
68 +        av_metadata_conv(ffmovie_ctx->fmt_ctx, NULL, ffmovie_ctx->fmt_ctx->iformat->metadata_conv);
69 +        ffmovie_ctx->metadata = ffmovie_ctx->fmt_ctx->metadata;
70 +    }
71 +
72 +    // can metadata be missing?
73 +    if (!ffmovie_ctx->metadata) {
74 +        return NULL;
75 +    }
76 +
77 +    // get from metadata
78 +    AVMetadataTag *tag = av_metadata_get(ffmovie_ctx->metadata, key, NULL, 0);
79 +    return tag ? tag->value : NULL;
80 +}
81 +#endif
82 +
83 +/* }}} */
84  
85  /* {{{ proto object ffmpeg_movie(string filename) 
86     Constructor for ffmpeg_movie objects
87 @@ -529,9 +554,16 @@
88      ff_movie_context *ffmovie_ctx;
89  
90      GET_MOVIE_RESOURCE(ffmovie_ctx);
91 -    
92 +
93 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
94 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "comment");
95 +    if (tag && *tag) {
96 +        RETURN_STRINGL(tag, strlen(tag), 1);
97 +    }
98 +#else
99      RETURN_STRINGL(ffmovie_ctx->fmt_ctx->comment,
100              strlen(ffmovie_ctx->fmt_ctx->comment), 1);
101 +#endif
102  }
103  /* }}} */
104  
105 @@ -545,8 +577,15 @@
106      
107      GET_MOVIE_RESOURCE(ffmovie_ctx);
108  
109 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
110 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "title");
111 +    if (tag && *tag) {
112 +        RETURN_STRINGL(tag, strlen(tag), 1);
113 +    }
114 +#else
115      RETURN_STRINGL(ffmovie_ctx->fmt_ctx->title,
116              strlen(ffmovie_ctx->fmt_ctx->title), 1);
117 +#endif
118  }
119  /* }}} */
120  
121 @@ -560,8 +599,15 @@
122      
123      GET_MOVIE_RESOURCE(ffmovie_ctx);
124  
125 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
126 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "artist");
127 +    if (tag && *tag) {
128 +        RETURN_STRINGL(tag, strlen(tag), 1);
129 +    }
130 +#else
131      RETURN_STRINGL(ffmovie_ctx->fmt_ctx->author,
132              strlen(ffmovie_ctx->fmt_ctx->author), 1);
133 +#endif
134  }
135  /* }}} */
136  
137 @@ -574,8 +620,15 @@
138      
139      GET_MOVIE_RESOURCE(ffmovie_ctx);
140  
141 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
142 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "copyright");
143 +    if (tag && *tag) {
144 +        RETURN_STRINGL(tag, strlen(tag), 1);
145 +    }
146 +#else
147      RETURN_STRINGL(ffmovie_ctx->fmt_ctx->copyright,
148              strlen(ffmovie_ctx->fmt_ctx->copyright), 1);
149 +#endif
150  }
151  /* }}} */
152  
153 @@ -589,8 +642,15 @@
154      
155      GET_MOVIE_RESOURCE(ffmovie_ctx);
156  
157 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
158 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "album");
159 +    if (tag && *tag) {
160 +        RETURN_STRINGL(tag, strlen(tag), 1);
161 +    }
162 +#else
163      RETURN_STRINGL(ffmovie_ctx->fmt_ctx->album,
164              strlen(ffmovie_ctx->fmt_ctx->album), 1);
165 +#endif
166  }
167  /* }}} */
168  
169 @@ -603,8 +663,15 @@
170      
171      GET_MOVIE_RESOURCE(ffmovie_ctx);
172  
173 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
174 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "genre");
175 +    if (tag && *tag) {
176 +        RETURN_STRINGL(tag, strlen(tag), 1);
177 +    }
178 +#else
179      RETURN_STRINGL(ffmovie_ctx->fmt_ctx->genre,
180              strlen(ffmovie_ctx->fmt_ctx->genre), 1);
181 +#endif
182  }
183  /* }}} */
184  
185 @@ -618,7 +685,14 @@
186      
187      GET_MOVIE_RESOURCE(ffmovie_ctx);
188      
189 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
190 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "track");
191 +    if (tag && *tag) {
192 +        RETURN_STRINGL(tag, strlen(tag), 1);
193 +    }
194 +#else
195      RETURN_LONG(ffmovie_ctx->fmt_ctx->track);
196 +#endif
197  }
198  /* }}} */
199  
200 @@ -631,7 +705,16 @@
201      
202      GET_MOVIE_RESOURCE(ffmovie_ctx);
203      
204 +#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52, 31, 0)
205 +    // "id3v2 tag TYER is not considered in generic format
206 +    // ideally "date" should be used here and extract year from it for full compatability
207 +    char *tag = _php_get_metadata_tag(ffmovie_ctx, "TYER");
208 +    if (tag && *tag) {
209 +        RETURN_STRINGL(tag, strlen(tag), 1);
210 +    }
211 +#else
212      RETURN_LONG(ffmovie_ctx->fmt_ctx->year);
213 +#endif
214  }
215  /* }}} */
216  
This page took 0.089643 seconds and 3 git commands to generate.