Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

c# - 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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...