How to change audio pitch without preserving duration - ffmpeg

I can change the audio pitch using ffmpeg by running
ffmpeg -i input.mp3 -filter:a "rubberband=pitch=1.059463094352953:pitchq=speed" output.mp3
But the duration of the track isn't shortned.

Related

Convert mp4 video with joining animation mp4 + audio(wav, mp3) using ffmpeg shell command

I want to create .mp4 video by joining short animation(.mp4) + audio(wav, mp3) using ffmpeg shell command.
I have tried few commands to join mp4 + audio here is my example command which will generate output video.
./ffmpeg -y -i ./output/preview-2.mp4 -i ./output/audio-file.mp3 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -r 25 -vcodec libx264 -pix_fmt yuv420p ./output/converted-video.mp4
But I want to play my animation till audio playing. The above FFMPEG command only join my animation(short video .mp4) file with audio and stopped animation playing after duration of short video reached to end (let's say animation file duration is 10seconds and stopped playing after 10 seconds). But my audio is about 3 minutes and I want to re-play the animation video again and again till the audio file duration (3 minutes). Just like a looping effect.
Add -stream_loop -1 and -shortest:
./ffmpeg -y -stream_loop -1 -i ./output/preview-2.mp4 -i ./output/audio-file.mp3 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -r 25 -vcodec libx264 -pix_fmt yuv420p -shortest ./output/converted-video.mp4

Create background sound for video with ffmpeg

I have a video file without sound and a stereo audio file. Video is several times longer than audio. I'd like to create a background sound which starts from 2 second silence, then trim silence of the audio at both ends and duplicate trimmed audio several times to the end of the video.
I found how to trim audio:
ffmpeg -y -i audio.wav -af silenceremove=start_periods=1:start_threshold=-75dB,areverse,silenceremove=start_periods=1:start_threshold=-75dB,areverse trimmed_audio.wav
And how to create silence:
ffmpeg -y -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000:duration=2 silence.wav
How can I duplicate the audio and combine it with the video?
Basic syntax is
ffmpeg -an -i video -stream_loop -1 -i trimmed_audio.wav -af adelay=2000:all=1 -shortest -fflags +shortest -max_interleave_delta 100M out.mp4
Use ffmpeg 4.1 or newer.

Is there a factor in ffmpeg code that cuts video time?

Im using ffmpeg to change resolution of video file and after conversion to another location the video lasts 0 seconds, but originally it lasts 2mins
My ffmepg code:
ffmpeg -i input.mp4 -filter:v scale=480:320 -t 5 output.mp4
Why are you using the -t modifier? You want to cut the video up? Otherwise, this will convert the whole length to the new quality.
ffmpeg -i input.mp4 -filter:v scale480:320 output.mp4

Mix audio/video of different lengths with ffmpeg

I want to mix video from video.mp4 (1 minute duration) and audio from audio.mp3 (10 minute duration) into one output file with a duration of 1 minute. The audio from audio.mp3 should be from the 4 min - 5 min position. How can I do this with ffmpeg?
If video.mp4 has no audio
You can use this command:
ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c copy -shortest output.mkv
The audio will be from the 4 minute position (-ss 00:04:00) as requested in the question.
This example will stream copy (re-mux) the video and audio–no re-encoding will happen.
If video.mp4 has audio
You will have to add the -map option as described here: FFmpeg mux video and audio (from another video) - mapping issue.
If the audio is shorter than the video
Add the apad filter to add silent padding:
ffmpeg -i video.mp4 -ss 00:04:00 -i audio.mp3 -c:v copy -af apad -shortest output.mkv
Note that filtering requires re-encoding, so the audio will be re-encoded in this example.

FFmpeg input duration?

With FFmpeg you have the option -t which will set the duration of the output. However I do not see a way to limit the duration of the input. Take this command
ffmpeg -i video.mp4 -c copy -t 60 out.mp4
This simply creates a 60 second clip of the original video. However if I wanted to clip the audio while keeping the full video stream, FFmpeg does not seem to have an option for this.
I have tried simply clipping the audio first, then combining the clipped audio with the video file, but this causes video/audio sync issues for me.
‘-aframes number (output)’
Set the number of audio frames to record. This is an alias for -frames:a.
§ Audio Options
ffmpeg -i video.mp4 -c copy -aframes 100 out.mp4
Use the "-itsoffset" option.
This makes the first 10 seconds mute.
ffmpeg -i video.mp4 -vn -acodec copy -ss 10.0 out_audio.mp4
ffmpeg -itsoffset 10.0 -i out_audio.mp4 -i video.mp4 -vcodec copy -acodec copy out.mp4

Resources