nschlia / ffmpegfs

FUSE-based transcoding filesystem with video support from many formats to FLAC, MP4, TS, WebM, OGG, MP3, HLS, and others.
https://nschlia.github.io/ffmpegfs/
GNU General Public License v3.0
198 stars 14 forks source link

WAV headers invalid when accessing file the first time #8

Closed nschlia closed 6 years ago

nschlia commented 6 years ago

Report.zip

In the WAV file header, the fields

// wav_size -> FF FF FF FF // data_bytes -> FF FF FF FF

get written too late when the header has already been sent. Probably gets updated only when write_trailer is called. Should be filled in earlier.

typedef struct wav_header {
    // RIFF Header
    char riff_header[4]; // Contains "RIFF" 
    int wav_size; // Size of the wav portion of the file, which follows the first 8 bytes. File size - 8
    char wave_header[4]; // Contains "WAVE" 

    // Format Header
    char fmt_header[4]; // Contains "fmt " (includes trailing space)
    int fmt_chunk_size; // Should be 16 for PCM
    short audio_format; // Should be 1 for PCM. 3 for IEEE Float
    short num_channels;
    int sample_rate;
    int byte_rate; // Number of bytes per second. sample_rate * num_channels * Bytes Per Sample
    short sample_alignment; // num_channels * Bytes Per Sample
    short bit_depth; // Number of bits per sample

    // ... IDv3 header. Start LIST

    // Data
    char data_header[4]; // Contains "data" 
    int data_bytes; // Number of bytes in data. Number of samples * num_channels * sample byte size
    // uint8_t bytes[]; // Remainder of wave file is bytes
} wav_header;