1 /*
2 * Copyright (c) 2015 Matthieu Bouron <matthieu.bouron stupeflix.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 #include <stdio.h>
29
31 {
32 int ret = 0;
33 int got_frame = 0;
36
39
41 if (ret < 0) {
44 }
45 }
46
48 if (!frame) {
51 }
52
55 }
56
57 do {
60 if (ret < 0)
61 break;
64
65 if (got_frame) {
66 break;
67 }
68 }
while (pkt->
size > 0);
69
72
74 return ret;
75 }
76
78 {
79 int ret = 0;
80 int i, done = 0;
82
84
85 while (!done) {
88
92 }
93
95 codec_ctx = st->codec;
96
97 /* Writing to AVStream.codec_info_nb_frames must not be done by
98 * user applications. It is done here for testing purposing as
99 * find_video_stream_info tries to mimic avformat_find_stream_info
100 * which writes to this field.
101 * */
105 continue;
106 }
107
109 if (ret < 0) {
112 }
113
115
116 /* check if all video streams have demuxed a packet */
117 done = 1;
120 codec_ctx = st->codec;
121
123 continue;
124
126 }
127 }
128
131
132 /* close all codecs opened in try_decode_video_frame */
136 }
137
138 return ret < 0;
139 }
140
142 {
143 int i;
144
149
150 printf("stream=%d, decode=%d\n", i, decode);
153
155 continue;
156
157 if (!strcmp(opt->
name,
"frame_number"))
158 continue;
159
161 printf(
" %s=%s\n", opt->
name, str);
163 }
164 }
165 }
166 }
167
169 {
170 int ret = 0;
171
173 if (ret < 0) {
176 }
177
179 if (ret < 0) {
181 }
182
184
186 return ret;
187 }
188
190 {
191 int i;
192 int ret = 0;
193
201
203 continue;
204
207
209 continue;
210
211 if (!strcmp(opt->
name,
"frame_number"))
212 continue;
213
216 if (strcmp(str1, str2)) {
219 }
222 }
223 }
224
225 return ret;
226 }
227
228 int main(
int argc,
char* argv[])
229 {
230 int ret = 0;
233
234 if (argc < 2) {
236 return -1;
237 }
238
242 }
243
247 }
248
250
254
255 return ret;
256 }
const struct AVCodec * codec
This structure describes decoded (raw) audio or video data.
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
int main(int argc, char *argv[])
static AVFormatContext * fmt_ctx
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
enum AVDiscard skip_frame
Skip decoding for selected frames.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int find_video_stream_info(AVFormatContext *fmt_ctx, int decode)
static av_cold int end(AVCodecContext *avctx)
AVStream ** streams
A list of all streams in the file.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int try_decode_video_frame(AVCodecContext *codec_ctx, AVPacket *pkt, int decode)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int avcodec_is_open(AVCodecContext *s)
simple assert() macros that are a bit more flexible than ISO C assert().
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
enum AVMediaType codec_type
attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
static int open_and_probe_video_streams(AVFormatContext **fmt_ctx, const char *filename, int decode)
main external API structure.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
static void dump_video_streams(const AVFormatContext *fmt_ctx, int decode)
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static int check_video_streams(const AVFormatContext *fmt_ctx1, const AVFormatContext *fmt_ctx2)
common internal api header.
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
This structure stores compressed data.