FFmpeg
Loading...
Searching...
No Matches
seek_print.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "config.h"
22#if HAVE_UNISTD_H
23#include <unistd.h> /* getopt */
24#endif
25
28#include "libavutil/timestamp.h"
29
30#if !HAVE_GETOPT
31#include "compat/getopt.c"
32#endif
33
34av_noreturn static void usage(int ret)
35{
36 fprintf(ret ? stderr : stdout,
37 "Usage: seek_print file [command ...]\n"
38 "Commands:\n"
39 " read\n"
40 " seek:stream:min_ts:ts:max_ts:flags\n"
41 );
42 exit(ret);
43}
44
45int main(int argc, char **argv)
46{
47 int opt, ret, stream, flags;
48 const char *filename;
49 AVFormatContext *avf = NULL;
50 int64_t min_ts, max_ts, ts;
51 AVPacket packet;
52
53 while ((opt = getopt(argc, argv, "h")) != -1) {
54 switch (opt) {
55 case 'h':
56 usage(0);
57 default:
58 usage(1);
59 }
60 }
61 argc -= optind;
62 argv += optind;
63 if (!argc)
64 usage(1);
65 filename = *argv;
66 argv++;
67 argc--;
68
69 if ((ret = avformat_open_input(&avf, filename, NULL, NULL)) < 0) {
70 fprintf(stderr, "%s: %s\n", filename, av_err2str(ret));
71 return 1;
72 }
73 if ((ret = avformat_find_stream_info(avf, NULL)) < 0) {
74 fprintf(stderr, "%s: could not find codec parameters: %s\n", filename,
75 av_err2str(ret));
76 return 1;
77 }
78
79 for (; argc; argc--, argv++) {
80 if (!strcmp(*argv, "read")) {
81 ret = av_read_frame(avf, &packet);
82 if (ret < 0) {
83 printf("read: %d (%s)\n", ret, av_err2str(ret));
84 } else {
85 AVRational *tb = &avf->streams[packet.stream_index]->time_base;
86 printf("read: %d size=%d stream=%d dts=%s (%s) pts=%s (%s)\n",
87 ret, packet.size, packet.stream_index,
88 av_ts2str(packet.dts), av_ts2timestr(packet.dts, tb),
89 av_ts2str(packet.pts), av_ts2timestr(packet.pts, tb));
90 av_packet_unref(&packet);
91 }
92 } else if (sscanf(*argv, "seek:%i:%"SCNi64":%"SCNi64":%"SCNi64":%i",
93 &stream, &min_ts, &ts, &max_ts, &flags) == 5) {
94 ret = avformat_seek_file(avf, stream, min_ts, ts, max_ts, flags);
95 printf("seek: %d (%s)\n", ret, av_err2str(ret));
96 } else {
97 fprintf(stderr, "'%s': unknown command\n", *argv);
98 return 1;
99 }
100 }
101
103
104 return 0;
105}
Main libavformat public API header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
__device__ int printf(const char *,...)
int main
Definition dovi_rpuenc.c:38
const char * usage
static int getopt(int argc, char *argv[], const char *opts)
Definition getopt.c:41
static int optind
Definition getopt.c:37
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition seek.c:664
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1588
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition demux.c:2606
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:377
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
Macro definitions for various function/variable attributes.
#define av_noreturn
Definition attributes.h:230
Format I/O context.
Definition avformat.h:1333
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
This structure stores compressed data.
Definition packet.h:580
int stream_index
Definition packet.h:605
int size
Definition packet.h:604
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition packet.h:596
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition packet.h:602
Rational number (pair of numerator and denominator).
Definition rational.h:58
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:805
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition timestamp.h:54
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition timestamp.h:83