51 #include <SDL_thread.h> 62 #define MAX_QUEUE_SIZE (15 * 1024 * 1024) 63 #define MIN_AUDIOQ_SIZE (20 * 16 * 1024) 68 #define SDL_AUDIO_BUFFER_SIZE 1024 71 #define AV_SYNC_THRESHOLD 0.01 73 #define AV_NOSYNC_THRESHOLD 10.0 75 #define FRAME_SKIP_FACTOR 0.05 78 #define SAMPLE_CORRECTION_PERCENT_MAX 10 81 #define AUDIO_DIFF_AVG_NB 20 84 #define SAMPLE_ARRAY_SIZE (2 * 65536) 97 #define VIDEO_PICTURE_QUEUE_SIZE 2 98 #define SUBPICTURE_QUEUE_SIZE 4 276 #define FF_ALLOC_EVENT (SDL_USEREVENT) 277 #define FF_REFRESH_EVENT (SDL_USEREVENT + 1) 278 #define FF_QUIT_EVENT (SDL_USEREVENT + 2) 288 q->
mutex = SDL_CreateMutex();
289 q->
cond = SDL_CreateCond();
297 SDL_LockMutex(q->
mutex);
307 SDL_UnlockMutex(q->
mutex);
313 SDL_DestroyMutex(q->
mutex);
314 SDL_DestroyCond(q->
cond);
328 SDL_LockMutex(q->
mutex);
339 SDL_CondSignal(q->
cond);
341 SDL_UnlockMutex(q->
mutex);
347 SDL_LockMutex(q->
mutex);
351 SDL_CondSignal(q->
cond);
353 SDL_UnlockMutex(q->
mutex);
362 SDL_LockMutex(q->
mutex);
388 SDL_UnlockMutex(q->
mutex);
393 int x,
int y,
int w,
int h,
int color)
400 SDL_FillRect(screen, &rect, color);
403 #define ALPHA_BLEND(a, oldp, newp, s)\ 404 ((((oldp << s) * (255 - (a))) + (newp * (a))) / (255 << s)) 406 #define RGBA_IN(r, g, b, a, s)\ 408 unsigned int v = ((const uint32_t *)(s))[0];\ 409 a = (v >> 24) & 0xff;\ 410 r = (v >> 16) & 0xff;\ 411 g = (v >> 8) & 0xff;\ 415 #define YUVA_IN(y, u, v, a, s, pal)\ 417 unsigned int val = ((const uint32_t *)(pal))[*(const uint8_t*)(s)];\ 418 a = (val >> 24) & 0xff;\ 419 y = (val >> 16) & 0xff;\ 420 u = (val >> 8) & 0xff;\ 424 #define YUVA_OUT(d, y, u, v, a)\ 426 ((uint32_t *)(d))[0] = (a << 24) | (y << 16) | (u << 8) | v;\ 435 int wrap, wrap3, width2, skip2;
436 int y,
u, v,
a, u1, v1, a1, w, h;
440 int dstx, dsty, dstw, dsth;
442 dstw = av_clip(rect->
w, 0, imgw);
443 dsth = av_clip(rect->
h, 0, imgh);
444 dstx = av_clip(rect->
x, 0, imgw - dstw);
445 dsty = av_clip(rect->
y, 0, imgh - dsth);
447 lum = dst[0] + dsty * dst_linesize[0];
448 cb = dst[2] + (dsty >> 1) * dst_linesize[2];
449 cr = dst[1] + (dsty >> 1) * dst_linesize[1];
451 width2 = ((dstw + 1) >> 1) + (dstx & ~dstw & 1);
453 wrap = dst_linesize[0];
456 pal = (
const uint32_t *)rect->
data[1];
473 for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
500 p += wrap3 - dstw *
BPP;
501 lum += wrap - dstw - dstx;
502 cb += dst_linesize[2] - width2 - skip2;
503 cr += dst_linesize[1] - width2 - skip2;
505 for (h = dsth - (dsty & 1); h >= 2; h -= 2) {
530 for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
562 p += -wrap3 + 2 *
BPP;
585 p += wrap3 + (wrap3 - dstw *
BPP);
586 lum += wrap + (wrap - dstw - dstx);
587 cb += dst_linesize[2] - width2 - skip2;
588 cr += dst_linesize[1] - width2 - skip2;
606 for (w = dstw - (dstx & 1); w >= 2; w -= 2) {
654 if (aspect_ratio <= 0.0)
656 aspect_ratio *= (float)vp->
width / (
float)vp->
height;
666 SDL_LockYUVOverlay (vp->
bmp);
672 SDL_UnlockYUVOverlay (vp->
bmp);
680 width = ((int)
rint(height * aspect_ratio)) & ~1;
681 if (width > is->
width) {
683 height = ((int)
rint(width / aspect_ratio)) & ~1;
688 rect.x = is->
xleft + x;
689 rect.y = is->
ytop + y;
692 SDL_DisplayYUVOverlay(vp->
bmp, &rect);
714 int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
715 int ch, channels, h, h2, bgcolor, fgcolor;
717 int rdft_bits, nb_freq;
719 for (rdft_bits = 1; (1 << rdft_bits) < 2 * s->
height; rdft_bits++)
721 nb_freq = 1 << (rdft_bits - 1);
725 nb_display_channels = channels;
739 delay += 2 * data_used;
740 if (delay < data_used)
746 for (i = 0; i < 1000; i += channels) {
753 if (h < score && (b ^ c) < 0) {
765 bgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0x00);
771 fgcolor = SDL_MapRGB(
screen->format, 0xff, 0xff, 0xff);
774 h = s->
height / nb_display_channels;
777 for (ch = 0; ch < nb_display_channels; ch++) {
779 y1 = s->
ytop + ch * h + (h / 2);
780 for (x = 0; x < s->
width; x++) {
789 s->
xleft + x, ys, 1, y,
797 fgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0xff);
799 for (ch = 1; ch < nb_display_channels; ch++) {
800 y = s->
ytop + ch * h;
807 nb_display_channels=
FFMIN(nb_display_channels, 2);
817 for (ch = 0; ch < nb_display_channels; ch++) {
818 data[ch] = s->
rdft_data + 2 * nb_freq * ch;
820 for (x = 0; x < 2 * nb_freq; x++) {
821 double w = (x-nb_freq) * (1.0 / nb_freq);
831 for (y = 0; y < s->
height; y++) {
832 double w = 1 / sqrt(nb_freq);
833 int a = sqrt(w * sqrt(data[0][2 * y + 0] * data[0][2 * y + 0] + data[0][2 * y + 1] * data[0][2 * y + 1]));
834 int b = (nb_display_channels == 2 ) ? sqrt(w * sqrt(data[1][2 * y + 0] * data[1][2 * y + 0]
835 + data[1][2 * y + 1] * data[1][2 * y + 1])) : a;
838 fgcolor = SDL_MapRGB(
screen->format, a, b, (a + b) / 2);
854 int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
858 else flags |= SDL_RESIZABLE;
877 #if defined(__APPLE__) && !SDL_VERSION_ATLEAST(1, 2, 14) 879 screen = SDL_SetVideoMode(w, h, 24, flags);
881 screen = SDL_SetVideoMode(w, h, 0, flags);
884 fprintf(stderr,
"SDL: could not set video mode - exiting\n");
914 event.user.data1 = opaque;
917 SDL_PushEvent(&event);
928 int hw_buf_size, bytes_per_sec;
937 pts -= (double)hw_buf_size / bytes_per_sec;
1008 double delay, sync_threshold, diff = 0;
1012 if (delay <= 0 || delay >= 10.0) {
1032 if (diff <= -sync_threshold)
1034 else if (diff >= sync_threshold)
1041 delay, frame_current_pts, -diff);
1064 if (time < vp->target_clock)
1079 if (is->
pictq_size > 1 || time > next_target + 0.5) {
1160 static int64_t last_time;
1162 int aqsize, vqsize, sqsize;
1166 if (!last_time || (cur_time - last_time) >= 30000) {
1179 printf(
"%7.2f A-V:%7.3f s:%3.1f aq=%5dKB vq=%5dKB sq=%5dB f=%"PRId64
"/%"PRId64
" \r",
1183 last_time = cur_time;
1201 SDL_FreeYUVOverlay(vp->
bmp);
1237 SDL_FreeYUVOverlay(vp->
bmp);
1246 if (!vp->
bmp || vp->
bmp->pitches[0] < vp->
width) {
1249 fprintf(stderr,
"Error: the video system does not support an image\n" 1250 "size of %dx%d pixels. Try using -vf \"scale=w:h\"\n" 1251 "to reduce the image size.\n", vp->
width, vp->
height );
1298 event.user.data1 = is;
1299 SDL_PushEvent(&event);
1318 SDL_LockYUVOverlay (vp->
bmp);
1320 data[0] = vp->
bmp->pixels[0];
1321 data[1] = vp->
bmp->pixels[2];
1322 data[2] = vp->
bmp->pixels[1];
1324 linesize[0] = vp->
bmp->pitches[0];
1325 linesize[1] = vp->
bmp->pitches[2];
1326 linesize[2] = vp->
bmp->pitches[1];
1333 SDL_UnlockYUVOverlay(vp->
bmp);
1354 double frame_delay,
pts;
1369 frame_delay += src_frame->
repeat_pict * (frame_delay * 0.5);
1437 char sws_flags_str[128];
1438 char buffersrc_args[256];
1443 snprintf(sws_flags_str,
sizeof(sws_flags_str),
"flags=%"PRId64,
sws_flags);
1446 snprintf(buffersrc_args,
sizeof(buffersrc_args),
"%d:%d:%d:%d:%d:%d:%d",
1454 "src", buffersrc_args,
NULL,
1462 last_filter = filt_out;
1466 #define INSERT_FILT(name, arg) do { \ 1467 AVFilterContext *filt_ctx; \ 1469 ret = avfilter_graph_create_filter(&filt_ctx, \ 1470 avfilter_get_by_name(name), \ 1471 "avplay_" name, arg, NULL, graph); \ 1475 ret = avfilter_link(filt_ctx, 0, last_filter, 0); \ 1479 last_filter = filt_ctx; \ 1487 if (displaymatrix) {
1489 if (rot < -135 || rot > 135) {
1492 }
else if (rot < -45) {
1494 }
else if (rot > 45) {
1586 frame->
pts = pts_int;
1598 pts_int = frame->
pts;
1604 "tb:%d/%d pts:%"PRId64
" -> tb:%d/%d pts:%"PRId64
"\n",
1639 int r,
g,
b, y,
u, v,
a;
1671 &got_subtitle, pkt);
1673 if (got_subtitle && sp->
sub.
format == 0) {
1705 size = samples_size /
sizeof(short);
1722 int samples_size1,
double pts)
1724 int n, samples_size;
1728 samples_size = samples_size1;
1733 double diff, avg_diff;
1734 int wanted_size, min_size, max_size, nb_samples;
1750 nb_samples = samples_size / n;
1754 if (wanted_size < min_size)
1755 wanted_size = min_size;
1756 else if (wanted_size > max_size)
1757 wanted_size = max_size;
1760 if (wanted_size < samples_size) {
1762 samples_size = wanted_size;
1763 }
else if (wanted_size > samples_size) {
1768 nb = (samples_size - wanted_size);
1769 samples_end = (
uint8_t *)samples + samples_size - n;
1770 q = samples_end + n;
1772 memcpy(q, samples_end, n);
1776 samples_size = wanted_size;
1780 diff, avg_diff, samples_size - samples_size1,
1791 return samples_size;
1800 int n, len1, data_size, got_frame;
1803 int flush_complete = 0;
1807 while (pkt_temp->
size > 0 || (!pkt_temp->
data && new_packet)) {
1808 int resample_changed, audio_resample;
1825 pkt_temp->
data += len1;
1826 pkt_temp->
size -= len1;
1846 if ((!is->
avr && audio_resample) || resample_changed) {
1850 else if (audio_resample) {
1853 fprintf(stderr,
"error allocating AVAudioResampleContext\n");
1857 if (audio_resample) {
1866 fprintf(stderr,
"error initializing libavresample\n");
1875 if (audio_resample) {
1877 int out_samples,
out_size, out_linesize;
1892 out_linesize, nb_samples,
1896 if (out_samples < 0) {
1897 fprintf(stderr,
"avresample_convert() failed\n");
1914 static double last_clock;
1915 printf(
"audio: delay=%0.3f clock=%0.3f pts=%0.3f\n",
1927 memset(pkt_temp, 0,
sizeof(*pkt_temp));
1955 int audio_size, len1;
1963 if (audio_size < 0) {
2003 if (codec->
type != type) {
2013 char *codec_name =
NULL;
2038 SDL_AudioSpec wanted_spec, spec;
2043 if (stream_index < 0 || stream_index >= ic->
nb_streams)
2090 fprintf(stderr,
"unable to guess channel layout\n");
2100 wanted_spec.format = AUDIO_S16SYS;
2103 wanted_spec.silence = 0;
2106 wanted_spec.userdata = is;
2107 if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
2108 fprintf(stderr,
"SDL_OpenAudio: %s\n", SDL_GetError());
2170 if (stream_index < 0 || stream_index >= ic->
nb_streams)
2255 return global_video_state && global_video_state->
abort_request;
2261 global_video_state =
NULL;
2282 int orig_nb_streams;
2284 memset(st_index, -1,
sizeof(st_index));
2289 global_video_state = is;
2323 for (i = 0; i < orig_nb_streams; i++)
2328 fprintf(stderr,
"%s: could not find codec parameters\n", is->
filename);
2349 fprintf(stderr,
"%s: could not seek to position %0.3f\n",
2364 st_index[AVMEDIA_TYPE_VIDEO],
2370 (st_index[AVMEDIA_TYPE_AUDIO] >= 0 ?
2371 st_index[AVMEDIA_TYPE_AUDIO] :
2372 st_index[AVMEDIA_TYPE_VIDEO]),
2379 if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
2384 if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
2392 if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) {
2397 fprintf(stderr,
"%s: could not open codecs\n", is->
filename);
2414 int pkt_in_play_range = 0;
2427 #if CONFIG_RTSP_DEMUXER 2436 int64_t seek_target = is->
seek_pos;
2437 int64_t seek_min = is->
seek_rel > 0 ? seek_target - is->
seek_rel + 2: INT64_MIN;
2438 int64_t seek_max = is->
seek_rel < 0 ? seek_target - is->
seek_rel - 2: INT64_MAX;
2444 fprintf(stderr,
"%s: error while seeking\n", is->
ic->
filename);
2539 event.user.data1 = is;
2540 SDL_PushEvent(&event);
2581 int start_index, stream_index;
2592 stream_index = start_index;
2603 if (stream_index == start_index)
2605 st = ic->
streams[stream_index];
2608 switch (codec_type) {
2630 #if defined(__APPLE__) && SDL_VERSION_ATLEAST(1, 2, 14) 2660 int bgcolor = SDL_MapRGB(
screen->format, 0x00, 0x00, 0x00);
2700 double incr, pos, frac;
2704 SDL_WaitEvent(&event);
2705 switch (event.type) {
2711 switch (event.key.keysym.sym) {
2784 case SDL_MOUSEBUTTONDOWN:
2789 case SDL_MOUSEMOTION:
2790 if (event.type == SDL_MOUSEBUTTONDOWN) {
2793 if (event.motion.state != SDL_PRESSED)
2804 int tns, thh, tmm, tss;
2807 tmm = (tns % 3600) / 60;
2809 frac = x / player->
width;
2812 mm = (ns % 3600) / 60;
2814 fprintf(stderr,
"Seek to %2.0f%% (%2d:%02d:%02d) of total duration (%2d:%02d:%02d) \n", frac*100,
2815 hh, mm, ss, thh, tmm, tss);
2823 case SDL_VIDEORESIZE:
2825 screen = SDL_SetVideoMode(event.resize.w, event.resize.h, 0,
2826 SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL);
2856 "Option '%s' has been removed, use private format options instead\n", opt);
2860 static int opt_width(
void *optctx,
const char *opt,
const char *arg)
2866 static int opt_height(
void *optctx,
const char *opt,
const char *arg)
2872 static int opt_format(
void *optctx,
const char *opt,
const char *arg)
2875 if (!file_iformat) {
2876 fprintf(stderr,
"Unknown input format: %s\n", arg);
2885 "Option '%s' has been removed, use private format options instead\n", opt);
2889 static int opt_sync(
void *optctx,
const char *opt,
const char *arg)
2891 if (!strcmp(arg,
"audio"))
2893 else if (!strcmp(arg,
"video"))
2895 else if (!strcmp(arg,
"ext"))
2898 fprintf(stderr,
"Unknown value for %s: %s\n", opt, arg);
2904 static int opt_seek(
void *optctx,
const char *opt,
const char *arg)
2916 #define OFF(x) offsetof(PlayerState, x) 2919 {
"x",
HAS_ARG, { .func_arg =
opt_width },
"force displayed width",
"width" },
2920 {
"y",
HAS_ARG, { .func_arg =
opt_height },
"force displayed height",
"height" },
2928 {
"ss",
HAS_ARG, { .func_arg =
opt_seek },
"seek to a given position in seconds",
"pos" },
2929 {
"t",
HAS_ARG, { .func_arg =
opt_duration },
"play \"duration\" seconds of audio/video",
"duration" },
2944 {
"sync",
HAS_ARG |
OPT_EXPERT, { .func_arg =
opt_sync },
"set audio-video sync. type (type=audio/video/ext)",
"type" },
2955 {
"i", 0, {
NULL },
"avconv compatibility dummy option",
""},
2965 printf(
"Simple media player\n");
2966 printf(
"usage: %s [options] input_file\n",
program_name);
2979 printf(
"\nWhile playing:\n" 2981 "f toggle full screen\n" 2983 "a cycle audio channel\n" 2984 "v cycle video channel\n" 2985 "t cycle subtitle channel\n" 2986 "w show audio waves\n" 2987 "s activate frame-step mode\n" 2988 "left/right seek backward/forward 10 seconds\n" 2989 "down/up seek backward/forward 1 minute\n" 2990 "mouse click seek to percentage in file corresponding to fraction of width\n" 2997 fprintf(stderr,
"Argument '%s' provided as input filename, but '%s' was already specified.\n",
3001 if (!strcmp(filename,
"-"))
3031 fprintf(stderr,
"An input file must be specified\n");
3032 fprintf(stderr,
"Use -h to get full help or, even better, run 'man %s'\n",
program_name);
3039 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
3040 #if !defined(__MINGW32__) && !defined(__APPLE__) 3041 flags |= SDL_INIT_EVENTTHREAD;
3043 if (SDL_Init (flags)) {
3044 fprintf(stderr,
"Could not initialize SDL - %s\n", SDL_GetError());
3049 const SDL_VideoInfo *vi = SDL_GetVideoInfo();
3054 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
3055 SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
3056 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
3062 fprintf(stderr,
"Could not setup the player\n");
unsigned int nb_chapters
Number of chapters in AVChapter array.
double audio_diff_avg_coef
uint64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
int64_t num_faulty_dts
Number of incorrect PTS values so far.
const struct AVCodec * codec
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static void update_sample_display(PlayerState *is, short *samples, int samples_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int audio_write_get_buf_size(PlayerState *is)
int64_t avio_size(AVIOContext *s)
Get the filesize.
This structure describes decoded (raw) audio or video data.
static double rint(double x)
int x
top left corner of pict, undefined when pict is not set
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
static int subtitle_thread(void *arg)
enum AVSampleFormat sdl_sample_fmt
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
static const AVFilterPad outputs[]
int avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t *const *input, int in_plane_size, int in_samples)
Convert input samples and write them to the output FIFO.
Main libavfilter public API header.
int64_t pos
byte position in stream, -1 if unknown
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Memory buffer source API.
static int workaround_bugs
void show_banner(void)
Print the program banner to stderr.
static void free_subpicture(SubPicture *sp)
attribute_deprecated int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph.
struct AVFilterInOut * next
next input/input in the list, NULL if this is the last
int h
agreed upon image height
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int repeat_pict
When decoding, this signals how much the picture must be delayed.
int nb_colors
number of colors in pict, undefined when pict is not set
static void toggle_pause(void)
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static double get_audio_clock(PlayerState *is)
Various defines for YUV<->RGB conversion.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
enum AVMediaType codec_type
static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
uint8_t * av_stream_get_side_data(AVStream *stream, enum AVPacketSideDataType type, int *size)
Get side information from stream.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static void packet_queue_abort(PacketQueue *q)
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
enum AVPixelFormat pix_fmt
static int configure_video_filters(AVFilterGraph *graph, PlayerState *is, const char *vfilters)
int av_usleep(unsigned usec)
Sleep for a period of time.
int subtitle_stream_changed
#define AV_CH_LAYOUT_STEREO
static void packet_queue_flush(PacketQueue *q)
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]
const int program_birth_year
program birth year, defined by the program for show_banner()
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Filter out options for given codec.
This struct describes the properties of an encoded stream.
void init_pts_correction(PtsCorrectionContext *ctx)
Reset the state of the PtsCorrectionContext.
static double get_master_clock(PlayerState *is)
static void video_audio_display(PlayerState *s)
static int get_video_frame(PlayerState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt)
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values.
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
AVFilterContext * in_video_filter
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static AVInputFormat * file_iformat
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static void video_display(PlayerState *is)
static void opt_input_file(void *optctx, const char *filename)
enum AVDiscard skip_frame
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
static int opt_format(void *optctx, const char *opt, const char *arg)
#define AV_LOG_QUIET
Print no output.
static int stream_component_open(PlayerState *is, int stream_index)
int w
width of pict, undefined when pict is not set
static void blend_subrect(uint8_t *dst[4], uint16_t dst_linesize[4], const AVSubtitleRect *rect, int imgw, int imgh)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
AVFilterLink ** inputs
array of pointers to input links
#define SAMPLE_ARRAY_SIZE
uint64_t sdl_channel_layout
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together.
static double get_video_clock(PlayerState *is)
void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Trivial log callback.
static double get_external_clock(PlayerState *is)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int stream_setup(PlayerState *is)
int opt_default(void *optctx, const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions...
static int opt_frame_pix_fmt(void *optctx, const char *opt, const char *arg)
static int wanted_stream[AVMEDIA_TYPE_NB]
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
static int decode_thread(void *arg)
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define RGBA_IN(r, g, b, a, s)
static void stream_close(PlayerState *is)
void init_opts(void)
Initialize the cmdutils option system, in particular allocate the *_opts contexts.
AVStream ** streams
A list of all streams in the file.
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
void avfilter_register_all(void)
Initialize the filter system.
static PlayerState * player
AVCodecContext * audio_dec
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt, const char *name, const char *args, void *opaque, AVFilterGraph *graph_ctx)
Create and add a filter instance into an existing graph.
static PlayerState player_state
static double av_q2d(AVRational a)
Convert rational to double.
static int synchronize_audio(PlayerState *is, short *samples, int samples_size1, double pts)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void(*parse_arg_function)(void *, const char *))
int avformat_network_init(void)
Do global initialization of network components.
#define AVERROR_EOF
End of file.
#define AV_LOG_VERBOSE
Detailed information.
static const OptionDef options[]
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
void parse_loglevel(int argc, char **argv, const OptionDef *options)
Find the '-loglevel' option in the command line args and apply it.
int h
height of pict, undefined when pict is not set
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define INSERT_FILT(name, arg)
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Print help for all options matching specified flags.
double video_current_pts_drift
static AVPacket flush_pkt
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
SpecifierOpt * codec_names
int64_t external_clock_time
AVDictionary * format_opts
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate, streams, container, programs, metadata, side data, codec and time base.
Main libavdevice API header.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
static int64_t start_time
static void packet_queue_end(PacketQueue *q)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
unsigned int audio_buf_size
int main(int argc, char **argv)
static void show_usage(void)
int y
top left corner of pict, undefined when pict is not set
static int decode_interrupt_cb(void *ctx)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
uint64_t resample_channel_layout
int error_concealment
error concealment flags
int capabilities
Codec capabilities.
int av_read_play(AVFormatContext *s)
Start playing a network-based stream (e.g.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
enum AVMediaType codec_type
General type of the encoded data.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
static enum AVDiscard skip_idct
#define AV_LOG_SKIP_REPEATED
Skip repeated messages, this requires the user app to use av_log() instead of (f)printf as the 2 woul...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
static int64_t audio_callback_time
const char * name
Name of the codec implementation.
static double compute_target_time(double frame_current_pts, PlayerState *is)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
#define AV_NOSYNC_THRESHOLD
uint64_t channel_layout
Audio channel layout.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
uint32_t end_display_time
int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
Attempt to guess proper monotonic timestamps for decoded video frames which might have incorrect time...
uint64_t channel_layout
Channel layout of the audio data.
int w
agreed upon image width
static int fs_screen_width
AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
static int refresh_thread(void *opaque)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static void toggle_audio_display(void)
int av_read_pause(AVFormatContext *s)
Pause a network-based stream (e.g.
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
char filename[1024]
input or output filename
#define AV_TIME_BASE
Internal time base represented as integer.
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int width
picture width / height.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
#define AV_SYNC_THRESHOLD
static int audio_decode_frame(PlayerState *is, double *pts_ptr)
AVCodecContext * video_dec
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color)
double audio_diff_threshold
void av_rdft_end(RDFTContext *s)
char * specifier
stream/chapter/program/...
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
static AVCodec * find_codec_or_die(const char *name, enum AVMediaType type)
enum AVPixelFormat pix_fmt
uint8_t * data[4]
data+linesize for the bitmap of this subtitle.
const AVCodecDescriptor * avcodec_descriptor_get_by_name(const char *name)
AVFilterContext * filter_ctx
filter context associated to this input/output
int format
agreed upon media format
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
if(ac->has_optimized_func)
static int opt_sync(void *optctx, const char *opt, const char *arg)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
A linked-list of the inputs/outputs of the filter chain.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static int stream_open(PlayerState *is, const char *filename, AVInputFormat *iformat)
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
static SDL_Surface * screen
const char program_name[]
program name, defined by the program for show_version().
static void stream_component_close(PlayerState *is, int stream_index)
enum AVMediaType codec_type
#define SUBPICTURE_QUEUE_SIZE
static void do_exit(void)
AVSampleFormat
Audio Sample Formats.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
char * av_strdup(const char *s)
Duplicate the string s.
int sample_rate
samples per second
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVIOContext * pb
I/O context.
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
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 int opt_width(void *optctx, const char *opt, const char *arg)
#define YUVA_OUT(d, y, u, v, a)
static int video_thread(void *arg)
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
static void toggle_full_screen(void)
#define ALPHA_BLEND(a, oldp, newp, s)
AVAudioResampleContext * avr
int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut *inputs, AVFilterInOut *outputs, void *log_ctx)
Add a graph described by a string to a graph.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static int opt_seek(void *optctx, const char *opt, const char *arg)
static void stream_seek(PlayerState *is, int64_t pos, int64_t rel, int seek_by_bytes)
int sample_rate
Sample rate of the audio data.
static const AVFilterPad inputs[]
int pad_idx
index of the filt_ctx pad to use for linking
static const uint8_t color[NB_LEVELS]
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
rational number numerator/denominator
static int is_full_screen
static void stream_cycle_channel(PlayerState *is, int codec_type)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds...
static void seek_chapter(PlayerState *is, int incr)
static int output_picture2(PlayerState *is, AVFrame *src_frame, double pts1, int64_t pos)
discard useless packets like 0 size packets in avi
SDL_Thread * subtitle_tid
static int decoder_reorder_pts
#define AUDIO_DIFF_AVG_NB
static const char * input_filename
const char * name
Name of the codec described by this descriptor.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define FRAME_SKIP_FACTOR
static int infinite_buffer
void show_help_default(const char *opt, const char *arg)
Per-avtool specific help handler.
int error
contains the error code or 0 if no error happened
uint8_t silence_buf[SDL_AUDIO_BUFFER_SIZE]
#define SAMPLE_CORRECTION_PERCENT_MAX
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
SDL_mutex * video_filter_mutex
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.
static int opt_duration(void *optctx, const char *opt, const char *arg)
This struct describes the properties of a single codec described by an AVCodecID. ...
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Parse a string and return its corresponding value as a double.
char * name
unique name for this input/output in the list
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
static int64_t pts
Global timestamp for the audio frames.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
static void stream_pause(PlayerState *is)
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds. ...
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVFilterContext * out_video_filter
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
int sample_rate
Audio only.
static int exit_on_keydown
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
AVAudioResampleContext * avresample_alloc_context(void)
Allocate AVAudioResampleContext and set options.
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
static PlayerState * global_video_state
AVFilterInOut * avfilter_inout_alloc(void)
Allocate a single AVFilterInOut entry.
AVDictionary * codec_opts
struct AVPacketList * next
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
static AVInputFormat * iformat
static const char * window_title
#define YUVA_IN(y, u, v, a, s, pal)
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
static void video_image_display(PlayerState *is)
static int compute_mod(int a, int b)
uint32_t start_display_time
static int queue_picture(PlayerState *is, AVFrame *src_frame, double pts, int64_t pos)
AVCodecContext * subtitle_dec
static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
AVRational time_base
time base in which the start/end timestamps are specified
static int fs_screen_height
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
enum AVDiscard skip_loop_filter
void uninit_opts(void)
Uninitialize the cmdutils option system, in particular free the *_opts contexts and their contents...
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
struct AVInputFormat * iformat
The input container format.
double av_display_rotation_get(const int32_t matrix[9])
The display transformation matrix specifies an affine transformation that should be applied to video ...
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
#define RGB_TO_Y_CCIR(r, g, b)
static void event_loop(void)
#define AVERROR_OPTION_NOT_FOUND
Option not found.
int eof_reached
true if eof reached
static void video_refresh_timer(void *opaque)
int channels
number of audio channels
static int error_concealment
void av_log_set_flags(int arg)
static int opt_height(void *optctx, const char *opt, const char *arg)
static int opt_frame_size(void *optctx, const char *opt, const char *arg)
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
int flags2
AV_CODEC_FLAG2_*.
static void step_to_next_frame(void)
#define VIDEO_PICTURE_QUEUE_SIZE
int bit_rate
Total stream bitrate in bit/s, 0 if not available.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
static void player_close(PlayerState *is)
static int video_open(PlayerState *is)
#define AV_DICT_IGNORE_SUFFIX
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
static int exit_on_mousedown
AVCodecParameters * codecpar
#define SDL_AUDIO_BUFFER_SIZE
int16_t sample_array[SAMPLE_ARRAY_SIZE]
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static int display_disable
static enum AVDiscard skip_loop_filter
attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
#define AV_CH_LAYOUT_MONO
enum AVSampleFormat resample_sample_fmt
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
PtsCorrectionContext pts_ctx
int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
Get a frame with filtered data from sink and put it in frame.
SubPicture subpq[SUBPICTURE_QUEUE_SIZE]
AVPixelFormat
Pixel format.
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
static AVCodec * choose_decoder(PlayerState *is, AVFormatContext *ic, AVStream *st)
int64_t video_current_pos
static void alloc_picture(void *opaque)
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
static enum AVDiscard skip_frame
static void packet_queue_init(PacketQueue *q)