FFmpeg で "Consider increasing the value for the 'analyzeduration'" とメッセージが表示されたので analyzeduration を設定する

試した環境

  • FFmpeg version 5.0.1-essentials

本題

FFmpeg でとある HLS の m3u8 を入力として mp4 に変換する処理をしたところ以下のメッセージが出力され、Audio データが含まれない Video データのみの mp4 ファイルが作成されました。

[hls @ 000001747aabbec0]  Could not find codec parameters for stream 1 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options

この問題を解消するには、このメッセージに従って 'analyzeduration' と 'probesize' の値を大きく設定します。 ドキュメントによると、analyzeduration と probesize のデフォルトの値は両方とも5000000のようですのでそれより大きい値にします。

https://ffmpeg.org/ffmpeg-formats.html

probesize integer (input)

Set probing size in bytes, i.e. the size of the data to analyze to get stream information. A higher value will enable detecting more information in case it is dispersed into the stream, but will increase latency. Must be an integer not lesser than 32. It is 5000000 by default.

analyzeduration integer (input)

Specify how many microseconds are analyzed to probe the input. A higher value will enable detecting more accurate information, but will increase latency. It defaults to 5,000,000 microseconds = 5 seconds.

私のケースでは動画サイズが小さかったこともあり、以下のコマンドのように analyzeduration の値を大きくするだけで最初に示したメッセージは出なくなり音声付きの動画ファイルが生成されました。

ffmpeg -analyzeduration 50M -i input.m3u8 -c copy output.mp4

問題はこれで解消できました。

気になって調べたこと

ところで、最初に示したメッセージの 'analyzeduration' と 'probesize' の直後の括弧内の数字は設定されている値のように思えますが、analyzeduration の値が0になっており、ドキュメントに記されたデフォルトの値ではありません。 そこで-analyzeduration 5000000にして実行したところ、括弧内の数字が変わりました。

[hls @ 0000016805a2bd00] Could not find codec parameters for stream 1 (Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp): unspecified sample rate
Consider increasing the value for the 'analyzeduration' (5000000) and 'probesize' (5000000) options

括弧内の数字は設定されている値で間違いなさそうです。 ただしもしかすると analyzeduration がデフォルトのときだけ出力するメッセージが間違っているという可能性もあるかもしれません。 このメッセージが表示されるということで、私が試した限りではこの値では Audio が含まれない mp4 ファイルが出力されるので、ドキュメントが間違っているのか analyzeduration のデフォルトのときの出力メッセージが間違っているのかまで判断できませんでした。

中途半端な調査内容ですが書き残しておきます。

参考

ffmpeg : Could not find codec parameters for stream 1 (Video: vp8, yuv420p): unspecified size? - Stack Overflow

FFmpeg Formats Documentation