本週日,來 OSC·年終盛典收割技術乾貨,get新技能!!>>>

NVIDIA 推出了適用於 Python 的開源視頻處理框架“ VideoProcessingFramework”(VPF)。據悉,VPF 是一組開源的 C ++ 庫和Python綁定,可與其封閉源代碼 Codec SDK 進行交互。該框架的功能是簡化從 Python 開發 GPU 加速視頻編碼/解碼的過程。

VPF 利用 NVIDIA Video Codec SDK 來提高靈活性和性能,併為開發人員提供 Python 固有的易用性。

實際上,儘管 Python 不是性能最高的語言,但它卻是一種易於使用的語言。並且在 NVIDIA 決定發佈此視頻處理框架之後,相當於在現有 Video Codec SDK C ++ 堆棧周圍的 Python wrapper,都將用於在 Kepler 及更高版本上基於 GPU 的視頻編碼/解碼。
因此,在利用基於 GPU 的高性能視頻加速的同時,用戶最終獲得了易於閱讀/編寫的代碼。

該代碼在 GitHub 上可作為 NVIDIA 的 VideoProcessingFramework 獲得。

此外,在介紹 VPF 的博客內容中,開發人員還提供了一個簡短的 Python 代碼示例,該示例使用 PyNvCodec 模塊顯示 Python 中的視頻轉碼。

import PyNvCodec as nvc gpuID = 0 encFile = "big_buck_bunny_1080p_h264.mov" xcodeFile = open("big_buck_bunny_1080p.h264", "wb") nvDec = nvc.PyNvDecoder(encFile, gpuID) nvEnc = nvc.PyNvEncoder({'preset': 'hq', 'codec': 'h264', 's': '1920x1080'}, gpuID) while True: rawSurface = nvDec.DecodeSingleSurface() # Decoder will return zero surface if input file is over; if not (rawSurface.GetCudaDevicePtr()): break encFrame = nvEnc.EncodeSingleSurface(rawSurface) if(encFrame.size): frameByteArray = bytearray(encFrame) xcodeFile.write(frameByteArray) # Encoder is asynchronous, so we need to flush it encFrames = nvEnc.Flush() for encFrame in encFrames: encByteArray = bytearray(encFrame) xcodeFile.write(encByteArray)

參考消息:

https://devblogs.nvidia.com/vpf-hardware-accelerated-video-processing-framework-in-python/

https://www.phoronix.com/scan.php?page=news_item&px=NVIDIA-Video-Process-Framework

相關鏈接