Why is it impossible to find Dart Native packages?

I find myself more frequently than not banging my head against the wall trying to find a Dart Native package, whether it be on Google, or Pub.dev. There are hundreds of useless Flutter packages that have not been updated for the past 3 years, and never a valuable Native package.

I have been trying to find a good ffmpeg library to export a thumbnail from an mp4 file, yet the only packages I can find are all iOS & Android only, and last updated 3 years ago.

​

/minor rant over.

​

If anyone has any recommendations for a package than can make a thumbnail out of an mp4 and is available for Dart Native I'd be very appreciative. I know there are quite a few available for Flutter, I have one that I like, but I still need to have feature parity across platforms.

Posted Jan 5, 2022, 1:23 AM UTC

179
HaMMeReD•

Dart native isn't that fast. There is a image library that can encode and save/edit file formats but it's not that fast.

A dart encoder probably wouldn't utilize any hardware accel or anything like that.

If you need to support this feature on native, maybe shelling out to ffmpeg itself is best if that is an option.

8
AndrewcpuOP•

Understood. Thanks for the info!

I might be naive here, but can you explain why ffmpeg is every developers go-to for these types of things? Is it just a well written multi platform library? Is it so well written that it's more than the default, but the only valid option?

3
HaMMeReD•

Best and only choice. Implementing yourself isn't really feasible. FFMPEG seems to get tons of contributions because it's used under the hood practically everywhere.

There hasn't been a huge demand for transcoding or encoding video on mobile since it's kind of resource intensive.

4
ilikecaketoomuch•

If you need to support this feature on native, maybe shelling out to ffmpeg itself is best if that is an option.

indeed, the use case of dart on server side, is the sharing code base with iOS/Mac/Windows/Android client apps. Dart serving up rest is OK, not something I would be proud of. However minor performance improvements have been done over the years. Using FFI / Rust is a common route for process intensive operations.

​

There is some advantage of having a 65% shared code base. For that, dart is king.

1
gbrlsnchs•

FFI might be your friend for this.

3
OrnsteinTheSlayer•

I still consider myself a noob with a lot of this, and someone mentioned FFmpeg already, but for just thumbnails you would probably have a better time writing the native code to interact with OS's video API.

I like FFmpeg, but in my opinion it seems like it's going overboard for just thumbnails, especially because now you have to package and ship your app with it.

Again really just a noob, so I might just be overthinking it.

3
chris37879•

As others have pointed out, doing what you want to do requires interacting with parts of the machine that dart just doesn't currently have a handle on. If FFMPEG has a C api, you _could_ try using FFI to call the functions, but it's hard work dealing with the bindings cause you have to deal with C pointers in dart and dart isn't really made to do that so the code gets ugly fast. There is the ffigen library, but I have not had great success using it to bind existing libraries, but I'm also not really a C expert so maybe I'm just not setting the correct options.

But once it's bound correctly, the Dart API is basically transparent.

3
RandalSchwartz•

If FFMPEG has a C api, you could try using FFI to call the functions,

This has been done more than once. Search the pub for ffmpeg.

2
chris37879•

Probably! I’ve seen a ton of gif bindings on there of varying quality, but it’s nice they exist. I’m currently doing a thin wrapper over a c api that FFI doesn’t like and that I don’t need all of, so I’m getting familiar with it.

1