main.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import 'dart:io';
  2. import 'package:dio/dio.dart';
  3. import 'package:flutter/material.dart';
  4. import 'dart:async';
  5. import 'package:flutter/services.dart';
  6. import 'package:fffmpeg/fffmpeg.dart';
  7. import 'package:path_provider/path_provider.dart';
  8. void main() {
  9. runApp(MyApp());
  10. }
  11. class MyApp extends StatefulWidget {
  12. @override
  13. _MyAppState createState() => _MyAppState();
  14. }
  15. class _MyAppState extends State<MyApp> {
  16. String _platformVersion = 'Unknown';
  17. @override
  18. void initState() {
  19. super.initState();
  20. initPlatformState();
  21. initss();
  22. }
  23. // Platform messages are asynchronous, so we initialize in an async method.
  24. Future<void> initPlatformState() async {
  25. String platformVersion;
  26. // Platform messages may fail, so we use a try/catch PlatformException.
  27. try {
  28. platformVersion = await Fffmpeg.platformVersion;
  29. } on PlatformException {
  30. platformVersion = 'Failed to get platform version.';
  31. }
  32. // If the widget was removed from the tree while the asynchronous platform
  33. // message was in flight, we want to discard the reply rather than calling
  34. // setState to update our non-existent appearance.
  35. if (!mounted) return;
  36. setState(() {
  37. _platformVersion = platformVersion;
  38. });
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return MaterialApp(
  43. home: Scaffold(
  44. floatingActionButton: FloatingActionButton(
  45. onPressed: ()async{
  46. String http="http://139.199.153.108:8080/test.mp4";
  47. String img="http://139.199.153.108:8080/tomcat.png";
  48. Directory temporaryDirectory =await getTemporaryDirectory();
  49. String sss= temporaryDirectory.path+"/test.mp4";
  50. String sss_img= temporaryDirectory.path+"/sss_img.png";
  51. if(!await File(sss).exists()){
  52. await Dio().download(http, sss,onReceiveProgress: (int2,int1){
  53. print("int===="+int2.toString()+"===="+int1.toString());
  54. });
  55. }
  56. if(!await File(sss_img).exists()){
  57. await Dio().download(img, sss_img);
  58. }
  59. input=sss;
  60. output= temporaryDirectory.path+"/test_water4.mp4";
  61. logo=sss_img;
  62. print("ok");
  63. String ss=input+","+output;
  64. // addWaterMask(input, output).then((value) => print("========"+value.toString()));
  65. Fffmpeg.addWatermarkToVedio(input, output, logo, WaterMarkPosition.LeftBottom);
  66. // Fffmpeg.exeCommand(ss);
  67. },
  68. ),
  69. appBar: AppBar(
  70. title: const Text('Plugin example app'),
  71. ),
  72. body: Center(
  73. child: Text('Running on: $_platformVersion\n'),
  74. ),
  75. ),
  76. );
  77. }
  78. static String logo="/storage/emulated/0/aa_flutter/logo.jpeg";
  79. static String input="/storage/emulated/0/aa_flutter/test.mp4";
  80. static String output="/storage/emulated/0/aa_flutter/test_water.mp4";
  81. //传个图片,能设定宽高和四个角落
  82. static Future addWaterMask(String inputPath,String outputPath)async{
  83. // await _addLogoTodisk();
  84. // String s = await _getWaterMaskPath();
  85. // await File(outputPath).create();
  86. //处理完返回路径吧
  87. return await Fffmpeg.addWatermarkToVedio(input,output,logo,WaterMarkPosition.LeftBottom);
  88. }
  89. initss()async{
  90. if(Platform.isIOS){
  91. Directory temporaryDirectory =await getTemporaryDirectory();
  92. String sss= temporaryDirectory.path+"/test.mp4";
  93. String sss_img= temporaryDirectory.path+"/sss_img.png";
  94. input=sss;
  95. output= temporaryDirectory.path+"/test_water.mp4";
  96. logo=sss_img;
  97. print("init_ok");
  98. }
  99. }
  100. }