资讯专栏INFORMATION COLUMN

在手机web中播放视频(使用js,不使用video标签,支持直播)

galois / 1851人阅读

摘要:主要原理是使用链接。是中解析视频,并把内容画在画布上。目前发现的不足无法播放声音,只能播放视频。视频文件只支持格式的视频目前版本支持视频格式,似乎是不支持了,官方建议用来转格式。

主要原理是使用 jsmpeg(Github链接) 。

jsmpeg是js中解析mpeg视频,并把内容画在画布上。

这篇文章是记录jsmpeg怎么用的。

目前发现jsmpeg的不足

无法播放声音,只能播放视频。(2018年更新,官方已解决该问题)

在苹果和性能低的安卓中卡顿严重(iPhone7有略微卡顿,部分2016年安卓旗舰机不卡,现在终于相信有安卓能秒苹果了)

目前(2018年)版本使用ts格式的视频,相同质量的视频大小差不多是mp4的两倍,太占流量了

缺少许多事件

解决不足

audio播放

无法解决,我本来想自己开启webgl,结果看到jsmpeg就是用的webgl,就是说他自己已经解决过了的。随着大家手机的升级,已经不卡了

也无法解决,只能在体积和可操作性上做取舍了

我自己增加了几个事件:https://gitee.com/haua/jsmpeg...

视频源 直播流

jsmpeg支持直播流,但是我还没研究,所以只是先提一下,先不深入。

视频文件

jsmpeg只支持mpeg格式的视频(目前2018版本支持ts视频格式,似乎是不支持mpeg了?),jsmpeg官方建议用ffmpeg来转格式。ffmpeg下载地址

从把视频转成mpg格式(转出的视频无音频,且应该是支持从许多种格式转过来的,我暂时只试过从mp4转)
./ffmpeg -i video.mp4 -f mpeg1video -vf "crop=iw-mod(iw,2):ih-mod(ih,2)" -b 0 video.mpg

从视频中提取音频(上面说过jsmpeg不能播声音,所以声音要多带带弄出来)
./ffmpeg -i video.mp4 -f mp3 -vn video.mp3

ffmpeg用法记录
Print help / information / capabilities:
-L show license
-h topic show help
-? topic show help
-help topic show help
--help topic show help
-version show version
-buildconf show build configuration
-formats show available formats
-devices show available devices
-codecs show available codecs
-decoders show available decoders
-encoders show available encoders
-bsfs show available bit stream filters
-protocols show available protocols
-filters show available filters
-pix_fmts show available pixel formats
-layouts show standard channel layouts
-sample_fmts show available audio sample formats
-colors show available color names
-sources device list sources of the input device
-sinks device list sinks of the output device
-hwaccels show available HW acceleration methods

Global options (affect whole program instead of just one file:
-loglevel loglevel set logging level
-v loglevel set logging level
-report generate a report
-max_alloc bytes set maximum size of a single allocated block
-y overwrite output files
-n never overwrite output files
-ignore_unknown Ignore unknown stream types
-stats print progress report during encoding
-max_error_rate ratio of errors (0.0: no errors, 1.0: 100% error maximum error rate
-bits_per_raw_sample number set the number of bits per raw sample
-vol volume change audio volume (256=normal)

Per-file main options:
-f fmt force format
-c codec codec name
-codec codec codec name
-pre preset preset name
-map_metadata outfile[,metadata]:infile[,metadata] set metadata information of outfile from infile
-t duration record or transcode "duration" seconds of audio/video
-to time_stop record or transcode stop time
-fs limit_size set the limit file size in bytes
-ss time_off set the start time offset
-sseof time_off set the start time offset relative to EOF
-seek_timestamp enable/disable seeking by timestamp with -ss
-timestamp time set the recording timestamp ("now" to set the current time)
-metadata string=string add metadata
-program title=string:st=number... add program with specified streams
-target type specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")
-apad audio pad
-frames number set the number of frames to output
-filter filter_graph set stream filtergraph
-filter_script filename read stream filtergraph description from a file
-reinit_filter reinit filtergraph on input parameter changes
-discard discard
-disposition disposition

Video options:
-vframes number set the number of video frames to output
-r rate set frame rate (Hz value, fraction or abbreviation)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number set the number of bits per raw sample
-vn disable video
-vcodec codec force video codec ("copy" to copy stream)
-timecode hh:mm:ss[:;.]ff set initial TimeCode value.
-pass n select the pass number (1 to 3)
-vf filter_graph set video filters
-ab bitrate audio bitrate (please use -b:a)
-b bitrate video bitrate (please use -b:v)
-dn disable data

Audio options:
-aframes number set the number of audio frames to output
-aq quality set audio quality (codec-specific)
-ar rate set audio sampling rate (in Hz)
-ac channels set number of audio channels
-an disable audio
-acodec codec force audio codec ("copy" to copy stream)
-vol volume change audio volume (256=normal)
-af filter_graph set audio filters

Subtitle options:
-s size set frame size (WxH or abbreviation)
-sn disable subtitle
-scodec codec force subtitle codec ("copy" to copy stream)
-stag fourcc/tag force subtitle tag/fourcc
-fix_sub_duration fix subtitles duration
-canvas_size size set canvas size (WxH or abbreviation)
-spre preset set the subtitle options to the indicated preset

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/34583.html

相关文章

  • 手机web播放视频使用js使用video标签支持直播

    摘要:主要原理是使用链接。是中解析视频,并把内容画在画布上。目前发现的不足无法播放声音,只能播放视频。视频文件只支持格式的视频目前版本支持视频格式,似乎是不支持了,官方建议用来转格式。 主要原理是使用 jsmpeg(Github链接) 。 jsmpeg是js中解析mpeg视频,并把内容画在画布上。 这篇文章是记录jsmpeg怎么用的。 目前发现jsmpeg的不足 无法播放声音,只能播放视...

    raise_yang 评论0 收藏0
  • 手机web播放视频使用js使用video标签支持直播

    摘要:主要原理是使用链接。是中解析视频,并把内容画在画布上。目前发现的不足无法播放声音,只能播放视频。视频文件只支持格式的视频目前版本支持视频格式,似乎是不支持了,官方建议用来转格式。 主要原理是使用 jsmpeg(Github链接) 。 jsmpeg是js中解析mpeg视频,并把内容画在画布上。 这篇文章是记录jsmpeg怎么用的。 目前发现jsmpeg的不足 无法播放声音,只能播放视...

    qpal 评论0 收藏0
  • wap html5播放器和直播开发小结

    摘要:此文已由作者吴家联授权网易云社区发布。欢迎访问网易云社区,了解更多网易技术产品运营经验。播放器的设计思路重构后应该包含这些功能支持点播非加密的和直播播放兼容适配移动端根据平台自动选择使用还是。直播的一些特点直播状态的判断。 此文已由作者吴家联授权网易云社区发布。 欢迎访问网易云社区,了解更多网易技术产品运营经验。 去年年中的时候,借着产品改版的机会,将之前的h5播放器好好整理重构了一番...

    Miyang 评论0 收藏0
  • 【腾讯bugly干货分享】HTML 5 视频直播一站式扫盲

    摘要:对于视频播放,可以使用协议播放直播流,和都天然支持这种协议,配置简单,直接使用标签即可。什么是简称是开发的一套视频直播协议,现在属于。 本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=1277 视频直播这么火,再不学就 out 了。 为了紧跟潮流,本文将向大家...

    cgspine 评论0 收藏0
  • 【腾讯Bugly干货分享】H5 视频直播那些事

    摘要:每周都会举行嘉宾分享,话题讨论等活动。本期,我们邀请了腾讯前端开发工程师吕鸣,为大家分享视频直播那些事。更多关于延迟的问题可以参考苹果官方地址但是直播视频却有一些不可替代的优势传播性好,利于分享等操作。 本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57a42... Dev Club 是一个交流移动开发技术,结交朋...

    enali 评论0 收藏0

发表评论

0条评论

galois

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<