/*
class VideoCameraSourceModule : public SimpleModule {
public:
VideoCameraSourceModule()
{
}
void init()
{
av_register_all();
}
void process( const Frame &frame ) {
AVFormatContext *avFormatContext = 0;
AVFormatParameters vp1, *vp = &vp1;
AVInputFormat *fmt1;
memset(vp, 0, sizeof(*vp));
fmt1 = av_find_input_format("video4linux");//video_grab_format);
vp->device = 0;//"/dev/video";//video_device;
vp->channel = 0;//video_channel;
vp->standard = "pal";//"ntsc";//video_standard;
vp->width = WIDTH;
vp->height = HEIGHT;
vp->frame_rate = 50;
vp->frame_rate_base = 1;
if (av_open_input_file(&avFormatContext, "", fmt1, 0, vp) < 0) {
printf("Could not find video grab device\n");
exit(1);
}
if ((avFormatContext->ctx_flags & AVFMTCTX_NOHEADER) && av_find_stream_info(avFormatContext) < 0) {
printf("Could not find video grab parameters\n");
exit(1);
}
// Gather stream information
if ( av_find_stream_info(avFormatContext) < 0 ) {
printf("error getting stream info\n");
return;
}
// AVCodecContext *videoCodecContext = avcodec_alloc_context();
AVCodecContext *videoCodecContext = &avFormatContext->streams[0]->codec;
AVCodec *codec = avcodec_find_decoder(avFormatContext->streams[0]->codec.codec_id);
if ( !codec ) {
printf("error finding decoder\n");
return;
}
printf("found decoder: %s\n", codec->name);
avFormatContext->streams[0]->r_frame_rate = vp->frame_rate;
avFormatContext->streams[0]->r_frame_rate_base = vp->frame_rate_base;
videoCodecContext->width = vp->width;
videoCodecContext->height = vp->height;
// if ( avcodec_open( videoCodecContext, &rawvideo_decoder ) < 0 ) {
if ( avcodec_open( videoCodecContext, codec ) < 0 ) { // is rawvideo_decoder
printf("error opening context\n");
videoCodecContext = 0;
}
if ( !videoCodecContext ) {
printf("can't process video data without a context\n");
return;
}
AVPacket pkt;
while( avFormatContext ) {
if ( av_read_frame(avFormatContext, &pkt) < 0 )
printf("error reading packet\n");
else {
AVFrame *picture = avcodec_alloc_frame();
YUVFrame *yuvFrame = new YUVFrame;
yuvFrame->pic = picture;
Frame *currentFrame = new Frame( "FRAME_ID_YUV_VIDEO_FRAME", yuvFrame );
currentFrame->ref();
int gotPicture = 0;
avcodec_decode_video( videoCodecContext, picture, &gotPicture, pkt.data, pkt.size );
if ( gotPicture ) {
yuvFrame->fmt = videoCodecContext->pix_fmt; // is PIX_FMT_YUV422
yuvFrame->width = videoCodecContext->width;
yuvFrame->height = videoCodecContext->height;
// printf("showing frame: %i %ix%i\n", yuvFrame->fmt, yuvFrame->width, yuvFrame->height );
SimpleModule::process( *currentFrame );
}
}
}
}
const char *name() { return "Video Camera Source"; }
Format inputFormat() { return "FRAME_ID_VIDEO_CAMERA_SOURCE"; }
Format outputFormat() { return "FRAME_ID_YUV_VIDEO_FRAME"; }
bool isBlocking() { return true; }
};
*/