Video file is hanging after concatenating video files and drawtext to output - ffmpeg

I'm trying to concat 3 video files and add text to output using ffmpeg.
Each part is 10 sec long.
I've end up with this code:
ffmpeg -i output3.mp4 -i output2.mp4 -i output1.mp4 -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[v][a]; [0:v:0]drawtext=fontfile=tahoma.ttf:text=Sample text:fontcolor=white:fontsize=40:box=1:boxcolor=black#0.7:boxborderw=5:x=100:y=100" -map "[v]" -map "[a]" output.mp4
The result video has 30 seconds but it hangs after 1st part (10s). When I remove drawtext filter part (just concat), then video is fine, but without text...
Anyone can help ?

Use
ffmpeg -i output3.mp4 -i output2.mp4 -i output1.mp4 -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[v][a]; [v]drawtext=fontfile=tahoma.ttf:text=Sample text:fontcolor=white:fontsize=40:box=1:boxcolor=black#0.7:boxborderw=5:x=100:y=100[v]" -map "[v]" -map "[a]" output.mp4
Your existing syntax applied the text on top of the video stream of the first input file, instead of the resultant video from the concat filter.

Related

How can I combine these two filters in ffmpeg

So Im trying to overlay a video on top of an image and then add text over the image in ffmpeg I found that Im able to do all these separately but when combining it gives me the error of
Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_drawtext_2
The line of code:
ffmpeg -loop 1 -i overlay.png -re
-i overlay.mp4
-filter_complex "[1]scale=1660:934[inner];[0][inner]overlay=0:0:shortest=1[out];
drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=text.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1"
-map "[out]" -map 1:a -c:a copy -y -s 1280x800 output.mp4
Can anyone help me with this?
You almost got it. Only needs some re-arranging:
ffmpeg -loop 1 -i overlay.png
-i overlay.mp4
-filter_complex "[1]scale=1660:934[inner];[0][inner]overlay=0:0:shortest=1,scale=1280:800,drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=text.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1[out]"
-map "[out]" -map 1:a -c:a copy output.mp4
See FFmpeg filtering intro for a quick explanation of the syntax.

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?

ffmpeg - Add INTRO and Watermark

I need to add INTRO.mp4 at the beginning of video.mp4 and add watermark.png (bottom right corner)
How to do this using ffmpeg, because I'm lost?
log file
Copy and paste this command. It will work with any intro.mp4 and video.mp4 assuming they both have audio.
ffmpeg -i intro.mp4 -i video.mp4 -i watermark1.png -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,fps=30000/1001,format=yuv420p[intro];[1:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1,setsar=1,fps=30000/1001,format=yuv420p[video];[2]scale=96:-1[logo];[0:a]aformat=sample_rates=48000:channel_layouts=stereo[introa];[1:a]aformat=sample_rates=48000:channel_layouts=stereo[videoa];[intro][introa][video][videoa]concat=n=2:v=1:a=1[vid][a];[vid][logo]overlay=W-w-5:H-h-5[v]" -map "[v]" -map "[a]" -movflags +faststart output.mp4
See:
FFmpeg Filters Documentation
How to add watermark with ffmpeg?
How to concatenate videos in ffmpeg with different attributes?

concatenate audio files with an image

I am trying to concatenate multiple audio files and a single image into one video file using one command.
I have list of mp3 files and a playlist file (.m3u) in a direcotry.
I managed to do this but my solution is bad:
reading the playlist file and creating a new .txt in the ffmpeg required format
concatenating the audio files using the .txt into an .mp3
concatenating the large audio file and the static image into a video
This creates 2 unnecessary files that I have to delete.
I tried a different command
ffmpeg -loop 1 -framerate 1 -i myImage.jpg -i file1.mp3 -i file2.mp3 -i file3.mp3 -filter_complex '[0:0][1:0][2:0]concat=n=3:v=0:a=1' -tune stillimage -shortest output.mp4
however im getting a Error initializing complex filters.
Invalid argument error
Another kick in the nuts is that the system im working on has spaces in the folder names.
i tried using -i "concat:file1.mp3|file2.mp3|..." however i cannot use double quote marks to quote out the path so I get an invalid argument error.
Thank you very much for your help.
Method 1: concat demuxer
Make input.txt containing the following:
file 'file1.mp3'
file 'file2.mp3'
file 'file3.mp3'
Run ffmpeg:
ffmpeg -loop 1 -framerate 1 -i myImage.jpg -f concat -i input.txt -filter_complex "[0]scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v]" -map "[v]" -r 15 -tune stillimage -map 1:a -shortest -movflags +faststart output.mp4
All MP3 files being input to the concat demuxer must have the same channel layout and sample rate. If they do not then convert them using the -ac and -ar options so they are all the same.
Method 2: concat filter
Update: There seems to be a bug with -shortest not working with the concat filter (I keep forgetting about that). See the method above using the concat demuxer, or replace -shortest with -t. The value for -t should equal the total duration of all three MP3 files.
ffmpeg -loop 1 -framerate 1 -i myImage.jpg -i file1.mp3 -i file2.mp3 -i file3.mp3 -filter_complex "[0]scale='iw-mod(iw,2)':'ih-mod(ih,2)',format=yuv420p[v];[1:a][2:a][3:a]concat=n=3:v=0:a=1[a]" -map "[v]" -r 15 -map "[a]" -tune stillimage -shortest -movflags +faststart output.mp4
Option descriptions
scale filter makes image have even width and height which is required when outputting YUV 4:2:0 with libx264.
format filter sets chroma subsampling to 4:2:0, otherwise libx264 will try to limit subsampling, but most players can only handle 4:2:0.
concat filter is accepting file1.mp3, file2.mp3, and file3.mp3 as inputs. Your original command was trying to concat the video to the audio resulting in Invalid argument.
-map "[v]" chooses the video output from -filter_complex.
-r 15 sets output frame rate to 15 because most players can't handle 1 fps. This is faster than setting -framerate 15.
-map "[a]" chooses the audio output from -filter_complex.
-map 1:a chooses the audio from input #1 (the second input as counting starts from 0).
-movflags +faststart after encoding finishes this option moves some data from the end of the MP4 output file to the beginning. This allows playback to begin faster otherwise the complete file will have to be downloaded first.

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