shahen94 / react-native-video-processing

Native Video editing/trimming/compressing :movie_camera: library for React-Native
https://shahen94.github.io/react-native-video-processing/
MIT License
1.25k stars 327 forks source link

[Android] Low quality of getFrameAt #61

Closed kesha-antonov closed 7 years ago

kesha-antonov commented 7 years ago

Hello, @shahen94 !

I'm working on some features for this lib right now.

When do I try to get preview of video as image I see it in a low quality. Do you have thoughts how to improve this?

I searched for MediaMetadataRetriever. And appears that it has low quality when capturing frame if I'm not mistaken.

They advice to use MediaCoder: http://stackoverflow.com/questions/31789609/android-bitmap-compress-poor-quality-with-png-format

Also I found that is possible to set config for generated bitmap. But it's commented out in FFMpeg library: https://github.com/wseemann/FFmpegMediaMetadataRetriever/blob/6c3be9da13252a8333958feda8a6df29e0502d28/gradle/fmmr-library/library/src/main/java/wseemann/media/FFmpegMediaMetadataRetriever.java#L562-L568

Have you tried to generate image previews in good quality?

shahen94 commented 7 years ago

Hi @kesha-antonov.

I've didn't paid attention to that. But now i just checked that out and see that it's producing images with low quality.

Probably the right way is to use FFMPEG for android. It's a fastest way, and full configurable.

We have it in Roadmap, so using it now definitely will give you more control over videos http://writingminds.github.io/ffmpeg-android-java/

kesha-antonov commented 7 years ago

OK.

So now this lib is using this package: https://github.com/wseemann/FFmpegMediaMetadataRetriever

And in roadmap we have to change to this lib: http://writingminds.github.io/ffmpeg-android-java/

Is it correct?

I'm a beginner in android dev so not familiar with "packages"

shahen94 commented 7 years ago

Correct - here's the list of android dependencies https://github.com/shahen94/react-native-video-processing/blob/master/android/build.gradle#L22

kesha-antonov commented 7 years ago

Great!

Thank you! @shahen94 I will experiment with that and send PR on success

shahen94 commented 7 years ago

Cool ! Thank you. I'll keep this thread open, so ping me if you'll need help.

kesha-antonov commented 7 years ago

@shahen94

I was able to link FFmpeg and process file with it but it left file the same. FFmpeg did not change anything. In my case I used "crop" command

Seems like it's because http://writingminds.github.io/ffmpeg-android-java/ is outdated (1 year passed since last update. ffmpeg v. 3.0.1 or something. I forgot where I saw it)

So next step is to build new FFmpeg (3.3) https://ffmpeg.org/download.html And we can do it with: 1) this: https://github.com/WritingMinds/ffmpeg-android 2) or this: https://github.com/icctv/ffmpeg-android

But I'm getting errors. Can you help with that?

We need this http://writingminds.github.io/ffmpeg-android-java/ but with ffmpeg v3.3 (latest).

kesha-antonov commented 7 years ago

My last commit with android and "crop": https://github.com/kesha-antonov/react-native-video-processing/commit/dae3b5862a29c74d81d7231a9e149eca710763e2

All changes: https://github.com/shahen94/react-native-video-processing/compare/master...kesha-antonov:master

shahen94 commented 7 years ago

What the error do you get ?

kesha-antonov commented 7 years ago
config.mk:25: builds/unix/unix-def.mk: No such file or directory
config.mk:26: builds/unix/unix-cc.mk: No such file or directory
make: execvp: ./include/freetype/freetype.h: Permission denied
make: *** No rule to make target `builds/unix/unix-cc.mk'.  Stop.
./autogen.sh: line 102: aclocal: command not found
./autogen.sh: line 55: test: 1: unary operator expected
./autogen.sh: line 59: test: 1: unary operator expected
./autogen.sh: line 67: test: 10: unary operator expected
./autogen.sh: line 71: test: 10: unary operator expected
generating `configure.ac'
running `aclocal -I . --force'
./autogen.sh: line 15: aclocal: command not found
error while running `aclocal -I . --force'

FreeType build system -- automatic system detection

If this does not correspond to your system or settings please remove the file
`config.mk' from this directory then read the INSTALL file for help.

/bin/sh: ./configure: No such file or directory
make: *** [setup] Error 127

We need something like this PR: https://github.com/WritingMinds/ffmpeg-android-java/pull/70/files But I didn't understand how to build these packages for now.

And seems like those scripts is meant for ubuntu. I'm on mac https://github.com/WritingMinds/ffmpeg-android

I'll try to build script by script a little bit later.

kesha-antonov commented 7 years ago

Ok. I've pasted that error. I think I'll be able to build it tomorrow

shahen94 commented 7 years ago

Great. @kesha-antonov sorry for slow reply. I'm little bit busy tomorrow, but will try to find time and figure out what's the error is it

kesha-antonov commented 7 years ago

Yeah, no problem!

As I said I was able to almost build it. And I think if all OK I'll build it myself. I'll write later about results

kesha-antonov commented 7 years ago

Ok. I've built it 1) Fixed scripts to make the build: https://github.com/kesha-antonov/ffmpeg-android 2) Replaces bins: https://github.com/kesha-antonov/ffmpeg-android-java

Maybe we need something more to change in ffmpeg-android-java?

kesha-antonov commented 7 years ago

Do you know where to upload https://github.com/kesha-antonov/ffmpeg-android-java to get it from build.gradle?

kesha-antonov commented 7 years ago

@shahen94 I've tried jitpack but it always gives error. I'm not familiar with java packages so "walking in the dark" right now. Maybe you have some experience with jitpack?

A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApk'.
   > A problem occurred configuring project ':react-native-video-processing'.
      > Could not resolve all dependencies for configuration ':react-native-video-processing:_debugPublishCopy'.
         > Could not find com.github.kesha-antonov:ffmpeg-android-java:bb79034f60af0a614430b4e0ab100c0fcb5b4d27.

build.gradle:

apply plugin: 'com.android.library'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.1"

  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    ndk {
      abiFilters "armeabi-v7a", "x86"
    }
  }
  lintOptions {
    warning 'InvalidPackage'
  }
}

allprojects {
  repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
  }
}

configurations.all {
  resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

dependencies {
  compile 'com.facebook.react:react-native:0.20.+'
  compile 'com.yqritc:android-scalablevideoview:1.0.4'
  compile 'com.googlecode.mp4parser:isoparser:1.1.20'
  compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
  compile 'com.github.kesha-antonov:ffmpeg-android-java:e69ea470d69d271fafbd03d0a4b0ea67d6731ccc'
}
shahen94 commented 7 years ago

It's ok, it can't compile your patched repository from github. You have to publish it to jcenter . Please take a look this article. It describes how to publish and compile gradle dependencies https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

kesha-antonov commented 7 years ago

But jitpack is meant to use repositories from Github: https://jitpack.io/

So no need to push to jcenter

kesha-antonov commented 7 years ago

Anyway I'm stuck here(

Need your help! @shahen94

shahen94 commented 7 years ago

I see. i haven't experience with jitpack, but will try to take a look this in the evening. If you have time watch this, the full introduction how to publish to jitpack.

https://www.youtube.com/watch?v=RYiZZprUNJw

kesha-antonov commented 7 years ago

Cool! Thanks!

Yeah, I'll watch. Will report if have any other results

kesha-antonov commented 7 years ago

Ok. I was able to build it after adding

allprojects {
  repositories {
    maven { url "https://jitpack.io" }
  }
}

to myproject/android/app/build.gradle

Not sure why it's needed though. I have this already in RN-video-processing/build.gradle

shahen94 commented 7 years ago

You need to point from where he should lookup dependencies, so no problem, add it if it will solve problem with install.

kesha-antonov commented 7 years ago

Seems like new ffmpeg working but not cropping anything. Tested locally on my mac: all OK

Must be something with android filesystem. Maybe I declare output file wrong somehow

https://github.com/kesha-antonov/react-native-video-processing/blob/master/android/src/main/java/com/shahenlibrary/Trimmer/Trimmer.java#L322-L332

Logs:

05-02 10:31:20.771  8277  8306 D cropWidth: 249
05-02 10:31:20.771  8277  8306 D cropHeight: 312
05-02 10:31:20.771  8277  8306 D cropOffsetX: 0
05-02 10:31:20.771  8277  8306 D cropOffsetY: 4
05-02 10:31:20.772  8277  8306 D RNTrimmerManager: [-y, -i, file:///storage/emulated/0/Download/video.mp4, -vf, crop=249:312:0:4, -strict, -2, file:///data/user/0/app/cache/b0ee3d95-4de8-4764-aea5-c8c9dca75001-screenshot1415758942.mp4]
05-02 10:31:20.772  8277  8306 D RNTrimmerManager: crop: onStart
...
05-02 10:31:36.740  8277  8277 D RNTrimmerManager: crop: onSuccess
05-02 10:31:36.741  8277  8277 D RNTrimmerManager: crop: onFinish
05-02 10:31:36.742  8277  8305 I ReactNativeJS: file:///data/user/0/app/cache/b0ee3d95-4de8-4764-aea5-c8c9dca75001-screenshot1415758942.mp4

Any thoughts? @shahen94

I've tried tempFile.getPath() and "file://" + tempFile.getPath()

shahen94 commented 7 years ago

@gevorg94 can you please take a look why it doesn't crop properly ?

shahen94 commented 7 years ago

@kesha-antonov can you please run -version only to see is FFMPEG installed and working or not

shahen94 commented 7 years ago

@kesha-antonov can you please try to set path without file:// like this /storage/emulated/0/Download/videofile.mp4 Also take look how we generate file with folders https://github.com/shahen94/react-native-video-processing/blob/master/android/src/main/java/com/shahenlibrary/utils/VideoEdit.java#L86

kesha-antonov commented 7 years ago

Ok. I did it. All works now

Will send PR with latest changes

shahen94 commented 7 years ago

@kesha-antonov You're great, thanks !

shauravg commented 6 years ago

I am still seeing this issue. The frame previews that are generated for the trimmer bar are very low quality and make it hard for the user to know what exactly they are trimming out.

khattab93 commented 4 years ago

Inside Trimmer.java, there is a method called getPreviewImages, I increased the resizeWidth value from 200 to 800 and the quality is increased.