jsmpeg 全屏_jsmpeg: MPEG1 Video Decoder in JavaScript

JSMpeg – MPEG1 Video & MP2 Audio Decoder in JavaScript

JSMpeg is a Video Player written in JavaScript. It consists of an MPEG-TS demuxer, MPEG1 video & MP2 audio decoders, WebGL & Canvas2D renderers and WebAudio sound output. JSMpeg can load static videos via Ajax and allows low latency streaming (~50ms) via WebSockets.

JSMpeg can decode 720p Video at 30fps on an iPhone 5S, works in any modern browser (Chrome, Firefox, Safari, Edge) and comes in at just 20kb gzipped.

Using it can be as simple as this:

Some more info and demos: jsmpeg.com

Usage

A JSMpeg video player can either be created in HTML using the CSS class jsmpeg for the container:

or by directly calling the JSMpeg.Player() constructor in JavaScript:

var player = new JSMpeg.Player(url [, options]);

Note that using the HTML Element (internally JSMpeg.VideoElement) provides some features on top of JSMpeg.Player. Namely a SVG pause/play button and the ability to "unlock" audio on iOS devices.

The url argument accepts a URL to an MPEG .ts file or a WebSocket server (ws://...).

The options argument supports the following properties:

canvas – the HTML Canvas elment to use for video rendering. If none is given, the renderer will create its own Canvas element.

loop – whether to loop the video (static files only). Default true.

autoplay - whether to start playing immediately (static files only). Default false.

audio - whether to decode audio. Default true.

video - whether to decode video. Default true.

poster – URL to an image to use as the poster to show before the video plays.

pauseWhenHidden – whether to pause playback when the tab is inactive. Default true. Note that browsers usually throttle JS in inactive tabs anyway.

disableGl - whether to disable WebGL and always use the Canvas2D renderer. Default false.

preserveDrawingBuffer – whether the WebGL context is created with preserveDrawingBuffer - necessary for "screenshots" via canvas.toDataURL(). Default false.

progressive - whether to load data in chunks (static files only). When enabled, playback can begin before the whole source has been completely loaded. Default true.

throttled - when using progressive, whether to defer loading chunks when they're not needed for playback yet. Default true.

chunkSize - when using progressive, the chunk size in bytes to load at a time. Default 1024*1024 (1mb).

decodeFirstFrame - whether to decode and display the first frame of the video. Useful to set

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
- `class Seq2Seq(nn.Module):`:定义一个名为 Seq2Seq 的类,继承自 nn.Module 类。 - `def __init__(self,encoder_embedding_num,encoder_hidden_num,en_corpus_len,decoder_embedding_num,decoder_hidden_num,ch_corpus_len):`:定义 Seq2Seq 类的初始化方法,接收六个参数。 - `super().__init__():`:调用父类 nn.Module 的初始化方法。 - `self.encoder = Encoder(encoder_embedding_num,encoder_hidden_num,en_corpus_len)`: 创建一个 Encoder 对象,并将其保存在 Seq2Seq 类的 encoder 属性中。 - `self.decoder = Decoder(decoder_embedding_num,decoder_hidden_num,ch_corpus_len)`: 创建一个 Decoder 对象,并将其保存在 Seq2Seq 类的 decoder 属性中。 - `self.classifier = nn.Linear(decoder_hidden_num,ch_corpus_len)`: 创建一个线性层对象,将其保存在 Seq2Seq 类的 classifier 属性中。 - `self.cross_loss = nn.CrossEntropyLoss()`: 创建一个交叉熵损失函数对象,将其保存在 Seq2Seq 类的 cross_loss 属性中。 - `def forward(self,en_index,ch_index):`:定义 Seq2Seq 类的前向传播方法,接收两个参数。 - `decoder_input = ch_index[:,:-1]`: 将目标序列 ch_index 去掉最后一个元素,并赋值给 decoder_input。 - `label = ch_index[:,1:]`: 将目标序列 ch_index 去掉第一个元素,并赋值给 label。 - `encoder_hidden = self.encoder(en_index)`: 通过调用 Encoder 对象的 __call__ 方法,将源序列 en_index 作为输入,得到编码器的隐状态,并将其赋值给 encoder_hidden。 - `decoder_output,_ = self.decoder(decoder_input,encoder_hidden)`: 通过调用 Decoder 对象的 __call__ 方法,将 decoder_input 和 encoder_hidden 作为输入,得到解码器的输出和隐状态,并将输出赋值给 decoder_output。 - `pre = self.classifier(decoder_output)`: 将 decoder_output 作为输入,通过调用线性层对象 self.classifier 得到预测值 pre。 - `loss = self.cross_loss(pre.reshape(-1,pre.shape[-1]),label.reshape(-1))`: 将 pre 和 label 通过交叉熵损失函数计算损失值 loss。 - `return loss`: 返回损失值 loss。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值