First a little background on audio and video. Both the audio and video are encoded by a codec. A codec turns a large number of images into a compressed video stream or a large number of audio samples into a compressed audio stream and vice versa. There are many codecs to choose from with different qualities, but some are more popular than others. That is just half of the story. When you want to merge the compressed audio and video streams in a single file, you also need a container format. Again, there are many container formats to choose from, but not all container formats support all codecs. Currently there are 2 popular combinations for HTML5 video:
H.264 video and AAC audio in a MP4 container
VP8 video and Vorbis audio in a WebM container
The following two combinations are also used, but are less popular:
Theora video and Vorbis audio in an Ogg container
MPEG-4 video and AAC audio in a MP4 container
Each combination of codecs and containers can be described by an identifier. That identifier contains the MIME type of the container and the codecs parameter, a combination of unique strings for each of the codecs that have been used.
For example, the MIME type for the Ogg container is video/ogg. The unique string for the Theora codec is theora and the string for the Vorbis codec is vorbis. The identifier would look like this: video/ogg; codecs="vorbis, theora"
H.264, MPEG-4 and AAC are a bit more complicated, because these codecs use profiles which determine which features are used by a codec. This only makes the unique string for each codec a bit more lengthy, but the principle is the same. For example Baseline Profile H.264 video has a unique string of avc1.42E01E and High Profile H.264 video has a unique string of avc1.64001E.
The MIME type for the MP4 container is video/mp4. The unique string for Low-Complexity AAC audio is mp4a.40.2. Combined with the unique string for Baseline Profile H.264 video you would get the following identifier: video/mp4; codecs="avc1.42E01E, mp4a.40.2".
Detecting which codecs are supported
The HTML5 specification does not specify which combination of codecs and containers should be supported in a browser, but it does provide a way to detect which actually are. This has become quite important because not every browser supports the same codecs. The reasons for this are complex and beyond the scope of this article. What is important, is that by calling the canPlayType() function with either the MIME type of the container or the complete identifier for a specific combination you can ask the browser if it supports that MIME type or combination. The browser then tells you one of three things:
an empty string: it does not support it,
the string maybe: it does not know if it is supported, but it is not sure it isn’t supported either,
the string probably: it supports the combination of container and codec.
Especially if you only specify the MIME type of the container the browser may not be entirely sure it can play it. The reason for this is that some containers support many codecs and the browser may only support one of them. So if you specify only the MIME type you should expect only an maybe answer at best.
The string probably is the best answer you can get. The reason why it isn’t a simple ‘yes’ is that there are other factors that determine whether or not a file can be played by a browser. This answer is as definitive an answer as you will get. The only way to be even more sure is to actually try to load the file and see if it fails or succeeds.
The rest of this article is a detailed explanation of how the different browsers respond to various canPlayType() requests. You’ll notice there are still quite some problems and Internet Explorer isn’t the only one affected. It’s just the first to be broken in such a way that actually prevents proper detection of codecs. I’ve only looked at the results for video codecs, so each codec parameter given to the canPlayType() function only contained the unique identifier of the video codec. I used a special testcase for determining the results: the HTML5test.com video testcase, which you try for yourse
แรกๆ เบื้องหลังของภาพและเสียง ทั้งเสียงและวิดีโอที่เข้ารหัสโดยตัวแปลงสัญญาณ . มีตัวแปลงสัญญาณจะเปลี่ยนเป็นจำนวนมากของภาพในการบีบอัดวิดีโอสตรีมหรือตัวเลขขนาดใหญ่ของตัวอย่างเสียงในการบีบอัดสตรีมเสียงและในทางกลับกัน มีหลายตัวแปลงสัญญาณเพื่อเลือกจากที่มีคุณภาพแตกต่างกัน แต่บางส่วนที่นิยมมากขึ้นกว่าคนอื่น ๆ นั่นเป็นเพียงครึ่งหนึ่งของเรื่องเมื่อคุณต้องการผสานเสียงบีบอัดและกระแสข้อมูลวิดีโอในไฟล์เดียว คุณยังต้องการภาชนะรูปแบบ อีกครั้ง มีให้เลือกหลายรูปแบบภาชนะ แต่ไม่ทุกรูปแบบภาชนะทั้งหมดสนับสนุนตัวแปลงสัญญาณ ขณะนี้มี 2 ชุดยอดนิยมสำหรับ HTML5 วิดีโอ : H.264 วิดีโอและ AAC เสียง
vp8 ภาชนะใน MP4 วิดีโอและเสียงในภาชนะ
Webm Vorbisต่อไปนี้สองชุดยังใช้ แต่ได้รับความนิยมน้อยลง :
theora วิดีโอและเสียงใน OGG Vorbis AAC MPEG - 4 วิดีโอและเสียงตู้
ใน MP4 ภาชนะแต่ละชุดของตัวแปลงสัญญาณและภาชนะบรรจุที่สามารถอธิบายได้โดยระบุ . ที่ระบุประเภท MIME ของภาชนะบรรจุและพารามิเตอร์ตัวแปลงสัญญาณ , การรวมกันของสตริงที่ไม่ซ้ำกันสำหรับแต่ละของตัวแปลงสัญญาณที่ได้รับใช้
เช่น ชนิด MIME สำหรับ OGG ภาชนะเป็นวิดีโอ / ogg สตริงที่ไม่ซ้ำกันสำหรับ theora ตัวแปลงสัญญาณเป็น theora และเชือกเพื่อ Vorbis ตัวแปลงสัญญาณเป็น Vorbis . ระบุจะมีลักษณะเช่นนี้ : วิดีโอ / OGG ; ตัวแปลงสัญญาณ = " Vorbis , theora "
H.264 , MPEG-4 และ AAC เป็นบิตซับซ้อนมากขึ้น เพราะตัวแปลงสัญญาณเหล่านี้ใช้โปรไฟล์ที่กำหนดคุณลักษณะที่ใช้ โดยตัวแปลงสัญญาณ .นี้จะทำให้สายที่ไม่ซ้ำกันสำหรับแต่ละเพลงที่เป็นบิตมากขึ้น แต่หลักการเหมือนกัน ตัวอย่างโปรไฟล์วิดีโอ ( H.264 มีสตริงที่เป็นเอกลักษณ์ของ avc1.42e01e และวิดีโอ H.264 โปรไฟล์สูงมีเชือกที่เป็นเอกลักษณ์ของ avc1.64001e
ชนิด MIME สำหรับภาชนะเป็น MP4 วิดีโอ / mp4 สตริงที่ไม่ซ้ำกันสำหรับเสียง AAC ความซับซ้อนต่ำเป็น mp4a . ขึ้น .รวมกับสตริงที่ไม่ซ้ำกันสำหรับโปรไฟล์วิดีโอ ( H.264 คุณจะได้รับต่อไปนี้ระบุตัวแปลงสัญญาณวิดีโอ / MP4 ; = " avc1.42e01e mp4a 40.2 , . " .
ซึ่งตัวแปลงสัญญาณตรวจจับรองรับ HTML5 ข้อกำหนดไม่ได้ระบุว่าการรวมกันของตัวแปลงสัญญาณและภาชนะควรได้รับการสนับสนุนในเบราว์เซอร์ แต่มันให้ วิธีการตรวจสอบที่เป็นจริงนี้ได้กลายเป็นที่ค่อนข้างสำคัญ เพราะไม่ใช่ทุกเบราว์เซอร์ที่สนับสนุนตัวแปลงสัญญาณเดียวกัน ด้วยเหตุผลนี้จะซับซ้อน และอยู่นอกเหนือขอบเขตของบทความนี้ สิ่งที่สำคัญคือว่าโดยการเรียกฟังก์ชัน canplaytype() กับทั้งประเภท MIME ของภาชนะบรรจุหรือสมบูรณ์ที่ระบุสำหรับการรวมกันที่เฉพาะเจาะจง คุณสามารถถามถ้ามันสนับสนุนเบราว์เซอร์ที่ใช้ประเภทหรือการรวมกันเบราว์เซอร์แล้วบอกคุณหนึ่งในสามสิ่ง :
เป็นสตริงที่ว่างเปล่า : มันไม่สนับสนุนมัน ,
ข้อความบางทีมันไม่ได้รู้ว่า มันมีการสนับสนุน แต่ก็ไม่แน่ใจว่ามันจะไม่ได้รับการสนับสนุนเหมือนกัน
สายคง : สนับสนุนการรวมกันของภาชนะและตัวแปลงสัญญาณ .
โดยเฉพาะอย่างยิ่งถ้า คุณเพียงระบุประเภท MIME ของคอนเทนเนอร์เบราว์เซอร์อาจจะไม่แน่ใจว่าทั้งหมดมันสามารถเล่นเหตุผลนี้คือ ว่า บางภาชนะที่สนับสนุนตัวแปลงสัญญาณจำนวนมากและเบราว์เซอร์อาจสนับสนุนเพียงหนึ่งของพวกเขา ดังนั้น ถ้าคุณระบุเฉพาะประเภท MIME คุณควรคาดหวังเพียงอาจเป็นคำตอบที่ดีที่สุด
สายอาจเป็นคำตอบที่ดีที่สุดที่คุณจะได้รับ เหตุผลที่ทำไมมันไม่ง่าย " ใช่ " ก็คือว่ามีปัจจัยอื่น ๆที่กำหนดหรือไม่ว่าไฟล์สามารถเล่นได้โดยเบราว์เซอร์คำตอบนี้เป็นคำตอบที่ชัดเจนที่คุณจะได้รับ วิธีเดียวที่จะแน่ใจมากขึ้นคือการพยายามที่จะโหลดไฟล์ และดูถ้ามันล้มเหลวหรือประสบความสำเร็จ
ส่วนที่เหลือของบทความนี้มีคำอธิบายรายละเอียดของวิธีการที่เบราว์เซอร์ที่แตกต่างกันตอบสนองการร้องขอ canplaytype() ต่าง ๆ คุณจะสังเกตเห็นมีค่อนข้างบางปัญหาและไม่ใช่ Internet Explorer ไม่ได้คนเดียวเท่านั้นที่ได้รับผลกระทบมันเป็นแค่ครั้งแรก จะเสียในลักษณะที่จริงป้องกันการตรวจจับที่เหมาะสมของตัวแปลงสัญญาณ ฉันมองแต่ผลวิดีโอตัวแปลงสัญญาณ , ตัวแปลงสัญญาณแต่ละพารามิเตอร์ให้กับฟังก์ชัน canplaytype() เท่านั้นมีการระบุที่ไม่ซ้ำกันของตัวแปลงสัญญาณวิดีโอ . ผมใช้ testcase พิเศษเพื่อกำหนดผลวิดีโอ html5test.com testcase ซึ่งคุณลองสำหรับตัวเอง
การแปล กรุณารอสักครู่..
