Video thumbnail generation method
By adding a JNI interface to the FFmpeg video player and using ffplay to obtain thumbnail data, the problem of video player not supporting thumbnail display in multiple video formats is solved, and the support for various video formats is achieved, and the ease of use of the product is improved.
Patent Information
- Application Number
- CN202510343333.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-06-27
AI Technical Summary
In the prior art, FFmpeg-based video player does not support thumbnail display in multiple video formats, which limits its application scope.
By adding a JNI interface to the target video player, using ffplay to obtain thumbnail data of video files and converting the data into bitmap images, the thumbnail display of various video formats is realized.
The FFmpeg-based video player has realized the thumbnail display capability of various video formats, improving the ease of use of the product.
Smart Images

Figure CN120223976A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video technology, and in particular, to a method for generating video thumbnails. Background Art
[0002] Due to the intuitiveness and rich content of videos, most entertainment content is presented in video files. Therefore, how to accurately present the content of the video file itself is crucial for user selection. Video thumbnails are used to preview video content and often appear in various scenarios, such as the starting screen of movies, TV dramas, TV shows, or advertising videos. The purpose is to allow users to quickly understand the content of the video and thus decide whether to further watch the video.
[0003] In the prior art, a player based on FFmpeg itself does not have the function of thumbnails. If the Android native MediaMetaDataRetriever is called to obtain video thumbnails, the video encapsulation formats supported by this interface are very limited, only including a few limited ones such as mp4, 3GP, and Webm, and even do not support common video formats such as AVI, MKV, and FLV, which greatly limits its application scope. Summary of the Invention
[0004] The present invention provides a method for generating video thumbnails, aiming to solve the defects in the prior art and realizing that a video player based on FFmpeg can support the display of thumbnails for various video formats, thereby improving the usability of the product.
[0005] To achieve the above object, the technical solution adopted by the present invention is as follows:
[0006] The present invention provides a method for generating video thumbnails, including:
[0007] Step 1: Add a JNI interface in the target video player, and the JNI interface is used for the JAVA layer to call the corresponding interface in the Native layer of the target video player;
[0008] Step 2: Load the target video file, and obtain the thumbnail data of the target video file through ffplay;
[0009] Step 3: Convert the thumbnail data into a bitmap image;
[0010] Step 4: The target video player reads the bitmap image as a thumbnail for display.
[0011] Specifically, the step 1 includes:
[0012] Step 101: Add a dynamic array in JNI and add the mapping between the native method and the Java class;
[0013] Step 102: Add predefined function definitions in JNI. The predefined functions include the path passed from the Java layer, the time parameter of the target video thumbnail passed from the Java layer, and the bitmap image returned to the upper layer.
[0014] Specifically, the said Step 2 includes:
[0015] Step 201: Open the context of the target video file, obtain stream information, and search for the video stream;
[0016] Step 202: Set the parameters of the target video encoder context and open the target video encoder;
[0017] Step 203: Jump to the nearest key frame of the target video file;
[0018] Step 204: Loop through and read avpackets, and obtain the timestamps in the avpackets;
[0019] Step 205: Determine whether the timestamp is the time parameter of the target video thumbnail. If so, it is determined that the decoding condition is met, decode the video frame data corresponding to the timestamp, obtain the corresponding data frame AVFrame and convert it to a byte array, otherwise return to Step 204;
[0020] Step 206: Filter out non-key frames and generate PICTUR objects from the key frames;
[0021] Step 207: Generate bitmap image data based on the PICTUR objects.
[0022] Specifically, the said obtaining stream information includes: obtaining stream information using avformat_find_stream_info().
[0023] Specifically, the said searching for the video stream includes: searching for the video stream using av_find_best_stream().
[0024] Specifically, the said Step 203 includes: jumping to the nearest key frame of the target video file through the SEEK method.
[0025] Specifically, the said generating PICTUR objects from the key frames includes: creating a YUV image with RGB88 and generating an image buffer.
[0026] Specifically, the said Step 207 includes:
[0027] Step 2071: Convert the PICTURE object to an unsigned character data array unsigned char*;
[0028] Step 2072: Perform data encoding on the unsigned character data array to generate bitmap image data.
[0029] Specifically, the step 2072 includes:
[0030] Step A1: Select a target picture encoder and set the parameters of the target picture encoder;
[0031] Step A2: Open the context of the target picture encoder and apply for memory space to create a target frame.
[0032] Step A3: Create an Avpacket data packet according to the PICTURE object.
[0033] Step A4: Add the picture data in the Avpacket data packet to the target frame.
[0034] Step A5: Determine whether the target video player needs to generate a picture. If so, convert the image pixel format in the target frame and write the processed image frame data to the target picture file; otherwise, proceed to the next step.
[0035] Step A6: Copy the picture data to the global buffer.
[0036] Specifically, the step 3 includes:
[0037] Step 301: The JAVA layer reads the picture data from the global buffer through the JNI interface;
[0038] Step 302: The JAVA layer converts the picture data into a bitmap image;
[0039] Step 303: Release the memory used by the JNI.
[0040] Specifically, the step 302 includes: converting the picture data into a bitmap image through the BitmapFactory.decodebyarray() method.
[0041] Specifically, the step 4 includes: the target video player calls the ffp_get_video_frameData method of ffplay to obtain the video frame bitmap image.
[0042] The beneficial effects of the present invention are as follows: By adding a JNI interface to the target video player, obtaining the thumbnail data of the target video file through ffplay, and converting the thumbnail data into a bitmap image, the target video player reads the bitmap image as a thumbnail for display, thereby enabling the video player based on FFmpeg to support the display of thumbnails for various video formats and improving the usability of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 It is a schematic flowchart of the video thumbnail generation method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0044] The embodiments of the present invention will be specifically described below with reference to the drawings. The drawings are for reference and illustration only and do not constitute a limitation on the protection scope of the present invention patent.
[0045] In the processes described in the specification, claims or drawings of the present invention, there are sequence numbers (such as step 10, 20, etc.) for each step. The sequence numbers are only used to distinguish each step, and the sequence numbers themselves do not represent any execution order. It should be noted that the descriptions such as "first", "second", etc. in this article are only used to distinguish the described objects and do not represent a sequence, nor do they mean that "first", "second", etc. are different types.
[0046] As Figure 1 shown, this embodiment provides a video thumbnail generation method, including:
[0047] Step 1: Add a JNI interface to the target video player. The JNI interface is used for the JAVA layer to call the corresponding interfaces in the Native layer of the target video player.
[0048] In this embodiment, the target video player refers to a video player based on FFmpeg.
[0049] In this embodiment, step 1 includes:
[0050] Step 101: Add a dynamic array in JNI and add a mapping between the native method and the Java class.
[0051] In this embodiment, the native method refers to a method written in C / C++ language in the Native layer.
[0052] Step 102: Add a preset function definition in JNI. The preset function includes the path passed from the Java layer, the time parameter of the target video thumbnail passed from the Java layer, and the bitmap image returned to the upper layer.
[0053] Step 2: Load the target video file and obtain the thumbnail data of the target video file through ffplay.
[0054] ffplay is a command-line video media player provided by the open-source multimedia processing framework FFmpeg, which can be used for audio and video playback and visual analysis, and provides image information related to audio and video display and playback, as well as information such as the waveform of the audio.
[0055] In this embodiment, Step 2 includes:
[0056] Step 201: Open the context of the target video file, obtain the stream information, and find the video stream.
[0057] In this embodiment, the obtaining of the stream information includes: obtaining the stream information using avformat_find_stream_info().
[0058] In this embodiment, the finding of the video stream includes: finding the video stream using av_find_best_stream().
[0059] Step 202: Set the parameters of the target video encoder context and open the target video encoder.
[0060] In specific implementation, setting the parameters of the target video encoder context means setting the parameters of AVCodecContext, such as resolution, bit rate, time base, etc.
[0061] Step 203: Jump to the nearest key frame of the target video file.
[0062] In this embodiment, Step 203 includes: jumping to the nearest key frame of the target video file through the SEEK method.
[0063] Step 204: Loop through and read avpacket, and obtain the timestamp in avpacket.
[0064] avpacket is a data structure in the FFmpeg library, which contains the actual data of the frame and the related metadata, such as the timestamp.
[0065] Step 205: Determine whether the timestamp is the time parameter of the target video thumbnail. If so, it is determined that the decoding condition is satisfied, decode the video frame data corresponding to the timestamp, obtain the corresponding data frame AVFrame and convert it into a byte array; otherwise, return to Step 204.
[0066] In this embodiment, the time parameter of the target video thumbnail is sent by the target video player, such as the time parameter generated by the user dragging the progress bar or a specific time set by the user.
[0067] Step 206: Filter non-key frames and generate PICTUR objects from the key frames.
[0068] In this embodiment, generating PICTUR objects from the key frames includes: creating a YUV image of RGB88 and generating an image buffer.
[0069] Step 207: Generate bitmap image data based on the PICTUR object.
[0070] In this embodiment, step 207 includes:
[0071] Step 2071: Convert the PICTURE object into an unsigned character data array unsigned char*.
[0072] Step 2072: Encode the unsigned character data array to generate bitmap image data.
[0073] In this embodiment, step 2072 includes:
[0074] Step A1: Select a target picture encoder and set the parameters of the target picture encoder.
[0075] In this embodiment, the parameters of the target picture encoder include the number of pixels of the image, etc.
[0076] Step A2: Open the context of the target picture encoder and apply for memory space to create a target frame.
[0077] Step A3: Create an Avpacket data packet based on the PICTURE object.
[0078] Step A4: Add the picture data in the Avpacket data packet to the target frame.
[0079] Step A5: Determine whether the target video player needs to generate a picture. If so, convert the image pixel format in the target frame and write the processed image frame data into the target picture file; otherwise, proceed to the next step.
[0080] Step A6: Copy the picture data to the global buffer g_pAlbumBuff.
[0081] In specific implementation, the picture data is bitmap image data.
[0082] g_pAlbumBuff is the thumbnail data near the specified time of the target video file.
[0083] Step 3: Convert the thumbnail data into a bitmap image.
[0084] In this embodiment, Step 3 includes:
[0085] Step 301: The JAVA layer reads the picture data from the global buffer g_pAlbumBuff through the JNI interface.
[0086] Step 302: The JAVA layer converts the picture data into a bitmap image.
[0087] In this embodiment, Step 302 includes: converting the picture data into a bitmap image through the BitmapFactory.decodebyarray() method.
[0088] BitmapFactory.decodeByteArray() is a method in the Android SDK for decoding a bitmap image from a byte array.
[0089] Step 303: Release the memory used by JNI.
[0090] Step 4: The target video player reads the bitmap image as a thumbnail for display.
[0091] In this embodiment, Step 4 includes: the target video player calls the ffp_get_video_frameData method of ffplay to obtain the video frame bitmap image.
[0092] The above-disclosed are only the preferred embodiments of the present invention and cannot be used to limit the scope of the patent protection of the present invention. Therefore, equivalent changes made according to the scope of the patent application of the present invention still fall within the scope covered by the present invention.
Claims
1. A method for generating a video thumbnail, characterized in that: include: Step 1: Add a JNI interface in the target video player, where the JNI interface is used by the JAVA layer to call the corresponding interface of the Native layer of the target video player; Step 2: Load the target video file and obtain the thumbnail data of the target video file through ffplay; Step 3, converting the thumbnail data into a bitmap image; Step 4: The target video player reads the bitmap image and displays it as a thumbnail.
2. The video thumbnail generation method according to claim 1, characterized in that: The step 1 comprises: Step 101, add a dynamic array in JNI, and add a mapping between native methods and Java classes; Step 102: Add a preset function definition in JNI, where the preset function includes the path passed by the Java layer, the time parameter of the target video thumbnail passed by the Java layer, and the bitmap image returned to the upper layer.
3. The video thumbnail generation method according to claim 1, characterized in that: The step 2 comprises: Step 201, open the context of the target video file, obtain stream information, and search for the video stream; Step 202: Setting parameters of the target video encoder context and opening the target video encoder; Step 203: Jump to the nearest key frame of the target video file; Step 204, loop through and read avpacket, and obtain the timestamp in avpacket; Step 205: determine whether the timestamp is the time parameter of the target video thumbnail. If yes, determine that the decoding condition is met, decode the video frame data corresponding to the timestamp, obtain the corresponding data frame AVFrame and convert it into a byte array, otherwise return to step 204; Step 206, filter non-key frames and generate key frames as PICTUR objects; Step 207: Generate bitmap image data according to the PICTUR object.
4. The video thumbnail generation method according to claim 3, characterized in that: The step 203 includes: jumping to the nearest key frame of the target video file by using the SEEK method.
5. The video thumbnail generation method according to claim 3, characterized in that: The step of generating a key frame as a PICTUR object includes: creating an RGB88 YUV image and generating an image buffer.
6. The video thumbnail generation method according to claim 3, characterized in that: The step 207 includes: Step 2071, convert the PICTURE object into an unsigned character data array unsigned char*; Step 2072: Encode the unsigned character data array to generate bitmap image data.
7. The video thumbnail generation method according to claim 6, characterized in that: The step 2072 includes: Step A1: select a target picture encoder and set parameters of the target picture encoder; Step A2: Open the context of the target picture encoder and apply for memory space for creating a target frame. Step A3: Create an Avpacket data packet according to the PICTURE object. Step A4: Add the picture data in the Avpacket data packet to the target frame. Step A5: determine whether the target video player needs to generate a picture. If yes, convert the image pixel format in the target frame and write the processed image frame data into the target picture file. Otherwise, proceed to the next step. Step A6: copy the image data to the global buffer.
8. The video thumbnail generation method according to claim 7, characterized in that: The step 3 comprises: Step 301: The JAVA layer reads the image data from the global buffer through the JNI interface; Step 302: The JAVA layer converts the image data into a bitmap image; Step 303: Release the memory used by JNI.
9. The video thumbnail generation method according to claim 8, characterized in that: The step 302 includes: converting the picture data into a bitmap image through the BitmapFactory.decodebyarray() method.
10. The video thumbnail generation method according to claim 9, characterized in that: The step 4 includes: the target video player calls the ffp_get_video_frameData method of ffplay to obtain the video frame bitmap image.