26 #undef __STRICT_ANSI__ //workaround due to broken kernel headers
37 #include <sys/ioctl.h>
40 #define _LINUX_TIME_H 1
41 #include <linux/videodev.h>
52 struct video_capability video_cap;
53 struct video_audio audio_saved;
54 struct video_window video_win;
56 struct video_mbuf gb_buffers;
57 struct video_mmap gb_buf;
67 {.palette = VIDEO_PALETTE_YUV420P, .depth = 12, .pix_fmt =
PIX_FMT_YUV420P },
68 {.palette = VIDEO_PALETTE_YUV422, .depth = 16, .pix_fmt =
PIX_FMT_YUYV422 },
69 {.palette = VIDEO_PALETTE_UYVY, .depth = 16, .pix_fmt =
PIX_FMT_UYVY422 },
70 {.palette = VIDEO_PALETTE_YUYV, .depth = 16, .pix_fmt =
PIX_FMT_YUYV422 },
72 {.palette = VIDEO_PALETTE_RGB24, .depth = 24, .pix_fmt =
PIX_FMT_BGR24 },
73 {.palette = VIDEO_PALETTE_RGB565, .depth = 16, .pix_fmt =
PIX_FMT_BGR565 },
74 {.palette = VIDEO_PALETTE_GREY, .depth = 8, .pix_fmt =
PIX_FMT_GRAY8 },
83 int desired_palette, desired_depth;
84 struct video_tuner tuner;
85 struct video_audio audio;
86 struct video_picture pict;
90 av_log(s1,
AV_LOG_WARNING,
"V4L input device is deprecated and will be removed in the next release.");
92 if (ap->time_base.den <= 0) {
106 video_fd = open(s1->
filename, O_RDWR);
112 if (ioctl(video_fd, VIDIOCGCAP, &s->
video_cap) < 0) {
117 if (!(s->
video_cap.type & VID_TYPE_CAPTURE)) {
133 desired_palette = -1;
135 for (j = 0; j < vformat_num; j++) {
144 if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
146 ioctl(video_fd, VIDIOCSTUNER, &tuner);
151 ioctl(video_fd, VIDIOCGAUDIO, &audio);
153 audio.flags &= ~VIDEO_AUDIO_MUTE;
154 ioctl(video_fd, VIDIOCSAUDIO, &audio);
156 ioctl(video_fd, VIDIOCGPICT, &pict);
157 av_dlog(s1,
"v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
158 pict.colour, pict.hue, pict.brightness, pict.contrast, pict.whiteness);
160 pict.palette = desired_palette;
161 pict.depth= desired_depth;
162 if (desired_palette == -1 || ioctl(video_fd, VIDIOCSPICT, &pict) < 0) {
163 for (j = 0; j < vformat_num; j++) {
166 if (-1 != ioctl(video_fd, VIDIOCSPICT, &pict))
169 if (j >= vformat_num)
173 if (ioctl(video_fd, VIDIOCGMBUF, &s->
gb_buffers) < 0) {
182 if (ioctl(video_fd, VIDIOCSWIN, s->
video_win) < 0) {
190 if (ioctl(video_fd, VIDIOCCAPTURE, &val) < 0) {
199 if ((
unsigned char*)-1 == s->
video_buf) {
200 s->
video_buf = mmap(0, s->
gb_buffers.size, PROT_READ|PROT_WRITE, MAP_PRIVATE, video_fd, 0);
201 if ((
unsigned char*)-1 == s->
video_buf) {
213 s->
gb_buf.format = pict.palette;
215 if (ioctl(video_fd, VIDIOCMCAPTURE, &s->
gb_buf) < 0) {
216 if (errno != EAGAIN) {
226 ioctl(video_fd, VIDIOCMCAPTURE, &s->
gb_buf);
232 for (j = 0; j < vformat_num; j++) {
240 if (j >= vformat_num)
263 while (ioctl(s->
fd, VIDIOCSYNC, &s->
gb_frame) < 0 &&
264 (errno == EAGAIN || errno == EINTR));
271 if (ioctl(s->
fd, VIDIOCMCAPTURE, &s->
gb_buf) < 0) {
288 int64_t curtime, delay;
305 ts.tv_sec = delay / 1000000;
306 ts.tv_nsec = (delay % 1000000) * 1000;
307 nanosleep(&ts,
NULL);
342 {
"standard",
"", offsetof(
VideoData, standard),
AV_OPT_TYPE_INT, {.dbl = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC,
AV_OPT_FLAG_DECODING_PARAM,
"standard" },
357 .
name =
"video4linux",
364 .priv_class = &v4l_class,
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
struct video_capability video_cap
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
#define FF_ARRAY_ELEMS(a)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
struct video_window video_win
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int read_header(FFV1Context *f)
static double av_q2d(AVRational a)
Convert rational to double.
static av_cold int read_close(AVFormatContext *ctx)
Main libavdevice API header.
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
AVStream * avformat_new_stream(AVFormatContext *s, AVCodec *c)
Add a new stream to a media file.
AVCodecContext * codec
codec context
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
static const AVClass v4l_class
int bit_rate
the average bitrate
char filename[1024]
input or output filename
int width
picture width / height.
static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
enum AVMediaType codec_type
static void close(AVCodecParserContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Describe the class of an AVClass context structure.
rational number numerator/denominator
static const AVOption options[]
packed RGB 8:8:8, 24bpp, BGRBGR...
static int grab_read_close(AVFormatContext *s1)
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
struct video_mbuf gb_buffers
static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
AVInputFormat ff_v4l_demuxer
void * priv_data
Format private data.
struct video_audio audio_saved
static const struct @61 video_formats[]
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t av_gettime(void)
Get the current time in microseconds.