summaryrefslogtreecommitdiff
path: root/tools/qt-faststart.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qt-faststart.c')
-rw-r--r--tools/qt-faststart.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index f33d6fa80c..8af510f71c 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -8,7 +8,7 @@
* is in front of the data, thus facilitating network streaming.
*
* To compile this program, start from the base directory from which you
- * are building Libav and type:
+ * are building FFmpeg and type:
* make tools/qt-faststart
* The qt-faststart program will be built in the tools/ directory. If you
* do not build the program in this manner, correct results are not
@@ -37,6 +37,8 @@
#define ftello(x) _ftelli64(x)
#endif
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+
#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
@@ -77,7 +79,7 @@
#define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
#define ATOM_PREAMBLE_SIZE 8
-#define COPY_BUFFER_SIZE 1024
+#define COPY_BUFFER_SIZE 33554432
int main(int argc, char *argv[])
{
@@ -96,7 +98,7 @@ int main(int argc, char *argv[])
uint32_t offset_count;
uint64_t current_offset;
uint64_t start_offset = 0;
- unsigned char copy_buffer[COPY_BUFFER_SIZE];
+ unsigned char *copy_buffer = NULL;
int bytes_to_copy;
if (argc != 3) {
@@ -293,12 +295,15 @@ int main(int argc, char *argv[])
}
/* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
+ bytes_to_copy = FFMIN(COPY_BUFFER_SIZE, last_offset);
+ copy_buffer = malloc(bytes_to_copy);
+ if (!copy_buffer) {
+ printf("could not allocate %d bytes for copy_buffer\n", bytes_to_copy);
+ goto error_out;
+ }
printf(" copying rest of file...\n");
while (last_offset) {
- if (last_offset > COPY_BUFFER_SIZE)
- bytes_to_copy = COPY_BUFFER_SIZE;
- else
- bytes_to_copy = last_offset;
+ bytes_to_copy = FFMIN(bytes_to_copy, last_offset);
if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) {
perror(argv[1]);
@@ -315,6 +320,7 @@ int main(int argc, char *argv[])
fclose(outfile);
free(moov_atom);
free(ftyp_atom);
+ free(copy_buffer);
return 0;
@@ -325,5 +331,6 @@ error_out:
fclose(outfile);
free(moov_atom);
free(ftyp_atom);
+ free(copy_buffer);
return 1;
}