WO2013139146A1 - 一种实现flv视频播放的方法及装置 - Google Patents

一种实现flv视频播放的方法及装置 Download PDF

Info

Publication number
WO2013139146A1
WO2013139146A1 PCT/CN2012/086022 CN2012086022W WO2013139146A1 WO 2013139146 A1 WO2013139146 A1 WO 2013139146A1 CN 2012086022 W CN2012086022 W CN 2012086022W WO 2013139146 A1 WO2013139146 A1 WO 2013139146A1
Authority
WO
WIPO (PCT)
Prior art keywords
flv
file
player
stream
parsing
Prior art date
Application number
PCT/CN2012/086022
Other languages
English (en)
French (fr)
Inventor
郑双喜
Original Assignee
深圳创维数字技术股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳创维数字技术股份有限公司 filed Critical 深圳创维数字技术股份有限公司
Publication of WO2013139146A1 publication Critical patent/WO2013139146A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/40Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
    • H04N21/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/434Disassembling of a multiplex stream, e.g. demultiplexing audio and video streams, extraction of additional data from a video stream; Remultiplexing of multiplex streams; Extraction or processing of SI; Disassembling of packetised elementary stream
    • H04N21/4341Demultiplexing of audio and video streams

Definitions

  • the present invention relates to multimedia transmission technologies, and in particular, to a method and apparatus for implementing FLV video playback. Background technique
  • the android system is a major intelligent operating system. It has developed rapidly since its introduction and has become the most widely used intelligent operation in the global mobile device intelligent operating system. System, android system supports many video formats such as 3GP, MP4, TS, MKV, but there are some video formats that cannot support such as FLV, and FLV format video is 4 ⁇ due to its small file size, good video quality, and fast network download speed. Multi-video website support, because the Android system can not support the playback of FLV format video, which will affect the user's demand for video playback.
  • the technical problem to be solved by the embodiments of the present invention is to provide a method and a device for implementing FLV video playback, which can realize playing FLV format video files in an android system playing application, and satisfy the user's demand for FLV format video playing.
  • an embodiment of the present invention provides a method for implementing FLV video playback, including: Parsing the streaming media FLV file, converting the FLV file into a file format supported by the android system, and reconstructing the file format stream, where the file format supported by the android system includes a transmission TS stream format;
  • the parsing the FLV file, converting the FLV file into a file format supported by the android system, and the step of reconstructing the file format stream includes:
  • the FLV file including a local FLV file and an online FLV file
  • the step of parsing the FLV file specifically includes:
  • Reading an audio tag audio tag obtaining a low overhead transmission multiplexing latm header, constructing an audio data transmission stream adts header according to the latm header, wherein the constructing an adts header provides parameters for audio decoding;
  • the step of reconstructing the file format stream includes:
  • An adts header is added to the audio and video frame, and a frame length in the adts header includes the length of the adts header.
  • the providing the reconstructed file format stream to the built-in player includes: Establishing a hypertext transfer protocol service http server thread, controlling the http server thread to send a customized uniform resource locator URL to the built-in player;
  • the reconstructed file format stream is provided to the built-in player by the http server thread.
  • an embodiment of the present invention further provides an apparatus for implementing FLV video playback, including: a parsing module, a connection module, and a player, where
  • the parsing module is configured to parse the received FLV file, convert the FLV file into a file format supported by the android system, and reconstruct the file format stream;
  • connection module is configured to provide the reconstructed file format stream to the player by using an http server thread according to a file format stream reconstructed by the parsing module;
  • the player is configured to control playing the reconstructed file format stream according to the reconstructed file format stream provided by the connection module.
  • the parsing module includes:
  • a receiving unit configured to receive an FLV file, where the FLV file includes a local FLV file and an online FLV file;
  • a parsing unit configured to parse the FLV file according to the FLV file received by the receiving unit, so as to reconstruct the file format stream;
  • a converting unit configured to convert the FLV file into the file format supported by the android according to the parsing result of the parsing unit.
  • the parsing module further includes:
  • a control module configured to receive the play control information sent by the player, and control the FLV file according to the play control information.
  • the connection module includes:
  • a second control unit configured to control the http server thread to send a customized URL to the player
  • a second receiving unit configured to receive an HTTP verification request sent by the player according to the customized URL
  • a sending unit configured to send, according to the verification request received by the receiving unit, connection success information to the player, and provide the reconstructed file format stream to the player.
  • the technical problem to be solved by the embodiments of the present invention is to provide a method and a device for implementing FLV video playback, effectively solving the problem of combining with the android system interface and the hard solution of the FLV playback, and realizing playing the FLV video in the android system playing application. , to meet the user's demand for FLV video playback.
  • FIG. 1 is a flowchart of a first embodiment of a method for implementing FLV video playback according to an embodiment of the present invention
  • FIG. 2 is a flowchart of a second embodiment of a method for implementing FLV video playback according to an embodiment of the present invention
  • FIG. 3 is a flowchart of a third embodiment of a method for implementing an FLV video playback frequency according to an embodiment of the present invention
  • FIG. 4 is a schematic structural diagram of a first embodiment of an apparatus for implementing FLV video playback according to an embodiment of the present invention
  • FIG. 5 is a schematic structural diagram of a second embodiment of an apparatus for implementing FLV video playback according to an embodiment of the present invention
  • FIG. 6 is a schematic structural diagram of a third embodiment of an apparatus for implementing FLV video playback according to an embodiment of the present invention. detailed description
  • the embodiment of the invention provides a method and a device for realizing FLV video playing, effectively solving the combination with the android system interface and the hard solution problem of the FLV playing, and realizing playing the FLV video in the android system.
  • the embodiment of the present invention mainly implements support for FLV video playback in android 2.3 and above, and is convenient for developers to play FLV video files in any android system.
  • the technical solution for implementing the FLV video in the android system in the embodiment of the present invention requires two environmental conditions: First, the android system version must be able to support the playback of the TS stream. Second, the encoding format used in the audio and video of the FLV file must be the decoding format supported by the android system itself, otherwise the FLV file will fail to play.
  • FIG. 1 is a flowchart of a first embodiment of a method for implementing FLV video playback according to an embodiment of the present invention. The method includes:
  • the embodiment of the present invention needs to change the file format of the FLV video, and must be a file format that the android system can support.
  • the video formats supported by the android system include 3GP and MP4.
  • the TS stream format is adopted, that is, the function of playing the FLV video in the Android system is implemented, the FLV video format is parsed, and the FLV video format is converted into the TS stream format, and the weight is used.
  • the constructed TS stream format is used as the source data of the built-in player of the Android system, that is, the reconstructed TS stream is provided to the built-in player, and the built-in player is controlled to play the reconstructed TS.
  • Stream format thus Completing the playback in the TS stream format, in fact completes the playback of the real data source FLV video format in the android system.
  • the FLV video is played in the android system, including the control of the audio and video data of the FLV video, the playback control, etc., firstly, a main program is played, and the main thread is played before the video playback process is actually entered. It is also necessary to establish a background thread, the background thread is configured to parse the FLV file by providing a parsing conversion thread, convert the FLV file into a TS stream format supported by the android system, and reconstruct a file format stream of the TS stream.
  • the reconstructed file format stream is provided to a built-in player.
  • a processing scheme for converting the FLV video format into a TS stream format playback in the android system is proposed, and the FLV video format is parsed by the background thread. Converting the FLV video format into a TS stream format supported by the android system, and transmitting the reconstructed TS stream to a hypertext transfer protocol service http server thread, where the http server thread receives the received TS format stream as The source data is provided to the built-in player, and the TS format stream is played in the built-in player.
  • the http server thread is established by the main play thread, parallel with the main play thread, and is in the step S101.
  • the FLV file parsing conversion thread established by the background thread is also parallel.
  • the embodiment of the present invention provides the TS stream service to the built-in player through the http server thread established in the android system, thereby completing the docking of the android system interface.
  • the built-in player in the android system can continuously obtain the TS stream data provided by the http server thread, and the connection refers to the transmission.
  • Control protocol tcp connection that is, after the http server thread is established, it will receive the tcp connection of the main thread, and process the http verification request, and the FLV file can be parsed and converted only after returning the correct response to the playing main thread.
  • the TS format stream obtained in the process is provided as source data to the built-in player in the android system, so that the data processing in the process of parsing and converting the FLV file and the data playing in the built-in player playing process are established.
  • Make a connection that causes the FLV file to parse the data in the conversion thread The data playback during processing and playback of the built-in player is parallel, and the two do not affect each other.
  • the embodiment of the present invention first converts the FLV video format into a file format that the android system can support, and the file format that the android system can support includes the TS stream format, and
  • the http server thread provides the TS stream format as a data source to the player built in the android system, and plays the TS stream in the android system playing application, and completes the playback of the FLV video in the android system.
  • the playing main thread will actively contact the http server thread after establishing the http server thread, and determine whether the http server thread responds correctly to the http authentication request, if the http server thread issues "connection normal" The response indicates that the connection is successfully established, and the built-in player continuously receives the TS stream sent by the http server thread, and implements the playback of the TS stream, completing the FLV video file of the real data source in the android system. Play.
  • the process of controlling the built-in player to play the reconstructed file format stream includes: the built-in player determining whether the currently played is an FLV video format, and if the determination is yes, according to the The URL set by the android system standard interface receives the HTTP authentication request sent by the built-in player according to the customized URL, and if the connection request is successful, the http verification request is sent, and if the connection is successful according to the HTTP standard protocol, the http is indicated.
  • the server thread may provide a TS stream for the playing main thread, and if the determination is no, the playback process is exited.
  • the built-in player of the android system supports the feature of playing the TS format stream, and directly receives the TS from the http server thread.
  • Streaming data such that the decoding process of the audio and video data is processed by the android system, for example, the android system itself supports hardware decoding of audio and video encoding formats such as advanced audio encoding AAC, H264 AVC, etc., and finally will pass the application interface of the android system.
  • the http server thread is completed and After the docking of the built-in player in the android system, the playback of the FLV video format is completely completed by the android system, and the development process is the same as that of a normal media file such as MP4, and the FLV file parses the conversion thread and provides the TS stream.
  • the http server thread of the service is parallel with the data playback process of the built-in player of the android system, and does not affect the playback of the TS format stream by the built-in player of the android system.
  • the process of playing the FLV video format is the same as the process of playing the ordinary media file. Greatly reduce the difficulty of development.
  • FIG. 2 is a flowchart of a second embodiment of a method for implementing FLV video playback according to an embodiment of the present invention. The method includes:
  • the background thread first needs to obtain the data of the FLV file, and the FLV file can be parsed and converted only by the background thread acquiring the FLV file, where the acquired FLV file includes the local FLV file and the online FLV.
  • a file, wherein the local FLV file can be stored in a secure data storage card SD card, and the online FLV file is from a network.
  • the background thread receives the control broadcast information sent by the player built in the android system while acquiring the FLV file, and controls the FLV file according to the information played by the control.
  • the FLV file in the embodiment of the present invention is generally composed of a file header (FLV header) and a plurality of text bodies (tag), according to
  • the FLV file obtained by the S201 parses the obtained FLV file, where the parsing comprises performing audio parsing and video parsing on the acquired FLV file, and the audio parsing of the FLV file is using advanced audio encoding AAC encoding.
  • the video parsing of the FLV file is encoded by standard video coding H264 AVC, wherein the most common formats of the AAC encoding include an audio data transmission layer ADTS and a low-open audio transmission multiplexing LATM.
  • the process of parsing the obtained FLV file in the embodiment of the present invention mainly includes: reading the FLV file header and the file body to obtain the file type and the lamt frame header of the FLV file. And the sps/pps information, constructing an adts frame header by using the obtained lapm frame header, thereby providing parameters for decoding audio and video of the FLV file, reading header information of the audio and video tag, and tag data area header, and obtaining The timestamp and time offset information provide a basis for reconstructing the TS stream process dts, pts.
  • the process of acquiring the FLV file in the step S201 is combined with the process of parsing the FLV file in the step S202 to implement the FLV file.
  • the parsing conversion, the parsing conversion of the FLV file is based on the size of the FLV file structure element parsed by the FLV file parsing thread in step S202 to determine the data length of the FLV file obtained in step S201, thus ensuring that the data read pointer is always At the edge of the FLV file structure element, this not only reduces the uncertainty of the data of the FLV file, but also can detect the errors in the FLV file and can deal with it in time, avoiding affecting the entire FLV file parsing conversion process and subsequent FLV. File playback.
  • step S202 further reconstructing the TS stream format, that is, the The FLV file is converted into the TS stream format supported by the Android system, and the process of the TS stream reconstruction includes: adding sps/pps information to each of the TS stream in the key frame header of the TS stream data, An adts header is added to the audio frame, and the frame length in the adts header includes the length of the adts header.
  • the background thread completes the parsing and conversion of the FLV video file
  • the parsing and converting of the FLV video file includes: providing a background thread to receive the FLV file, parsing the FLV file according to the received FLV file, and reconstructing Transmitting the file format, and converting the FLV file into a TS stream format supported by android, and providing the TS stream as a data source to the built-in player through the http server thread, thereby realizing playing the TS stream in the android system, and realizing Play on the real data source FLV file in android.
  • FIG. 3 is a method for implementing FLV video playback according to an embodiment of the present invention.
  • a flow chart of the third embodiment. The method includes:
  • parsing the streaming FLV file parsing the streaming FLV file, converting the FLV file into a file format supported by the android system, and reconstructing the file format stream, where the file format supported by the android system comprises transmitting a TS stream format;
  • the play main thread in the embodiment of the present invention establishes a tcp contact with the http server thread after the establishment of the http server thread is established, and the http server thread successfully sends a customized unified resource to the built-in player after the establishment of the http server thread.
  • Locator URL the customized URL can be in the following format: http://localhost: [port] or http://127.0.0.1:[port], the http server URL can be set through the android standard interface .
  • S303 Control the http server thread to receive an HTTP verification request sent by the built-in player according to the customized URL.
  • the http server thread is established by the playing main thread, and the playing main thread is used as the client of the http server, and the interface of the player built in the android system is connected by connecting the http server, the http After the server thread is started, waiting for the tcp connection request of the playing main thread, and receiving an HTTP verification request sent by the built-in player according to the customized URL according to the URL set by the android system standard interface, the http server thread According to the HTTP standard protocol, "connection success" is issued, indicating that the http server thread can provide a TS stream for the play main thread, and the http server thread is for parsing the data processing process of the FLV file and the FLV playing the main thread. Data docking is established between the video playing processes, so that the http server thread provides the TS stream service to complete the interface with the FLV playing main thread interface.
  • the http server thread in the embodiment of the present invention is the key to realize the interface with the android system interface, and the playing main thread sets the URL by calling the setting data source SetDataSource (string path) in the Media Player interface of the media player, and through the customized URL.
  • SetDataSource string path
  • Connect the http server thread to establish the FLV playback main thread and FLV solution The relationship between the conversion threads is analyzed, and the data docking between the data playback of the FLV playback main thread and the data analysis of the FLV parsing conversion thread is realized.
  • S304 Control the http server thread to send connection success information to the built-in player when the verification succeeds;
  • the http server thread is established by the playing main thread, and after the http server thread is started, waiting for the tcp connection request of the playing main thread, and receiving according to the URL set by the standard interface of the android system.
  • the built-in player sends an HTTP success request according to the customized URL, and the http server thread sends a connection success message to the built-in player when the verification succeeds, that is, the http server thread sends according to the HTTP standard protocol.
  • "Connected successfully" means that the http server thread can provide the TS stream as a source data stream to the player built into the android system.
  • the playing main thread sets the URL by calling SetDataSource (string path) in the MediaPlayer interface, and realizes data docking between the data playing of the main thread of the FLV playing and the data analysis of the FLV parsing conversion thread.
  • the actual docking process is performed internally in the setDataSource(string path) and prepare() methods, that is, the internal implementation of the android standard interface. Therefore, in the embodiment of the present invention, it is only necessary to write that the MediaPlayer is called.
  • the method of the setDataSource(string path) in the interface may be: determining, according to S304, that the mediaPlayer playing the main thread is ready to play, the http server receiving the TS stream reconstructed by the FLV parsing conversion thread, and using the TS stream as the source data.
  • the MediaPlayer of the FLV playing main thread calls the interface start() to start playing.
  • the reconstructed file format stream is provided to the built-in player by the http server thread.
  • the purpose of establishing an http server thread in the android system is to establish a connection between the FLV file parsing conversion thread and the playing main thread through the http server thread, so that the FLV file parsing conversion thread processes and plays the main thread.
  • the data playback in the parallel is the same, the two do not affect each other, so the playback main thread can get the ts stream continuously provided by the http server thread as long as the connection http server thread is completed, effectively controlling the playback interface with the android system.
  • FIG. 4 is a schematic structural diagram of a first embodiment of an apparatus for implementing FLV video playback according to an embodiment of the present invention. As shown in FIG. 4, the method includes: a parsing module 10, a connection module 20, and a player 30, where
  • the parsing module 10 is configured to parse the received FLV file, convert the FLV file into a file format supported by the android system, and reconstruct the file format stream;
  • the parsing module 10 is configured to parse the received FLV file, and convert the FLV file into a file format supported by the android system, and reconstruct the file format stream, so as to implement the android system.
  • the function of playing the FLV video, changing the file format of the FLV video, and the file format that the android system can support, such as the TS stream format, the reconstructed TS stream format parsed by the parsing module 10 is built into the android system.
  • the source data of the player completes the playback of the TS stream format, and in fact completes the playback of the FLV video format in the android system.
  • connection module 20 is configured to receive, by the http server thread, the file format stream reconstructed by the parsing module 10, and provide the reconstructed file format stream to the player 30;
  • connection module 20 in the embodiment of the present invention receives the TS stream obtained by parsing and converting the parsing module 10 through the http server thread, and provides the TS stream as source data to the player module 30, where
  • the connection module 20 receives the tcp connection of the play main thread through the http server thread, and processes the http verification request, and the connection module 20 can provide the TS stream as source data only if the verification request is correctly responded.
  • the play main thread can obtain the TS stream as long as the connection http server thread is completed, so that the parsing module 10 and the player 30 are A connection is established, that is, the data processing in the FLV file parsing conversion thread and the data playing of the player in the parsing module 10 are parallel, and the two do not affect each other, in the embodiment of the present invention.
  • the connection module 20 is completed by the http server thread to complete the docking with the player 30 in the android system, so that the connection module 20 provides the TS stream obtained in the parsing module 10 as source data to the play through the http server thread. 30.
  • the player 30 is configured to control playing the reconstructed file format stream according to the reconstructed file format stream provided by the connection module 20.
  • the first embodiment of the present invention converts the FLV video format into a TS stream format that can be supported by the android system through the parsing module 10, and the connection module 20 uses the http server thread to send the TS stream.
  • the format is provided as a data source to the player 30 built in the android system, and the TS stream is played in the android system playing application, and the FLV video is played in the android system.
  • the process of playing the reconstructed file format stream by the player 30 includes: the player 30 determining whether the currently playing is an FLV video format, and if the determination is yes, setting according to the android system standard interface.
  • the URL receives the HTTP authentication request sent by the player 30 according to the customized URL. If the connection request is successful, the http verification request is sent. If the http is successfully connected according to the HTTP standard protocol, the http server thread may be the The playback main thread provides the TS stream. If the judgment is no, the playback process is exited.
  • the play main thread in the embodiment of the present invention actively contacts the http server thread after establishing the http server thread, and determines whether the http server thread responds correctly to the http verification request, if the http server thread issues The "connected normal" response indicates that the connection is successfully established, and the built-in player continuously receives the TS stream sent by the http server thread, and implements the playback of the TS stream, completing the FLV video file for the real data source. Play in the android system.
  • connection module 20 in the embodiment of the present invention completes the docking with the player 30 in the android system through the http server thread
  • the player 30 directly receives the TS stream data from the connection module 20, so that the decoding process of the audio and video data is completely completed.
  • the android system is completed, and solves the problem that the FLV audio and video data is hard solved, and the development process is the same as that of the ordinary media file such as MP4, and the FLV file parsing conversion thread of the parsing module 10 and the connection for providing the TS stream service are provided.
  • the module 20 is parallel with the data playing process of the player 30 in the android system, and does not affect the playback of the TS format stream by the player 30 in the android system.
  • the process of playing the FLV video format is the same as the process of playing the ordinary media file. Reduce development difficulty.
  • FIG. 5 is a schematic structural diagram of a second embodiment of an FLV video playback device according to an embodiment of the present invention.
  • the implementation of the FLV video playback device includes: in addition to the connection module 20 and the player 30 in the FLV video device, the parsing module 10 further includes: a receiving unit 101, and an analysis Unit 102, conversion unit 103, control unit 104, wherein
  • the receiving unit 101 is configured to receive an FLV file, where the FLV file includes a local FLV file and an online FLV file;
  • the receiving unit 101 acquires the FLV file, and the FLV file can be parsed and converted by the background thread only after the FLV file is acquired by the receiving unit 101.
  • the FLV file acquired by the receiving unit 101 includes a local FLV file and an online FLV file, where The local FLV file can be stored on a secure data storage SD card.
  • the parsing unit 102 is configured to parse the FLV file according to the received FLV file received by the receiving unit 101, so as to reconstruct the file format stream;
  • the parsing unit 102 parses the FLV file received by the receiving unit 101 according to the FLV file acquired by the receiving unit 101, and the parsing includes the FLV acquired by the receiving unit 101.
  • the audio parsing and video parsing of the file, the parsing unit 102 parsing the FLV file received by the receiving unit 101 includes: reading the file type of the FLV file header to obtain the file, reading the audio tag of the FLV file, obtaining the lamt frame header and sps/ Pps information, and then constructing the adts frame header by the obtained lapm frame header, thereby providing parameters for audio decoding and video decoding, reading header information of the audio and video tag, and tag data area header, and obtaining timestamp and time offset information therefrom To provide a basis for reconstructing the TS stream process dts, pts calculation.
  • the converting unit 103 is configured to reconstruct the reconstructed file according to the parsing unit 102. a stream, converting the FLV file to the file format supported by the android.
  • the FLV file received by the receiving unit 101 is converted into the file format supported by the android according to the parsing result of the parsing unit 102, that is, the converting unit 103 is configured according to the parsing unit 102.
  • the FLV file received by the receiving unit 101 converts the audio and video data and the parsing result of the parameter, and further reconstructs the TS stream format, that is, the converting unit 103 converts the FLV file into a TS stream format supported by the android system.
  • the control unit 104 is configured to receive the play control information sent by the player 30, and control the FLV file according to the play control information.
  • the process of acquiring the FLV file by the receiving unit 101 and the process of parsing the acquired FLV file by the parsing unit 102 are generally combined.
  • the size of the FLV file structure element parsed by the parsing unit 102 determines the data length of the FLV file acquired by the receiving unit 101, so that the data read pointer is always at the edge of the FLV file structure element, thus reducing the receiving unit's acquisition.
  • the uncertainty of the FLV file data can also find that there is a problem with the acquired FLV file, and at the same time avoid affecting the entire FLV file parsing conversion process and subsequent FLV file playback.
  • the embodiment of the present invention analyzes how the background thread completes the parsing and conversion of the FLV video file, and the FLV file parsing conversion process includes the receiving unit 101 acquiring the FLV file, and the FLV file acquired by the parsing unit 102 according to the receiving unit 101. Parsing the acquired FLV file, the converting unit 103 converts the FLV file into the TS stream format supported by the android according to the parsing result of the parsing unit 102, and provides the TS stream as a data source to the FLV player.
  • the main thread that is, the TS stream is played in the android system playback application, which is to complete the playback of the real data source FLV file in the android system.
  • FIG. 6 is a schematic structural diagram of a third embodiment of an apparatus for implementing an FLV video playback apparatus according to an embodiment of the present invention.
  • the implementation of the FLV video playback device includes: in addition to the parsing module 10 and the player 30 in the FLV video playback device, the connection module 20 further includes: a second control unit 201.
  • the second receiving unit 202 and the sending unit 203 where
  • the second control unit 201 is configured to control the http server thread to send a customized URL to the player 30.
  • connection module 20 in the embodiment of the present invention completes the docking with the player 30 in the android system by using the http server thread
  • the player 30 and the connection module are established after the connection module 20 establishes the http server thread.
  • the second receiving unit 202 is configured to receive an HTTP verification request sent by the player module 30 according to the customized URL.
  • the http server thread in the embodiment of the present invention is established by the player 30, and the player 30 serves as a client connecting the r module 20, and completes the interface with the player 30 in the android system through the http server thread.
  • the connection module 20 waits for the tcp connection request of the player 30 after the http server thread is started, and receives the HTTP verification request sent by the player 30 according to the customized URL by the second receiving unit 202.
  • the connection module 20 sends a "connection success" according to the HTTP standard protocol, indicating that the connection module 20 can provide the TS stream to the player 30, so that the connection module 20 provides the TS stream service completion and the player 30. Interface docking.
  • the sending unit 203 is configured to send, according to the verification request received by the receiving unit 202, connection success information to the player 30 when determining that the verification request is successful, and send the reconstructed file format stream. Provided to the player module 30.
  • the http server thread in the embodiment of the present invention is a key for the connection module 20 to interface with the player 30 in the android system, and the connection module 20 waits for the player 30 after the http server thread is started.
  • a tcp connection request and according to the HTTP verification request sent by the player 30 according to the customized URL, according to the HTTP authentication request sent by the player 30, when the verification request is successful, the sending unit 203 is used to play the
  • the device 30 sends the connection success information, that is, the connection module 20 According to the HTTP standard protocol, "connection success" is issued, indicating that the connection module 20 can provide the TS stream as a source data stream to the player 30 in the android system, and implement the TS in the player module 30. Format stream.
  • the connection module 20 of the embodiment of the present invention receives the tcp connection of the player 30 through the http server thread, and processes the http verification request.
  • the connection module 20 can use the TS stream as the correct response only if the verification request is correctly received.
  • the source data is provided to the player 30, and a connection is established between the parsing conversion process of the parsing module 10 and the playing process of the player module 30 through the connection module 20, that is, the data processing in the file parsing conversion thread of the parsing module 10.
  • the data playback of the player 30 is parallel, and the two are mutually unaffected. Therefore, the player 30 can obtain the ts stream continuously provided by the connection module 20 as long as the connection connection module 20 is completed, thus effectively interacting with the android.
  • the docking of the interface of the player 30 of the system makes the FLV playback operation completely completed by the player 30, and the establishment of the FLV file parsing conversion thread and the http server thread does not play the FLV video format on the player 30.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本发明公开了一种实现FLV视频播放的方法,所述方法包括:解析流媒体FLV文件,将该FLV文件转换为android系统支持的文件格式,重构所述文件格式流,所述android系统支持的文件格式包括传输TS流格式;将所述重构的文件格式流提供给内置的播放器;控制所述内置的播放器播放所述重构的文件格式流。本发明还提供了一种实现播放FLV视频的装置。采用本发明实施例,可实现android系统在播放应用中播放FLV视频文件,满足用户对FLV视频播放的需求。

Description

一种实现 FLV视频播放的方法及装置
技术领域
本发明涉及多媒体传输技术, 尤其涉及一种实现 FLV视频播放 的方法及装置。 背景技术
目前智能移动设备越来越普遍, 并配置了智能操作系统, 其中 android系统是一种主要的智能操作系统, 自从面世后发展非常迅速, 已成为全球移动设备智能操作系统中应用最广的智能操作系统, android系统支持很多视频格式如 3GP、 MP4、 TS、 MKV, 但还有一 些视频格式无法支持如 FLV, 而 FLV格式视频因其自身文件体积小、 视频质量好、网络下载速度快成为 4艮多视频网站的支持,由于 android 系统却无法支持 FLV格式视频的播放, 这就会影响用户对视频播放 的需求。
现有技术中解决 android系统播放 FLV视频的方法,大多数都是采 用在 android系统上移植开源媒体库 ffmpeg来完成对 FLV文件的解析、 解码、 播放。
但现有技术存在很多缺陷如在 an dro i d系统上移植开源媒体库 ffmpeg非常复杂、 在 android系统上播放 FLV文件的硬解问题及与 android标准接口对接艮复杂。 发明内容
本发明实施例所要解决的技术问题在于, 提供一种实现 FLV视 频播放的方法及装置, 可实现在 android系统播放应用中播放 FLV格 式视频文件, 满足用户对 FLV格式视频播放的需求。
为了解决上述技术问题, 本发明实施例提供了一种实现 FLV视 频播放的方法, 包括: 解析流媒体 FLV文件,将该 FLV文件转换为 android系统支持的 文件格式, 重构所述文件格式流, 所述 android系统支持的文件格式 包括传输 TS流格式;
将所述重构的文件格式流提供给内置的播放器;
控制所述内置的播放器播放所述重构的文件格式流。
其中,所述解析 FLV文件,将该 FLV文件转换为 android系统支 持的文件格式, 重构所述文件格式流的步骤包括:
接收 FLV文件, 所述 FLV文件包括本地 FLV文件和在线 FLV 文件;
解析所述 FLV文件, 对所述 FLV音频数据和参数的解析; 重构所述文件格式流, 得到 android系统支持的文件格式。
其中, 所述解析所述 FLV文件的步骤具体包括:
读取 FLV文件头,并根据所述 FLV文件头获取所述 FLV文件类 型;
读取音频标签 audio tag, 获取低开销传输复用 latm头, 根据所 述 latm头构建音频数据传输流 adts头, 其中, 所述构建 adts头是为 音频解码提供参数;
读取音视频标签 tag的头信息及 tag数据区头, 并根据所述读取 的音视频 tag的头信息及 tag数据区头获取时间戳和时间偏移, 以便 于重构 TS流过程数据传输流 dts、 显示时间戳数据流 pts的计算。
其中, 所述重构所述文件格式流步骤包括:
在视频数据中的关键帧的头部添加视频格式 sps/pps信息, 所述 关键帧是指视频数据中第一帧;
在所述音视频帧添加 adts头,所述 adts头中帧长度包括所述 adts 头长度。
其中, 还包括:
接收内置的播放器发送的播放控制信息,并根据所述播放控制信 息对所述 FLV文件进行控制。
其中,所述将所述重构的文件格式流提供给内置的播放器,包括: 建立超文本传输协议服务 http server线程, 控制所述 http server 线程向所述内置的播放器发送定制统一资源定位符 URL;
控制所述 http server 线程接收所述内置的播放器根据所述定制 URL发送的 HTTP验证请求;
控制所述 http server线程在验证成功时, 向所述内置的播放器发 送连接成功信息;
通过所述 http server线程将所述重构的文件格式流提供给内置的 播放器。
相应地, 本发明实施例还提供了一种实现 FLV视频播放的装置, 包括: 解析模块、 连接模块、 播放器, 其中,
所述解析模块, 用于解析接受到的 FLV文件, 将该 FLV文件转 换为 android系统支持的文件格式, 重构所述文件格式流;
所述连接模块, 用于通过 http server线程根据所述解析模块重构 的文件格式流, 将所述重构的文件格式流提供给所述播放器;
所述播放器, 用于根据所述连接模块提供的重构的文件格式流, 控制播放所述重构的文件格式流。
其中, 所述解析模块包括:
接收单元, 用于接收 FLV文件, 所述 FLV文件包括本地 FLV文 件和在线 FLV文件;
解析单元, 用于根据所述接收单元接收到的 FLV文件, 解析该 FLV文件, 以便重构所述文件格式流;
转换单元, 用于根据所述解析单元的解析结果, 将所述 FLV文 件转换为所述 android支持的文件格式。
其中, 所述解析模块还包括:
控制模块, 用于接收所述播放器发送的播放控制信息, 并根据所 述播放控制信息对所述 FLV文件进行控制。
其中, 所述连接模块包括:
第二控制单元, 用于控制所述 http server线程向所述播放器发送 定制 URL; 第二接收单元, 用于接收所述播放器根据所述定制 URL发送的 HTTP验证请求;
发送单元, 用于根据所述接收单元接收到的验证请求, 在确定所 述验证请求成功时, 向所述播放器发送连接成功信息, 并将所述重构 的文件格式流提供给所述的播放器。
本发明实施例所要解决的技术问题在于, 提供一种实现 FLV视 频播放的方法及装置, 有效地解决与 android系统接口结合以及 FLV 播放的硬解问题, 实现了在 android系统播放应用中播放 FLV视频, 满足用户对 FLV视频播放的需求。 附图说明
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面 将对实施例或现有技术描述中所需要使用的附图作筒单地介绍,显而 易见地, 下面描述中的附图仅仅是本发明的一些实施例, 对于本领域 普通技术人员来讲, 在不付出创造性劳动性的前提下, 还可以根据这 些附图获得其他的附图。
图 1是本发明实施例提供的一种实现 FLV视频播放的方法第一 实施例的流程图;
图 2是本发明实施例提供的一种实现 FLV视频播放的方法第二 实施例的流程图;
图 3是本发明实施例提供的一种实现 FLV视播放频的方法第三 实施例的流程图;
图 4是本发明实施例提供的一种实现 FLV视频播放的装置的第 一实施例的结构示意图;
图 5是本发明实施例提供的一种实现 FLV视频播放的装置的第 二实施例的结构示意图;
图 6是本发明实施例提供的一种实现 FLV视频播放的装置的第 三实施例的结构示意图。 具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方 案进行清楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部 分实施例, 而不是全部的实施例。 基于本发明中的实施例, 本领域普 通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。
本发明实施例提供了一种实现 FLV视频播放的方法及装置, 有 效地解决与 android系统接口的结合以及 FLV播放的硬解问题, 实现 了在 android系统中播放 FLV视频。
需要说明到是, 本发明实施例主要是在 android2.3及以上版本中 实现对 FLV视频播放的支持, 方便开发人员在任意 android系统中播 放 FLV视频文件。
本发明实施例中实现 android系统播放 FLV视频的技术方案需要 具备的二个环境条件: 第一, android系统版本必须能够支持 TS流的 播放。 第二, FLV文件中音视频所采用的编码格式必须是 android系 统本身支持的解码格式, 否则 FLV文件会播放失败。
参见图 1 ,为本发明实施例提供的实现 FLV视频播放的方法第一 实施例的流程图。 所述方法包括:
S101 , 解析流媒体 FLV文件, 将该 FLV文件转换为 android系 统支持的文件格式, 重构所述文件格式流, 所述 android系统支持的 文件格式包括传输 TS流格式;
具体的, 本发明实施例为了实现在 android系统中播放 FLV视频 的功能, 需要改变 FLV视频的文件格式, 而且必须是 android系统能 够支持的文件格式,目前 android系统支持的视频格式包括 3GP、MP4、 TS、 MKVD等,本发明实施例中采用 TS流格式, 即为实现在 android 系统中播放 FLV视频的功能,解析所述 FLV视频格式,并将所述 FLV 视频格式转变为 TS流格式,用重构后的 TS流格式作为 android系统 的内置的播放器的源数据, 也就是将所述重构的 TS流提供给内置的 播放器, 并控制所述内置的播放器播放所述重构的 TS流格式, 从而 完成在 TS流格式的播放,事实上就完成对真正数据源 FLV视频格式 在 android系统中的播放。
本发明实施例中要完成在 android系统中播放 FLV视频, 包括对 所述 FLV视频的音视频数据的控制、 播放控制等, 首先需要一个播 放主程序,而且播放主线程在真正进入视频播放过程之前还需要建立 一个后台线程, 所述后台线程通过提供解析转换线程用于解析所述 FLV文件, 将该 FLV文件转换为 android系统支持的 TS流格式, 重 构所述 TS流的文件格式流。
S102, 将所述重构的文件格式流提供给内置的播放器;
具体的, 本发明实施例中为实现在 android系统中播放 FLV视频 的功能,提出在 android系统中将所述 FLV视频格式转换成 TS流格 式播放的处理方案, 通过后台线程解析所述 FLV视频格式, 将所述 FLV视频格式转换为 android系统支持的 TS流格式, 并将所述重构 的 TS流发送给超文本传输协议服务 http server线程,所述 http server 线程将接收到的 TS 格式流作为源数据提供给内置的播放器, 并完 成在所述内置的播放器中播放 TS格式流,所述 http server线程是播 放主线程建立的, 与播放主线程是并行的, 而且和 S101步骤中所述 后台线程建立的 FLV文件解析转换线程也是是并行的, 本发明实施 例通过在 android系统中建立的 http server线程向内置的播放器提供 TS流服务, 从而完成 android系统接口对接。
所述 http server线程在完成与 android系统中内置的播放器接口 的对接后, 所述 android 系统中内置的播放器就可以不断得到所述 http server线程提供的 TS流数据, 所述连接是指传输控制协议 tcp 连接, 即所述 http server线程建立后会接收播放主线程的 tcp连接, 并处理 http验证请求, 只有在向播放主线程返回了正确的回应, 才 能够将所述 FLV文件解析转换线程过程中得到的 TS格式流作为源 数据, 提供给所述 android系统中内置的播放器, 这样就在 FLV文 件解析转换线程过程中的数据处理和内置的播放器播放过程中的数 据播放之间建立起一个连接, 使得 FLV文件解析转换线程中的数据 处理和内置播放器播放过程中的数据播放是并行的, 二者是互不影 响的。
S103 , 控制所述内置的播放器播放所述重构的文件格式流。
具体的, 本发明实施例为了实现在 android系统中播放 FLV视频 格式,首先将 FLV视频格式转变为 android系统能够支持的文件格式, 所述 android系统能够支持的文件格式包括 TS流格式, 并通过所述 http server线程将所述 TS流格式作为数据源提供给所述 android系统 内置的播放器, 实现在 android系统播放应用中播放 TS流, 完成了 FLV视频在 android系统中的播放, 本发明实施例中的播放主线程在 建立了 http server线程后会主动联系所述 http server线程的, 并判断 所述 http server线程是否对其发出 http验证请求响应正确, 如果所述 http server线程发出 "连接正常" 的响应, 表示连接成功建立, 则所 述内置的播放器不断地接收到所述 http server线程发送的 TS流, 并 实现 TS流的播放, 完成了对真正数据源 FLV视频文件在 android系 统中的播放。
需要说明的是所述控制所述内置的播放器播放所述重构的文件 格式流的过程包括: 所述内置的播放器判断当前播放的是否是 FLV 视频格式, 若判断为是, 根据所述 android系统标准接口设置的 URL 接收所述内置的播放器根据所述定制 URL发送的 HTTP验证请求, 如果连接请求成功后发送 http验证请求,若根据 HTTP标准协议发出 "连接成功", 表示所述 http server线程可以为所述播放主线程提供 TS流, 若判断为否, 退出播放过程。
本发明实施例中的 http server线程在完成与 android系统中内置 的播放器的对接后,利用所述 android系统内置的播放器支持播放 TS 格式流的特点, 直接从所述 http server线程中接收 TS流数据, 这样 音视频数据的解码过程是由所述 android系统处理, 比如所述 android 系统本身支持高级音频编码 AAC, H264 AVC等音视频编码格式的硬 件解码, 则最终会通过 android系统的应用接口中完成调用, 就解决 所述 FLV音视频数据硬解的问题,另外所述 http server线程在完成与 android系统中内置的播放器的对接后, 所述 FLV视频格式的播放完 全由所述 android系统完成,开发过程与普通媒体文件如 MP4的播放 相同, 同时所述 FLV文件解析转换线程以及提供 TS流服务的 http server线程与 android系统内置播放器数据播放过程是并行的, 不会 对 android系统内置的播放器播放 TS格式流产生影响, 其播放 FLV 视频格式的过程与播放普通媒体文件的过程相同, 大大降低开发难 度。
参见图 2,为本发明实施例提供的实现 FLV视频播放的方法第二 实施例的流程图。 所述方法包括:
5201 , 接收 FLV文件, 所述 FLV文件包括本地 FLV文件和在线 FLV文件;
具体的, 本发明实施例中后台线程首先要获取 FLV文件的数据, 只有通过后台线程获取到所述 FLV文件才能够解析转换所述 FLV文 件, 所述获取的 FLV文件包括本地 FLV文件和在线 FLV文件, 其中 所述本地 FLV文件可以存储在安全数据存储卡 SD卡中, 所述在线 FLV文件是指来自网络。
另外, 本发明实施例中所述后台线程在获取 FLV文件的同时接收 android 系统内置的播放器发送的控制播放的信息, 并根据该控制播 放的信息对所述 FLV文件进行控制。
5202,解析所述 FLV文件,对所述 FLV音频数据和参数的解析; 具体的, 本发明实施例中所述 FLV 文件通常由文件头 (FLV header )和很多文本体(tag )构成的, 根据 S201获取到的 FLV文件, 对所述获取到的 FLV文件进行解析, 所述解析包括对获取到的 FLV 文件的进行音频解析和视频解析, 所述对 FLV文件音频解析是采用 高级音频编码 AAC编码、所述对 FLV文件的视频解析是采用标准视 频编码 H264 AVC编码, 其中所述 AAC编码最常见的格式包括音频 数据传输层 ADTS与低开稍音频传输复用 LATM。
本发明实施例中解析所述获取到的 FLV文件的过程主要包括: 读取所述 FLV文件头和文件体获取 FLV文件的文件类型和 latm帧头 和 sps/pps信息、 通过所述获取到的 latm帧头构建 adts帧头, 从而为 对所述 FLV文件的音视频解码提供参数、读取音视频 tag的头信息及 tag数据区头, 从中获取时间戳和时间偏移信息, 为重构 TS流过程 dts、 pts的计算提供依据。
需要说明的是, 为了保证后台线程在对 FLV文件的解析转换过 程的有效性, 通常将 S201步骤中的获取 FLV文件的过程与 S202步 骤中解析 FLV文件的过程结合来实现对所述 FLV文件的解析转换, 所述对 FLV文件的解析转换是根据 S202步骤中的 FLV文件解析线程 解析的 FLV文件结构元素的大小来决定 S201步骤中获取 FLV文件的 数据长度, 这样就保证了数据读取指针始终处于 FLV文件结构元素 的边缘, 这样既减少获取 FLV文件的数据的不确定性, 又能够发现 FLV 文件中存在的错误并能够及时进行相应的处理, 避免影响整个 FLV文件解析转换过程及后续的 FLV文件播放。
5203,重构所述文件格式流,得到 android系统支持的文件格式; 具体的,根据 S202步骤中对接收到 FLV文件进行音视频数据及 参数的解析结果, 进一步重构 TS流格式, 即将所述 FLV文件转换为 所述 android系统支持的 TS流格式, 所述 TS流重构的过程中包括: 在所述 TS流的数据中的关键帧头部添加 sps/pps信息、 对 TS流的每 个音频帧中添加 adts头, 所述 adts头中帧长度包括 adts头的长度。
5204, 将所述重构的文件格式流提供给内置的播放器;
5205, 控制所述内置的播放器播放所述重构的文件格式流。
本发明实施例后台线程完成对 FLV视频文件的解析转换, 所述 对 FLV视频文件的解析转换包括: 提供后台线程接收 FLV文件、 根 据所述接收到的 FLV文件, 解析该 FLV文件, 以便重构所述文件格 式流,并将所述 FLV文件转换为 android支持的 TS流格式,通过 http server 线程将该 TS 流作为数据源提供给内置的播放器, 实现在 android系统中播放 TS流, 实现了对真正数据源 FLV文件在 android 系统中的播放。
参见图 3,图 3是本发明实施例提供的实现 FLV视频播放的方法 第三实施例的流程图。 所述方法包括:
5301 , 解析流媒体 FLV文件, 将该 FLV文件转换为 android系 统支持的文件格式, 重构所述文件格式流, 所述 android系统支持的 文件格式包括传输 TS流格式;
5302, 建立超文本传输协议服务 http server线程, 控制所述 http server线程向所述内置的播放器发送定制统一资源定位符 URL;
具体的, 本发明实施例中的播放主线程在建立 http server线程建 立之后会与所述 http server线程建立 tcp联系, 所述 http server线程 成功建立后会向所述内置的播放器发送定制统一资源定位符 URL, 所述定制的 URL 可以为如下格式: http ://localhost: [port] 或 http://127.0.0.1:[port] , 所述 http server的 URL可以通过 android系统 标准接口完成设置。
5303 , 控制所述 http server线程接收所述内置的播放器根据所述 定制 URL发送的 HTTP验证请求;
具体的, 本发明实施例中 http server线程是由播放主线程建立 的,所述播放主线程作为 http server的客户端,通过连接 http server 完 成与 android 系统内置的播放器的接口对接, 所述 http server线程启 动后, 等待所述播放主线程的 tcp连接请求, 并根据所述 android系 统标准接口设置的 URL接收所述内置的播放器根据所述定制 URL发 送的 HTTP验证请求, 所述 http server线程根据 HTTP标准协议发出 "连接成功", 表示所述 http server线程可以为所述播放主线程提供 TS流, 所述 http server线程是为了在 FLV文件解析转换线程的数据 处理过程和 FLV播放主线程的视频播放过程之间建立数据对接, 使 所述 http server线程提供 TS流服务完成与所述 FLV播放主线程的接 口对接。
本发明实施例中所述 http server线程是实现与所述 android系统 接口对接的关键, 播放主线程通过调用媒体播放器 MediaPlayer接口 中的设置数据源 SetDataSource(string path)设置 URL, 并通过定制的 URL连接所述 http server线程, 从而建立 FLV播放主线程和 FLV解 析转换线程之间的联系, 实现了 FLV播放主线程的数据播放和 FLV 解析转换线程的数据分析之间的数据对接。
5304, 控制所述 http server线程在验证成功时, 向所述内置的播 放器发送连接成功信息;
具体的, 本发明实施例中 http server 线程是由播放主线程建立 的, 所述 http server线程启动后, 等待所述播放主线程的 tcp连接请 求,并根据所述 android系统标准接口设置的 URL接收所述内置的播 放器根据所述定制 URL发送的 HTTP验证请求, 所述 http server线 程在验证成功时, 向所述内置的播放器发送连接成功信息, 即所述 http server线程根据 HTTP标准协议发出 "连接成功", 表示所述 http server线程可以将所述 TS流作为源数据流提供给所述 android系统内 置的播放器。
需要说明的是, 本发明实施例中播放主线程通过调用 MediaPlayer接口中的 SetDataSource(string path)设置 URL, 实现了 FLV播放主线程的数据播放和 FLV解析转换线程的数据分析之间的 数据对接, 但是真正的对接过程是在 setDataSource(string path)和 prepare()两个方法内部完成的, 也就是涉及到 android标准接口的内 部实现的, 因此在本发明实施例中只需要写明是通过调用 MediaPlayer接口中 setDataSource(string path)的方法即可, 根据 S304 判断播放主线程的 MediaPlayer播放准备成功, 所述 http server接收 所述 FLV解析转换线程重构的 TS流, 并将所述 TS流作为源数据提 供给所述 FLV播放主线程, FLV播放主线程的 MediaPlayer调用接口 start()开始播放。
5305 , 通过所述 http server线程将所述重构的文件格式流提供给 内置的播放器。
5306, 控制所述内置的播放器播放所述重构的文件格式流。 本发明实施例在 android系统中建立 http server线程目的就是通 过 http server线程在 FLV文件解析转换线程和播放主线程之间建立了 一个连接, 使得 FLV文件解析转换线程中的数据处理和播放主线程 中的数据播放是并行的, 二者是互不影响的, 因此所述播放主线程只 要完成连接 http server线程就可以得到不断得到 http server 线程提供 的 ts流,有效地与 android系统的控制播放接口的对接,使得 FLV播 放控制操作完全由播放主线程完成的, 而且所述 FLV文件解析转换 线程、 http server线程的建立不会对 FLV播放主线程的播放产生影响, 所述 FLV播放过程与 android系统本身支持的 3GP、 MP4其他普通媒 体文件的播放过程完全相同, 这样就降低了开发的难度。
参见图 4,图 4是本发明实施例提供的一种实现 FLV视频播放的 装置的第一实施例的结构示意图。 如图 4所示, 包括: 解析模块 10、 连接模块 20、 播放器 30, 其中,
所述解析模块 10, 用于解析接收到的 FLV文件, 将该 FLV文件 转换为 android系统支持的文件格式, 重构所述文件格式流;
具体的, 本发明实施例中解析模块 10用于解析接收到的 FLV文 件, 并将所述 FLV文件转换为 android系统支持的文件格式, 重构所 述文件格式流,就是为了实现在 android系统中播放 FLV视频的功能, 改变 FLV视频的文件格式, 而且必须是 android系统能够支持的文件 格式如 TS流格式, 通过所述解析模块 10解析得到的重构后的 TS流 格式作为 android系统的内置的播放器的源数据, 完成 TS流格式的 播放, 事实上完成 FLV视频格式在 android系统中的播放。
所述连接模块 20, 用于通过 http server线程接收所述解析模块 10 重构的文件格式流, 将所述重构的文件格式流提供给所述播放器 30;
具体的, 本发明实施例中的连接模块 20是通过 http server线程 接收所述解析模块 10解析转换后得到的 TS流, 并将所述 TS流作为 源数据提供给所述播放器模块 30, 其中所述连接模块 20通过 http server线程接收播放主线程的 tcp连接, 并处理 http验证请求, 只有 在所述验证请求得到正确的回应,所述连接模块 20才能够将所述 TS 流作为源数据提供给播放主线程, 所述播放主线程只要完成了连接 http server线程就可以得到 TS流,这样就在解析模块 10和播放器 30 之间建立了一个连接, 也就是所述解析模块 10中对 FLV文件解析转 换线程中的数据处理和所述播放器的数据播放是并行的,二者是互不 影响的, 在本发明实施例中所述连接模块 20就是通过 http server线 程完成与 android系统中播放器 30完成对接, 从而使得连接模块 20 通过 http server线程将所述解析模块 10中得到的 TS流作为源数据提 供给所述播放器 30。
所述播放器 30 , 用于根据所述连接模块 20提供的重构的文件格 式流, 控制播放所述重构的文件格式流。
具体的, 本发明实施例为了实现在 android系统中播放 FLV视频 格式, 首先通过解析模块 10将 FLV视频格式转变为 android系统能 够支持的 TS流格式, 连接模块 20通过 http server线程将所述 TS流 格式作为数据源提供给所述 android系统中内置的播放器 30, 实现在 android系统播放应用中播放 TS流, 完成了 FLV视频在 android系统 中的播放。
需要说明的是所述播放器 30播放所述重构的文件格式流的过程 包括: 所述播放器 30判断当前播放的是否是 FLV视频格式, 若判断 为是, 根据所述 android系统标准接口设置的 URL接收所述播放器 30根据所述定制 URL发送的 HTTP验证请求如果连接请求成功后发 送 http验证请求, 若 http根据 HTTP标准协议发出 "连接成功", 表 示所述 http server线程可以为所述播放主线程提供 TS流, 若判断为 否,退出播放过程。本发明实施例中的播放主线程在建立了 http server 线程后会主动联系所述 http server线程的, 并判断所述 http server线 程是否对其发出 http验证请求响应正确, 如果所述 http server线程发 出 "连接正常" 的响应, 表示连接成功建立, 则所述内置的播放器不 断地接收到所述 http server线程发送的 TS流, 并实现 TS流的播放, 完成了对真正数据源 FLV视频文件在 android系统中的播放。
本发明实施例中的连接模块 20 通过 http server 线程完成与 android系统中播放器 30的对接后, 所述播放器 30直接从所述连接 模块 20接收 TS 流数据, 这样音视频数据的解码过程完全由所述 android系统完成, 解决了所述 FLV音视频数据硬解的问题, 并且其 开发过程与普通媒体文件如 MP4的播放相同, 同时所述解析模块 10 的 FLV 文件解析转换线程以及提供 TS 流服务的连接模块 20 与 android系统中播放器 30的数据播放过程是并行的, 不会对 android 系统中的播放器 30播放 TS格式流产生影响, 其播放 FLV视频格式 的过程与播放普通媒体文件的过程相同, 降低开发难度。
参见图 5,图 5是本发明实施例提供的一种实现 FLV视频播放装 置的第二实施例的结构示意图。 如图 5所示, 所述实现 FLV视频播 放装置除包括上述第一实施例中实现播放 FLV视频装置中的连接模 块 20、 播放器 30外, 所述解析模块 10进一步包括: 接收单元 101、 解析单元 102、 转换单元 103, 控制单元 104, 其中,
所述接收单元 101 , 用于接收 FLV文件, 所述 FLV文件包括本 地 FLV文件和在线 FLV文件;
具体的, 接收单元 101获取 FLV文件, 只有通过接收单元 101 获取到 FLV文件后才能够通过后台线程解析、 转换 FLV文件, 所述 接收单元 101获取的 FLV文件包括本地 FLV文件和在线 FLV文件, 其中所述本地 FLV文件可以存储在安全数据存储 SD卡上。
所述解析单元 102, 用于根据所述接收单元 101接收到的接收到 的 FLV文件, 解析该 FLV文件, 以便重构所述文件格式流;
具体的, 在本发明实施例中解析单元 102根据所述接收单元 101 获取到的 FLV文件, 对所述接收单元 101接收到的 FLV文件进行解 析, 所述解析包括对接收单元 101获取到的 FLV文件的音频解析和 视频解析, 解析单元 102对接收单元 101接收到的 FLV文件的解析 包括:读取 FLV文件头获取 文件的文件类型、读取 FLV文件的音频 tag, 获取 latm帧头和 sps/pps信息、 再由所述获取的 latm帧头构建 adts帧头, 从而为音频解码和视频解码提供参数、 读取音视频 tag的 头信息及 tag数据区头,从中获取时间戳和时间偏移信息,为重构 TS 流过程 dts、 pts计算提供依据。
所述转换单元 103, 根据所述解析单元 102所解析重构的文件格 式流, 将所述 FLV文件转换为所述 android支持的文件格式。
具体的, 根据所述解析单元 102 的解析结果, 将所述接收单元 101接收到的 FLV文件转换为所述 android支持的文件格式, 也就是 所述转换单元 103根据所述解析单元 102对所述接收单元 101接收的 到的 FLV文件转换进行音视频数据及参数的解析结果, 进一步重构 TS流格式, 即所述转换单元 103将所述 FLV文件转换为 android系 统支持的 TS流格式。
所述控制单元 104, 用于接收播放器 30发送的播放控制信息, 并 根据所述播放控制信息对所述 FLV文件进行控制。
需要说明的是, 为了保证后台线程在对 FLV文件的解析转换过 程的有效性, 通常将接收单元 101获取 FLV文件的过程和解析单元 102 的解析所述获取到的 FLV文件的过程相结合, 由解析单元 102 解析的 FLV文件结构元素的大小决定所述接收单元 101获取的 FLV 文件的数据长度, 这样就保证了数据读取指针始终处于 FLV文件结 构元素的边缘, 这样既减少接收单元对获取的 FLV文件数据的不确 定性, 又能够发现所获取的 FLV文件存在问题, 同时避免影响整个 FLV文件解析转换过程及后续的 FLV文件播放。
本发明实施例分析了后台线程是如何完成对 FLV视频文件的解 析转换的过程, 所述 FLV文件解析转换过程包括接收单元 101获取 FLV文件、解析单元 102根据所述接收单元 101获取到的 FLV文件, 解析该获取到的 FLV文件、 转换单元 103根据所述解析单元 102的 解析结果将所述 FLV文件转换为所述 android支持的 TS流格式, 并 将所述 TS流为数据源提供给 FLV播放主线程, 即在 android系统播 放应用中播放该 TS流,这样也就是完成了对真正数据源 FLV文件在 android系统中的播放。
参见图 6,图 6是本发明实施例提供的一种实现 FLV视频播放装 置的第三实施例的结构示意图。 如图 6所示, 所述实现 FLV视频播 放装置除包括上述第一上述例中实现 FLV视频播放装置中的解析模 块 10、 播放器 30外, 所述连接模块 20进一步包括: 第二控制单元 201、 第二接收单元 202、 发送单元 203 , 其中,
所述第二控制单元 201 , 用于控制所述 http server线程向所述播 放器 30发送定制 URL;
具体的, 本发明实施例中的连接模块 20通过 http server线程完 成与 android系统中播放器 30的对接后, 所述播放器 30在所述连接 模块 20建立 http server线程之后会与所述连接模块 20建立 tcp联系, 并通过控制单元 201向所述播放器模块 20发送定制统一资源定位符 URL, 所述定制的 URL 可以为如下格式: http://localhost:[port] 或 http://127.0.0.1:[port] , 所述向所述播放器模块 20发送的定制统一资 源定位符 URL可以通过 android系统标准接口完成设置。
所述第二接收单元 202, 用于接收所述播放器模块 30根据所述 定制 URL发送的 HTTP验证请求;
具体的, 本发明实施例中的 http server线程是由所述播放器 30 建立的,所述播放器 30作为连接 r模块 20的客户端,通过 http server 线程完成与 android 系统中的播放器 30接口对接, 所述连接模块 20 在 http server线程启动后, 等待所述播放器 30的 tcp连接请求, 并通 过所述第二接收单元 202接收所述播放器 30根据所述定制 URL发送 的 HTTP验证请求, 所述连接模块 20根据 HTTP标准协议发出 "连 接成功", 表示所述连接模块 20可以为所述播放器 30提供 TS流, 使所述连接模块 20提供 TS流服务完成与所述播放器 30的接口对接。
所述发送单元 203 , 用于根据所述接收单元 202接收到的验证请 求, 在确定所述验证请求成功时, 向所述播放器 30发送连接成功信 息, 并将所述重构的文件格式流提供给所述播放器模块 30。
具体的, 本发明实施例中所述 http server线程是连接模块 20实 现与所述 android系统中播放器 30接口对接的关键, 所述连接模块 20在 http server线程启动后, 等待所述播放器 30的 tcp连接请求, 并根据所述接收单元 202接收到的所述播放器 30根据所述定制 URL 发送的 HTTP验证请求, 在确定所述验证请求成功时, 通过所述发送 单元 203向所述播放器 30发送连接成功信息,即所述连接模块 20根 据 HTTP标准协议发出 "连接成功", 表示所述连接模块 20可以将所 述 TS流作为源数据流提供给所述 android系统中的播放器 30, 并将 所述播放器模块 30中实现播放 TS格式流。
本发明实施例的连接模块 20通过 http server线程接收播放器 30 的 tcp连接, 并处理 http验证请求, 只有在所述验证请求得到正确的 回应, 所述连接模块 20才能够将所述 TS流作为源数据提供给播放 器 30, 通过连接模块 20在解析模块 10的解析转换过程和播放器模 块 30的播放过程之间建立了一个连接,也就是说解析模块 10的文件 解析转换线程中的数据处理和播放器 30的数据播放是并行的, 二者 是互不影响的,因此所述播放器 30只要完成连接连接模块 20就可以 得到不断得到连接模块 20提供的 ts流, 这样就有效地与 android系 统的播放器 30接口的对接, 使得 FLV播放制操作完全由播放器 30 完成的, 而且所述 FLV文件解析转换线程、 http server线程的建立不 会对所述播放器 30播放 FLV视频格式的播放产生影响,所述 FLV播 放过程与 android系统本身支持的 3GP、 MP4其他普通媒体文件的播 放过程完全相同, 这样就降低了开发的难度。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解 到本发明可借助软件加必需的硬件平台的方式来实现,当然也可以全 部通过硬件来实施。基于这样的理解, 本发明的技术方案对背景技术 做出贡献的全部或者部分可以以软件产品的形式体现出来,该计算机 软件产品可以存储在存储介质中, 如 ROM/RAM、 磁碟、 光盘等, 包 括若干指令用以使得一台计算机设备(可以是个人计算机, 服务器, 或者网络设备等)执行本发明各个实施例或者实施例的某些部分所述 的方法。
以上所揭露的仅为本发明一种较佳实施例而已,当然不能以此来限定 本发明之权利范围, 因此依本发明权利要求所作的等同变化, 仍属本 发明所涵盖的范围。

Claims

权 利 要 求
1、 一种实现 FLV视频播放的方法, 其特征在于, 包括:
解析流媒体 FLV文件,将该 FLV文件转换为 android系统支持的文件格式, 重构所述文件格式流, 所述 android系统支持的文件格式包括传输 TS流格式; 将所述重构的文件格式流提供给内置的播放器;
控制所述内置的播放器播放所述重构的文件格式流。
2、 如权利要求 1所述的方法, 其特征在于, 所述解析 FLV文件, 将该 FLV 文件转换为 android系统支持的文件格式, 重构所述文件格式流的步骤包括: 接收 FLV文件, 所述 FLV文件包括本地 FLV文件和在线 FLV文件; 解析所述 FLV文件, 对所述 FLV音频数据和参数的解析;
重构所述文件格式流, 得到 android系统支持的文件格式。
3、 如权利要求 2所述的方法, 其特征在于, 所述解析所述 FLV文件的步骤 具体包括:
读取 FLV文件头, 并根据所述 FLV文件头获取所述 FLV文件类型; 读取音频标签 audio tag, 获取低开销传输复用 latm头, 根据所述 latm头构 建音频数据传输流 adts头, 其中, 所述构建 adts头是为音频解码提供参数; 读取音视频标签 tag的头信息及 tag数据区头,并根据所述读取的音视频 tag 的头信息及 tag数据区头获取时间戳和时间偏移, 以便于重构 TS流过程数据传 输流 dts、 显示时间戳数据流 pts的计算。
4、 如权利要求 2所述的方法, 其特征在于, 所述重构所述文件格式流步骤 包括:
在视频数据中的关键帧的头部添加视频格式 sps/pps信息, 所述关键帧是指 视频数据中第一帧;
在所述音视频帧添加 adts头, 所述 adts头中帧长度包括所述 adts头长度。 如权利要求 2所述的方法, 其特征在于, 还包括: 接收内置的播放器发送的播放控制信息, 并根据所述播放控制信息对所述
FLV文件进行控制。
6、 如权利要求 1所述的方法, 其特征在于, 所述将所述重构的文件格式流 提供给内置的播放器, 包括:
建立超文本传输协议服务 http server线程, 控制所述 http server线程向所述 内置的播放器发送定制统一资源定位符 URL;
控制所述 http server线程接收所述内置的播放器根据所述定制 URL发送的 HTTP验证请求;
控制所述 http server线程在验证成功时,向所述内置的播放器发送连接成功 信息;
通过所述 http server线程将所述重构的文件格式流提供给内置的播放器。
7、 一种实现 FLV视频播放的装置, 其特征在于, 包括: 解析模块、 连接模 块、 播放器, 其中,
所述解析模块,用于解析接受到的 FLV文件,将该 FLV文件转换为 android 系统支持的文件格式, 重构所述文件格式流;
所述连接模块,用于通过 http server线程接收所述解析模块重构的文件格式 流, 将所述重构的文件格式流提供给所述播放器;
所述播放器, 用于根据所述连接模块提供的重构的文件格式流, 控制播放 所述重构的文件格式流。
8、 如权利要求 7所述的装置, 其特征在于, 所述解析模块包括:
接收单元, 用于接收 FLV文件, 所述 FLV文件包括本地 FLV文件和在线 FLV文件;
解析单元, 用于根据所述接收单元接收到的 FLV文件, 解析该 FLV文件, 以便重构所述文件格式流;
转换单元, 用于根据所述解析单元的解析结果, 将所述 FLV文件转换为所 述 android支持的文件格式。
9、 如权利要求 8所述的装置, 其特征在于, 所述解析模块还包括: 控制模块, 用于接收所述播放器发送的播放控制信息, 并根据所述播放控 制信息对所述 FLV文件进行控制。
10、 如权利要求 7所述的装置, 其特征在于, 所述连接模块包括: 第二控制单元, 用于控制所述 http server线程向所述播放器发送定制 URL; 第二接收单元, 用于接收所述播放器根据所述定制 URL发送的 HTTP验证 请求;
发送单元, 用于根据所述接收单元接收到的验证请求, 在确定所述验证请 求成功时, 向所述播放器发送连接成功信息, 并将所述重构的文件格式流提供 给所述的播放器。
PCT/CN2012/086022 2012-03-23 2012-12-06 一种实现flv视频播放的方法及装置 WO2013139146A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210079071.6A CN102630059B (zh) 2012-03-23 2012-03-23 一种实现flv视频播放的方法及装置
CN201210079071.6 2012-03-23

Publications (1)

Publication Number Publication Date
WO2013139146A1 true WO2013139146A1 (zh) 2013-09-26

Family

ID=46588197

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/086022 WO2013139146A1 (zh) 2012-03-23 2012-12-06 一种实现flv视频播放的方法及装置

Country Status (2)

Country Link
CN (1) CN102630059B (zh)
WO (1) WO2013139146A1 (zh)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102929559B (zh) * 2012-09-20 2015-07-22 深圳市亚特尔科技有限公司 一种提供文件的方法及文件提供系统
CN103702240A (zh) * 2013-12-06 2014-04-02 乐视网信息技术(北京)股份有限公司 一种视频播放的方法和设备
CN104717446B (zh) * 2013-12-12 2017-10-24 中国航空工业集团公司第六三一研究所 多视频格式向itu656协议pal制式的自动转换方法
CN104717444B (zh) * 2013-12-12 2017-11-24 中国航空工业集团公司第六三一研究所 多视频格式向VESA协议1920X1440分辨率75Hz帧率视频的自动转换方法
CN104754349A (zh) * 2013-12-25 2015-07-01 炫一下(北京)科技有限公司 硬解码音视频的方法及装置
CN106686443A (zh) * 2015-11-10 2017-05-17 中兴通讯股份有限公司 一种媒体播放方法、终端及系统
CN108184137A (zh) * 2017-12-29 2018-06-19 北京奇虎科技有限公司 一种流媒体flv文件的定位播放方法和装置
CN110858923B (zh) * 2018-08-24 2022-09-06 北京字节跳动网络技术有限公司 分段媒体文件生成方法、装置及存储介质
CN110858919A (zh) * 2018-08-24 2020-03-03 北京字节跳动网络技术有限公司 媒体文件播放过程中的数据处理方法、装置及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101415069A (zh) * 2008-10-22 2009-04-22 清华大学 一种服务器及其在线播放视频的发送方法
CN102075528A (zh) * 2010-12-27 2011-05-25 上海聚欣网络科技有限公司 一种播放多种封装格式的网络多媒体文件的方法与设备
CN102118428A (zh) * 2010-12-29 2011-07-06 天脉聚源(北京)传媒科技有限公司 一种播放流媒体的方法和系统
WO2011090715A2 (en) * 2009-12-28 2011-07-28 Akamai Technologies, Inc. Edge server for format-agnostic streaming architecture

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2010031009A1 (en) * 2008-09-12 2010-03-18 Jamabi, Inc. Method and system for distributing media content and processing payments and/or voluntary data collection
CN102123279B (zh) * 2010-12-28 2013-01-23 乐视网信息技术(北京)股份有限公司 一种分布式实时转码方法与系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101415069A (zh) * 2008-10-22 2009-04-22 清华大学 一种服务器及其在线播放视频的发送方法
WO2011090715A2 (en) * 2009-12-28 2011-07-28 Akamai Technologies, Inc. Edge server for format-agnostic streaming architecture
CN102075528A (zh) * 2010-12-27 2011-05-25 上海聚欣网络科技有限公司 一种播放多种封装格式的网络多媒体文件的方法与设备
CN102118428A (zh) * 2010-12-29 2011-07-06 天脉聚源(北京)传媒科技有限公司 一种播放流媒体的方法和系统

Also Published As

Publication number Publication date
CN102630059A (zh) 2012-08-08
CN102630059B (zh) 2015-09-30

Similar Documents

Publication Publication Date Title
WO2013139146A1 (zh) 一种实现flv视频播放的方法及装置
CN104796796B (zh) 提高Android平台的HLS流播放器容错的方法
WO2015051755A1 (zh) 多媒体文件播放方法、系统、云转码服务设备及存储介质
TW201517572A (zh) 一種數據處理方法、裝置及系統
EP2822274A1 (en) Method for converting online media data or playing video and apparatus thereof
WO2013185514A1 (zh) 一种播放流媒体的系统和方法
CN105812895A (zh) 一种视频点播数据处理方法及其系统
JP2007295038A (ja) 動画再生装置及び方法
CN102833585B (zh) 一种泛终端视频传输系统和方法
WO2017219575A1 (zh) 在线播放电视的方法及装置
CN113938470B (zh) 一种浏览器播放rtsp数据源的方法、装置以及流媒体服务器
WO2018103696A1 (zh) 媒体文件的播放方法、服务端、客户端及系统
WO2013053259A1 (zh) 流媒体数据的处理方法、播放方法以及装置
CN202759552U (zh) 一种基于ip网络的多终端视频同步播放的系统
US20080307105A1 (en) Streaming media archiver for live events
JPWO2016174960A1 (ja) 受信装置、送信装置、およびデータ処理方法
WO2014048198A1 (zh) 倍速播放方法、装置及系统
CN101848367A (zh) 基于文件的动态影像网络直播方法
JP6116240B2 (ja) 送信装置、送信方法、及びプログラム
CN115865884A (zh) 一种网络摄像头数据访问装置、方法、网络摄像头和介质
JPWO2017038353A1 (ja) 受信装置、送信装置、およびデータ処理方法
CN102439935A (zh) 媒体适配的方法和装置
TW201605230A (zh) 即時影音傳輸方法及其系統
CN106303754A (zh) 一种音频数据播放方法及装置
CN108600826B (zh) 一种播放ts流的方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 12871764

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 20/02/2015)

122 Ep: pct application non-entry in european phase

Ref document number: 12871764

Country of ref document: EP

Kind code of ref document: A1