Tom, Hopefully this reply will prompt someone to tell us the best method.
For some formats (for example, MPG) the duration is not available from the file header. So opening the file is not the only thing you need to do to get the duration. What I do, which is probably not the most efficient way but is quite simple, is to read all of the frames but not process them. That gives me the frame count, which I then multiply by the inverse of the frame rate to get the duration in mS. For my applicatiooon, this is not too much of a handicap because I'm do another "pre-pass" over the file to build a frame index (modified FFMPEG-FAS) and do some other processing that I need to do. I find that for a 1 hour file - like a 1GB VOB file, for example, I can get the duration in about 20-25 seconds. If that is too slow, then you could always use a second thread to compute the duration while the main thread is displaying the video or whatever it is you're doing. Clive -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Tom Handal Sent: 16 March 2009 05:46 To: [email protected] Subject: [libav-user] av_open_input_stream not getting duration Sorry to send this again, but I really need to find a way to do this... Please see my forwarded e-mail... Thanks in advance... Tom ---------- Forwarded message ---------- From: Tom Handal <[email protected]> Date: Fri, Mar 13, 2009 at 11:15 AM Subject: [libav-user] av_open_input_stream not getting duration To: [email protected] Hi all, I am trying to use av_open_input_stream to open the stream, which works great. The problem I am having is that the duration entry in the format context is not getting set to a proper value. This is on Mac OS X (Leopard). What am I doing wrong here? code: AVProbeData pd; av_register_all(); pd.filename = m_URI; // This is just a regular local filename pd.buf = (unsigned char *) av_malloc(188 * 50); pd.buf_size = 188 * 50; m_pByteDataPtr = pd.buf; m_pFormatContext = NULL; // Read small amount of data to determine format m_pFileReader->Read((char *) pd.buf, pd.buf_size); init_put_byte(&m_ByteIOContext, m_pByteDataPtr, pd.buf_size, 0, this, ReadData, NULL, SeekFile); // ReadData and SeekFile are functions that just use my FileReader class to read and seek into file ... this is standard posix stuff m_pInputFormat = av_probe_input_format(&pd, 1); m_ByteIOContext.is_streamed = 0; av_open_input_stream(&m_pFormatContext, &m_ByteIOContext, m_URI, m_pInputFormat, NULL); av_find_stream_info(m_pFormatContext); dump_format(m_pFormatContext, 0, "", false); When the dump format happens, it says that the duration is N/A, so I am assuming it is AV_NOPTS_VALUE or whatever... When i look at the m_pFormatContext in the debugger, the value is obiously wrong... its like -9223372036854775808 Any ideas as to why it is not getting the duration of the file for me? Thanks in advance!! Tom _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
