[Ffmpeg-devel] [PATCH] support v4l2 video source and normid input
Limin Wang
lance.lmwang
Fri Mar 23 09:06:28 CET 2007
Hi,
After the patch, ffmpeg don't need depend on other applications like tvtime,
xawtv etc to set them.
Thanks,
Limin
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 8487)
+++ ffmpeg.c (working copy)
@@ -181,6 +181,9 @@
static int video_channel = 0;
static char *video_standard = "ntsc";
+static int tv_video_input = 0;
+static int tv_normid = 0;
+
static int audio_volume = 256;
static int using_stdin = 0;
@@ -2324,6 +2327,16 @@
video_channel = strtol(arg, NULL, 0);
}
+static void opt_tv_video_input(const char *arg)
+{
+ tv_video_input = strtol(arg, NULL, 0);
+}
+
+static void opt_tv_normid(const char *arg)
+{
+ tv_normid = strtol(arg, NULL, 0);
+}
+
static void opt_video_standard(const char *arg)
{
video_standard = av_strdup(arg);
@@ -2521,6 +2534,8 @@
ap->height = frame_height + frame_padtop + frame_padbottom;
ap->pix_fmt = frame_pix_fmt;
ap->channel = video_channel;
+ ap->tv_video_input = tv_video_input;
+ ap->tv_normid = tv_normid;
ap->standard = video_standard;
ap->video_codec_id = video_codec_id;
ap->audio_codec_id = audio_codec_id;
@@ -3633,6 +3648,8 @@
/* grab options */
{ "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_channel}, "set video grab channel (DV1394 only)", "channel" },
+ { "normid", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_tv_normid}, "set tv normid (v4l2 only)", "normid" },
+ { "tv_video_input", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_tv_video_input}, "set tv video input (v4l2 only)", "tv video input" },
{ "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO | OPT_GRAB, {(void*)opt_video_standard}, "set television standard (NTSC, PAL (SECAM))", "standard" },
{ "isync", OPT_BOOL | OPT_EXPERT | OPT_GRAB, {(void*)&input_sync}, "sync read on input", "" },
Index: libavformat/v4l2.c
===================================================================
--- libavformat/v4l2.c (revision 8487)
+++ libavformat/v4l2.c (working copy)
@@ -429,6 +429,8 @@
int width, height;
int res, frame_rate, frame_rate_base;
uint32_t desired_format, capabilities;
+ struct v4l2_input input;
+ struct v4l2_standard standard;
if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
av_log(s1, AV_LOG_ERROR, "Missing/Wrong parameters\n");
@@ -494,6 +496,36 @@
}
s->frame_format = desired_format;
+ /* set tv video input */
+ memset (&input, 0, sizeof (input));
+ input.index = ap->tv_video_input;
+ if(ioctl (s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
+ return AVERROR_IO;
+ }
+
+ av_log(s1, AV_LOG_INFO, "The V4L2 driver set input_id: %d(%d), input: %s\n",
+ ap->tv_video_input, input.index, input.name);
+ if(ioctl (s->fd, VIDIOC_S_INPUT, &input.index) < 0 ) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input failed:\n");
+ return AVERROR_IO;
+ }
+
+ /* set tv standard */
+ memset (&standard, 0, sizeof (standard));
+ standard.index = ap->tv_normid;
+ if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum norm failed:\n");
+ return AVERROR_IO;
+ }
+
+ av_log(s1, AV_LOG_INFO, "The V4L2 driver set normid: %d, norm: %s\n",
+ ap->tv_normid, standard.name);
+ if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
+ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set norm failed:\n");
+ return AVERROR_IO;
+ }
+
st->codec->pix_fmt = fmt_v4l2ff(desired_format);
s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height);
if (capabilities & V4L2_CAP_STREAMING) {
Index: libavformat/avformat.h
===================================================================
--- libavformat/avformat.h (revision 8487)
+++ libavformat/avformat.h (working copy)
@@ -144,6 +144,8 @@
#if LIBAVFORMAT_VERSION_INT < (52<<16)
const char *device; /**< video, audio or DV device */
#endif
+ int tv_video_input; /**< tv video source input */
+ int tv_normid; /**< tv normid, v4l2 only */
const char *standard; /**< tv standard, NTSC, PAL, SECAM */
int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070323/496c2aea/attachment.pgp>
More information about the ffmpeg-devel
mailing list