Speed up a video without audio to 2x with FFmpeg in android - android

I am working on a project in which I need to speed up a mute video. I did a little digging around and found the following command.
ffmpeg -i input.mkv -filter:v "setpts=PTS/2" output.mkv
Tried to use it in android as follows.
new String[]{"-y", "-i", inputFileAbsolutePath, "-filter_complex", "setpts=PTS/2", "-map", "[v]", "-map", "[a]", "-b:v", "2097k", "-r", "60", "-vcodec", "mpeg4", fileOutput};
It doesn't even show anything in the Logcat.
I have also tried a few other solutions but no luck.
Any help would be appreciated.
Thanks.

If you were to view the log from the ffmpeg process it would provide an error:
Output with label 'v' does not exist in any defined filter graph, or was already used elsewhere.
So either properly label and map the filter output:
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/2[v]" -map "[v]" -b:v 2097k -r 60 -vcodec mpeg4 output.mp4
...or omit the labels and rely on the default stream selection behavior.
ffmpeg -i input.mp4 -filter_complex setpts=PTS/2 -b:v 2097k -r 60 -vcodec mpeg4 output.mp4

Related

Android ffmpeg just convert an image file to video file

I want to make a sample video file into video for 30 seconds to show. But I can not do it because I'm not good enough with FFmpeg.
My code :
String command[]={
"-y",
"-r",
"1/5",
"-i",
src.getAbsolutePath(), // only one image file path
"-c:v",
"libx264",
"-vf",
"fps=25",
"-pix_fmt",
"yuv420p",
imagesvideoOutput
};
Simple command for 30 second video from a single image:
ffmpeg -loop 1 -i image.png -vf format=yuv420p -t 30 output.mp4
Faster, but somewhat more complicated method:
ffmpeg -loop 1 -framerate 1 -i image.png -vf fps=25,format=yuv420p -t 30 output.mp4

Invalid argument Unable to print text using drawtext using ffmpeg

I am trying to add text and time stamp on video but not able to print the simple text on it.
String[] complexCommand = {"-f", "3gp", "-i", videoPath, "-s", height + "x" + width, "-r",
"17", "drawtext=fontfile='file://android_asset/font_eight.ttf':fontsize=20:text='test':x=10:y=100",
"-vcodec", "libx264", "-vb", "2000k", "-preset", "fast", "-f", "3gp", dir.getAbsolutePath() + "/out.3gp"};
ffmpeg -f 3gp -i /storage/emulated/0/DCIM/Camera/VID_20171211_105946.3gp -s 1920x1080
-r 17 drawtext='fontfile=file://android_asset/font_eight.ttf:fontsize=20:text=test:x=10:y=100
-vcodec libx264 -vb 2000k -preset fast -f 3gp /storage/emulated/0/Pictures/Video/out.3gp
-- Edited Question ---
Error:
Fontconfig error: Cannot load default config file
[Parsed_drawtext_0 # 0xf5ba0730] impossible to init fontconfig
[AVFilterGraph # 0xf5b89040] Error initializing filter 'drawtext' with args 'fontfile=file://android_asset/font_eight.ttf:fontsize=32:text=test:fontcolor=white:x=0:y=0'
Error opening filters!
Same command runs on windows with no error, But when I converted it for mobile device and tested getting error of font-path.
drawtext is a video filter, so it has to be passed as an argument to -vf or -filter_complex (used when filtering multiple streams).
So,
-vf drawtext=fontsize=20:=text='aaa':x=10:y=100

FFMPEG image to video with transition effects

I have used this command to concate multiple images with transition effects to create video.
"-y -f concat -safe 0 -i <txt file path> -filter_complex [0:0][1:0]concat=n=2:v=0:a=1[out] -map [v] -shortest -vf fps=40 -pix_fmt yuv420p <video path>"
But it is showing error :
Stream specifier ':0' in filtergraph description [0:0][1:0]concat=n=2:v=0:a=1[out] matches no streams.
Here is my txt file
file '/storage/emulated/0/image1.jpg'
duration 5
file '/storage/emulated/0/image2.jpg'
duration 5
file '/storage/emulated/0/image3.jpg'
However if i am not applying any filter effect, it is successfully creating a video.
Following command creates the video at a frame rate of 1 frame for 5 seconds.
ffmpeg -y -r 1/5 -i image1.jpg -i image2.jpg -i image3.jpg -filter_complex 'concat=n=3:v=1:a=0 [out]' -map [out] -c:v libx264 output.mp4

How to Compress video file in android

I want to compress video file before uploading to server.I gone through this link
How to compress a video to maximum level android, but i did not get an answer. Can anyone help me ??
Give this a try
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setVideoEncodingBitRate(690000 );
We can compress video using ffmpeg in android.
For integrating FFmpeg in android we can use precompiled libraries like ffmpeg-android.
You can use below command to compress video
String[] command = {"-y", "-i", inputFileAbsolutePath, "-s", "160x120", "-r", "25", "-vcodec", "mpeg4", "-b:v", "150k", "-b:a", "48000", "-ac", "2", "-ar", "22050", outputFileAbsolutePath};
Here,
-y
Overwrite output files without asking.
-i
ffmpeg reads from an arbitrary number of input “files” specified by the -i option
-s
video output size
-r
Set frame rate
-vcodec
Set the video codec.
-b:v
Set the video bitrate
-b:a
Set the audio bitrate
-ac
Set the number of audio channels.
-ar
sets the sampling rate for audio streams if encoded
For detailed explanation and code on using ffmpeg in android to edit videos,check out below ffmpeg video editor tutorial link on my blog which includes compressing video using ffmpeg-
https://androidlearnersite.wordpress.com/2017/03/17/ffmpeg-video-editor/
You have to use ffmpeg lib to compress your video:-
ffmpeg -i input.mp4 -acodec mp2 output.mp4

Unable to concatenate videos due to identical MOOV atoms

I am cutting out segments from a long mp4 file and then rejoining parts of them. However, since FFMPEG apparently keeps the same MOOV atom for the trimmed files as the original, it looks to FFMPEG that the trimmed videos are all identical since they all have the same MOOV atom, and therefore only uses the first segment when trying to join the videos. Is there a way around this? Unfortunately since FFMPEG is embedded in an Android app, I can only use version 0.11.
Edit:
This is a sample of the processes:
ffmpeg -i /sdcard/path/movie.mp4 -ss 00:00:06.000, -t 00:00:05.270, -c:a aac -c:v libx264 /sdcard/path/file1.mp4
ffmpeg -i /sdcard/path/movie.mp4 -ss 00:00:12.000, -t 00:00:04.370, -c:a aac -c:v libx264 /sdcard/path/file2.mp4
ffmpeg -i /sdcard/path/movie.mp4 -ss 00:00:23.000, -t 00:00:03.133, -c:a aac -c:v libx264 /sdcard/path/file3.mp4
ffmpeg -i "concat:/sdcard/path/file1.mp4|/sdcard/path/file2.mp4|/sdcard/path/file3.mp4" -c:a aac -c:v libx264 /sdcard/path/output.mp4
I've also tried using the copy codec option but that hasn't helped.
Can you try something like:
ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
I hope this works with ffmpeg version 0.11. We need to make sure you can concat before applying the cut of file.
Also can you check the intermediary file*.mp4 works well? Can you try to put your video files on the same folder as ffmpeg I am not sure how the concat protocol reacts to /sdcard/path/file1.mp4|/sdcard/path/file2.mp4?

Categories

Resources