Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter ffmpeg plugin

ffmpeg plugin for flutter. supports ios and android.

1. features

  • based on mobileffmpeg
  • supports
    • both android and ios
    • ffmpeg v4.2-dev-x (master) releases
    • arm-v7a, arm-v7a-neon, arm64-v8a, x86 and x86_64 architectures on android
    • armv7, armv7s, arm64, arm64e, i386 and x86_64 architectures on ios
    • 24 external libraries

      fontconfig, freetype, fribidi, gmp, gnutls, kvazaar, lame, libaom, libass, libiconv, libilbc, libtheora, libvorbis, libvpx, libwebp, libxml2, opencore-amr, opus, shine, snappy, soxr, speex, twolame, wavpack

    • 4 external libraries with gpl license

      vid.stab, x264, x265, xvidcore

    • zlib and mediacodec android system libraries
    • bzip2, zlib ios system libraries and audiotoolbox, coreimage, videotoolbox, avfoundation ios system frameworks
  • licensed under lgpl 3.0, can be customized to support gpl v3.0
  • includes eight different packages with different external libraries enabled in ffmpeg plugin
min min-gpl https https-gpl audio video full full-gpl
external libraries vid.stab
x264
x265
xvidcore
gmp
gnutls
gmp
gnutls
vid.stab
x264
x265
xvidcore
lame
libilbc
libvorbis
opencore-amr
opus
shine
soxr
speex
twolame
wavpack
fontconfig
freetype
fribidi
kvazaar
libaom
libass
libiconv
libtheora
libvpx
libwebp
snappy
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus
shine
snappy
soxr
speex
twolame
wavpack
fontconfig
freetype
fribidi
gmp
gnutls
kvazaar
lame
libaom
libass
libiconv
libilbc
libtheora
libvorbis
libvpx
libwebp
libxml2
opencore-amr
opus
shine
snappy
soxr
speex
twolame
vid.stab
wavpack
x264
x265
xvidcore
android system libraries zlib
mediacodec
ios system libraries zlib
audiotoolbox
avfoundation
coreimage
videotoolbox
bzip2

2. installation

add flutter_ffmpeg as a dependency in your pubspec.yaml file.

2.1 packages

installation of flutterffmpeg using pub enables the default package, which is based on https package of lts release. it is possible to enable other packages using the following steps.

  1. use the following dependency block in your pubspec.yaml file.
    dependencies:
      flutter_ffmpeg:
        git:
          url: git://github.com/tanersener/flutter-ffmpeg.git
          ref: v0.1.1
          path: packages/flutter_ffmpeg_https
    
    
  2. update version in ref: argument.
  3. set package name in path: packages/flutter_ffmpeg_<package name>[_lts] section. include _lts postfix only if you want to depend on an lts release.

2.2 lts releases

flutter_ffmpeg is published in two different variants: main release and lts release. both releases share the same source code but is built with different settings. below you can see the changes between the two.

main release lts release
android api level 24 21
android camera access x
android architectures arm-v7a-neon
arm64-v8a
x86
x86-64
arm-v7a
arm-v7a-neon
arm64-v8a
x86
x86-64
ios sdk 12.1 9.3
xcode support 10.1 7.3.1
ios architectures arm64
arm64e
x86-64
armv7
arm64
i386
x86-64

3. using

  1. execute commands.
    • use execute() method with a single command line
    import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
    
    final flutterffmpeg _flutterffmpeg = new flutterffmpeg();
    
    _flutterffmpeg.execute("-i file1.mp4 -c:v mpeg4 file2.mp4").then((rc) => print("ffmpeg process exited with rc $rc"));
    
    • use executewitharguments() method with an array of arguments
    import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
    
    final flutterffmpeg _flutterffmpeg = new flutterffmpeg();
    
    var arguments = ["-i", "file1.mp4", "-c:v", "mpeg4", "file2.mp4"];
    _flutterffmpeg.executewitharguments(arguments).then((rc) => print("ffmpeg process exited with rc $rc"));
    
  2. check execution output. zero represents successful execution, non-zero values represent failure.
    _flutterffmpeg.getlastreturncode().then((rc) => print("last rc: $rc"));
    
    _flutterffmpeg.getlastcommandoutput().then((output) => print("last command output: $output"));
    
  3. stop an ongoing operation. note that this function does not wait for termination to complete and returns immediately.
    _flutterffmpeg.cancel();
    
  4. get media information for a file.
    • print all fields
    _flutterffmpeg.getmediainformation("<file path or uri>").then((info) => print(info));
    
    • print selected fields
    _flutterffmpeg.getmediainformation("<file path or uri>").then((info) {
        print("media information");
    
        print("path: ${info['path']}");
        print("format: ${info['format']}");
        print("duration: ${info['duration']}");
        print("start time: ${info['starttime']}");
        print("bitrate: ${info['bitrate']}");
    
        if (info['streams'] != null) {
            final streamsinfoarray = info['streams'];
    
            if (streamsinfoarray.length > 0) {
                for (var streamsinfo in streamsinfoarray) {
                    print("stream id: ${streamsinfo['index']}");
                    print("stream type: ${streamsinfo['type']}");
                    print("stream codec: ${streamsinfo['codec']}");
                    print("stream full codec: ${streamsinfo['fullcodec']}");
                    print("stream format: ${streamsinfo['format']}");
                    print("stream full format: ${streamsinfo['fullformat']}");
                    print("stream width: ${streamsinfo['width']}");
                    print("stream height: ${streamsinfo['height']}");
                    print("stream bitrate: ${streamsinfo['bitrate']}");
                    print("stream sample rate: ${streamsinfo['samplerate']}");
                    print("stream sample format: ${streamsinfo['sampleformat']}");
                    print("stream channel layout: ${streamsinfo['channellayout']}");
                    print("stream sar: ${streamsinfo['sampleaspectratio']}");
                    print("stream dar: ${streamsinfo['displayaspectratio']}");
                    print("stream average frame rate: ${streamsinfo['averageframerate']}");
                    print("stream real frame rate: ${streamsinfo['realframerate']}");
                    print("stream time base: ${streamsinfo['timebase']}");
                    print("stream codec time base: ${streamsinfo['codectimebase']}");
                }
            }
        }
    
    
  5. enable log callback and redirect all ffmpeg logs to a console/file/widget.
    void logcallback(int level, string message) {
        print(message);
    }
    ...
    _flutterffmpeg.enablelogcallback(this.logcallback);
    
  6. enable statistics callback and follow the progress of an ongoing operation.
    void statisticscallback(int time, int size, double bitrate, double speed, int videoframenumber, double videoquality, double videofps) {
        print("statistics: time: $time, size: $size, bitrate: $bitrate, speed: $speed, videoframenumber: $videoframenumber, videoquality: $videoquality, videofps: $videofps");
    }
    ...
    _flutterffmpeg.enablestatisticscallback(this.statisticscallback);
    
  7. poll statistics without implementing statistics callback.
    _flutterffmpeg.getlastreceivedstatistics().then((stats) => print(stats));
    
  8. reset statistics before starting a new operation.
    _flutterffmpeg.resetstatistics();
    
  9. set log level.
    _flutterffmpeg.setloglevel(loglevel.av_log_warning);
    
  10. register your own fonts by specifying a custom fonts directory, so they are available to use in ffmpeg filters.
    _flutterffmpeg.setfontdirectory("<folder with fonts>");
    
  11. use your own fontconfig configuration.
    _flutterffmpeg.setfontconfigconfigurationpath("<fontconfig configuration directory>");
    
  12. disable log functionality of the library. logs will not be printed to console and log callback will be disabled.
    _flutterffmpeg.disablelogs();
    
  13. disable statistics functionality of the library. statistics callback will be disabled but the last received statistics data will be still available.
    _flutterffmpeg.disablestatistics();
    
  14. list enabled external libraries.
    _flutterffmpeg.getexternallibraries().then((packagelist) {
         packagelist.foreach((value) => print("external library: $value"));
    });
    

4. versions

  • 0.1.x releases are based on ffmpeg v4.2-dev and mobileffmpeg v4.2.lts

5. tips

  • you should not use double quotes (“) to define your complex filters or map definitions.
     -filter_complex [0:v]scale=1280:-1[v] -map [v]
    
  • if your commands include unnecessary quotes or space characters your command will fail with no such filter: ' ' errors. please check your command and remove them.
  • enabling proguard on android causes linking errors. please add the following rule inside your proguard-rules.pro file to preserve necessary method names and prevent linking errors.
    -keep class com.arthenica.mobileffmpeg.config {
        native <methods>;
        void log(int, byte[]);
        void statistics(int, float, float, long , int, double, double);
    }
    
  • by default, xcode compresses png files during packaging. if you use .png files in your commands make sure you set the following two settings to no. if one of them is set to yes, your operations may fail with error while decoding stream #0:0: generic error in an external library error.

    png_settings


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.