I finally managed to get videoIO in Jaunty (thanks to Peitschie for his excellent wiki and help).
Things work fine for some codecs (e.g. mpeg4), but not for some others (eg xvid).
For example:
vw=videoWriter('test.avi', 'codec', 'xvid');
for ii=1:50
addframe(vw,rand(512));
end
close(vw);
creates without reporting any errors an unreadable file with size 5.5KB. The file size doesn't change when I add more frames or change the frame size, and when I try to read it I get:
??? Error using ==> videoReader_ffmpegPopen2
Could not find the stream info for "test.avi".
Failed assertion : (ffmpegRc = (av_find_stream_info(pFormatCtx))) >= 0
ffmpeg error -1: Unrecognized ffmpeg error code.
Function : void VideoIO::FfmpegIVideo::open(const std::string&)
File : FfmpegIVideo.cpp
Line : 291
Error in ==> videoReader.videoReader at 151
vr.handle = feval(vr.plugin, 'open',vr.handle, ...
Error in ==> videoIO_test at 17
vr = videoReader('test.avi');
The videoReader works fine with other xvid files which I created with previous versions of ffmpeg/videoIO
The same script works fine with 'mpeg4'. For example:
vw=videoWriter('test.avi', 'codec', 'mpeg4');
for ii=1:50
addframe(vw,rand(512));
end
close(vw);
creates nice sequences that can be seen and read with no problems.
The problem has been confirmed by Peitschie, so there should be something going on with videoWriter.
FYI my latest configuration is videoIO r725, matlab R2008a, and
Is xvid the only codec that has problems? A Windows user is also having troubles with xvid, so I'm trying to figure out if this problem is specific to xvid.
On my box, I don't have xvid installed, and I only have decoding troubles with some of the more esoteric codecs like old RealVideo ones, Microsoft MPEG4 v1, and some of the mjpeg-like variants (pam, pgm, etc.).
clc;
clear all;
codecs = videoWriter([],'codecs');
for ci = 1:length(codecs)
codec = codecs{ci};
fprintf('%s: ', codec);
try
vw = videoWriter('t.avi', 'codec',codec, 'width',720, 'height',480);
for i=1:50
addframe(vw, rand);
end
close(vw);
encoded = 1;
catch
encoded = 0;
fprintf('encoding fails\n');
end
if encoded
try
vr = videoReader('t.avi');
for i=1:50-8
assert(next(vr));
assert(~isempty(getframe(vr)));
end
close(vr);
fprintf('success\n');
catch
fprintf('DECODING fails\n');
end
end
end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
By the way, isn't it strange that some other codecs, for example Schroedinger/dirac give the following error:
>> videoWriter('test.avi','codec','libschroedinger')
??? Error using ==> videoWriter_ffmpegPopen2
The "libschroedinger" codec is not recognized by your version of ffmpeg.
Failed assertion : newCodecId != CODEC_ID_NONE
Function : virtual void VideoIO::FfmpegOVideo::setup(VideoIO::KeyValueMap&)
File : FfmpegOVideo.cpp
Line : 195
Error in ==> videoWriter.videoWriter at 124
[vw.handle,vw.w,vw.h] = feval(vw.plugin, 'open', vw.handle, ...
I can assure you that in the same system, I can use ffmpeg from command line to compress videos with Schroedinger. Something like:
On the libschroedinger issue, I did a little poking around. FfmpegOVideo::buildCodecMaps uses some older code with a manually-built mapping of all codec types. Later, I wrote what's found in the enumerateFormats function in FfmpegCommon.cpp that dynamically gets the list of codecs. It looks like I can now modify FfmpegOVideo so that it uses the dynamic method and adds extra code for extracting the codec ID from ffmpeg's data structures. I'll add this to the to-do list.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just in case it is of any help to you, I did a further check to see which codecs give the: 'The "XXXX" codec is not recognized by your version of ffmpeg.' error.
For xvid and theora I've fount out that to be ok, one needs to use "xvid" and "theora" (instead of "lib...."), but for the rest I couldn't find an alternative that works.
Let me know if you need any more info on this or the xvid case.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I finally had a chance to hunt down the problem. FFMPEG has a field, sample_aspect_ratio. Nearly all codecs are okay with the aspect ratio being left unspecified (defaulting to an aspect ratio of 1:1 for square pixels). Unfortunately, libxvid doesn't want to make any guesses and thus it requires an explicit setting. I'm putting a fix in that hard codes the aspect ratio to 1:1. If you're impatient, add the following line:
`st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q(1, 1);`
just before the return statement in FfmpegOVideo::addVideoStream().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
At a library level, explicitly setting just the sample_aspect_ratio (think "pixel" when you see "sample") fixes the problem. As I recall from hunting around ffmpeg.c, the ffmpeg application uses the frame aspect ratio to calculate the pixel aspect ratio (though I could be remembering incorrectly; once I found a solution, I stopped hunting).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello there,
I finally managed to get videoIO in Jaunty (thanks to Peitschie for his excellent wiki and help).
Things work fine for some codecs (e.g. mpeg4), but not for some others (eg xvid).
For example:
vw=videoWriter('test.avi', 'codec', 'xvid');
for ii=1:50
addframe(vw,rand(512));
end
close(vw);
creates without reporting any errors an unreadable file with size 5.5KB. The file size doesn't change when I add more frames or change the frame size, and when I try to read it I get:
??? Error using ==> videoReader_ffmpegPopen2
Could not find the stream info for "test.avi".
Failed assertion : (ffmpegRc = (av_find_stream_info(pFormatCtx))) >= 0
ffmpeg error -1: Unrecognized ffmpeg error code.
Function : void VideoIO::FfmpegIVideo::open(const std::string&)
File : FfmpegIVideo.cpp
Line : 291
Error in ==> videoReader.videoReader at 151
vr.handle = feval(vr.plugin, 'open',vr.handle, ...
Error in ==> videoIO_test at 17
vr = videoReader('test.avi');
The videoReader works fine with other xvid files which I created with previous versions of ffmpeg/videoIO
The same script works fine with 'mpeg4'. For example:
vw=videoWriter('test.avi', 'codec', 'mpeg4');
for ii=1:50
addframe(vw,rand(512));
end
close(vw);
creates nice sequences that can be seen and read with no problems.
The problem has been confirmed by Peitschie, so there should be something going on with videoWriter.
FYI my latest configuration is videoIO r725, matlab R2008a, and
FFmpeg version 0.5-svn17737+3:0.svn20090303-1ubuntu6, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --extra-version=svn17737+3:0.svn20090303-1ubuntu6 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --disable-stripping --disable-vhook --enable-libdc1394 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Apr 10 2009 23:18:41, gcc: 4.3.3
Please have a look when you have some time.
Thanks and good luck with your defense dalleyg...
emmdarakis,
Is xvid the only codec that has problems? A Windows user is also having troubles with xvid, so I'm trying to figure out if this problem is specific to xvid.
On my box, I don't have xvid installed, and I only have decoding troubles with some of the more esoteric codecs like old RealVideo ones, Microsoft MPEG4 v1, and some of the mjpeg-like variants (pam, pgm, etc.).
clc;
clear all;
codecs = videoWriter([],'codecs');
for ci = 1:length(codecs)
codec = codecs{ci};
fprintf('%s: ', codec);
try
vw = videoWriter('t.avi', 'codec',codec, 'width',720, 'height',480);
for i=1:50
addframe(vw, rand);
end
close(vw);
encoded = 1;
catch
encoded = 0;
fprintf('encoding fails\n');
end
if encoded
try
vr = videoReader('t.avi');
for i=1:50-8
assert(next(vr));
assert(~isempty(getframe(vr)));
end
close(vr);
fprintf('success\n');
catch
fprintf('DECODING fails\n');
end
end
end
Hello there,
I'm using the unstripped codec libraries provided by the ubuntu repos (and maybe few more libraries that I can't recal) and that's what I get:
asv1: encoding fails
asv2: encoding fails
bmp: encoding fails
dnxhd: encoding fails
dvvideo: success
ffv1: success
ffvhuff: success
flashsv: encoding fails
flv: encoding fails
gif: encoding fails
h261: encoding fails
h263: encoding fails
h263p: success
huffyuv: success
jpegls: encoding fails
libschroedinger: encoding fails
libtheora: encoding fails
libx264: encoding fails
libxvid: encoding fails
ljpeg: encoding fails
mjpeg: success
mpeg1video: success
mpeg2video: success
mpeg4: success
msmpeg4: encoding fails
msmpeg4v1: DECODING fails
msmpeg4v2: success
pam: DECODING fails
pbm: DECODING fails
pgm: DECODING fails
pgmyuv: DECODING fails
png: success
ppm: DECODING fails
qtrle: DECODING fails
rawvideo: encoding fails
roqvideo: encoding fails
rv10: DECODING fails
rv20: DECODING fails
sgi: encoding fails
snow: encoding fails
svq1: encoding fails
targa: encoding fails
tiff: encoding fails
wmv1: success
wmv2: success
zlib: encoding fails
zmbv: encoding fails
By the way, isn't it strange that some other codecs, for example Schroedinger/dirac give the following error:
>> videoWriter('test.avi','codec','libschroedinger')
??? Error using ==> videoWriter_ffmpegPopen2
The "libschroedinger" codec is not recognized by your version of ffmpeg.
Failed assertion : newCodecId != CODEC_ID_NONE
Function : virtual void VideoIO::FfmpegOVideo::setup(VideoIO::KeyValueMap&)
File : FfmpegOVideo.cpp
Line : 195
Error in ==> videoWriter.videoWriter at 124
[vw.handle,vw.w,vw.h] = feval(vw.plugin, 'open', vw.handle, ...
I can assure you that in the same system, I can use ffmpeg from command line to compress videos with Schroedinger. Something like:
ffmpeg -i test_%03d.png -vcodec libschroedinger test.avi
works fine. I don't know if that's related to the xvid problems at all.
Thanks a lot...
Thanks for the info.
On the libschroedinger issue, I did a little poking around. FfmpegOVideo::buildCodecMaps uses some older code with a manually-built mapping of all codec types. Later, I wrote what's found in the enumerateFormats function in FfmpegCommon.cpp that dynamically gets the list of codecs. It looks like I can now modify FfmpegOVideo so that it uses the dynamic method and adds extra code for extracting the codec ID from ffmpeg's data structures. I'll add this to the to-do list.
Hi there,
I didn't know much of these details.
Just in case it is of any help to you, I did a further check to see which codecs give the: 'The "XXXX" codec is not recognized by your version of ffmpeg.' error.
Here they are:
'bmp' 'dnxhd' 'flashsv' 'flv' 'gif' 'jpegls' 'libschroedinger' 'libtheora' 'libx264' 'libxvid' 'msmpeg4' 'roqvideo' 'sgi' 'targa' 'tiff' 'zmbv'
For xvid and theora I've fount out that to be ok, one needs to use "xvid" and "theora" (instead of "lib...."), but for the rest I couldn't find an alternative that works.
Let me know if you need any more info on this or the xvid case.
Thanks
Okay, thanks. That's helpful.
The "XXXX" problem is independent of whatever other xvid issues there are.
I finally had a chance to hunt down the problem. FFMPEG has a field, sample_aspect_ratio. Nearly all codecs are okay with the aspect ratio being left unspecified (defaulting to an aspect ratio of 1:1 for square pixels). Unfortunately, libxvid doesn't want to make any guesses and thus it requires an explicit setting. I'm putting a fix in that hard codes the aspect ratio to 1:1. If you're impatient, add the following line:
`st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q(1, 1);`
just before the return statement in FfmpegOVideo::addVideoStream().
Hi delleyg,
I'm moving house these days and didn't have time to post earlier.
Indeed long time ago I figured out too that libxvid wouldn't work without the aspect ratio option.
Are you sure that it is the pixel aspect ratio and not the aspect ratio of the frame?? Ffmpeg documentation describes it as:
`-aspect aspect'
Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777).
which to me it sounds more like the aspect ratio of the frame.
Regards.
At a library level, explicitly setting just the sample_aspect_ratio (think "pixel" when you see "sample") fixes the problem. As I recall from hunting around ffmpeg.c, the ffmpeg application uses the frame aspect ratio to calculate the pixel aspect ratio (though I could be remembering incorrectly; once I found a solution, I stopped hunting).