ruffle-rs / ruffle

A Flash Player emulator written in Rust
https://ruffle.rs
Other
15k stars 772 forks source link

flv: PCM audio is broken #16614

Open onkrot opened 3 weeks ago

onkrot commented 3 weeks ago

Describe the bug

Steps to reproduce:

  1. Generate a tone of 400 Hz sine wave (I have used this generator)
  2. Convert it to flv using FFmpeg with PCM 16 LE encoding ffmpeg -i output.wav -acodec pcm_s16le -ar 22050 -ac 1 a.flv
  3. Try to play it using local NetConnection, NetStream, and Video classes (see the attachment)

Expected behavior

Tone plays normally

Content Location

a.zip

Affected platform

Desktop app

Operating system

Windows 11

Browser

No response

Additional information

I found the bug when I tried to create a test for #16570. This problem also affects the proposed decoder.

Error logs suggest some underflow when only a portion of the audio stream gets decoded and played (happens when I replace PCM encoded flv with a-law encoded one)

2024-06-06T03:58:19.347628Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.347639Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.347641Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.347642Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.347643Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.383323Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.383335Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.383336Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.383337Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.383338Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.383339Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.384510Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.384519Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.384520Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.384521Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.384522Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.397256Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.397268Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.397270Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.397271Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.397272Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.418222Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.418242Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.418245Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.418248Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.418250Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.418253Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.432325Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.432339Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.432340Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.432341Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.432342Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.433408Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.433416Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.433417Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.433418Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.433419Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.462837Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.462850Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.462851Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.462852Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
2024-06-06T03:58:19.462853Z ERROR ruffle_core::streams: Error committing sound stream: Unknown codec
torokati44 commented 3 weeks ago

Generate a tone of 400 Hz sine wave (I have used this generator) Convert it to flv using FFmpeg with PCM 16 LE encoding ffmpeg -i output.wav -acodec pcm_s16le -ar 22050 -ac 1 a.flv

FWIW, FFmpeg has a built-in signal generator, I used it to make the test inputs for #16526, like this for example: ffmpeg -f lavfi -i "sine=frequency=444:duration=1:sample_rate=44100" -af "volume=5" -ac 2 -c:a aac tone_stereo_44100hz.flv

See: https://ffmpeg.org/ffmpeg-filters.html#sine