Qt uses ffmpeg to get keyframes at any time''

Before using Qt to obtain key frames at any time, you need to understand the basic concepts of ffmpeg. ffmpeg is an open source audio and video processing tool, which can be used to encode, decode, and convert audio and video files in various formats. In ffmpeg, the key frame (I frame) is the most important type of frame in video coding. It contains all the information of the entire image, and other frames are obtained by calculating the difference with the previous frame or the next frame. Therefore, when performing operations such as video clipping, intercepting and extracting key frames, it is usually necessary to locate key frames.

The following are the basic steps to get keyframes at any moment using Qt:

  1. Install the ffmpeg library: First, you need to install the ffmpeg library and configure the corresponding environment variables. You can download the latest version of the library file from the ffmpeg official website and follow the prompts to install it. After the installation is complete, you need to add ffmpeg-related header files and library files to the Qt project.

  2. Open a video file: use the AVFormatContext structure to open a video file, and check whether the file is opened successfully. You can use the avformat open input() function to open a video file, and use the avformat_find stream info() function to get information about the video stream.

  3. Find the key frame: find the key frame in the video stream, you can use the av seek frame () function to achieve. This function can search for the nearest keyframe at a specified time point, and returns 0 if a keyframe is found, otherwise returns -1.

  4. Decoding key frames: Decoding key frames can use avcodec send packet() and avcodec receive frame() functions. First, you need to send a data packet to the decoder, and then use the avcodec receive frame() function to get the decoded video frame.

  5. Display keyframes: Display the decoded keyframes, and use the QImage class provided by Qt to process image data. You can use the av image copy to buffer() function to copy the decoded video frame to the QImage object, and then display it on the interface.

In short, using Qt to obtain key frames at any time needs to be realized in combination with the ffmpeg library, which is completed by opening video files, finding key frames, decoding key frames, and displaying key frames. For the specific implementation process, please refer to the official ffmpeg documentation and related Qt sample codes.

★The business card at the end of the article can receive audio and video development learning materials for free, including (FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, srs) and audio and video learning roadmaps, etc.

see below!

おすすめ

転載: blog.csdn.net/yinshipin007/article/details/130408529