If the url does not end with mjpeg extension, av_open_input_file will not guess 
the format, then you should tell it to use mjpeg. You can do it this way:

    //forzamos el formato de entrada a MJPEG
    m_fmt = av_find_input_format("mjpeg");
    if (!m_fmt) {
       fprintf(stderr, "Unknown input format: mjpeg\n");
       return false;
    }

    // Open video file
    if(av_open_input_file(&m_pFormatCtx, m_InputFile.c_str(), m_fmt, 0, 
NULL)!=0)
    {
        fprintf(stderr, "Couldn't open file\n");
        return false; // Couldn't open file
    }

    // Retrieve stream information
    if(av_find_stream_info(m_pFormatCtx)<0)
    {
        fprintf(stderr, "Couldn't find stream information\n");
        return false; // Couldn't find stream information
    }

    // Dump information about file onto standard error
    dump_format(m_pFormatCtx, 0, m_InputFile.c_str(), false);

    // Find the first video stream
    m_videoStream=-1;
    for(int i=0; i<m_pFormatCtx->nb_streams; i++)
        if(m_pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
        {
            m_videoStream=i;
            break;
        }
    if(m_videoStream==-1)
    {
        fprintf(stderr, "Didn't find a video stream\n");
        return false; // Didn't find a video stream
    }

    // Get a pointer to the codec context for the video stream
    m_pCodecCtx=m_pFormatCtx->streams[m_videoStream]->codec;

    // Find the decoder for the video stream
    m_pCodec=avcodec_find_decoder(m_pCodecCtx->codec_id);
    if(m_pCodec==NULL)
    {
        fprintf(stderr, "Codec not found\n");
        return false; // Codec not found
    }

    // Open codec
    if(avcodec_open(m_pCodecCtx, m_pCodec)<0)
    {
        fprintf(stderr, "Could not open codec\n");
        return false; // Could not open codec
    }

........
........


And then continue as normal


> Date: Mon, 1 Dec 2008 17:27:22 -0800
> From: [EMAIL PROTECTED]
> To: [email protected]
> Subject: RE: [libav-user] how to grab video from a IP camera
> 
> Hi
> so I am experimenting with trying to grab video(mjpeg) from an IP webcam and 
> I am using the Stepehen Dranger's tutorial01 as my starting point and I know 
> that in his program he does a call av_find_stream_info to retrieve the stream 
> information. Now I tried to feed the url of the ip webcam into his program 
> and it fails at av_find_stream_info (which is expected because when I try to 
> grab video from this IP camera using ffplay I have to do a -f mjpg to specify 
> an input format). Now I am assuming I will have to manually allocate and set 
> the values of an AVCodecContext variable. Now I have allocated a an 
> AVCodecContext variable using av_allocate_context(). So what should I do 
> next? What fields inside the AVCodecContext variable do I need to set so that 
> I can pass it into avcodec_open()? Thanks
> 
> Xin Cai
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] on behalf of Cai, Xin
> Sent: Mon 12/1/2008 2:30 PM
> To: [email protected]
> Subject: [libav-user] how to grab video from a IP camera
> 
> Hi guys
> 
> I am working on a program that requires me to grab video(mjpeg) from an
> IP camera and I was able to do it using ffmpeg, but now I want to
> acquire the video from the IP camera using libav api(s) directly. Now I
> went through the Stephen Dranger tutorial already but the tutorial reads
> from file, so how can I modify it to read from an IP camera? Any help
> would be appreciated.
> 
> 
> 
> Thanks
> 
> 
> 
> Xin Cai
> 
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
> 

_________________________________________________________________
Sé el primero en tener el nuevo Windows Live Messenger
http://download.live.com/
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to