Open delfme opened 1 year ago
I just compared FFmpeg and Swift native on macOS and FFmpeg is on average 10X slower for video compression. I was using media_tool_flutter which is a little faster than __light_compressor__ in my tests.
@delfme, do you have better results or why you avoid the native iOS version?
@starkdmi sorry this got lost. Isn't https://github.com/starkdmi/media_tool_flutter slow on android due to lack of native implementation?
@starkdmi for us ffmpeg is slow only on android, it depends on the command you are using to compress video.
@delfme yes, media_tool supports ios/mac only as for now, ffmpeg was a temporary fix for other platforms but no real demand here. As for compression options of light_compressor package, isn't videoBitrateInMbps
sufficient for your case?
If you are using ffmpeg I suggest you to try hevc_mediacodec and hevc_videotoolbox codecs for hardware accelerated encoding.
Yes indeed this was our workaround. But we noticed that the compressed video are not loaded quicly from player (kind of something corrupting the idea). We tested with the same file uncompressed and compressed and the compressed one needs 3-4sec to initialize.
What performance are you achieving on android with ffmpeg and hevc_mediacodec and hevc_videotoolbox codecs? Can you please write here how to use the codecs? This is our command: String command = "-i $_filePath -c:v libx264 -crf 23 -preset veryfast -g 12 -r 25 $outputPath";
@delfme, to try those codecs:
Use:
ffmpeg -hide_banner -loglevel error -i $_filePath -c:v h264_videotoolbox -crf 23 -preset veryfast -g 12 -r 25 -movflags +faststart $outputPath
ffmpeg -hide_banner -loglevel error -i $_filePath -c:v hevc_videotoolbox -tag:v hvc1 -crf 28 -preset veryfast -g 12 -r 25 -movflags +faststart $outputPath
For HEVC add -tag:v hvc1
, and use crf about 28 for same quality as H.264 with 23.
For faster playback start time you can try adding -movflags +faststart
. Try running ffmpeg -i input.mp4 -c copy -movflags +faststart output.mp4
on compressed files to see if -movflags +faststart
helps with yours 3-4 sec delay.
Note that hardware accelerated codecs could provide worse results, and aren't always faster but more efficient, adjust your quality if needed.
Thx will try those ones. Did you try unltrafast without r and g, and crt 28? It is fast on our side.
String command = "-i $_filePath -c:v libx264 -crf 28 -preset ultrafast $outputPath";
@delfme ultrafast produce larger files, I prefer default presets, you could just lower quality for playback on mobiles (via crf). There is also libx265 for you to try. I do not use g (keyframe interval), r (frame rate) under 30 is a good choice (excluding slo-mo).
Hello, We are testing the plugin and like it very much.
However, to get better results for our use case, we would need to set compression options.
For example, let's us consider an input File with size: 13.66MB
On iOS, FFMPEG is fast:
result is 3.96MB in 2.5 sec, which is our reference
With veryfast preset and below settings for -g and -r String command = "-i $_filePath -c:v libx264 -crf 23 -preset veryfast -g 12 -r 25 $outputPath";On Android (mid-end phone) , it performs poorly, mostly due to Dart:
5.81MB in 6.39 sec
On Android with LightCompressor, we get better results than FFMPEG:
high quality:: 6.10MB compression time: 4.5 sec