summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-01-26 01:52:29 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-01-26 02:23:56 +0100
commit3c5fe5b52758225e58fec917cc29281d6025aa67 (patch)
treed7484edfa989ffc33744cbbf11960e803f677f2b /tools
parent01e5e97026cf0b344abafca22b0336a2c58b2a33 (diff)
parentd78bb1a4b2a3a415b68e4e6dd448779eccec64e3 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (22 commits) wma: Clip WMA1 and WMA2 frame length to 11 bits. movenc: Don't require frame_size to be set for modes other than mov doc: Update APIchanges with info on muxer flushing movenc: Reindent a block tools: Remove some unnecessary #undefs. rv20: prevent calling ff_h263_decode_mba() with unset height/width tools: K&R reformatting cosmetics Ignore generated aviocat and ismindex tools. build: Automatically include architecture-specific library Makefile snippets. indeo5: prevent null pointer dereference on broken files pktdumper: Use usleep instead of sleep cosmetics: Remove some unnecessary block braces. Drop unnecessary prefix from *sink* variable and struct names. Add a tool for creating smooth streaming manifests movdec: Calculate an average bit rate for fragmented streams, too movenc: Write the sample rate instead of time scale in the stsd atom movenc: Add a separate ismv/isma (smooth streaming) muxer movenc: Allow the caller to decide on fragmentation libavformat: Add a flag for muxers that support write_packet(NULL) for flushing movenc: Add support for writing fragmented mov files ... Conflicts: Changelog cmdutils.c cmdutils.h doc/APIchanges ffmpeg.c ffplay.c libavfilter/Makefile libavformat/Makefile libavformat/avformat.h libavformat/movenc.c libavformat/movenc.h libavformat/version.h tools/graph2dot.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'tools')
-rw-r--r--tools/aviocat.c6
-rw-r--r--tools/cws2fws.c56
-rw-r--r--tools/graph2dot.c37
-rw-r--r--tools/ismindex.c521
-rw-r--r--tools/lavfi-showfiltfmts.c6
-rw-r--r--tools/pktdumper.c28
-rw-r--r--tools/probetest.c28
-rw-r--r--tools/qt-faststart.c1
-rw-r--r--tools/trasher.c39
9 files changed, 629 insertions, 93 deletions
diff --git a/tools/aviocat.c b/tools/aviocat.c
index 92483c345a..f5da526ba9 100644
--- a/tools/aviocat.c
+++ b/tools/aviocat.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+
#include "libavformat/avformat.h"
static int usage(const char *argv0, int ret)
@@ -80,13 +81,14 @@ int main(int argc, char **argv)
stream_pos += n;
if (bps) {
avio_flush(output);
- while ((av_gettime() - start_time)*bps/AV_TIME_BASE < stream_pos)
- usleep(50*1000);
+ while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos)
+ usleep(50 * 1000);
}
}
avio_flush(output);
avio_close(output);
+
fail:
avio_close(input);
avformat_network_deinit();
diff --git a/tools/cws2fws.c b/tools/cws2fws.c
index 35fce35683..68f7953b56 100644
--- a/tools/cws2fws.c
+++ b/tools/cws2fws.c
@@ -26,46 +26,42 @@ int main(int argc, char *argv[])
z_stream zstream;
struct stat statbuf;
- if (argc < 3)
- {
+ if (argc < 3) {
printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]);
return 1;
}
fd_in = open(argv[1], O_RDONLY);
- if (fd_in < 0)
- {
+ if (fd_in < 0) {
perror("Error opening input file");
return 1;
}
- fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644);
- if (fd_out < 0)
- {
+ fd_out = open(argv[2], O_WRONLY | O_CREAT, 00644);
+ if (fd_out < 0) {
perror("Error opening output file");
close(fd_in);
return 1;
}
- if (read(fd_in, &buf_in, 8) != 8)
- {
+ if (read(fd_in, &buf_in, 8) != 8) {
printf("Header error\n");
close(fd_in);
close(fd_out);
return 1;
}
- if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S')
- {
+ if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') {
printf("Not a compressed flash file\n");
return 1;
}
fstat(fd_in, &statbuf);
- comp_len = statbuf.st_size;
+ 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);
+ printf("Compressed size: %d Uncompressed size: %d\n",
+ comp_len - 4, uncomp_len - 4);
// write out modified header
buf_in[0] = 'F';
@@ -75,36 +71,35 @@ int main(int argc, char *argv[])
}
zstream.zalloc = NULL;
- zstream.zfree = NULL;
+ zstream.zfree = NULL;
zstream.opaque = NULL;
inflateInit(&zstream);
- for (i = 0; i < comp_len-8;)
- {
+ 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.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)
- {
+ if (ret != Z_STREAM_END && ret != Z_OK) {
printf("Error while decompressing: %d\n", ret);
inflateEnd(&zstream);
return 1;
}
dbgprintf("a_in: %d t_in: %lu a_out: %d t_out: %lu -- %lu out\n",
- zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out,
- zstream.total_out-last_out);
+ zstream.avail_in, zstream.total_in, zstream.avail_out,
+ zstream.total_out, zstream.total_out - last_out);
- if (write(fd_out, &buf_out, zstream.total_out - last_out) < zstream.total_out - last_out) {
+ if (write(fd_out, &buf_out, zstream.total_out - last_out) <
+ zstream.total_out - last_out) {
perror("Error writing output file");
return 1;
}
@@ -115,15 +110,14 @@ int main(int argc, char *argv[])
break;
}
- if (zstream.total_out != uncomp_len-8)
- {
+ if (zstream.total_out != uncomp_len - 8) {
printf("Size mismatch (%lu != %d), updating header...\n",
- zstream.total_out, uncomp_len-8);
+ 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;
+ 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);
if (write(fd_out, &buf_in, 4) < 4) {
diff --git a/tools/graph2dot.c b/tools/graph2dot.c
index 766afdb050..c000c4ca3a 100644
--- a/tools/graph2dot.c
+++ b/tools/graph2dot.c
@@ -20,7 +20,6 @@
#include <unistd.h> /* getopt */
-#undef HAVE_AV_CONFIG_H
#include "libavutil/pixdesc.h"
#include "libavutil/audioconvert.h"
#include "libavfilter/avfiltergraph.h"
@@ -63,19 +62,25 @@ static void print_digraph(FILE *outfile, AVFilterGraph *graph)
char dst_filter_ctx_label[128];
const AVFilterContext *dst_filter_ctx = link->dst;
- snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label), "%s (%s)",
+ snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label),
+ "%s (%s)",
dst_filter_ctx->name,
dst_filter_ctx->filter->name);
- fprintf(outfile, "\"%s\" -> \"%s\"", filter_ctx_label, dst_filter_ctx_label);
+ fprintf(outfile, "\"%s\" -> \"%s\"",
+ filter_ctx_label, dst_filter_ctx_label);
if (link->type == AVMEDIA_TYPE_VIDEO) {
- fprintf(outfile, " [ label= \"fmt:%s w:%d h:%d tb:%d/%d\" ]",
+ fprintf(outfile,
+ " [ label= \"fmt:%s w:%d h:%d tb:%d/%d\" ]",
av_pix_fmt_descriptors[link->format].name,
- link->w, link->h, link->time_base.num, link->time_base.den);
+ link->w, link->h, link->time_base.num,
+ link->time_base.den);
} else if (link->type == AVMEDIA_TYPE_AUDIO) {
char buf[255];
- av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
- fprintf(outfile, " [ label= \"fmt:%s sr:%"PRId64" cl:%s tb:%d/%d\" ]",
+ av_get_channel_layout_string(buf, sizeof(buf), -1,
+ link->channel_layout);
+ fprintf(outfile,
+ " [ label= \"fmt:%s sr:%"PRId64" cl:%s tb:%d/%d\" ]",
av_get_sample_fmt_name(link->format),
link->sample_rate, buf,
link->time_base.num, link->time_base.den);
@@ -90,17 +95,17 @@ static void print_digraph(FILE *outfile, AVFilterGraph *graph)
int main(int argc, char **argv)
{
const char *outfilename = NULL;
- const char *infilename = NULL;
- FILE *outfile = NULL;
- FILE *infile = NULL;
- char *graph_string = NULL;
+ const char *infilename = NULL;
+ FILE *outfile = NULL;
+ FILE *infile = NULL;
+ char *graph_string = NULL;
AVFilterGraph *graph = av_mallocz(sizeof(AVFilterGraph));
char c;
av_log_set_level(AV_LOG_DEBUG);
while ((c = getopt(argc, argv, "hi:o:")) != -1) {
- switch(c) {
+ switch (c) {
case 'h':
usage();
return 0;
@@ -119,7 +124,8 @@ int main(int argc, char **argv)
infilename = "/dev/stdin";
infile = fopen(infilename, "r");
if (!infile) {
- fprintf(stderr, "Impossible to open input file '%s': %s\n", infilename, strerror(errno));
+ fprintf(stderr, "Impossible to open input file '%s': %s\n",
+ infilename, strerror(errno));
return 1;
}
@@ -127,7 +133,8 @@ int main(int argc, char **argv)
outfilename = "/dev/stdout";
outfile = fopen(outfilename, "w");
if (!outfile) {
- fprintf(stderr, "Impossible to open output file '%s': %s\n", outfilename, strerror(errno));
+ fprintf(stderr, "Impossible to open output file '%s': %s\n",
+ outfilename, strerror(errno));
return 1;
}
@@ -142,7 +149,7 @@ int main(int argc, char **argv)
struct line *new_line = av_malloc(sizeof(struct line));
count += strlen(last_line->data);
last_line->next = new_line;
- last_line = new_line;
+ last_line = new_line;
}
last_line->next = NULL;
diff --git a/tools/ismindex.c b/tools/ismindex.c
new file mode 100644
index 0000000000..59d1286c46
--- /dev/null
+++ b/tools/ismindex.c
@@ -0,0 +1,521 @@
+/*
+ * Copyright (c) 2012 Martin Storsjo
+ *
+ * This file is part of Libav.
+ *
+ * Libav 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.
+ *
+ * Libav 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 Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * To create a simple file for smooth streaming:
+ * avconv <normal input/transcoding options> -movflags frag_keyframe foo.ismv
+ * ismindex -n foo foo.ismv
+ * This step creates foo.ism and foo.ismc that is required by IIS for
+ * serving it.
+ *
+ * To pre-split files for serving as static files by a web server without
+ * any extra server support, create the ismv file as above, and split it:
+ * ismindex -split foo.ismv
+ * This step creates a file Manifest and directories QualityLevel(...),
+ * that can be read directly by a smooth streaming player.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include "libavformat/avformat.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/mathematics.h"
+
+static int usage(const char *argv0, int ret)
+{
+ fprintf(stderr, "%s [-split] [-n basename] file1 [file2] ...\n", argv0);
+ return ret;
+}
+
+struct MoofOffset {
+ int64_t time;
+ int64_t offset;
+ int duration;
+};
+
+struct VideoFile {
+ const char *name;
+ int64_t duration;
+ int bitrate;
+ int track_id;
+ int is_audio, is_video;
+ int width, height;
+ int chunks;
+ int sample_rate, channels;
+ uint8_t *codec_private;
+ int codec_private_size;
+ struct MoofOffset *offsets;
+ int timescale;
+ const char *fourcc;
+ int blocksize;
+ int tag;
+};
+
+struct VideoFiles {
+ int nb_files;
+ int64_t duration;
+ struct VideoFile **files;
+ int video_file, audio_file;
+ int nb_video_files, nb_audio_files;
+};
+
+static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name)
+{
+ int32_t size, tag;
+
+ size = avio_rb32(in);
+ tag = avio_rb32(in);
+ avio_wb32(out, size);
+ avio_wb32(out, tag);
+ if (tag != tag_name)
+ return -1;
+ size -= 8;
+ while (size > 0) {
+ char buf[1024];
+ int len = FFMIN(sizeof(buf), size);
+ if (avio_read(in, buf, len) != len)
+ break;
+ avio_write(out, buf, len);
+ size -= len;
+ }
+ return 0;
+}
+
+static int write_fragment(const char *filename, AVIOContext *in)
+{
+ AVIOContext *out = NULL;
+ int ret;
+
+ if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, NULL, NULL)) < 0)
+ return ret;
+ copy_tag(in, out, MKBETAG('m', 'o', 'o', 'f'));
+ copy_tag(in, out, MKBETAG('m', 'd', 'a', 't'));
+
+ avio_flush(out);
+ avio_close(out);
+
+ return ret;
+}
+
+static int write_fragments(struct VideoFiles *files, int start_index,
+ AVIOContext *in)
+{
+ char dirname[100], filename[500];
+ int i, j;
+
+ for (i = start_index; i < files->nb_files; i++) {
+ struct VideoFile *vf = files->files[i];
+ const char *type = vf->is_video ? "video" : "audio";
+ snprintf(dirname, sizeof(dirname), "QualityLevels(%d)", vf->bitrate);
+ mkdir(dirname, 0777);
+ for (j = 0; j < vf->chunks; j++) {
+ snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")",
+ dirname, type, vf->offsets[j].time);
+ avio_seek(in, vf->offsets[j].offset, SEEK_SET);
+ write_fragment(filename, in);
+ }
+ }
+ return 0;
+}
+
+static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f)
+{
+ int ret = AVERROR_EOF, track_id;
+ int version, fieldlength, i, j;
+ int64_t pos = avio_tell(f);
+ uint32_t size = avio_rb32(f);
+ struct VideoFile *vf = NULL;
+
+ if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a'))
+ goto fail;
+ version = avio_r8(f);
+ avio_rb24(f);
+ track_id = avio_rb32(f); /* track id */
+ for (i = start_index; i < files->nb_files && !vf; i++)
+ if (files->files[i]->track_id == track_id)
+ vf = files->files[i];
+ if (!vf) {
+ /* Ok, continue parsing the next atom */
+ ret = 0;
+ goto fail;
+ }
+ fieldlength = avio_rb32(f);
+ vf->chunks = avio_rb32(f);
+ vf->offsets = av_mallocz(sizeof(*vf->offsets) * vf->chunks);
+ if (!vf->offsets) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ for (i = 0; i < vf->chunks; i++) {
+ if (version == 1) {
+ vf->offsets[i].time = avio_rb64(f);
+ vf->offsets[i].offset = avio_rb64(f);
+ } else {
+ vf->offsets[i].time = avio_rb32(f);
+ vf->offsets[i].offset = avio_rb32(f);
+ }
+ for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++)
+ avio_r8(f);
+ for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++)
+ avio_r8(f);
+ for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++)
+ avio_r8(f);
+ if (i > 0)
+ vf->offsets[i - 1].duration = vf->offsets[i].time -
+ vf->offsets[i - 1].time;
+ }
+ if (vf->chunks > 0)
+ vf->offsets[vf->chunks - 1].duration = vf->duration -
+ vf->offsets[vf->chunks - 1].time;
+ ret = 0;
+
+fail:
+ avio_seek(f, pos + size, SEEK_SET);
+ return ret;
+}
+
+static int read_mfra(struct VideoFiles *files, int start_index,
+ const char *file, int split)
+{
+ int err = 0;
+ AVIOContext *f = NULL;
+ int32_t mfra_size;
+
+ if ((err = avio_open2(&f, file, AVIO_FLAG_READ, NULL, NULL)) < 0)
+ goto fail;
+ avio_seek(f, avio_size(f) - 4, SEEK_SET);
+ mfra_size = avio_rb32(f);
+ avio_seek(f, -mfra_size, SEEK_CUR);
+ if (avio_rb32(f) != mfra_size)
+ goto fail;
+ if (avio_rb32(f) != MKBETAG('m', 'f', 'r', 'a'))
+ goto fail;
+ while (!read_tfra(files, start_index, f)) {
+ /* Empty */
+ }
+
+ if (split)
+ write_fragments(files, start_index, f);
+
+fail:
+ if (f)
+ avio_close(f);
+ return err;
+}
+
+static int get_private_data(struct VideoFile *vf, AVCodecContext *codec)
+{
+ vf->codec_private_size = codec->extradata_size;
+ vf->codec_private = av_mallocz(codec->extradata_size);
+ if (!vf->codec_private)
+ return AVERROR(ENOMEM);
+ memcpy(vf->codec_private, codec->extradata, codec->extradata_size);
+ return 0;
+}
+
+static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec)
+{
+ AVIOContext *io = NULL;
+ uint16_t sps_size, pps_size;
+ int err = AVERROR(EINVAL);
+
+ if (codec->codec_id == CODEC_ID_VC1)
+ return get_private_data(vf, codec);
+
+ avio_open_dyn_buf(&io);
+ if (codec->extradata_size < 11 || codec->extradata[0] != 1)
+ goto fail;
+ sps_size = AV_RB16(&codec->extradata[6]);
+ if (11 + sps_size > codec->extradata_size)
+ goto fail;
+ avio_wb32(io, 0x00000001);
+ avio_write(io, &codec->extradata[8], sps_size);
+ pps_size = AV_RB16(&codec->extradata[9 + sps_size]);
+ if (11 + sps_size + pps_size > codec->extradata_size)
+ goto fail;
+ avio_wb32(io, 0x00000001);
+ avio_write(io, &codec->extradata[11 + sps_size], pps_size);
+ err = 0;
+
+fail:
+ vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private);
+ return err;
+}
+
+static int handle_file(struct VideoFiles *files, const char *file, int split)
+{
+ AVFormatContext *ctx = NULL;
+ int err = 0, i, orig_files = files->nb_files;
+ char errbuf[50], *ptr;
+ struct VideoFile *vf;
+
+ err = avformat_open_input(&ctx, file, NULL, NULL);
+ if (err < 0) {
+ av_strerror(err, errbuf, sizeof(errbuf));
+ fprintf(stderr, "Unable to open %s: %s\n", file, errbuf);
+ return 1;
+ }
+
+ err = avformat_find_stream_info(ctx, NULL);
+ if (err < 0) {
+ av_strerror(err, errbuf, sizeof(errbuf));
+ fprintf(stderr, "Unable to identify %s: %s\n", file, errbuf);
+ goto fail;
+ }
+
+ if (ctx->nb_streams < 1) {
+ fprintf(stderr, "No streams found in %s\n", file);
+ goto fail;
+ }
+ if (!files->duration)
+ files->duration = ctx->duration;
+
+ for (i = 0; i < ctx->nb_streams; i++) {
+ AVStream *st = ctx->streams[i];
+ vf = av_mallocz(sizeof(*vf));
+ files->files = av_realloc(files->files,
+ sizeof(*files->files) * (files->nb_files + 1));
+ files->files[files->nb_files] = vf;
+
+ vf->name = file;
+ if ((ptr = strrchr(file, '/')) != NULL)
+ vf->name = ptr + 1;
+
+ vf->bitrate = st->codec->bit_rate;
+ vf->track_id = st->id;
+ vf->timescale = st->time_base.den;
+ vf->duration = av_rescale_rnd(ctx->duration, vf->timescale,
+ AV_TIME_BASE, AV_ROUND_UP);
+ vf->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO;
+ vf->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO;
+
+ if (!vf->is_audio && !vf->is_video) {
+ fprintf(stderr,
+ "Track %d in %s is neither video nor audio, skipping\n",
+ vf->track_id, file);
+ av_freep(&files->files[files->nb_files]);
+ continue;
+ }
+
+ if (vf->is_audio) {
+ if (files->audio_file < 0)
+ files->audio_file = files->nb_files;
+ files->nb_audio_files++;
+ vf->channels = st->codec->channels;
+ vf->sample_rate = st->codec->sample_rate;
+ if (st->codec->codec_id == CODEC_ID_AAC) {
+ vf->fourcc = "AACL";
+ vf->tag = 255;
+ vf->blocksize = 4;
+ } else if (st->codec->codec_id == CODEC_ID_WMAPRO) {
+ vf->fourcc = "WMAP";
+ vf->tag = st->codec->codec_tag;
+ vf->blocksize = st->codec->block_align;
+ }
+ get_private_data(vf, st->codec);
+ }
+ if (vf->is_video) {
+ if (files->video_file < 0)
+ files->video_file = files->nb_files;
+ files->nb_video_files++;
+ vf->width = st->codec->width;
+ vf->height = st->codec->height;
+ if (st->codec->codec_id == CODEC_ID_H264)
+ vf->fourcc = "H264";
+ else if (st->codec->codec_id == CODEC_ID_VC1)
+ vf->fourcc = "WVC1";
+ get_video_private_data(vf, st->codec);
+ }
+
+ files->nb_files++;
+ }
+
+ avformat_close_input(&ctx);
+
+ read_mfra(files, orig_files, file, split);
+
+fail:
+ if (ctx)
+ avformat_close_input(&ctx);
+ return err;
+}
+
+static void output_server_manifest(struct VideoFiles *files,
+ const char *basename)
+{
+ char filename[1000];
+ FILE *out;
+ int i;
+
+ snprintf(filename, sizeof(filename), "%s.ism", basename);
+ out = fopen(filename, "w");
+ if (!out) {
+ perror(filename);
+ return;
+ }
+ fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
+ fprintf(out, "<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n");
+ fprintf(out, "\t<head>\n");
+ fprintf(out, "\t\t<meta name=\"clientManifestRelativePath\" "
+ "content=\"%s.ismc\" />\n", basename);
+ fprintf(out, "\t</head>\n");
+ fprintf(out, "\t<body>\n");
+ fprintf(out, "\t\t<switch>\n");
+ for (i = 0; i < files->nb_files; i++) {
+ struct VideoFile *vf = files->files[i];
+ const char *type = vf->is_video ? "video" : "audio";
+ fprintf(out, "\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n",
+ type, vf->name, vf->bitrate);
+ fprintf(out, "\t\t\t\t<param name=\"trackID\" value=\"%d\" "
+ "valueType=\"data\" />\n", vf->track_id);
+ fprintf(out, "\t\t\t</%s>\n", type);
+ }
+ fprintf(out, "\t\t</switch>\n");
+ fprintf(out, "\t</body>\n");
+ fprintf(out, "</smil>\n");
+ fclose(out);
+}
+
+static void output_client_manifest(struct VideoFiles *files,
+ const char *basename, int split)
+{
+ char filename[1000];
+ FILE *out;
+ int i, j;
+
+ if (split)
+ snprintf(filename, sizeof(filename), "Manifest");
+ else
+ snprintf(filename, sizeof(filename), "%s.ismc", basename);
+ out = fopen(filename, "w");
+ if (!out) {
+ perror(filename);
+ return;
+ }
+ fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
+ fprintf(out, "<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" "
+ "Duration=\"%"PRId64 "\">\n", files->duration * 10);
+ if (files->video_file >= 0) {
+ struct VideoFile *vf = files->files[files->video_file];
+ int index = 0;
+ fprintf(out,
+ "\t<StreamIndex Type=\"video\" QualityLevels=\"%d\" "
+ "Chunks=\"%d\" "
+ "Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n",
+ files->nb_video_files, vf->chunks);
+ for (i = 0; i < files->nb_files; i++) {
+ vf = files->files[i];
+ if (!vf->is_video)
+ continue;
+ fprintf(out,
+ "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
+ "FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" "
+ "CodecPrivateData=\"",
+ index, vf->bitrate, vf->fourcc, vf->width, vf->height);
+ for (j = 0; j < vf->codec_private_size; j++)
+ fprintf(out, "%02X", vf->codec_private[j]);
+ fprintf(out, "\" />\n");
+ index++;
+ }
+ vf = files->files[files->video_file];
+ for (i = 0; i < vf->chunks; i++)
+ fprintf(out, "\t\t<c n=\"%d\" d=\"%d\" />\n", i,
+ vf->offsets[i].duration);
+ fprintf(out, "\t</StreamIndex>\n");
+ }
+ if (files->audio_file >= 0) {
+ struct VideoFile *vf = files->files[files->audio_file];
+ int index = 0;
+ fprintf(out,
+ "\t<StreamIndex Type=\"audio\" QualityLevels=\"%d\" "
+ "Chunks=\"%d\" "
+ "Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n",
+ files->nb_audio_files, vf->chunks);
+ for (i = 0; i < files->nb_files; i++) {
+ vf = files->files[i];
+ if (!vf->is_audio)
+ continue;
+ fprintf(out,
+ "\t\t<QualityLevel Index=\"%d\" Bitrate=\"%d\" "
+ "FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" "
+ "BitsPerSample=\"16\" PacketSize=\"%d\" "
+ "AudioTag=\"%d\" CodecPrivateData=\"",
+ index, vf->bitrate, vf->fourcc, vf->sample_rate,
+ vf->channels, vf->blocksize, vf->tag);
+ for (j = 0; j < vf->codec_private_size; j++)
+ fprintf(out, "%02X", vf->codec_private[j]);
+ fprintf(out, "\" />\n");
+ index++;
+ }
+ vf = files->files[files->audio_file];
+ for (i = 0; i < vf->chunks; i++)
+ fprintf(out, "\t\t<c n=\"%d\" d=\"%d\" />\n",
+ i, vf->offsets[i].duration);
+ fprintf(out, "\t</StreamIndex>\n");
+ }
+ fprintf(out, "</SmoothStreamingMedia>\n");
+ fclose(out);
+}
+
+static void clean_files(struct VideoFiles *files)
+{
+ int i;
+ for (i = 0; i < files->nb_files; i++) {
+ av_freep(&files->files[i]->codec_private);
+ av_freep(&files->files[i]->offsets);
+ av_freep(&files->files[i]);
+ }
+ av_freep(&files->files);
+ files->nb_files = 0;
+}
+
+int main(int argc, char **argv)
+{
+ const char *basename = NULL;
+ int split = 0, i;
+ struct VideoFiles vf = { 0, .video_file = -1, .audio_file = -1 };
+
+ av_register_all();
+
+ for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-n")) {
+ basename = argv[i + 1];
+ i++;
+ } else if (!strcmp(argv[i], "-split")) {
+ split = 1;
+ } else if (argv[i][0] == '-') {
+ return usage(argv[0], 1);
+ } else {
+ handle_file(&vf, argv[i], split);
+ }
+ }
+ if (!vf.nb_files || (!basename && !split))
+ return usage(argv[0], 1);
+
+ if (!split)
+ output_server_manifest(&vf, basename);
+ output_client_manifest(&vf, basename, split);
+
+ clean_files(&vf);
+
+ return 0;
+}
diff --git a/tools/lavfi-showfiltfmts.c b/tools/lavfi-showfiltfmts.c
index 26fccbb0ec..5647cbf523 100644
--- a/tools/lavfi-showfiltfmts.c
+++ b/tools/lavfi-showfiltfmts.c
@@ -97,11 +97,13 @@ int main(int argc, char **argv)
}
if (avfilter_open(&filter_ctx, filter, NULL) < 0) {
- fprintf(stderr, "Inpossible to open filter with name '%s'\n", filter_name);
+ fprintf(stderr, "Inpossible to open filter with name '%s'\n",
+ filter_name);
return 1;
}
if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) {
- fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", filter_name, filter_args);
+ fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
+ filter_name, filter_args);
return 1;
}
diff --git a/tools/pktdumper.c b/tools/pktdumper.c
index 999e1e6c63..0daa8e0941 100644
--- a/tools/pktdumper.c
+++ b/tools/pktdumper.c
@@ -24,11 +24,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "libavformat/avformat.h"
-#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin"
+#include "libavformat/avformat.h"
-#undef strcat
+#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"
static int usage(int ret)
{
@@ -46,10 +45,10 @@ int main(int argc, char **argv)
char pktfilename[PATH_MAX];
AVFormatContext *fctx = NULL;
AVPacket pkt;
- int64_t pktnum = 0;
+ int64_t pktnum = 0;
int64_t maxpkts = 0;
- int donotquit = 0;
- int nowrite = 0;
+ int donotquit = 0;
+ int nowrite = 0;
int err;
if ((argc > 1) && !strncmp(argv[1], "-", 1)) {
@@ -64,16 +63,16 @@ int main(int argc, char **argv)
return usage(1);
if (argc > 2)
maxpkts = atoi(argv[2]);
- strncpy(fntemplate, argv[1], PATH_MAX-1);
+ strncpy(fntemplate, argv[1], PATH_MAX - 1);
if (strrchr(argv[1], '/'))
- strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-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) {
+ if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX - 1) {
fprintf(stderr, "filename too long\n");
return usage(1);
}
@@ -99,11 +98,14 @@ int main(int argc, char **argv)
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 & AV_PKT_FLAG_KEY)?'K':'_');
- printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & AV_PKT_FLAG_KEY)?'K':'_');
+ snprintf(pktfilename, PATH_MAX - 1, fntemplate, pktnum,
+ pkt.stream_index, pkt.pts, pkt.size,
+ (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
+ printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size,
+ (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_');
//printf("open(\"%s\")\n", pktfilename);
if (!nowrite) {
- fd = open(pktfilename, O_WRONLY|O_CREAT, 0644);
+ fd = open(pktfilename, O_WRONLY | O_CREAT, 0644);
err = write(fd, pkt.data, pkt.size);
if (err < 0) {
fprintf(stderr, "write: error %d\n", err);
@@ -120,7 +122,7 @@ int main(int argc, char **argv)
avformat_close_input(&fctx);
while (donotquit)
- sleep(60);
+ usleep(60 * 1000000);
return 0;
}
diff --git a/tools/probetest.c b/tools/probetest.c
index b4bb5aea9e..36a05a3de1 100644
--- a/tools/probetest.c
+++ b/tools/probetest.c
@@ -39,7 +39,8 @@ static void probe(AVProbeData *pd, int type, int p, int size)
int score = fmt->read_probe(pd);
if (score > score_array[i] && score > AVPROBE_SCORE_MAX / 4) {
score_array[i] = score;
- fprintf(stderr, "Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
+ fprintf(stderr,
+ "Failure of %s probing code with score=%d type=%d p=%X size=%d\n",
fmt->name, score, type, p, size);
failures++;
}
@@ -75,9 +76,8 @@ int main(void)
init_put_bits(&pb, pd.buf, size);
switch (type) {
case 0:
- for (i = 0; i < size * 8; i++) {
+ for (i = 0; i < size * 8; i++)
put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20);
- }
break;
case 1:
for (i = 0; i < size * 8; i++) {
@@ -89,10 +89,10 @@ int main(void)
break;
case 2:
for (i = 0; i < size * 8; i++) {
- unsigned int p2 = (p >> (hist*3)) & 7;
+ unsigned int p2 = (p >> (hist * 3)) & 7;
unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29;
put_bits(&pb, 1, v);
- hist = (2*hist + v) & 3;
+ hist = (2 * hist + v) & 3;
}
break;
case 3:
@@ -100,12 +100,18 @@ int main(void)
int c = 0;
while (p & 63) {
c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24;
- if (c >= 'a' && c <= 'z' && (p & 1)) break;
- else if(c >= 'A' && c <= 'Z' && (p & 2)) break;
- else if(c >= '0' && c <= '9' && (p & 4)) break;
- else if(c == ' ' && (p & 8)) break;
- else if(c == 0 && (p & 16)) break;
- else if(c == 1 && (p & 32)) break;
+ if (c >= 'a' && c <= 'z' && (p & 1))
+ break;
+ else if (c >= 'A' && c <= 'Z' && (p & 2))
+ break;
+ else if (c >= '0' && c <= '9' && (p & 4))
+ break;
+ else if (c == ' ' && (p & 8))
+ break;
+ else if (c == 0 && (p & 16))
+ break;
+ else if (c == 1 && (p & 32))
+ break;
}
pd.buf[i] = c;
}
diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index 79467f0415..bb8e02eac9 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -138,7 +138,6 @@ int main(int argc, char *argv[])
}
start_offset = ftello(infile);
} else {
-
/* 64-bit special case */
if (atom_size == 1) {
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
diff --git a/tools/trasher.c b/tools/trasher.c
index 114eb78a68..61fd395f28 100644
--- a/tools/trasher.c
+++ b/tools/trasher.c
@@ -23,47 +23,50 @@
#include <inttypes.h>
static uint32_t state;
-static uint32_t ran(void){
- return state= state*1664525+1013904223;
+static uint32_t ran(void)
+{
+ return state = state * 1664525 + 1013904223;
}
-int main(int argc, char** argv)
+int main(int argc, char **argv)
{
FILE *f;
int count, maxburst, length;
- if (argc < 5){
+ if (argc < 5) {
printf("USAGE: trasher <filename> <count> <maxburst> <seed>\n");
return 1;
}
- f= fopen(argv[1], "rb+");
- if (!f){
+ f = fopen(argv[1], "rb+");
+ if (!f) {
perror(argv[1]);
return 2;
}
- count= atoi(argv[2]);
- maxburst= atoi(argv[3]);
- state= atoi(argv[4]);
+ count = atoi(argv[2]);
+ maxburst = atoi(argv[3]);
+ state = atoi(argv[4]);
fseek(f, 0, SEEK_END);
- length= ftell(f);
+ length = ftell(f);
fseek(f, 0, SEEK_SET);
- while(count--){
- int burst= 1 + ran() * (uint64_t) (abs(maxburst)-1) / UINT32_MAX;
- int pos= ran() * (uint64_t) length / UINT32_MAX;
+ while (count--) {
+ int burst = 1 + ran() * (uint64_t) (abs(maxburst) - 1) / UINT32_MAX;
+ int pos = ran() * (uint64_t) length / UINT32_MAX;
fseek(f, pos, SEEK_SET);
- if(maxburst<0) burst= -maxburst;
+ if (maxburst < 0)
+ burst = -maxburst;
- if(pos + burst > length)
+ if (pos + burst > length)
continue;
- while(burst--){
- int val= ran() * 256ULL / UINT32_MAX;
+ while (burst--) {
+ int val = ran() * 256ULL / UINT32_MAX;
- if(maxburst<0) val=0;
+ if (maxburst < 0)
+ val = 0;
fwrite(&val, 1, 1, f);
}