← Back to posts Cover image for Optimizing Video Streaming in Flutter: Cost-Effective Alternatives to Azure and AWS for Media Storage and Delivery

Optimizing Video Streaming in Flutter: Cost-Effective Alternatives to Azure and AWS for Media Storage and Delivery

· 3 min read
Weekly Digest

The Flutter news you actually need

No spam, ever. Unsubscribe in one click.

Chris
By Chris

Building a video streaming app in Flutter is an exciting challenge, but the excitement can quickly fade when your first cloud bill arrives. Services like AWS S3 and Azure Blob Storage are robust, but their pricing models—combining storage, bandwidth (egress), and per-request fees—can become expensive as your user base grows. If you’re seeing costs spiral from every video play and upload, you’re not alone. The good news is there are cost-effective alternatives designed for media.

The core issue often isn’t just the provider, but the combination of unoptimized media and a pricing structure that penalizes scale. Before you switch anything, your first step should be to ensure your video files aren’t larger than they need to be.

Step 1: Optimize Your Media at the Source

A smaller file means less storage used and less data transferred every time it’s streamed.

  • Encode Efficiently: Use modern codecs like H.264/AVC or H.265/HEVC, which can reduce file sizes compared to older codecs at similar quality.
  • Implement Adaptive Bitrate Streaming (ABR): Don’t serve a single 4K file to every user. Use ABR (like HLS or DASH) to create multiple quality renditions. The player automatically selects the best stream for the user’s network. Tools like ffmpeg are essential here.
  • Compress Thoughtfully: Before upload, run videos through compression. Libraries like video_compress for Flutter can help with basic tasks on the client side for user-generated content.

Here’s a Flutter example using video_compress to process a video before upload:

import 'package:video_compress/video_compress.dart';

Future<MediaInfo?> compressAndGetVideoFile(File originalVideo) async {
  // Get thumbnail
  final thumbnail = await VideoCompress.getFileThumbnail(originalVideo.path);

  // Compress the video
  final MediaInfo? mediaInfo = await VideoCompress.compressVideo(
    originalVideo.path,
    quality: VideoQuality.MediumQuality,
    deleteOrigin: false,
    includeAudio: true,
  );

  return mediaInfo;
}

Step 2: Choose a Cost-Effective Storage & CDN Provider

Once your files are optimized, pick a provider with transparent pricing. Look for:

  • Simple, predictable pricing
  • Integrated global CDN
  • Developer-friendly APIs and SDKs

One option is Bunny.net. Their product, Bunny Stream, combines storage, a video CDN, and a built-in encoder to create ABR HLS streams automatically.

Step 3: Integrate with Your Flutter App

Integrating a service like Bunny Stream involves uploads via REST API and playback in Flutter.

For Playback: Use video_player for basic needs or chewie for a polished UI. For HLS/DASH, better_player works well.

Add the package to pubspec.yaml:

dependencies:
  better_player: ^0.0.81

In your widget:

import 'package:better_player/better_player.dart';

class OptimizedVideoPlayer extends StatelessWidget {
  final String hlsMasterPlaylistUrl;

  const OptimizedVideoPlayer({super.key, required this.hlsMasterPlaylistUrl});

  @override
  Widget build(BuildContext context) {
    BetterPlayerConfiguration config = const BetterPlayerConfiguration(
      aspectRatio: 16 / 9,
      fit: BoxFit.contain,
      autoPlay: false,
      looping: false,
    );

    BetterPlayerDataSource dataSource = BetterPlayerDataSource(
      BetterPlayerDataSourceType.network,
      hlsMasterPlaylistUrl,
    );

    return BetterPlayer(
      controller: BetterPlayerController(config, betterPlayerDataSource: dataSource),
    );
  }
}

Common Pitfalls to Avoid

  1. Uploading Raw Files: Always compress and encode first.
  2. Ignoring CDN Geography: Choose a provider with POPs near your audience.
  3. Forgetting Access Control: Use signed URLs or token authentication.
  4. Over-Engineering: You don’t need to build your own transcoding pipeline. Use a service that includes it.

By optimizing your video assets and using a media-focused CDN, you can reduce costs while improving performance.

This blog is produced with the assistance of AI by a human editor. Learn more

Related Posts

Cover image for Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Choosing the Right Storage for Flutter: Beyond SharedPreferences for Persistent Data

Developers frequently struggle with persistent storage in Flutter, especially when dealing with OS-level backups and app reinstalls. This post will clarify the nuances of different storage solutions like `SharedPreferences`, `path_provider`, and `flutter_secure_storage`, focusing on how to correctly manage data lifetimes (per-install vs. per-user) and avoid issues like device IDs migrating to new phones or data being unexpectedly backed up.

Cover image for Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Optimizing Flutter UI Performance: Solving `ImageFiltered` Lag and Smooth Blurring

Flutter's `ImageFiltered` can cause significant lag when blurring large or frequently changing content like text. This post will explain the performance bottlenecks, provide solutions like caching blurred outputs with `RepaintBoundary` or `SnapshotWidget`, and offer practical tips to ensure smooth UI effects without sacrificing frame rates.