Ffmpeg Concat and Scale Simultaneously

ffmpeg concat and scale simultaneously?

ffmpeg -i d:\1.mp4 -i d:\2.mp4 -filter_complex "concat=n=2:v=1:a=1 [v] [a]; \
[v]scale=320:200[v2]" -map "[v2]" -map "[a]" d:\3.mp4

Firstly we concatenate everything and pipe result to [v] [a] (see filtergraph syntax docs - its output from concat filter). Next we take [v], scale it and output to [v2], lastly we take [v2] and [a] and mux it to d:\3.mp4 file.

FFMPEG concatenate 2 random and different videos

The videos have to be the same size (pixel dimensions, that is). The output stream can't change sizes midway through. So resize one (or both) to the desired size.

e.g.:

ffmpeg -y -i {orginalVideo.itsExtention} -vf scale=640:480 -vcodec wmv2 4.wmv

And see https://trac.ffmpeg.org/wiki/Scaling for more.

ffmpeg how to vertically rotate and concat/stack two videos in one command?

You just need to do the same prep work on both video streams (i.e., 2 filter chains) before stacking them together (the final chain):

ffmpeg -i outside.MOV -i inside.MOV \
-filter_complex "[0:v]scale=640:-1,hflip,vflip[v0];\
[1:v]scale=640:-1,hflip,vflip[v1];\
[v0][v1]vstack=inputs=2" inside_and_outside.MOV

transpose or rotate should work the same, I'm using yet another alternate hflip,vflip for illustration. Don't know which one is the fastest.

ffmpeg concat two sources with optional audio

Must match stream count & type

All segments to be concatenated must have the same number and type of streams. So if input1.mp4 has audio, and input2.mp4 does not, then you need to either omit the audio from input1.mp4 or add audio for input2.mp4. One method is to add silent audio with the anullsrc filter as shown in:

  • FFmpeg concatenation, no Audio in Final Output
  • Add black video to video with sound
  • How to concatenate videos in ffmpeg with different attributes?

Detecting audio

There is no option to automatically add missing audio, so you have to check the inputs with ffprobe to tell you if the inputs have audio or not:

  • Using ffprobe to check audio-only files
  • How can I know a certain file is a video or audio file?

You can then use the results in your preferred scripting/coding language to execute the appropriate command.

How to concatenate two MP4 files using FFmpeg?

I ended up using mpg as the intermediate format and it worked (NOTE this is a dangerous example, -qscale 0 will re-encode the video...)

ffmpeg -i 1.mp4 -qscale 0 1.mpg
ffmpeg -i 2.mp4 -qscale 0 2.mpg
cat 1.mpg 2.mpg | ffmpeg -f mpeg -i - -qscale 0 -vcodec mpeg4 output.mp4

FFMPEG -- Error when trying to concat multiple files with and without audio

Can someone spot whats wrong here please?

In your command you are attempting to feed the audio from noSound1.mp4 ([0:a]) and noSound2.mp4 ([2:a]) to aformat, but these inputs have no audio.

All inputs must either have audio or no audio: you can't mix them. So that's what anullsrc (the silent audio generator) is for. It will make dummy/silent/filler audio for the inputs without audio. For the inputs without audio you need to feed anullsrc ([4] or [4:a] in your example) to concat:

ffmpeg -i noSound1.mp4 -i story1.mp4 -i noSound2.mp4 -i story2.mp4 -t 0.1 -f lavfi -i anullsrc=channel_layout=stereo -filter_complex 
"[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v0];
[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v1];
[2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v2];
[3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v3];
[1:a]aformat=sample_rates=48000:channel_layouts=stereo[a1];
[3:a]aformat=sample_rates=48000:channel_layouts=stereo[a3];
[v0][4][v1][a1][v2][4][v3][a3]concat=n=4:v=1:a=1[v][a]"
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart testOutput.mp4

To understand the [0:a] syntax see FFMPEG mux video and audio (from another video) - mapping issue and FFmpeg Wiki: Map.

Now a slightly separate question. If I have N input videos where i do not know if they have sound or not, is there a way I can have a loop that does the above without having massive amounts of command lines?

No, but you can use ffprobe to determine if an input has audio or not which should be helpful in scripting a solution. See Using ffprobe to check audio-only files.



Related Topics



Leave a reply



Submit