How to speed up sound and video and modify the pitch? - ffmpeg

I want to increase speed on both the sound and the video, while adding pitch to the audio alone.
I have those two ffmpeg commands, but I don't know how to make them work together.
ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.94*PTS[v];[0:a]atempo=1.06[a]" -map "[v]" -map "[a]" output.mkv
and
ffmpeg -i input.mkv -filter:a "atempo=1.06,asetrate=44100*1.25" output.mkv

Combined command:
ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.94*PTS[v];[0:a]atempo=1.06,asetrate=44100*1.25[a]" -map "[v]" -map "[a]" output.mkv
Although I assume you want to reset the audio sample rate from 55125 back to 44100:
ffmpeg -i input.mkv -filter_complex "[0:v]setpts=0.94*PTS[v];[0:a]atempo=1.06,asetrate=44100*1.25,aformat=sample_rates=44100[a]" -map "[v]" -map "[a]" output.mkv
Alternatively, just add -ar 44100 output option to the first example.

Related

ffmpeg - Generate a ping-pong looping Gif with images as input [duplicate]

I was able to reverse with:
ffmpeg -i input.mp4 -vf reverse output_reversed.mp4
And I can concat with:
ffmpeg -i input.mp4 -i input.mp4 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4
But can I concat with a reverse version of the video, with a single command?
What I am trying to achieve is a ping pong effect, where the video plays once, then plays backwards right after.
Thanks!
Technically, you can do it using
ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][0:a][r] [0:a]concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4
But the reverse filter will use a lot of memory for large videos. I've added a fifo filter to avoid frame drops. But test and see. (I haven't reversed the audio)
If your clip has no audio, the above command will throw an error – instead, use:
ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" output.mp4

can we use -vf and -filter:a with -filter_complex

I want to combine some videos with some specific features like(video Speed, volume increase, resolution, rotation, framerate) of the final output of the video
We can do this process in 2 steps like
Combine video
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] output.mp4
Then apply filters
ffmpeg -i output.mp4 -filter:a volume=1.0,atempo=1.0 -vf transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30 final.mp4
I can do it this way but is there any way to do it in 1 step
thank you
You have to apply the filters after concat.
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[v][a];[v]transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30[outv];[a]volume=1.0,atempo=1.0[outa] -map [outv] -map [outa] output.mp4

adding background music to video using ffmpeg

I am trying to add bacground music to a video using ffmpeg and it is working fine but I want if length of video is more than the music file then music should start playing again till the video is over -
ffmpeg -i 1.mp4 -i 2.mp3 -map 0:v:0 -map 1:a:0 output.mp4
is there anyway to perform this action?
you can use the following example:
ffmpeg -i ./INPUUT_VIDEO.mp4 -filter_complex "amovie=./INPUT_MUSIC.M4A:loop=0,asetpts=N/SR/TB[aud];[0:a][aud]amix[a]" -map 0:v -map '[a]' -c:v copy -c:a aac -b:a 256k -shortest ./OUTPUT_VIDEO.mp4
you can set/change the audio bit rate by using -b:a flag, for more detail, take a look at this document.
EDIT:
for replacing new audio in the video (repeat it until the end of the video):
ffmpeg -i VIDEO.mp4 -stream_loop -1 -i MUSIC.mp3 -c copy -shortest -map 0:v:0 -map 1:a:0 OUTPUT.mp4
replacing new audio in the video (repeat video until the end of the audio):
ffmpeg -stream_loop -1 -i VIDEO.mp4 -i MUSIC.mp3 -c copy -shortest -map 0:v:0 -map 1:a:0 OUTPUT.mp4

FFMPEG - Merge 2 Files (video_video), with TC and watermark

I need to merge two video files, add a watermaker and a timecode burned in the video.
I see this (by #llogan:)
ffmpeg -i video.mp4 -i audio.mp3 -i watermark.png -filter_complex "[0:v:0]drawtext=fontfile=/usr/share/fonts/TTF/DejaVuSansMono.ttf:timecode='01\:23\:45\:00':r=25:x=(w-text_w)/2:y=h-text_h-20:fontsize=20:fontcolor=white:box=1:boxborderw=4:boxcolor=black[bg];[1][bg]overlay=W-w-10:H-h-12:format=auto[v]" -map "[v]" -map 1:a -shortest output.mp4
But I can't apply for two videos, because of the map. Can someone help me, please? My last attempt was:
ffmpeg -i [video1] -i [video2] -i [image-overlay] -filter_complex "[0:v:0]drawtext=fontfile=/Windows/Fonts/arial.ttf: timecode='00\:00\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=0xccFFFF#1: fontsize=85: box=1: boxcolor=0x000000#0.2[bg];concat=n=2:v=1:a=1[vv][a];[vv][2:v]overlay=0:0[v];[vv][bg]overlay=0:0" -map "[v]" -map "[a]" -c:v libx264 -b 2000k -preset fast -c:a aac [output file]
Assuming you want to draw timecode to only video1, and concatenate video1 to video2, and add image overlay over the combined videos:
ffmpeg -i [video1] -i [video2] -i [image-overlay] -filter_complex "[0:v:0]drawtext=fontfile=/Windows/Fonts/arial.ttf: timecode='00\:00\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=0xccFFFF#1: fontsize=85: box=1: boxcolor=0x000000#0.2[tc];[tc][0:a][1:v][1:a]concat=n=2:v=1:a=1[cat][a];[cat][2:v]overlay=0:0[v]" -map "[v]" -map "[a]" -c:v libx264 -b:v 2000k -preset fast -c:a aac [output file]

Merge video and audio while delaying audio by x seconds

This works for merging audio and video
ffmpeg -i video.mp4 -i audio.ogg -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -c:a libvorbis -ac 2 -shortest out.mp4 -y -nostdin
I can't figure out how to delay the audio so it starts x seconds into the video. I have tried -itsoffset but it doesn't work.
Use
ffmpeg -i video.mp4 -i audio.ogg -filter_complex "[1:a]adelay=1000|1000[a1];[0:a][a1]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -c:a libvorbis -ac 2 -shortest out.mp4 -y -nostdin
The adelay adds 1000 ms of silence to both channels of the OGG.
This is more of a workaround, but you could concatenate 1 second of silence with your ogg first:
https://trac.ffmpeg.org/wiki/Concatenate

Resources