FFmpeg
Loading...
Searching...
No Matches
demux_probe.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdio.h>
20
21#include "libavutil/error.h"
22#include "libavutil/log.h"
23#include "libavutil/pixfmt.h"
25#include "libavformat/demux.h"
26
27static int packets_read;
28static int corrupt_after;
30
32{
34
35 if (!st)
36 return AVERROR(ENOMEM);
37 st->time_base = (AVRational) { 1, 15 };
41 st->codecpar->width = 1;
42 st->codecpar->height = 1;
43 return 0;
44}
45
47{
48 int ret;
49
50 if (packets_read >= 450)
51 return AVERROR_EOF;
52 ret = av_new_packet(pkt, 1);
53 if (ret < 0)
54 return ret;
55 pkt->data[0] = 0;
56 pkt->stream_index = 0;
57 pkt->pts = pkt->dts = packets_read;
58 pkt->duration = 1;
60 pkt->pts = pkt->dts = corrupt_after +
62 pkt->duration = corrupt_duration;
63 pkt->flags |= AV_PKT_FLAG_CORRUPT;
64 }
66 return 0;
67}
68
70 .p.name = "test",
71 .p.flags = AVFMT_NOFILE,
72 .read_header = read_header,
73 .read_packet = read_packet,
74};
75
76int main(void)
77{
79 for (int corrupt = 0; corrupt < 3; corrupt++) {
81 int ret;
82
83 if (!s)
84 return 1;
85 packets_read = 0;
86 corrupt_after = corrupt ? 5 : 450;
87 corrupt_duration = corrupt == 2 ? 2 : 1;
88 s->max_analyze_duration = 500000;
89 /* Keep probing for FPS until the analysis-duration limit stops it. */
90 s->fps_probe_size = 1000;
92 if (ret >= 0)
94 if (ret >= 0) {
95 AVRational fps = s->streams[0]->avg_frame_rate;
96 printf("%s: packets=%d fps=%d/%d\n",
97 corrupt == 2 ? "corrupt-long" : corrupt ? "corrupt" : "clean",
98 packets_read, fps.num, fps.den);
99 }
101 if (ret < 0)
102 return 1;
103 }
104 return 0;
105}
Main libavformat public API header.
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition avformat.h:490
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
static AVPacket * pkt
static const FFInputFormat test_demuxer
Definition demux_probe.c:69
static int read_packet(AVFormatContext *s, AVPacket *pkt)
Definition demux_probe.c:46
int main(void)
Definition demux_probe.c:76
static int packets_read
Definition demux_probe.c:27
static int corrupt_after
Definition demux_probe.c:28
static int corrupt_duration
Definition demux_probe.c:29
static int read_header(AVFormatContext *s)
Definition demux_probe.c:31
error code definitions
int ret
Definition ffplay.c:391
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:580
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition packet.h:658
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
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:2674
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:400
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
void av_log_set_level(int level)
Set the log level.
Definition log.c:482
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
pixel format definitions
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1401
This structure stores compressed data.
Definition packet.h:587
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807