I am trying to do a custom downmix conversion, that is the rough equivalent of :
ffmpeg -y -i "file.mkv" \
-map 0:1 -c:0 flac -ac:0 4 \
-map 0:3 -c:1 flac -ac:1 3 \
-map 0:3 -c:2 flac -ac:2 3 \
audio.mkv
I tried using the command:
ffmpeg -y -i "file.mkv" \
-map 0:1 -c:0 flac -af:0 "pan=3.1| FL < FL + 0.6*BL + 0.6*SL | FR < FR + 0.6*BR + 0.6*SR | FC = FC | LFE = LFE" \
-map 0:3 -c:1 flac -af:1 "pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC | LFE = LFE" \
-map 0:3 -c:2 flac -af:2 "pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC + 0.5*LFE | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC + 0.5*LFE" \
audio.mkv
But it gave an error that only 1 "af" is supported, unlike "ac":
Only '-af pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC + 0.5*LFE | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC + 0.5*LFE | LFE = FC' read, ignoring remaining -af options: Use ',' to separate filters
So I tried doing as it said, and separated them with a comma:
ffmpeg -y -i "file.mkv" \
-map 0:1 -c:0 flac \
-map 0:3 -c:1 flac \
-map 0:3 -c:2 flac \
-af "pan=3.1| FL < FL + 0.6*BL + 0.6*SL | FR < FR + 0.6*BR + 0.6*SR | FC = FC | LFE = LFE,pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC | LFE = LFE,pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC + 0.5*LFE | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC + 0.5*LFE | LFE = LFE" \
audio.mkv
Which started the encoding, but I noticed that it was only applying the last pan, and all three tracks were being downmixed to the last 2.1!
According to the documentation, https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-syntax-1 adding a "," is creating a "filterchain" which I don't think I want, as I am doing the same filter on three different tracks. So I am at a loss of what I am supposed to do from there.
Thanks for any help!
-af is an old shorthand for -filter:a and does not accept stream specifiers. Use -filter:a:1 for example to assign filters for the 2nd audio output stream.
Another method is to use -filter_complex:
ffmpeg -i "file.mkv" -filter_complex \
"[0:1]pan=3.1| FL < FL + 0.6*BL + 0.6*SL | FR < FR + 0.6*BR + 0.6*SR | FC = FC | LFE = LFE[a0];
[0:3]pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC | LFE = LFE[a1];
[0:3]pan=2.1| FL < FL + 0.6*BL + 0.6*SL + 0.5*FC + 0.5*LFE | FR < FR + 0.6*BR + 0.6*SR + 0.5*FC + 0.5*LFE[a2]" \
-map "[a0]" -map "[a1]" -map "[a2]" -c:a flac audio.mkv
Related
Hello everyone here I have a problem this code works well with 1080x1080 images but if I put 1920x1080 images does it no longer work? can someone tell me why or put me on a track thank you
fmpeg/ffmpeg \
-loop 1 -t 3 -i agence_quatre_img/1669992356.png \
-loop 1 -t 3 -i agence_quatre_img/1669992343.png \
-loop 1 -t 3 -i agence_quatre_img/1669992317.png \
-loop 1 -t 3 -i agence_quatre_img/1669992290.png \
-loop 1 -t 3 -i agence_quatre_img/1669992290.png \
-filter_complex \
"[1]fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \
[2]fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \
[3]fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+10/TB[f2]; \
[4]fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+12/TB[f3]; \
[0][f0]overlay[bg1];[bg1][f1]overlay[bg2];[bg2][f2]overlay[bg3]; \
[bg3][f3]overlay,format=yuv420p[v]" -map "[v]" agence_quatre_img/output.mov
I've downloaded some videos from my course and I think they are too big. I need to reencode them to something better and smaller.
The problem is I made the script but it saves the file in the first folder. I want the output files inside the same folder as the input files. For example:
Folder 1
- script.sh
Folder 2
- file1.mp4
- file1.new
Folder 3
- file2.mp4
- file2.new
I've tried using the for loop only, and it was working actually but I couldn't encode the files recursively. This wouldn't work. Using find solved the problem, but now the output files are all in the same directory, which is the same directory where the script is located (working directory).
IFS=$'\n'; set -f
for i in $(find . -name '*.mp4'); do
if ($width > 600) && ($width < 800); then
echo "$i is a 720p video. Let's encode it to VP9."
notify-send Shrinker "Beginning encoding filename "$i""
ffmpeg -i "$i" -vf mpdecimate,setpts=N/FRAME_RATE/TB -vf scale=1280x720 -b:v 1800k \
-minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 \
-quality good -crf 32 -c:v libvpx-vp9 -c:a libopus \
-pass 1 -speed 4 "$(basename "${i/.mp4}")".webm && \
ffmpeg -y -i "$i" -vf mpdecimate,setpts=N/FRAME_RATE/TB -vf scale=1280x720 -b:v 1800k \
-minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 \
-quality good -crf 32 -c:v libvpx-vp9 -c:a libopus \
-pass 2 -speed 4 -y "$(basename "${i/.mp4}")".webm
elif ($width > 800) && ($width < 1081) && ($fps < 31.000); then
echo "$i is a 1080p video with 30fps or maybe less. Let's encode it to VP9."
ffmpeg -i "$i" -vf mpdecimate,setpts=N/FRAME_RATE/TB -vf scale=1920x1080 -b:v 1800k \
-minrate 900k -maxrate 2610k -tile-columns 2 -g 240 -threads 8 \
-quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
-pass 1 -speed 4 "$(basename "${i/.mp4}")".webm && \
ffmpeg -y -i "$i" -vf mpdecimate,setpts=N/FRAME_RATE/TB -vf scale=1920x1080 -b:v 1800k \
-minrate 900k -maxrate 2610k -tile-columns 4 -g 240 -threads 8 \
-quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
-pass 2 -speed 4 -y "$(basename "${i/.mp4}")".webm
notify-send Shrinker "Beginning encoding filename "$i""
elif ($width > 800) && ($width < 1081) && ($fps > 49.000); then
echo "$i is a 1080p video with 50fps or maybe more. Let's encode it to VP9."
ffmpeg -i "$i" -vf mpdecimate,setpts=N/FRAME_RATE/TB -vf scale=1920x1080 -b:v 3000k \
-minrate 1500k -maxrate 4350k -tile-columns 2 -g 240 -threads 8 \
-quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
-pass 1 -speed 4 "$(basename "${i/.mp4}")".webm && \
ffmpeg -y -i "$i" -vf mpdecimate,setpts=N/FRAME_RATE/TB -vf scale=1920x1080 -b:v 3000k \
-minrate 1500k -maxrate 4350k -tile-columns 4 -g 240 -threads 8 \
-quality good -crf 31 -c:v libvpx-vp9 -c:a libopus \
-pass 2 -speed 4 -y "$(basename "${i/.mp4}")".webm
notify-send Shrinker "Beginning encoding filename "$i""
else
echo "no file found"
fi
done
My script finds every file and encodes them BUT the output files are saved into folder 1. It should save on folder 2 and folder 3.
I get this:
Folder 1
- script.sh
- file1.webm
- file2.webm
Folder 2
- file1.mp4
Folder 3
- file2.mp4
I want this:
Folder 1
- script.sh
Folder 2
- file1.mp4
- file1.webm
Folder 3
- file2.mp4
- file2.webm
When I execute the ffmpeg command I get this error:
Unable to find a suitable output format for ffmpeg
String strCommand = "ffmpeg -loop 1 -t 3 -i " + list.get(0)" -loop 1 -t 3 -i " + list.get(1)+" -loop 1 -t 3 -i " + list.get(2)+" -loop 1 -t 3 -i " + list.get(3)+ " -filter_complex[0:v]trim=duration=3,fade=t=out:st=2.5:d=0.5[v0];[1:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v1];[2:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v2];[3:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v3];[v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p[v] -map [v] -preset ultrafast " + getVideoFilePath();
You command seems to be ok, please be sure that getVideoFilePath() can get a right path with the supported format, for example, /path/.../slide.mp4, here is a workable example ffmpeg line:
ffmpeg \
-loop 1 -t 3 -i pic001.jpg \
-loop 1 -t 3 -i pic002.jpg \
-loop 1 -t 3 -i pic003.jpg \
-loop 1 -t 3 -i pic004.jpg \
-filter_complex "\
[0:v]trim=duration=3,fade=t=out:st=2.5:d=0.5[v0];\
[1:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v1];\
[2:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v2];\
[3:v]trim=duration=3,fade=t=in:st=0:d=0.5,fade=t=out:st=2.5:d=0.5[v3];\
[v0][v1][v2][v3]concat=n=4:v=1:a=0,format=yuv420p[v]" \
-map "[v]" -preset ultrafast slide.mp4
In Reference to https://superuser.com/questions/833232/create-video-with-5-images-with-fadein-out-effect-in-ffmpeg
I have a bunch of images. and I want to make a video using these images.
Below is my code for FFMpeg. But the problem is how can I append an audio file to -filter_complex (with bitrate)
ffmpeg \
-loop 1 -i input0.png \
-loop 1 -i input1.png \
-loop 1 -i input2.png \
-loop 1 -i input3.png \
-loop 1 -i input4.png \
-filter_complex \
"[0:v]trim=duration=15,fade=t=out:st=14.5:d=0.5[v0]; \
[1:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v1]; \
[2:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v2]; \
[3:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v3]; \
[4:v]trim=duration=15,fade=t=in:st=0:d=0.5,fade=t=out:st=14.5:d=0.5[v4]; \
[v0][v1][v2][v3][v4]concat=n=5:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4
I have a file for screencasting on linux, and I want to modify parts of it based on user input. At the moment I can't even get it to stick an argument in a command from a variable.
#!/bin/bash -x
fps="30"
capturesize="hd1080"
outputsize="720"
filter=-vf 'scale=${outputsize}'
avconv \
-f x11grab -r $fps -s $capturesize -i :0.0 \
-f alsa -ac 2 -i pulse \
-f alsa -ac 2 -i pulse \
-f alsa -ac 1 -i pulse \
-map 0:0 -map 1:0 -map 2:0 -map 3:0 \
-vcodec libx264 \
$filter \
-pre:v lossless_ultrafast \
-acodec libmp3lame \
-threads 4 \
-y $#
$fps and $capturesize are evaluated properly but $filter assignment gives a nice little:
+ filter=-vf
+ 'scale=${outputsize}'
~/bin/screencap: line 9: scale=${outputsize}: command not found
Changing the line to:
filter="-vf 'scale=$outputsize'"
Gives an even less pleasant:
+ filter='-vf '\''scale=720'\'''
+ avconv -f x11grab [...] -vf ''\''scale=720'\''' [...]
[...]
No such filter: 'scale=720'
Error opening filters!
Use an array. It has the added benefit of protecting items that contain spaces, something
you can't do if you try to store it in a space-separated list.
#!/bin/bash -x
fps="30"
capturesize="hd1080"
outputsize="720"
filter=( -vf "scale=${outputsize}" )
avconv \
-f x11grab -r "$fps" -s "$capturesize" -i :0.0 \
-f alsa -ac 2 -i pulse \
-f alsa -ac 2 -i pulse \
-f alsa -ac 1 -i pulse \
-map 0:0 -map 1:0 -map 2:0 -map 3:0 \
-vcodec libx264 \
"${filter[#]}" \
-pre:v lossless_ultrafast \
-acodec libmp3lame \
-threads 4 \
-y "$#"
You can put all the options in a single array; a small example:
options=( -f x11grab -r "$fps" -s "$capturesize" )
options+=( -i :0.o )
# etc
avconv "${options[#]}" -y "$#"
filter="-vf scale=${outputsize}"