24 #include <linux/videodev2.h>
25 #include <sys/ioctl.h>
41 struct v4l2_selection selection;
58 ret = ioctl(s->
fd, VIDIOC_G_FMT, &capture->
format);
69 selection.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
72 ret = ioctl(s->
fd, VIDIOC_S_SELECTION, &selection);
74 ret = ioctl(s->
fd, VIDIOC_G_SELECTION, &selection);
78 av_log(avctx,
AV_LOG_DEBUG,
"crop output %dx%d\n", selection.r.width, selection.r.height);
80 capture->
height = selection.r.height;
81 capture->
width = selection.r.width;
106 struct v4l2_event_subscription sub;
113 memset(&sub, 0,
sizeof(sub));
114 sub.type = V4L2_EVENT_SOURCE_CHANGE;
115 ret = ioctl(s->
fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
117 if (output->height == 0 || output->width == 0) {
119 "the v4l2 driver does not support VIDIOC_SUBSCRIBE_EVENT\n"
120 "you must provide codec_height and codec_width on input\n");
189 #define OFFSET(x) offsetof(V4L2m2mContext, x)
190 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
194 {
"num_capture_buffers",
"Number of buffers in the capture context",
199 #define M2MDEC(NAME, LONGNAME, CODEC, bsf_name) \
200 static const AVClass v4l2_m2m_ ## NAME ## _dec_class = {\
201 .class_name = #NAME "_v4l2_m2m_decoder",\
202 .item_name = av_default_item_name,\
204 .version = LIBAVUTIL_VERSION_INT,\
207 AVCodec ff_ ## NAME ## _v4l2m2m_decoder = { \
208 .name = #NAME "_v4l2m2m" ,\
209 .long_name = NULL_IF_CONFIG_SMALL("V4L2 mem2mem " LONGNAME " decoder wrapper"),\
210 .type = AVMEDIA_TYPE_VIDEO,\
212 .priv_data_size = sizeof(V4L2m2mContext),\
213 .priv_class = &v4l2_m2m_ ## NAME ## _dec_class,\
214 .init = v4l2_decode_init,\
215 .receive_frame = v4l2_receive_frame,\
216 .close = ff_v4l2_m2m_codec_end,\
enum AVPixelFormat ff_v4l2_format_v4l2_to_avfmt(uint32_t v4l2_fmt, enum AVCodecID avcodec)
static const AVOption options[]
This structure describes decoded (raw) audio or video data.
int coded_width
Bitstream width / height, may be different from width/height e.g.
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_v4l2_context_init(V4L2Context *ctx)
Initializes a V4L2Context.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int ff_v4l2_context_dequeue_frame(V4L2Context *ctx, AVFrame *frame)
Dequeues a buffer from a V4L2Context to an AVFrame.
int width
Width and height of the frames it produces (in case of a capture context, e.g.
int ff_v4l2_m2m_codec_init(AVCodecContext *avctx)
Probes the video nodes looking for the required codec capabilities.
enum AVCodecID av_codec_id
AVCodecID corresponding to this buffer context.
static int v4l2_receive_frame(AVCodecContext *avctx, AVFrame *frame)
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
#define AVERROR_EOF
End of file.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int ff_v4l2_context_set_status(V4L2Context *ctx, int cmd)
Sets the status of a V4L2Context.
enum AVPixelFormat av_pix_fmt
AVPixelFormat corresponding to this buffer context.
V4L2Buffer * buffers
Indexed array of V4L2Buffers.
int streamon
Whether the stream has been started (VIDIOC_STREAMON has been sent).
int ff_v4l2_context_enqueue_packet(V4L2Context *ctx, const AVPacket *pkt)
Enqueues a buffer to a V4L2Context from an AVPacket.
preferred ID for MPEG-1/2 video decoding
struct v4l2_format format
Format returned by the driver after initializing the buffer context.
static int v4l2_try_start(AVCodecContext *avctx)
Libavcodec external API header.
main external API structure.
#define M2MDEC(NAME, LONGNAME, CODEC, bsf_name)
static int v4l2_prepare_decoder(V4L2m2mContext *s)
static av_cold int v4l2_decode_init(AVCodecContext *avctx)
#define V4L_M2M_DEFAULT_OPTS
This structure stores compressed data.
enum v4l2_buf_type type
Type of this buffer context.