> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# Extract audio from video

[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/audio/audio-extract-from-video.ipynb)  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/audio/audio-extract-from-video.ipynb)  [![Download Notebook](https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue)](https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/cookbooks/audio/audio-extract-from-video.ipynb)

> [!TIP]
>
> This documentation page is also available as an interactive notebook. You can launch the notebook in
> Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
> above links.

Extract the audio track from video files for transcription, analysis, or
processing.

## Problem

You have video files but need to work with just the audio track—for
transcription, speaker analysis, or audio processing. Extracting audio
manually with ffmpeg is tedious and doesn’t integrate with your data
pipeline.

## Solution

**What’s in this recipe:**

* Extract audio from video as a computed column
* Choose audio format (mp3, wav, flac)
* Chain with transcription for automatic video-to-text

You use the `extract_audio` function to create an audio column from
video. This integrates seamlessly with transcription and other audio
processing.

### Setup

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
%pip install -qU pixeltable 'numpy<2.4'
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt
from pixeltable.functions.video import extract_audio

# Create a fresh directory
pxt.drop_dir('audio_extract_demo', force=True)
pxt.create_dir('audio_extract_demo')
```

<pre>
  Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
  Created directory 'audio\_extract\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x1061fc510>
</pre>

### Extract audio from video

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Create table for videos
videos = pxt.create_table(
    'audio_extract_demo/videos', {'title': pxt.String, 'video': pxt.Video}
)
```

<pre>
  Created table 'videos'.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Add computed column to extract audio as MP3
videos.add_computed_column(
    audio=extract_audio(videos.video, format='mp3')
)
```

<pre>
  Added 0 column values with 0 errors.
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Insert a sample video (from multimedia-commons with audio)
video_url = 's3://multimedia-commons/data/videos/mp4/ffe/ffb/ffeffbef41bbc269810b2a1a888de.mp4'

videos.insert([{'title': 'Sample Video', 'video': video_url}])
```

<pre>
  Inserting rows into \`videos\`: 1 rows \[00:00, 207.52 rows/s]
  Inserted 1 row with 0 errors.
  1 row inserted, 4 values computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View results
videos.select(videos.title, videos.audio).collect()
```

### Chain with transcription

Add transcription as a follow-up computed column:

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Install whisper for transcription
%pip install -qU openai-whisper
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
from pixeltable.functions import whisper

# Add transcription of the extracted audio
videos.add_computed_column(
    transcription=whisper.transcribe(videos.audio, model='base.en')
)
```

<pre>
  Added 1 column value with 0 errors.
  1 row updated, 1 value computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Extract the transcript text
videos.add_computed_column(transcript=videos.transcription.text)
```

<pre>
  Added 1 column value with 0 errors.
  1 row updated, 1 value computed.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# View the full pipeline results
videos.select(videos.title, videos.transcript).collect()
```

## Explanation

**Audio format options:**

**Pipeline flow:**

<pre>
  Video → extract\_audio → Audio → whisper.transcribe → Transcript
</pre>

Each step is a computed column. When you insert a new video:

1. Audio is extracted automatically
2. Whisper transcribes the audio
3. All results are cached for future queries

## See also

* [Transcribe
  audio](https://docs.pixeltable.com/howto/cookbooks/audio/audio-transcribe.md) -
  Audio-only transcription
* [Summarize
  podcasts](https://docs.pixeltable.com/howto/cookbooks/audio/audio-summarize-podcast.md) -
  Transcribe and summarize
* [Extract video
  frames](https://docs.pixeltable.com/howto/cookbooks/video/video-extract-frames.md) -
  Work with video frames


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.