I'm working on a feature in which I want to add picture over the video and save it to sd card.
in general, the user selects an image with semi-transparent background and puts that image above the video, after the user presses the save button he gets a new video but already with the image above the video.
I have heard about ffmpeg, and saw some commands that are provided by ffmpeg. but I don't know where I should initialize. can anyone provide me an example for the same?
Thank you.
One common approach is to use an ffmpeg wrapper to access ffmpeg functionality from your Android app.
There are several fairly well used wrappers available on GitHub - the ones below are particularly well featured and documented (note, I have not used these as they were not so mature when I was looking at this previously, but if I was doing something like this again now I would definitely build on one of these):
http://writingminds.github.io/ffmpeg-android-java/
https://github.com/guardianproject/android-ffmpeg
Using one of the well supported and used libraries will take care of some common issues that you might otherwise encounter - having to load different binaries for different processor types, and some tricky issues with native library reloading to avoid crashes on subsequent invocations of the wrapper.
Because this approach uses the standard ffmpeg cmd line syntax for commands it also means you should be able to search and find help easily on multiple different operations (as anyone using ffmpeg in 'normal' model will use the same syntax for the ffmpeg command itself).
For example, for your adding an image case here are some results from a quick search (ffmpeg syntax can change over time so it is worth doing a current check):
https://stackoverflow.com/a/32250369/334402
https://superuser.com/a/678171
Related
I am new to android. I have two files of same length, One is audio file and one is video file with no audio. I want to make a video with audio by combining these two files. Help me to achieve this task.
I assume you have native Android app and familiarity with Java (or know porting the code in native C) and are willing to use other open-source classes in your project.
This is what you might give a head-start: Since this project is not actively maintained now, you might have to fork and use their logic into your code.
https://github.com/tqnst/MP4ParserMergeAudioVideo
Another alternative is using ffmpeg port for Android (however I am not sure how this works natively).
https://github.com/WritingMinds/ffmpeg-android-java
It's possible that we start an android project in which it's necessary after recognising an image by camera to visualise a content generated in unity.
The easy part would be to use webGL to display it, but there is the problem of devices that do not support it directly. My question is if from android (and later iOs). It's possible to download a content of unity, load and visualise it in runtime?.
Is possible that I had to direct all the effort to generate that content in a .jar and then use something like dependency injection to load it?
I have already a unity scene in an activity but of course in project definition not in run time.
Any help or guidance would be welcome.
Unity builds levels into the final runtime executable, so adding a downloaded 'scene' directly is not possible. The best way around this is to create a 'generator' scene which can accept input from a downloaded text file, such as JSON, and use that to render the level.
However, this method does assume that all the possible objects that can be rendered are in your game as prefabs. If you're wanting to pull images from the net to be loaded into textures, the WWW class might get you started down the right path:
https://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html
I have a video(.mp4) file in my SDCard,I want to reduce a size of .mp4 file and upload this file to a server.
One way you can do this is to use ffmpeg.
There are several ways of using ffmpeg in an Android program:
use the native libraries directly from c using JNI
use a library which provides a wrapper around the 'ffmpeg' cmd line utility (also uses JNI in the wrapper library)
call ffmpeg cmd line via 'exec' from within you Android app
Of the three, I personally have used the wrapper approach in the past and found it worked well. IMHO, the documentation and examples available with the native libraries represented quite a steep learning curve.
Note, if you do use 'exec' there are some things it is worth being aware of - see bottom of this answer: https://stackoverflow.com/a/25002844/334402.
The wrapper does have limitations - at heart, the ffmpeg cmd line tool is not intended to be used this way and you have to keep that in mind, but it does work. There is an example project available on github which seems to have a reasonable user base - I did not use it myself but I did refer to it and found it useful, especially for an issue you will find if you need to call your ffmpeg wrapper more than once from the same activity or task:
https://github.com/jhotovy/android-ffmpeg
See this answer (and the questions and answers it is part if) for some more specifics on the 'calling ffmpeg two times' solution:
https://stackoverflow.com/a/28752190/334402
I've been trying to use an ffmpeg binary with command line access for a while now and getting nowhere (Using runtime.exec)
It looks like the only way I'll be able to get it to work is using a wrapper in C to access the built ffmpeg libraries using JNI...
Main problem: I haven't coded C for more than one and a half decades now and wouldn't know where to begin...
I just need 3 operations, I need to add audio to a video file, I need to concatenate two video files and if possible I need to rotate a clip by 90 degrees (but I could do without this)...
Does anyone have any example code that could work for me, or some good places to start (I've already exhausted much of the first pages of various google results to no avail)...
Any help would be greatly appreciated!
There are many open source projects available, But for simplicity, You can start from here
I believe this is what you are looking for:
https://github.com/hoary/JavaAV
Multiple platforms supported so your code will be more portable.
We need an Android app that can encode a folder of images to a video. I have been looking for solutions a while now, but cannot find anything good. The Android API does not support it. We are trying ffmpeg, but cannot get it to work. We need a working solution, using ffmpeg is not mandatory. A full Android Java solution is also a possibility, since this would work on all Android devices, possibly at the cost of some performance.
The app also needs to be able to add an audio track to the movie if the user chooses to do this.
Any help would be appreciated.
Kind regards,
AƤron
From the FFmpeg FAQ entry "How do I encode single pictures into movies?":
First, rename your pictures to follow a numerical sequence. For example, img1.jpg, img2.jpg, img3.jpg,... Then you may run:
ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
Adding an audio track should just involve add another input (e.g., -i audio.mp3), but could also require explicit -maping with older versions.