FFMPeg hstack video not same height - c#

I am currently trying to horizontally stack multiple video files and receiving this error
[libvorbis # 000001bb38f23a80] Queue input is backward in
timerate=N/A speed= 0x
[libvorbis # 000001bb38f23a80] Queue input is backward in
timetrate= 799.4kbits/s dup=0 drop=3894 speed=15.7x
[libvorbis # 000001bb38f23a80] Queue input is backward in
timetrate= 798.7kbits/s dup=0 drop=3924 speed=15.8x
[Parsed_hstack_2 # 000001bb3a3411c0] Input 1 height 480 does not
match input 0 height 360.op=3929 speed= 16x
[Parsed_hstack_2 # 000001bb3a3411c0] Failed to configure output pad
on Parsed_hstack_2
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argumentError
while processing the decoded data for stream #0:0
This is my command.
ffmpeg -i RT05974d20e9550b89697b15f8bc3feb78.mkv -i RTb295d0534191e1acb22a45bb971a12e6.mka -i RTc2de0d06575c6c225b44dbce73104ed8.mkv -i RT3904b3a60273760ec9e9c181ea35bdc4.mka -i RT13386752138abbe5eb941da3f7fdfdc5.mka -i RTe31da14ad7c898ad8d8ce6bbafc5e387.mkv -i RT103bfe5f4b129860f69cd8e820f3a10b.mka -i RT2e5859b6a555070f3305735c698966d0.mka -filter_complex "[2:v]tpad=start_duration=120:color=black[vpad]; [3:a]adelay=120000:all=1[a2pad]; [4:a]adelay=150000:all=1[a3pad]; [5:v]tpad=start_duration=20:color=black[v2pad]; [6:a]adelay=200000:all=1[a5pad]; [7:a]adelay=240000:all=1[a6pad]; [0:v][vpad][v2pad]hstack=inputs=3[vout]; [1:a][a2pad][a3pad][a5pad][a6pad]amix=inputs=5:weights=1|1|1|1|1[aout]" -map [vout] -map [aout] output.mkv
I then also checked each file individually to make sure that their height and width were correct.
ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x RT05974d20e9550b89697b15f8bc3feb78.mkv
640x480
ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x RTc2de0d06575c6c225b44dbce73104ed8.mkv
640x480
ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x RTe31da14ad7c898ad8d8ce6bbafc5e387.mkv
640x480
Full log pasted here - https://pastebin.com/0XEipXjA
Log when only two files are used - https://pastebin.com/AVYisBeh
Log when that first video file is not used (works) - https://pastebin.com/8YfHRsQ1
What am I doing incorrectly?

Looks like the first input's resolution is changing midway.
Suppress reinitializing filters, and force initial resolution using scale.
ffmpeg -reinit_filter 0 -i RT05974d20e9550b89697b15f8bc3feb78.mkv -i RTb295d0534191e1acb22a45bb971a12e6.mka -i RTc2de0d06575c6c225b44dbce73104ed8.mkv -i RT3904b3a60273760ec9e9c181ea35bdc4.mka -i RT13386752138abbe5eb941da3f7fdfdc5.mka -i RTe31da14ad7c898ad8d8ce6bbafc5e387.mkv -i RT103bfe5f4b129860f69cd8e820f3a10b.mka -i RT2e5859b6a555070f3305735c698966d0.mka -filter_complex "[0:v]scale=iw:ih,setsar=1[v0];[2:v]tpad=start_duration=120:color=black[vpad]; [3:a]adelay=120000:all=1[a2pad]; [4:a]adelay=150000:all=1[a3pad]; [5:v]tpad=start_duration=20:color=black[v2pad]; [6:a]adelay=200000:all=1[a5pad]; [7:a]adelay=240000:all=1[a6pad]; [v0][vpad][v2pad]hstack=inputs=3[vout]; [1:a][a2pad][a3pad][a5pad][a6pad]amix=inputs=5:weights=1|1|1|1|1[aout]" -map [vout] -map [aout] output.mkv

Related

What is the longest duration ffmpeg is able to record from an rtsp source

TL;DR:
Here is my question:
Can a ffmpeg process recording a rtsp stream run for 10 years or will it break down at some point, given there are no issues with storage and the stream? Glad for any experience like ( "this process has run for x weeks or days)
I have a task to enable my client to record and archive rtsp cam recordings. They should be restreamable and searchable so i opted for mpegts for fast cutting and concatenation, and restreaming as Video on Demand at a later point. This was all fun and games until a new recent requirement, that this should be stable for 10 years.
My FFMPEG Arguments look like this:
-hide_banner -rtsp_transport tcp -i rtsp://MYRTSPURL -threads 8 -pix_fmt yuvj420p -map 0 -c:v h264 -b:v 2M -bf 0 -muxpreload 0 -muxdelay 0 -force_key_frames "expr:gte(t,n_forced0.5)" -strftime 1 -f segment -segment_time 60 -segment_format mpegts -reset_timestamps 1 C:\RecorderTest\capture-%Y-%m-%d_%H-%M-%S.ts -pix_fmt yuvj420p -map 0 -c:v h264 -b:v 200k -bf 0 -muxpreload 0 -muxdelay 0 -force_key_frames "expr:gte(t,n_forced0.5)" -s 192:144 -strftime 1 -f segment -segment_time 60 -segment_format mpegts -reset_timestamps 1 C:\RecorderTest\capture-%Y-%m-%d_%H-%M-%S_preview.ts
which I utilize trough a C# Process. It works quite well so far but I noticed that despite I have set -reset_timestamps 1 the StdErr Progress Output is not resetting but keeps increasing.
FFMPEG STDERR says: frame= 1840 fps= 30 q=28.0 q=22.0 size=N/A time=00:00:59.80 bitrate=N/A dup=0 drop=2 speed=0.983x
FFMPEG STDERR says: [segment # 0000023d8c5e8b40] Opening 'C:\RecorderTest\capture-2022-03-01_11-54-57_preview.ts' for writing
FFMPEG STDERR says: [segment # 0000023d8c5ee940] Opening 'C:\RecorderTest\capture-2022-03-01_11-54-57.ts' for writing
FFMPEG STDERR says: frame= 1855 fps= 30 q=28.0 q=22.0 size=N/A time=00:01:00.30 bitrate=N/A dup=0 drop=2 speed=0.983x
So the time value is increasing and not resetting. Now I fear that this could lead to some undefined behavior. Does anyone know where I could check in ffmpeg source if the case that this time index reaches the max value is catched or if the process will crash by then?

FFMPEG video scale & add image background

I want to create a video with ffmpeg. There are background image(450pxx800px) and video(unknown sizes). I want scale to video 450x800 and put the image video background. I try this code but when finish job, video create without audio. what must i do?
ffmpeg -loop 1 -i C:\Users\drt\Desktop\media\background\bg4.png -vf "movie='C\:\\Users\\drt\\Desktop\\media\\fX4I0jW8_fX4I0jW8.mp4',scale=450:800:force_original_aspect_ratio=1,pad=450:800:0:264:color=black#0,setsar=1[inner];[in][inner] overlay=0:0[out]" -ss 00:00:00.000 -to 00:00:15.000 -y C:\Users\drt\Desktop\media\2q4pyZpSCE7syzJMj.mp4
You need to map the output streams. Also, no need to use the movie filter: that method is from a billion years ago.
ffmpeg -y -i C:\Users\drt\Desktop\media\fX4I0jW8_fX4I0jW8.mp4 -i C:\Users\drt\Desktop\media\background\bg4.png -filter_complex "[1:v]scale=450:800:force_original_aspect_ratio=1,pad=450:800:0:264:color=black#0,setsar=1[inner];[0:v][inner]overlay=0:0[video]" -map "[video]" -map 0:a -c:a copy -to 00:00:15.000 C:\Users\drt\Desktop\media\2q4pyZpSCE7syzJMj.mp4

ffmpeg extract the first frame even if I assign other frame?

I have this line of code in Windows Forms c#:
string.Format("-i \"{0}\" -s {3} \"{1}\" -vcodec mjpeg -ss {2} -vframes 1 -an -f rawvideo ", input.Path, saveThumbnailTo, secs, imgWidthHeight);
the problem is that the code only extracting the first frame whatever I put another frame.
Adding -ss {2} twice solved my problem, I added -ss 00:25:00 in the beginning of line and it worked

C# Mono start process with pipe command in linux

In windows, pretty easy to send pipe via cmd.exe, I simply write
.FileName = "cmd.exe"; and
.Arguments = "d:\ifme\addons\ffmpeg\ffmpeg -i d:\Videos\sata.mp4 -pix_fmt yuv420p -f yuv4mpegpipe - 2> nul | d:\ifme\addons\x265\x265lo -p medium --crf 28 -f 523 -o d:\ifme\temp\video.hevc --dither --y4m -";
but in Linux (Ubuntu 14.04.1) I write:
.FileName = "/bin/bash";
.Arguments = "-c /home/anime4000/Desktop/ifme/addons/ffmpeg/ffmpeg -i /home/anime4000/Videos/sata.mp4 -pix_fmt yuv420p -f yuv4mpegpipe - 2> /dev/null | /home/anime4000/Desktop/ifme/addons/x265/x265lo -p medium --crf 28 -f 523 -o /home/anime4000/Desktop/ifme/temp/video.hevc --dither --y4m -";
I got FFmpeg error which is no command specified...
I use create file method:
System.IO.File.WriteAllText("cmd.sh", "/home/anime4000/Desktop/ifme/addons/ffmpeg/ffmpeg -i /home/anime4000/Videos/sata.mp4 -pix_fmt yuv420p -f yuv4mpegpipe - 2> /dev/null | /home/anime4000/Desktop/ifme/addons/x265/x265lo -p medium --crf 28 -f 523 -o /home/anime4000/Desktop/ifme/temp/video.hevc --dither --y4m -");
.FileName = "sh";
.Arguments = "cmd.sh";
I got an error which is x265lo file not exist, but file was there with execute permission
So, how to get proper pipe command with C# Mono?
Note: x265lo is a 8 bit BPP build, x265hi is a 16 bit BPP build, because contain two x265 with different BPP
(Sorry, this should be a comment but I don't have enough reputation here.)
I don't know what's wrong specifically, but you should be able to determine how Mono calls your shell by doing something like this:
strace -fv -s4096 -e trace=execve /path/to/your/program args-to-your-program
Once you have done this, please update your question with the relevant execve() lines.

convert image sequence using ffmpeg

I have been using ffmpeg to convert a sequence of jpegs to a video using the following syntax
ffmpeg -f image2 -i frame%d.jpg -vcodec mpeg4 -b 800k video.avi
it works a treat, however if the filenames dont start at 0 and then pursue in accending order I get weird results. for example the first file in the directory is frame1 and last file is fram 61.I should point out that im always using a list of jpegs which accend in incrental order. for example a list of files called frame1, fram2, fram3 etc.
the following works fine
frame1.jpg to frame9.jpg
frame1.jpg to frame10.jpg
frame2.jpg to frame8.jpg
frame2.jpg to frame10.jpg
frame2.jpg to frame11.jpg
frame2.jpg to frame17.jpg
frame2.jpg to frame20.jpg
frame2.jpg to frame30.jpg
frame2.jpg to frame61.jpg
the following doesnt work
26 to 57 fail
11 to 61 fail
10 to 61 fail
20 to 61 fail
24 to 61 fail
Can I modify the arguments for ffmpeg so that it will make the video regardless of the filenames? (frame%d)
The only way I got this to work was by naming frames files with a constant fixed width for frame counters. If you are taking frames from webcams check if that could be done by the webcam itself, otherwise, you'll have to rename it yourself. You may develop a Windows Service that use a FileWatcher class in C# that "listens" for a folder to be writted with a frame and then rename it to another folder with the beforemention format. This worked for me.
frame01.jpg
frame02.jpg
...
frame10.jpg
frame11.jpg
...
frame61.jpg
Then using this:
ffmpeg.exe -r 1 -f image2 -i frame%02d.jpg -r 16 -vcodec mpeg4 -b 800k -y video.avi
-i frame%02d.jpg: indicates 2 digits for frame counter
I added -r 1 and -r 16 as optional framerates that I test to have worked for me.
You could rename all jpeg files so the numbering always starts at zero and there are no gaps.

Categories