mpeg 1.0.0 copy "mpeg: ^1.0.0" to clipboard
mpeg: ^1.0.0 copied to clipboard

Spawn ffmpeg and ffprobe from dart:io, probe media metadata, and inspect supported formats.

example/mpeg_example.dart

import 'dart:convert';
import 'dart:io';

import 'package:mpeg/mpeg.dart';

Future<void> main() async {
  if (!await MpegClient.isSupported()) {
    stderr.writeln(
      'ffmpeg/ffprobe are not available on PATH. Install FFmpeg first.',
    );
    exitCode = 1;
    return;
  }

  final client = MpegClient();
  final ffmpegVersion = await client.getFfmpegVersionInfo();
  final formats = await client.getFormats();
  final supportedVideoInputExtensions = await client
      .getSupportedVideoInputExtensions();
  final supportedVideoOutputExtensions = await client
      .getSupportedVideoOutputExtensions();

  stdout.writeln('Using ${ffmpegVersion.toolName} ${ffmpegVersion.version}');
  stdout.writeln('Parsed ${formats.length} ffmpeg/ffprobe format rows.');
  stdout.writeln(
    'Common supported input video extensions: '
    '${supportedVideoInputExtensions.join(', ')}',
  );
  stdout.writeln(
    'Common supported output video extensions: '
    '${supportedVideoOutputExtensions.join(', ')}',
  );

  final tempDir = await Directory.systemTemp.createTemp('mpeg_example_');
  try {
    final inputFile = File('${tempDir.path}/input.mov');
    final outputFile = File('${tempDir.path}/output.mp4');

    final generateInput = await client.runFfmpeg([
      '-y',
      '-f',
      'lavfi',
      '-i',
      'testsrc=size=320x180:rate=24',
      '-t',
      '1',
      '-pix_fmt',
      'yuv420p',
      '-c:v',
      'mpeg4',
      inputFile.path,
    ]);
    if (generateInput.exitCode != 0) {
      stderr.writeln(generateInput.stderr);
      exitCode = generateInput.exitCode;
      return;
    }

    final transcode = await client.runFfmpeg([
      '-y',
      '-i',
      inputFile.path,
      '-vf',
      'scale=160:90',
      '-c:v',
      'mpeg4',
      outputFile.path,
    ]);
    if (transcode.exitCode != 0) {
      stderr.writeln(transcode.stderr);
      exitCode = transcode.exitCode;
      return;
    }

    final metadata = await client.probeJson(inputPath: outputFile.path);
    stdout.writeln(const JsonEncoder.withIndent('  ').convert(metadata));
  } finally {
    await tempDir.delete(recursive: true);
  }
}
0
likes
150
points
85
downloads

Documentation

API reference

Publisher

verified publisherarcane.art

Weekly Downloads

Spawn ffmpeg and ffprobe from dart:io, probe media metadata, and inspect supported formats.

Repository (GitHub)
View/report issues

License

GPL-3.0 (license)

More

Packages that depend on mpeg