OK, my initial assumption was wrong. "av_find_stream_info()" actually unblocks after it receives a certain number of frames and then you can continue with the program execution. Since I was recording 2 frames per second MJPEG video i takes a while to unblock so I thought it never will. Silly me :)
But still, does it really need around 80 frames (for me) to analyze video stream? Could i make it need less frames? Also, how could I make variable frame rate, since I'm recording from IP camera and id doesn't have a constant frame rate. Sometimes it is 6 fps, sometimes 5 or 7. Without inserting additional frames of the same picture in between of course. happilylazy wrote: > > Hi. > > I have a problem reading the MJPEG stream from an IP camera. > Program successfully reads the stream (server also accepts new connection) > and while the stream is streaming program waits in "av_find_stream_info()" > forever, that is until i shut down the stream. Then it successfully > encodes everything in one go. > > I would like to encode frame-by-frame as they are coming so I can > manipulate length and store the movies and pictures, but for that I need > to get out of the "av_find_stream_info()". Is there a way? > > Code goes like this (Taken from a post > http://www.nabble.com/how-to-grab-video-from-a-IP-camera-td20782070.html#a20782070 > how to grab video from a IP camera ) > > int main(int argc, char *argv[]) { > AVFormatContext *m_pFormatCtx; > int i, m_videoStream; > AVCodecContext *m_pCodecCtx; > AVCodec *m_pCodec; > AVFrame *pFrame; > AVFrame *pFrameRGB; > AVPacket packet; > AVInputFormat *m_fmt; > int frameFinished; > int numBytes; > uint8_t *buffer; > > if(argc < 2) { > printf("Please provide a movie file\n"); > return -1; > } > > // Register all formats and codecs > av_register_all(); > > m_fmt = av_find_input_format("mjpeg"); > if (!m_fmt) { > fprintf(stderr, "Unknown input format: mjpeg\n"); > return -1; > } > > // Open video file > if(av_open_input_file(&m_pFormatCtx, argv[1], m_fmt, 0, NULL)!=0) { > fprintf(stderr, "Couldn't open file\n"); > return -1; // Couldn't open file > } > > // Retrieve stream information > if(av_find_stream_info(m_pFormatCtx)<0) { > fprintf(stderr, "Couldn't find stream information\n"); > return -1; // Couldn't find stream information > } > ... > > And here it lags until stream is shut down, and then it successfully > encodes picture and video. > argv[1] = "http://192.168.0.30" that is stream process. > -- View this message in context: http://www.nabble.com/Reading-MJPEG-stream-problem-tp23481361p23502385.html Sent from the libav-users mailing list archive at Nabble.com. _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
