2 * Copyright (c) 2013 Nicolas George
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
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
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <unistd.h> /* getopt */
28 #include "libavformat/avformat.h"
29 #include "libavutil/timestamp.h"
32 #include "compat/getopt.c"
35 static void usage(int ret)
37 fprintf(ret ? stderr : stdout,
38 "Usage: seek_print file [command ...]\n"
41 " seek:stream:min_ts:ts:max_ts:flags\n"
46 int main(int argc, char **argv)
48 int opt, ret, stream, flags;
50 AVFormatContext *avf = NULL;
51 int64_t min_ts, max_ts, ts;
54 while ((opt = getopt(argc, argv, "h")) != -1) {
71 if ((ret = avformat_open_input(&avf, filename, NULL, NULL)) < 0) {
72 fprintf(stderr, "%s: %s\n", filename, av_err2str(ret));
75 if ((ret = avformat_find_stream_info(avf, NULL)) < 0) {
76 fprintf(stderr, "%s: could not find codec parameters: %s\n", filename,
81 for (; argc; argc--, argv++) {
82 if (!strcmp(*argv, "read")) {
83 ret = av_read_frame(avf, &packet);
85 printf("read: %d (%s)\n", ret, av_err2str(ret));
87 AVRational *tb = &avf->streams[packet.stream_index]->time_base;
88 printf("read: %d size=%d stream=%d dts=%s (%s) pts=%s (%s)\n",
89 ret, packet.size, packet.stream_index,
90 av_ts2str(packet.dts), av_ts2timestr(packet.dts, tb),
91 av_ts2str(packet.pts), av_ts2timestr(packet.pts, tb));
92 av_free_packet(&packet);
94 } else if (sscanf(*argv, "seek:%i:%"SCNi64":%"SCNi64":%"SCNi64":%i",
95 &stream, &min_ts, &ts, &max_ts, &flags) == 5) {
96 ret = avformat_seek_file(avf, stream, min_ts, ts, max_ts, flags);
97 printf("seek: %d (%s)\n", ret, av_err2str(ret));
99 fprintf(stderr, "'%s': unknown command\n", *argv);
104 avformat_close_input(&avf);