I am using ffmpeg library to compress video and upload it to server.
My problem is :
Video is saved with perfect rotation in storage but when I upload it to server it gets 90degree rotated.
Command is:
setCommand("ffmpeg -y -i /sdcard/videokit/" + NetworkStatus.OrderNo
+ ".mp4 -strict experimental -vcodec libx264 -preset ultrafast -crf 24 -acodec aac -ar 44100 -ac 2 -b:a 96k -s 320x240 /sdcard/videokit/" + NetworkStatus.OrderNo + "out.mp4");
Can you please help me to get out of this. I need to show video in portrait mode only if I have captured video in portrait.
Thanks
Related
I want to compress a 1 minute video in less than a minute on Android using ffmpeg in the best possible quality. But when the time is short, the quality is low and when the quality is good, it takes a long time to compress.
Do you know the right command?
For "best quality" at fastest encoding speed:
ffmpeg -i input.mp4 -c:v libx264 -crf 18 -preset veryfast output.mp4
This assumes you want H.264 + AAC in MP4.
If input audio is AAC add -c:a copy.
If -preset veryfast is too slow use -preset ultrafast.
See FFmpeg Wiki: H.264 for more info and examples.
FFMPEG cannot do any magic....Low quality takes less time than better quality, so you have to choose right compromise between compression speed and video quality.
You didn't tell us what are size dimensions (WxH and Size in bytes) and neither current Audio and Video Codec (H264 or others).
For example 1 minute of 8K video takes more than 1 minute to be converted using HEVC codec using 10Mbps as bitrate, and cannot be reduced.....so.....
Compress video using FFMPEG:
ffmpeg -i videoPath -s 1280x720 -vf transpose=2 -metadata:s:v:0 rotate=90 -b:v 150k -vcodec mpeg4 -acodec copy outputFile
i solved problem with this command
ffmpeg -i innerPath -c:v libx264 -preset superfast -b:a 256k -vf -b:v 1.5M -c:a aac targetFilePath
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...' ...
I'm using com.netcompss.loader.LoadJNI (FFmpeg4Android) and it was working fine until I try to concat 1 video with audio track and other video without audio track.
I was using this command line:
ffmpeg -y -i /storage/emulated/0/app/1.mp4 -i /storage/emulated/0/DCIM/2.mp4 -strict experimental -filter_complex [0:v]scale=640x360,setsar=1:1[v0];[1:v]scale=1280x720,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1 -ab 48000 -ac 2 -ar 22050 -s 640x360 -r 30 -vcodec libx264 -acodec aac -crf 18 /storage/emulated/0/app/out.mp4
1.mp4 has resolution at 640x360 and has audio track.
2.mp4 has resolution at 1280x720 and has no audio track.
On vk.log it was showing this:
Setting 'n' to value '2'
Setting 'v' to value '1'
Setting 'a' to value '1'
Stream specifier ':a' in filtergraph description [0:v]scale=1280x720,setsar=1:1[v0];[1:v]scale=1280x720,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1 matches no streams.
exit_program: 1
Cannot find a matching stream for unlabeled input pad 3 on filter Parsed_concat_4
I'm not good with ffmpeg, so I did some changes to the command line without success.
When all video being concatenated have audio track, there's no problem. But when one of the videos has no audio track, it fails.
What would be the correct command line in this case?
The concat filter requires all segments to have the same number of (matching) streams, and in this case, since you only have two files, where the first one has the audio, you can skip the audio concat.
ffmpeg -y -i /storage/emulated/0/app/1.mp4 -i /storage/emulated/0/DCIM/2.mp4 \
-strict experimental -filter_complex \
[0:v]scale=640x360,setsar=1[v0];[1:v]scale=640x360,setsar=1[v1]; \
[v0][v1]concat=n=2[v] -map "[v]" -r 30 -vcodec libx264 -crf 18 \
-map 0:a -acodec aac -ab 48000 -ac 2 -ar 22050 /storage/emulated/0/app/out.mp4
Since you are scaling the final video to 640x360, there's no point scaling the 2nd video to 1280x720; just scale it directly to final size. And once you do that, there's no need to insert another scaler using the -s option.
The answer from Mulvya works fine and answer what I asked. But it will keep only the first audio from first video. In my case a user may want to concat, for example, 4 videos and only one of it has no audio track. The user want to keep other videos audio.
My solution was to check each video before concat. If a video has no audio track, I add a silent audio track. Then, when running my concat command line it won't face any problem.
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";
I am using this command to generate the video from silent video and audio but the problem is video is 3 sec and audio is 20 sec and final video generating is 20 sec but video is for 3 sec and the last frame of that video is repeat till end.
ffmpeg -i v.mp4 -i a.m4a -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 output.mp4
I just want to repeat the whole video