diff options
author | Måns Rullgård <mans@mansr.com> | 2007-07-13 21:33:24 +0000 |
---|---|---|
committer | Måns Rullgård <mans@mansr.com> | 2007-07-13 21:33:24 +0000 |
commit | c07ed8c8a22c1427323dccb7722b2b094f95e728 (patch) | |
tree | 429fe6bdd3616d542e709792dfdcb6c7f86e3fdd /tools | |
parent | fdc1973e30b5ccafaa2443053fd65a35fdbd9d5a (diff) | |
download | ffmpeg-c07ed8c8a22c1427323dccb7722b2b094f95e728.tar.gz |
create and populate "tools" directory
Originally committed as revision 9634 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/build_avopt | 9 | ||||
-rwxr-xr-x | tools/clean-diff | 11 | ||||
-rw-r--r-- | tools/cws2fws.c | 130 | ||||
-rw-r--r-- | tools/pktdumper.c | 117 | ||||
-rw-r--r-- | tools/qt-faststart.c | 311 | ||||
-rwxr-xr-x | tools/unwrap-diff | 2 |
6 files changed, 580 insertions, 0 deletions
diff --git a/tools/build_avopt b/tools/build_avopt new file mode 100755 index 0000000000..fcf165765c --- /dev/null +++ b/tools/build_avopt @@ -0,0 +1,9 @@ +#!/bin/sh +sed 's/unsigned//g' |\ + sed 's/enum//g' |\ + egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\ + sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\ + sed 's/AVRATIONAL_M/INT_M/g'|\ + sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\ + sed 's/FLOAT_M/FLT_M/g'|\ + sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g' diff --git a/tools/clean-diff b/tools/clean-diff new file mode 100755 index 0000000000..98e26a79f9 --- /dev/null +++ b/tools/clean-diff @@ -0,0 +1,11 @@ +#!/bin/sh +sed '/^+[^+]/!s/ /TaBBaT/g' |\ + expand -t `seq -s , 9 8 200` |\ + sed 's/TaBBaT/ /g' |\ + sed '/^+[^+]/s/ * $//' |\ + tr -d '\015' |\ + tr '\n' '°' |\ + sed 's/\(@@[^@]*@@°[^@]*\)/\n\1/g' |\ + egrep -v '@@[^@]*@@°(( [^°]*°)|([+-][[:space:]]*°)|(-[[:space:]]*([^°]*)°\+[[:space:]]*\5°))*$' |\ + tr -d '\n' |\ + tr '°' '\n' diff --git a/tools/cws2fws.c b/tools/cws2fws.c new file mode 100644 index 0000000000..f81e2e26ea --- /dev/null +++ b/tools/cws2fws.c @@ -0,0 +1,130 @@ +/* + * cws2fws by Alex Beregszaszi + * This file is placed in the public domain. + * Use the program however you see fit. + * + * This utility converts compressed Macromedia Flash files to uncompressed ones. + */ + +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <zlib.h> + +#ifdef DEBUG +#define dbgprintf printf +#else +#define dbgprintf +#endif + +int main(int argc, char *argv[]) +{ + int fd_in, fd_out, comp_len, uncomp_len, i, last_out; + char buf_in[1024], buf_out[65536]; + z_stream zstream; + struct stat statbuf; + + if (argc < 3) + { + printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]); + exit(1); + } + + fd_in = open(argv[1], O_RDONLY); + if (fd_in < 0) + { + perror("Error while opening: "); + exit(1); + } + + fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644); + if (fd_out < 0) + { + perror("Error while opening: "); + close(fd_in); + exit(1); + } + + if (read(fd_in, &buf_in, 8) != 8) + { + printf("Header error\n"); + close(fd_in); + close(fd_out); + exit(1); + } + + if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') + { + printf("Not a compressed flash file\n"); + exit(1); + } + + fstat(fd_in, &statbuf); + comp_len = statbuf.st_size; + uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24); + + printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4); + + // write out modified header + buf_in[0] = 'F'; + write(fd_out, &buf_in, 8); + + zstream.zalloc = NULL; + zstream.zfree = NULL; + zstream.opaque = NULL; + inflateInit(&zstream); + + for (i = 0; i < comp_len-8;) + { + int ret, len = read(fd_in, &buf_in, 1024); + + dbgprintf("read %d bytes\n", len); + + last_out = zstream.total_out; + + zstream.next_in = &buf_in[0]; + zstream.avail_in = len; + zstream.next_out = &buf_out[0]; + zstream.avail_out = 65536; + + ret = inflate(&zstream, Z_SYNC_FLUSH); + if (ret != Z_STREAM_END && ret != Z_OK) + { + printf("Error while decompressing: %d\n", ret); + inflateEnd(&zstream); + exit(1); + } + + dbgprintf("a_in: %d t_in: %d a_out: %d t_out: %d -- %d out\n", + zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out, + zstream.total_out-last_out); + + write(fd_out, &buf_out, zstream.total_out-last_out); + + i += len; + + if (ret == Z_STREAM_END || ret == Z_BUF_ERROR) + break; + } + + if (zstream.total_out != uncomp_len-8) + { + printf("Size mismatch (%d != %d), updating header...\n", + zstream.total_out, uncomp_len-8); + + buf_in[0] = (zstream.total_out+8) & 0xff; + buf_in[1] = (zstream.total_out+8 >> 8) & 0xff; + buf_in[2] = (zstream.total_out+8 >> 16) & 0xff; + buf_in[3] = (zstream.total_out+8 >> 24) & 0xff; + + lseek(fd_out, 4, SEEK_SET); + write(fd_out, &buf_in, 4); + } + + inflateEnd(&zstream); + close(fd_in); + close(fd_out); + return 0; +} diff --git a/tools/pktdumper.c b/tools/pktdumper.c new file mode 100644 index 0000000000..04488caa45 --- /dev/null +++ b/tools/pktdumper.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2005 Francois Revol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <avformat.h> +#include <limits.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin" + +static int usage(int ret) +{ + fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n"); + fprintf(stderr, "each packet is dumped in its own file named like `basename file.ext`_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n"); + fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n"); + fprintf(stderr, "-n\twrite No file at all, only demux.\n"); + fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n"); + return ret; +} + +int main(int argc, char **argv) +{ + char fntemplate[PATH_MAX]; + char pktfilename[PATH_MAX]; + AVFormatContext *fctx; + AVPacket pkt; + int64_t pktnum = 0; + int64_t maxpkts = 0; + int donotquit = 0; + int nowrite = 0; + int err; + + if ((argc > 1) && !strncmp(argv[1], "-", 1)) { + if (strchr(argv[1], 'w')) + donotquit = 1; + if (strchr(argv[1], 'n')) + nowrite = 1; + argv++; + argc--; + } + if (argc < 2) + return usage(1); + if (argc > 2) + maxpkts = atoi(argv[2]); + strncpy(fntemplate, argv[1], PATH_MAX-1); + if (strrchr(argv[1], '/')) + strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1); + if (strrchr(fntemplate, '.')) + *strrchr(fntemplate, '.') = '\0'; + if (strchr(fntemplate, '%')) { + fprintf(stderr, "can't use filenames containing '%%'\n"); + return usage(1); + } + if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) { + fprintf(stderr, "filename too long\n"); + return usage(1); + } + strcat(fntemplate, PKTFILESUFF); + printf("FNTEMPLATE: '%s'\n", fntemplate); + + // register all file formats + av_register_all(); + + err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL); + if (err < 0) { + fprintf(stderr, "av_open_input_file: error %d\n", err); + return 1; + } + + err = av_find_stream_info(fctx); + if (err < 0) { + fprintf(stderr, "av_find_stream_info: error %d\n", err); + return 1; + } + + av_init_packet(&pkt); + + while ((err = av_read_frame(fctx, &pkt)) >= 0) { + int fd; + snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_'); + printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_'); + //printf("open(\"%s\")\n", pktfilename); + if (!nowrite) { + fd = open(pktfilename, O_WRONLY|O_CREAT, 0644); + write(fd, pkt.data, pkt.size); + close(fd); + } + pktnum++; + if (maxpkts && (pktnum >= maxpkts)) + break; + } + + while (donotquit) + sleep(60); + + return 0; +} diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c new file mode 100644 index 0000000000..2cbf12b1d9 --- /dev/null +++ b/tools/qt-faststart.c @@ -0,0 +1,311 @@ +/* + * qt-faststart.c, v0.1 + * by Mike Melanson (melanson@pcisys.net) + * This file is placed in the public domain. Use the program however you + * see fit. + * + * This utility rearranges a Quicktime file such that the moov atom + * is in front of the data, thus facilitating network streaming. + * + * Compile this program using: + * make qt-faststart + * Invoke the program with: + * qt-faststart <infile.mov> <outfile.mov> + * + * Notes: Quicktime files can come in many configurations of top-level + * atoms. This utility stipulates that the very last atom in the file needs + * to be a moov atom. When given such a file, this utility will rearrange + * the top-level atoms by shifting the moov atom from the back of the file + * to the front, and patch the chunk offsets along the way. This utility + * presently only operates on uncompressed moov atoms. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> + +#ifdef __MINGW32__ +#define fseeko(x,y,z) fseeko64(x,y,z) +#define ftello(x) ftello64(x) +#endif + +#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) +#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ + (((uint8_t*)(x))[1] << 16) | \ + (((uint8_t*)(x))[2] << 8) | \ + ((uint8_t*)(x))[3]) +#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \ + ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \ + ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \ + ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \ + ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \ + ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \ + ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \ + ((uint64_t)((uint8_t*)(x))[7])) + +#define BE_FOURCC( ch0, ch1, ch2, ch3 ) \ + ( (uint32_t)(unsigned char)(ch3) | \ + ( (uint32_t)(unsigned char)(ch2) << 8 ) | \ + ( (uint32_t)(unsigned char)(ch1) << 16 ) | \ + ( (uint32_t)(unsigned char)(ch0) << 24 ) ) + +#define QT_ATOM BE_FOURCC +/* top level atoms */ +#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e') +#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k') +#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't') +#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v') +#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't') +#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p') +#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e') +#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T') +#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p') + +#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v') +#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o') +#define CO64_ATOM QT_ATOM('c', 'o', '6', '4') + +#define ATOM_PREAMBLE_SIZE 8 +#define COPY_BUFFER_SIZE 1024 + +int main(int argc, char *argv[]) +{ + FILE *infile; + FILE *outfile; + unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; + uint32_t atom_type = 0; + uint64_t atom_size = 0; + uint64_t last_offset; + unsigned char *moov_atom; + unsigned char *ftyp_atom = 0; + uint64_t moov_atom_size; + uint64_t ftyp_atom_size = 0; + uint64_t i, j; + uint32_t offset_count; + uint64_t current_offset; + uint64_t start_offset = 0; + unsigned char copy_buffer[COPY_BUFFER_SIZE]; + int bytes_to_copy; + + if (argc != 3) { + printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n"); + return 0; + } + + infile = fopen(argv[1], "rb"); + if (!infile) { + perror(argv[1]); + return 1; + } + + /* traverse through the atoms in the file to make sure that 'moov' is + * at the end */ + while (!feof(infile)) { + if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { + break; + } + atom_size = (uint32_t)BE_32(&atom_bytes[0]); + atom_type = BE_32(&atom_bytes[4]); + + if ((atom_type != FREE_ATOM) && + (atom_type != JUNK_ATOM) && + (atom_type != MDAT_ATOM) && + (atom_type != MOOV_ATOM) && + (atom_type != PNOT_ATOM) && + (atom_type != SKIP_ATOM) && + (atom_type != WIDE_ATOM) && + (atom_type != PICT_ATOM) && + (atom_type != FTYP_ATOM)) { + printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n"); + break; + } + + /* keep ftyp atom */ + if (atom_type == FTYP_ATOM) { + ftyp_atom_size = atom_size; + ftyp_atom = malloc(ftyp_atom_size); + if (!ftyp_atom) { + printf ("could not allocate 0x%llX byte for ftyp atom\n", + atom_size); + fclose(infile); + return 1; + } + fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR); + if (fread(ftyp_atom, atom_size, 1, infile) != 1) { + perror(argv[1]); + free(ftyp_atom); + fclose(infile); + return 1; + } + start_offset = ftello(infile); + continue; + } + + /* 64-bit special case */ + if (atom_size == 1) { + if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { + break; + } + atom_size = BE_64(&atom_bytes[0]); + fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); + } else { + fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); + } + } + + if (atom_type != MOOV_ATOM) { + printf ("last atom in file was not a moov atom\n"); + fclose(infile); + return 0; + } + + /* moov atom was, in fact, the last atom in the chunk; load the whole + * moov atom */ + fseeko(infile, -atom_size, SEEK_END); + last_offset = ftello(infile); + moov_atom_size = atom_size; + moov_atom = malloc(moov_atom_size); + if (!moov_atom) { + printf ("could not allocate 0x%llX byte for moov atom\n", + atom_size); + fclose(infile); + return 1; + } + if (fread(moov_atom, atom_size, 1, infile) != 1) { + perror(argv[1]); + free(moov_atom); + fclose(infile); + return 1; + } + + /* this utility does not support compressed atoms yet, so disqualify + * files with compressed QT atoms */ + if (BE_32(&moov_atom[12]) == CMOV_ATOM) { + printf ("this utility does not support compressed moov atoms yet\n"); + free(moov_atom); + fclose(infile); + return 1; + } + + /* close; will be re-opened later */ + fclose(infile); + + /* crawl through the moov chunk in search of stco or co64 atoms */ + for (i = 4; i < moov_atom_size - 4; i++) { + atom_type = BE_32(&moov_atom[i]); + if (atom_type == STCO_ATOM) { + printf (" patching stco atom...\n"); + atom_size = BE_32(&moov_atom[i - 4]); + if (i + atom_size - 4 > moov_atom_size) { + printf (" bad atom size\n"); + free(moov_atom); + return 1; + } + offset_count = BE_32(&moov_atom[i + 8]); + for (j = 0; j < offset_count; j++) { + current_offset = BE_32(&moov_atom[i + 12 + j * 4]); + current_offset += moov_atom_size; + moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF; + moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF; + moov_atom[i + 12 + j * 4 + 2] = (current_offset >> 8) & 0xFF; + moov_atom[i + 12 + j * 4 + 3] = (current_offset >> 0) & 0xFF; + } + i += atom_size - 4; + } else if (atom_type == CO64_ATOM) { + printf (" patching co64 atom...\n"); + atom_size = BE_32(&moov_atom[i - 4]); + if (i + atom_size - 4 > moov_atom_size) { + printf (" bad atom size\n"); + free(moov_atom); + return 1; + } + offset_count = BE_32(&moov_atom[i + 8]); + for (j = 0; j < offset_count; j++) { + current_offset = BE_64(&moov_atom[i + 12 + j * 8]); + current_offset += moov_atom_size; + moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF; + moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF; + moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF; + moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF; + moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF; + moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF; + moov_atom[i + 12 + j * 8 + 6] = (current_offset >> 8) & 0xFF; + moov_atom[i + 12 + j * 8 + 7] = (current_offset >> 0) & 0xFF; + } + i += atom_size - 4; + } + } + + /* re-open the input file and open the output file */ + infile = fopen(argv[1], "rb"); + if (!infile) { + perror(argv[1]); + free(moov_atom); + return 1; + } + + if (start_offset > 0) { /* seek after ftyp atom */ + fseeko(infile, start_offset, SEEK_SET); + last_offset -= start_offset; + } + + outfile = fopen(argv[2], "wb"); + if (!outfile) { + perror(argv[2]); + fclose(outfile); + free(moov_atom); + return 1; + } + + /* dump the same ftyp atom */ + if (ftyp_atom_size > 0) { + printf (" writing ftyp atom...\n"); + if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + } + + /* dump the new moov atom */ + printf (" writing moov atom...\n"); + if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + + /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */ + 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; + + if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) { + perror(argv[1]); + goto error_out; + } + if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + + last_offset -= bytes_to_copy; + } + + fclose(infile); + fclose(outfile); + free(moov_atom); + if (ftyp_atom_size > 0) + free(ftyp_atom); + + return 0; + +error_out: + fclose(infile); + fclose(outfile); + free(moov_atom); + if (ftyp_atom_size > 0) + free(ftyp_atom); + return 1; +} diff --git a/tools/unwrap-diff b/tools/unwrap-diff new file mode 100755 index 0000000000..ccea99b7b4 --- /dev/null +++ b/tools/unwrap-diff @@ -0,0 +1,2 @@ +#!/bin/sh +tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n' |