How to save files in a different location after conversion with FFMpeg - ffmpeg

I am using FFMpeg on Windows to add the same audio to multiple videos using the following line of code:
for %i in (*.mp4) do ffmpeg -y -i "%i" -i m.mp3 -af apad -map 0:v -map 1:a -c:v copy -shortest "%~ni with audio.mp4"
The problem is that the program saves the output files in the same location. Is there any way that I can save them in another location?

you can tell FFmpeg to output to a folder like this:
ffmpeg -i input.mp3 path\to\some\folder\output.mp4

Related

Batch replace audio using ffmpeg

I have a folder with mkv and aac files on my Mac. I have used ffmpeg to replace audio in mkv files with success but I can't figure out how to loop it in a folder. Let's say I have a folder with vid1.mkv, vid1.aac, vid2.mkv, vid2.aac etc. I tried this but it doesn't work:
for i in *.mkv; do ffmpeg -i "$i" -i "${i%.*}.aac" -c copy -map 0:v:0 -map 1:a:0 "${i%.*}.remux.mp4" done

How to use -filter_complex and -vf in same command in FFMPEG

I edit the video with the command
ffmpeg -i video.mp4 -y -vf eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t -c:a copy output.mp4
then the resulting video
ffmpeg -i output.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4
I tried to combine all this together so that I didn't have to spend time processing the video twice, but I couldn't do it because you can't use the -vf and -filter_complex commands together. How can this problem be solved?
First apply the video specific filters before using the result as overlay input.
ffmpeg -i video.mp4 -i logo.png -filter_complex "[0:v]eq=saturation={rand_saturation},fade=in:st=0:d={rand_fade},hflip,noise=alls={rand_noise}:allf=t[vid];[vid][1:v]overlay=x='if(lt(mod(t,10),5),1,W-w-10)':y='if(lt(mod(t,10),5),5,H-h-200)'" -c:a copy output_1.mp4

Merge (video and audio) with (background music) with ffmpeg

I have video file input.mp4 that contain video and two audio source - speaking, and music.mp3 that contain background music. Now, I want to merge them.
Here is the command that i use:
ffmpeg -i input.mp4 -i music.mp3 -c:v copy -filter_complex "[0:a]aformat = fltp:44100:stereo,apad[0a];[1] aformat=fltp:44100:stereo,volume=1.5[1a];[0a] [1a] amerge[a]" -map 0:v -map "[a]" -ac 2 -y -shortest output.mp4
input file
https://d9f35555a8b3e9044c8d-95c21efaab8093d23d4124e599a618ee.ssl.cf5.rackcdn.com/mub_audio/1e03dc67-5079-46d5-b692-d69bbb6ee3e3.mp4
audio file
https://d9f35555a8b3e9044c8d-95c21efaab8093d23d4124e599a618ee.ssl.cf5.rackcdn.com/mub_audio/a6cab88a63eb11eb8d8b901b0efa6f1d.mp3
you can check the output file here
https://d9f35555a8b3e9044c8d-95c21efaab8093d23d4124e599a618ee.ssl.cf5.rackcdn.com/mub_audio/6e6e79ef-a732-49d9-8317-4ba97c05a352.mp4
The input file has a pause after every sentence. But in output, that pause duration doesn't have any background music.
What can be the reason? what is the solution for it?

replace a word in subtitle with ffmpeg

I want to use ffmpeg to replace all occurrences of a word in all subtitles of a video file with ffmpeg. All non-subtitles channels should be copied (not reencoded) and all formatting from the original subtitles should stay if possible.
example:
ffmpeg -i input.mkv -SUBTITLEFILER='old_word/new_word' output.mkv
I am using ubuntu 19.04 and bash (in case additional steps or dependencies would be required for this)
ffmpeg has no find/replace functionality for subtitles, but you can do this losslessly in 3 commands:
Extract the subtitles:
ffmpeg -i input.mkv -map 0:s:0 -c copy sub0.ass -map 0:s:1 -c copy sub1.ass -map 0:s:2 -c copy sub2.ass
I'm assuming your subtitles are SubStation Alpha (ASS/SSA) subtitles. Use the appropriate output name if they differ: such as .srt for SubRip (refer to ffmpeg -muxers).
Replace with sed:
sed -i 's/cat/dog/g' *.ass
Remux:
ffmpeg -i input.mkv -i sub0.ass -i sub1.ass -i sub2.ass -map 0 -map -0:s -map 1 -map 2 -map 3 -c copy -metadata:s:s:0 language=fas -metadata:s:s:1 language=eng -metadata:s:s:2 language=fin output.mkv
If you want to make a certain subtitle the default see the -disposition option as shown in ffmpeg set subtitles track as default.

ffmpeg output in Audacity

I wanted to split the audio track of a mp4 file each receiving different filter then merge to an output mp4 file. Please note I do not wanted series filter but rather parallel filter and then merge.
I came up with the following command.
ffmpeg -i input.mp4 -filter_complex "[0:a]asplit[audio1][audio2];[audio1]highpass=f=200:p=1:t=h:w=50;[audio2]lowpass=f=700:p=1:t=h:w=200;[audio1][audio2]amerge=inputs=2[out]" -map "[out]" -map 0:v -c:v copy -map 0:s? -c:s copy -ac 2 -y output.mp4
this output will play on Vlc and mpv. However, when I try to open it in Audacity, I get:
Why I do get this? I assume the index[05] is the correct audio output.
This raise the question, which audio track is playing when opened in Vlc? How can I create an output which has only one final audio track?
You shouldn't leave filter outputs unlabelled. They are treated as sinks if not consumed by any downstream filters and implicitly mapped for output.
Use
ffmpeg -i input.mp4 -filter_complex "[0:a]asplit[audio1][audio2];[audio1]highpass=f=200:p=1:t=h:w=50[audio1];[audio2]lowpass=f=700:p=1:t=h:w=200[audio2];[audio1][audio2]amerge=inputs=2[out]" -map "[out]" -map 0:v -c:v copy -map 0:s? -c:s copy -ac 2 -y output.mp4

Resources