FFMPEG Slow Video and Audio by Half - audio

I am using the latest version of FFMPEG and am trying to slow video and audio by half
This is the best I could come up with
./ffmpeg.exe -i "C:/ffmpeg/input.mp4" -filter_complex "[0:v]setpts=1.5*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" "C://ffmpeg/output.mp4"
But the audio and video are not being slowed down at the same rate.
Any suggestions?
Thanks.

If you mean to slow to 50% i.e. 1/2, it should be setpts=2*PTS & atempo=0.5.
If you mean to slow by 50% i.e. 2/3, it should be setpts=1.5*PTS & atempo=0.6667.

Related

How to divide my video horizontally using ffmpeg (without any other side-effects)?

I am processing my video(640 X 1280 dimensions). I want to divide my video horizontally into 2 separate videos(each video will now be 640 X 640 in dimensions),then combine them horizontally (video dimension will be now 1280 X 640)in a single video. I did the research on the internet and my issue was solved and not solved at the same time
I made a batch file and add these commands in it:-
ffmpeg -i input.mp4 -filter_complex "[0]crop=iw:ih/2:0:0[top];[0]crop=iw:ih/2:0:oh[bottom]" -map "[top]" top.mp4 -map "[bottom]" bottom.mp4
ffmpeg -i top.mp4 -i bottom.mp4 -filter_complex hstack output.mp4
Yes,my task got solved but many other issues also came out of it:-
1.) My output video has NO audio in it. No idea why there is no audio in the end results
2.) My main video file (on which I am doing all this) is 258 MB in size. But the result was only 38 MB in size. No idea what is happening? And even worse,I closely looked at the video,results were pretty same (only animation were not as smooth in output file as compared to input file)
3.) It is taking too much time(I know that computing takes some time but maybe there may be some way/sacrifice to make the process much quicker)
Thanks in advance for helping me
Combine your two commands
ffmpeg -i input.mp4 -filter_complex "[0]crop=iw:ih/2:0:0[top];[0]crop=iw:ih/2:0:oh[bottom];[top][bottom]hstack" -preset fast -c:a copy output.mp4
If you need it to encode faster then use a faster -preset as shown in FFmpeg Wiki: H.264.
x264 is a better encoder than your phone so it is not surprising that the file size is smaller.
Or use your player to do it
No need to wait for encoding. Just have your player do everything upon playback. This does not output a file, but only plays the re-arranged video. Example using mpv:
mpv --lavfi-complex="[vid1]split[v0][v1];[v0]crop=iw:ih/2:0:0[c0];[v1]crop=iw:ih/2:0:oh[c1];[c0][c1]hstack[vo]" input.mp4

ffmpeg image watermark on video first half of video on Bottom left and next half of video on Top Right

I was playing with this for several hours, I couldn't make so thought of reaching for help, Can you please help me in framing the ffmpeg command to display the watermark Image on the video, For the Initial half video the watermark should be on the bottom left and for the rest half video the watermark shop be on the right top.
Bottom left: ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.mp4
Top right:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=main_w-overlay_w-5:5" -codec:a copy output.mp4
Also, I had a look on this for Timeoverlay ffmpeg watermark first 30 second.
How to merge all these and satisfy my requirements as mentioned above?
In this example the duration of input.mp4 is 30 seconds. The overlay filter supports the enable option.
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:enable='lte(t,15)'[bg];[bg][1]overlay=main_w-overlay_w-5:5:enable='gte(t,15)'" -codec:a copy output.mp4
To get duration see How to get video duration in seconds?. On Linux one method to calculate 50% duration is with bc. See example at Use ffmpeg to get middle frame of a video?
Alternative method is to use the sendcmd filter, but it is more complicated. See example at Sendcmd in ffmpeg.
See available functions at FFmpeg Expression Evaluation.

Use ffmpeg to sequentially add multiple audio tracks and pin a specific track to the end

I have a single video with no audio tracks and want to add several audio tracks sequentially (each track starts immediately after the other).
The basic case might look something like this:
|-----------VIDEO-----------VIDEO-------------VIDEO-----------VIDEO-----------|
|---FULL AUDIO TRACK 1---|---FULL AUDIO TRACK 2---|---PARTIAL AUDIO TRACK 3---|
Here is my attempt to achieve this:
ffmpeg -i video.mov -i audio1.mp3 -i audio2.mp3 -i audio3.mp3 -map 0:0 -map 1:0 -map 2:0 -map 3:0 out.mp4
Of course it doesn't produced the desired result. It only uses the first music clip in out.mp4, and no other audio tracks are started when it ends.
Question 1
What am I missing in order to add multiple audio tracks sequentially? I assume it's specifying starting and end points of audio clips but I'm coming up short on locating the syntax.
...
In addition, I'm looking for a way to ensure that the video ends with the full duration of AUDIO TRACK 3, as seen below:
|-----------VIDEO-----------VIDEO-------------VIDEO-----------VIDEO-----------|
|---FULL AUDIO TRACK 1---|---PARTIAL AUDIO TRACK 2---|---FULL AUDIO TRACK 3---|
In this case, AUDIO TRACK 2 gets trimmed so that the full AUDIO TRACK 3 is pinned to the end.
Question 2
Can this type of audio pinning be done in FFmpeg, or would I have to trim AUDIO TRACK 2 with another program first?
Use the atrim, asetpts, and concat filters:
ffmpeg -i video.mov -i audio1.mp3 -i audio2.mp3 -i audio3.mp3
-filter_complex "[2:a]atrim=duration=5,asetpts=PTS-STARTPTS[a2];[1:a][a2][3:a]concat=n=3:a=1:v=0[a]"
-map 0:v -map "[a]" -c copy -c:a aac -shortest output.mp4
atrim trims the audio. You can also use the start and/or end options if you prefer them over duration.
asetpts resets the timestamps (required by concat).
concat concatenates each audio segment.
If you want to automate this you'll have to script it. You can get the duration of each input with ffprobe:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
Then use that to determine the duration of whatever audio stream you want to trim.

FFMPEG change Tone Frequency, keep length (Pitch Audio)

How can I change the Tone frequency.
This Example only pitches it by keeping the old tone frequency and only decrease the length of File.
For Example, I have a constant 100 Herz tone (as mp3) and I want it to change 90 Herz
ffmpeg -i 100h.mp3 -af atempo=100/90 90h.mp3
This Example doesn't work for me, it sounds the same
inputfile Mp3
outputfile Mp3
finally, by combining the asetrate and resample from Gyan, with atempo, the following works and preserves also the audio length
for example: use 0.9 for 90% of the frequenz
ffmpeg -i test.mp3 -af asetrate=44100*0.9,aresample=44100,atempo=1/0.9 output.mp3
Basic method is
ffmpeg -i 100h.mp3 -af asetrate=44100*0.9,aresample=44100 90h.mp3
where 44100 should be replaced with the input sample rate.

Merge 2 video use ffmpeg but i want

I have two videos of different lengths Video one: 12 minutes Video two: 6 minutes I want to take audio of video one I want to take image of video two And put them together Output video length = 6 minutes. Use ffmpeg one command please help me - thanks ( watch image )____
Use
ffmpeg -i 12m.mp4 -i 6m.mp4 -vf setpts=(PTS-STARTPTS)/1.1 -af atempo=1.1 -map 1:v -map 0:a -shortest new.mp4
The setpts filter alters the video frame timestamps to 1/1.1 of their present value. FFmpeg will drop frames in the cadence needed to preserve source framerate.
The atempo filter speeds up the audio to 1.1 times the original speed.
-map 1:v -map 0:a tells ffmpeg to include the video stream from the 2nd input (6m.mp4) and the audio from the first input.
-shortest tells ffmpeg to conclude conversion when the shorter (of the audio and video) stream ends.

Resources