This repository has been archived on 2026-10-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
barn/docs/ffmpeg.md
T
Daniel SamsonandClaude Opus 4.5 3b5c796afd docs: add FFmpeg integration guide
Explains FFmpeg's stdout/stderr behavior (progress goes to stderr by design),
exit codes, recommended flags, and monitoring patterns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 09:58:54 +00:00

2.8 KiB

FFmpeg Integration Guide

This guide covers FFmpeg-specific behavior when running jobs with Barn.

Output Streams (stdout vs stderr)

Important: FFmpeg outputs progress and status information to stderr, not stdout. This is by design.

Why FFmpeg Uses stderr

FFmpeg is designed to support piping video data through stdout:

# Example: pipe video to another command
ffmpeg -i input.mp4 -f mp4 - | another_command

To make this work, FFmpeg sends:

  • stdout: Raw video/audio data (when outputting to - or pipe)
  • stderr: All informational messages (version, configuration, progress, warnings, errors)

What This Means for Barn

When you run an FFmpeg job with Barn:

barn run -- ffmpeg -i input.mkv -c:v libx264 output.mp4

The logs will show:

  • stdout.log: Empty (video goes to output file)
  • stderr.log: All FFmpeg output (version info, progress, statistics)

Example barn describe --logs output:

{
  "logs": {
    "stdout": "",
    "stderr": "ffmpeg version 7.0...\nframe=1000 fps=120 q=28.0 size=50000kB..."
  }
}

This is correct behavior, not a bug.

Common FFmpeg Patterns

Transcoding to File

barn run --tag=transcode -- ffmpeg -y -i input.mkv -c:v libx264 -crf 23 output.mp4
  • stdout: empty
  • stderr: progress and statistics

Hardware-Accelerated Encoding (macOS)

barn run --tag=transcode -- ffmpeg -y -i input.mkv -c:v h264_videotoolbox -b:v 4M output.mp4

Analyzing Media with ffprobe

barn run --tag=analyze -- ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
  • stdout: JSON output (when using -print_format json)
  • stderr: errors only (when using -v quiet)

Monitoring FFmpeg Jobs

To watch FFmpeg progress in real-time:

# Watch the stderr log
tail -f /tmp/barn/jobs/<job-id>/logs/stderr.log

# Or use barn describe with --logs
watch -n 2 'barn describe <job-id> --logs --output=json | jq .logs.stderr'

FFmpeg Exit Codes

Exit Code Meaning
0 Success
1 Generic error (check stderr for details)
69 Invalid data in input
183 Output file already exists (use -y to overwrite)
ffmpeg \
  -y                    # Overwrite output without asking
  -threads 0            # Auto-detect optimal thread count
  -progress pipe:2      # Send progress to stderr (default)
  -stats                # Show encoding statistics
  -loglevel info        # Show info level logs (default)
  input.mp4 output.mp4

Suppressing FFmpeg Output

If you want minimal output:

ffmpeg -y -loglevel error -i input.mp4 output.mp4

Or for completely silent operation:

ffmpeg -y -loglevel quiet -i input.mp4 output.mp4

Note: Even with -loglevel quiet, fatal errors still go to stderr.