Video orientation using ffmpeg - android

How to get video orientation using ffmpeg? I am using ffmpeg on android.
It seems ffmpeg not taking care automatically, in android lower versions I could not find api, so trying using ffmpeg. In android there is metadataretriver but it's api level is 17.
Please suggest way for this.

Are you looking for the syntax of the transpose filter? For instance, to rotate the input by 90 degrees counter-clockwise:
ffmpeg -i input -vf "transpose=1" output
If not, could you detail your request a little bit more?

Related

Is it possible to convert h265 video to h264 with resizing in Android app without the FFMPEG?

I want to convert all videos based on h265 to h264 and at the same time reduce the resolution to for example 720p to avoid working on very big resolutions and later uploading that kind of big size files.
I see docs https://developer.android.com/guide/topics/media/media-formats says that for h265 Android OS supports only decoding, not encoding.
I know that FFMPEG will solve all my problems, but including FFMPEG will increase the app size very much, I'd like to avoid that. I am trying to use currently the Android MediaCodec, but it looks like it would work fine with converting h264 to h264 but not with h265 to h264.
Do you have any ideas? I don't need to support old Android versions.
Thanks for any advice.
If you're compiling it for Android 12 or higher, you can use the built-in transcoder
Otherwise, you'll need to include a 3rd-party media transcoder library, and FFMPEG is still your best choice

How crop and scale a video programmatically without ffmpeg

i would like to crop and scale a recorded video without the use of ffmpeg, is there any way?
I would avoid to use ffmpeg to not have compatibility problems.
Thanks guys
Ummm... try to use gstreamer instead of ffmpeg. BTW, what is wrong with ffmpeg?
For example, this is gstreamer conveyor
gst-launch v4l2src ! video/x-raw-yuv,width=640,height=480,framerate=15/1 ! aspectratiocrop aspect-ratio=16/9 ! \ ffmpegcolorspace ! xvimagesink
It takes video from the webcam, changes aspect, then shows output to user.

How to trim video in android (without ffmpeg)?

Hi I am trying to trim video in android, but all of the source codes I have found are using ffmpeg, is there a smaller library, which I can use ?
Because ffmpeg library is about 8-9 MB, and my application is about 6 MB, adding ffmpeg library to my app will make it more than double size.
You can do this with mp4parser library. Have a look at the ShortenExample it does exactly what the name suggests. Since the library cannot re-encode the video it can only cut the video at I-frames. So the points in time where you can make a cut are quite coarse.
On Android 4.1 you can access the hardware codecs via MediaCodec API which could be an option (but I haven't seen any example of that yet)
Or, you can use this class: TrimVideoUtils.java

Adding watermark bitmap over video in android: 4.3's MediaMuxer or ffmpeg

Here is my scenario:
Download an avi movie from the web
Open a bitmap resource
Overlay this bitmap at the bottom of the movie on all frames in the background
Save the video on extarnal storage
The video length is 15 seconds usually
Is this possible to achieve using MediaMuxer ? Any info on the matter is gladly received
I've been looking to http://bigflake.com/mediacodec/#DecodeEditEncodeTest (Thanks #fadden) and it says there:
"Decoding the frame and copying it into a ByteBuffer with
glReadPixels() takes about 8ms on the Nexus 5, easily fast enough to
keep pace with 30fps input, but the additional steps required to save
it to disk as a PNG are expensive (about half a second)"
So having almost 1 sec/frame is not acceptable. From what I am thinking one way would be to save each frame as PNG, open it, add the bitmap overlay on it and then save it. However this would take an enormous time to accomplish.
I wonder if there is a way to do things like this:
Open video file from external storage
Start decoding it
Each decoded frame will be altered with the bitmap overlay in memory
The frame is sent to an encoder.
On iOS I saw that there a way to take the original audio + original video + an image and add them in a container and then just encode the whole thing...
Should I switch to ffmpeg ? How stable and compatible is ffmpeg ? Am I risking compatibility issues with android 4.0+ devices ? Is there a way to use ffmpeg to acomplish this ? I am new to this domain and still doing research.
Years later edit:
Years have passed since the question and ffmpeg isn't really easy to add to a commercial software in terms of license. How did this evolved? Newer versions of android are more capable on this with the default sdk?
Some more time later edit
I got some negative votes for posting info as an answer so I'll edit the original question. Here is a great library which, from my testing does apply watermark to video and does it with progress callback making it a lot easier to show progress to the user and also uses the default android sdks. https://github.com/MasayukiSuda/Mp4Composer-android
This library generate an Mp4 movie using Android MediaCodec API and apply filter, scale, and rotate Mp4.
Sample code, could look like:
new mp4Composer(sourcePath, destinationPath)
.filter(new GlWatermarkFilter(watermarkBitmap)
.listener(){
#Override
private void onProgress(double value){}
#Override
private void onCompleted(double value){
runOnUiThread( () ->{
showSneakbar
}
}
#Override
private void onCancelled(double value){}
#Override
private void onFailed(Exception e){}
}).start();
Testing on emulator, seems to work fine on android 8+ while on older generates a black video file.However, when testing on real device seems to work.
I don't know much about the MediaMuxer but ffmpeg does support overlaying functionality. FFMPEG has various filters one of them is overlay filter. What I understand is you want to overlay an image (i.e. png) on the video, ffmpeg surely is a useful framework to do this job. You can set the output format you can set the co-ordinates of the image which is to be overplayed.
E.g.
ffmpeg -i input.avi -i logo.png -filter_complex 'overlay=10:main_h-overlay_h-10' output.avi
Above command adds overlays logo.png on the input.avi video file in bottom left corner.
More information about the filters is available at following website,
https://www.ffmpeg.org/ffmpeg-filters.html#overlay-1
If this is a solution to your problem you need the C code equivalent to the above command. You also need to see the performance of the ffmpeg because it a pure software framework.
Hope I have understood your question correctly and this helps.
If you need do this without ffmpeg on Android device:
Start from : https://github.com/google/grafika
The answer on your question between Play video (PlayMovieActivity.java) and Record Gl App (RecordFBOActivity.java) examples.
Steps:
Setup mInputWindowSurface as Video Encoder Input Surface.
Decode frame from video stream using MoviePlayer as video (external) texture.
Draw this video texture on Surface.
Draw watermark on the same Surface over video texture.
Notify MediaCodec that surface ready for encoding:
mVideoEncoder.frameAvailableSoon();
mInputWindowSurface.setPresentationTime(timeStampNanos);
and then goto Step 2.
Don't forget to adjust speed of decoding. Just remove SpeedControlCallback which in example set to decode 60 FPS video.
Advantages of this way:
Media Codec use hardware decoder/encoder for video processing.
You can change bit rate of result video.
You can try INDE Media Pack - https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials
It has transcoding\remuxing functionality as MediaComposer class and several sample effects like JpegSubstituteEffect - it shows how substitute video frame by a picture from jpg file and TextOverlayEffect to overlay text on video frame etc. It could be easily enhanced to watermark effect
This is what worked for me:
ffmpeg -i input.avi -i logo.png -filter_complex 'overlay=10:main_h-overlay_h-10' -strict -2 output.avi
ffmpeg recommended the usage -strict -2 inorder to allow the usage of experimental codecs. without the inclusion, the accepted answer above fails to work.

Transcode/Convert Video to Mp4 on Android

I've a requirement where I need to transcode small video clips shot from Native camera app to lower bitrate/resolution Mp4 which is shreable via email etc.
What is the best way to transcode/convert the video on device itself. FFMPEG or any other library?
p.s. I know this is an overkill for the device but client leaves me with no option. He doesn't care about battery or time it takes. I'm targeting this for quad-cores, where CPU is not a problem.
Your best bet would be to use something like ffmpeg which has been ported to Android (see this SO post: ffmpeg for a android (using tutorial: "ffmpeg and Android.mk") and the ffmpeg port for android which is here: http://bambuser.com/opensource). You'll have to use JNI etc, but that will save you the hassle of dealing with the byte stream yourself.
Haven't tried it on Android myself, so YMMV:
Is there a Java API for mp4 files?
http://code.google.com/p/mp4parser/
If you're recording on-device, why not set the expected format from your code? It appears the api lets you set video size, framerate etc. in the MediaRecorder class.

Categories

Resources