# Audio exports

> Extract AAC audio from a video or audio Source and save it in an M4A file.

Select `m4a_aac` to create an audio-only file from a Source that contains audio. Video Sources and audio-only Sources use the same request.

Defaults are 128000 bits per second, 48000 Hz, and two channels. Set `audio_bitrate`, `audio_samplerate`, and `channels` when you need different audio settings.

## Create an M4A transcode

Run these examples on your server after [setting up your SDK and Source](/docs/transcoding/quickstart#before-you-begin). Replace the token and Source ID.

These examples save the file in your Project's output storage. Set `storage.path` to the filename you want to use.

<ignore>
SDK publication check: drafted from api/openapi.json and existing SDK conventions. Add Transcodings models, create/retrieve/list/cancel/delete mappings, pagination and data unwrapping to the owning SDK generator configuration. Verify generated method names and Go union/format/storage types in TypeScript, Python, PHP and Go before publication.
</ignore>

<codegroup>
<codeblock lang="TypeScript">
```typescript
import Chunkify from '@chunkify/chunkify';

async function main() {
    const client = new Chunkify({
        projectAccessToken: 'My Project Access Token',
    });

    const transcoding = await client.transcodings.create({
        source_id: 'src_2G6MJiNz71bHQGNzGwKx5cJwPFS',
        format: {
            id: "m4a_aac",
            audio_bitrate: 128000,
        },
        storage: {
            path: 'exports/audio.m4a',
        },
    });

    console.log(transcoding.id, transcoding.status);
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});
```
</codeblock>
<codeblock lang="Python">
```python
from chunkify import Chunkify

client = Chunkify(
    project_access_token="My Project Access Token",
)

transcoding = client.transcodings.create(
    source_id="src_2G6MJiNz71bHQGNzGwKx5cJwPFS",
    format={
        "id": "m4a_aac",
        "audio_bitrate": 128000,
    },
    storage={
        "path": "exports/audio.m4a",
    },
)

print(transcoding.id, transcoding.status)
```
</codeblock>
<codeblock lang="PHP">
```php
<?php

use Chunkify\Client;

require_once __DIR__ . '/vendor/autoload.php';

$client = new Client(
    projectAccessToken: 'My Project Access Token',
);

$transcoding = $client->transcodings->create(
    sourceID: 'src_2G6MJiNz71bHQGNzGwKx5cJwPFS',
    format: [
        'id' => 'm4a_aac',
        'audio_bitrate' => 128000,
    ],
    storage: [
        'path' => 'exports/audio.m4a',
    ],
);

var_dump($transcoding->id, $transcoding->status);
```
</codeblock>
<codeblock lang="Go">
```go
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/chunkifydev/chunkify-go"
	"github.com/chunkifydev/chunkify-go/option"
)

func main() {
	client := chunkify.NewClient(
		option.WithProjectAccessToken("My Project Access Token"),
	)

	transcoding, err := client.Transcodings.New(
		context.Background(),
		chunkify.TranscodingNewParams{
			SourceID: "src_2G6MJiNz71bHQGNzGwKx5cJwPFS",
			Format: chunkify.TranscodingNewParamsFormatUnion{
				OfM4aAac: &chunkify.TranscodingM4aAacParam{
					AudioBitrate: chunkify.Int(128000),
				},
			},
			Storage: chunkify.TranscodingNewParamsStorage{
				Path: chunkify.String("exports/audio.m4a"),
			},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(transcoding.ID, transcoding.Status)
}
```
</codeblock>
</codegroup>

## Select an interval

Use `seek` and `duration` to export part of the Source. The accepted interval is aligned to audio samples and capped at the Source end. It must retain at least 0.001 seconds.

The response omits video dimensions, video codec, and video encoding progress for audio-only output. Follow `status` and `processing_stage`, then read the published `files` collection.

## Audio-only selection from a video format

Setting `disable_video: true` on a video format also resolves to AAC M4A. Its output filename must end in `.m4a`. Omit video-specific settings, including dimensions, per-title optimization, CRF, and video bitrate.

## Encoding parameters

<openapi-schema schema="#/components/schemas/TranscodingM4aAac"></openapi-schema>
