Handle libve_open(vconfig_t* config, vstream_info_t* stream_info, void* parent) { Handle result; if (!libve_open_orig) { libve_open_orig = libve_dlsym(__func__); } wrap_log("func\tlibve_open\tenter\n"); result = libve_open_orig(config,stream_info,parent); dump_stream_info(stream_info); libve_handle = result; wrap_log("func\tlibve_open\texit\n"); return result; }
void open(const std::string& filename, VideoInfo& info) { std::cerr << "load_file_start:'" << filename << "'\n"; AVFormatParameters params; memset(¶ms, 0, sizeof(params)); params.initial_pause = 1; // open input file without format or bufffer size // (let ffmpeg try autodetection) int err = av_open_input_file(&av_fc, filename.c_str(), 0, 0, ¶ms); if (err < 0) { std::cerr << "err = " << err << "\n"; throw std::runtime_error("could not open file"); } err = av_find_stream_info(av_fc); if (err < 0) { close(); throw std::runtime_error("Could not find codec parameters\n"); } // look for the video stream int stream_index = -1; for (int i = 0; i < av_fc->nb_streams; i++) { AVCodecContext* enc = av_fc->streams[i]->codec; if (enc->codec_type == CODEC_TYPE_VIDEO) { stream_index = i; break; } } if (stream_index == -1) { close(); throw std::runtime_error("Could not find any video streams in file"); } // some debug info dump_format(av_fc, 0, filename.c_str(), 0); dump_stream_info(av_fc); try { open_stream(av_fc, stream_index); video_stream_index = stream_index; } catch (...) { close(); throw; } AVCodecContext* enc = av_fc->streams[video_stream_index]->codec; if (enc->width == 0) { close(); throw std::runtime_error("No width and height"); } AVStream* video_stream = av_fc->streams[video_stream_index]; m_fps = av_q2d(video_stream->r_frame_rate); double duration_s; int ret = estimate_duration(av_fc, video_stream_index, m_fps, &duration_s, &m_start_time); if (ret < 0) { close(); throw std::runtime_error("Could not estimate stream duration"); } int num_frames = static_cast<int>(floor(av_q2d(video_stream->r_frame_rate) * duration_s)); info.width = enc->width; info.height = enc->height; info.num_frames = num_frames; m_width = info.width; m_height = info.height; m_num_frames = info.num_frames; std::cout << "(width x height) = (" << info.width << "x" << info.height <<")\n"; std::cout << "#frames = " << info.num_frames << "\n"; m_current_timestamp = -100; std::cout << "duration : " << duration_s << "s (" << (double) video_stream->duration * av_q2d(video_stream->time_base) << " s)\n"; std::cout << "start_time: " << m_start_time << " s\n"; std::cout << "fps : " << m_fps << "\n"; std::cout << "timebase : " << av_q2d(video_stream->time_base) << "\n"; m_frame = avcodec_alloc_frame(); file_name = filename; m_bytes_left = 0; m_scale_buf = 0; m_scale_buf_size = 0; }