How to input an audio file, generate video, split, crop and overlay to output a kaleidoscope effect - audio

I need to create an FFMPEG script which reads in an audio file ("testloop.wav" in this example) generates a video from the waveform using the "showcqt" filter , and then crops and overlays the output from that to generate a kaleidoscope effect. This is the code I have so far - the generation of the intial video and the output section work correctly, but there is a fault in the split, crop and overlay section which I cannot trace.
ffmpeg -i "testloop.wav" -i "testloop.wav" \
-filter_complex "[0:a]showcqt,format=yuv420p[v]" -map "[v]" \
"split [tmp1][tmp2]; \
[tmp1] crop=iw:(ih/3)*2:0:0, pad=0:ih+ih/2 [top]; \
[tmp2] crop=iw:ih/3:0:(ih/3)*2, hflip [bottom]; \
[top][bottom] overlay=0:(H/3)*2"\
-map 1:a:0 -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart "${i%.wav}.mp4

You can't split or define multiple filter_complexes. Also, no need to feed input twice.
ffmpeg -i "testloop.wav" \
-filter_complex "[0:a]showcqt,format=yuv420p, \
split [tmp1][tmp2]; \
[tmp1] crop=iw:(ih/3)*2:0:0, pad=0:ih+ih/2 [top]; \
[tmp2] crop=iw:ih/3:0:(ih/3)*2, hflip [bottom]; \
[top][bottom] overlay=0:(H/3)*2"\
-c:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p \
-c:a aac -strict -2 -b:a 384k -ar 48000 -movflags +faststart out.mp4
(I'm not debugging the logic of the effect you're trying to achieve. Only the syntax)

Related

FFMPEG 1 Audio + 1 Still image + multiple image frames at several times

I want to create a video from combination of all these files which includes single audio file, still image in background and multiple image frames at several times, i have achieved this with video file on this help Now i have tried a failure attempt to create audio with same approach. But got an error which is obvious because still lack of knowledge in FFMPEG
Following is my failure attempt with error Output with label 'v2' does not exist in any defined filter graph, or was already used elsewhere.
ffmpeg -y -loop 1 -i bg.jpg -i img/%07d.png -i dia.mp3 -c:v libx264 -tune stillimage -pix_fmt yuv420p -c:a aac -b:a 128k -shortest -vf "[0:v]scale=1280:1280:force_original_aspect_ratio=increase,crop=1280:1280[v1],[v1][2]overlay=10:10:enable='between(t,0,6)'[v2]" -map "[v2]" out.mp4 2>&1
Use
ffmpeg -y -loop 1 -i bg.jpg -i img/%07d.png -i dia.mp3 -c:v libx264 -tune stillimage -pix_fmt yuv420p -c:a aac -b:a 128k -shortest -filter_complex "[0:v]scale=1280:1280:force_original_aspect_ratio=increase,crop=1280:1280[v1];[v1][1]overlay=10:10:enable='between(t,0,6)'" out.mp4 2>&1
The pad numbering is wrong, and there should be a semi-colon after the bg image scale.

Generate Video From Images and Audio

I have a list of images: 1.png, 2.png... and a list of audio files 1.mp3, 2.mp3...
I'd like to generate a video file where audio clips are concatenated, and each image is displayed over the corresponding audio clip:
Think of the images as slides in a slideshow, and the audio as narration for the slide.
Are there any frameworks which would allow me to do this? I'd like to use FFmpeg CLI or something high level if possible.
Lazy method is to make each segment then concatenate with the concat demuxer:
ffmpeg -loop 1 -i 1.png -i 1.mp3 -c:v libx264 -preset stillimage -vf format=yuv420p -c:a aac -shortest 1.mp4
ffmpeg -loop 1 -i 2.png -i 2.mp3 -c:v libx264 -preset stillimage -vf format=yuv420p -c:a aac -shortest 2.mp4
ffmpeg -loop 1 -i 2.png -i 2.mp3 -c:v libx264 -preset stillimage -vf format=yuv420p -c:a aac -shortest 2.mp4
ffmpeg -f concat -i input.txt -c copy -movflags +faststart output.mp4
This assumes the image files are the same width & height, and the audio files have the same channel layout & sample rate.
More complicated method is to use the concat filter which allows you to do it all in one command, but you'll have to enter the duration of each image segment to match the corresponding audio duration.

Make green nullsrc to black

I have a video which hasn't 1920x1080 so I need to make it.
I try to use next command:
ffmpeg -i "video.avi" -filter_complex "nullsrc=size=1920x1080 [0:v]; [0:v] overlay=shortest=1:x=200:y=100" -r 30 -c:v libx264 -preset fast -crf 18 -profile:v high -bf 2 -flags +cgop -coder 1 -pix_fmt yuv420p -strict -2 -c:a aac -b:a 384k "video.mp4"
But I got a green frame over the video like this - http://i.imgur.com/QNVUGb5.jpg
I dont find a solution to make a green in any other color.
How possible to make green frame to black frame?
Thanks.
Use the pad filter instead
It is simpler to just use the pad filter to add the frame:
ffmpeg -i input -filter_complex "pad=1920:1080:(ow-iw)/2:(oh-ih)/2" output
Not as efficient alternatives
Alternatively, if you want to use the overlay filter to add padding then you can use the color source filter instead of nullsrc:
ffmpeg -f lavfi -i color=s=1920x1080:c=black -i video.mp4 -filter_complex "[0][1]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1" output.mp4
If you still want to use nullsrc then refer to the chromakey filter, but this is inefficient and not a recommend method.

ffmpeg-Error "Buffer queue overflow, dropping." when merging two videos with delay

I want to merge two videos (as example the iphone video from https://peach.blender.org/trailer-page/). The videos are placed on an background image with the overlay filter and the second video starts 3 seconds later.
And I need that the audio is mixed.
Here is my code:
ffmpeg \
-loop 1 -i background.png \
-itsoffset 0 -i trailer_iphone.m4v \
-itsoffset 3 -i trailer_iphone.m4v \
\
-y \
-t 36 \
-filter_complex "
[2:a] adelay=3000 [2delayed];
[1:a][2delayed] amerge=inputs=2 [audio];
[0][1:v] overlay=10:10:enable='between(t,0,33)' [lv1];
[lv1][2:v] overlay=10:300:enable='between(t,0,36)' [video]
" \
\
-threads 0 \
-map "[video]" -map "[audio]" \
-vcodec libx264 -acodec aac \
merged-video.mp4
I get the error message:
[Parsed_overlay_3 # 0x7fe892502ac0] [framesync # 0x7fe892502b88] Buffer queue overflow, dropping.
And the merged video has many dropped frames.
I know that are some other posting with this error message. But the suggested solutions doesn't work for me.
How can I fix the problem?
FFmpeg is dropping frames from [2:v] because the processing of [0][1:v]overlay is taking longer than the frame drop threshold.
Insert a fifo filter to 2:v to avoid this.
ffmpeg -loop 1 -i background.png
-itsoffset 0 -i trailer_iphone.m4v
-itsoffset 3 -i trailer_iphone.m4v
-t 36 -filter_complex
"[2:a]adelay=3000[2delayed];[1:a][2delayed]amerge=inputs=2[audio];
[0][1:v]overlay=10:10:enable='between(t,0,33)'[lv1];
[2:v]fifo[2f];[lv1][2f]overlay=10:300:enable='between(t,0,36)'[video]"
-threads 0 -map "[video]" -map "[audio]" -vcodec libx264 -acodec aac merged-video.mp4
(For stereo audio, it should be adelay=3000|3000)

ffmpeg add all audio tracks to video conversion (mkv)

I have a script that takes in input a video file (generally avi or mp4) and converts it to a "lower quality" mkv video optimized for web streaming.
The ffmpeg command I use is this one:
ffmpeg -fflags +genpts -i file:"$input" -sn -codec:v:0 libx264 -force_key_frames expr:gte\(t,n_forced*5\) -vf "scale=trunc(min(max(iw\,ih*dar)\,1280)/2)*2:trunc(ow/dar/2)*2" -pix_fmt yuv420p -preset superfast -crf 23 -b:v 1680000 -maxrate 1680000 -bufsize 3360000 -vsync vfr -profile:v high -level 41 -map_metadata -1 -threads 8 -codec:a:0 libmp3lame -ac 2 -ab 320000 -af "aresample=async=1" -y "$output"
The problem is that this command only includes the first audio track of my video. I have some dual language videos (italian and english) for which I want to include both languages.
Is there a simple ffmpeg command option that automatically includes all audio tracks found in a video?
Add -map 0:a to include all audio streams.

Resources