Real-time video transcoding sending method and device and user terminal
Technical Field
the present invention relates to the field of communications, and in particular, to a method and an apparatus for transmitting a real-time video transcoding, and a user terminal.
background
With the rapid development of science and technology, in order to meet the requirements of video users to the maximum extent, a video real-time transmission technology is continuously developed, on one hand, a camera is also developed to a current high-definition digital camera from an original analog camera, on the other hand, the camera is subjected to real-time acquisition and processing of video data, then the video data are uploaded to a cloud server, and the video real-time transmission of the video data which are downloaded to one or more background user sides through the cloud server is also a mainstream at present.
The use of a large number of high-definition digital cameras leads to a rapid increase in the output video code stream, the cost of the transmission bandwidth is higher, and a common commercial camera usually adopts the peltier system (PAL system), that is, the output single-channel video code stream transmits 25 frames of pictures per second, and usually occupies about 2M or more of the transmission bandwidth. To realize remote real-time transmission of multiple video camera streams, the real-time transmission of video is usually accelerated by increasing the bandwidth, which is also very expensive.
In addition, for some video monitoring of merchants or companies, the video monitoring is generally deployed in an intranet environment and can be accessed in a local area network, but the external network cannot necessarily be accessed, and particularly, when the local area network is isolated, remote real-time monitoring cannot be directly realized, so that the application scene of the existing video monitoring system is often limited by the intercommunication condition of the local area network and the external network and can only be applied to a certain network condition, for example, when the local area network can access the external network, the video monitoring system can be uploaded to a cloud server to realize remote monitoring, and when the local area network is isolated, the video monitoring system is only applied to video monitoring in the intranet.
disclosure of Invention
In view of the above problems, the present invention provides a method, an apparatus and a user terminal for transcoding a real-time video.
In order to solve the above problems, the present invention provides a method for transmitting a real-time video stream transcoding, which is applied to a user terminal and a cloud server, and comprises:
Encapsulating the input transcoding code stream according to a preset stream encapsulation format to obtain a video stream data packet;
According to the intercommunication condition of a local area network where a user terminal is located and the Internet, the video stream data packet is sent through a first network port or a second network port, wherein the first network port is connected with the local area network, and the second network port is connected with the Internet;
and sending the video stream data packet to a cloud server according to a preset transmission protocol and the selected internet access.
Further, the "sending the video stream data packet through the first network port or the second network port according to the intercommunication between the local area network where the user terminal is located and the internet" includes:
if the video stream data packets are communicated with the cloud server, the video stream data packets are selected to be sent to the cloud server through the first internet access; and if the video stream data packet is not communicated with the cloud server, the video stream data packet is selected to be sent to the cloud server through the second network port.
Further, the "interworking between the local area network where the user terminal is located and the internet" includes:
And detecting the intercommunication condition of the local area network and the Internet by checking the gateway address of the local area network and testing whether the gateway address can access the Internet.
Further, the preset transmission protocol is an RTMP protocol.
In addition, the present invention also provides a real-time video transcoding transmitting apparatus, which is applied to a user terminal and a cloud server, and includes:
The packaging unit is used for packaging the input transcoding code stream according to a preset stream packaging format to obtain a video stream data packet;
the network port management unit is used for selecting a first network port or a second network port to send the video stream data packet according to the intercommunication condition between a local area network where the user terminal is located and the Internet, wherein the first network port is connected with the local area network, and the second network port is connected with the Internet;
And the sending unit is used for sending the video stream data packet to a cloud server according to a preset transmission protocol and the selected internet access.
Further, the network port management unit is configured to detect an interworking condition between the local area network and the internet, and if interworking occurs, select to send the video stream data packet to a cloud server through the first network port; and if the video stream data packet is not communicated with the cloud server, the video stream data packet is selected to be sent to the cloud server through the second network port.
further, the sending unit sends the video stream data packet to the cloud server through an RTMP protocol.
further, the real-time video transcoding transmitting apparatus further includes:
the acquisition module is used for acquiring video image signals output by the analog and digital cameras in real time;
And the transcoding module is used for transcoding the video image signal in real time and obtaining the transcoded code stream.
In addition, the invention also provides a user terminal, which comprises a memory and a processor, wherein the memory is used for storing the real-time video transcoding sending program, and the processor runs the real-time video transcoding sending program so as to enable the user terminal to execute the real-time video transcoding sending method.
Furthermore, the present invention also provides a computer storage medium, in which a computer program is stored, and the computer program controls the computer storage medium to execute the real-time video transcoding transmitting method as described above.
The real-time video transcoding sending method, the device and the user terminal provided by the invention are not limited by whether the local area network where the user terminal is located is communicated with the Internet or not, are suitable for real-time video remote transmission and monitoring under the condition that the local area network where the user terminal is located is not isolated or isolated, and increase the system compatibility and the practicability.
drawings
in order to more clearly illustrate the technical solution of the present invention, the drawings required to be used in the embodiments will be briefly described below, and it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope of the present invention. Like components are numbered similarly in the various figures.
Fig. 1 is a flowchart illustrating a real-time video stream transcoding method according to a first embodiment of the present invention;
Fig. 2 is a flowchart illustrating a real-time video stream transcoding method according to a second embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a real-time video stream transcoding and transmitting apparatus according to the present invention;
Fig. 4 is a schematic structural diagram of an acquisition module of the real-time video stream transcoding transmitting apparatus according to the present invention;
fig. 5 is a schematic structural diagram of a transcoding module of the apparatus for transcoding a real-time video stream according to the present invention;
Fig. 6 is a schematic structural diagram of a portal management unit of the apparatus for real-time transcoding and transmitting a video stream according to the present invention.
Description of the main element symbols:
An acquisition module-100; a transcoding module-200; a packaging unit-300; a network port management unit-400; a transmitting unit-500;
An analog acquisition unit-110; a digital acquisition unit-120;
An image frame acquisition unit-210; a frame extraction processing unit-220; an encoding unit-230;
A first portal-410; a second port-420; management unit-430.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the present invention, "a plurality" means two or more unless specifically defined otherwise.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein in the description of the real-time video stream transcoding method is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the term "and/or" includes any and all combinations of one or more of the associated listed items.
The following detailed description of embodiments of the invention refers to the accompanying drawings.
the real-time video transcoding sending method is suitable for a video transcoding sending system, and transcoding code streams obtained after real-time video transcoding are subjected to corresponding format packaging processing and sent to a cloud server for a background user to perform remote monitoring or viewing and other operations.
Example 1
Fig. 1 is a flowchart illustrating a real-time video stream transcoding transmitting method according to a first embodiment of the present invention. The method provided by the invention is applied to the user terminal and the cloud server, and comprises the following steps:
And S100, encapsulating the input transcoding code stream according to a preset stream encapsulation format to obtain a video stream data packet.
The method includes the steps that format encapsulation needs to be carried out on an input transcoding code stream before the input transcoding code stream is sent to a cloud server, the preset stream encapsulation format adopts an FLV (flash video) encapsulation format, and video stream data packets in the FLV format are obtained through encapsulation according to the FLV encapsulation format, wherein the preset video stream format encapsulation can also be in an RMVB format, an MKV format (MKV, Multimedia Container), an MPEG2-TS format and the like.
and S200, sending the video stream data packet through a first network port or a second network port according to the intercommunication condition of the local area network where the user terminal is located and the Internet, wherein the first network port is connected with the local area network, and the second network port is connected with the Internet.
the local area network is an internal network including a camera and a video monitoring user terminal, the internet is other wide area networks except the local area network, generally referred to as external networks, and the cloud server is in the internet. The first network port is connected with the local area network, the second network port is connected with the internet, and the priority of the first network port is preset to be higher than that of the second network port. If the local area network is communicated with the internet, the internet can be accessed through both the first network port and the second network port, and the video stream data packet is preferentially sent to the cloud server through the first network port according to the preset priority, while the second network port is reserved for standby so as to reduce the power consumption of the system, and at the moment, the first network port is not only responsible for communicating with the camera in the local area network to acquire the video image signal of the camera in real time, but also responsible for sending the video stream data packet to the cloud server. If the local area network is not intercommunicated with the Internet, the local area network is isolated and cannot send data to an external network through the first network port, so that the video stream data packet is sent to the cloud server through the second network port, and the first network port is still connected with the local area network and is used for collecting video image signals of the camera.
The intercommunication condition of the local area network and the internet can be determined by checking the gateway address of the local area network and testing whether the gateway address can normally access an external network website, if so, the intercommunication of the local area network and the internet is indicated, otherwise, the intercommunication of the local area network and the internet is not indicated.
And S300, sending the video stream data packet to a cloud server according to a preset transmission protocol and the selected internet access.
the preset transmission Protocol is a Real Time Message Protocol (RTMP Protocol) and belongs to an application layer Protocol. In the process of transmitting media data by the RTMP protocol, firstly establishing RTMP connection based on a transmission layer connection through 'handshaking', then encapsulating the media data into messages and dividing the messages into message blocks, and finally sending the divided message blocks out through the TCP protocol. The transport layer protocol is a Transmission Control Protocol (TCP), which is a connection-oriented, reliable transport layer communication protocol based on byte streams.
In this embodiment, sending the video stream packet to the cloud server based on the RTMP protocol and the selected internet access specifically includes: and performing RTMP connection with the cloud server, packaging the video stream data packet into a message, dividing the message into message blocks, and finally sending the divided message blocks to the cloud server through a TCP (transmission control protocol). And the cloud server receives and recombines the messages, and then the video stream data can be recovered by decapsulating the messages.
the real-time video transcoding sending method provided by the invention can select the corresponding network port to send the video stream data packet according to the intercommunication condition of the local area network where the camera is positioned and the Internet without being limited by whether the local area network is isolated or not, thereby increasing the system compatibility and the practicability.
Example 2
Fig. 2 is a diagram illustrating a real-time video transcoding transmitting method according to a second embodiment of the present invention. Based on the first embodiment, the second embodiment further includes the following steps:
Step S10: raw image data of an input video is acquired.
The input video comprises an analog video image signal output by an analog camera and a digital video image signal output by a digital camera, and the original image data is obtained by acquiring the video image signal in real time and carrying out corresponding processing.
Specifically, the analog video image signal is acquired in real time and is subjected to corresponding digital processing to obtain digital original image data, where the digital processing specifically may include: sampling, quantization, coding, data separation processing of gray level and color of the image, and the like.
For a digital video image signal output by a digital camera or a network camera in a local area network, an RTSP Protocol (Real Time Streaming Protocol) may be adopted to collect the digital video image signal, which may specifically include: and acquiring the IP address of the digital camera or the network camera, establishing a transmission layer protocol-based connection with the camera, acquiring an RTSP video stream, and performing protocol analysis and coding format decoding on the acquired RTSP video stream to acquire original image data.
step S20: and performing corresponding transcoding processing on the original image data to obtain a transcoded code stream.
the corresponding transcoding process specifically includes: obtaining an original image frame from the original image data; extracting the original image frame according to a preset frame extraction rule to obtain an extracted image frame; selecting corresponding frames from the extracted image frames as key frames according to a preset frame interval, and taking other frames as common frames; and performing compression coding on the key frames and the common frames according to a preset compression coding algorithm to obtain the transcoding code stream.
The preset frame extraction rule adopts equal-interval frame extraction, specifically, an interval value is obtained by rounding the ratio of the input frame rate of the input video to the target frame rate, and the original image frames are extracted at equal intervals according to the interval value. The preset decimation frame principle can include, but is not limited to, equal interval decimation frames, and can also include progressive interval decimation frames, random decimation frames, and the like.
the preset inter-frame distance refers to the number of frames between two preset key frames. The key frame comprises a complete picture, and other frames are not required to be relied on to complete image reconstruction. The extracted image frames are from original image frames which are independent from each other, so that key frames selected from the extracted image frames all comprise complete pictures, and the position of the next key frame is determined according to the preset frame interval. In this embodiment, the first frame of the extracted image frames is selected as the first key frame, and corresponding other frames are selected from the extracted image frames as the second to nth key frames according to the preset inter-frame distance. The key frames and the common frames are compressed and encoded according to a preset compression encoding algorithm to obtain a transcoding code stream, wherein the obtained transcoding code stream is also called a sequence, generally consists of 1I frame and a plurality of P frames or consists of 1I frame, a plurality of P frames and B frames, and starts from the I frame until the next I frame arrives.
The I frame is also called an intra-frame prediction coding frame and is obtained by carrying out compression coding on intra-frame space redundant information on the key frame, and a complete image can be reconstructed by only using the data of the I frame during decoding. The P frame is obtained by inter-frame compression coding the normal frame with the I frame as a reference, wherein the P frame is also called a forward predictive coding frame, and is obtained by compressing data of the frame according to different points between the frame and an adjacent previous frame (I frame or P frame), and a complete picture needs to be reconstructed with reference to image information of the previous frame (I frame or P frame) during decoding. The B frame is also called a bidirectional predictive coding frame, and compresses data of a frame according to a difference between an adjacent previous frame (I frame or P frame), the frame and a next frame (P frame), and a complete picture needs to be reconstructed with reference to image information of the previous frame (I frame or P frame) and the next frame (P frame) when decoding.
in the embodiment, an H.264 compression coding algorithm is adopted to perform intraframe compression coding on the key frame to obtain an I frame; and performing interframe compression coding on the common frame by taking the I frame as a reference to obtain a P frame, wherein the I frame and the P frame form the transcoding code stream. The common frame in this embodiment may be encoded into a P frame or a B frame, so that the transcoded bit stream is composed of an I frame, a P frame, and a B frame. The compression coding algorithm is not limited to the h.264 algorithm, but may be an MPEG-4 algorithm, an h.265 algorithm, or a hybrid algorithm combining the above listed algorithms, and the like. And then, step S100, step S200 and step S300 are executed to send the transcoded code stream to the cloud server.
According to the invention, the video image signals are collected, the corresponding original image data are obtained, then the frame extraction transcoding processing is carried out on the original image data, and the transcoded code stream after the frame extraction transcoding is sent to the cloud server, so that the system compatibility and the practicability are increased, the transmission frame rate is reduced, and the video transmission bandwidth cost is reduced.
Example 3
Fig. 3 is a schematic structural diagram of a real-time video stream transcoding transmitting device according to the present invention. The real-time video stream transcoding and transmitting device comprises: encapsulation unit 300, portal management unit 400, and sending unit 500. The apparatus for transcoding and sending a real-time video stream provided by this embodiment further includes: an acquisition module 100 and a transcoding module 200.
The acquisition module 100 is used for acquiring a video image signal of a local camera in real time, and referring to fig. 4, the acquisition module 100 specifically includes: an analog acquisition unit 110 and a digital acquisition unit 120. After establishing physical connection with an analog camera through a coaxial cable, the analog acquisition unit 110 directly performs video real-time acquisition on an analog video image signal and obtains original image data in a digital form through corresponding digital processing; the digital collecting unit 120 collects the digital video image signal of the digital camera or the network camera in the local area network through the RTSP protocol. The acquisition module 100 may also acquire and process multiple corresponding video image signals through multiple analog or digital acquisition channels, respectively.
The acquisition module 100 may further include only an analog acquisition unit 110 or a digital acquisition unit 120, so as to perform single-path or multi-path video acquisition on the corresponding cameras.
the transcoding module 200 is configured to perform corresponding transcoding processing on the original image data obtained by the acquisition module 100, and referring to fig. 5, the transcoding module 200 includes: an image frame acquiring unit 210, a frame extracting processing unit 220 and an encoding unit 230. The video transcoding process of this embodiment is: the image frame acquiring unit 210 reads the original image data from the acquisition module 100 to acquire original image frames of each frame and sends the original image frames to the frame extracting unit 220 for frame extracting. The frame extraction processing unit 220 extracts the original image frames according to an equal-interval frame extraction rule to obtain extracted image frames, where the equal-interval frame extraction rule is to obtain interval values by rounding a ratio of an input frame rate to a target frame rate of the video, and extract the original image frames at equal intervals according to the interval values. The encoding unit 230 performs compression encoding on the extracted image frame according to a preset compression encoding algorithm to obtain a transcoding code stream. In the embodiment, an H.264 compression coding algorithm is adopted to perform compression coding on the extracted image frame and finally obtain an H.264 transcoding code stream.
The transcoding module 200 may also adopt other transcoding methods, for example, frame extraction is performed on the acquired video data according to a preset frame extraction rule, and then the extracted frame data is completely decoded and re-encoded, so as to achieve the purpose of frame-dropping transcoding of the video. The preset frame extraction rule may not be limited to equal-interval frame extraction, but may also be a random frame or progressive frame extraction. The preset compression encoding algorithm may not be limited to the h.264 algorithm, but may also be an MPEG-4 algorithm, an h.265 algorithm, or the like.
The encapsulating unit 300 is configured to encapsulate the input transcoded bit stream according to a preset stream encapsulation format to obtain a video stream packet. In this embodiment, the transcoded bit stream is encapsulated into an FLV video stream packet by using an FLV encapsulation format.
The port management unit 400 is configured to select, according to an interworking condition between the local area network where the camera is located and the internet, to send the video stream data packet through a first port or a second port, where the first port is connected to the local area network and the second port is connected to the internet.
Referring to fig. 6, the portal management unit 400 includes a first portal 410, a second portal 420 and a management unit 430, where the first portal 410 is used for connecting to the lan, the second portal 420 is used for connecting to the internet, and the management unit 430 is used for detecting an interworking condition between the lan and the internet and selecting the first portal or the second portal to send the video stream packet according to a detection result.
The sending unit 500 is configured to send the video stream data packet to a cloud server according to a preset transmission protocol and the selected internet access. In this embodiment, an RTMP protocol is used to send the video stream packet to the cloud server.
The real-time video transcoding sending device provided by the invention can select the corresponding network port to send the video streaming data packet according to the intercommunication condition of the local area network where the user terminal is located and the Internet without being limited by whether the local area network is isolated or not, and the system compatibility and the practicability are improved.
The invention also provides a user terminal which comprises a memory and a processor, wherein the memory is used for storing the real-time video transcoding sending program, and the processor runs the real-time video transcoding sending program so as to enable the user terminal to execute the real-time video transcoding sending method.
The invention also provides a computer storage medium, in which a computer program is stored, and the computer program controls the computer storage medium to make a computer execute the real-time video transcoding sending method as described above when running.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative and, for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, each functional module or unit in each embodiment of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention or a part of the technical solution that contributes to the prior art in essence can be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.