ffmpeg extract the first frame even if I assign other frame? - c#

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

Related

FFMPeg hstack video not same height

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

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

&& exit does not quit as expected, takes it as text string in cmd

So im trying to run multiple commands in a one command line, im using WGET to download a few files to a local path this part works so far.
Here is what Ive got
startInfo.Arguments = #"/K wget -x -np -S -N -nH -r -R ""index.html*""
http://my-server.ip -P """ +
Properties.Settings.Default.userAddonDir+" && exit";
with this I should expect CMD to launch WGET with the command line:
-x -np -S -N -nH -r -R ""index.html*""
from my server:
http://my-server.ip
to my users local path for example:
E:/Folder/Sub Folder/
then once wget is finished it should see
&& Exit
and close cmd...
things to note, the users local path is likely to have white space so I've wrapped it in quotes to prevent the path being cut off. (hence all the quotes)
but what the path resolves to is odd. not to sure
E:/Folder/Sub Folder/ && exit/
If I place any more "" it breaks any ideas or pointers as im at a loss.
Thanks in advance.
Change your command to
string x = #"E:\temp";
string t = #"/K wget -x -np -S -N -nH -r -R ""index.html*"" http://my-server.ip -P """ +
x + #""" && exit";
After the operator + the initial verbatim character is no more effective. You need to reapply it to the last part of your string constant && exit
However, have you tried to launch your command with /C instead of /K?
This will automatically close the command window so you don't need anymore the Exit command

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