2 * Copyright (c) 2012 Martin Storsjo
4 * This file is part of Libav.
6 * Libav 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.
11 * Libav 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "libavformat/avformat.h"
26 #include "libavformat/riff.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/mathematics.h"
30 static int usage(const char *argv0, int ret)
32 fprintf(stderr, "%s [-b bytespersec] input_url output_url\n", argv0);
36 int main(int argc, char **argv)
39 const char *input_url = NULL, *output_url = NULL;
40 int64_t stream_pos = 0;
43 AVIOContext *input, *output;
46 avformat_network_init();
48 for (i = 1; i < argc; i++) {
49 if (!strcmp(argv[i], "-b")) {
50 bps = atoi(argv[i + 1]);
52 } else if (!input_url) {
54 } else if (!output_url) {
57 return usage(argv[0], 1);
61 return usage(argv[0], 1);
63 ret = avio_open2(&input, input_url, AVIO_FLAG_READ, NULL, NULL);
65 av_strerror(ret, errbuf, sizeof(errbuf));
66 fprintf(stderr, "Unable to open %s: %s\n", input_url, errbuf);
69 ret = avio_open2(&output, output_url, AVIO_FLAG_WRITE, NULL, NULL);
71 av_strerror(ret, errbuf, sizeof(errbuf));
72 fprintf(stderr, "Unable to open %s: %s\n", output_url, errbuf);
76 start_time = av_gettime();
80 n = avio_read(input, buf, sizeof(buf));
83 avio_write(output, buf, n);
87 while ((av_gettime() - start_time)*bps/AV_TIME_BASE < stream_pos)
95 avformat_network_deinit();