Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:37:19+00:00 2026-06-09T17:37:19+00:00

i am trying to read a wav file generated by ffmpeg with ffmpeg -i

  • 0

i am trying to read a wav file generated by ffmpeg with

ffmpeg -i av

FFmpeg generates a wav file with a header size of 18 but without any extension data.

This are my data structures:

struct wav_header {
  uint32_t chunk_id;
  uint32_t chunk_data_size;
  uint32_t riff_type;
  uint32_t fmt;
  uint32_t fmt_chunk_size;
  uint16_t format_tag;
  uint16_t channels;
  uint32_t samples_per_second;
  uint32_t bytes_per_second;
  uint16_t block_align;         /* 1 => 8-bit mono, 2 => 8-bit stereo or 16-bit mono, 4 => 16-bit stereo */
  uint16_t bits_per_sample;
};

struct fact_header {
  uint32_t chunk_id;
  uint32_t chunk_data_size;
  uint32_t sample_length;
};

struct data_header {
  uint32_t id;
  uint32_t size;
};

If i read them out i get the following results of my wav file:

chunk_data_size: 40836134

ftm_chunk_size: 18
channels: 2
samples_per_second (samplerate): 48000
bytes_per_second: 192000
block_align: 4
bits_per_sample: 16

data_id: 61746164    -> 'data' OK
data_size: 40836096    

I try now to calculate the length in seconds by using the formula

data_size / bytes_per_second 

and get the following output:

length_in_seconds: 212.68800354
length_in_minutes: 3.54480004    (length_in_seconds / 60)

But when i open my file in itunes i get a length of 3:31. I also tried it with other sound files and i am always a little bit too far.

What i also tried was, to hexdump my wav file. The hexdump showed less output than if i do a
for (i < data_size; i += 2) printf(“%02x”, data[i])

so i am somehow reading too far?

I searched the whole internet about formulas but im kinda stuck because I always come to the same results.

http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html

you can read the following statement:

“WAVE files often have information chunks that precede or follow the sound data (Data chunk). Some programs (naively) assume that for PCM data, the file header is exactly 44 bytes long and that the rest of the file contains sound data. This is not a safe assumption.”

This is probably what i am doing wrong. But how can i get then the right sound_chuck_data_size?

EDIT

lile gcb pointed out below everything is alright. The solution was that the time was stored in decimal time and i had to convert it to regular time 🙂 this is what i came up with and it works fine:

track.duration_dec = (float)data.size / (header.bytes_per_second * 60);
track.duration_time = convert_time(track.duration_dec);


static double convert_time(double input) {
  double integral;
  double frac;
  char buffer[48];
  frac = modf(input, &integral);
  sprintf(buffer, "%d.%1.f", (int)integral, frac*60);
  return atof(buffer);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:37:20+00:00Added an answer on June 9, 2026 at 5:37 pm

    It sounds ok to me. So your song is 3.54480004. As already stated, this is in decimal. So you have 3 minutes and then 0.54480004 * 60 which is 33.28 seconds. So I’d say 3.33 minutes long

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read data of a .wav file both in java and
I am trying to read the .wav file and give the raw data as
I am trying to read a wav file from the resources of my Java
I'm trying to read a .wav file into an array of bytes to be
I am trying to read bytes from a wav file and send it across
am trying to read a file (double values) with scanner and save the data
I'm trying to read a WAV file (and in the future also MP3 and
Im trying to read and write to/from the same file, is this possible? Here
I m trying read XML data using XML parser from Url( https://....etc ). But
I am trying to read a *.wav file using scipy. I do the following:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.