Browse code

create and populate "tools" directory

Originally committed as revision 9634 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2007/07/14 06:33:24
Showing 14 changed files
... ...
@@ -102,10 +102,10 @@ version.h:
102 102
 output_example$(EXESUF): output_example.o .libs
103 103
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(EXTRALIBS)
104 104
 
105
-qt-faststart$(EXESUF): qt-faststart.c
105
+tools/qt-faststart$(EXESUF): qt-faststart.c
106 106
 	$(CC) $(CFLAGS) $< -o $@
107 107
 
108
-cws2fws$(EXESUF): cws2fws.c
108
+tools/cws2fws$(EXESUF): cws2fws.c
109 109
 	$(CC) $(CFLAGS) $< -o $@ -lz
110 110
 
111 111
 ffplay.o: CFLAGS += $(SDL_CFLAGS)
112 112
deleted file mode 100755
... ...
@@ -1,9 +0,0 @@
1
-#!/bin/sh
2
-sed 's/unsigned//g' |\
3
- sed 's/enum//g' |\
4
- egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\
5
- sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\
6
- sed 's/AVRATIONAL_M/INT_M/g'|\
7
- sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\
8
- sed 's/FLOAT_M/FLT_M/g'|\
9
- sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g'
10 1
deleted file mode 100755
... ...
@@ -1,11 +0,0 @@
1
-#!/bin/sh
2
-sed '/^+[^+]/!s/	/TaBBaT/g' |\
3
- expand -t `seq -s , 9 8 200` |\
4
- sed 's/TaBBaT/	/g' |\
5
- sed '/^+[^+]/s/ * $//' |\
6
- tr -d '\015' |\
7

                
8

                
9

                
10
- tr -d '\n' |\
11

                
... ...
@@ -1994,6 +1994,7 @@ if enabled source_path_used; then
1994 1994
          libavutil \
1995 1995
          libswscale \
1996 1996
          tests \
1997
+         tools \
1997 1998
          vhook \
1998 1999
          "
1999 2000
     FILES="\
2000 2001
deleted file mode 100644
... ...
@@ -1,130 +0,0 @@
1
-/*
2
- * cws2fws by Alex Beregszaszi
3
- * This file is placed in the public domain.
4
- * Use the program however you see fit.
5
- *
6
- * This utility converts compressed Macromedia Flash files to uncompressed ones.
7
- */
8
-
9
-#include <sys/stat.h>
10
-#include <fcntl.h>
11
-#include <stdio.h>
12
-#include <stdlib.h>
13
-#include <unistd.h>
14
-#include <zlib.h>
15
-
16
-#ifdef DEBUG
17
-#define dbgprintf printf
18
-#else
19
-#define dbgprintf
20
-#endif
21
-
22
-int main(int argc, char *argv[])
23
-{
24
-    int fd_in, fd_out, comp_len, uncomp_len, i, last_out;
25
-    char buf_in[1024], buf_out[65536];
26
-    z_stream zstream;
27
-    struct stat statbuf;
28
-
29
-    if (argc < 3)
30
-    {
31
-        printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
32
-        exit(1);
33
-    }
34
-
35
-    fd_in = open(argv[1], O_RDONLY);
36
-    if (fd_in < 0)
37
-    {
38
-        perror("Error while opening: ");
39
-        exit(1);
40
-    }
41
-
42
-    fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644);
43
-    if (fd_out < 0)
44
-    {
45
-        perror("Error while opening: ");
46
-        close(fd_in);
47
-        exit(1);
48
-    }
49
-
50
-    if (read(fd_in, &buf_in, 8) != 8)
51
-    {
52
-        printf("Header error\n");
53
-        close(fd_in);
54
-        close(fd_out);
55
-        exit(1);
56
-    }
57
-
58
-    if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S')
59
-    {
60
-        printf("Not a compressed flash file\n");
61
-        exit(1);
62
-    }
63
-
64
-    fstat(fd_in, &statbuf);
65
-    comp_len = statbuf.st_size;
66
-    uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
67
-
68
-    printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4);
69
-
70
-    // write out modified header
71
-    buf_in[0] = 'F';
72
-    write(fd_out, &buf_in, 8);
73
-
74
-    zstream.zalloc = NULL;
75
-    zstream.zfree = NULL;
76
-    zstream.opaque = NULL;
77
-    inflateInit(&zstream);
78
-
79
-    for (i = 0; i < comp_len-8;)
80
-    {
81
-        int ret, len = read(fd_in, &buf_in, 1024);
82
-
83
-        dbgprintf("read %d bytes\n", len);
84
-
85
-        last_out = zstream.total_out;
86
-
87
-        zstream.next_in = &buf_in[0];
88
-        zstream.avail_in = len;
89
-        zstream.next_out = &buf_out[0];
90
-        zstream.avail_out = 65536;
91
-
92
-        ret = inflate(&zstream, Z_SYNC_FLUSH);
93
-        if (ret != Z_STREAM_END && ret != Z_OK)
94
-        {
95
-            printf("Error while decompressing: %d\n", ret);
96
-            inflateEnd(&zstream);
97
-            exit(1);
98
-        }
99
-
100
-        dbgprintf("a_in: %d t_in: %d a_out: %d t_out: %d -- %d out\n",
101
-            zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out,
102
-            zstream.total_out-last_out);
103
-
104
-        write(fd_out, &buf_out, zstream.total_out-last_out);
105
-
106
-        i += len;
107
-
108
-        if (ret == Z_STREAM_END || ret == Z_BUF_ERROR)
109
-            break;
110
-    }
111
-
112
-    if (zstream.total_out != uncomp_len-8)
113
-    {
114
-        printf("Size mismatch (%d != %d), updating header...\n",
115
-            zstream.total_out, uncomp_len-8);
116
-
117
-        buf_in[0] = (zstream.total_out+8) & 0xff;
118
-        buf_in[1] = (zstream.total_out+8 >> 8) & 0xff;
119
-        buf_in[2] = (zstream.total_out+8 >> 16) & 0xff;
120
-        buf_in[3] = (zstream.total_out+8 >> 24) & 0xff;
121
-
122
-        lseek(fd_out, 4, SEEK_SET);
123
-        write(fd_out, &buf_in, 4);
124
-    }
125
-
126
-    inflateEnd(&zstream);
127
-    close(fd_in);
128
-    close(fd_out);
129
-    return 0;
130
-}
131 1
deleted file mode 100644
... ...
@@ -1,117 +0,0 @@
1
-/*
2
- * Copyright (c) 2005 Francois Revol
3
- *
4
- * This file is part of FFmpeg.
5
- *
6
- * FFmpeg is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * FFmpeg is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with FFmpeg; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
-#include <avformat.h>
22
-#include <limits.h>
23
-#include <fcntl.h>
24
-#include <stdio.h>
25
-#include <stdlib.h>
26
-#include <string.h>
27
-#include <unistd.h>
28
-
29
-#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin"
30
-
31
-static int usage(int ret)
32
-{
33
-    fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n");
34
-    fprintf(stderr, "each packet is dumped in its own file named like `basename file.ext`_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n");
35
-    fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n");
36
-    fprintf(stderr, "-n\twrite No file at all, only demux.\n");
37
-    fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n");
38
-    return ret;
39
-}
40
-
41
-int main(int argc, char **argv)
42
-{
43
-    char fntemplate[PATH_MAX];
44
-    char pktfilename[PATH_MAX];
45
-    AVFormatContext *fctx;
46
-    AVPacket pkt;
47
-    int64_t pktnum = 0;
48
-    int64_t maxpkts = 0;
49
-    int donotquit = 0;
50
-    int nowrite = 0;
51
-    int err;
52
-
53
-    if ((argc > 1) && !strncmp(argv[1], "-", 1)) {
54
-        if (strchr(argv[1], 'w'))
55
-            donotquit = 1;
56
-        if (strchr(argv[1], 'n'))
57
-            nowrite = 1;
58
-        argv++;
59
-        argc--;
60
-    }
61
-    if (argc < 2)
62
-        return usage(1);
63
-    if (argc > 2)
64
-        maxpkts = atoi(argv[2]);
65
-    strncpy(fntemplate, argv[1], PATH_MAX-1);
66
-    if (strrchr(argv[1], '/'))
67
-        strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1);
68
-    if (strrchr(fntemplate, '.'))
69
-        *strrchr(fntemplate, '.') = '\0';
70
-    if (strchr(fntemplate, '%')) {
71
-        fprintf(stderr, "can't use filenames containing '%%'\n");
72
-        return usage(1);
73
-    }
74
-    if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) {
75
-        fprintf(stderr, "filename too long\n");
76
-        return usage(1);
77
-    }
78
-    strcat(fntemplate, PKTFILESUFF);
79
-    printf("FNTEMPLATE: '%s'\n", fntemplate);
80
-
81
-    // register all file formats
82
-    av_register_all();
83
-
84
-    err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL);
85
-    if (err < 0) {
86
-        fprintf(stderr, "av_open_input_file: error %d\n", err);
87
-        return 1;
88
-    }
89
-
90
-    err = av_find_stream_info(fctx);
91
-    if (err < 0) {
92
-        fprintf(stderr, "av_find_stream_info: error %d\n", err);
93
-        return 1;
94
-    }
95
-
96
-    av_init_packet(&pkt);
97
-
98
-    while ((err = av_read_frame(fctx, &pkt)) >= 0) {
99
-        int fd;
100
-        snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_');
101
-        printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_');
102
-        //printf("open(\"%s\")\n", pktfilename);
103
-        if (!nowrite) {
104
-            fd = open(pktfilename, O_WRONLY|O_CREAT, 0644);
105
-            write(fd, pkt.data, pkt.size);
106
-            close(fd);
107
-        }
108
-        pktnum++;
109
-        if (maxpkts && (pktnum >= maxpkts))
110
-            break;
111
-    }
112
-
113
-    while (donotquit)
114
-        sleep(60);
115
-
116
-    return 0;
117
-}
118 1
deleted file mode 100644
... ...
@@ -1,311 +0,0 @@
1
-/*
2
- * qt-faststart.c, v0.1
3
- * by Mike Melanson (melanson@pcisys.net)
4
- * This file is placed in the public domain. Use the program however you
5
- * see fit.
6
- *
7
- * This utility rearranges a Quicktime file such that the moov atom
8
- * is in front of the data, thus facilitating network streaming.
9
- *
10
- * Compile this program using:
11
- *  make qt-faststart
12
- * Invoke the program with:
13
- *  qt-faststart <infile.mov> <outfile.mov>
14
- *
15
- * Notes: Quicktime files can come in many configurations of top-level
16
- * atoms. This utility stipulates that the very last atom in the file needs
17
- * to be a moov atom. When given such a file, this utility will rearrange
18
- * the top-level atoms by shifting the moov atom from the back of the file
19
- * to the front, and patch the chunk offsets along the way. This utility
20
- * presently only operates on uncompressed moov atoms.
21
- */
22
-
23
-#include <stdio.h>
24
-#include <stdlib.h>
25
-#include <inttypes.h>
26
-
27
-#ifdef __MINGW32__
28
-#define fseeko(x,y,z)  fseeko64(x,y,z)
29
-#define ftello(x)      ftello64(x)
30
-#endif
31
-
32
-#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
33
-#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
34
-                  (((uint8_t*)(x))[1] << 16) | \
35
-                  (((uint8_t*)(x))[2] << 8) | \
36
-                   ((uint8_t*)(x))[3])
37
-#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \
38
-                  ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \
39
-                  ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \
40
-                  ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \
41
-                  ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \
42
-                  ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \
43
-                  ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \
44
-                  ((uint64_t)((uint8_t*)(x))[7]))
45
-
46
-#define BE_FOURCC( ch0, ch1, ch2, ch3 )             \
47
-        ( (uint32_t)(unsigned char)(ch3) |          \
48
-        ( (uint32_t)(unsigned char)(ch2) << 8 ) |   \
49
-        ( (uint32_t)(unsigned char)(ch1) << 16 ) |  \
50
-        ( (uint32_t)(unsigned char)(ch0) << 24 ) )
51
-
52
-#define QT_ATOM BE_FOURCC
53
-/* top level atoms */
54
-#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e')
55
-#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k')
56
-#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't')
57
-#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v')
58
-#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't')
59
-#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p')
60
-#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e')
61
-#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T')
62
-#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p')
63
-
64
-#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v')
65
-#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o')
66
-#define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
67
-
68
-#define ATOM_PREAMBLE_SIZE 8
69
-#define COPY_BUFFER_SIZE 1024
70
-
71
-int main(int argc, char *argv[])
72
-{
73
-    FILE *infile;
74
-    FILE *outfile;
75
-    unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
76
-    uint32_t atom_type = 0;
77
-    uint64_t atom_size = 0;
78
-    uint64_t last_offset;
79
-    unsigned char *moov_atom;
80
-    unsigned char *ftyp_atom = 0;
81
-    uint64_t moov_atom_size;
82
-    uint64_t ftyp_atom_size = 0;
83
-    uint64_t i, j;
84
-    uint32_t offset_count;
85
-    uint64_t current_offset;
86
-    uint64_t start_offset = 0;
87
-    unsigned char copy_buffer[COPY_BUFFER_SIZE];
88
-    int bytes_to_copy;
89
-
90
-    if (argc != 3) {
91
-        printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n");
92
-        return 0;
93
-    }
94
-
95
-    infile = fopen(argv[1], "rb");
96
-    if (!infile) {
97
-        perror(argv[1]);
98
-        return 1;
99
-    }
100
-
101
-    /* traverse through the atoms in the file to make sure that 'moov' is
102
-     * at the end */
103
-    while (!feof(infile)) {
104
-        if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
105
-            break;
106
-        }
107
-        atom_size = (uint32_t)BE_32(&atom_bytes[0]);
108
-        atom_type = BE_32(&atom_bytes[4]);
109
-
110
-        if ((atom_type != FREE_ATOM) &&
111
-            (atom_type != JUNK_ATOM) &&
112
-            (atom_type != MDAT_ATOM) &&
113
-            (atom_type != MOOV_ATOM) &&
114
-            (atom_type != PNOT_ATOM) &&
115
-            (atom_type != SKIP_ATOM) &&
116
-            (atom_type != WIDE_ATOM) &&
117
-            (atom_type != PICT_ATOM) &&
118
-            (atom_type != FTYP_ATOM)) {
119
-            printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n");
120
-            break;
121
-        }
122
-
123
-        /* keep ftyp atom */
124
-        if (atom_type == FTYP_ATOM) {
125
-            ftyp_atom_size = atom_size;
126
-            ftyp_atom = malloc(ftyp_atom_size);
127
-            if (!ftyp_atom) {
128
-                printf ("could not allocate 0x%llX byte for ftyp atom\n",
129
-                        atom_size);
130
-                fclose(infile);
131
-                return 1;
132
-            }
133
-            fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
134
-            if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
135
-                perror(argv[1]);
136
-                free(ftyp_atom);
137
-                fclose(infile);
138
-                return 1;
139
-            }
140
-            start_offset = ftello(infile);
141
-            continue;
142
-        }
143
-
144
-        /* 64-bit special case */
145
-        if (atom_size == 1) {
146
-            if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
147
-                break;
148
-            }
149
-            atom_size = BE_64(&atom_bytes[0]);
150
-            fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR);
151
-        } else {
152
-            fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR);
153
-        }
154
-    }
155
-
156
-    if (atom_type != MOOV_ATOM) {
157
-        printf ("last atom in file was not a moov atom\n");
158
-        fclose(infile);
159
-        return 0;
160
-    }
161
-
162
-    /* moov atom was, in fact, the last atom in the chunk; load the whole
163
-     * moov atom */
164
-    fseeko(infile, -atom_size, SEEK_END);
165
-    last_offset = ftello(infile);
166
-    moov_atom_size = atom_size;
167
-    moov_atom = malloc(moov_atom_size);
168
-    if (!moov_atom) {
169
-        printf ("could not allocate 0x%llX byte for moov atom\n",
170
-            atom_size);
171
-        fclose(infile);
172
-        return 1;
173
-    }
174
-    if (fread(moov_atom, atom_size, 1, infile) != 1) {
175
-        perror(argv[1]);
176
-        free(moov_atom);
177
-        fclose(infile);
178
-        return 1;
179
-    }
180
-
181
-    /* this utility does not support compressed atoms yet, so disqualify
182
-     * files with compressed QT atoms */
183
-    if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
184
-        printf ("this utility does not support compressed moov atoms yet\n");
185
-        free(moov_atom);
186
-        fclose(infile);
187
-        return 1;
188
-    }
189
-
190
-    /* close; will be re-opened later */
191
-    fclose(infile);
192
-
193
-    /* crawl through the moov chunk in search of stco or co64 atoms */
194
-    for (i = 4; i < moov_atom_size - 4; i++) {
195
-        atom_type = BE_32(&moov_atom[i]);
196
-        if (atom_type == STCO_ATOM) {
197
-            printf (" patching stco atom...\n");
198
-            atom_size = BE_32(&moov_atom[i - 4]);
199
-            if (i + atom_size - 4 > moov_atom_size) {
200
-                printf (" bad atom size\n");
201
-                free(moov_atom);
202
-                return 1;
203
-            }
204
-            offset_count = BE_32(&moov_atom[i + 8]);
205
-            for (j = 0; j < offset_count; j++) {
206
-                current_offset = BE_32(&moov_atom[i + 12 + j * 4]);
207
-                current_offset += moov_atom_size;
208
-                moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF;
209
-                moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF;
210
-                moov_atom[i + 12 + j * 4 + 2] = (current_offset >>  8) & 0xFF;
211
-                moov_atom[i + 12 + j * 4 + 3] = (current_offset >>  0) & 0xFF;
212
-            }
213
-            i += atom_size - 4;
214
-        } else if (atom_type == CO64_ATOM) {
215
-            printf (" patching co64 atom...\n");
216
-            atom_size = BE_32(&moov_atom[i - 4]);
217
-            if (i + atom_size - 4 > moov_atom_size) {
218
-                printf (" bad atom size\n");
219
-                free(moov_atom);
220
-                return 1;
221
-            }
222
-            offset_count = BE_32(&moov_atom[i + 8]);
223
-            for (j = 0; j < offset_count; j++) {
224
-                current_offset = BE_64(&moov_atom[i + 12 + j * 8]);
225
-                current_offset += moov_atom_size;
226
-                moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF;
227
-                moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF;
228
-                moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF;
229
-                moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF;
230
-                moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF;
231
-                moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF;
232
-                moov_atom[i + 12 + j * 8 + 6] = (current_offset >>  8) & 0xFF;
233
-                moov_atom[i + 12 + j * 8 + 7] = (current_offset >>  0) & 0xFF;
234
-            }
235
-            i += atom_size - 4;
236
-        }
237
-    }
238
-
239
-    /* re-open the input file and open the output file */
240
-    infile = fopen(argv[1], "rb");
241
-    if (!infile) {
242
-        perror(argv[1]);
243
-        free(moov_atom);
244
-        return 1;
245
-    }
246
-
247
-    if (start_offset > 0) { /* seek after ftyp atom */
248
-        fseeko(infile, start_offset, SEEK_SET);
249
-        last_offset -= start_offset;
250
-    }
251
-
252
-    outfile = fopen(argv[2], "wb");
253
-    if (!outfile) {
254
-        perror(argv[2]);
255
-        fclose(outfile);
256
-        free(moov_atom);
257
-        return 1;
258
-    }
259
-
260
-    /* dump the same ftyp atom */
261
-    if (ftyp_atom_size > 0) {
262
-        printf (" writing ftyp atom...\n");
263
-        if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) {
264
-            perror(argv[2]);
265
-            goto error_out;
266
-        }
267
-    }
268
-
269
-    /* dump the new moov atom */
270
-    printf (" writing moov atom...\n");
271
-    if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {
272
-        perror(argv[2]);
273
-        goto error_out;
274
-    }
275
-
276
-    /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
277
-    printf (" copying rest of file...\n");
278
-    while (last_offset) {
279
-        if (last_offset > COPY_BUFFER_SIZE)
280
-            bytes_to_copy = COPY_BUFFER_SIZE;
281
-        else
282
-            bytes_to_copy = last_offset;
283
-
284
-        if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) {
285
-            perror(argv[1]);
286
-            goto error_out;
287
-        }
288
-        if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) {
289
-            perror(argv[2]);
290
-            goto error_out;
291
-        }
292
-
293
-        last_offset -= bytes_to_copy;
294
-    }
295
-
296
-    fclose(infile);
297
-    fclose(outfile);
298
-    free(moov_atom);
299
-    if (ftyp_atom_size > 0)
300
-        free(ftyp_atom);
301
-
302
-    return 0;
303
-
304
-error_out:
305
-    fclose(infile);
306
-    fclose(outfile);
307
-    free(moov_atom);
308
-    if (ftyp_atom_size > 0)
309
-        free(ftyp_atom);
310
-    return 1;
311
-}
312 1
new file mode 100755
... ...
@@ -0,0 +1,9 @@
0
+#!/bin/sh
1
+sed 's/unsigned//g' |\
2
+ sed 's/enum//g' |\
3
+ egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\
4
+ sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\
5
+ sed 's/AVRATIONAL_M/INT_M/g'|\
6
+ sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\
7
+ sed 's/FLOAT_M/FLT_M/g'|\
8
+ sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g'
0 9
new file mode 100755
... ...
@@ -0,0 +1,11 @@
0
+#!/bin/sh
1
+sed '/^+[^+]/!s/	/TaBBaT/g' |\
2
+ expand -t `seq -s , 9 8 200` |\
3
+ sed 's/TaBBaT/	/g' |\
4
+ sed '/^+[^+]/s/ * $//' |\
5
+ tr -d '\015' |\
6

                
7

                
8

                
9
+ tr -d '\n' |\
10

                
0 11
new file mode 100644
... ...
@@ -0,0 +1,130 @@
0
+/*
1
+ * cws2fws by Alex Beregszaszi
2
+ * This file is placed in the public domain.
3
+ * Use the program however you see fit.
4
+ *
5
+ * This utility converts compressed Macromedia Flash files to uncompressed ones.
6
+ */
7
+
8
+#include <sys/stat.h>
9
+#include <fcntl.h>
10
+#include <stdio.h>
11
+#include <stdlib.h>
12
+#include <unistd.h>
13
+#include <zlib.h>
14
+
15
+#ifdef DEBUG
16
+#define dbgprintf printf
17
+#else
18
+#define dbgprintf
19
+#endif
20
+
21
+int main(int argc, char *argv[])
22
+{
23
+    int fd_in, fd_out, comp_len, uncomp_len, i, last_out;
24
+    char buf_in[1024], buf_out[65536];
25
+    z_stream zstream;
26
+    struct stat statbuf;
27
+
28
+    if (argc < 3)
29
+    {
30
+        printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
31
+        exit(1);
32
+    }
33
+
34
+    fd_in = open(argv[1], O_RDONLY);
35
+    if (fd_in < 0)
36
+    {
37
+        perror("Error while opening: ");
38
+        exit(1);
39
+    }
40
+
41
+    fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644);
42
+    if (fd_out < 0)
43
+    {
44
+        perror("Error while opening: ");
45
+        close(fd_in);
46
+        exit(1);
47
+    }
48
+
49
+    if (read(fd_in, &buf_in, 8) != 8)
50
+    {
51
+        printf("Header error\n");
52
+        close(fd_in);
53
+        close(fd_out);
54
+        exit(1);
55
+    }
56
+
57
+    if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S')
58
+    {
59
+        printf("Not a compressed flash file\n");
60
+        exit(1);
61
+    }
62
+
63
+    fstat(fd_in, &statbuf);
64
+    comp_len = statbuf.st_size;
65
+    uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
66
+
67
+    printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4);
68
+
69
+    // write out modified header
70
+    buf_in[0] = 'F';
71
+    write(fd_out, &buf_in, 8);
72
+
73
+    zstream.zalloc = NULL;
74
+    zstream.zfree = NULL;
75
+    zstream.opaque = NULL;
76
+    inflateInit(&zstream);
77
+
78
+    for (i = 0; i < comp_len-8;)
79
+    {
80
+        int ret, len = read(fd_in, &buf_in, 1024);
81
+
82
+        dbgprintf("read %d bytes\n", len);
83
+
84
+        last_out = zstream.total_out;
85
+
86
+        zstream.next_in = &buf_in[0];
87
+        zstream.avail_in = len;
88
+        zstream.next_out = &buf_out[0];
89
+        zstream.avail_out = 65536;
90
+
91
+        ret = inflate(&zstream, Z_SYNC_FLUSH);
92
+        if (ret != Z_STREAM_END && ret != Z_OK)
93
+        {
94
+            printf("Error while decompressing: %d\n", ret);
95
+            inflateEnd(&zstream);
96
+            exit(1);
97
+        }
98
+
99
+        dbgprintf("a_in: %d t_in: %d a_out: %d t_out: %d -- %d out\n",
100
+            zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out,
101
+            zstream.total_out-last_out);
102
+
103
+        write(fd_out, &buf_out, zstream.total_out-last_out);
104
+
105
+        i += len;
106
+
107
+        if (ret == Z_STREAM_END || ret == Z_BUF_ERROR)
108
+            break;
109
+    }
110
+
111
+    if (zstream.total_out != uncomp_len-8)
112
+    {
113
+        printf("Size mismatch (%d != %d), updating header...\n",
114
+            zstream.total_out, uncomp_len-8);
115
+
116
+        buf_in[0] = (zstream.total_out+8) & 0xff;
117
+        buf_in[1] = (zstream.total_out+8 >> 8) & 0xff;
118
+        buf_in[2] = (zstream.total_out+8 >> 16) & 0xff;
119
+        buf_in[3] = (zstream.total_out+8 >> 24) & 0xff;
120
+
121
+        lseek(fd_out, 4, SEEK_SET);
122
+        write(fd_out, &buf_in, 4);
123
+    }
124
+
125
+    inflateEnd(&zstream);
126
+    close(fd_in);
127
+    close(fd_out);
128
+    return 0;
129
+}
0 130
new file mode 100644
... ...
@@ -0,0 +1,117 @@
0
+/*
1
+ * Copyright (c) 2005 Francois Revol
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include <avformat.h>
21
+#include <limits.h>
22
+#include <fcntl.h>
23
+#include <stdio.h>
24
+#include <stdlib.h>
25
+#include <string.h>
26
+#include <unistd.h>
27
+
28
+#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin"
29
+
30
+static int usage(int ret)
31
+{
32
+    fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n");
33
+    fprintf(stderr, "each packet is dumped in its own file named like `basename file.ext`_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n");
34
+    fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n");
35
+    fprintf(stderr, "-n\twrite No file at all, only demux.\n");
36
+    fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n");
37
+    return ret;
38
+}
39
+
40
+int main(int argc, char **argv)
41
+{
42
+    char fntemplate[PATH_MAX];
43
+    char pktfilename[PATH_MAX];
44
+    AVFormatContext *fctx;
45
+    AVPacket pkt;
46
+    int64_t pktnum = 0;
47
+    int64_t maxpkts = 0;
48
+    int donotquit = 0;
49
+    int nowrite = 0;
50
+    int err;
51
+
52
+    if ((argc > 1) && !strncmp(argv[1], "-", 1)) {
53
+        if (strchr(argv[1], 'w'))
54
+            donotquit = 1;
55
+        if (strchr(argv[1], 'n'))
56
+            nowrite = 1;
57
+        argv++;
58
+        argc--;
59
+    }
60
+    if (argc < 2)
61
+        return usage(1);
62
+    if (argc > 2)
63
+        maxpkts = atoi(argv[2]);
64
+    strncpy(fntemplate, argv[1], PATH_MAX-1);
65
+    if (strrchr(argv[1], '/'))
66
+        strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1);
67
+    if (strrchr(fntemplate, '.'))
68
+        *strrchr(fntemplate, '.') = '\0';
69
+    if (strchr(fntemplate, '%')) {
70
+        fprintf(stderr, "can't use filenames containing '%%'\n");
71
+        return usage(1);
72
+    }
73
+    if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) {
74
+        fprintf(stderr, "filename too long\n");
75
+        return usage(1);
76
+    }
77
+    strcat(fntemplate, PKTFILESUFF);
78
+    printf("FNTEMPLATE: '%s'\n", fntemplate);
79
+
80
+    // register all file formats
81
+    av_register_all();
82
+
83
+    err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL);
84
+    if (err < 0) {
85
+        fprintf(stderr, "av_open_input_file: error %d\n", err);
86
+        return 1;
87
+    }
88
+
89
+    err = av_find_stream_info(fctx);
90
+    if (err < 0) {
91
+        fprintf(stderr, "av_find_stream_info: error %d\n", err);
92
+        return 1;
93
+    }
94
+
95
+    av_init_packet(&pkt);
96
+
97
+    while ((err = av_read_frame(fctx, &pkt)) >= 0) {
98
+        int fd;
99
+        snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_');
100
+        printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_');
101
+        //printf("open(\"%s\")\n", pktfilename);
102
+        if (!nowrite) {
103
+            fd = open(pktfilename, O_WRONLY|O_CREAT, 0644);
104
+            write(fd, pkt.data, pkt.size);
105
+            close(fd);
106
+        }
107
+        pktnum++;
108
+        if (maxpkts && (pktnum >= maxpkts))
109
+            break;
110
+    }
111
+
112
+    while (donotquit)
113
+        sleep(60);
114
+
115
+    return 0;
116
+}
0 117
new file mode 100644
... ...
@@ -0,0 +1,311 @@
0
+/*
1
+ * qt-faststart.c, v0.1
2
+ * by Mike Melanson (melanson@pcisys.net)
3
+ * This file is placed in the public domain. Use the program however you
4
+ * see fit.
5
+ *
6
+ * This utility rearranges a Quicktime file such that the moov atom
7
+ * is in front of the data, thus facilitating network streaming.
8
+ *
9
+ * Compile this program using:
10
+ *  make qt-faststart
11
+ * Invoke the program with:
12
+ *  qt-faststart <infile.mov> <outfile.mov>
13
+ *
14
+ * Notes: Quicktime files can come in many configurations of top-level
15
+ * atoms. This utility stipulates that the very last atom in the file needs
16
+ * to be a moov atom. When given such a file, this utility will rearrange
17
+ * the top-level atoms by shifting the moov atom from the back of the file
18
+ * to the front, and patch the chunk offsets along the way. This utility
19
+ * presently only operates on uncompressed moov atoms.
20
+ */
21
+
22
+#include <stdio.h>
23
+#include <stdlib.h>
24
+#include <inttypes.h>
25
+
26
+#ifdef __MINGW32__
27
+#define fseeko(x,y,z)  fseeko64(x,y,z)
28
+#define ftello(x)      ftello64(x)
29
+#endif
30
+
31
+#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
32
+#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
33
+                  (((uint8_t*)(x))[1] << 16) | \
34
+                  (((uint8_t*)(x))[2] << 8) | \
35
+                   ((uint8_t*)(x))[3])
36
+#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \
37
+                  ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \
38
+                  ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \
39
+                  ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \
40
+                  ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \
41
+                  ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \
42
+                  ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \
43
+                  ((uint64_t)((uint8_t*)(x))[7]))
44
+
45
+#define BE_FOURCC( ch0, ch1, ch2, ch3 )             \
46
+        ( (uint32_t)(unsigned char)(ch3) |          \
47
+        ( (uint32_t)(unsigned char)(ch2) << 8 ) |   \
48
+        ( (uint32_t)(unsigned char)(ch1) << 16 ) |  \
49
+        ( (uint32_t)(unsigned char)(ch0) << 24 ) )
50
+
51
+#define QT_ATOM BE_FOURCC
52
+/* top level atoms */
53
+#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e')
54
+#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k')
55
+#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't')
56
+#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v')
57
+#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't')
58
+#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p')
59
+#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e')
60
+#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T')
61
+#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p')
62
+
63
+#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v')
64
+#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o')
65
+#define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
66
+
67
+#define ATOM_PREAMBLE_SIZE 8
68
+#define COPY_BUFFER_SIZE 1024
69
+
70
+int main(int argc, char *argv[])
71
+{
72
+    FILE *infile;
73
+    FILE *outfile;
74
+    unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
75
+    uint32_t atom_type = 0;
76
+    uint64_t atom_size = 0;
77
+    uint64_t last_offset;
78
+    unsigned char *moov_atom;
79
+    unsigned char *ftyp_atom = 0;
80
+    uint64_t moov_atom_size;
81
+    uint64_t ftyp_atom_size = 0;
82
+    uint64_t i, j;
83
+    uint32_t offset_count;
84
+    uint64_t current_offset;
85
+    uint64_t start_offset = 0;
86
+    unsigned char copy_buffer[COPY_BUFFER_SIZE];
87
+    int bytes_to_copy;
88
+
89
+    if (argc != 3) {
90
+        printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n");
91
+        return 0;
92
+    }
93
+
94
+    infile = fopen(argv[1], "rb");
95
+    if (!infile) {
96
+        perror(argv[1]);
97
+        return 1;
98
+    }
99
+
100
+    /* traverse through the atoms in the file to make sure that 'moov' is
101
+     * at the end */
102
+    while (!feof(infile)) {
103
+        if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
104
+            break;
105
+        }
106
+        atom_size = (uint32_t)BE_32(&atom_bytes[0]);
107
+        atom_type = BE_32(&atom_bytes[4]);
108
+
109
+        if ((atom_type != FREE_ATOM) &&
110
+            (atom_type != JUNK_ATOM) &&
111
+            (atom_type != MDAT_ATOM) &&
112
+            (atom_type != MOOV_ATOM) &&
113
+            (atom_type != PNOT_ATOM) &&
114
+            (atom_type != SKIP_ATOM) &&
115
+            (atom_type != WIDE_ATOM) &&
116
+            (atom_type != PICT_ATOM) &&
117
+            (atom_type != FTYP_ATOM)) {
118
+            printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n");
119
+            break;
120
+        }
121
+
122
+        /* keep ftyp atom */
123
+        if (atom_type == FTYP_ATOM) {
124
+            ftyp_atom_size = atom_size;
125
+            ftyp_atom = malloc(ftyp_atom_size);
126
+            if (!ftyp_atom) {
127
+                printf ("could not allocate 0x%llX byte for ftyp atom\n",
128
+                        atom_size);
129
+                fclose(infile);
130
+                return 1;
131
+            }
132
+            fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
133
+            if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
134
+                perror(argv[1]);
135
+                free(ftyp_atom);
136
+                fclose(infile);
137
+                return 1;
138
+            }
139
+            start_offset = ftello(infile);
140
+            continue;
141
+        }
142
+
143
+        /* 64-bit special case */
144
+        if (atom_size == 1) {
145
+            if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
146
+                break;
147
+            }
148
+            atom_size = BE_64(&atom_bytes[0]);
149
+            fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR);
150
+        } else {
151
+            fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR);
152
+        }
153
+    }
154
+
155
+    if (atom_type != MOOV_ATOM) {
156
+        printf ("last atom in file was not a moov atom\n");
157
+        fclose(infile);
158
+        return 0;
159
+    }
160
+
161
+    /* moov atom was, in fact, the last atom in the chunk; load the whole
162
+     * moov atom */
163
+    fseeko(infile, -atom_size, SEEK_END);
164
+    last_offset = ftello(infile);
165
+    moov_atom_size = atom_size;
166
+    moov_atom = malloc(moov_atom_size);
167
+    if (!moov_atom) {
168
+        printf ("could not allocate 0x%llX byte for moov atom\n",
169
+            atom_size);
170
+        fclose(infile);
171
+        return 1;
172
+    }
173
+    if (fread(moov_atom, atom_size, 1, infile) != 1) {
174
+        perror(argv[1]);
175
+        free(moov_atom);
176
+        fclose(infile);
177
+        return 1;
178
+    }
179
+
180
+    /* this utility does not support compressed atoms yet, so disqualify
181
+     * files with compressed QT atoms */
182
+    if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
183
+        printf ("this utility does not support compressed moov atoms yet\n");
184
+        free(moov_atom);
185
+        fclose(infile);
186
+        return 1;
187
+    }
188
+
189
+    /* close; will be re-opened later */
190
+    fclose(infile);
191
+
192
+    /* crawl through the moov chunk in search of stco or co64 atoms */
193
+    for (i = 4; i < moov_atom_size - 4; i++) {
194
+        atom_type = BE_32(&moov_atom[i]);
195
+        if (atom_type == STCO_ATOM) {
196
+            printf (" patching stco atom...\n");
197
+            atom_size = BE_32(&moov_atom[i - 4]);
198
+            if (i + atom_size - 4 > moov_atom_size) {
199
+                printf (" bad atom size\n");
200
+                free(moov_atom);
201
+                return 1;
202
+            }
203
+            offset_count = BE_32(&moov_atom[i + 8]);
204
+            for (j = 0; j < offset_count; j++) {
205
+                current_offset = BE_32(&moov_atom[i + 12 + j * 4]);
206
+                current_offset += moov_atom_size;
207
+                moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF;
208
+                moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF;
209
+                moov_atom[i + 12 + j * 4 + 2] = (current_offset >>  8) & 0xFF;
210
+                moov_atom[i + 12 + j * 4 + 3] = (current_offset >>  0) & 0xFF;
211
+            }
212
+            i += atom_size - 4;
213
+        } else if (atom_type == CO64_ATOM) {
214
+            printf (" patching co64 atom...\n");
215
+            atom_size = BE_32(&moov_atom[i - 4]);
216
+            if (i + atom_size - 4 > moov_atom_size) {
217
+                printf (" bad atom size\n");
218
+                free(moov_atom);
219
+                return 1;
220
+            }
221
+            offset_count = BE_32(&moov_atom[i + 8]);
222
+            for (j = 0; j < offset_count; j++) {
223
+                current_offset = BE_64(&moov_atom[i + 12 + j * 8]);
224
+                current_offset += moov_atom_size;
225
+                moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF;
226
+                moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF;
227
+                moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF;
228
+                moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF;
229
+                moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF;
230
+                moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF;
231
+                moov_atom[i + 12 + j * 8 + 6] = (current_offset >>  8) & 0xFF;
232
+                moov_atom[i + 12 + j * 8 + 7] = (current_offset >>  0) & 0xFF;
233
+            }
234
+            i += atom_size - 4;
235
+        }
236
+    }
237
+
238
+    /* re-open the input file and open the output file */
239
+    infile = fopen(argv[1], "rb");
240
+    if (!infile) {
241
+        perror(argv[1]);
242
+        free(moov_atom);
243
+        return 1;
244
+    }
245
+
246
+    if (start_offset > 0) { /* seek after ftyp atom */
247
+        fseeko(infile, start_offset, SEEK_SET);
248
+        last_offset -= start_offset;
249
+    }
250
+
251
+    outfile = fopen(argv[2], "wb");
252
+    if (!outfile) {
253
+        perror(argv[2]);
254
+        fclose(outfile);
255
+        free(moov_atom);
256
+        return 1;
257
+    }
258
+
259
+    /* dump the same ftyp atom */
260
+    if (ftyp_atom_size > 0) {
261
+        printf (" writing ftyp atom...\n");
262
+        if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) {
263
+            perror(argv[2]);
264
+            goto error_out;
265
+        }
266
+    }
267
+
268
+    /* dump the new moov atom */
269
+    printf (" writing moov atom...\n");
270
+    if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {
271
+        perror(argv[2]);
272
+        goto error_out;
273
+    }
274
+
275
+    /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
276
+    printf (" copying rest of file...\n");
277
+    while (last_offset) {
278
+        if (last_offset > COPY_BUFFER_SIZE)
279
+            bytes_to_copy = COPY_BUFFER_SIZE;
280
+        else
281
+            bytes_to_copy = last_offset;
282
+
283
+        if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) {
284
+            perror(argv[1]);
285
+            goto error_out;
286
+        }
287
+        if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) {
288
+            perror(argv[2]);
289
+            goto error_out;
290
+        }
291
+
292
+        last_offset -= bytes_to_copy;
293
+    }
294
+
295
+    fclose(infile);
296
+    fclose(outfile);
297
+    free(moov_atom);
298
+    if (ftyp_atom_size > 0)
299
+        free(ftyp_atom);
300
+
301
+    return 0;
302
+
303
+error_out:
304
+    fclose(infile);
305
+    fclose(outfile);
306
+    free(moov_atom);
307
+    if (ftyp_atom_size > 0)
308
+        free(ftyp_atom);
309
+    return 1;
310
+}
0 311
new file mode 100755
... ...
@@ -0,0 +1,2 @@
0
+#!/bin/sh
1
+tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n'
0 2
deleted file mode 100755
... ...
@@ -1,2 +0,0 @@
1
-#!/bin/sh
2
-tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n'