CN116962815A - Method for playing MKV video in original mode by browser - Google Patents
Method for playing MKV video in original mode by browser Download PDFInfo
- Publication number
- CN116962815A CN116962815A CN202311211800.3A CN202311211800A CN116962815A CN 116962815 A CN116962815 A CN 116962815A CN 202311211800 A CN202311211800 A CN 202311211800A CN 116962815 A CN116962815 A CN 116962815A
- Authority
- CN
- China
- Prior art keywords
- video
- mkv
- track data
- data
- audio
- Prior art date
- Legal status (The legal status 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 status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 16
- 238000004806 packaging method and process Methods 0.000 claims abstract description 9
- AWSBQWZZLBPUQH-UHFFFAOYSA-N mdat Chemical compound C1=C2CC(N)CCC2=CC2=C1OCO2 AWSBQWZZLBPUQH-UHFFFAOYSA-N 0.000 claims description 20
- 239000012634 fragment Substances 0.000 claims description 12
- 238000005538 encapsulation Methods 0.000 claims description 7
- 238000012986 modification Methods 0.000 claims description 6
- 230000004048 modification Effects 0.000 claims description 6
- 238000012544 monitoring process Methods 0.000 claims description 3
- 238000010586 diagram Methods 0.000 description 3
- 206010000060 Abdominal distension Diseases 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 208000024330 bloating Diseases 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 238000005070 sampling Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/43—Processing 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/44—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs
- H04N21/44008—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs involving operations for analysing video streams, e.g. detecting features or characteristics in the video stream
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/43—Processing 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/44—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs
- H04N21/4402—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs involving reformatting operations of video signals for household redistribution, storage or real-time display
- H04N21/440218—Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs involving reformatting operations of video signals for household redistribution, storage or real-time display by transcoding between formats or standards, e.g. from MPEG-2 to MPEG-4
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N21/00—Selective content distribution, e.g. interactive television or video on demand [VOD]
- H04N21/40—Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
- H04N21/47—End-user applications
- H04N21/478—Supplemental services, e.g. displaying phone caller identification, shopping application
- H04N21/4782—Web browsing, e.g. WebTV
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)
Abstract
The invention discloses a method for playing a MKV video by a browser, and belongs to the technical field of video playing. The method comprises the following steps: creating a Video player and a MediaSource object, and setting the MediaSource object as a play address of the Video player; loading the MKV video into the memory of the browser in the form of a binary file; analyzing the MKV video to obtain video track data, audio track data and subtitle track data; packaging video track data and audio track data into an fmp4 format; putting video track data and audio track data packaged into fmp4 format into a MediaSource object; creating a caption display layer on the upper layer of the video player, and transmitting caption track data to the caption display layer; and playing the MKV video and displaying the corresponding caption on the caption display layer. The invention realizes plug-in-free playing of the MKV video.
Description
Technical Field
The invention belongs to the technical field of video playing, and particularly relates to a method for playing a MKV video in a browser.
Background
Currently, the main mode of watching video is changed from downloading to online watching, and the online watching mode generally comprises two modes of watching through video software and watching through web pages, however, the existing browser does not support direct playing of mkv format video.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a method for playing an MKV video by a browser.
The aim of the invention is realized by the following technical scheme: a method for playing MKV video by a browser comprises the following steps:
creating a Video player and a MediaSource object, and setting the MediaSource object as a play address of the Video player;
loading the MKV video into the memory of the browser in the form of a binary file;
analyzing the MKV video to obtain video track data, audio track data and subtitle track data;
packaging video track data and audio track data into an fmp4 format;
putting video track data and audio track data packaged into fmp4 format into a MediaSource object;
creating a caption display layer on the upper layer of the video player, and transmitting caption track data to the caption display layer;
clicking a play button of the video player to play the MKV video, and displaying the corresponding caption on a caption display layer.
Further, loading the MKV video into the memory of the browser in the form of a binary file, including:
creating an XMLHttpRequest object and loading the MKV video into the memory of the browser in the form of a binary file.
Further, parsing the MKV video to obtain video track data, audio track data, and subtitle track data includes:
analyzing the Track part of the MKV video to obtain attribute information of the video, the audio and the subtitle;
analyzing Clusters part of the MKV video to obtain original data information of the video, the audio and the subtitle;
generating video track data according to the attribute information and the original data information of the video;
generating audio track data according to the attribute information and the original data information of the audio;
and generating subtitle track data according to the attribute information and the original data information of the subtitle.
Further, encapsulating the video track data into fmp4 format includes:
packaging video creation time, video modification time, play rate, video duration, volume size, video width, sound channel and video/audio position into corresponding box types, assembling and putting into moov boxes;
creating moof, and writing video duration, video data length and data type into moof according to the video data of the current fragment;
creating mdat, and writing the current fragment data into mdat box;
and circulating the video track video, and continuously generating moof+mdat, thereby completing the video track data encapsulation.
Further, packaging the audio track data into fmp4 format, comprising:
after video track data is packaged into an fmp4 format, moof is created, and audio duration, audio data length and data type are written into moof according to the audio data of the current fragment;
creating mdat, and writing the data of the current fragment into mdat;
and (5) circulating the audio track video, and continuously generating moof+mdat, thereby completing the audio track data encapsulation.
Further, displaying the corresponding subtitle on the subtitle display layer includes:
monitoring a time head update event of a video player when playing the MKV video;
transmitting the time header into a caption display layer;
the caption display layer searches caption rail data according to the time header, displays the captions with the time header larger than the inPoint and smaller than the outPoint, and hides the rest captions.
The beneficial effects of the invention are as follows:
(1) The invention realizes the function of playing the MKV video without plug-in;
(2) The invention is compatible with partial historical media library video, and reduces the work of back-end video format conversion;
(3) In the invention, the video and the caption are in one file, so that the management quantity of the back-end file is reduced.
Drawings
FIG. 1 is a flowchart of a method for playing a MKV video in a browser in a native manner according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a structure of an EBML;
FIG. 3 is a schematic diagram of the analysis result of the Track portion;
FIG. 4 is a schematic representation of the results of Clusters partial resolution;
fig. 5 is a schematic diagram of a box structure.
Detailed Description
The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments, and it is apparent that the described embodiments are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by a person skilled in the art without any inventive effort, are intended to be within the scope of the present invention, based on the embodiments of the present invention.
Referring to fig. 1 to 5, the present invention provides a method for playing a MKV video by a browser in a native manner:
as shown in fig. 1, a method for playing a MKV video by a browser includes steps S100 to S700.
Step S100, creating a Video player and a MediaSource object, and setting the MediaSource object as a play address of the Video player.
And S200, loading the MKV video into a memory of a browser in a binary file mode.
Specifically, an XMLHttpRequest object is created, and the MKV video is loaded into the memory of the browser in the form of a binary file.
And S300, analyzing the MKV video to obtain video track data, audio track data and subtitle track data.
The MKV video file structure generally includes a Header, meta Seek Information, segment Information, track, chapters, clusters, cueing Data, attachment, and taging, as shown in table 1.
TABLE 1
The Header section contains EBML version information and the type of EBML (indicated as Matroska file).
The Metaseek section Info portion contains index information for locating other portions of the file (e.g., track Info, chapters, tags, cues, attachments, etc.). This portion is not necessary and may be obtained by scanning other fields of the entire file if not present.
The Segment Info section contains basic information about the entire file, such as title information, and contains a unique ID, and if there are multiple related files in succession, the ID of the next file.
The Track section contains Track-related information such as audio, video, subtitles, video resolution, audio sampling rate, coding mode, etc.
The Chapters section gives all Chapters. Wherein each Chapters is a way of bloating preset audio and video play points.
The clusteris section contains mainly audio and video frames per track.
The Cueing Data part contains all Cue information. Cues is index information of each track, similar to MetaSeek Info, but mainly used for seek to a specific time when playing.
The Attachment part is mainly used for supporting the Attachment of any type of files in the MKV file, including pictures, web pages, programs and the like.
The Tag section contains tags associated with the file and each track. These tags, like the ID3 tags in MP3 files, contain information such as the owner writer, singer, ctor.
The MKV video describes its file structure in an extensible binary meta-language EBML (Extensible Binary Meta Language), as shown in fig. 2, EBML describes EBML documents in terms of Elements. By looping or recursion, different data portions can be located. EBML is an XML-based data structure, consisting of multiple underlying ebml_elements, which constitute a complete EBML.
typedef struct {
vint ID;// EBML-ID
vint size;// size of element
char data[size];// data
} EBML_ELEMENT;
In some embodiments, parsing the MKV video to obtain video track data, audio track data, and subtitle track data includes: analyzing the Track part of the MKV video to obtain attribute information of the video, the audio and the subtitle, as shown in figure 3; analyzing Clusters part of the MKV video to obtain original data information of the video, the audio and the subtitle, as shown in figure 4; generating video track data according to the attribute information and the original data information of the video; generating audio track data according to the attribute information and the original data information of the audio; and generating subtitle track data according to the attribute information and the original data information of the subtitle.
And S400, packaging the video track data and the audio track data into an fmp4 format.
Specifically, the mp4 encapsulation format organizes data using a structure called a box, and as shown in fig. 5, the header consists of size (4 bytes) +type (4 bytes) +large size (8 bytes), and the body is the next box or data. fmp4 is composed of individual boxes, the first layer has four main types of boxes, respectively: ftyp (file type box), file header, record some compatibility information; moov (movie box), recording media information; moof (movie box), recording media information in the current segment; mdat (media data), media load. Unlike ordinary Mp4, fmp4 is in a streaming format, with the exception of ftyp and moov, fmp4 consists of boxes of successive moof and mdat. Packaging video track data and audio track data into fmp4 format, comprising: (1) According to the analyzed MKV data information, video creation time, video modification time, playing speed, video duration, volume size, video height and width, sound channel, video/audio position and the like are packaged into corresponding box types, and the box types are assembled and put into a moov box; (2) Creating moof, and writing video duration, video data length and data type into moof according to the video data of the current fragment; (3) creating mdat, writing the current fragment data as mdat box; (4) And circulating the video track video, and continuously generating moof+mdat, thereby completing the video track data encapsulation.
Packaging audio track data in fmp4 format, comprising: after video track data is packaged into an fmp4 format, moof is created, and audio duration, audio data length and data type are written into moof according to the audio data of the current fragment; creating mdat, and writing the data of the current fragment into mdat; and (5) circulating the audio track video, and continuously generating moof+mdat, thereby completing the audio track data encapsulation.
And S500, putting the video track data and the audio track data which are packaged into the fmp4 format into a media source object.
And S600, creating a caption display layer on the upper layer of the video player, and transmitting caption track data to the caption display layer.
And S700, clicking a play button of the video player to play the MKV video, and displaying the corresponding caption on a caption display layer.
In some embodiments, displaying the corresponding subtitles on the subtitle display layer includes: monitoring a time head update event of a video player when playing the MKV video; transmitting the time header into a caption display layer; the caption display layer searches caption rail data according to the time header, displays the captions with the time header larger than the inPoint and smaller than the outPoint, and hides the rest captions.
The foregoing is merely a preferred embodiment of the invention, and it is to be understood that the invention is not limited to the form disclosed herein but is not to be construed as excluding other embodiments, but is capable of numerous other combinations, modifications and environments and is capable of modifications within the scope of the inventive concept, either as taught or as a matter of routine skill or knowledge in the relevant art. And that modifications and variations which do not depart from the spirit and scope of the invention are intended to be within the scope of the appended claims.
Claims (6)
1. A method for playing a MKV video in a browser, comprising:
creating a Video player and a MediaSource object, and setting the MediaSource object as a play address of the Video player;
loading the MKV video into the memory of the browser in the form of a binary file;
analyzing the MKV video to obtain video track data, audio track data and subtitle track data;
packaging video track data and audio track data into an fmp4 format;
putting video track data and audio track data packaged into fmp4 format into a MediaSource object;
creating a caption display layer on the upper layer of the video player, and transmitting caption track data to the caption display layer;
clicking a play button of the video player to play the MKV video, and displaying the corresponding caption on a caption display layer.
2. The method for playing the MKV video in the browser as set forth in claim 1, wherein loading the MKV video in the form of a binary file into the memory of the browser comprises:
creating an XMLHttpRequest object and loading the MKV video into the memory of the browser in the form of a binary file.
3. The method for playing the MKV video in the browser as set forth in claim 1, wherein parsing the MKV video to obtain video track data, audio track data and subtitle track data includes:
analyzing the Track part of the MKV video to obtain attribute information of the video, the audio and the subtitle;
analyzing Clusters part of the MKV video to obtain original data information of the video, the audio and the subtitle;
generating video track data according to the attribute information and the original data information of the video;
generating audio track data according to the attribute information and the original data information of the audio;
and generating subtitle track data according to the attribute information and the original data information of the subtitle.
4. The method for playing the MKV video in the browser as set forth in claim 1, wherein the encapsulating the video track data into fmp4 format includes:
packaging video creation time, video modification time, play rate, video duration, volume size, video width, sound channel and video/audio position into corresponding box types, assembling and putting into moov boxes;
creating moof, and writing video duration, video data length and data type into moof according to the video data of the current fragment;
creating mdat, and writing the current fragment data into mdat box;
and circulating the video track video, and continuously generating moof+mdat, thereby completing the video track data encapsulation.
5. The method for playing the MKV video native to the browser according to claim 4, wherein the encapsulating the audio track data into fmp4 format includes:
after video track data is packaged into an fmp4 format, moof is created, and audio duration, audio data length and data type are written into moof according to the audio data of the current fragment;
creating mdat, and writing the data of the current fragment into mdat;
and (5) circulating the audio track video, and continuously generating moof+mdat, thereby completing the audio track data encapsulation.
6. The method for playing MKV video in the native browser of claim 1, wherein displaying the corresponding subtitles on the subtitle display layer includes:
monitoring a time head update event of a video player when playing the MKV video;
transmitting the time header into a caption display layer;
the caption display layer searches caption rail data according to the time header, displays the captions with the time header larger than the inPoint and smaller than the outPoint, and hides the rest captions.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311211800.3A CN116962815B (en) | 2023-09-20 | 2023-09-20 | Method for playing MKV video in original mode by browser |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311211800.3A CN116962815B (en) | 2023-09-20 | 2023-09-20 | Method for playing MKV video in original mode by browser |
Publications (2)
Publication Number | Publication Date |
---|---|
CN116962815A true CN116962815A (en) | 2023-10-27 |
CN116962815B CN116962815B (en) | 2023-11-21 |
Family
ID=88454936
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311211800.3A Active CN116962815B (en) | 2023-09-20 | 2023-09-20 | Method for playing MKV video in original mode by browser |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116962815B (en) |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103338401A (en) * | 2013-06-03 | 2013-10-02 | 贝壳网际(北京)安全技术有限公司 | Video playing control method, device and system for mobile terminal browser |
WO2019227748A1 (en) * | 2018-05-29 | 2019-12-05 | 北京字节跳动网络技术有限公司 | Method and apparatus for playing non-streaming media file in webpage, and storage medium |
US20200413160A1 (en) * | 2018-05-29 | 2020-12-31 | Beijing Bytedance Network Technology Co., Ltd. | Webcasting method, device and storage medium of media file |
CN112653700A (en) * | 2020-12-23 | 2021-04-13 | 武汉烽火众智数字技术有限责任公司 | Website video communication method based on WEBRTC |
CN112929686A (en) * | 2021-02-04 | 2021-06-08 | 北京华宇信息技术有限公司 | Method and device for playing back recorded video in real time on line |
CN112995760A (en) * | 2019-12-18 | 2021-06-18 | 腾讯科技(深圳)有限公司 | Video processing method, device, equipment and computer storage medium |
CN116261021A (en) * | 2023-05-16 | 2023-06-13 | 北京蓝色星际科技股份有限公司 | Video stream playing method and device, electronic equipment and storage medium |
-
2023
- 2023-09-20 CN CN202311211800.3A patent/CN116962815B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103338401A (en) * | 2013-06-03 | 2013-10-02 | 贝壳网际(北京)安全技术有限公司 | Video playing control method, device and system for mobile terminal browser |
WO2019227748A1 (en) * | 2018-05-29 | 2019-12-05 | 北京字节跳动网络技术有限公司 | Method and apparatus for playing non-streaming media file in webpage, and storage medium |
CN110545469A (en) * | 2018-05-29 | 2019-12-06 | 北京字节跳动网络技术有限公司 | Webpage playing method, device and storage medium of non-streaming media file |
US20200413160A1 (en) * | 2018-05-29 | 2020-12-31 | Beijing Bytedance Network Technology Co., Ltd. | Webcasting method, device and storage medium of media file |
CN112995760A (en) * | 2019-12-18 | 2021-06-18 | 腾讯科技(深圳)有限公司 | Video processing method, device, equipment and computer storage medium |
CN112653700A (en) * | 2020-12-23 | 2021-04-13 | 武汉烽火众智数字技术有限责任公司 | Website video communication method based on WEBRTC |
CN112929686A (en) * | 2021-02-04 | 2021-06-08 | 北京华宇信息技术有限公司 | Method and device for playing back recorded video in real time on line |
CN116261021A (en) * | 2023-05-16 | 2023-06-13 | 北京蓝色星际科技股份有限公司 | Video stream playing method and device, electronic equipment and storage medium |
Non-Patent Citations (2)
Title |
---|
OTHER: "如何在网络浏览器中播放 MKV 视频?", Retrieved from the Internet <URL:https://www.wp2.cn/other/%E5%A6%82%E4%BD%95%E5%9C%A8%E7%BD%91%E7%BB%9C%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%AD%E6%92%AD%E6%94%BE-mkv-%E8%A7%86%E9%A2%91/> * |
赛琳娜·托马斯(SELENA THOMAS): "如何在Chromecast上播放MKV –这是您应该知道的2种有效方法", Retrieved from the Internet <URL:https://www.bluraycopys.com/zh-CN/resource/chromecast-play-mkv.html> * |
Also Published As
Publication number | Publication date |
---|---|
CN116962815B (en) | 2023-11-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10430212B1 (en) | Method for recording, editing and reproduction of computer session | |
CN1777945B (en) | Method and apparatus for synchronous reproduction of main contents recorded on an interactive recording medium and additional contents therefor | |
CN1327431C (en) | Information memory media containing pre-carrying information and its reproducing equipment and method | |
US8799757B2 (en) | Synchronization aspects of interactive multimedia presentation management | |
US7721308B2 (en) | Synchronization aspects of interactive multimedia presentation management | |
US7313809B1 (en) | Convergence-enabled DVD and web system | |
US20070006079A1 (en) | State-based timing for interactive multimedia presentations | |
US20070006065A1 (en) | Conditional event timing for interactive multimedia presentations | |
US20070118554A1 (en) | System and method for authoring multimedia contents description metadata | |
US20070073747A1 (en) | Information Storage medium on which interactive contents version information is recorded, and recording and/or reproducing method and apparatus | |
US8020084B2 (en) | Synchronization aspects of interactive multimedia presentation management | |
KR20110056476A (en) | Multimedia distribution and playback systems and methods using enhanced metadata structures | |
CN1954384A (en) | Method of and apparatus for reproducing downloaded data along with data recorded on storage medium | |
CN100479047C (en) | Storage medium recording text-based subtitle stream, apparatus and method reproducing thereof | |
US20230377606A1 (en) | Video editing projects using single bundled video files | |
US20060257106A1 (en) | Information storage medium, information recording apparatus, and information playback apparatus | |
US20090136218A1 (en) | Multimedia presentation format | |
US20080056663A1 (en) | File Recording Apparatus, File Recording Method, Program of File Recording Process, Storage Medium in Which a Program of File Recording Processing in Stored, File Playback Apparatus File Playback Method Program of File Playback Process | |
CN116962815B (en) | Method for playing MKV video in original mode by browser | |
CN100555432C (en) | Method and apparatus and storage medium thereof with reproducing AV data in interactive mode | |
KR101014665B1 (en) | Information storage medium containing preload information, apparatus and method for reproducing therefor | |
US20070006062A1 (en) | Synchronization aspects of interactive multimedia presentation management | |
CN100418151C (en) | Information storage medium including device-aspect-ratio information, method and apparatus therefor | |
KR102422450B1 (en) | Method for managing media data and sensing data | |
CN101689389A (en) | Information storage medium, reproducing apparatus, and reproducing method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |