How to create a video from images?











up vote
0
down vote

favorite
1












I have an algorithm, which after each iteration creates a matrix. After some operations on matrix it is plotted to the user. if I run program 6 times I will get:



a bunch of images



My goal is to changing image dynamically, like a movie.



I have no idea from which side to start. I found some ways of creating video from images in python and then wrap it in the video player. But it seems to be a bit complicated and it is impossible to see the changes while algorithm is working. Are there any suggestions how to do it?










share|improve this question




















  • 1




    you might want to take a look at this question
    – Kevin He
    Nov 8 at 19:17















up vote
0
down vote

favorite
1












I have an algorithm, which after each iteration creates a matrix. After some operations on matrix it is plotted to the user. if I run program 6 times I will get:



a bunch of images



My goal is to changing image dynamically, like a movie.



I have no idea from which side to start. I found some ways of creating video from images in python and then wrap it in the video player. But it seems to be a bit complicated and it is impossible to see the changes while algorithm is working. Are there any suggestions how to do it?










share|improve this question




















  • 1




    you might want to take a look at this question
    – Kevin He
    Nov 8 at 19:17













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I have an algorithm, which after each iteration creates a matrix. After some operations on matrix it is plotted to the user. if I run program 6 times I will get:



a bunch of images



My goal is to changing image dynamically, like a movie.



I have no idea from which side to start. I found some ways of creating video from images in python and then wrap it in the video player. But it seems to be a bit complicated and it is impossible to see the changes while algorithm is working. Are there any suggestions how to do it?










share|improve this question















I have an algorithm, which after each iteration creates a matrix. After some operations on matrix it is plotted to the user. if I run program 6 times I will get:



a bunch of images



My goal is to changing image dynamically, like a movie.



I have no idea from which side to start. I found some ways of creating video from images in python and then wrap it in the video player. But it seems to be a bit complicated and it is impossible to see the changes while algorithm is working. Are there any suggestions how to do it?







python image matrix video cv2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 19:39









martineau

65.1k987176




65.1k987176










asked Nov 8 at 18:44









Sergey Vladimirovich

104110




104110








  • 1




    you might want to take a look at this question
    – Kevin He
    Nov 8 at 19:17














  • 1




    you might want to take a look at this question
    – Kevin He
    Nov 8 at 19:17








1




1




you might want to take a look at this question
– Kevin He
Nov 8 at 19:17




you might want to take a look at this question
– Kevin He
Nov 8 at 19:17












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You can use FFMPEG



def convert():
os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")


Alternatively, you can use ImageIO to generate a GIF. You can set the parameters for duration of each frame.



import imageio
with imageio.get_writer('/path_to_video.gif', mode='I') as writer:
for filename in filenames:
image = imageio.imread(filename)
writer.append_data(image)


Read the manual on website for more detailed instructions.



Or with cv2,



import cv2

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')
img3 = cv2.imread('3.jpg')

height , width , layers = img1.shape

video = cv2.VideoWriter('video.avi',-1,1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()





share|improve this answer

















  • 1




    Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
    – Sergey Vladimirovich
    Nov 9 at 10:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214221%2fhow-to-create-a-video-from-images%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










You can use FFMPEG



def convert():
os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")


Alternatively, you can use ImageIO to generate a GIF. You can set the parameters for duration of each frame.



import imageio
with imageio.get_writer('/path_to_video.gif', mode='I') as writer:
for filename in filenames:
image = imageio.imread(filename)
writer.append_data(image)


Read the manual on website for more detailed instructions.



Or with cv2,



import cv2

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')
img3 = cv2.imread('3.jpg')

height , width , layers = img1.shape

video = cv2.VideoWriter('video.avi',-1,1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()





share|improve this answer

















  • 1




    Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
    – Sergey Vladimirovich
    Nov 9 at 10:12















up vote
2
down vote



accepted










You can use FFMPEG



def convert():
os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")


Alternatively, you can use ImageIO to generate a GIF. You can set the parameters for duration of each frame.



import imageio
with imageio.get_writer('/path_to_video.gif', mode='I') as writer:
for filename in filenames:
image = imageio.imread(filename)
writer.append_data(image)


Read the manual on website for more detailed instructions.



Or with cv2,



import cv2

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')
img3 = cv2.imread('3.jpg')

height , width , layers = img1.shape

video = cv2.VideoWriter('video.avi',-1,1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()





share|improve this answer

















  • 1




    Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
    – Sergey Vladimirovich
    Nov 9 at 10:12













up vote
2
down vote



accepted







up vote
2
down vote



accepted






You can use FFMPEG



def convert():
os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")


Alternatively, you can use ImageIO to generate a GIF. You can set the parameters for duration of each frame.



import imageio
with imageio.get_writer('/path_to_video.gif', mode='I') as writer:
for filename in filenames:
image = imageio.imread(filename)
writer.append_data(image)


Read the manual on website for more detailed instructions.



Or with cv2,



import cv2

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')
img3 = cv2.imread('3.jpg')

height , width , layers = img1.shape

video = cv2.VideoWriter('video.avi',-1,1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()





share|improve this answer












You can use FFMPEG



def convert():
os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")


Alternatively, you can use ImageIO to generate a GIF. You can set the parameters for duration of each frame.



import imageio
with imageio.get_writer('/path_to_video.gif', mode='I') as writer:
for filename in filenames:
image = imageio.imread(filename)
writer.append_data(image)


Read the manual on website for more detailed instructions.



Or with cv2,



import cv2

img1 = cv2.imread('1.jpg')
img2 = cv2.imread('2.jpg')
img3 = cv2.imread('3.jpg')

height , width , layers = img1.shape

video = cv2.VideoWriter('video.avi',-1,1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 19:17









Aravind Voggu

751413




751413








  • 1




    Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
    – Sergey Vladimirovich
    Nov 9 at 10:12














  • 1




    Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
    – Sergey Vladimirovich
    Nov 9 at 10:12








1




1




Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
– Sergey Vladimirovich
Nov 9 at 10:12




Thanks! I also found another way of dinamically representation of images: matplotlib.org/2.1.2/gallery/animation/image_slices_viewer.html
– Sergey Vladimirovich
Nov 9 at 10:12


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214221%2fhow-to-create-a-video-from-images%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini