一場關於FLV是否要支持HEVC的爭論

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"前幾天,在瀏覽FFMpeg的Trac時,發現了一個希望"},{"type":"link","attrs":{"href":"https://trac.ffmpeg.org/ticket/6389","title":null},"content":[{"type":"text","text":"FFMpeg增加"},{"type":"text","marks":[{"type":"italic"}],"text":"讓FLV支持HEVC編碼"}]},{"type":"text","text":"的需求。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這個需求是2017年提交到FFMpeg社區的,從整個交流過程可以看出,需求提出者和FFMpeg的社區維護者對這個需求的分歧較大,從中也能看出一些工作思路和工作文化上的差異。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"整個需求討論的大概過程"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"提議發起"},{"type":"text","text":":目前HLS和TS都已經支持H265了,但是國內大部分CDN更多采用的是RTMP/HTTP-FLV格式。並且,因爲HLS的延遲比較高,因此國內大部分直播業務採用的都是RTMP/HTTP-FLV格式。所以,該ISSUE的發起者就想問一下FFMpeg社區是否有計劃讓FLV支持HEVC。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"FFMpeg社區回覆"},{"type":"text","text":":不得不說,社區的回覆還是很快的。在需求提出20分鐘後,有人回覆了。大概意思就是:並不是不能讓FLV支持HEVC,只是因爲Adobe沒有對FLV支持HEVC做出具體說明。因此,如果Adobe不擴展標準,FFMpeg是不會讓FLV支持HEVC的。同時,社區還提出了一些備選的解決方法。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"針對延遲的爭論"},{"type":"text","text":":接下來就是雙方針對直播流延遲的爭論了。一方認爲可以對HLS或MPEG-DASH做一些優化來降低延遲,一方認爲HLS不可能達到1-3秒的延遲,基本上接下來的討論就是在討論延遲了。因爲RTMP/HTTP-FLV的低延遲已經國內CDN廠商的完美支持,因此,還是希望FFMpeg能讓FLV支持HEVC。並且,有好多評論也在支持這個需求。確實,在2017年,尤其是在國內,對於直播業務而言,能讓FLV支持H265真的是一件非常值得激動的事。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"社區強烈反對"},{"type":"text","text":":在衆多支持該需求的評論之後,FFMpeg直接關閉了這個提議,並且將該提議置爲了"},{"type":"codeinline","content":[{"type":"text","text":"invalid"}]},{"type":"text","text":"狀態。這些是馬甲賬號的灌水評論,這些評論對於FFMpeg是否實現該提議沒有任何作用。只要Adobe不升級FLV的標準,FFMpeg就不會讓FLV支持HEVC。不管怎麼樣,FFMpeg都不會支持這種定製的需求。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此,一直到現在,3年過去了,FFMpeg也沒有實現在FLV中支持HEVC的特性。因此,直到如今,在直播業務中,也都無法使用社區版本的FFMpeg實現:在FLV格式中傳輸H265的直播流。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所幸的"},{"type":"link","attrs":{"href":"https://github.com/ksvc/FFmpeg/tree/release/3.4","title":null},"content":[{"type":"text","text":"金山雲實現了FFMpeg的"},{"type":"text","marks":[{"type":"italic"}],"text":"hack"},{"type":"text","text":"版本"}]},{"type":"text","text":",從而讓RTMP/HTTP-FLV協議支持了HEVC編碼。因此,即使標準的解碼器(播放器)無法播放金山雲的"},{"type":"text","marks":[{"type":"italic"}],"text":"hack"},{"type":"text","text":"版本生成的RTMP/HTTP-FLV的H265直播流,但是,金山雲實現的這個私有的協議也基本上成爲了國內直播相關業務的標準協議了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"協議/標準先行,還是實現先行?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"11:6 耶和華說,看哪,他們成爲一樣的人民,都是一樣的言語,如今既作起這事來,以後他們所要作的事就沒有不成就的了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"11:7 我們下去,在那裏變亂他們的口音,使他們的言語彼此不通。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"11:8 於是,耶和華使他們從那裏分散在全地上。他們就停工,不造那城了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"11:9 因爲耶和華在那裏變亂天下人的言語,使衆人分散在全地上,所以那城名叫巴別(就是變亂的意思)。"}]},{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" ——《聖經·創世紀》"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如今,生產社會化程度越來越高,技術要求越來越複雜,生產協作越來越廣泛。許多技術和產品,往往涉及幾十個、幾百個甚至上萬個企業,這客觀上要求:必須在技術上使生產活動保持高度的統一和協調。此時,必須通過制定和執行技術標準使各生產部門和企業內部各生產環節有機地聯繫起來,保證生產有條不紊地進行。沒有標準、協議,就無法有效的實現社會化大生產。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"縱觀整個計算機行業,無論哪個領域,無論是網絡通信還是編解碼協議,都是協議先行。私有協議的推廣,也是先從標準化開始,然後才推動具體實現。否則,行業內就無法達成共識,否則,整個網絡的互聯、互通也就無從談起。因此,必須是標準、協議先行。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"另一個方面,標準、協議是具體實現的抽象,沒有接口的定義,哪裏來的接口的實現呢?當然,也可以從具體的實現中抽取接口,但是我們必須意識到,在接口抽取之前,這個實現相當於是私有的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此,FFMpeg社區拒絕讓FLV自持HEVC是合理的。否則,我們的工作就會充斥着各種FFMpeg的"},{"type":"text","marks":[{"type":"italic"}],"text":"hack"},{"type":"text","text":"版本,並且每個"},{"type":"text","marks":[{"type":"italic"}],"text":"hack"},{"type":"text","text":"版本都是用來解決不同的問題。這真是一件非常恐怖的事情。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"兵馬未動,糧草先行。如果真的想讓事情變的更便捷,最好的方式就是優先推動標準或協議的升級。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我見到過很多次較爲嚴重的線上問題,其根本原因就是上下游之間沒有一個定義良好的協議,導致升級過程出現了"},{"type":"link","attrs":{"href":"https://wangwei1237.gitee.io/monolith-to-microservices/docs/Breaking_Changes.html","title":null},"content":[{"type":"text","text":"破壞性修改"}]},{"type":"text","text":",進而導致問題的發生。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"組織文化優先還是用戶需求優先?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不同的社區有不同的文化。組織的文化會使得當出現問題的時候,組織內所有成員對該問題的應激反應都是一致的,這種應激反應是無需請求上級就可以作出的。從"},{"type":"link","attrs":{"href":"https://trac.ffmpeg.org/ticket/6389","title":null},"content":[{"type":"text","text":"提議"}]},{"type":"text","text":"中可以看出,FFMpeg社區的文化之一是:編解碼器要針對標準和規範來實施。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果閱讀FFMpeg的源碼,其實也能發現很多如下的代碼:"}]},{"type":"codeblock","attrs":{"lang":"cpp"},"content":[{"type":"text","text":"enum {\n // 7.4.3.1: vps_max_layers_minus1 is in [0, 62].\n HEVC_MAX_LAYERS = 63,\n // 7.4.3.1: vps_max_sub_layers_minus1 is in [0, 6].\n HEVC_MAX_SUB_LAYERS = 7,\n // 7.4.3.1: vps_num_layer_sets_minus1 is in [0, 1023].\n HEVC_MAX_LAYER_SETS = 1024,\n\n // 7.4.2.1: vps_video_parameter_set_id is u(4).\n HEVC_MAX_VPS_COUNT = 16,\n // 7.4.3.2.1: sps_seq_parameter_set_id is in [0, 15].\n HEVC_MAX_SPS_COUNT = 16,\n // 7.4.3.3.1: pps_pic_parameter_set_id is in [0, 63].\n HEVC_MAX_PPS_COUNT = 64,\n\n // A.4.2: MaxDpbSize is bounded above by 16.\n HEVC_MAX_DPB_SIZE = 16,\n // 7.4.3.1: vps_max_dec_pic_buffering_minus1[i] is in [0, MaxDpbSize - 1].\n HEVC_MAX_REFS = HEVC_MAX_DPB_SIZE,\n \n // ...\n};"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此,社區不同的人對該提議的意見都是一致的。即便這個用戶需求再合理,即便這個需求有多少用戶支持,只要是標準不更新,FFMpeg永遠都不會支持。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"另外,用戶只是需要一種能夠支持H265編碼的、CDN又支持良好的、延遲又非常低的視頻流媒體格式而已,不是嗎?如果真的有這種格式,讓FLV支持HEVC是否就不是一個問題了呢?既然,Adobe已經停止了對RTMP的維護了,那麼爲什麼還要花時間在這個協議上呢?爲什麼不選擇更新的技術呢?雖然選擇新的技術意味着需要冒更大的風險和花費更多的成本。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"尤其是當不同的用戶需求之間存在衝突時,如何處理?To be or not to be, that’s a question!"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"對於技術,是向前看還是回頭看?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"“始生之物,其形必醜”。但是,新技術必然會取代舊技術,從根本上說是因爲:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"新技術具有新的結構和功能,能適應已經變化了的環境和條件"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"新技術是對舊技術的揚棄,並添加了舊技術所不能容納的新內容"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"因此,對於技術而言,我們需要向前看,需要去了解這些新技術。當然,採用新技術肯定是要付出一定代價的,沒有不付出就會有的收穫。需要深入研究新技術和我們業務之間的差距,然後在業務的實踐中不斷完善新的技術。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"另外,在瞭解新技術時,還要了解新技術的歷史,瞭解在新技術是基於什麼歷史背景而產出的,是用於解決什麼問題的?這些東西,是新技術的應用根本,只有深入瞭解了這些,才能在後續的應用中,得心應手。錯誤的應用新技術產生的問題比正確的使用舊技術要大的多。錯誤的忽略舊技術的優勢也會讓我們在應用新技術的的過程中花費過多的成本。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"例如在HTTP2的協議中,有這樣的描述:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"HTTP/2 addresses these issues by defining an optimized mapping of HTTP’s semantics to an underlying connection. Specifically, it allows interleaving of request and response messages on the same connection and uses an efficient coding for HTTP header fields. It also allows prioritization of requests, letting more important requests complete more quickly, further improving performance."}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在HTTP3中,有如下的描述:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"HTTP/2 introduced a binary framing and multiplexing layer to improve latency without modifying the transport layer. However, because the parallel nature of HTTP/2’s multiplexing is not visible to TCP’s loss recovery mechanisms, a lost or reordered packet causes all active transactions to experience a stall regardless of whether that transaction was impacted by the lost packet."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"The QUIC transport protocol incorporates stream multiplexing and per-stream flow control, similar to that provided by the HTTP/2 framing layer. By providing reliability at the stream level and congestion control across the entire connection, it has the capability to improve the performance of HTTP compared to a TCP mapping."}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/60/60d4a4ea4dfcdafe086276d4b2519db0.jpeg","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"就像上圖的“烏鴉喝水”一樣,是採用吸管呢?還是對原有的石頭進行各種改進呢?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"後來,在網上找到了又拍雲的一篇"},{"type":"link","attrs":{"href":"https://www.cnblogs.com/upyun/p/7053150.html","title":null},"content":[{"type":"text","text":"《如何將HLS延時縮短至4秒,HLS+技術詳解》"}]},{"type":"text","text":"的一篇文章。"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章