Quantcast
Viewing all articles
Browse latest Browse all 3852

Mapping byte sequence of FFmpeg API structures

I’m seeing if it’s possible to call the FFmpeg APIs directly from Xojo. I’m using the APIs rather than calling FFmpeg from the Shell as I need to bundle FFmpeg with my Mac/Win app and don’t want to require my clients to install FFmpeg. I see I can include the shared libraries in my apps by following the FFmpeg compliance list.

First I wanted to ask has anyone done this before from Xojo?

As a bit of background I have no previous programming knowledge of C, so for example it took me several hours to work out that an asterisk (*) in a declaration refers to a ptr! I haven’t been able to find a comprehensive reference on how to write declares in this forum, xDev mag, xDev library or the developer conference videos that I have or can access on-line. Don’t get me wrong, there’s some very helpful posts here in this forum, but they seem to be more for calling OS APIs. However, if anyone knows of something else please let me know.

To start I’m trying to call the APIs to load a stereo WAV file and split it into two mono WAV files (something I can easily do by calling FFmpeg via the shell). I’ve been able to load the WAV into an AVFormatContext, then get ptrs to the audio stream and codec. I’m able to get a sensible codec name from the codec object (ptr), so I know I’m onto something. I’m currently using DeclareLibraryMBS to interact with the APIs which all seems to be working well (many thanks for your help so far @Christian_Schmitz).

I’m coming unstuck with larger structures and knowing how to access this data, or see where the data is that I need in the byte sequence. I’m currently looking to get and set the values for an AVCodecParameters structure. Here’s the debugger showing the bytes for this structure when I load my stereo WAV:

0100 0000 0C00 0100 0100 0000 0000 0000
0000 0000 0000 0000 0000 0000 0200 0000
0028 2300 0000 0000 1800 0000 1800 0000
9DFF FFFF 9DFF FFFF 0000 0000 0000 0000
0000 0000 0100 0000 0000 0000 0000 0000
0200 0000 0200 0000 0200 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0200 0000 80BB 0000 0600 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0200 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0100 0000
0000 0000 0000 0000 0000 0000 0000 0000

I have shown in bold what seem to be 2x sets of bit rate values (24 bit) and 1x sample rate value (48 kHz).

I’m not sure if all audio properties are set correctly, but it seems as though I need to set ‘ch_layout’, ‘sample_rate’ and ‘bit_rate’ so I can apply these settings to the codec context and read each frame.

If the two ‘1800 0000’ are ‘bits_per_coded_sample’ and ‘bits_per_raw_sample’ then does anyone see how ‘bit_rate’ stored before these two values could be set to ‘0028 2300 0000 0000’ ? I’m assuming this value would be stored in 8 bytes being a ‘int64_t’.

Any help would be much appreciated.

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 3852

Trending Articles