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
Related
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
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
Using Ffmpeg on Android to make a video from Single image merged with an Audio file, it works but the output video is not seeking to any time stamps
ex - always starts from 0:00, on seeking the video ahead it just restarts the whole video from start.
The command I used is -
-y -framerate 30 -i "+ImagePath+" -i "+AudioPath+" -vsync vfr -c:v libx264 -codec:a copy -pix_fmt yuv420p -crf 23 "+OutputVideoPath
can this be due to single frame only? (one image in video)
if so what can be used to convert a single image to seekable video.
This command will work to make a seekable MP4 (using input from image file and MP3 audio).
ffmpeg -y -i AUDIO.file -f image2 -loop 1 -r 2 -i IMAGE.file -shortest -c:a copy -c:v libx264 -crf 18 -framerate 30 -preset veryfast -movflags +faststart OUTPUT.mp4
Just replace AUDIO.file and IMAGE.fileand OUTPUT.mp4 with your custom file names.
Try this in your Android code:
-y -i "+AudioPath+" -f image2 -loop 1 -r 2 -i "+ImagePath+" -shortest -c:a copy -c:v libx264 -crf 18 -framerate 30 -preset veryfast -movflags +faststart "+OutputVideoPath+"
Try setting up your code like this:
"-y -i "+AudioPath+" -f image2 -loop 1 -r 2 -i "+ImagePath+" -shortest -c:a copy -c:v libx264 -crf 18 -framerate 30 -preset veryfast -movflags +faststart "+OutputVideoPath
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
I have used following command for compress video in android.
ffmpeg -y -i /sdcard/DCIM/Camera/VID_20150326_125017.mp4 -strict experimental -s 640x360 -r 25 -vcodec mpeg4 -b 1000k -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4
Above command is a work properly, but it's taking too much time for compression.
An 80MB video file takes around 3 minutes to compress to an 8MB file. Is there any way I can reduce this time.
Try this.
-y -i $sourceFile -s ${width}x${height} -r 5 -c:v libx264 -b:v 600k -b:a 44100 -ac 2 -ar 22050 -tune fastdecode -preset ultrafast $destPath
This command uses libx264 codec and -r 5 reduces the time taken.
-tune fastdecode -preset ultrafast this is also used for faster compression.
Reference ffmpeg preset
Result :
SOURCE SIZE : 63.7 MB DEST SIZE : 5.06MB
Time Taken : 15 Secs
Try the command mentioned below to compress videos. In my situation, 52 MB of video was compressed to 12 MB in about 19 seconds.
function command(input, output, bitrate) {
return new Promise((resolve, reject) => {
ffmpeg(input)
.outputOptions(['-c:v libx264', `-b:v ${bitrate}k`, '-c:a aac', '-b:a 58k','-crf 35'])
.output(output)
.on('start', (command) => {
console.log('TCL: command -> command', command)
})
.on('progress', function (progress) {
console.log('Processing: ' + progress.percent + '% done');
})
.on('error', (error) => reject(error))
.on('end', () => resolve())
.run()
})
}
Try the below command for video compression
In my case, i had video of 82mb and compressed to 5mb within around 50secs.
String[] command = new String[]{"-i", videoPath, "-vcodec", "h264", "-b:v", "1000k", "-acodec", "mp3" ,"-preset", "ultrafast", outputPath};
Hope it works!