一种视频播放方法及装置Method and device for playing video
本申请要求于2019年11月1日提交中国专利局、申请号为201911061090.4、发明名称为“一种视频播放方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on November 1, 2019, the application number is 201911061090.4, and the invention title is "a method and device for video playback", the entire content of which is incorporated into this application by reference .
技术领域Technical field
本申请涉及视频处理技术领域,特别是涉及一种视频播放方法及装置。This application relates to the technical field of video processing, and in particular to a video playback method and device.
背景技术Background technique
一些场景中,在从服务器获取视频数据之后,既可以通过用户客户端播放所获取的视频数据,也可以通过网页客户端,在网页中播放所获取的视频数据。In some scenarios, after the video data is obtained from the server, the obtained video data may be played through the user client, or the obtained video data may be played on the web page through the web client.
相关技术中,通过网页客户端,在网页中播放所获取的视频数据的方案为:通过浏览器的OCX(Object Linking and Embedding Control Extension,对象类别扩充组件)插件或NPAPI(Netscape Plugin Application Programming Interface,网景插件应用程序编程接口)插件,调用对应的用户客户端的视频播放模块,进而通过视频播放模块,在网页中播放所获取的视频数据。In related technologies, the solution for playing the acquired video data on the web page through the web client is: through the browser's OCX (Object Linking and Embedding Control Extension) plug-in or NPAPI (Netscape Plugin Application Programming Interface, Netscape plug-in application programming interface) plug-in, call the video playback module of the corresponding user client, and then play the acquired video data on the webpage through the video playback module.
但是,OCX插件或NPAPI插件在一些浏览器中可能存在无法使用的情况,这样,浏览器无法调用用户客户端的视频播放模块,导致在网页中无法播放所获取的视频数据。However, the OCX plug-in or NPAPI plug-in may be unusable in some browsers. In this way, the browser cannot call the video playback module of the user client, resulting in the inability to play the acquired video data on the web page.
发明内容Summary of the invention
本申请实施例的目的在于提供一种视频播放方法及装置,以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。具体技术方案如下:The purpose of the embodiments of the present application is to provide a video playback method and device, so as to improve the compatibility of the solution of playing the acquired video data on the webpage through the webpage client. The specific technical solutions are as follows:
本申请实施例提供了一种视频播放方法,应用于电子设备的网页客户端,方法包括:The embodiment of the application provides a video playback method, which is applied to a web client of an electronic device, and the method includes:
生成视频获取请求;Generate video acquisition request;
将视频获取请求发送至本地服务端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端,本地服务端用于为电子设备提供网络服务;Send the video acquisition request to the local server, so that the local server acquires the video to be processed according to the video acquisition request, decodes the video to be processed, and obtains multiple video frames, and sends the multiple video frames to the web client. The server is used to provide network services for electronic devices;
接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。Receive multiple video frames returned by the local server, and render multiple video frames.
可选的,在对多个视频帧进行渲染之前,方法还包括:Optionally, before rendering multiple video frames, the method further includes:
创建工作线程,工作线程为超级文本标记语言HTML5标准中的网页线程,工作线程包括一个或多个;Create a working thread. The working thread is a web page thread in the HTML5 standard of Hypertext Markup Language. The working thread includes one or more;
在工作线程中,创建离屏画布;In the working thread, create an off-screen canvas;
对多个视频帧进行渲染,包括:Render multiple video frames, including:
调用WebGL,在离屏画布中对多个视频帧进行渲染。Call WebGL to render multiple video frames in an off-screen canvas.
可选的,将视频获取请求发送至本地服务端,包括:Optionally, the video acquisition request is sent to the local server, including:
建立与本地服务端之间的websocket连接;Establish a websocket connection with the local server;
通过websocket连接,将视频获取请求发送至本地服务端;Through the websocket connection, the video acquisition request is sent to the local server;
接收本地服务端返回的解码后的待处理视频,包括:Receive the decoded to-be-processed video returned by the local server, including:
通过websocket连接,接收本地服务端返回的解码后的待处理视频。Through the websocket connection, receive the decoded to-be-processed video returned by the local server.
可选的,接收本地服务端返回的多个视频帧,对多个视频帧进行渲染,包括:Optionally, receiving multiple video frames returned by the local server, and rendering the multiple video frames, including:
接收本地服务端返回的多个视频帧;Receive multiple video frames returned by the local server;
将接收到的多个视频帧存入缓存区;Store the received multiple video frames in the buffer area;
根据视频播放参数,从缓存区中获取视频帧;Obtain video frames from the buffer area according to the video playback parameters;
对所获取的视频帧进行渲染。Render the acquired video frame.
可选的,对多个视频帧进行渲染之后,方法还包括:Optionally, after rendering multiple video frames, the method further includes:
获取每个视频帧对应的待叠加元素;Obtain the element to be superimposed corresponding to each video frame;
将待叠加元素叠加至每个渲染后的视频帧中,展示叠加后的视频画面。The elements to be superimposed are superimposed on each rendered video frame, and the superimposed video image is displayed.
可选的,在将视频获取请求发送至本地服务端之后,方法还包括:Optionally, after sending the video acquisition request to the local server, the method further includes:
根据用户发送的停止播放指令,生成视频暂停指令;Generate a video pause instruction according to the stop playback instruction sent by the user;
将视频暂停指令发送至本地服务端,以使本地服务端根据视频暂停指令,停止获取待处理视频,并停止对待处理视频进行解码。The video pause instruction is sent to the local server, so that the local server stops acquiring the video to be processed and stops decoding the video to be processed according to the video pause instruction.
本申请实施例还提供了一种视频播放方法,应用于电子设备的本地服务端,方法包括:The embodiment of the present application also provides a video playback method, which is applied to a local server of an electronic device, and the method includes:
接收电子设备的网页客户端发送的视频获取请求,并根据视频获取请求,获取待处理视频;Receive the video acquisition request sent by the web client of the electronic device, and acquire the to-be-processed video according to the video acquisition request;
对待处理视频进行解码,得到多个视频帧;Decode the video to be processed to obtain multiple video frames;
确定得到的多个视频帧的分辨率,根据分辨率,确定多个视频帧的数据传输格式;Determine the resolution of the multiple video frames obtained, and determine the data transmission format of the multiple video frames according to the resolution;
按照数据传输格式,将多个视频帧发送至网页客户端,以使网页客户端对多个视频帧进行渲染。According to the data transmission format, multiple video frames are sent to the web client, so that the web client renders the multiple video frames.
本申请实施例还提供了一种视频播放装置,应用于电子设备的网页客户端,装置包括:An embodiment of the application also provides a video playback device, which is applied to a web client of an electronic device, and the device includes:
生成模块,用于生成视频获取请求;The generation module is used to generate a video acquisition request;
发送模块,用于将视频获取请求发送至本地服务端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端,本地服务端用于为电子设备提供网络服务;The sending module is used to send the video acquisition request to the local server, so that the local server acquires the video to be processed according to the video acquisition request, decodes the video to be processed, obtains multiple video frames, and sends the multiple video frames to Web client, the local server is used to provide network services for electronic devices;
渲染模块,用于接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。The rendering module is used to receive multiple video frames returned by the local server and render multiple video frames.
可选的,渲染模块,还用于:Optionally, the rendering module is also used for:
创建工作线程,工作线程为超级文本标记语言HTML5标准中的网页线程,工作线程包括一个或多个;Create a working thread. The working thread is a web page thread in the HTML5 standard of Hypertext Markup Language. The working thread includes one or more;
在工作线程中,创建离屏画布;In the working thread, create an off-screen canvas;
调用WebGL,在离屏画布中对多个视频帧进行渲染。Call WebGL to render multiple video frames in an off-screen canvas.
可选的,发送模块,具体用于:Optionally, the sending module is specifically used for:
建立与本地服务端之间的websocket连接;Establish a websocket connection with the local server;
通过websocket连接,将视频获取请求发送至本地服务端;Through the websocket connection, the video acquisition request is sent to the local server;
渲染模块,还用于通过websocket连接,接收本地服务端返回的解码后的待处理视频。The rendering module is also used to connect through the websocket to receive the decoded to-be-processed video returned by the local server.
可选的,渲染模块,具体用于:Optionally, the rendering module is specifically used for:
接收本地服务端返回的多个视频帧;Receive multiple video frames returned by the local server;
将接收到的多个视频帧存入缓存区;Store the received multiple video frames in the buffer area;
根据视频播放参数,从缓存区中获取视频帧;Obtain video frames from the buffer area according to the video playback parameters;
对所获取的视频帧进行渲染。Render the acquired video frame.
可选的,渲染模块,还用于:Optionally, the rendering module is also used for:
获取每个视频帧对应的待叠加元素;Obtain the element to be superimposed corresponding to each video frame;
将待叠加元素叠加至每个渲染后的视频帧中,展示叠加后的视频画面。The elements to be superimposed are superimposed on each rendered video frame, and the superimposed video image is displayed.
可选的,生成模块,还用于在将视频获取请求发送至本地服务端之后,根据用户发送的停止播放指令,生成视频暂停指令;Optionally, the generating module is also used to generate a video pause instruction according to the stop playing instruction sent by the user after the video acquisition request is sent to the local server;
发送模块,还用于将视频暂停指令发送至本地服务端,以使本地服务端根据视频暂停指令,停止获取待处理视频,并停止对待处理视频进行解码。The sending module is also used to send the video pause instruction to the local server, so that the local server stops acquiring the video to be processed according to the video pause instruction, and stops decoding the video to be processed.
本申请实施例还提供了一种视频播放装置,应用于电子设备的本地服务端,装置包括:The embodiment of the present application also provides a video playback device, which is applied to a local server of an electronic device, and the device includes:
接收模块,用于接收电子设备的网页客户端发送的视频获取请求,并根据视频获取请求,获取待处理视频;The receiving module is used to receive the video acquisition request sent by the web client of the electronic device, and obtain the video to be processed according to the video acquisition request;
解码模块,用于对待处理视频进行解码,得到多个视频帧;The decoding module is used to decode the video to be processed to obtain multiple video frames;
确定模块,用于确定得到的多个视频帧的分辨率,根据分辨率,确定多个视频帧的数据传输格式;The determining module is used to determine the resolutions of the obtained multiple video frames, and determine the data transmission format of the multiple video frames according to the resolution;
发送模块,用于按照数据传输格式,将多个视频帧发送至网页客户端,以使网页客户端对多个视频帧进行渲染。The sending module is used to send multiple video frames to the web client according to the data transmission format, so that the web client renders the multiple video frames.
本申请实施例还提供了一种电子设备,包括处理器、通信接口、存储器和通信总线,其中,处理器,通信接口,存储器通过通信总线完成相互间的通信;An embodiment of the present application also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete mutual communication through the communication bus;
存储器,用于存放计算机程序;Memory, used to store computer programs;
处理器,用于执行存储器上所存放的程序时,实现上述任一所述的视频播放方法。The processor is used to implement any one of the above-mentioned video playback methods when executing the program stored in the memory.
本申请实施例还提供了一种计算机可读存储介质,计算机可读存储介质内存储有计算机程序,计算机程序被处理器执行时实现上述任一所述的视频播放方法。The embodiments of the present application also provide a computer-readable storage medium, and a computer program is stored in the computer-readable storage medium. When the computer program is executed by a processor, any one of the above-mentioned video playback methods is implemented.
本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述实施例中任一所述的视频播放方法。The embodiments of the present application also provide a computer program product containing instructions, which when run on a computer, cause the computer to execute the video playback method described in any of the above embodiments.
本申请实施例提供的视频播放方法及装置,可以应用于电子设备的网页客户端,首先,生成视频获取请求,然后,将视频获取请求发送至本地服务 端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端,其中,本地服务端用于为电子设备提供网络服务,进而,接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。这样,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。当然,实施本申请的任一产品或方法并不一定需要同时达到以上的所有优点。The video playback method and device provided in the embodiments of this application can be applied to the web client of an electronic device. First, a video acquisition request is generated, and then the video acquisition request is sent to the local server, so that the local server can obtain the video according to the video acquisition request. , Obtain the video to be processed, decode the video to be processed, obtain multiple video frames, and send the multiple video frames to the web client, where the local server is used to provide network services for electronic devices, and in turn, receive the local server The returned multiple video frames are used to render multiple video frames. In this way, the local server does not provide any interface-related functions, but only provides data and network services, which is conducive to the cross-platform migration of the local server, which can improve the compatibility of the program of playing the acquired video data on the web page through the web client. Sex. Of course, implementing any product or method of the present application does not necessarily need to achieve all the above advantages at the same time.
附图说明Description of the drawings
为了更清楚地说明本申请实施例和现有技术的技术方案,下面对实施例和现有技术中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to explain the embodiments of the present application and the technical solutions of the prior art more clearly, the following briefly introduces the drawings needed in the embodiments and the prior art. Obviously, the drawings in the following description are merely the present For some of the applied embodiments, those of ordinary skill in the art can obtain other drawings based on these drawings without creative work.
图1为本申请实施例提供的一种应用于电子设备的网页客户端的视频播放方法的流程示意图;FIG. 1 is a schematic flowchart of a video playback method applied to a web client of an electronic device according to an embodiment of the application;
图2为本申请实施例提供的视频播放方法中网页客户端与本地服务端的功能分布示意图;2 is a schematic diagram of the function distribution of the web client and the local server in the video playback method provided by the embodiment of the application;
图3为本申请实施例提供的一种应用于电子设备的本地服务端的视频播放方法的流程示意图;3 is a schematic flowchart of a video playback method applied to a local server of an electronic device according to an embodiment of the application;
图4为一种实现方式中,本申请实施例提供的视频播放方法中网页客户端与本地服务端之间的时序图;FIG. 4 is a timing diagram between a web client and a local server in the video playback method provided by an embodiment of the present application in an implementation manner;
图5为本申请实施例提供的一种应用于电子设备的网页客户端的视频播放装置的结构示意图;FIG. 5 is a schematic structural diagram of a video playback device applied to a web client of an electronic device according to an embodiment of the application;
图6为本申请实施例提供的一种应用于电子设备的本地服务端的视频播放装置的结构示意图;6 is a schematic structural diagram of a video playback device applied to a local server of an electronic device according to an embodiment of the application;
图7为本申请实施例提供的电子设备的结构示意图。FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做 出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of this application.
一些场景中,在从服务器获取视频数据之后,既可以通过用户客户端播放所获取的视频数据,也可以通过网页客户端,在网页中播放所获取的视频数据。In some scenarios, after the video data is obtained from the server, the obtained video data may be played through the user client, or the obtained video data may be played on the web page through the web client.
相关技术中,通过网页客户端,在网页中播放所获取的视频数据的方案为:通过浏览器的OCX插件或NPAPI插件,调用对应的用户客户端的视频播放模块,进而通过视频播放模块,在网页中播放所获取的视频数据。In related technologies, the scheme of playing the acquired video data on the webpage through the webpage client is: through the browser's OCX plug-in or NPAPI plug-in, call the video playback module of the corresponding user client, and then use the video playback module to display the video on the webpage. Play the acquired video data.
但是,OCX插件或NPAPI插件在一些浏览器中可能存在无法使用的情况,这样,浏览器无法调用用户客户端的视频播放模块,导致在网页中无法播放所获取的视频数据。However, the OCX plug-in or NPAPI plug-in may be unusable in some browsers. In this way, the browser cannot call the video playback module of the user client, resulting in the inability to play the acquired video data on the web page.
为了解决上述技术问题,本申请实施例提供了一种视频播放方法,该方法可以应用在电子设备的网页客户端。In order to solve the above-mentioned technical problems, embodiments of the present application provide a video playback method, which can be applied to a web client of an electronic device.
下面从总体上对本申请实施例提供的视频播放方法进行说明。The following describes the video playback method provided in the embodiments of the present application as a whole.
一种实现方式中,上述视频播放方法包括:In an implementation manner, the foregoing video playback method includes:
生成视频获取请求;Generate video acquisition request;
将视频获取请求发送至本地服务端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端;Send the video acquisition request to the local server, so that the local server acquires the video to be processed according to the video acquisition request, decodes the video to be processed, obtains multiple video frames, and sends the multiple video frames to the web client;
接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。Receive multiple video frames returned by the local server, and render multiple video frames.
由以上可见,本申请实施例提供的视频播放方法中,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that, in the video playback method provided by the embodiments of the present application, the local server does not provide any interface-related functions, but only provides data and network services, which is beneficial to the cross-platform migration of the local server, which can improve the access to the web client. The compatibility of the scheme for playing the acquired video data on the web page.
下面将通过具体的实施例,对本申请实施例提供的视频播放方法进行详细描述。The following will describe in detail the video playback method provided in the embodiments of the present application through specific embodiments.
如图1所示,为本申请实施例提供的视频播放方法的流程示意图,应用于电子设备的网页客户端,该方法包括如下步骤:As shown in FIG. 1, it is a schematic flowchart of a video playback method provided by an embodiment of this application, which is applied to a web client of an electronic device, and the method includes the following steps:
S101:生成视频获取请求。S101: Generate a video acquisition request.
举例而言,客户端可以根据用户的视频播放指令生成视频获取请求。比如,用户可以在网页客户端上打开预设界面,在预设界面中包括视频的列表,然后,用户可以从列表中选择某一视频,作为待播放视频,并通过点击该视频的播放按钮,发送对于该视频的视频播放指令,进而,客户端在接收到该视频播放指令之后,生成对于该视频的视频获取请求。For example, the client can generate a video acquisition request according to the user's video playback instruction. For example, the user can open the preset interface on the web client, and include a list of videos in the preset interface. Then, the user can select a video from the list as the video to be played, and by clicking the play button of the video, Send a video play instruction for the video, and further, after receiving the video play instruction, the client generates a video acquisition request for the video.
S102:将视频获取请求发送至本地服务端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端。S102: Send the video acquisition request to the local server, so that the local server acquires the video to be processed according to the video acquisition request, decodes the video to be processed, obtains multiple video frames, and sends the multiple video frames to the web client .
其中,本地服务端用于为电子设备(执行主体)提供网络服务,是一种运行在后台的程序。可以理解,其他电子设备无法访问本地服务端,只有当前运行在本电子设备(执行主体)上的应用可以访问本地服务端。Among them, the local server is used to provide network services for electronic devices (executors), and is a program running in the background. It can be understood that other electronic devices cannot access the local server, and only applications currently running on the electronic device (executor) can access the local server.
一种实现方式中,在将视频获取请求发送至本地服务端之前,可以预先建立与本地服务端之间的websocket(网络套接字)连接,然后,通过websocket连接,将视频获取请求发送至本地服务端,并且,本地服务端可以通过websocket连接返回解码后的待处理视频。In one implementation, before the video acquisition request is sent to the local server, a websocket (network socket) connection with the local server can be established in advance, and then the video acquisition request is sent to the local through the websocket connection The server, and the local server can return the decoded to-be-processed video through the websocket connection.
可以理解,webSocket使得网页客户端和本地服务端之间的数据交换变得更加简单,允许本地服务端主动向网页客户端推送数据,网页客户端和本地服务端只需要完成一次握手,两者之间就直接可以创建持久性的连接,并进行双向数据传输。It can be understood that webSocket makes the data exchange between the web client and the local server easier, allowing the local server to actively push data to the web client, and the web client and the local server only need to complete a handshake. You can directly create a persistent connection and perform two-way data transmission.
一种实现方式中,网页客户端可能会接收到用户的多个并发的视频播放指令,即,网页客户端生成了多个视频获取请求,需要并发播放多个视频的视频帧。在这种情况下,网页客户端需要针对每个视频,预先建立该视频与本地服务端之间的websocket连接,然后,通过该视频对应的websocket连接,将视频获取请求发送至本地服务端,并且,本地服务端可以通过视频对应的websocket连接返回解码后的待处理视频。也就是说,对于不同的视频而言,网页客户端与本地服务端之间的websocket连接是互相独立的。In an implementation manner, the web client may receive multiple concurrent video playback instructions from the user, that is, the web client generates multiple video acquisition requests and needs to play video frames of multiple videos concurrently. In this case, the web client needs to establish a websocket connection between the video and the local server in advance for each video, and then send the video acquisition request to the local server through the websocket connection corresponding to the video, and , The local server can return the decoded to-be-processed video through the websocket connection corresponding to the video. In other words, for different videos, the websocket connection between the web client and the local server is independent of each other.
这样,在多个视频并发播放时,多个视频的数据传输不会互相影响,即使其中一个视频数据传输错误,其他视频也可以正常进行数据传输。In this way, when multiple videos are played concurrently, the data transmission of multiple videos will not affect each other, and even if one of the video data is transmitted incorrectly, the other videos can also perform data transmission normally.
举例而言,本地服务端获取的待处理视频可以是待处理视频的文件,也 可以是待处理视频的码流。在视频获取请求中,可以包括待处理视频的URL(Uniform Resource Locator,统一资源定位符)地址,这样,本地服务端在获取到视频获取请求之后,可以根据待处理视频的URL地址,获取待处理视频。For example, the to-be-processed video obtained by the local server can be the file of the to-be-processed video or the code stream of the to-be-processed video. The video acquisition request can include the URL (Uniform Resource Locator) address of the video to be processed. In this way, after the local server receives the video acquisition request, it can obtain the URL address of the video to be processed according to the URL address of the video to be processed. video.
本地服务端按照相应的数据传输格式,将解码得到的多个视频帧发送至网页客户端,其中,数据传输格式可以由本地服务端确定。本地服务端在得到多个视频帧之后,可以进一步对得到的多个视频帧进行分析,确定每个视频帧的分辨率,进而,根据视频帧的分辨率,确定视频帧的数据传输格式,并按照所确定的数据传输格式,将多个视频帧发送至网页客户端。The local server sends the decoded multiple video frames to the web client according to the corresponding data transmission format, where the data transmission format can be determined by the local server. After obtaining multiple video frames, the local server can further analyze the obtained multiple video frames to determine the resolution of each video frame, and then determine the data transmission format of the video frame according to the resolution of the video frame, and According to the determined data transmission format, multiple video frames are sent to the web client.
举例而言,视频帧的数据传输格式可以包括YUV、JPEG(Joint Photographic Experts Group,联合图像专家小组)或PNG(Portable Network Graphics,便携式网络图形)等,其中,YUV格式的视频帧数据量较大,JPEG格式的视频帧数据量较小,但是,JPEG格式会损失视频帧的一部分信息。这样,当视频帧的分辨率较高时,可以按照JPEG格式将多个视频帧发送至网页客户端,从而减少数据传输量,减少数据传输超负荷的情况,而当视频帧的分辨率较低时,可以按照YUV格式将多个视频帧发送至网页客户端,尽可能保留视频帧中的信息。For example, the data transmission format of a video frame can include YUV, JPEG (Joint Photographic Experts Group), or PNG (Portable Network Graphics, portable network graphics), etc. Among them, the amount of video frame data in the YUV format is relatively large. , JPEG format has a small amount of video frame data, but JPEG format will lose part of the video frame information. In this way, when the resolution of the video frame is high, multiple video frames can be sent to the web client according to the JPEG format, thereby reducing the amount of data transmission and reducing the overload of data transmission, and when the resolution of the video frame is low At the same time, multiple video frames can be sent to the web client according to the YUV format, and the information in the video frames can be preserved as much as possible.
S103:接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。S103: Receive multiple video frames returned by the local server, and render the multiple video frames.
一种实现方式中,若网页客户端对应的浏览器支持OffscreenCanvas(离屏画布),那么,在对多个视频帧进行渲染之前,可以先创建Worker(工作线程),其中,Worker为HTML5(HyperText Markup Language 5.0,超级文本标记语言5.0)标准中的网页线程,工作线程包括一个或多个,可以实现网页客户端的多线程工作。In one implementation, if the browser corresponding to the web client supports OffscreenCanvas (off-screen canvas), then before rendering multiple video frames, you can create a Worker (worker thread), where Worker is HTML5 (HyperText Markup Language 5.0, Hypertext Markup Language 5.0) The webpage thread in the standard, the work thread includes one or more, which can realize the multi-threaded work of the webpage client.
然后,可以在Worker中,创建OffscreenCanvas,OffscreenCanvas是一种API(Application Programming Interface,应用程序接口),通过OffscreenCanvas,可以在Worker中调用Canvas(画布),从而使得网页客户端可以在Worker中加载Canvas,并操作Canvas显示图像,从而有效提升网页客户端的渲染性能。Then, you can create OffscreenCanvas in Worker. OffscreenCanvas is an API (Application Programming Interface). Through OffscreenCanvas, Canvas (canvas) can be called in Worker, so that web clients can load Canvas in Worker. And operate Canvas to display images, thereby effectively improving the rendering performance of the web client.
这样,在对多个视频帧进行渲染时,可以基于OffscreenCanvas,对多个视频帧进行渲染。比如,可以调用WebGL(Web Graphics Library,网络图形库),在OffscreenCanvas中对多个视频帧进行渲染。In this way, when rendering multiple video frames, multiple video frames can be rendered based on OffscreenCanvas. For example, you can call WebGL (Web Graphics Library) to render multiple video frames in OffscreenCanvas.
一种实现方式中,网页客户端可能会接收到用户的多个并发的视频播放指令,即,网页客户端生成了多个视频获取请求,需要并发播放多个视频的视频帧。在这种情况下,网页客户端需要针对每个视频,创建该视频对应的Worker,进而,可以在该视频对应的Worker中,创建该视频对应的OffscreenCanvas。也就是说,每个视频都有其唯一对应的Worker和OffscreenCanvas。In an implementation manner, the web client may receive multiple concurrent video playback instructions from the user, that is, the web client generates multiple video acquisition requests and needs to play video frames of multiple videos concurrently. In this case, the web client needs to create a Worker corresponding to the video for each video, and then, in the Worker corresponding to the video, create an OffscreenCanvas corresponding to the video. In other words, each video has its unique corresponding Worker and OffscreenCanvas.
这样,在多个视频并发播放时,多个视频之间不会互相影响,即使其中一个视频播放错误,其他视频也可以正常播放。In this way, when multiple videos are played concurrently, the multiple videos will not affect each other, and even if one of the videos is played incorrectly, the other videos can be played normally.
另一种实现方式中,若网页客户端对应的浏览器不支持OffscreenCanvas,那么,可以由主线程接收本地服务端返回的多个视频帧,并对多个视频帧进行渲染。In another implementation manner, if the browser corresponding to the web client does not support OffscreenCanvas, the main thread can receive multiple video frames returned by the local server, and render multiple video frames.
在本步骤中,接收本地服务端返回的解码后的待处理视频之后,可以先将接收到的多个视频帧存入缓存区,然后,根据视频播放参数,从缓存区中获取视频帧,进而对所获取的视频帧进行渲染。In this step, after receiving the decoded to-be-processed video returned by the local server, the received multiple video frames can be stored in the buffer area, and then the video frames are obtained from the buffer area according to the video playback parameters, and then Render the acquired video frame.
其中,视频播放参数可以是播放控制模块生成的,举例而言,播放控制模块可以从缓存区中按照视频帧率匀速获取视频帧,并将所获取的视频帧推送给音视频渲染模块进行渲染,以此做到流畅播放音视频的功能。比如,若视频的帧率为25FPS(Frame Per Second,每秒传输帧数),则播放控制模块以每40毫秒获取一帧的速度匀速获取视频帧。Among them, the video playback parameters may be generated by the playback control module. For example, the playback control module may obtain video frames from the buffer area at a uniform speed according to the video frame rate, and push the obtained video frames to the audio and video rendering module for rendering. In this way, the function of playing audio and video smoothly. For example, if the frame rate of the video is 25FPS (Frame Per Second, the number of frames transmitted per second), the playback control module acquires video frames at a constant rate at a rate of acquiring one frame every 40 milliseconds.
或者,视频播放参数也可以是从视频获取请求中解析得到的,举例而言,用户可以设定播放视频时的帧率,这样,在视频获取请求中可以携带用户设定的帧率,进而,可以按照用户设定的帧率获取视频帧。Alternatively, the video playback parameters can also be parsed from the video acquisition request. For example, the user can set the frame rate when playing the video. In this way, the video acquisition request can carry the frame rate set by the user, and further, The video frame can be obtained according to the frame rate set by the user.
另外,一种实现方式中,网页客户端还可以进行元素叠加,在对多个视频帧进行渲染之后,可以获取每个视频帧对应的待叠加元素,将待叠加元素叠加至每个渲染后的视频帧之上,展示叠加后的视频画面。In addition, in one implementation, the web client can also perform element superposition. After rendering multiple video frames, it can obtain the elements to be superimposed corresponding to each video frame, and superimpose the elements to be superimposed on each rendered Above the video frame, the superimposed video picture is displayed.
其中,待叠加元素可以是文字、图像、特效等等,可以是用户手动添加的元素,也可以按照预设规则叠加特定的元素,具体不做限定。通过元素叠加,可以使得向用户展示的视频画面更丰富。Among them, the elements to be superimposed can be text, images, special effects, etc., can be elements manually added by the user, or can be superimposed on specific elements according to preset rules, which are not specifically limited. Through element superposition, the video images displayed to users can be made richer.
当将视频获取请求发送至本地服务端并接收到用户发送的停止播放指令 时,网页客户端可以生成视频暂停指令,然后,将视频暂停指令发送至本地服务端,以使本地服务端根据视频暂停指令,停止获取待处理视频,并停止对待处理视频进行解码。这样,网页客户端就无法获取到本地服务端返回的视频帧,也就无法对视频帧进行渲染。从而停止了对视频的播放。When the video acquisition request is sent to the local server and the stop playback instruction sent by the user is received, the web client can generate a video pause instruction, and then send the video pause instruction to the local server to make the local server pause according to the video Instruction to stop obtaining the video to be processed, and stop decoding the video to be processed. In this way, the web client cannot obtain the video frame returned by the local server, and cannot render the video frame. Thus, the playback of the video is stopped.
进一步的,本地服务端可以向网页客户端返回停止结果,网页客户端在接收到本地服务端返回的停止结果之后,可以关闭工作线程和离屏画布,从而尽快减少资源占用率。Further, the local server can return a stop result to the web client. After receiving the stop result returned by the local server, the web client can close the work thread and off-screen canvas, thereby reducing resource occupancy as soon as possible.
在本申请实施例中,网页客户端与本地服务端的功能分布如图2所示,由网页客户端进行视频渲染、播放控制和元素叠加,由本地服务端通过websocket服务获取并读取待处理视频,对待处理视频进行解码等功能。In the embodiment of this application, the function distribution of the web client and the local server is shown in Figure 2. The web client performs video rendering, playback control, and element overlay, and the local server obtains and reads the to-be-processed video through the websocket service. , Functions such as decoding the video to be processed.
由以上可见,本申请实施例提供的视频播放方法中,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that, in the video playback method provided by the embodiments of the present application, the local server does not provide any interface-related functions, but only provides data and network services, which is beneficial to the cross-platform migration of the local server, which can improve the access to the web client. The compatibility of the scheme for playing the acquired video data on the web page.
如图3所示,为本申请实施例提供的视频播放方法的流程示意图,应用于电子设备的本地服务端,该方法包括如下步骤:As shown in FIG. 3, a schematic flowchart of a video playback method provided by an embodiment of this application is applied to a local server of an electronic device, and the method includes the following steps:
S301:接收电子设备的网页客户端发送的视频获取请求,并根据视频获取请求,获取待处理视频。S301: Receive a video acquisition request sent by a web client of the electronic device, and acquire a to-be-processed video according to the video acquisition request.
一种实现方式中,网页客户端可以预先建立与本地服务端之间的websocket连接,然后,通过websocket连接,将视频获取请求发送至本地服务端,并且,本地服务端可以通过websocket连接返回解码后的待处理视频。In one implementation, the web client can pre-establish a websocket connection with the local server, and then send the video acquisition request to the local server through the websocket connection, and the local server can return the decoded via the websocket connection Pending video.
可以理解,WebSocket使得网页客户端和本地服务端之间的数据交换变得更加简单,允许本地服务端主动向网页客户端推送数据,网页客户端和本地服务端只需要完成一次握手,两者之间就直接可以创建持久性的连接,并进行双向数据传输。It can be understood that WebSocket makes the data exchange between the web client and the local server easier, allowing the local server to actively push data to the web client, and the web client and the local server only need to complete a handshake. You can directly create a persistent connection and perform two-way data transmission.
一种实现方式中,网页客户端可能会接收到用户的多个并发的视频播放指令,即,网页客户端生成了多个视频获取请求,需要并发播放多个视频的视频帧。在这种情况下,网页客户端需要针对每个视频,预先建立该视频与 本地服务端之间的websocket连接,然后,通过该视频对应的websocket连接,将视频获取请求发送至本地服务端,并且,本地服务端可以通过视频对应的websocket连接返回解码后的待处理视频。也就是说,对于不同的视频而言,网页客户端与本地服务端之间的websocket连接是互相独立的。In an implementation manner, the web client may receive multiple concurrent video playback instructions from the user, that is, the web client generates multiple video acquisition requests and needs to play video frames of multiple videos concurrently. In this case, the web client needs to establish a websocket connection between the video and the local server in advance for each video, and then send the video acquisition request to the local server through the websocket connection corresponding to the video, and , The local server can return the decoded to-be-processed video through the websocket connection corresponding to the video. In other words, for different videos, the websocket connection between the web client and the local server is independent of each other.
这样,在多个视频并发播放时,多个视频的数据传输不会互相影响,即使其中一个视频数据传输错误,其他视频也可以正常进行数据传输。In this way, when multiple videos are played concurrently, the data transmission of multiple videos will not affect each other, and even if one of the video data is transmitted incorrectly, the other videos can also perform data transmission normally.
S302:对待处理视频进行解码,得到多个视频帧。S302: Decode the video to be processed to obtain multiple video frames.
举例而言,本地服务端获取的待处理视频可以是待处理视频的文件,也可以是待处理视频的码流。在视频获取请求中,可以包括待处理视频的URL(Uniform Resource Locator,统一资源定位符)地址,这样,本地服务端在获取到视频获取请求之后,可以根据待处理视频的URL地址,获取待处理视频。For example, the to-be-processed video obtained by the local server may be a file of the to-be-processed video, or it may be a code stream of the to-be-processed video. The video acquisition request can include the URL (Uniform Resource Locator) address of the video to be processed. In this way, after the local server receives the video acquisition request, it can obtain the URL address of the video to be processed according to the URL address of the video to be processed. video.
S303:确定得到的多个视频帧的分辨率,根据分辨率,确定多个视频帧的数据传输格式。S303: Determine the resolution of the obtained multiple video frames, and determine the data transmission format of the multiple video frames according to the resolution.
本地服务端按照相应的数据传输格式,将解码得到的多个视频帧发送至网页客户端,其中,数据传输格式可以由本地服务端确定。本地服务端在得到多个视频帧之后,可以进一步对得到的多个视频帧进行分析,确定每个视频帧的分辨率,进而,根据视频帧的分辨率,确定视频帧的数据传输格式,并按照所确定的数据传输格式,将多个视频帧发送至网页客户端。The local server sends the decoded multiple video frames to the web client according to the corresponding data transmission format, where the data transmission format can be determined by the local server. After obtaining multiple video frames, the local server can further analyze the obtained multiple video frames to determine the resolution of each video frame, and then determine the data transmission format of the video frame according to the resolution of the video frame, and According to the determined data transmission format, multiple video frames are sent to the web client.
举例而言,视频帧的数据传输格式可以包括YUV、JPEG或PNG等,其中,YUV格式的视频帧数据量较大,JPEG格式的视频帧数据量较小,但是,JPEG格式会损失视频帧的一部分信息。这样,当视频帧的分辨率较高时,可以按照JPEG格式将多个视频帧发送至网页客户端,从而减少数据传输量,减少数据传输超负荷的情况,而当视频帧的分辨率较低时,可以按照YUV格式将多个视频帧发送至网页客户端,尽可能保留视频帧中的信息。For example, the data transmission format of a video frame can include YUV, JPEG, or PNG. Among them, the amount of video frame data in the YUV format is larger, and the amount of video frame data in the JPEG format is smaller. However, the JPEG format will lose the amount of video frame data. Part of the information. In this way, when the resolution of the video frame is high, multiple video frames can be sent to the web client according to the JPEG format, thereby reducing the amount of data transmission and reducing the overload of data transmission, and when the resolution of the video frame is low At the same time, multiple video frames can be sent to the web client according to the YUV format, and the information in the video frames can be preserved as much as possible.
S304:按照数据传输格式,将多个视频帧发送至网页客户端,以使网页客户端对多个视频帧进行渲染。S304: Send multiple video frames to the web client according to the data transmission format, so that the web client renders the multiple video frames.
当接收到用户发送的停止播放指令之后,网页客户端可以生成视频暂停指令,然后,将视频暂停指令发送至本地服务端,以使本地服务端根据视频暂停指令,停止获取待处理视频,并停止对待处理视频进行解码。这样,网 页客户端就无法获取到本地服务端返回的视频帧,也就无法对视频帧进行渲染。从而停止了对视频的播放。After receiving the stop playback instruction sent by the user, the web client can generate a video pause instruction, and then send the video pause instruction to the local server, so that the local server stops acquiring the pending video according to the video pause instruction, and stops Decode the video to be processed. In this way, the web page client cannot obtain the video frame returned by the local server, and cannot render the video frame. Thus, the playback of the video is stopped.
进一步的,本地服务端可以向网页客户端返回停止结果,网页客户端在接收到本地服务端返回的停止结果之后,可以关闭工作线程和离屏画布,从而尽快减少资源占用率。Further, the local server can return a stop result to the web client. After receiving the stop result returned by the local server, the web client can close the work thread and off-screen canvas, thereby reducing resource occupancy as soon as possible.
由以上可见,本申请实施例提供的视频播放方法中,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that, in the video playback method provided by the embodiments of the present application, the local server does not provide any interface-related functions, but only provides data and network services, which is beneficial to the cross-platform migration of the local server, which can improve the access to the web client. The compatibility of the scheme for playing the acquired video data on the web page.
举例而言,如图4所示,为一种实现方式中,本申请实施例提供的视频播放方法中网页客户端与本地服务端之间的时序图。其中:For example, as shown in FIG. 4, it is a timing diagram between the web client and the local server in the video playback method provided in the embodiment of the present application in an implementation manner. among them:
S401:网页客户端获取用户发送的视频获取请求,创建工作线程,在工作线程中创建离屏画布,并建立与本地服务端之间的websocket连接。S401: The web client obtains the video obtaining request sent by the user, creates a working thread, creates an off-screen canvas in the working thread, and establishes a websocket connection with a local server.
S402:网页客户端将视频获取请求发送至本地服务端。S402: The web client sends the video acquisition request to the local server.
S403:本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧。S403: The local server obtains the video to be processed according to the video acquisition request, decodes the video to be processed, and obtains multiple video frames.
S404:本地服务端将多个视频帧发送至网页客户端。S404: The local server sends multiple video frames to the web client.
S405:网页客户端接收本地服务端返回的多个视频帧,将接收到的多个视频帧存入缓存区,并根据视频播放参数,从缓存区中获取视频帧,对所获取的视频帧进行渲染。S405: The web client receives multiple video frames returned by the local server, stores the received multiple video frames in the buffer area, and obtains the video frames from the buffer area according to the video playback parameters, and performs processing on the obtained video frames. Rendering.
S406:网页客户端接收用户发送的停止播放指令,生成视频暂停指令。S406: The web client receives the stop playing instruction sent by the user, and generates a video pause instruction.
S407:网页客户端将视频暂停指令发送至本地服务端。S407: The web client sends the video pause instruction to the local server.
S408:本地服务端根据视频暂停指令,停止获取待处理视频,并停止对待处理视频进行解码。S408: According to the video pause instruction, the local server stops acquiring the video to be processed, and stops decoding the video to be processed.
S409:本地服务端向网页客户端返回停止结果。S409: The local server returns a stop result to the web client.
S410:网页客户端关闭工作线程和离屏画布。S410: The web client closes the working thread and off-screen canvas.
由以上可见,本申请实施例提供的视频播放方法中,本地服务不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务的跨平台移植, 从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that in the video playback method provided by the embodiments of the present application, the local service does not provide any interface-related functions, but only provides data and network services, which is conducive to the cross-platform migration of local services, which can improve the Compatibility of the scheme for playing the acquired video data in the webpage.
如图5所示,本申请实施例还提供了一种视频播放装置,应用于电子设备的网页客户端,该装置包括:As shown in FIG. 5, an embodiment of the present application also provides a video playback device, which is applied to a web client of an electronic device, and the device includes:
生成模块501,用于生成视频获取请求;The generating module 501 is used to generate a video acquisition request;
发送模块502,用于将视频获取请求发送至本地服务端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端,本地服务端用于为电子设备提供网络服务;The sending module 502 is used to send the video acquisition request to the local server, so that the local server acquires the video to be processed according to the video acquisition request, decodes the video to be processed, obtains multiple video frames, and sends the multiple video frames To the web client, the local server is used to provide network services for electronic devices;
渲染模块503,用于接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。The rendering module 503 is configured to receive multiple video frames returned by the local server, and render the multiple video frames.
一种实现方式中,渲染模块503,还用于:In an implementation manner, the rendering module 503 is also used for:
创建工作线程,工作线程为超级文本标记语言HTML5标准中的网页线程,工作线程包括一个或多个;Create a working thread. The working thread is a web page thread in the HTML5 standard of Hypertext Markup Language. The working thread includes one or more;
在工作线程中,创建离屏画布;In the working thread, create an off-screen canvas;
基于离屏画布,对多个视频帧进行渲染。Based on off-screen canvas, multiple video frames are rendered.
一种实现方式中,渲染模块503,还用于:In an implementation manner, the rendering module 503 is also used for:
调用WebGL,在离屏画布中对多个视频帧进行渲染。Call WebGL to render multiple video frames in an off-screen canvas.
一种实现方式中,发送模块502,具体用于:In an implementation manner, the sending module 502 is specifically used for:
建立与本地服务端之间的websocket连接;Establish a websocket connection with the local server;
通过websocket连接,将视频获取请求发送至本地服务端;Through the websocket connection, the video acquisition request is sent to the local server;
渲染模块503,还用于通过websocket连接,接收本地服务端返回的解码后的待处理视频。The rendering module 503 is also used for receiving the decoded to-be-processed video returned by the local server through a websocket connection.
一种实现方式中,渲染模块503,具体用于:In one implementation manner, the rendering module 503 is specifically used for:
接收本地服务端返回的多个视频帧;Receive multiple video frames returned by the local server;
将接收到的多个视频帧存入缓存区;Store the received multiple video frames in the buffer area;
根据视频播放参数,从缓存区中获取视频帧;Obtain video frames from the buffer area according to the video playback parameters;
对所获取的视频帧进行渲染。Render the acquired video frame.
一种实现方式中,渲染模块503,还用于:In an implementation manner, the rendering module 503 is also used for:
获取每个视频帧对应的待叠加元素;Obtain the element to be superimposed corresponding to each video frame;
将待叠加元素叠加至每个渲染后的视频帧中,展示叠加后的视频画面。The elements to be superimposed are superimposed on each rendered video frame, and the superimposed video image is displayed.
一种实现方式中,生成模块501,还用于在将视频获取请求发送至本地服务端之后,根据用户发送的停止播放指令,生成视频暂停指令;In an implementation manner, the generating module 501 is further configured to generate a video pause instruction according to a stop playing instruction sent by the user after the video acquisition request is sent to the local server;
发送模块502,还用于将视频暂停指令发送至本地服务端,以使本地服务端根据视频暂停指令,停止获取待处理视频,并停止对待处理视频进行解码。The sending module 502 is also used to send the video pause instruction to the local server, so that the local server stops acquiring the video to be processed according to the video pause instruction, and stops decoding the video to be processed.
由以上可见,本申请实施例提供的视频播放装置中,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that in the video playback device provided by the embodiment of the present application, the local server does not provide any interface-related functions, but only provides data and network services, which is beneficial to the cross-platform migration of the local server, which can improve the accessibility of the web client. The compatibility of the scheme for playing the acquired video data on the web page.
如图6所示,本申请实施例还提供了一种视频播放装置,应用于电子设备的本地服务端,该装置包括:As shown in FIG. 6, an embodiment of the present application also provides a video playback device, which is applied to a local server of an electronic device, and the device includes:
接收模块601,用于接收电子设备的网页客户端发送的视频获取请求,并根据视频获取请求,获取待处理视频;The receiving module 601 is configured to receive a video acquisition request sent by a web client of an electronic device, and obtain a video to be processed according to the video acquisition request;
解码模块602,用于对待处理视频进行解码,得到多个视频帧;The decoding module 602 is configured to decode the video to be processed to obtain multiple video frames;
确定模块603,用于确定得到的多个视频帧的分辨率,根据分辨率,确定多个视频帧的数据传输格式;The determining module 603 is configured to determine the resolution of the obtained multiple video frames, and determine the data transmission format of the multiple video frames according to the resolution;
发送模块604,用于按照数据传输格式,将多个视频帧发送至网页客户端,以使网页客户端对多个视频帧进行渲染。The sending module 604 is configured to send multiple video frames to the web client according to the data transmission format, so that the web client renders the multiple video frames.
由以上可见,本申请实施例提供的视频播放装置中,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that in the video playback device provided by the embodiment of the present application, the local server does not provide any interface-related functions, but only provides data and network services, which is beneficial to the cross-platform migration of the local server, which can improve the accessibility of the web client. The compatibility of the scheme for playing the acquired video data on the web page.
本申请实施例还提供了一种电子设备,如图7所示,包括处理器701、通信接口702、存储器703和通信总线704,其中,处理器701,通信接口702,存储器703通过通信总线704完成相互间的通信,An embodiment of the present application also provides an electronic device, as shown in FIG. 7, including a processor 701, a communication interface 702, a memory 703, and a communication bus 704. The processor 701, the communication interface 702, and the memory 703 pass through the communication bus 704. Complete the communication between each other,
存储器703,用于存放计算机程序;The memory 703 is used to store computer programs;
处理器701,用于执行存储器703上所存放的程序。The processor 701 is configured to execute a program stored in the memory 703.
其中,存储器703上所存放的程序可以实现如下步骤:Among them, the program stored in the memory 703 can implement the following steps:
生成视频获取请求;Generate video acquisition request;
将视频获取请求发送至本地服务端,以使本地服务端根据视频获取请求,获取待处理视频,对待处理视频进行解码,得到多个视频帧,并将多个视频帧发送至网页客户端;Send the video acquisition request to the local server, so that the local server acquires the video to be processed according to the video acquisition request, decodes the video to be processed, obtains multiple video frames, and sends the multiple video frames to the web client;
接收本地服务端返回的多个视频帧,对多个视频帧进行渲染。Receive multiple video frames returned by the local server, and render multiple video frames.
或者,存储器703上所存放的程序还可以实现如下步骤:Alternatively, the program stored in the memory 703 may also implement the following steps:
接收电子设备的网页客户端发送的视频获取请求,并根据视频获取请求,获取待处理视频;Receive the video acquisition request sent by the web client of the electronic device, and acquire the to-be-processed video according to the video acquisition request;
对待处理视频进行解码,得到多个视频帧;Decode the video to be processed to obtain multiple video frames;
确定得到的多个视频帧的分辨率,根据分辨率,确定多个视频帧的数据传输格式;Determine the resolution of the multiple video frames obtained, and determine the data transmission format of the multiple video frames according to the resolution;
按照数据传输格式,将多个视频帧发送至网页客户端,以使网页客户端对多个视频帧进行渲染。According to the data transmission format, multiple video frames are sent to the web client, so that the web client renders the multiple video frames.
由以上可见,本申请实施例提供的电子设备中,本地服务端不提供任何界面相关的功能,仅提供数据和网络服务,有利于本地服务端的跨平台移植,从而可以提高通过网页客户端,在网页中播放所获取的视频数据的方案的兼容性。It can be seen from the above that in the electronic equipment provided by the embodiments of the present application, the local server does not provide any interface-related functions, but only provides data and network services, which is beneficial to the cross-platform migration of the local server, thereby improving the access to the web client. Compatibility of the scheme for playing the acquired video data in the webpage.
上述电子设备提到的通信总线可以是外设部件互连标准(Peripheral Component Interconnect,PCI)总线或扩展工业标准结构(Extended Industry Standard Architecture,EISA)总线等。该通信总线可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
通信接口用于上述电子设备与其他设备之间的通信。The communication interface is used for communication between the above-mentioned electronic device and other devices.
存储器可以包括随机存取存储器(Random Access Memory,RAM),也可以包括非易失性存储器(Non-Volatile Memory,NVM),例如至少一个磁盘存储器。可选的,存储器还可以是至少一个位于远离前述处理器的存储装置。The memory may include random access memory (Random Access Memory, RAM), and may also include non-volatile memory (Non-Volatile Memory, NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located far away from the foregoing processor.
上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(Digital Signal Processing,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (Network Processor, NP), etc.; it may also be a digital signal processor (Digital Signal Processing, DSP), a dedicated integrated Circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
在本申请提供的又一实施例中,还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述实施例中任一所述的视频播放方法。In yet another embodiment provided in this application, a computer-readable storage medium is also provided. The computer-readable storage medium stores instructions that, when run on a computer, cause the computer to execute any of the above-mentioned embodiments. The described video playback method.
在本申请提供的又一实施例中,还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述实施例中任一所述的视频播放方法。In another embodiment provided in this application, a computer program product containing instructions is also provided, which when running on a computer, causes the computer to execute the video playback method described in any of the above embodiments.
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行计算机程序指令时,全部或部分地产生按照本申请实施例的流程或功能。计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘Solid State Disk(SSD))等。In the above-mentioned embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented by software, it can be implemented in the form of a computer program product in whole or in part. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. Computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions may be transmitted from a website, computer, server, or data center through a cable (such as Coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) to transmit to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center integrated with one or more available media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、 “包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括要素的过程、方法、物品或者设备中还存在另外的相同要素。It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply one of these entities or operations. There is any such actual relationship or order between. Moreover, the terms "include", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes those that are not explicitly listed Other elements of, or also include elements inherent to this process, method, article or equipment. Without more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other identical elements in the process, method, article, or equipment that includes the element.
本说明书中的各个实施例均采用相关的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于装置实施例、电子设备实施例以及存储介质实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。The various embodiments in this specification are described in a related manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the device embodiment, the electronic device embodiment, and the storage medium embodiment, since they are basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiment.
以上仅为本申请的较佳实施例而已,并非用于限定本申请的保护范围。凡在本申请的精神和原则之内所作的任何修改、等同替换、改进等,均包含在本申请的保护范围内。The above are only preferred embodiments of the present application, and are not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application are all included in the protection scope of this application.