Linux 如何播放html5视频?当文件是file.m4v?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7698953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to play html5 video? When the file is file.m4v?
提问by
I have tried several methods but none is playing the file2.m4v using html5 see screen shot.
我尝试了几种方法,但没有一个使用 html5 播放 file2.m4v,请参阅屏幕截图。
But if i use that same file using VLC/Mplayer it play the film nicely (no problem). Please see following the code and the file detail information's to find the code's its using:
但是如果我使用 VLC/Mplayer 使用相同的文件,它可以很好地播放电影(没问题)。请参阅以下代码和文件详细信息以查找代码的用途:
video.php:
视频.php:
<html>
<head>
</head>
<body>
<video preload="auto" autoplay="autoplay" controls>
<source
src="/var/www/html/video/file2.m4v"
type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>
</body>
</html>
Find the file audio/video codecs:
找到文件音频/视频编解码器:
$ mplayer -vo null -ao null -frames 0 -identify file2.m4v
MPlayer SVN-r33251-4.6.0 (C) 2000-2011 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing file2.m4v.
TS file format detected.
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
TS_PARSE: COULDN'T SYNC
VIDEO MPEG4(pid=69) AUDIO AAC(pid=68) NO SUBS (yet)! PROGRAM N. 1
ID_VIDEO_ID=69
ID_AUDIO_ID=68
FPS not specified in the header or invalid, use the -fps option.
Load subtitles in ./
ID_FILENAME=file2.m4v
ID_DEMUXER=mpegts
ID_VIDEO_FORMAT=0x10000004
ID_VIDEO_BITRATE=0
ID_VIDEO_WIDTH=352
ID_VIDEO_HEIGHT=288
ID_VIDEO_FPS=0.000
ID_VIDEO_ASPECT=0.0000
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
ID_AUDIO_FORMAT=MP4A
ID_AUDIO_BITRATE=0
ID_AUDIO_RATE=0
ID_AUDIO_NCH=0
PROGRAM_ID=1 (0x01), PMT_PID: 66(0x42)
ID_START_TIME=28315.35
ID_LENGTH=0.00
ID_SEEKABLE=1
ID_CHAPTERS=0
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Unsupported PixelFormat 61
Unsupported PixelFormat 53
Selected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)
==========================================================================
ID_VIDEO_CODEC=ffodivx
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 8000 Hz, 1 ch, s16le, 0.0 kbit/0.00% (ratio: 0->16000)
ID_AUDIO_BITRATE=0
ID_AUDIO_RATE=8000
ID_AUDIO_NCH=1
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
AO: [null] 8000Hz 1ch s16le (2 bytes per sample)
ID_AUDIO_CODEC=ffaac
Starting playback...
Exiting... (End of file)
ID_EXIT=EOF
What else i can use to play this file in the browser? Is there any javascript player available also in case html5 cant play it?
我还能用什么来在浏览器中播放这个文件?如果 html5 无法播放,是否还有可用的 javascript 播放器?
采纳答案by adeneo
HTML5 Video is just a convention to play a certain video formats with a new element for which browsers will implement an own player. HTML5 won't provide players or something like that.
HTML5 Video 只是一种使用新元素播放特定视频格式的约定,浏览器将为其实现自己的播放器。HTML5 不会提供播放器或类似的东西。
You have to look for the codecs and contained supported by most browsers, which, if I remember well, are mostly Theora for Video and Vorbis for audio, in an OGG container.
您必须在 OGG 容器中查找大多数浏览器支持的编解码器和包含的编解码器,如果我没记错的话,主要是用于视频的 Theora 和用于音频的 Vorbis。
Then I remember that Webkit browsers will support Matroska (MKV) containers using V8 as video codec and Vorbis for audio.
然后我记得 Webkit 浏览器将支持使用 V8 作为视频编解码器和 Vorbis 作为音频的 Matroska (MKV) 容器。
My recommendation:provide an OGG file with Theora and Vorbis as video and audio codecs respectively. Inside provide a fallback using an MKV file with V8 and Vorbis and then, if you can, inside an MPG video file using Mpeg2 and MP2 (couldn't think on something better) as video and audio codecs, fallback. Then as the last fallback, a Flash player playing a FLV video file.
我的建议:分别提供一个带有 Theora 和 Vorbis 作为视频和音频编解码器的 OGG 文件。内部使用带有 V8 和 Vorbis 的 MKV 文件提供回退,然后,如果可以,在使用 Mpeg2 和 MP2(想不出更好的东西)作为视频和音频编解码器的 MPG 视频文件中,回退。然后作为最后一个后备,Flash 播放器播放 FLV 视频文件。
Example for how your HTML should look like:
您的 HTML 应该是什么样子的示例:
<video src="thevideo.ogg">
<video src="firstFallback.mkv">
<object type="video/mpeg" src="secondFallback.mpeg">
<object
type="application/x-shockwave-flash"
src="player.swf?etc...">
<p>Download <a href="videourl">the video etc...</a><br />
or use a more modern browser to watch online, etc...</p>
</object>
</object>
</video>
</video>
Etc... ;-)
等等... ;-)
With this configuration, most (if not all) browsers should be able to play your video, preferring the most supported (and most modern) format. “Fallbacking” until they find a Flash Player.
使用此配置,大多数(如果不是全部)浏览器应该能够播放您的视频,更喜欢最受支持(和最现代)的格式。“后备”直到他们找到 Flash Player。
For hints on what formats to support:take a look at the HTML5 Video part in Wikipedia.
有关支持哪些格式的提示:查看Wikipedia中的 HTML5 视频部分。
Important:In your code you are refering to an absolute filesystem path, which is totally not-accesible for a web visitor. Maybe in the srcyou meant /video/file2.m4v
.
重要提示:在您的代码中,您指的是绝对文件系统路径,对于网络访问者来说,这是完全无法访问的。也许在你的意思的src 中/video/file2.m4v
。
回答by adeneo
Try:
尝试:
<video id="myVideo" width="300" height="200" preload="auto" src="/var/www/html/video/file2.m4v" type="video/mp4" autoplay controls></video>
Also try renaming the file to file2.mp4
也尝试将文件重命名为 file2.mp4
回答by Tieson T.
HTML5 is a web standard (in other words, a specification), not a technology, so the phrase "html5 cant play it" implies a bit of misunderstanding on your part. The file is decoded by the browser according to the settings you specify in the <video>
tag. It is worth noting that not every browser and/or operating system has the same codecs available, so first verify that you can play the video natively.
HTML5 是一种网络标准(换句话说,一种规范),而不是一种技术,因此“html5 无法播放”这句话暗示了您的一些误解。该文件由浏览器根据您在<video>
标签中指定的设置进行解码。值得注意的是,并非每个浏览器和/或操作系统都具有相同的可用编解码器,因此请先验证您是否可以本地播放视频。
Firefox, for one, cannot decode anything encoded with the H.264 codec, which I believe is used in .m4v files (anyone who knows better, please correct me).
一方面,Firefox 无法解码使用 H.264 编解码器编码的任何内容,我相信它用于 .m4v 文件(任何更了解的人,请纠正我)。
Lastly, as someone else pointed out, your path is likely wrong. Remove the 'var' and 'www' portions of the path.
最后,正如其他人指出的那样,您的路径可能是错误的。删除路径的“var”和“www”部分。
回答by Gerben
Your html is correct, so either the path is incorrect, the file is invalid, or the browser doesn't support m4v.
你的html是正确的,所以要么路径不正确,文件无效,要么浏览器不支持m4v。
/var/www/ is highly suspicious, but as you say it works with a avi file, so that is not it
Try using the file: http://ade.apple.com/movies/institute2011/hotel.m4vin the src. If it is playing, then your m4v is probably not correctly encoded.
If you are using Firefox or Opera then the movie will never play, as they don't support anything other than WebM and OGG
/var/www/ 非常可疑,但正如您所说,它适用于 avi 文件,所以事实并非如此
尝试在 src 中使用文件:http: //ade.apple.com/movies/institute2011/hotel.m4v。如果正在播放,则您的 m4v 可能未正确编码。
如果您使用的是 Firefox 或 Opera,则该电影将永远无法播放,因为它们不支持 WebM 和 OGG 以外的任何内容