CN110545461A - Resolution switching method and device of media file and storage medium - Google Patents

Resolution switching method and device of media file and storage medium Download PDF

Info

Publication number
CN110545461A
CN110545461A CN201810532261.6A CN201810532261A CN110545461A CN 110545461 A CN110545461 A CN 110545461A CN 201810532261 A CN201810532261 A CN 201810532261A CN 110545461 A CN110545461 A CN 110545461A
Authority
CN
China
Prior art keywords
media
media file
file
resolution
segmented
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.)
Pending
Application number
CN201810532261.6A
Other languages
Chinese (zh)
Inventor
银国徽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co Ltd
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 Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN201810532261.6A priority Critical patent/CN110545461A/en
Publication of CN110545461A publication Critical patent/CN110545461A/en
Pending legal-status Critical Current

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/433Content storage operation, e.g. storage operation in response to a pause request, caching operations
    • H04N21/4335Housekeeping operations, e.g. prioritizing content for deletion because of storage space restrictions
    • 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/44Processing 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/44004Processing 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 video buffer management, e.g. video decoder buffer or video display buffer
    • 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/44Processing 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/4402Processing 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/440263Processing 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 altering the spatial resolution, e.g. for displaying on a connected PDA
    • 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/47End-user applications
    • H04N21/478Supplemental services, e.g. displaying phone caller identification, shopping application
    • H04N21/4782Web 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 present disclosure provides a resolution switching method for a media file, including: responding to a resolution switching event of a media file played by an embedded player in a webpage, and clearing a part of segmented media files with original resolution cached in a media resource expansion interface of the webpage; the media files correspond to a plurality of segmented media files; acquiring a segmented media file with a target resolution ratio continuing the playing point according to the playing point of the media file and the media file; and sending the acquired segmented media file with the target resolution to the media resource expansion interface, and calling the media elements of the webpage for playing through the media resource expansion interface. The embodiment of the disclosure also provides a resolution switching device and a storage medium of the media file.

Description

resolution switching method and device of media file and storage medium
Technical Field
The present disclosure relates to a technology for switching resolutions of media files, and in particular, to a method and an apparatus for switching resolutions of media files, and a storage medium.
Background
When multimedia information is played through a web page, media data between a current playing point and an ending point is usually preloaded. However, preloading of the media data will take up a lot of buffer space, reducing the processing speed of the player.
Disclosure of Invention
in view of this, embodiments of the present disclosure provide a method and an apparatus for switching resolution of a media file, and a storage medium, which can clear preloaded media data, release a cache space, and improve a processing speed of a player.
In one aspect, an embodiment of the present disclosure provides a method for switching resolutions of media files, including: responding to a resolution switching event of a media file played by an embedded player in a webpage, and clearing a part of segmented media files with original resolution cached in a media resource expansion interface of the webpage; the media files correspond to a plurality of segmented media files; acquiring a segmented media file with a target resolution ratio continuing the playing point according to the playing point of the media file and the media file; and sending the acquired segmented media file with the target resolution to the media resource expansion interface, and calling the media elements of the webpage for playing through the media resource expansion interface.
in another aspect, an embodiment of the present disclosure provides a device for switching resolution of a media file, including:
The clearing unit is used for responding to a resolution switching event of a media file played by an embedded player in a webpage and clearing a part of segmented media files with original resolution cached in a media resource expansion interface of the webpage; the media files correspond to a plurality of segmented media files;
An obtaining unit, configured to obtain, according to a playing point of the media file and the media file, a segmented media file with a target resolution that is subsequent to the playing point;
And the sending unit is used for sending the acquired segmented media file with the target resolution to the media resource expansion interface and calling the media elements of the webpage to play through the media resource expansion interface.
in another aspect, an embodiment of the present disclosure provides a device for switching resolution of a media file, including:
A memory for storing executable instructions;
And the processor is used for realizing the resolution switching method of the media file by executing the executable instructions stored in the memory.
in another aspect, an embodiment of the present disclosure provides a storage medium, where executable instructions are stored in the storage medium, and when the executable instructions are executed, the storage medium is configured to implement the method for switching the resolution of a media file.
Executable instructions may be interpreted as a generic concept of installation packages, programs, code, plug-ins, libraries (dynamic/static libraries).
in the embodiment of the disclosure, when a resolution switching event occurs to a media file played by an embedded player in a webpage, part of segmented media files of an original resolution cached in a media resource expansion interface of the webpage are cleared; the occupation of the buffer space is reduced, and the processing speed of the player is improved.
Drawings
FIG. 1 is a schematic view of an alternative construction of a container provided by embodiments of the present disclosure;
Fig. 2 is a schematic diagram of an alternative package structure of an MP4 file provided by an embodiment of the present disclosure;
Fig. 3 is a schematic structural diagram of a media data container storing media data in a media file provided by an embodiment of the present disclosure;
FIG. 4 is a schematic diagram of an alternative packaging structure of an FMP4 file provided by an embodiment of the present disclosure;
Fig. 5 is an alternative structural schematic diagram of a media file resolution switching apparatus provided by an embodiment of the disclosure;
Fig. 6 is a schematic processing flow diagram of an alternative resolution switching method for a media file according to an embodiment of the present disclosure;
fig. 7 is a schematic view of an alternative process flow of a player acquiring a segmented media file with a target resolution of a continuous play point according to an embodiment of the present disclosure;
FIG. 8 is a schematic diagram of an alternative process for parsing media information from a metadata container according to an embodiment of the present disclosure;
FIG. 9 is an alternative flow diagram for packaging segmented media files provided by embodiments of the present disclosure;
Fig. 10 is a schematic flowchart illustrating that a player sends a segmented media file to a media element of a web page for decoding and playing through a media source extension interface of the web page according to an embodiment of the present disclosure;
FIG. 11 is an alternative diagram of a player according to an embodiment of the present disclosure playing a segmented media file through a media source extension interface of a web page;
FIG. 12 is a schematic diagram of an MP4 file being converted into an FMP4 file and being played through a media source extension interface according to an embodiment of the present disclosure;
Fig. 13 is a schematic processing flow diagram of an alternative resolution switching method applied to a media file embedded in a web page according to an embodiment of the present disclosure;
Fig. 14 is a schematic structural diagram of a resolution switching apparatus for media files according to an embodiment of the present disclosure.
Detailed Description
For the purpose of making the purpose, technical solutions and advantages of the present disclosure clearer, the present disclosure will be described in further detail with reference to the accompanying drawings, the described embodiments should not be construed as limiting the present disclosure, and all other embodiments obtained by a person of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present disclosure.
unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure.
Before the present disclosure is explained in further detail, terms and expressions referred to in the embodiments of the present disclosure are explained, and the terms and expressions referred to in the embodiments of the present disclosure are applied to the following explanations.
1) a media file, a file storing encoded media data (e.g., at least one of audio data and video data) in a container (Box), includes metadata, i.e., data describing the media data, and carries media information to ensure that the media data is decoded correctly.
For example, a file in which multimedia data is encapsulated in an MP4 container format is referred to as an MP4 file, and typically, the MP4 file stores therein Advanced Video Coding (AVC, Advanced Video Coding, or h.264) or MPEG-4(Part 2) specification coded Video data and Advanced Audio Coding (AAC, Advanced Audio Coding) specification coded Audio data, although other Coding modes of Video and Audio are not excluded.
2) The container (Box), also called a Box, an object-oriented component defined by a unique type identifier and a length, see fig. 1, is an optional structural diagram of the container provided by the embodiment of the present disclosure, and includes a container Header (Box Header) and container Data (Box Data), which are filled with binary Data to express various information.
The container header includes a size (size) and a type (type), the size indicates a size (also referred to as a capacity or a length herein) of a storage space occupied by the container, the type indicates a type of the container, and fig. 2 is a schematic diagram of an alternative package structure of an MP4 file provided by an embodiment of the present disclosure, and basic container types referred to in an MP4 file include a file type container (ftyp box), a metadata container (moov box), and a media data container (mdat box).
the container data portion may store specific data, where the container is referred to as a "data container," and may further encapsulate other types of containers, where the container is referred to as a "container of a container.
3) track (Track), a time-ordered sequence of related samples (Sample) in a container of media data, which represents a sequence of video frames or a sequence of audio frames for media data, and may also include a subtitle Track synchronized with the sequence of video frames, a set of consecutive samples in the same Track being called a Chunk (Chunk).
4) A file type container, a container for storing the capacity (i.e. length of occupied bytes) and type of a file in a media file, as shown in fig. 2, binary data stored in the file type container describes the type and capacity of the container according to the specified byte length.
5) A metadata container, a container in a media file for storing metadata (i.e., data describing multimedia data stored in the media data container), and information expressed by binary data stored in the metadata container in the MP4 file are referred to as media information.
as shown in fig. 2, the header of the metadata container represents the type of the container as "moov box" using binary data, and the container data part encapsulates an mvhd container for storing general information of an MP4 file, is independent of an MP4 file, and is related to the playing of an MP4 file, including a time length, a creation time, a modification time, and the like.
The media data container of the media file may include sub-containers corresponding to a plurality of tracks, such as an audio track container (audio track box) and a video track container (video track box), in which references and descriptions of media data of the corresponding tracks are included, and the necessary sub-containers include: a container (denoted tkhd box) for describing the characteristics and overall information of the track (e.g. duration, width, height), and a container (denoted mdia box) for recording media information of the track (e.g. information of media type and sample).
as for the sub-containers packaged in the mdia box, it may include: recording the relevant attributes and content of the track (denoted mdhd box), recording the playing procedure information of the media (denoted hdlr box), describing the media information of the media data in the track (denoted minf box); the minf box in turn has a sub-container (denoted as dinf box) for explaining how to locate the media information, and a sub-container (denoted as stbl box) for recording all the time information (decoding time/display time), position information, codec etc. of the samples in the track.
referring to fig. 3, which is a schematic structural diagram of a media data container in a media file for storing media data according to an embodiment of the present disclosure, the time, type, capacity and location of a sample in the media data container can be interpreted by using media information identified from binary data in a stbl box container, and each sub-container in the stbl box is described below.
The stsd box contains a sample description (sample description) table, and there may be one or more description tables in each media file according to different coding schemes and the number of files storing data, and the description information of each sample can be found through the description tables, and the description information can ensure correct decoding of the sample, and different media types store different description information, for example, the description information is the structure of the image in the case of video media.
the stts box stores the duration information of the samples and provides a table to map time (decoding time) and the serial numbers of the samples, and the samples at any time in the media file can be located through the sttx box; the stts box also uses other tables to map the sample size and pointers, where each entry in the table provides the serial number of consecutive samples within the same time offset and the offset of the sample, and increments these offsets to build a complete time-sample mapping table, and the calculation formula is as follows:
DT(n+1)=DT(n)+STTS(n)(1)
Where STTS (n) is the duration of the nth sample, DT (n) is the display time of the nth sample, the samples are arranged in a time sequence, such that the offset is always non-negative, DT generally starts with 0, and the calculation formula is as follows, taking the display time DT (i) of the ith sample as an example:
DT(i)=SUM(for j=0to i-1of delta(j))(2)
the sum of all offsets is the duration of the media data in the track.
The stss box records the sequence number of the key frame in the media file.
The stsc box records the mapping relation between the samples and the blocks for storing the samples, the relation between the serial numbers of the samples and the serial numbers of the blocks is mapped through a table, and the blocks containing the specified samples can be found through table lookup.
the stco box defines the position of each block in the track, expressed in terms of the offset of the starting byte in the media data container, and the length (i.e., the size) relative to the starting byte.
the stsz box records the size (i.e., size) of each sample in the media file.
6) a media data container, a container for storing multimedia data in a media file, for example, a media data container in an MP4 file, as shown in fig. 3, a sample is a unit stored in the media data container, and is stored in a block of the media file, and the lengths of the block and the sample may be different from each other.
7) and segmenting the media files, wherein the media files are divided into subfiles, and each segmented media file can be independently decoded.
Taking the MP4 file as an example, the media data in the MP4 file is divided according to the key frames, the divided media data and the corresponding metadata are packaged to form a segmented MP4 (segmented MP4) file, and the metadata in each FMP4 file can ensure that the media data is correctly decoded.
For example, when the MP4 file shown in fig. 2 is converted into multiple FMP4 files, referring to fig. 4, which is an optional packaging structure diagram of FMP4 files provided in the embodiment of the present disclosure, one MP4 file may be converted into multiple FMP4 files, and each FMP4 file includes three basic containers: moov containers, moof containers, and mdat containers.
the moov container includes MP4 file level metadata describing all media data in the MP4 file from which the FMP4 file is derived, such as the duration, creation time, and modification time of the MP4 file.
The moof container stores segment-level metadata describing media data packaged in the FMP4 file where it is located, ensuring that the media data in the FMP4 can be decoded.
the 1 moof container and the 1 mdat container constitute 1 segment of the segment MP4 file, and 1 or more such segments may be included in the 1 segment MP4 file, and the metadata encapsulated in each segment ensures that the media data encapsulated in the segment can be independently decoded.
8) Media resource Extensions (MSE) interface, player-oriented interface implemented in web pages, interpreted by the browser's interpreter during loading in the web page, implemented by executing a front-end programming language (e.g., JavaScript), provides the player with the functionality to call the play Media stream of hypertext markup language (HTML) Media elements (Media elements), for example, to implement the play functionality of video/audio using video Element < video > and audio Element < audio >.
9) The streaming media packaging format is a packaging technology for packaging media data into a file of streaming media, the file of the streaming media can be decoded and played without complete downloading and extra transcoding, namely, the packaging technology supports downloading while playing once as is. Typical Streaming media encapsulation format files are, for example, TS media file fragments based on HTTP Live Streaming (HLS, HTTP Live Streaming) technology, flv (flash video) files, and the like.
10) a non-streaming media encapsulation format, which is an encapsulation technology for encapsulating media data into a media file and allowing the media file to be decoded and played after the media file is completely downloaded, and a typical file in the non-streaming media encapsulation format includes: MP4 files, Windows Media Video (WMV) files, Advanced Streaming Format (ASF) files, and the like.
It should be noted that MP4 file does not natively support streaming media playback, but the technical effect of filling invalid binary data in the transcoded media stream of the player after on-line transcoding (for example, in the case of full download of ftyp container and moov container, the missing part of the filled mdat container is replaced by invalid binary data) can also be achieved by filling invalid binary data in the missing part of the partially downloaded MP4 file.
the following describes a flow of a player implementing an embodiment of the present disclosure to acquire media data in a given period.
when playing a movie or a track, the player must be able to correctly parse the data stream, obtain the corresponding media data for a certain time and ensure that the piece of media data can be decoded independently.
1. Determining a time interval corresponding to the media data to be acquired, wherein the time interval is a period of time for continuously playing a current playing point, and the time corresponding to the playing point is time measurement relative to a media time coordinate system (taking the playing start time of the media file as a time origin).
2. The stts box is checked to determine the sequence number of the samples for a given period of decoding time.
For audio frame frames, the stts box is checked to determine the sequence number of the audio frame for a given period of decoding time.
for video frames, due to the compression algorithm, if the first frame in a given period is not a key frame, the first frame in the given period needs to be traced back to the key frame before the start time of the given period according to the time sequence to ensure that the frames in the given period can be decoded.
3. The sequence number of the block including the sample is determined by querying the stsc box according to the employed sequence number.
4. the offset of the block is looked up from the stco box.
5. And searching the stsz box according to the serial number of the sample, and finding the offset of the sample in the block and the volume of the sample.
The process of finding key frames implementing the embodiments of the present disclosure is described.
1. The sequence number of samples in a given time is determined.
2. The stss box is checked to find the key frame after this sample.
3. The stsc box is checked to find the block corresponding to the key frame.
4. The offset of the block is extracted from the stco box.
5. The stsz box is used to find the offset of the key frame sample within the block and the size of the key frame.
The following first describes a resolution switching device for media files according to an embodiment of the present disclosure, where the resolution switching device for media files clears a part of segmented media files with original resolution cached in a media resource extension interface of a web page in response to a resolution switching event of a media file played by an embedded player in the web page; the media files correspond to a plurality of segmented media files; acquiring a segmented media file with a target resolution ratio continuing the playing point according to the playing point of the media file and the media file; and sending the acquired segmented media file with the target resolution to the media resource expansion interface, and calling the media elements of the webpage for playing through the media resource expansion interface.
the following is a description of the structure of the media file resolution switching apparatus that implements the embodiments of the present disclosure.
Referring to fig. 5, which is an optional structural schematic diagram of the apparatus 100 for switching the resolution of a media file according to the embodiment of the present disclosure, the apparatus for switching the resolution of a media file shown in fig. 5 includes: at least one processor 150, at least one communication bus 160, a user interface 180, at least one network interface 170, and memory 190. The various components in the resolution switching device 100 for media files are coupled together by a communication bus 160. It will be appreciated that a communication bus 160 is used to enable communications among the components. The communication bus 160 includes a power bus, a control bus, and a status signal bus in addition to a data bus. But for clarity of illustration the various busses are labeled in figure 5 as communication bus 160.
The user interface 180 may include, among other things, a display, a keyboard, a mouse, a trackball, a click wheel, a key, a button, a touch pad, or a touch screen. The network interface 170 may include a standard wired interface and the wireless interface may be a WiFi interface.
It is understood that the Memory 190 may be a high-speed RAM Memory or a Non-Volatile Memory (Non-Volatile Memory), such as at least one disk Memory. Memory 190 may also be at least one storage system physically located remote from processor 150.
The resolution switching method of the media file applied to the resolution switching apparatus of the media file provided by the embodiment of the present disclosure may be applied to the processor 150, or implemented by the processor 150. The processor 150 may be an integrated circuit chip having signal processing capabilities. In implementation, the different operations in the resolution switching method of the media file applied to the resolution switching apparatus of the media file may be performed by an integrated logic circuit in the form of hardware or an instruction in the form of software in the processor 150. The processor 150 described above may be a general purpose processor, a DSP or other programmable logic device, discrete gate or transistor logic devices, discrete hardware components, or the like. The processor 150 may implement or execute a method, a step, and a logic block diagram for switching the resolution of a media file, which are applied to a resolution switching apparatus of a media file according to an embodiment of the present disclosure. A general purpose processor may be a microprocessor or any conventional processor or the like. The method for switching the resolution of the media file applied to the device for switching the resolution of the media file provided by the embodiment of the disclosure can be directly implemented by a hardware decoding processor, or implemented by combining hardware and software modules in the decoding processor.
as an example, the software module may be located in a storage medium, which may be the memory 190 shown in fig. 5, and the processor 150 reads executable instructions in the memory 190, and completes an optional processing flow of the resolution switching method of a media file applied to the resolution switching apparatus of a media file provided in the embodiment of the disclosure in combination with hardware thereof, as shown in fig. 6, including the following steps:
Step S101, responding to the resolution switching event of the media file played by the embedded player in the webpage, and eliminating the partial segmented media file with the original resolution cached in the media resource expansion interface of the webpage.
in the embodiment of the disclosure, the web page may be a web page of a browser, or a web page of an app embedded with a browser kernel; the web page is used as an example of the operation of the browser, so that an MSE interface can be implemented in each web page, and if the description that the player loads the content unit to the MSE interface of the browser appears hereinafter, it can be understood that the player should be considered to load the content unit to the MSE interface of the web page running with the playing window, rather than loading the content unit to the MSE interface of all web pages in the browser. .
In the embodiment of the disclosure, the media file corresponds to a plurality of segmented media files, and the plurality of segmented media files are divided according to the playing time, characters, scenes and the like of the media file.
For a media file that supports streaming media playing, the media file is a set of a series of segmented media files, such as an HLS streaming media file, or a set of a series of continuous TS files.
for media files that do not support streaming media playback, such as MP4 files, segmented media files are independently decodable and playable segmented MP4 files formed by repackaging data extracted from the media files.
In the related art, one way of managing the cache of the media resource extension interface is to clear a segmented media file when the playing of the segmented media file is finished. The other mode is to ensure that the cache is not overflowed, namely when the segmented media files added by the Source Buffer cause the cache to be overflowed, the segmented media files are cleared according to the principle of first entering the cache and first clearing, and the new segmented media files can be ensured to be added into the Source Buffer.
according to the above manner, when a resolution switching event occurs, the segmented media file of the original resolution can be kept in the cache all the time without causing cache overflow, but is not necessary to be kept actually, and therefore can be cleared.
in some embodiments, clearing the partial segmented media file of the original resolution cached in the media resource extension interface of the web page means that the segmented media file of which the playing time includes the original resolution of the playing point is reserved in the cache of the media resource extension interface, and the segmented media file of which the playing time does not include the original resolution of the playing point is cleared.
As for the play point, it may be a play time that is reached by continuously playing the media file (i.e., naturally playing without user intervention), for example, from a play point of 30 th minute to a play point of 40 th minute; or, the media file may reach the playing time of the media file by means of jumping (i.e., the user clicks the progress bar through the cursor to realize page jumping), where for example, the original playing point is 20% of the playing progress, and the jumping playing point is 30% of the playing progress.
The segmented media file with the playing time including the original resolution of the playing point refers to the segmented media file which is being played when a resolution switching event occurs; the segmented media files with playing time not including the original resolution of the playing point refer to the segmented media files with playing time earlier than the playing point and the segmented media files with playing time later than the playing point.
In other embodiments, when the resolution switching device of the media file receives the resolution switching event of the media file, timeout detection is performed; and when the resolution switching event returning to the original resolution is not received within the overtime, the segmented media file of the original resolution cached in the media resource expansion interface of the webpage is cleared.
Here, the fact that a resolution switching event returning to the original resolution is not received within the timeout period indicates that the segmented media file of the original resolution is to be played continuously at the target resolution, the segmented media file of the original resolution is not required to be reserved, and all the segmented media files of the original resolution are cleared, so that the cache space is saved, and the processing speed of the player is improved.
step S102, according to the playing point of the media file and the media file, acquiring the segmented media file with the target resolution ratio of the continuous playing point.
In some embodiments, when the media file is in a non-streaming media file format, taking the example that the resolution switching device of the media file is a player, an optional processing flow diagram of the player obtaining a segmented media file with a target resolution following a playing point is shown in fig. 7, and includes the following steps:
In step S201, the player determines two key frames that continue to the playing point in the media file with the target resolution based on the media information of the media file with the target resolution.
Here, the media information of the media file includes related information describing the video frame and the audio frame, and the player obtains information such as decoding time, offset, and capacity of each key frame of the video frame by querying the list of key frames.
before the encapsulation of the segmented media file, metadata of the media data to be filled needs to be calculated, which needs to be calculated in combination with metadata in the media file to obtain metadata at the level of the segmented media file (for example, corresponding to metadata filled into moov box for FMP4 file), and metadata at the level of the segments in the segmented media file (for example, corresponding to metadata filled into moof box for FMP4 file).
In the following, an exemplary implementation is described in which metadata encapsulated in a metadata container of a media file is parsed to obtain media information describing media data encapsulated in a media data container of the media file.
in one embodiment of the present disclosure, the media file is an MP4 file, the nested structure of the child containers in the metadata container of the media file is analyzed, and the binary data in each child container is read according to the nested structure; and analyzing the media information of the media data represented by each sub-container from the read binary data.
With reference to the structure shown in fig. 2, the moov container of the MP4 file is a nested structure, the nested structure of the sub-containers in the metadata container is parsed, the sub-containers nested in the moov container, such as the mvhd container, the audio track container, and the video track container, are determined, if the sub-containers are also nested with containers, the parsing continues until the sub-containers are parsed, the binary data encapsulated in the corresponding sub-containers are read, and the media message represented by the binary data, such as the sequence number of the key frame in the media file recorded by the stss box, the volume (i.e., size) of each sample in the media file recorded by the stsz box, is parsed.
In one embodiment of the present disclosure, a manner is provided for setting a parser according to a container type, and parsing sub-containers in a metadata container according to the container type to obtain media information, which will be described with reference to fig. 8.
Referring to fig. 8, fig. 8 is an alternative flowchart for parsing media information from a metadata container according to an embodiment of the present disclosure, which will be described with reference to the steps shown in fig. 8.
Step S301 locates the position of the metadata container in the media file.
In one embodiment, by reading binary data from the binary data of the media file that conforms to the container header specification, the offset and size of the metadata container in the media file is located according to the type and length of the container identified in the read binary data.
for example, for binary data of a media file, binary data starting from zero bytes corresponds to a file type container, the starting position of the binary data of the media file is read through the specified length of the container header, the binary data conforming to the specified length of the container header is read, and the type and length of a container located behind the file type container in the media file can be determined by parsing the read binary data.
if the parsed type is a file type container, the length (i.e., capacity) of the metadata container can be parsed, and the offset of the metadata container is the length of the file type container.
If the parsed type is a media data container, the binary data conforming to the canonical length of the container header is continuously read according to the length of the media data container and the length of the classified type container as offsets, so that the length (i.e., the capacity) of the metadata container can be parsed, wherein the length of the metadata container is the sum of the length of the file type container and the length of the media data container.
The media file has no specification except that the initial container is a file type container, and the packaging sequence of the subsequent container is not specified, so that the positions of the file type container in the media file can be accurately and efficiently located no matter whether the packaging sequence of the container in the media file is the file type container, the metadata container and the media data container or the file type container, the media data container and the metadata container.
Step S302, according to the position of the metadata container in the media file, binary data corresponding to the metadata container is obtained from the binary data of the media file.
The position of the metadata container in the media file is represented by an offset and a capacity, the binary data is read from the media file at the position corresponding to the offset until the length of the read binary data conforms to the capacity of the metadata container, and therefore the binary data corresponding to the metadata container is read.
Step S303, sequentially analyzing binary data corresponding to the specified length of the container header in the binary data of the metadata container to obtain the container type of the child container in the metadata container and the length of the container data of the child container.
in one embodiment, for the case where multiple sub-containers are nested in the metadata container, the offset of each reading of binary data is the sum of the lengths of the identified sub-containers, and the length of the read binary data conforms to the canonical length of the container header, so that the type and length of the currently processed sub-container can be parsed.
For example, when reading for the first time, the binary data is read from zero bytes of the binary data of the metadata container, and the length of the read binary data conforms to the specified length of the container header, so that the type and length of the first sub-container can be parsed; and in the second reading, the binary data is read by taking the length of the first read sub-container as an offset, and the length of the read binary data conforms to the specified length of the container header, so that the type and the length of the second sub-container can be analyzed.
The binary data is read in the mode, the condition of backspacing caused by multi-reading can not occur, the condition of secondary reading caused by less reading can not occur, and the analysis efficiency and the accuracy can be ensured.
And step S304, calling a parser with a type corresponding to the container type of the sub-container, and sequentially parsing binary data corresponding to the length of the container data in the unresolved data to obtain the media information represented by the container data.
In one embodiment, a typical container type nested in the metadata container is pre-marked for indicating whether the container is directly used for packaging binary data or is further packaged with a container, for example, a container is further packaged with a mark such as mvhd box, audio track box and video track box shown in fig. 2, and a container is directly packaged with binary data with a mark such as stts box, stsd box shown in fig. 2.
Setting parsers corresponding to the container types one by one for the container types marked as directly encapsulating the binary data, wherein the parsers are used for parsing the represented media information according to the binary data; in step S304, when the container type of the child container parsed in step S303 is compared with the pre-marked container type, the following two cases are involved.
case 1) when the container type of the child container is determined to be pre-marked by comparison and pre-marked for directly encapsulating binary data, a parser corresponding to the container type of the child container is called, and the container data in the child container is parsed by the parser, so that the media information represented by the container data is obtained.
Case 2) when it is determined by the comparison that the container type of the child container is pre-marked and pre-marked for continuously packaging the container, recursively parsing the binary data corresponding to the child container according to the canonical length of the container header in the media file until it is parsed that the container type of the container packaged in the child container is pre-marked and pre-marked for directly packaging the binary data, calling a parser corresponding to the container type of the container packaged in the child container, parsing the binary data byte by byte, the length of the parsed binary data corresponding to the length of the container data of the container packaged in the child container, to obtain the media information represented by the container data of the container packaged in the child container.
in one embodiment, a method for recording media information in a process of parsing a metadata container is described, when binary data corresponding to a standard length of a container header in binary data of the metadata container is sequentially parsed to obtain a container type of a child container in the metadata container, an object is established according to a nesting relationship between the child container and an attributed container and the nesting relationship between the child container and an encapsulated container, when the container type of the child container is pre-marked to be used for directly encapsulating the binary data, an array including the media information is stored in the object established in the corresponding child container, and the stored media information is represented by the container data of the child container.
For example, in fig. 2, when the type of the parsed sub-container is stts box, since the stts box is pre-marked as direct package binary data, an array including media information is stored in an object created corresponding to the stts box, where the media information is duration information represented by container data of the stts box.
In one embodiment, a manner of recording nesting relationships among child containers in a process of parsing a metadata container is described, when binary data corresponding to a canonical length of a container header in binary data of the metadata container is sequentially parsed to obtain a container type of the child container in the metadata container, if the container type is pre-marked as directly encapsulating the binary data, the parsed child container is recorded in a called parser; and setting the recorded instances of the child containers into child container attributes, wherein the child container attributes are included in the containers to which the child containers belong, and are used for describing the nesting relation between the child containers and the belonged containers.
For example, in fig. 2, when the type of the parsed sub-container is stsd box, since stsd box is pre-marked as directly encapsulating binary data, stsd box is recorded in the parser corresponding to the stsd box, an instance of stsd box is set to the stbl box sub-container attribute, and so on, and finally a plurality of sub-containers nested in stbl box, such as stsd box, stts box, stsc box, etc., are recorded in the sub-container attribute of stsd box.
in one embodiment, when the container type of the sub-container is determined by comparison to be not pre-marked or pre-marked to directly package binary data but a parser of a corresponding type is not called, the binary data corresponding to the sub-container is ignored for parsing, and according to the length of the sub-container, a part of the binary data corresponding to a next sub-container is jumped to for further parsing.
In fact, the user-defined container type can appear in the media file, the progress of the overall analysis of the metadata container can not be influenced in a skipping mode, meanwhile, when the container type of the metadata container changes, the latest metadata container can be compatible and analyzed quickly by adding, deleting and modifying analyzers of corresponding types, and the media file has the characteristic of flexible and quick upgrading.
For the first key frame and the second key frame, it may be determined based on a specific time granularity, that is, the difference between the decoding times of the two frames (i.e., the time when decoding starts) conforms to the time granularity; it may also be a content unit based determination that the content of the two frame time representation corresponds to the same subject, e.g. the same person, scene, location, plot unit, etc.
When the playing point is reached by a continuous playing mode, the first key frame of the two key frames is: adding the first key frame after the playing end time of the segmented media file of the media source in the media resource expansion interface; the second key frame of the two key frames is: the second key frame is decoded later than the first key frame. The segmented media file added to the media source in the media resource extension interface refers to a segmented media file currently played by the player.
for the case that the playing point is the playing time that arrives by continuously playing the media file, the manner of determining two key frames (set as the first key frame and the second key frame after the first key frame in decoding time) will be described according to the case that the video frame corresponding to the playing point and the video frame corresponding to the ending time of the given period are the normal frame or the key frame:
Case 1) the video frame corresponding to the playing point is a normal frame, and since the player uses the media data between two key frames as a basic playing loading unit, the media data after the playing point and before the first key frame (the key frame whose decoding time is later than the decoding time of the key frame of the playing point and closest to the playing point) after the playing point is the loaded media data, and in order to avoid repeatedly acquiring the loaded media data, the first key frame in the two key frames at a given time interval is: the first key frame in the media file whose decoding time is after the play point.
Case 2) the video frame corresponding to the playing point is a key frame, and the first key frame of the two key frames in the given period is: the corresponding key frame of the playing point, i.e. the key frame aligned with the start time of the given period.
Case 3) if the video frame corresponding to the end time of the given time period is an ordinary frame, since the player uses the media data between two key frames as a basic playing loading unit, if the key frame before the end time is used as the second key frame of the given time period, the media data between the key frame and the video frame corresponding to the end time is missed to be acquired, and when the media file is played, the media data between the key frame before the end time and the video frame corresponding to the end time cannot be played and skipped, so that in order to ensure that the video frame corresponding to the end time of the given time period can be played normally without frame skipping, the second key frame in the two key frames of the given time period is: decoding a key frame closest to an end time among key frames having a time later than the end time of the given period;
case 4) the video frame corresponding to the end time of the given period is a key frame, and the second key frame of the two key frames of the given period is: the second key frame, which is time-aligned with the end time of the given period, is decoded, i.e., the key frame aligned with the end time of the given period.
In the above cases 1) and 3), the key frame crossing the playing point is used as the end point of the media data in a given period, so that it can be ensured that the video frame corresponding to the playing point has enough information for correct decoding, and frame skipping due to lack of decoded data (i.e. key frame) does not occur.
in the above cases 2) and 4), for the case that the playing point aligns the key frames, the aligned key frames are directly used as the end points of the media data in the given time period, so as to reduce the situation of requesting redundant data to the maximum extent and avoid the situation that the occupation of connection and traffic causes the delay of non-media playing service in the web page.
When the playing point is reached by skipping, the first key frame of the two key frames is: the first key frame of the media file with the decoding time before the playing point, namely the key frame before the playing point and closest to the playing point; the second key frame of the two key frames is: key frames in the media file that are decoded later than the first key frame.
For the case where the playback point is the playback time that has arrived by means of jumping, the manner of determining two keyframes (set as the first keyframe and the second keyframe following the first keyframe in decoding time) will be described according to the case where the video frame corresponding to the playback point and the video frame corresponding to the end time of the given period are normal frames or keyframes.
Case 1) the video frame corresponding to the play point is a normal frame, and since the play point is reached by jumping, the first key frame before the play point and the media data between the play point are not loaded, and the first key frame is: in the media file, the first key frame before the playing point of the decoding time, that is, the time of the media data (that is, the corresponding relationship between the sequence number represented by the media information and the decoding time of the frame) is searched for the key frame whose decoding time is earlier than the starting time of the given period and is closest to the starting time.
the media data between the extra request playing point and the key frame before the playing point can ensure that the jumping to any playing point can be decoded normally, and the condition that the frame jumping occurs because the frame can not be decoded when the playing point corresponds to the common frame is avoided.
Case 2) the video frame corresponding to the play point is a key frame, and the first key frame is: the key frame corresponding to the playing point, that is, the key frame whose decoding time searched from the time of the media data (that is, the corresponding relationship between the sequence number represented by the media information and the decoding time of the frame) is aligned with the start time of the given period.
Case 3) the video frame corresponding to the end time of the given period is a normal frame, and the second key frame is: the key frame whose decoding time is later than the end time of the given period and is closest to the end time is decoded.
In the above cases 1) and 3), the key frame crossing the playing point is used as the end point of the media data in a given period, so that it can be ensured that the video frame corresponding to the playing point has enough information for correct decoding, and frame skipping due to lack of decoded data (i.e. key frame) does not occur.
Case 4) the video frame corresponding to the end time of the given period is a key frame, and the second key frame is: the key frames that are time aligned with the end time of a given period are decoded.
In the cases 2) and 4), the media data to be acquired is defined by aligning the key frames of the playing points, so that on the premise that the playing points can be correctly decoded, the situation of acquiring unnecessary media data is reduced to the maximum extent, occupation of connection and flow is reduced, and real-time performance of non-media playing services in the webpage is further ensured.
Here, there may be no other key frame between the first key frame and the second key frame, i.e. the second key frame is the key frame that appears first after the first key frame; there may be other key frames between the first key frame and the second key frame, i.e. the second key frame is not the first occurring key frame after the first key frame.
determining the number of key frames between the first key frame and the second key frame according to the caching performance (such as the capacity of available cache) of the browser and the network performance (such as network bandwidth); the number of the key frames between the first key frame and the second key frame is positively correlated with the caching performance of the browser, that is, the better the caching performance of the browser is, the larger the number of the key frames between the first key frame and the second key frame is; or the better the network performance, the greater the number of keyframes between the first and second keyframes.
In step S202, the player requests the server for media data between two key frames in the media file of the target resolution.
In some embodiments, when two key frames (a first key frame and a second key frame) succeeding the play point in the media file of the target resolution are determined, an offset and a capacity of a video frame between the two key frames and an offset and a capacity of an audio frame aligned with the video frame in the media file are determined according to media information identified from the media file of the target resolution; determining the offset and the capacity of a target interval according to the determined offset and the capacity, wherein the target interval comprises a video frame and an audio frame; media data located in a target interval in the media file of the target resolution is requested.
here, the media information refers to information such as positions, offsets, and decoding times of video frames and audio frames; the target interval is the minimum interval for storing the video frame and the audio frame to be extracted in the mdat container of the MP4 file, such as the offset of the video frame at the position of the media file, the corresponding interval is a-b (the address is set as ascending order), the offset of the audio frame at the position of the media file, the corresponding interval is c-d, then the target interval is min (a, c) -max (b, d)
Here, the media data between two key frames (first key frame and second key frame) is used to fill a media data container (mdat) to a segmented media file
In some embodiments, if media data between the first key frame and the second key frame is cached in the cache of the browser, the media data between the first key frame and the second key frame extracted from the media file by the player is ignored.
Step S203, the player packages the requested media data and the metadata calculated according to the requested media data into a segmented media file container to obtain a segmented media file with a target resolution.
Here, the encapsulation of the segmented media file uses data: data representing the type and size of the segmented media file for filling into a file type container (ftyp);
Metadata corresponding to media data between key frames, media information describing the media data between key frames (such as offset, capacity, decoding time, duration, width, and the like of video/audio frames for supporting independent decoding), a metadata container (moof) for filling to a segmented media file level;
In some embodiments, the metadata is formed in a manner that includes: extracting file-level metadata from the media file of the target resolution, and calculating new metadata corresponding to the media data between the key frames requested from the server according to media information represented by the extracted metadata; the new metadata includes: metadata at a segmented media file level, and metadata at a segmented level in a segmented media file; and filling the new metadata according to the packaging structure of the segmented media file.
in one embodiment, a player obtains media data corresponding to a given time period from a server, wherein the given time period is used for continuing a playing point, and encapsulates the media data according to the media data and metadata describing the media data according to an encapsulation structure of a segmented media file to form a segmented media file capable of being used for being independently decoded by media elements of a webpage.
referring to fig. 9, fig. 9 is an alternative flow chart of packaging segmented media files provided by the disclosed example, which will be described in conjunction with the steps shown in fig. 9.
Step S401, filling data representing the type and compatibility of the segmented media file into a file type container of the segmented media file.
For example, taking as an example an FMP4 file packaged to form a package structure as shown in fig. 4, the type and length of a container (representing the entire length of the ftyp box) are filled in the header of the file type container of the FMP4 file, that is, the ftyp box, and data (binary data) representing that the file type is FMP4 and a compatible protocol is generated by filling in the data portion of the ftyp box.
Step S402, filling metadata indicating the file level of the segmented media file into a metadata container of the segmented media file.
in one embodiment, the metadata describing the media data required to fill the nested structure is calculated from the nested structure of the metadata container in the segmented media file, based on the media data to be filled into the encapsulation structure of the segmented media file.
still taking fig. 4 as an example, metadata representing the file level of the FMP4 file is calculated and filled into a metadata container (i.e., moov box) of the FMP4, in which three containers of mvhd, track, and video extension (mvex) are nested.
Wherein, the metadata packaged in the mvhd container is used for representing the media information related to the playing of the segmented media file, including the position, the duration, the creation time, the modification time, and the like; the sub-containers nested in the track container represent references and descriptions of corresponding tracks in the media data, for example, a container (denoted as tkhd box) in which characteristics and overall information (such as duration and width) describing the tracks, and a container (denoted as mdia box) in which media information (such as information of media type and sample) of the tracks are nested in the track container.
Step S403, correspondingly filling the extracted media data and the metadata describing the media data into a media data container and a metadata container at a segment level in a segment container of the segmented media file.
In one embodiment, one or more segments (fragments) may be encapsulated in a segmented media file, and for media data to be filled, one or more segmented media data containers (i.e., mdat boxes) of the segmented media file may be filled, and a segment-level metadata container (denoted as moof box) is encapsulated in each segment, wherein the filled metadata is used to describe the media data filled in the segment, so that the segments can be independently decoded.
In conjunction with fig. 4, for example, the media data to be filled is filled into 2 segments of the packaging structure of the FMP4 file, and each segment is filled with the media data; the metadata that needs to be filled into the metadata container (i.e., moof box) of the segmentation level of the corresponding segment is calculated and correspondingly filled into the child containers nested in the moof box, wherein the head of the moof box is called moof box, and the filled binary data is used to indicate the type of the container as "moof box" and the length of the moof box.
In one embodiment of filling data into the corresponding container in steps S401 to S403, when the filling operation is performed, a write operation function of a calling class completes writing and merging of binary data in the memory buffer of the child container, and returns an instance of the class, where the returned instance is used to merge the child container with a child container having a nested relationship.
As an example of the stuffing data, a class MP4 for implementing a package function is established, and each sub-container in the segmented media file is packaged as a static method of class Stream; establishing class streams for realizing binary data operation functions, wherein each class Stream is provided with a memory buffer area for storing binary data to be filled; converting multi-byte decimal data to be padded into binary data by a static method provided by Stream; merging and filling binary data to be filled into the sub-containers in the memory buffer area through a write operation function provided by the Stream-like instance; the static method provided by Stream returns a new Stream instance, and the merging of the current child container and other child containers with nested relation can be realized.
In the embodiment of the disclosure, when the player converts the media file in the non-streaming media format into the segmented media file, the player can realize the playing effect of the media file in the streaming media format type without pre-storing the complete media file in the non-streaming media format; meanwhile, the server does not need to convert the media files in the non-streaming media format into the segmented media files in advance and store the segmented media files, so that the storage space of the server is saved.
Step S103, sending the acquired segmented media file with the target resolution to a media resource expansion interface, and calling media elements of a webpage through the media resource expansion interface to play.
Taking the example that the resolution switching device of the media file is implemented as a player, the process that the player sends the segmented media file to the media source extension interface of the web page to perform decoding playing on the media element of the web page is continuously described.
Referring to fig. 10, it is a schematic flowchart of a process that a player sends a segmented media file to a media element of a web page through a media source extension interface of the web page for decoding and playing, and the steps shown in fig. 10 will be described.
step S501, the player adds the segmented media file to the media source object in the media resource extension interface.
Referring to fig. 11, fig. 11 is an optional schematic diagram of a player playing a segmented Media file through a Media Source extension interface of a web page according to an embodiment of the present disclosure, where when the player receives a play event of the Media file at a play window (corresponding to the play window) in the web page, the player creates a Media Source object by executing a Media Source method; executing an addSource buffer method packaged in a media source expansion interface to create a buffer of a MediaSource object, namely a Source buffer (Source buffer) object, wherein one MediaSource object has one or more Source buffer objects, and each Source buffer object can be used for corresponding to a playing window in a webpage and is used for receiving a segmented media file to be played in the window.
In the process of playing the media file, a Parser (Parser) in the player continuously constructs a new segmented media file by parsing newly acquired media data, and adds the segmented media file to a SourceBuffer object of the same SourceBuffer object by executing an appndbuffer method of the SourceBuffer object.
Step S502, the player calls the media resource expansion interface to create a virtual address corresponding to the media source object.
for example, the player executes the createObjectURL method encapsulated in the media source extension interface, and creates a virtual address, i.e. a virtual URL, of the corresponding media source object, in which the Blob-type segmented media file is encapsulated.
In addition, the player sets the MediaSource object as the source (src) attribute of the virtual URL, i.e., binds the virtual URL with a media element in the web page, such as a video/audio element, which is also referred to as associating the media source object to the media element in the web page.
In step S503, the player transmits a virtual address to the media element of the web page, where the virtual address is used for the media element to play with the media source object as a data source.
For example, the player includes a statement that calls the media element to play the virtual URL, such as: < audio > virtual URL. When the browser interprets the corresponding statement in the player embedded in the webpage, the media element of the browser reads the segmented media file from the SourceBuffer object bound by the virtual URL, and decodes and plays the segmented media file.
The following describes a process in which the player converts the MP4 file into the FMP4 file and plays the web page through the media source extension interface.
Referring to fig. 12, fig. 12 is a schematic diagram of converting an MP4 file provided by the embodiment of the present disclosure into an FMP4 file and playing the file through a media source extension interface, where the player requests to obtain partial media data in an MP4 file from a server based on a real address (http:// www.toutiao.com/a/b. MP4) of the media file, for example, data with a decoding time in a given time period for a subsequent playing point.
The player constructs an FMP4 file based on the acquired media data, and then adds the FMP4 file to a Source buffer object corresponding to the MediaSource object, because the virtual URL is bound to the MediaSource object, when the player calls the code of the audio/video element to be executed, the audio/video element reads a new FMP4 file which is added continuously from the Source buffer object of the MediaSource object, decodes the new FMP4 file, and realizes the continuous playing of the media file.
Based on an optional processing flow of the method for switching the resolution of a media file provided by the foregoing embodiment of the present disclosure, an optional processing flow of the method for switching the resolution of a media file applied to a player embedded in a web page provided by the embodiment of the present disclosure is, as shown in fig. 13, including the following steps:
In step S601, the player receives a resolution switching event for the media file from the user.
Here, the resolution switching event is that a user requests the player to switch the display resolution of the played media file by clicking a mouse or by touch; if the display resolution of the media file is requested to be switched from standard definition to high definition.
Step S602, the player obtains the segmented media file with the target resolution of the continuous playing point from the server according to the playing point of the media file and the media file.
Step S603, the player sends the acquired segmented media file with the target resolution to the media resource extension interface.
Step S604, the media elements of the webpage are called through the media resource expansion interface to play the segmented media files with the target resolution.
Step S605, when the real-time playing point is in the playing time period of the segmented media file with the original resolution that is not cleared and a resolution switching event returning to the original resolution is received, the media element of the webpage is called through the media resource extension interface to play the cached segmented media file with the original resolution.
Based on the foregoing method for switching the resolution of a media file, an embodiment of the present disclosure further provides a device for switching the resolution of a media file, where a composition structure of the device 700 for switching the resolution of a media file, as shown in fig. 14, includes:
A clearing unit 701, configured to respond to a resolution switching event of a media file played by an embedded player in a web page, and clear a part of segmented media files with an original resolution cached in a media resource extension interface of the web page; the media files correspond to a plurality of segmented media files;
an obtaining unit 702, configured to obtain, according to a playing point of the media file and the media file, a segmented media file with a target resolution that is subsequent to the playing point;
A sending unit 703, configured to send the acquired segmented media file with the target resolution to the media resource extension interface, and call the media element of the web page through the media resource extension interface to play the media element.
In some embodiments, the clearing unit 701 is configured to reserve, in a buffer of the media resource extension interface, a segmented media file including the original resolution of the playback point, and,
And clearing the segmented media file of which the playing time does not comprise the original resolution of the playing point.
In some embodiments, the apparatus further comprises:
A detecting unit 704, configured to perform timeout detection after receiving a resolution switching event of a media file;
The clearing unit 701 is further configured to clear the segmented media file with the original resolution cached in the media resource extension interface of the web page when the detecting unit does not receive the resolution switching event returning to the original resolution within the timeout period.
in some embodiments, the apparatus further comprises: the playing unit 705 is configured to, when the real-time playing point is within the playing time period of the segmented media file with the original resolution that is not cleared, and a resolution switching event returning to the original resolution is received,
And calling the media elements of the webpage to play the cached segmented media files with the original resolution through the media resource expansion interface.
In some embodiments, the obtaining unit 702 is further configured to, when the real-time playing point is in the playing time period of the segmented media file with the original resolution that is not cleared, and a resolution switching event returning to the original resolution is received, invoke, through the media resource extension interface, the media element of the web page to play the cached segmented media file with the original resolution.
in some embodiments, the obtaining unit 702 is further configured to determine, when the media file is in a non-streaming media file format, two key frames that are subsequent to the playing point in the media file with the target resolution based on the media information of the media file with the target resolution;
Requesting media data between the two key frames in the media file at the target resolution;
And packaging the requested media data and metadata correspondingly calculated according to the requested media data into a segmented media file container to obtain a segmented media file with a target resolution.
In some embodiments, when the play point is reached by continuous play,
The first key frame of the two key frames is: adding the first key frame after the playing end time of the segmented media file of the media source in the media resource expansion interface;
The second key frame of the two key frames is: the second key frame is decoded later than the first key frame.
In some embodiments, when the play point is reached by jumping,
The first key frame of the two key frames is: a first key frame in the media file with a decoding time before the playing point;
The second key frame of the two key frames is: key frames in the media file that are decoded later than the first key frame.
In some embodiments, the obtaining unit 702 is configured to, when two key frames succeeding the playing point in the media file with the target resolution are determined,
Determining the offset and the capacity of a video frame between the two key frames and the offset and the capacity of an audio frame aligned with the video frame in the media file according to the media information identified from the media file with the target resolution;
Determining an offset and a capacity of a target interval according to the determined offset and capacity, wherein the target interval comprises the video frame and the audio frame;
And requesting the media data positioned in the target interval in the media file with the target resolution.
The embodiment of the present disclosure further provides a storage medium, where the storage medium stores computer-executable instructions, and the computer-executable instructions are used to execute the method for switching the resolution of the media file.
In summary, the above embodiments of the present disclosure have the following advantages:
1. when a resolution switching event occurs to a media file played by an embedded player in a webpage, removing a part of segmented media files with the original resolution cached in a media resource expansion interface of the webpage; the occupation of the buffer space is reduced, and the processing speed of the player is improved.
2. when a given time interval of the media file needs to be played, only the media data of a given time needs to be extracted from the media file in the non-streaming media format and packaged into the segmented media file which can be independently decoded, and by the mode, on one hand, the limitation that the non-streaming media format file can be independently played after being completely downloaded is overcome, and the playing real-time performance is good; on the other hand, because the segmented media file is only required to be constructed for a given time period, rather than the complete media file is converted into the streaming media format in advance, the conversion delay is small, and therefore the segmented media file does not need to be stored in advance, the original media file does not occupy additional storage space, and the occupation of the storage space is obviously reduced.
3. the media data in the media file in the non-streaming media format is converted into the segmented media file, and the segmented media file is sent to the media element of the webpage for decoding and playing through the media source expansion interface of the webpage, so that the player can play the media file in the non-streaming media format through the embedded webpage, and the limitation that the file in the non-streaming media packaging format can be independently played after being completely downloaded is overcome.
4. The player acquires partial media data among the key frames of the media file, and the control of loading the media data in the process of playing the media file is realized.
5. The segmented media file obtained by encapsulation is based on partial media data of the obtained media file, but not all data of the media file, so that conversion delay is small, pre-storage is not needed, no additional storage space is occupied except for the original media file, occupation of the storage space is remarkably reduced, black screen or blockage can not occur when resolution ratio switching is carried out in the watching process of a user, and instantaneity of resolution ratio switching is improved.
6. The media elements of the webpage acquire the segmented media file based on the virtual address for decoding and playing, and not acquire and play the media data based on the real address of the media file, so that the real address of the MP4 file is protected.
The above description is only for the specific embodiments of the present disclosure, but the scope of the present disclosure is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present disclosure, and all the changes or substitutions should be covered within the scope of the present disclosure. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (20)

1. A method for switching resolution of a media file, comprising:
Responding to a resolution switching event of a media file played by an embedded player in a webpage, and clearing a part of segmented media files with original resolution cached in a media resource expansion interface of the webpage;
The media files correspond to a plurality of segmented media files;
Acquiring a segmented media file with a target resolution ratio continuing the playing point according to the playing point of the media file and the media file;
And sending the acquired segmented media file with the target resolution to the media resource expansion interface, and calling the media elements of the webpage for playing through the media resource expansion interface.
2. the method of claim 1, wherein the clearing the partially segmented media file of the original resolution cached in the media resource extension interface of the web page comprises:
in a cache of the media asset extension interface, retaining a segmented media file comprising the original resolution of the playback point, and,
And clearing the segmented media file of which the playing time does not comprise the original resolution of the playing point.
3. The method of claim 1, further comprising:
after receiving a resolution switching event of the media file, performing overtime detection;
And when the resolution switching event returning to the original resolution is not received within the overtime, the segmented media file of the original resolution cached in the media resource expansion interface of the webpage is cleared.
4. The method of claim 1, further comprising:
when the real-time playing point is in the playing period of the segmented media file with the original resolution which is not cleared and a resolution switching event for returning to the original resolution is received,
and calling the media elements of the webpage to play the cached segmented media files with the original resolution through the media resource expansion interface.
5. the method of claim 1, wherein obtaining the segmented media file of the target resolution succeeding the playback point comprises:
When the media file is in a non-streaming media file format,
Determining two key frames which are continuous with the playing point in the media file with the target resolution ratio based on the media information of the media file with the target resolution ratio;
requesting media data between the two key frames in the media file at the target resolution;
And packaging the requested media data and metadata correspondingly calculated according to the requested media data into a segmented media file container to obtain a segmented media file with a target resolution.
6. The method of claim 5,
When the playing point is reached by means of continuous playing,
the first key frame of the two key frames is: adding the first key frame after the playing end time of the segmented media file of the media source in the media resource expansion interface;
The second key frame of the two key frames is: the second key frame is decoded later than the first key frame.
7. the method of claim 5,
When the play point is reached by jumping,
The first key frame of the two key frames is: a first key frame in the media file with a decoding time before the playing point;
The second key frame of the two key frames is: key frames in the media file that are decoded later than the first key frame.
8. the method of claim 5, further comprising:
when two key frames succeeding the playback point in the media file of the target resolution are determined,
Determining the offset and the capacity of a video frame between the two key frames and the offset and the capacity of an audio frame aligned with the video frame in the media file according to the media information identified from the media file with the target resolution;
determining an offset and a capacity of a target interval according to the determined offset and capacity, wherein the target interval comprises the video frame and the audio frame;
and requesting the media data positioned in the target interval in the media file with the target resolution.
9. the method of claim 5, wherein encapsulating the requested media data and metadata correspondingly computed from the requested media data into a segmented media file container comprises:
Filling data representing the type and compatibility of the segmented media file into a file type container of the segmented media file;
Populating metadata representing a file level of the segmented media file into a metadata container of the segmented media file;
and correspondingly filling the extracted media data and the metadata describing the media data into a media data container and a metadata container at a segmentation level in a segmentation container of the segmented media file.
10. an apparatus for switching a resolution of a media file, comprising:
The clearing unit is used for responding to a resolution switching event of a media file played by an embedded player in a webpage and clearing a part of segmented media files with original resolution cached in a media resource expansion interface of the webpage; the media files correspond to a plurality of segmented media files;
An obtaining unit, configured to obtain, according to a playing point of the media file and the media file, a segmented media file with a target resolution that is subsequent to the playing point;
and the sending unit is used for sending the acquired segmented media file with the target resolution to the media resource expansion interface and calling the media elements of the webpage to play through the media resource expansion interface.
11. The apparatus of claim 10, wherein the clearing unit is configured to reserve a segmented media file including the original resolution of the playback point in a buffer of the media resource extension interface, and,
and clearing the segmented media file of which the playing time does not comprise the original resolution of the playing point.
12. The apparatus of claim 10, further comprising:
the detection unit is used for carrying out overtime detection after receiving the resolution switching event of the media file;
The clearing unit is further configured to clear the segmented media file with the original resolution cached in the media resource extension interface of the web page when the detection unit does not receive the resolution switching event returning to the original resolution within the timeout period.
13. The apparatus of claim 10, further comprising:
A playing unit, for when the real-time playing point is in the playing time interval of the segmented media file with original resolution not cleared and a resolution switching event returning to the original resolution is received,
and calling the media elements of the webpage to play the cached segmented media files with the original resolution through the media resource expansion interface.
14. The apparatus of claim 10,
The obtaining unit is further configured to, when the media file is in a non-streaming media file format,
determining two key frames which are continuous with the playing point in the media file with the target resolution ratio based on the media information of the media file with the target resolution ratio;
requesting media data between the two key frames in the media file at the target resolution;
And packaging the requested media data and metadata correspondingly calculated according to the requested media data into a segmented media file container to obtain a segmented media file with a target resolution.
15. The apparatus of claim 14, wherein when the playback point is reached by continuous playback,
the first key frame of the two key frames is: adding the first key frame after the playing end time of the segmented media file of the media source in the media resource expansion interface;
The second key frame of the two key frames is: the second key frame is decoded later than the first key frame.
16. the apparatus of claim 14, wherein when the playpoint is reached by jumping,
The first key frame of the two key frames is: a first key frame in the media file with a decoding time before the playing point;
the second key frame of the two key frames is: key frames in the media file that are decoded later than the first key frame.
17. The apparatus of claim 14, wherein the obtaining unit is further configured to, when two key frames following the playback point in the media file with the target resolution are determined,
Determining the offset and the capacity of a video frame between the two key frames and the offset and the capacity of an audio frame aligned with the video frame in the media file according to the media information identified from the media file with the target resolution;
determining an offset and a capacity of a target interval according to the determined offset and capacity, wherein the target interval comprises the video frame and the audio frame;
And requesting the media data positioned in the target interval in the media file with the target resolution.
18. The apparatus according to claim 14, wherein the obtaining unit is further configured to fill data indicating the type and compatibility of the segmented media file into a file type container of the segmented media file;
populating metadata representing a file level of the segmented media file into a metadata container of the segmented media file;
And correspondingly filling the extracted media data and the metadata describing the media data into a media data container and a metadata container at a segmentation level in a segmentation container of the segmented media file.
19. An apparatus for switching a resolution of a media file, comprising:
A memory for storing executable instructions;
A processor for implementing the method of resolution switching of a media file according to any of claims 1 to 9 by executing executable instructions stored in the memory.
20. A storage medium having stored therein executable instructions for performing the method of switching resolution of a media file according to any one of claims 1 to 9.
CN201810532261.6A 2018-05-29 2018-05-29 Resolution switching method and device of media file and storage medium Pending CN110545461A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810532261.6A CN110545461A (en) 2018-05-29 2018-05-29 Resolution switching method and device of media file and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810532261.6A CN110545461A (en) 2018-05-29 2018-05-29 Resolution switching method and device of media file and storage medium

Publications (1)

Publication Number Publication Date
CN110545461A true CN110545461A (en) 2019-12-06

Family

ID=68701494

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810532261.6A Pending CN110545461A (en) 2018-05-29 2018-05-29 Resolution switching method and device of media file and storage medium

Country Status (1)

Country Link
CN (1) CN110545461A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021248888A1 (en) * 2020-06-11 2021-12-16 上海哔哩哔哩科技有限公司 Web-end video playing method and apparatus, and computer device

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102521279A (en) * 2011-11-25 2012-06-27 Tcl集团股份有限公司 Playing method, playing system and player of streaming media files
CN102739627A (en) * 2011-04-14 2012-10-17 深圳市快播科技有限公司 Method and system for switching and playing video
CN102905188A (en) * 2012-11-01 2013-01-30 北京奇艺世纪科技有限公司 Video code stream switching method and device
CN105451098A (en) * 2014-08-15 2016-03-30 北京风行在线技术有限公司 Method and device for providing multimedia file
US9602819B2 (en) * 2011-01-31 2017-03-21 Apple Inc. Display quality in a variable resolution video coder/decoder system
CN106528455A (en) * 2016-10-28 2017-03-22 上海斐讯数据通信技术有限公司 Multimedia cache cleaning method and system for electronic terminal, and electronic terminal
CN107197371A (en) * 2016-03-15 2017-09-22 广州市动景计算机科技有限公司 The switching method and device of video definition

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9602819B2 (en) * 2011-01-31 2017-03-21 Apple Inc. Display quality in a variable resolution video coder/decoder system
CN102739627A (en) * 2011-04-14 2012-10-17 深圳市快播科技有限公司 Method and system for switching and playing video
CN102521279A (en) * 2011-11-25 2012-06-27 Tcl集团股份有限公司 Playing method, playing system and player of streaming media files
CN102905188A (en) * 2012-11-01 2013-01-30 北京奇艺世纪科技有限公司 Video code stream switching method and device
CN105451098A (en) * 2014-08-15 2016-03-30 北京风行在线技术有限公司 Method and device for providing multimedia file
CN107197371A (en) * 2016-03-15 2017-09-22 广州市动景计算机科技有限公司 The switching method and device of video definition
CN106528455A (en) * 2016-10-28 2017-03-22 上海斐讯数据通信技术有限公司 Multimedia cache cleaning method and system for electronic terminal, and electronic terminal

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021248888A1 (en) * 2020-06-11 2021-12-16 上海哔哩哔哩科技有限公司 Web-end video playing method and apparatus, and computer device

Similar Documents

Publication Publication Date Title
CN110545491B (en) Network playing method, device and storage medium of media file
CN110545466B (en) Webpage-based media file playing method and device and storage medium
CN110545456B (en) Synchronous playing method and device of media files and storage medium
CN110545483B (en) Method, device and storage medium for playing media file by switching resolution in webpage
CN110545490B (en) Media file conversion method, device and storage medium
CN110545479B (en) Loading control method and device for media playing and storage medium
US11025991B2 (en) Webpage playing method and device and storage medium for non-streaming media file
CN110545460B (en) Media file preloading method and device and storage medium
CN110545461A (en) Resolution switching method and device of media file and storage medium
CN110545463B (en) Play control method and device based on media file conversion and storage medium
CN110545471B (en) Playing control method and device based on offline conversion and storage medium
CN110545481B (en) Connection allocation method, device and storage medium in media playing process
CN110545468B (en) Media file playing method and device based on parameter encapsulation and storage medium
CN110545480A (en) Preloading control method and device of media file and storage medium
CN110545470A (en) Media file loading method and device and storage medium
CN110545464A (en) Media file resolution switching method and device and storage medium
CN110545467B (en) Media file loading control method, device and storage medium

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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20191206