Raspberry Piでの動画遅延のトラブルシューティング
原題: Troubleshooting Video Delay On The Raspberry Pi
日本語訳
# タイトル
Raspberry Piにおけるビデオ遅延のトラブルシューティング
# 本文
Raspberry Piシリーズのシングルボードコンピュータは、非常に優れた小型デバイスであり、カメラやビデオを用いた高度な活用が可能です。しかし、使用するボードや具体的な用途によっては、これらのタスクにおいてかなりのレイテンシ(遅延)が発生することがあります。最高のパフォーマンスを引き出すには、適切なセットアップが必要です。[MattKC]氏は個人のプロジェクトでこの問題に直面していましたが、最近、ある種のブレイクスルーを達成しました。
この問題は、[MattKC]氏がWiiUのゲームパッドを複製しようとする作業の中で発生しました。その構想は、WiiU本体からビデオストリームを受信し、Raspberry Pi Zero 2Wを使って表示するというものです。彼はレイテンシの問題に悩まされており、ビデオパイプライン内にどうしても解消されない、奇妙な「3フレーム分」の遅延が発生していました。パイプラインにダミーフレームを挿入し、出力時にそれらを無視するという手法を試みても効果はなく、遅延は解消されませんでした。最終的に、[MattKC]氏は、この遅延が特定のフレーム数によるものではなく、時間によるものであることに気づきました。実際には、約50ミリ秒の遅延でした。
さらに詳しく調査した結果、デコーダーへのフレームの供給およびデコーダーからのフレームの受け取り方に問題があることが判明しました。最初のフレームのデコードには約50msかかっていましたが、それ以降のフレームははるかに短く、わずか5msほどでした。しかし、[MattKC]氏のコードはデコードが完了した瞬間にフレームを取得する仕組みになっていなかったため、そのラグが次へと持ち越されてしまっていたのです。ビデオでは、その詳細と、デコーダーを定期的にポーリング(polling)することがどのように問題解決に繋がったかが詳しく解説されています。最終的に、Raspberry Pi Zero 2Wは、オリジナルのNintendo WiiUゲームパッドと同等の速さでWiiUのビデオフィードを処理・表示できるようになりました。
もしこの内容に興味を持ったなら、WiiUゲームパッドプロジェクトの始まりについても遡ってチェックしてみる価値があります。ビデオはCMの後に。
原文(英語)を表示
The Raspberry Pi line of single-board computers are great little devices, and they can do great things with cameras and video. However, there can be a fair bit of latency involved in these tasks depending on the board you’re using and just what you’re doing. You need to have things set up just so to get peak performance. [MattKC] has tangled with this issue in a personal project, and recently had somewhat of a breakthrough.
The issue came up during [MattKC’s] work on cloning the WiiU gamepad. The idea was to receive the video stream from the WiiU console and display it using a Raspberry Pi Zero 2W. He had some problems with latency, wherein there was a strange 3 frames of latency in the video pipeline that just wouldn’t go away. Even substituting in some dummy frames into the pipeline and ignoring them at output time didn’t work—the latency stuck around. Eventually, [MattKC] realized the delay wasn’t about a certain number of frames—it was about time. About 50 milliseconds, in fact.
Drilling down further revealed that there was a problem in the way frames were being fed into and received from the decoder. The first frame would take about 50 ms to decode, while later frames would take far less—as little as 5ms. However, [MattKC’s] code wasn’t set up to grab frames as soon as they were done, so the lag carried forward. The video explains it in greater detail, and how polling the decoder regularly helped solve the issue. The final result was a Raspberry Pi Zero 2W that could process and display the WiiU video feed as quickly as the original Nintendo WiiU gamepad.
If you dug this, it’s worth going back and checking out where the WiiU gamepad project started, too. Video after the break.