16
|
1 /*
|
|
2 * The contents of this file are subject to the Mozilla Public
|
|
3 * License Version 1.1 (the "License"); you may not use this file
|
|
4 * except in compliance with the License. You may obtain a copy of
|
|
5 * the License at http://www.mozilla.org/MPL/
|
|
6 *
|
|
7 * Software distributed under the License is distributed on an "AS
|
|
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
9 * implied. See the License for the specific language governing
|
|
10 * rights and limitations under the License.
|
|
11 *
|
|
12 * The Original Code is MPEG4IP.
|
|
13 *
|
|
14 * The Initial Developer of the Original Code is Cisco Systems Inc.
|
|
15 * Portions created by Cisco Systems Inc. are
|
|
16 * Copyright (C) Cisco Systems Inc. 2004. All Rights Reserved.
|
|
17 *
|
|
18 * Contributor(s):
|
|
19 * Bill May wmay@cisco.com (from mp4info.cpp)
|
|
20 */
|
|
21
|
|
22 #include "mp4.h"
|
|
23 #include "mpeg4ip_getopt.h"
|
|
24
|
|
25 static void strip_filename (const char *name, char *buffer)
|
|
26 {
|
|
27 const char *suffix, *slash;
|
|
28 if (name != NULL) {
|
|
29 suffix = strrchr(name, '.');
|
|
30 slash = strrchr(name, '/');
|
|
31 if (slash == NULL) slash = name;
|
|
32 else slash++;
|
|
33 if (suffix == NULL)
|
|
34 suffix = slash + strlen(slash);
|
|
35 memcpy(buffer, slash, suffix - slash);
|
|
36 buffer[suffix - slash] = '\0';
|
|
37 } else {
|
|
38 strcpy(buffer, "out");
|
|
39 }
|
|
40 }
|
|
41
|
|
42 int main(int argc, char** argv)
|
|
43 {
|
|
44 const char* usageString =
|
|
45 "<file-name>\n";
|
|
46
|
|
47 /* begin processing command line */
|
|
48 char* ProgName = argv[0];
|
|
49 while (true) {
|
|
50 int c = -1;
|
|
51 int option_index = 0;
|
|
52 static struct option long_options[] = {
|
|
53 { "version", 0, 0, 'V' },
|
|
54 { NULL, 0, 0, 0 }
|
|
55 };
|
|
56
|
|
57 c = getopt_long_only(argc, argv, "V",
|
|
58 long_options, &option_index);
|
|
59
|
|
60 if (c == -1)
|
|
61 break;
|
|
62
|
|
63 switch (c) {
|
|
64 case '?':
|
|
65 fprintf(stderr, "usage: %s %s", ProgName, usageString);
|
|
66 exit(0);
|
|
67 case 'V':
|
|
68 fprintf(stderr, "%s - %s version %s\n", ProgName,
|
|
69 MPEG4IP_PACKAGE, MPEG4IP_VERSION);
|
|
70 exit(0);
|
|
71 default:
|
|
72 fprintf(stderr, "%s: unknown option specified, ignoring: %c\n",
|
|
73 ProgName, c);
|
|
74 }
|
|
75 }
|
|
76
|
|
77 /* check that we have at least one non-option argument */
|
|
78 if ((argc - optind) < 1) {
|
|
79 fprintf(stderr, "usage: %s %s", ProgName, usageString);
|
|
80 exit(1);
|
|
81 }
|
|
82
|
|
83 /* end processing of command line */
|
|
84 printf("%s version %s\n", ProgName, MPEG4IP_VERSION);
|
|
85
|
|
86 while (optind < argc) {
|
|
87 char *mp4FileName = argv[optind++];
|
|
88 MP4FileHandle mp4file = MP4Read(mp4FileName);
|
|
89 if (mp4file != MP4_INVALID_FILE_HANDLE) {
|
|
90 uint8_t *art;
|
|
91 uint32_t art_size;
|
|
92
|
|
93 if (MP4GetMetadataCoverArt(mp4file, &art, &art_size)) {
|
|
94 char filename[MAXPATHLEN];
|
|
95 strip_filename(mp4FileName, filename);
|
|
96 strcat(filename, ".png");
|
|
97 struct stat fstat;
|
|
98 if (stat(filename, &fstat) == 0) {
|
|
99 fprintf(stderr, "file %s already exists\n", filename);
|
|
100 } else {
|
|
101 FILE *ofile = fopen(filename, FOPEN_WRITE_BINARY);
|
|
102 if (ofile != NULL) {
|
|
103 fwrite(art, art_size, 1, ofile);
|
|
104 fclose(ofile);
|
|
105 printf("created file %s\n", filename);
|
|
106 } else {
|
|
107 fprintf(stderr, "couldn't create file %s\n", filename);
|
|
108 }
|
|
109 }
|
|
110
|
|
111 free(art);
|
|
112 } else {
|
|
113 fprintf(stderr, "art not available for %s\n", mp4FileName);
|
|
114 }
|
|
115 MP4Close(mp4file);
|
|
116 }
|
|
117 }
|
|
118
|
|
119 return(0);
|
|
120 }
|
|
121
|