A method and system for adding watermark to video stream
By processing video streams frame by frame and adding watermarks to video streams on the Android platform, the problem of complex and costly watermark addition process in the existing technology is solved, and efficient, flexible and customized watermark addition effect is achieved.
Patent Information
- Application Number
- CN202411772605.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-04
AI Technical Summary
There are multiple challenges in combining WebRTC technology to add watermarks to video streams on Android platforms, including the complex integration process of the FFmpeg library, the Canvas method is limited by the Android system mechanism, and the high cost and potential risks of third-party audio and video SDKs.
By obtaining the video stream frame by frame, converting the image format, creating a canvas object and adding a watermark to the new bitmap object, finally converting the watermark bitmap object into a watermark video frame, and outputting a watermark video stream.
The process of adding watermarks is simplified, the complex integration problem of the FFmpeg library is avoided, the dependence on third-party SDKs is reduced, the performance and real-timeness is improved, and the customization and creativity of watermarks are enhanced.
Smart Images

Figure CN119767055A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of video technology, and in particular to a method and system for adding watermarks to video streams. Background Art
[0002] In the emergency communication platform project, the use of WebRTC technology for audio and video transmission has become standard, and Android devices are widely used as key audio and video terminals. In order to achieve information marking, brand promotion, and prevent content tampering, watermark information is usually embedded in the video stream, such as terminal name, geographic location coordinates, and timestamp. However, on the Android platform, adding watermarks to video streams in combination with WebRTC technology faces multiple challenges.
[0003] At present, the mainstream watermarking solutions include integrating FFmpeg library, drawing through Canvas, and adopting third-party audio and video SDK. Although FFmpeg library is comprehensive, its integration process is quite complicated. It needs to deal with compatibility issues of different Android architectures, and errors are prone to occur in the compilation and linking process, and the entire construction process is quite cumbersome. In addition, FFmpeg's command line tools and programming interfaces are complex in design and difficult to learn. Once the parameters are set improperly, processing failure may occur. The method of drawing with Canvas is limited by the Android system mechanism. It is necessary to draw first and then recapture the video, which brings many technical obstacles. As for the use of third-party audio and video SDK, although it is easy to operate, it is often accompanied by high costs, and long-term use is even more expensive. At the same time, dependence on third-party SDKs also brings potential risks. Once the SDK stops updating and maintenance or is incompatible with the new Android version, its functions will be affected and it is difficult to optimize directly. In addition, third-party SDKs may not meet specific personalized needs, and the customization options of watermarks are limited, which to a certain extent limits the creativity.
[0004] In summary, although there are currently many methods for adding watermarks to video streams on the Android platform in combination with WebRTC technology, each method has its own inherent defects and challenges. Therefore, in practical applications, we need to select the most appropriate method based on specific needs and scenarios, and continue to optimize and improve it in order to achieve the best application effect. Summary of the invention
[0005] In view of the problems existing in the prior art, the present invention provides a method for adding a watermark to a video stream, comprising:
[0006] Step S1, acquiring each original video frame from the video stream frame by frame, and saving it in a first format;
[0007] Step S2, converting the image format of each original video frame into an original image bitmap object;
[0008] Step S3, for each of the original bitmap objects, create a canvas object and create a new bitmap object in the canvas object, then draw the original bitmap object into the new bitmap object, and add a watermark at a specified position of the new bitmap object to obtain a watermark bitmap object;
[0009] Step S4: convert each of the watermark bitmap objects into a watermarked video frame in the first format, and output them in sequence to obtain a watermarked video stream.
[0010] Preferably, the first format is I420Buffer, and the step S1 comprises:
[0011] Step S11, calling the rewritten video frame capture function to capture frame by frame from the video stream to obtain the original video frame and save it into a buffer;
[0012] Step S12, obtaining the saved original video frame from the buffer and converting it into an I420Buffer format.
[0013] Preferably, the step S2 comprises:
[0014] Step S21, for each frame of the original video, converting the first format into a second format using the JNI method;
[0015] Step S22: converting the original video frame in the second format into the original image bitmap object.
[0016] Preferably, the second format is NV21 format, and the step S21 comprises:
[0017] Step S211, for each original video frame, obtaining the width and height of the original video frame and calculating the data size of its Y, U, and V component data;
[0018] Step S212, creating a data storage array, then respectively obtaining the buffer objects of the Y, U, and V component data and the strides of the U component and the V component, and copying the buffer object of the Y component data to the data storage array;
[0019] Step S213, calling a JNI method to traverse the U component data and the V component data and insert them into the data storage array to obtain an NV21 data array, and returning the original video frame in the second format.
[0020] Preferably, the step S22 includes:
[0021] Step S221, creating a memory allocation input object and a memory allocation output object, copying the data in the NV21 data group into the memory allocation input object, performing format conversion on the memory allocation input object and storing the conversion result in the memory allocation output object;
[0022] Step S222, creating a blank bitmap object, and copying the data in the memory allocation output object to the blank bitmap object to obtain the original bitmap object.
[0023] The present invention also provides a system for adding watermarks to a video stream, which uses the above-mentioned watermark adding method and comprises:
[0024] A frame acquisition module, used for acquiring each original video frame from the video stream frame by frame, and saving it in a first format;
[0025] A format conversion module, connected to the frame acquisition module, for converting the image format of each original video frame into an original bitmap object;
[0026] a watermark adding module, connected to the format conversion module, for creating a canvas object and a new bitmap object in the canvas object for each original bitmap object, then drawing the original bitmap object into the new bitmap object, and adding a watermark at a specified position of the new bitmap object to obtain a watermark bitmap object;
[0027] The video output module is connected to the watermark adding module and is used to convert each of the watermark bitmap objects into a watermarked video frame in the first format, and output the watermarked video stream in sequence.
[0028] Preferably, the first format is I420Buffer, and the frame acquisition module includes:
[0029] A capture unit, used for calling the rewritten video frame capture function to capture the original video frames from the video stream frame by frame and save them into a buffer;
[0030] A storage unit is connected to the capture unit and is used to obtain the saved original video frame from the buffer and convert it into an I420Buffer format.
[0031] Preferably, the format conversion module includes:
[0032] A format conversion unit, configured to convert each original video frame from the first format to a second format using the JNI method;
[0033] A bitmap conversion unit is connected to the format conversion unit and is used to convert the original video frame in the second format into the original image bitmap object.
[0034] Preferably, the second format is NV21 format, and the format conversion unit includes:
[0035] A width and height acquisition subunit, for acquiring the width and height of each original video frame and calculating the data size of its Y, U, and V component data;
[0036] An array creation subunit, connected to the width and height acquisition subunit, is used to create a data storage array, and then respectively acquires the buffer objects of the Y, U, and V component data and the strides of the U component and the V component, and copies the buffer object of the Y component data to the data storage array;
[0037] The format conversion subunit is connected to the array creation unit, and is used to call a JNI method to traverse the U component data and the V component data and insert them into the data storage array to obtain an NV21 data array, and return the original video frame as the second format.
[0038] Preferably, the bitmap conversion unit comprises:
[0039] A bitmap conversion subunit is used to create a memory allocation input object and a memory allocation output object, copy the data in the NV21 data group into the memory allocation input object, perform format conversion on the memory allocation input object and store the conversion result into the memory allocation output object;
[0040] The bitmap drawing subunit is connected to the bitmap conversion subunit and is used to create a blank bitmap object, and copy the data in the memory allocation output object to the blank bitmap object to obtain the original bitmap object.
[0041] The above technical solution has the following advantages or beneficial effects:
[0042] 1. It avoids the complex integration process and compilation and linking issues of the FFmpeg library. This frame-based processing method is more intuitive and reduces the complexity of technical implementation. It ensures the real-time nature of watermarking. At the same time, by optimizing the format conversion and drawing process, it also improves performance and reduces delays and freezes.
[0043] 2. Compared with the method of drawing using Canvas, although this method also involves drawing steps, it draws directly on the converted bitmap object without re-capturing the video, thereby simplifying the process. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 A schematic flow chart of a method for adding a watermark to a video stream in a preferred embodiment of the present invention;
[0045] Figure 2 This is a flow chart of step S1 in a preferred embodiment of the present invention;
[0046] Figure 3 Schematic diagram of the process of step S2 in a preferred embodiment of the present invention;
[0047] Figure 4 Schematic diagram of the process of step S21 in a preferred embodiment of the present invention;
[0048] Figure 5 Schematic diagram of the process of step S22 in a preferred embodiment of the present invention;
[0049] Figure 6 The figure is a schematic structural diagram of a system for adding watermarks to a video stream in a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0050] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. The present invention is not limited to this embodiment, and other embodiments may also fall within the scope of the present invention as long as they conform to the gist of the present invention.
[0051] In a preferred embodiment of the present invention, based on the above problems existing in the prior art, a method for adding a watermark to a video stream is provided. Figure 1 Said, including:
[0052] Step S1, obtaining each original video frame from the video stream frame by frame, and saving it in a first format;
[0053] Step S2, converting the image format of each original video frame into an original bitmap object;
[0054] Step S3, for each original bitmap object, create a canvas object and create a new bitmap object in the canvas object, then draw the original bitmap object into the new bitmap object, and add a watermark at a specified position of the new bitmap object to obtain a watermark bitmap object;
[0055] Step S4: convert each watermark bitmap object into a watermarked video frame in a first format, and output them in sequence to obtain a watermarked video stream.
[0056] Specifically, in this embodiment, by processing the video stream frame by frame and adding a watermark to each frame, the complex integration process and compilation linking problems of the FFmpeg library are avoided. This frame-based processing method is more intuitive and reduces the complexity of technical implementation. It ensures the real-time nature of watermark addition. At the same time, by optimizing the format conversion and drawing process, it also improves performance and reduces delays and freezes.
[0057] Compared with the method of drawing using Canvas, although this method also involves a drawing step, it draws directly on the converted bitmap object without re-capturing the video, thereby simplifying the process.
[0058] The conversion of video frame formats (such as I420Buffer to NV21) is implemented through the JNI (Java Native Interface) method, ensuring compatibility on different Android architectures (such as ARM, x86, etc.). This method takes advantage of the cross-platform characteristics of JNI and improves the stability of the system.
[0059] In addition, through frame-by-frame processing and instant conversion, system crashes or performance degradation caused by long processing or complex operations are avoided.
[0060] Furthermore, compared with the solution of using a third-party audio and video SDK, this method does not rely on external libraries or SDKs, thereby reducing costs. In addition, since this method is completely self-implemented, it can be flexibly adjusted and optimized according to needs, avoiding the potential risks and limitations that may be brought by third-party SDKs.
[0061] This method allows you to add a watermark at a specified location, and you can adjust the content, size, and position of the watermark as needed. This flexibility makes the customization options of watermarks richer and meets diverse needs. By directly manipulating bitmap objects, your solution also supports more complex watermark effects, such as transparency adjustment, rotation, scaling, etc., thereby enhancing the creativity and expressiveness of watermarks.
[0062] In summary, the method in this embodiment shows significant advantages in solving the defects of the existing technology of adding watermarks to video streams in combination with WebRTC technology on the Android platform. It simplifies the process, improves compatibility and stability, reduces costs and dependencies, enhances watermark customization and creativity, and optimizes performance and real-time performance. These advantages make the method in this embodiment highly feasible and practical in practical applications.
[0063] In a preferred embodiment of the present invention, the first format is I420Buffer, such as Figure 2 As shown, step S1 includes:
[0064] Step S11, calling the rewritten video frame capture function to capture the original video frames from the video stream frame by frame and save them into a buffer;
[0065] Step S12, obtaining the saved original video frame from the buffer and converting it into an I420Buffer format.
[0066] Specifically, in this embodiment, by rewriting the onFrameCaptured(VideoFramevideoFrame) method, each frame in the video stream can be captured in real time. This means that the watermarking operation can be performed immediately after the video frame is captured, without waiting for the entire video stream to be processed, thereby ensuring the real-time nature of the watermarking.
[0067] In the onFrameCaptured method, you can directly access the captured video frame object videoFrame. This enables you to directly obtain the buffer data of the video frame without going through additional steps or interfaces. This direct access method reduces the latency and complexity of data processing.
[0068] The captured video frame is converted into I420Buffer format. I420Buffer is a common video frame format that supports the processing of YUV image data. This format compatibility enables the watermarking method in this embodiment to be more widely applied to different video processing scenarios and platforms.
[0069] After converting the video frame to I420Buffer format, you can process the video data more efficiently. The I420 format stores YUV data separately, where the Y component represents brightness information and the U and V components represent chrominance information. This separation allows you to process brightness information and chrominance information independently, thereby improving the efficiency and flexibility of data processing.
[0070] In a preferred embodiment of the present invention, Figure 3 As shown, step S2 includes:
[0071] Step S21, for each original video frame, converting from the first format to the second format using a JNI method;
[0072] Step S22: converting the original video frame in the second format into an original bitmap object.
[0073] In a preferred embodiment of the present invention, the second format is NV21 format, such as Figure 4 As shown, step S21 includes:
[0074] Step S211, for each original video frame, obtain the width and height of the original video frame and calculate the data size of its Y, U, and V component data;
[0075] Step S212, creating a data storage array, then respectively obtaining the buffer objects of the Y, U, and V component data and the strides of the U component and the V component, and copying the buffer object of the Y component data to the data storage array;
[0076] Step S213, calling the JNI method to traverse the U component data and the V component data and insert them into the data storage array to obtain the NV21 data array, and returning the original video frame as the second format.
[0077] Specifically, I420 and NV21 both belong to the YUV encoding format, the difference lies in the arrangement of UV type data:
[0078] I420:YYYYYYYYUUVV
[0079] NV21: YYYYYYYYYVUVU
[0080] The conversion principle is to interleave the positions of u and v data.
[0081] In this embodiment, step S21 converts the video frames in I420 format to NV21 format through the JNI method. Since both I420 and NV21 belong to YUV encoding formats, but the arrangement of UV components is different, performing this conversion directly in Java may be very time-consuming and inefficient, resulting in slow or stuck video playback. However, your solution chooses to use C++ for conversion and calls it through JNI, making full use of C++'s advantages in processing underlying data and algorithms, thereby achieving efficient data conversion.
[0082] Using C++ for conversion not only improves the efficiency of data processing, but also optimizes the overall performance. Compared with Java, C++ usually has a higher execution speed when processing complex data and algorithms, which enables your solution to achieve faster video processing and watermarking without sacrificing video quality.
[0083] By calling C++ methods through JNI for conversion, resource consumption at the Java level is reduced. Java may require more memory and CPU resources when processing underlying data and algorithms, while C++ can use these resources more efficiently, thereby reducing overall resource consumption.
[0084] Specifically, in this embodiment, variables are first initialized, and I420Buffer is used to obtain the width and height (width and height) of the video frame. The Y component data size (ySize) is equal to width*height, and the data size (uvSize) of the U and V components is equal to one quarter of the Y component (ySize / 4).
[0085] Next, create the target array
[0086] Create an array to store the converted NV21 data. The length of the NV21 data array is ySize+2*uvSize, which is used to store the converted NV21 data.
[0087] Next, get the Y, U, V data
[0088] Get the data buffer objects yBuffer, uBuffer, and vBuffer of the Y, U, and V components respectively.
[0089] Next, get the stride of the U and V components
[0090] Get the strides uStride and vStride of the U and V components respectively, that is, the number of bytes per row of data.
[0091] Next, copy the Y data
[0092] Copies the Y component data from yBuffer to the first ySize positions of the nv21 array.
[0093] Next, call the C++ method to convert
[0094] After the above data is prepared, use the java jni method to call the c++ method and use these parameters to convert the I420 format data into NV21 format.
[0095] The C++ method includes the following steps:
[0096] 1. Calculate the data size.
[0097] ySize represents the data size of the Y component, which is equal to width*height.
[0098] uvSize represents the data size of the U and V components, and the size of each U and V component is ySize / 4.
[0099] nv21Size represents the total size of NV21 data, which is equal to ySize+2*uvSize.
[0100] 2. Get the buffer address.
[0101] Use the GetDirectBufferAddress method to get the addresses of the data buffers for the Y, U, and V components.
[0102] 3. Create the target array.
[0103] Create a new data storage array with a size of nv21Size.
[0104] 4. Copy the Y data.
[0105] Copies the Y component data from yBuf to the first ySize positions of the data storage array.
[0106] 5. Interleave U and V data,
[0107] Iterate over each row of U and V data.
[0108] Calculate the starting positions uPos and vPos of the U and V data of the current row.
[0109] Calculate the starting position nvPos of the corresponding position in the data storage array.
[0110] Insert the data of the V and U components into the corresponding positions of the data storage array in turn to obtain the NV21 data array.
[0111] 6. Return the converted NV21 data array.
[0112] In a preferred embodiment of the present invention, Figure 5 As shown, step S22 includes:
[0113] Step S221, creating a memory allocation input object and a memory allocation output object, copying the data in the NV21 data group into the memory allocation input object, converting the format of the memory allocation input object and storing the conversion result in the memory allocation output object;
[0114] Step S222, creating a blank bitmap object, and copying the data in the memory allocation output object to the blank bitmap object to obtain the original bitmap object.
[0115] Specifically, in this embodiment, first, initialize the RenderScript environment:
[0116] Create a RenderScript object rs to manage and execute RenderScript tasks.
[0117] Next, create a script for YUV to RGB conversion:
[0118] Create a ScriptIntrinsicYuvToRGB object yuvToRgb to perform YUV to RGB conversion. ScriptIntrinsicYuvToRGB is a built-in script provided by RenderScript, which is specifically used to convert YUV format image data to RGB format image data.
[0119] Next, initialize the RenderScript type:
[0120] yuvType: Creates a Type object to represent the type of NV21 data. The element type is U8 (unsigned 8-bit integer) and the length is nv21.length.
[0121] rgbaType: Creates a Type object to represent image data in RGBA format, with width and height.
[0122] Memory allocation input object in and memory allocation output object out: Create two Allocation objects to store input NV21 data and output RGBA data respectively.
[0123] Next, copy the NV21 data from the nv21 array to the memory allocated input object in:
[0124] The NV21 data is copied from the NV21 data array obtained in the above-mentioned embodiment to the memory allocation input object in.
[0125] Next, perform the YUV to RGB conversion:
[0126] Set the input of the yuvToRgb script to the data in the memory allocated input object in.
[0127] Call the forEach method to perform the YUV to RGB conversion and store the result in the memory allocated output object out.
[0128] Next, create a Bitmap object: (Blank bitmap object, Bitmap, also known as bitmap, is the representation of the image in memory.)
[0129] Create a blank bitmap object with width width, height height, and configuration ARGB_8888.
[0130] Next, copy the output assignment to a blank bitmap object:
[0131] Copy the RGBA data in the memory allocated output object out to the blank bitmap object to obtain the original bitmap object and return it.
[0132] Then execute the content in step S3;
[0133] First, create a Canvas object (a canvas object is used in Android to draw graphics, process images, etc. It provides a canvas that allows developers to draw custom graphics, and can also handle text drawing and image synthesis.) for drawing on the new bitmap object;
[0134] Next, draw the original bitmap object onto the new bitmap object;
[0135] Then, create a Paint object (in Android development, the Paint object is a brush tool used to set the color, style, font, effect and other properties of the drawing to meet various drawing requirements. In Java graphics programming, Paint is an abstract class used to describe drawing colors and patterns.), set the text attributes, where the text content, color, size and other setting parameters can be set by the user;
[0136] Next, draw the text watermark at the specified position to get the watermark bitmap object. The parameters of the text watermark position can be set by the user.
[0137] Finally, each watermark bitmap object is converted into a watermarked video frame in the first format, and the watermarked video stream is output in sequence.
[0138] For the last step, the following steps are mainly included:
[0139] 1. Create a YuvConverter object
[0140] Used to convert YUV format. YuvConverter is a tool class in the org.webrtc library for converting between different color spaces. (The org.webrtc library is the Java implementation of the WebRTC project, which provides a powerful framework for building real-time communication applications. This library contains various components and interfaces required to implement audio and video communication, such as video capture, audio capture, video encoding, audio encoding, network transmission, media stream management, etc.)
[0141] 2. Create an OpenGLES texture
[0142] The role of managing and operating graphic resources is to process Bitmap data (that is, the watermark bitmap object obtained in the previous step)
[0143] Upload the Bitmap data into the texture
[0144] 3. Get the texture identifier
[0145] Creating a TextureBufferImpl Object
[0146] Create a TextureBufferImpl object to encapsulate the size, type, texture identifier, matrix and other information of the Bitmap data. TextureBufferImpl is a class in the org.webrtc library used to process texture buffers. (In the WebRTC framework, TextureBufferImpl usually exists as a component in the video frame rendering and encoding process. It uses the rendering capabilities of OpenGL to render video frames into Texture and prepares to pass the data in Texture to the MediaCodec encoder for compression.)
[0147] 4. Convert TextureBufferImpl to I420 buffer
[0148] Use the convert method of YuvConverter to convert TextureBufferImpl into a buffer in I420 format (ie the first format).
[0149] 5. Create a VideoFrame object
[0150] Create a new VideoFrame object with the converted I420 buffer, rotation angle, and timestamp as parameters.
[0151] 6. Call the onFrame method of videoSink to output the processed VideoFrame object (i.e., the video stream with watermark).
[0152] The present invention also provides a watermark adding system for video stream, using the watermark adding method as described above, such as Figure 6 As shown, including:
[0153] The frame acquisition module 1 is used to acquire each original video frame from the video stream frame by frame and save it in a first format;
[0154] The format conversion module 2 is connected to the frame acquisition module 1 and is used to convert the image format of each original video frame into an original bitmap object;
[0155] The watermark adding module 3 is connected to the format conversion module 2 and is used for creating a canvas object and a new bitmap object in the canvas object for each original bitmap object, then drawing the original bitmap object into the new bitmap object, and adding a watermark at a specified position of the new bitmap object to obtain a watermark bitmap object;
[0156] The video output module 4 is connected to the watermark adding module 3 and is used for converting each watermark bitmap object into a watermarked video frame in a first format and outputting the watermarked video stream in sequence.
[0157] In a preferred embodiment of the present invention, the first format is I420Buffer, such as Figure 6 As shown, the frame acquisition module 1 includes:
[0158] A capture unit 11 is used to call the rewritten video frame capture function to capture the original video frames from the video stream frame by frame and save them into a buffer;
[0159] The storage unit 12 is connected to the capture unit 11 and is used to obtain the saved original video frame from the buffer and convert it into an I420Buffer format.
[0160] In a preferred embodiment of the present invention, the format conversion module 2 includes:
[0161] A format conversion unit 21, configured to convert each original video frame from a first format to a second format using a JNI method;
[0162] The bitmap conversion unit 22 is connected to the format conversion unit 21 and is used to convert the original video frame in the second format into an original bitmap object.
[0163] In a preferred embodiment of the present invention, the second format is NV21 format, and the format conversion unit 21 includes:
[0164] The width and height acquisition subunit 211 is used to acquire the width and height of each original video frame and calculate the data size of its Y, U, and V component data;
[0165] The array creation subunit 212 is connected to the width and height acquisition subunit 211, and is used to create a data storage array, and then respectively acquire the buffer objects of the Y, U, and V component data and the strides of the U component and the V component, and copy the buffer object of the Y component data to the data storage array;
[0166] The format conversion subunit 213 is connected to the array creation unit 212, and is used to call the JNI method to traverse the U component data and the V component data and insert them into the data storage array to obtain the NV21 data array, and return the original video frame as the second format.
[0167] In a preferred embodiment of the present invention, the bitmap conversion unit 22 includes:
[0168] The bitmap conversion subunit 221 is used to create a memory allocation input object and a memory allocation output object, copy the data in the NV21 data group into the memory allocation input object, perform format conversion on the memory allocation input object and store the conversion result into the memory allocation output object;
[0169] The bitmap drawing subunit 222 is connected to the bitmap conversion subunit 221 and is used to create a blank bitmap object and copy the data in the memory allocation output object to the blank bitmap object to obtain the original bitmap object.
[0170] The above are only preferred embodiments of the present invention, and are not intended to limit the implementation methods and protection scope of the present invention. Those skilled in the art should be aware that all solutions obtained by equivalent substitutions and obvious changes made using the contents of this specification and illustrations should be included in the protection scope of the present invention.
Claims
1. A method for adding a watermark to a video stream, characterized in that: include: Step S1, acquiring each original video frame from the video stream frame by frame, and saving it in a first format; Step S2, converting the image format of each original video frame into an original image bitmap object; Step S3, for each of the original bitmap objects, create a canvas object and create a new bitmap object in the canvas object, then draw the original bitmap object into the new bitmap object, and add a watermark at a specified position of the new bitmap object to obtain a watermark bitmap object; Step S4: convert each of the watermark bitmap objects into a watermarked video frame in the first format, and output them in sequence to obtain a watermarked video stream.
2. The watermark adding method according to claim 1, characterized in that: The first format is I420Buffer, and the step S1 comprises: Step S11, calling the rewritten video frame capture function to capture frame by frame from the video stream to obtain the original video frame and save it into a buffer; Step S12, obtaining the saved original video frame from the buffer and converting it into an I420Buffer format.
3. The watermark adding method according to claim 1, characterized in that: The step S2 comprises: Step S21, for each frame of the original video, converting the first format into a second format using the JNI method; Step S22: converting the original video frame in the second format into the original image bitmap object.
4. The watermark adding method according to claim 3, characterized in that: The second format is NV21 format, and the step S21 includes: Step S211, for each original video frame, obtaining the width and height of the original video frame and calculating the data size of its Y, U, and V component data; Step S212, creating a data storage array, then respectively obtaining the buffer objects of the Y, U, and V component data and the strides of the U component and the V component, and copying the buffer object of the Y component data to the data storage array; Step S213, calling a JNI method to traverse the U component data and the V component data and insert them into the data storage array to obtain an NV21 data array, and returning the original video frame in the second format.
5. The watermark adding method according to claim 4, characterized in that: The step S22 comprises: Step S221, creating a memory allocation input object and a memory allocation output object, copying the data in the NV21 data group into the memory allocation input object, performing format conversion on the memory allocation input object and storing the conversion result in the memory allocation output object; Step S222, creating a blank bitmap object, and copying the data in the memory allocation output object to the blank bitmap object to obtain the original bitmap object.
6. A system for adding watermarks to a video stream, characterized in that: Applying the watermark adding method as described in any one of claims 1 to 5, comprising: A frame acquisition module, used for acquiring each original video frame from the video stream frame by frame, and saving it in a first format; A format conversion module, connected to the frame acquisition module, for converting the image format of each original video frame into an original bitmap object; a watermark adding module, connected to the format conversion module, for creating a canvas object and a new bitmap object in the canvas object for each original bitmap object, then drawing the original bitmap object into the new bitmap object, and adding a watermark at a specified position of the new bitmap object to obtain a watermark bitmap object; The video output module is connected to the watermark adding module and is used to convert each of the watermark bitmap objects into a watermarked video frame in the first format, and output the watermarked video stream in sequence.
7. The watermark adding system according to claim 6, characterized in that: The first format is I420Buffer, and the frame acquisition module includes: A capture unit, used for calling the rewritten video frame capture function to capture the original video frames from the video stream frame by frame and save them into a buffer; A storage unit is connected to the capture unit and is used to obtain the saved original video frame from the buffer and convert it into an I420Buffer format.
8. The watermark adding system according to claim 6, characterized in that: The format conversion module comprises: A format conversion unit, configured to convert each original video frame from the first format to a second format using the JNI method; A bitmap conversion unit is connected to the format conversion unit and is used to convert the original video frame in the second format into the original image bitmap object.
9. The watermark adding system according to claim 8, characterized in that: The second format is NV21 format, and the format conversion unit includes: A width and height acquisition subunit, for acquiring the width and height of each original video frame and calculating the data size of its Y, U, and V component data; An array creation subunit, connected to the width and height acquisition subunit, is used to create a data storage array, and then respectively acquires the buffer objects of the Y, U, and V component data and the strides of the U component and the V component, and copies the buffer object of the Y component data to the data storage array; The format conversion subunit is connected to the array creation unit, and is used to call a JNI method to traverse the U component data and the V component data and insert them into the data storage array to obtain an NV21 data array, and return the original video frame as the second format.
10. The watermark adding system according to claim 9, characterized in that: The bitmap conversion unit comprises: A bitmap conversion subunit is used to create a memory allocation input object and a memory allocation output object, copy the data in the NV21 data group into the memory allocation input object, perform format conversion on the memory allocation input object and store the conversion result into the memory allocation output object; The bitmap drawing subunit is connected to the bitmap conversion subunit and is used to create a blank bitmap object, and copy the data in the memory allocation output object to the blank bitmap object to obtain the original bitmap object.