Disclosure of Invention
The embodiment of the invention provides a video playing method, a medium and a related device, which are used for realizing on-demand and live broadcast switching and time-shift watching of an HLS video in the process of live broadcast streaming of the HLS video.
The embodiment of the invention provides a video playing method, wherein in the process of video live broadcast, a live broadcast index file and an on-demand index file are generated simultaneously;
the method comprises the following steps:
when a video playing request is received, judging whether the video playing request is a video live broadcast request or a video on demand request;
if the request is a video live broadcast request, acquiring the live broadcast index file and sending the live broadcast index file to a requesting party;
and if the request is a video on demand request, acquiring the on demand index file, and supplementing an end field in the acquired on demand index file and then sending the on demand index file to the requesting party.
Optionally, in the video live broadcast process, the live broadcast index file and the on-demand index file are generated simultaneously according to the following method:
in the video live broadcast process, receiving original data and processing parameters of a video source and an audio source, wherein the processing parameters comprise the slice length and the number of a hypertext transfer protocol live broadcast stream (HLS) and encoding parameters;
coding the original data according to the coding parameters to obtain video coding data and audio coding data;
packaging the video coding data and the audio coding data into a data packet with a preset format;
segmenting the data packet according to the HLS slice length and the number to obtain TS slice files with corresponding number; and are
And generating a live broadcast index file and an on-demand index file, wherein the live broadcast index file comprises the TS slice file obtained this time, and the on-demand index comprises all the TS slice files.
Optionally, generating the on-demand index file specifically includes:
and supplementing the TS slice file obtained this time into the on-demand index file.
Optionally, the determining whether the video playing request is a video live broadcast request or a video on demand request specifically includes:
judging whether the video playing request is a video live broadcasting request or a video on demand request according to the time point of receiving the video playing request; or
And judging whether the video playing request is a video live broadcasting request or a video on demand request according to the access path or the access interface of the received video playing request.
An embodiment of the present invention provides a video playing device, including:
the generating unit is used for simultaneously generating a live broadcast index file and an on-demand index file in the video live broadcast process;
the device comprises a judging unit, a video playing unit and a video playing unit, wherein the judging unit is used for judging whether a video playing request is a live video request or a video on demand request when the video playing request is received;
the response unit is used for acquiring the live broadcast index file and sending the live broadcast index file to a requester if the judgment unit judges that the request is a video live broadcast request; and if the judging unit judges that the request is a video on demand request, acquiring the on demand index file, supplementing an end field in the acquired on demand index file, and then sending the end field to the requesting party.
Optionally, the generating unit specifically includes:
the receiving subunit is used for receiving original data and processing parameters of a video source and an audio source in a video live broadcast process, wherein the processing parameters comprise the slice length and the number of a hypertext transfer protocol live broadcast stream HLS and encoding parameters;
the encoding subunit is used for encoding the original data according to the encoding parameters to obtain video encoding data and audio encoding data;
the packaging subunit is used for packaging the video coding data and the audio coding data into a data packet with a preset format;
the slicing subunit is used for segmenting the data packet according to the HLS slicing length and the number to obtain TS slicing files with corresponding number;
and the generation subunit is used for generating a live broadcast index file and an on-demand index file, wherein the live broadcast index file comprises the TS slice file obtained this time, and the on-demand index comprises all the TS slice files.
Optionally, the generating subunit is configured to supplement the currently obtained TS slice file to the on-demand index file.
Optionally, the determining unit is specifically configured to determine, according to a time point at which the video playing request is received, whether the video playing request is a live video request or a video-on-demand request; or judging whether the video playing request is a video live broadcast request or a video on demand request according to the access path or the access interface of the received video playing request.
An embodiment of the present invention provides a computing apparatus, including at least one processing unit and at least one storage unit, where the storage unit stores a computer program, and when the program is executed by the processing unit, the processing unit is enabled to execute the steps of any of the video playing methods described above.
An embodiment of the present invention provides a computer-readable medium, which stores a computer program executable by a computing device, and when the program runs on the computing device, the computer program causes the computing device to execute the steps of any of the video playing methods described above.
The video playing method, the media and the related device provided by the embodiment of the invention generate the on-demand index file for the user to call when on-demand while generating the live index file, so that the on-demand and live can be switched randomly while live broadcasting is carried out, and a time-shifting watching function is supported.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Detailed Description
In order to support random switching between on-demand and live broadcasting in the process of live video broadcasting and realize time-shift watching, the embodiment of the invention provides a video playing method, a medium and a related device.
The preferred embodiments of the present invention will be described below with reference to the accompanying drawings of the specification, it being understood that the preferred embodiments described herein are merely for illustrating and explaining the present invention, and are not intended to limit the present invention, and that the embodiments and features of the embodiments in the present invention may be combined with each other without conflict.
The inventor finds that an old index file needs to be deleted in real time in the existing live video streaming process based on the HLS protocol, so that if a user wants to see videos at past moments in the live video streaming process, a server cannot perform corresponding audio and video pushing, that is, the existing HLS protocol does not support any switching between on-demand and live video in the live video streaming process, the user can perform on-demand watching only after the server generates an on-demand index file at the end of live video, and therefore the existing HLS protocol does not support time-shifting watching.
In view of this, an embodiment of the present invention provides a video playing method, in a video live broadcasting process, an on-demand index file that has played a video is generated while a live broadcast index file is generated, and is invoked when the on-demand index file is shared with a user for on-demand broadcasting, so that an arbitrary switch between on-demand broadcasting and live broadcasting is realized, and a time-shift watching function is realized.
Fig. 1 is a schematic diagram of an on-demand index file, and fig. 2 is a schematic diagram of a live index file. After receiving a video playing request, a video player or a browser first judges whether the request is an on-demand request or a live broadcast request, and performs subsequent processing. If the request is on-demand, the playing of the TS video in the index file is finished, and jumping is supported in the playing. If the request is a live broadcast request, TS videos in the index file are sequentially played from the beginning, the index file is requested again after the playing is finished, the playing is performed sequentially, and skipping cannot be performed. Therefore, the conventional HLS playing technology cannot satisfy the switching between on-demand and live broadcasting, and the time-shift viewing function.
In the embodiment of the invention, in order to meet the time-shifting watching requirement in the live video broadcasting process, the video playing method and the video playing system compatible with the HLS technology are provided, the random switching between on-demand broadcasting and live broadcasting is realized, and the time-shifting watching function is supported, so that the existing video player or browser can meet the time-shifting watching requirement without redevelopment.
In specific implementation, in the video live broadcasting process, the video playing method provided in the embodiment of the present invention generates the live broadcast index file and the on-demand index file of the played video at the same time, and specifically, the live broadcast index file and the on-demand index file may be generated according to the flow shown in fig. 3:
and S31, receiving the original data and processing parameters of the video source and the audio source in the video live broadcast process.
Wherein the processing parameters comprise the slice length and number of the HTTP Live Streaming (HLS) and the encoding parameters.
In this step, the video transcoder in the server receives the video stream input, which includes the original data of the video source and the audio source, such as RTSP, RTMP, UDP, etc.; in specific implementation, the processing parameters of the video processor are also input, including the length of the HLS slice, for example, 3 seconds, 5 seconds, or 10 seconds; the number of HLS slices, e.g., 3 or 5; and coding parameters of the video, such as 3 seconds, 5 seconds, or 10 seconds; number of HLS slices, e.g. 3 or 5; coding parameters of the video, such as code rate, frame rate, resolution; coding parameters of the audio, such as code rate, channel; other parameters such as subtitles, picture overlays, etc.
And S32, coding the original data according to the coding parameters to obtain video coding data and audio coding data.
In a specific implementation, the video transcoder may perform H264 coding, AAC coding, and the like on the original data, which is not limited in this embodiment of the present invention.
And S33, packaging the video coded data and the audio coded data into a data packet with a preset format.
For example, a video transcoder may encapsulate video encoded data and audio encoded data into MPEG-TS packets.
And S34, segmenting the data packet to obtain TS slice files with corresponding quantity according to the HLS slice length and quantity.
And S35, generating a live broadcast index file and an on-demand index file, wherein the live broadcast index file comprises the TS slice file obtained this time, and the on-demand index comprises all the TS slice files.
In this step, the video transcoder may perform slicing and live index generation conforming to the HLS protocol on the input video stream, and perform the supplementation of the on-demand index file at the same time. The live index includes n slices generated this time, for example, n may be 3 or 5; the on-demand index contains all the slices, and the TS slice file obtained at this time is supplemented into the on-demand index file after each new slice is generated.
In specific implementation, the video server updates the received HLS index file and the received slice file in real time and responds to a request of a user. Based on this, an embodiment of the present invention provides a video playing method, as shown in fig. 4, which is a schematic implementation flow diagram of the video playing method provided in the embodiment of the present invention, and the method may include the following steps:
s41, when receiving the video playing request, judging whether the video playing request is a video live broadcast request or a video on demand request, if the video live broadcast request is the video live broadcast request, executing the step S42, and if the video on demand request is the video on demand request, executing the step S43.
In the step, the video server can judge whether the video playing request is a live video request or a video on demand request according to the time point of receiving the video playing request; or judging whether the video playing request is a video live broadcast request or a video on demand request according to the access path or the access interface of the received video playing request.
Specifically, the video server may determine whether the request is a live broadcast request or an on-demand broadcast request according to a time point of a broadcast request sent by a user. The video server can also provide different access paths and access interfaces for the outside to distinguish the live request from the on-demand request.
And S42, acquiring the live index file and sending the live index file to a requester, and ending the process.
In this step, if the request sent by the user is a live broadcast request, the live broadcast index file generated by the video transcoder is read and returned to the user.
And S43, acquiring the on-demand index file, and sending the on-demand index file to the requester after supplementing an end field in the acquired on-demand index file.
In this step, if the request sent by the user is a video-on-demand request, the current on-demand index file is read first, and then the end field "# EXT-X-ENDLIST" is supplemented to the on-demand index file, and then returned to the user.
Finally, when the live broadcasting is finished, the video transcoder deletes the live broadcasting index file, and then supplements an end field "# EXT-X-ENDLIST" at the bottom of the live broadcasting index file to generate a complete click-to-dial index file.
In the video playing method provided by the embodiment of the invention, the on-demand index file is generated while the video is live broadcast, so that the random switching between on-demand and live broadcast can be supported, the time-shifted viewing is realized, and the minimum time interval of the time-shifted viewing is the length of one TS slice.
It should be noted that, in this embodiment of the present invention, the video transcoder and the video storage device, for example, a video storage server, may be independently deployed, and in this embodiment, as shown in fig. 5, it is a schematic structural diagram of a system in which the video transcoder and the video storage device may be independently deployed. In a specific implementation, the video transcoder and the video storage device may also be disposed in the video server, which is not limited in this embodiment of the present invention.
When the video transcoder and the video storage device are independently deployed, the video transcoder completes the conversion from the video stream input to the HLS video stream, such as RTSP, RTMP, UDP, etc.; and generating a live index file and an on-demand index file, the input parameters of the video processor further including the length of the HLS slice, for example, 3 seconds, 5 seconds, or 10 seconds; number of HLS slices, e.g. 3 or 5; coding parameters of the video, such as code rate, frame rate, resolution; coding parameters of the audio, such as code rate, channel; other parameters such as subtitles, picture overlays, etc. The video storage server stores TS slice files, live broadcast index files and on-demand index files of HLS videos. The video server finishes the processing of a user request, and if a video playing request sent by the user is a video live broadcast request, a live broadcast index file generated by the video transcoder is read from the video storage server and returned to the user; if the video playing request sent by the user is a video-on-demand request, reading the current on-demand index file, then supplementing an ending field "# EXT-X-ENDLIST" to the on-demand index file, and then returning to the user. And the video player sends a video live broadcast request or a video on demand request to the video server according to the operation of the user.
Based on the same inventive concept, the embodiment of the present invention further provides a video playing apparatus, and as the principle of the apparatus for solving the problem is similar to the video playing method, the implementation of the apparatus can refer to the implementation of the method, and repeated details are not repeated.
As shown in fig. 6, which is a schematic structural diagram of a video playing apparatus according to an embodiment of the present invention, the video playing apparatus includes:
the generating unit 61 is used for simultaneously generating a live broadcast index file and an on-demand index file in the video live broadcast process;
the judging unit 62 is configured to, when receiving a video playing request, judge whether the video playing request is a live video request or a video-on-demand request;
a response unit 63, configured to, if the determining unit 62 determines that the request is a video live broadcast request, obtain the live broadcast index file and send the live broadcast index file to a requestor; if the determining unit 62 determines that the request is a video-on-demand request, the on-demand index file is obtained, and the obtained on-demand index file is supplemented with an end field and then sent to the requesting party.
The generating unit 61 specifically includes:
the receiving subunit is used for receiving original data and processing parameters of a video source and an audio source in a video live broadcast process, wherein the processing parameters comprise the slice length and the number of a hypertext transfer protocol live broadcast stream HLS and encoding parameters;
the encoding subunit is used for encoding the original data according to the encoding parameters to obtain video encoding data and audio encoding data;
the packaging subunit is used for packaging the video coding data and the audio coding data into a data packet with a preset format;
the slicing subunit is used for segmenting the data packet according to the HLS slicing length and the number to obtain TS slicing files with corresponding number;
and the generation subunit is used for generating a live broadcast index file and an on-demand index file, wherein the live broadcast index file comprises the TS slice file obtained this time, and the on-demand index comprises all the TS slice files.
Preferably, the generating subunit is configured to supplement the currently obtained TS slice file to the on-demand index file.
In specific implementation, the determining unit 62 is specifically configured to determine, according to a time point at which the video playing request is received, whether the video playing request is a live video request or a video-on-demand request; or judging whether the video playing request is a video live broadcast request or a video on demand request according to the access path or the access interface of the received video playing request.
For convenience of description, the above parts are separately described as modules (or units) according to functional division. Of course, the functionality of the various modules (or units) may be implemented in the same or in multiple pieces of software or hardware in practicing the invention.
Having described the video playback method and apparatus according to an exemplary embodiment of the present invention, a computing apparatus according to another exemplary embodiment of the present invention is described next.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or program product. Thus, various aspects of the invention may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
In some possible embodiments, a computing device according to the present invention may comprise at least one processing unit, and at least one memory unit. Wherein the storage unit stores program code, which, when executed by the processing unit, causes the processing unit to perform the steps of the video playing method according to various exemplary embodiments of the present invention described above in this specification. For example, the processing unit may execute step S41 shown in fig. 4, determine whether the video playing request is a live video request or a video on demand request when the video playing request is received, execute step S42 if the video playing request is a live video request, execute step S43 if the video on demand request is a video on demand request, and execute step S42, acquire the live index file and send to the requestor, where the process ends, and execute step S43, acquire the on demand index file, and send to the requestor after an end field is supplemented in the acquired on demand index file.
The computing device 70 according to this embodiment of the invention is described below with reference to fig. 7. The computing device 70 shown in fig. 7 is only an example and should not impose any limitations on the functionality or scope of use of embodiments of the present invention.
As shown in fig. 7, the computing apparatus 70 is embodied in the form of a general purpose computing device. Components of computing device 70 may include, but are not limited to: the at least one processing unit 71, the at least one memory unit 72, and a bus 73 connecting the various system components (including the memory unit 72 and the processing unit 71).
Bus 73 represents one or more of any of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus architectures.
The storage unit 72 may include readable media in the form of volatile memory, such as Random Access Memory (RAM)721 and/or cache memory 722, and may further include Read Only Memory (ROM) 723.
The memory unit 72 may also include a program/utility 725 having a set (at least one) of program modules 724, such program modules 724 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Computing device 70 may also communicate with one or more external devices 74 (e.g., keyboard, pointing device, etc.), with one or more devices that enable a user to interact with computing device 70, and/or with any devices (e.g., router, modem, etc.) that enable computing device 70 to communicate with one or more other computing devices. Such communication may be through an input/output (I/O) interface 75. Also, computing device 70 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) through network adapter 76. As shown, network adapter 76 communicates with other modules for computing device 70 over bus 73. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with computing device 70, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
In some possible embodiments, the aspects of the video playing method provided by the present invention may also be implemented as a program product, which includes program code, when the program product runs on a computer device, the program code is configured to enable the computer device to execute the steps in the video playing method according to various exemplary embodiments of the present invention described above in this specification, for example, the computer device may execute step S41 shown in fig. 4, when receiving a video playing request, determine whether the video playing request is a video live request or a video on demand request, execute step S42 if the video playing request is received, execute step S43 if the video on demand request is received, and execute step S42, obtain the live index file to send to a requesting party, end the process, and obtain the on demand index file in step S43, and sending the obtained on-demand index file to the requesting party after supplementing an end field.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The program product for video playback of embodiments of the present invention may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a computing device. However, the program product of the present invention is not limited in this regard and, in the present document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device over any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., over the internet using an internet service provider).
It should be noted that although several units or sub-units of the apparatus are mentioned in the above detailed description, such division is merely exemplary and not mandatory. Indeed, the features and functions of two or more of the units described above may be embodied in one unit, according to embodiments of the invention. Conversely, the features and functions of one unit described above may be further divided into embodiments by a plurality of units.
Moreover, while the operations of the method of the invention are depicted in the drawings in a particular order, this does not require or imply that the operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.