Skip to content

refactor(audio_processing): replace pipe with temp files for FFmpeg p…#37127

Draft
joeyhacker wants to merge 1 commit intohuggingface:mainfrom
joeyhacker:main
Draft

refactor(audio_processing): replace pipe with temp files for FFmpeg p…#37127
joeyhacker wants to merge 1 commit intohuggingface:mainfrom
joeyhacker:main

Conversation

@joeyhacker
Copy link
Copy Markdown

…rocessing

This change replaces the previous pipe-based FFmpeg audio decoding approach
with temporary file operations to improve reliability, especially for
container formats like MP4/m4a.

Key reasons for this change:
1. MP4 container format requires random access to metadata (moov atoms) which is often located at the end of the file. Pipe streaming makes this access pattern impossible.
2. FFmpeg's format detection works more reliably with physical files compared to streamed input via pipes.
3. Temporary files provide better error diagnostics since the input can be preserved for debugging when failures occur.
4. Some FFmpeg codecs and filters behave differently with pipe input versus file input due to buffering differences.

The new implementation:
- Creates properly named temporary files with correct extensions
- Uses atomic write operations with flush()
- Implements comprehensive cleanup in finally blocks
- Provides better error messages when failures occur

This fixes issues with partial file errors ("offset 0x3f9: partial file")
that occurred during demuxing of m4a files in the pipe-based approach

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

…rocessing

This change replaces the previous pipe-based FFmpeg audio decoding approach
    with temporary file operations to improve reliability, especially for
    container formats like MP4/m4a.

    Key reasons for this change:
    1. MP4 container format requires random access to metadata (moov atoms)
       which is often located at the end of the file. Pipe streaming makes
       this access pattern impossible.
    2. FFmpeg's format detection works more reliably with physical files
       compared to streamed input via pipes.
    3. Temporary files provide better error diagnostics since the input can
       be preserved for debugging when failures occur.
    4. Some FFmpeg codecs and filters behave differently with pipe input
       versus file input due to buffering differences.

    The new implementation:
    - Creates properly named temporary files with correct extensions
    - Uses atomic write operations with flush()
    - Implements comprehensive cleanup in finally blocks
    - Provides better error messages when failures occur

    This fixes issues with partial file errors ("offset 0x3f9: partial file")
    that occurred during demuxing of m4a files in the pipe-based approach
@github-actions github-actions Bot marked this pull request as draft March 31, 2025 05:51
@github-actions
Copy link
Copy Markdown
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@Rocketknight1
Copy link
Copy Markdown
Member

I think this makes sense for pipelines and I agree that media files often require seeking that is incompatible with piping/streaming. cc @eustlb for audio, WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants