FFmpeg stucks for few seconds on start - android

I'm trying to cut and resize video on Android(but it is similar on MacOS) , but when I run the ffmpeg command it returns me
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
It repeats for about 20 sec (I have 4K video with 3 sec duration).
Is there any way to improve process speed? Here is example of my ffmpeg command
ffmpeg -y -i input.mp4 -ss 00:01.82 -to 00:02.94 -vf scale=500:1024 -c:v libx264 -c:a aac -b:v 500k -b:a 96k output.mp4

Use of -ss after the input performs a decoded frame seek, which is slower. Switch to demuxer seek
ffmpeg -y -ss 00:01.82 -to 00:02.94 -i input.mp4 -vf scale=500:1024 -c:v libx264 -c:a aac -b:v 500k -b:a 96k output.mp4
-to for demuxer was only recently added, so get a current git version. Else, use -t with the calculated duration.

Related

ffmpeg command for create final video from two different videos and two different audios

I have two videos and two audios
1:-
video 1 - length:- 60 sec || audio 1 - length:- 15 sec
2:-
video - length:- 86 sec || audio 2 - length:- 18 sec
Play video1 and audio1 together, if audio1 is ended then restart that audio till video1 end. this will final video 1.
same way,
play video2 and audio2 together, if audio2 is ended then restart that audio till video2 end. this will final video 2.
after that concatenate those final video 1 and final video 2 and create single video as output.
Thank you in advance.
Because your inputs are arbitrary you need to make them the same before concatenation.
ffmpeg -i video1 -stream_loop -1 -i audio1 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp1.mp4
ffmpeg -i video2 -stream_loop -1 -i audio2 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp2.mp4
Concatenate.
Make input.txt:
file 'temp1.mp4'
file 'temp2.mp4'
Run ffmpeg:
ffmpeg -f concat -i input.txt -c copy -movflags +faststart output.mp4
As a "single line command" as requested (but make input.txt first):
ffmpeg -i video1 -stream_loop -1 -i audio1 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp1.mp4 && ffmpeg -i video2 -stream_loop -1 -i audio2 -filter_complex "[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1,setsar=1,fps=25,format=yuv420p[v]" -map "[v]" -map 1:a -ac 2 -ar 44100 -shortest temp2.mp4 && ffmpeg -f concat -safe 0 -i input.txt -c copy -movflags +faststart output.mp4

FFmpeg converting two videos with dynamic frame rates - dup/drop frames

I have problems with converting two videos using ffmpeg. Those videos have dynamic frame rate. I'm using this ffmpeg command:
ffmpeg -y -i /storage/emulated/0/Movies/RMR/RMR_camera_2017-10-04-20-42-56.mp4 -i /storage/emulated/0/Movies/RMR/RMR_screen_2017-10-04-20-42-56.mp4 -strict experimental -preset ultrafast -filter_complex [0]scale=iw/4:ih/4[pip];[pip]transpose=2[rotate];[1][rotate]overlay=main_w-overlay_w-30:main_h-overlay_h-10 -profile:v main -level 3.1 -ar 44100 -b:a 160k -crf 20 -s 720x1280 -vcodec h264 -vsync 2 -acodec aac -movflags +faststart /storage/emulated/0/Movies/RMR/out.mp4
I'm using -vsync to drop duplicated frames. This is not good enough, video is with freezing frames. How can I prevent freezing?
Setting a constant frame rate for the two would do
ffmpeg -i ... -i ... -lavfi '[0:v]fps=24000/1001[v1];[1:v]fps=24000/1001[v2];other_filters...' ...

ffmpeg using Single image and an audio file, but output video is not seek-able ( only resumes from 0:00, even if seeked ahead )

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

Ffmpeg pcm to mp3 for android

-y -ac 1 -ar 8000 -f s16le -i xxx.pcm -acodec libmp3lame -ab 128K yyy.mp3
I use sampling rates of 8000, PCM convert mp3 is right.
When I use sampling raets of 16000, PCM convert mp3 is wrong.
How can I fix it?
"-y -ac 1 -ar 16000 -f s16le -i %s -c:a libmp3lame -q:a 2 %s"

Android ffmpeg apply video effects take log time

I am using below command to apply effect,its take 6-8 minutes to apply effect for 2 min video. Please help me to improve effective time for ffmpeg commands.
String commandStr = "ffmpeg -y -i "
+ mVideoData.getPath()
+ " -strict experimental -vf curves=vintage -s 640x480 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k -vcodec mpeg4 /sdcard/videokit/curve.mp4";

Categories

Resources