I want to convert a sequence of ppm images to avi video (or another possible video format acceptable by OpenCV) First I converted the ppm images with no drop in quality to jpg:

$ for f in *ppm ; do convert -quality 100 $f `basename $f ppm`jpg; done 

then I used the following command to convert to avi:

$ ffmpeg -i CS585Bats-FalseColor_frame*.jpg  -vcodec mpeg4 test.avi

But I got the following error:

FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers
  built on Aug  2 2016 19:05:32 with clang 7.3.0 (clang-703.0.31)
  configuration: --enable-libmp3lame --enable-libfaac --enable-gpl --enable-nonfree --enable-shared --disable-mmx --arch=x86_64 --cpu=core2
  libavutil     50.36. 0 / 50.36. 0
  libavcore      0.16. 1 /  0.16. 1
  libavcodec    52.108. 0 / 52.108. 0
  libavformat   52.93. 0 / 52.93. 0
  libavdevice   52. 2. 3 / 52. 2. 3
  libavfilter    1.74. 0 /  1.74. 0
  libswscale     0.12. 0 /  0.12. 0
Input #0, image2, from 'CS585Bats-FalseColor_frame000000750.jpg':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: mjpeg, yuvj444p, 1024x1024 [PAR 1:1 DAR 1:1], 25 tbr, 25 tbn, 25 tbc
ffmpeg(11831,0x7fffa5dc6340) malloc: *** error for object 0x100000001: pointer being realloc'd was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Then I thought to use this other method but still get error:

$  convert -delay 6 -quality 100 CS585Bats-FalseColor_frame000000*ppm movie.mpg
convert: delegate failed `'ffmpeg' -nostdin -v -1 -i '%M%%d.jpg' '%u.%m' 2> '%u'' @ error/delegate.c/InvokeDelegate/1919.

ppm file names look like below:

$ ls *ppm | head -5
CS585Bats-FalseColor_frame000000750.ppm
CS585Bats-FalseColor_frame000000751.ppm
CS585Bats-FalseColor_frame000000752.ppm
CS585Bats-FalseColor_frame000000753.ppm
CS585Bats-FalseColor_frame000000754.ppm
share|improve this question
    
Your ffmpeg is absolutely ancient. Get a new version and prevent a headache. – LordNeckbeard Oct 31 '17 at 18:40

You have several options available with the image file demuxer.

Using the sequence pattern

ffmpeg -framerate 25 -i "CS585Bats-FalseColor_frame%09d.ppm" output

You can change the start number with the -start_number input option.

Using the glob pattern

ffmpeg -pattern_type glob -framerate 25 -i "CS585Bats-FalseColor_frame*.ppm" output

If these are the only PPM files in the directory your glob pattern can be simpler:

ffmpeg -pattern_type glob -framerate 25 -i "*.ppm" output
share|improve this answer

Not sure what bash script will do the task but this Python script works like a charm:

import cv2
import glob

img1 = cv2.imread('bat/FalseColor/CS585Bats-FalseColor_frame000000750.ppm')
height, width, layers = img1.shape

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

filenames = glob.glob('bat/FalseColor/*.ppm')
for filename in filenames:
    img = cv2.imread(filename)
    video.write(img)

cv2.destroyAllWindows()
video.release()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.