Aviread not reading frames correctly from video, repeates key frames

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Aviread not reading frames correctly from video, repeates key frames

pecenastruca
The problems:

I have a .mp4 video, trying to read it. What I get as an end result are
repeating key frames. I tested the same setup in a virtualbox machine,
installed Ubuntu 18.04, required dependencies for the video package and the
same input file, which worked.

The other problem:

It seems to fail reading the file at position 471 and every position after.
The video has 600 frames in total.
 
>> aviread("dge.mp4",471)
AVHandler: Error reading packet after timestamp 0
error: aviread: cannot read frame 471

Example:

So if the video has 30 frames per second and a key frame is every 1 second,
that means that there are going to be 30 duplicate frames in a 1 second
video.

Link to the video file:
https://www.dropbox.com/s/rfge2ek4njgegmp/dge.mp4

What I tried so far:

I am using octave 4.2.2. I tried reinstalling and building from source, same
results. I am running Xubuntu 16.04. The versions of libavutil-dev
libavformat-dev libswscale-dev libavcodec-dev were all on versions
7:2.8.15. I then removed them and replaced them with a newer, backported
version of FFMPEG-4
https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-4 from here.

I have run out of ideas what to try. It seems that the problem lies
somewhere inbetween Octave and the libraries. The libraries seem fine and
Octave works well too.

The code:
--------------------
pkg load video
pkg load image
info = aviinfo (video)
info.NumFrames

for i = 1:info.NumFrames-1
  string = int2str(i)
  concated = strcat("img",string,".jpeg")
  img = aviread(video,i);
  imwrite(img, concated)                  
end
--------------------
Output of aviinfo:

info =

  scalar structure containing the fields:

    Filename = dge.mp4
    FileSize =  18238587
    FileModDate = 04-Aug-2018 19:51:46
    NumFrames =  600
    FramesPerSecond =  29.934
    Width =  1920
    Height =  1080
    ImageType = truecolor
    VideoCompression = h264
    Quality =  100
    NumColormapEntries = 0
    AudioFormat = aac
    AudioRate =  48000
    NumAudioChannels =  2
    Title =
    Author =
    Comment =
The folder with the images:
<http://octave.1599824.n4.nabble.com/file/t373154/2019-01-05_13-17.png>




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

Andreas Weber-6
Hi Pecena?

Am 05.01.19 um 13:24 schrieb pecenastruca:
> The problems:

You should report bugs to the bugtracker so that it isn't lost.

>>> aviread("dge.mp4",471)
> AVHandler: Error reading packet after timestamp 0

Your used codec uses AV_CODEC_CAP_DELAY, see
https://libav.org/documentation/doxygen/master/group__lavc__core.html#ga3f55f5bcfbb12e06c7cb1195028855e6

this isn't handled yet. Can you provide a patch to implement this?

Thank you, Andy


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

Andreas Weber-6
Am 06.01.19 um 20:14 schrieb Andreas Weber:

> Hi Pecena?
>
> Am 05.01.19 um 13:24 schrieb pecenastruca:
>> The problems:
>
> You should report bugs to the bugtracker so that it isn't lost.
>
>>>> aviread("dge.mp4",471)
>> AVHandler: Error reading packet after timestamp 0
>
> Your used codec uses AV_CODEC_CAP_DELAY, see
> https://libav.org/documentation/doxygen/master/group__lavc__core.html#ga3f55f5bcfbb12e06c7cb1195028855e6 
>
>
> this isn't handled yet. Can you provide a patch to implement this?
>
> Thank you, Andy
>
>

I pushed a change here:
https://sourceforge.net/p/octave/video/ci/default/tree/

can you clone the repo and try it?

-- Thanks, Andy



Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

Amol Ghaware
octave:11> fsamp=8000;
octave:12> fcuts=[1000 1500];
octave:13> mags=[1 0];
octave:14> devs=[0.05 0.01];
octave:15> [n,wn,beta,ftype]=kaiserord(fcuts,mags,devs,fsamp);
octave:16> hh=fir1(n,wn,ftype,kaiser(n+1,beta));
octave:17> freqz(hh)
warning: range error for conversion to character value
warning: called from
    __gnuplot_drawnow__ at line 87 column 16
I am trying design Low pass filter in octave getting above error, I am getting blank plot, Can anybody tell how to solve above warning ?


On Mon, Jan 7, 2019 at 1:13 AM Andreas Weber <[hidden email]> wrote:
Am 06.01.19 um 20:14 schrieb Andreas Weber:
> Hi Pecena?
>
> Am 05.01.19 um 13:24 schrieb pecenastruca:
>> The problems:
>
> You should report bugs to the bugtracker so that it isn't lost.
>
>>>> aviread("dge.mp4",471)
>> AVHandler: Error reading packet after timestamp 0
>
> Your used codec uses AV_CODEC_CAP_DELAY, see
> https://libav.org/documentation/doxygen/master/group__lavc__core.html#ga3f55f5bcfbb12e06c7cb1195028855e6
>
>
> this isn't handled yet. Can you provide a patch to implement this?
>
> Thank you, Andy
>
>

I pushed a change here:
https://sourceforge.net/p/octave/video/ci/default/tree/

can you clone the repo and try it?

-- Thanks, Andy





--
Thanks and Regards,
Amol
WS492


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

pecenastruca
In reply to this post by Andreas Weber-6
Thank you for the swift reply!


Andreas Weber-6 wrote

> Hi Pecena?
>
> Am 05.01.19 um 13:24 schrieb pecenastruca:
>> The problems:
>
> You should report bugs to the bugtracker so that it isn't lost.
>
>>>> aviread("dge.mp4",471)
>> AVHandler: Error reading packet after timestamp 0
>
> Your used codec uses AV_CODEC_CAP_DELAY, see
> https://libav.org/documentation/doxygen/master/group__lavc__core.html#ga3f55f5bcfbb12e06c7cb1195028855e6
>
> this isn't handled yet. Can you provide a patch to implement this?
>
> Thank you, Andy

I'm sorry, but I am not capable for implementing a patch for this.



Andreas Weber-6 wrote

> Am 06.01.19 um 20:14 schrieb Andreas Weber:
>> Hi Pecena?
>>
>> Am 05.01.19 um 13:24 schrieb pecenastruca:
>>> The problems:
>>
>> You should report bugs to the bugtracker so that it isn't lost.
>>
>>>>> aviread("dge.mp4",471)
>>> AVHandler: Error reading packet after timestamp 0
>>
>> Your used codec uses AV_CODEC_CAP_DELAY, see
>> https://libav.org/documentation/doxygen/master/group__lavc__core.html#ga3f55f5bcfbb12e06c7cb1195028855e6 
>>
>>
>> this isn't handled yet. Can you provide a patch to implement this?
>>
>> Thank you, Andy
>>
>>
>
> I pushed a change here:
> https://sourceforge.net/p/octave/video/ci/default/tree/
>
> can you clone the repo and try it?
>
> -- Thanks, Andy

I cloned it. But the install failed. I compiled the package with "make dist"
to provide a package. I then installed it in octave via pkg install. I am
not sure what the install error is giving me. I tried to run "make install"
which I am speculating the same as running pkg install inside Octave? I get
the same error. I get the following error:

>> pkg install video-1.2.4.tar.gz
AVHandler.cc: In member function ‘int AVHandler::setup_read()’:
AVHandler.cc:246:29: error: ‘CODEC_CAP_TRUNCATED’ was not declared in this
scope
   if (codec->capabilities & CODEC_CAP_TRUNCATED)
                             ^
AVHandler.cc:247:30: error: ‘CODEC_FLAG_TRUNCATED’ was not declared in this
scope
     vstream->codec->flags |= CODEC_FLAG_TRUNCATED;
                              ^
AVHandler.cc: In member function ‘int AVHandler::read_frame(unsigned int)’:
AVHandler.cc:361:37: warning: comparison between signed and unsigned integer
expressions [-Wsign-compare]
   if ((uint64_t)vstream->start_time != AV_NOPTS_VALUE)
                                     ^
AVHandler.cc:441:74: error: ‘CODEC_CAP_DELAY’ was not declared in this scope
       if (avcodec_find_decoder(vstream->codec->codec_id)->capabilities &
CODEC_CAP_DELAY)
                                                                          ^
make: *** [AVHandler.o] Error 1
make: Entering directory '/tmp/oct-zJ7qYu/video-1.2.4/src'
/usr/bin/mkoctfile -Wall -v -Wno-deprecated-declarations -c -DHAVE_CONFIG_H
AVHandler.cc -o AVHandler.o
g++ -std=gnu++11 -c -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC
-I/usr/include/octave-4.2.2/octave/.. -I/usr/include/octave-4.2.2/octave
-I/usr/include/hdf5/serial -I/usr/include/mpi  -pthread -fopenmp -g -O2
-fstack-protector-strong -Wformat -Werror=format-security  -Wall
-Wno-deprecated-declarations   -DHAVE_CONFIG_H AVHandler.cc -o AVHandler.o
Makefile:17: recipe for target 'AVHandler.o' failed
make: Leaving directory '/tmp/oct-zJ7qYu/video-1.2.4/src'

pkg: error running `make' for the video package.
error: called from
    configure_make at line 95 column 9
    install at line 194 column 7
    pkg at line 394 column 9






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

Andreas Weber-6
Am 07.01.19 um 11:05 schrieb pecenastruca:
> I cloned it. But the install failed.

After clone you have to cd to src, ./bootstrap && ./configure to create
the Makefile.

In the toplevel directory you can run "make run" without installation.

> AVHandler.cc:246:29: error: ‘CODEC_CAP_TRUNCATED’ was not declared in this

I've used libav(util, format, and so on) 7:3.2.12-1~deb9u1
It looks like your installed lib lacks CODEC_CAP_TRUNCATED?

-- Andy


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

pecenastruca
Andreas Weber-6 wrote

> Am 07.01.19 um 11:05 schrieb pecenastruca:
>> I cloned it. But the install failed.
>
> After clone you have to cd to src, ./bootstrap && ./configure to create
> the Makefile.
>
> In the toplevel directory you can run "make run" without installation.
>
>> AVHandler.cc:246:29: error: ‘CODEC_CAP_TRUNCATED’ was not declared in
>> this
>
> I've used libav(util, format, and so on) 7:3.2.12-1~deb9u1
> It looks like your installed lib lacks CODEC_CAP_TRUNCATED?
>
> -- Andy

I ran ./bootstrap && ./configure, afterwards "make run" in the toplevel dir,
but still fails with the same output.

I was using libav(and others) of version 7:4.1-1 from here
https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-4 (a backport to the
xenial ubuntu dist). I then tried the 7.3* from
https://launchpad.net/~jonathonf/+archive/ubuntu/ffmpeg-3 which are of
version 7:3.4.4-1.  I ran make install which seemed to work:

user@hplaptop:~/ovid/octave-video$ make install
Creating package version 1.2.4 release ...
rm -rf video-1.2.4
hg archive --exclude ".hg*" --exclude Makefile --type files video-1.2.4
cd "video-1.2.4" && rm -rf "devel/" && cd "src/" && ./bootstrap && rm -rf
"autom4te.cache"
chmod -R a+rX,u+w,go-w video-1.2.4
tar cf - --posix video-1.2.4 | gzip -9n > video-1.2.4.tar.gz
rm -rf video-1.2.4
Installing package locally ...
octave --silent --eval 'pkg install video-1.2.4.tar.gz;'
AVHandler.cc: In member function ‘int AVHandler::read_frame(unsigned int)’:
AVHandler.cc:361:37: warning: comparison between signed and unsigned integer
expressions [-Wsign-com                                                                                  
pare]
   if ((uint64_t)vstream->start_time != AV_NOPTS_VALUE)
                                     ^
The video package is installed in Octave now, but the reading of the file
fails at some point:
AVHandler: Error decoding video stream
error: aviread: cannot read frame 40
error: called from
    atest at line 11 column 7

in the atest function that was the line with the img = aviread(video,i);



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

Andreas Weber-6
Am 07.01.19 um 11:39 schrieb pecenastruca:
> The video package is installed in Octave now, but the reading of the file
> fails at some point:
> AVHandler: Error decoding video stream
> error: aviread: cannot read frame 40
> error: called from
>      atest at line 11 column 7
>
> in the atest function that was the line with the img = aviread(video,i);

This is the same video previously linked from dropbox?
Do you know C programming?

-- Andy


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

pecenastruca
Andreas Weber-6 wrote

> Am 07.01.19 um 11:39 schrieb pecenastruca:
>> The video package is installed in Octave now, but the reading of the file
>> fails at some point:
>> AVHandler: Error decoding video stream
>> error: aviread: cannot read frame 40
>> error: called from
>>      atest at line 11 column 7
>>
>> in the atest function that was the line with the img = aviread(video,i);
>
> This is the same video previously linked from dropbox?
> Do you know C programming?
>
> -- Andy

Yes it is. Only the basics. I tested another video. With this one it worked.
It read all of the frames. So it seems that it does not like the videos
which I have. They are recorded with a Samsung mobile phone. info of the
"cwb3.avi" video:

>> aviinfo("cbw3.avi")
ans =

  scalar structure containing the fields:

    Filename = cbw3.avi
    FileSize =  837120
    FileModDate = 15-Jul-2018 19:38:52
    NumFrames =  250
    FramesPerSecond =  40
    Width =  256
    Height =  240
    ImageType = truecolor
    VideoCompression = indeo4
    Quality =  100
    NumColormapEntries = 0
    AudioFormat =
    AudioRate = 0
    NumAudioChannels = 0
    Title =
    Author =
    Comment =





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

pecenastruca
I have tested again in a virtualized enviroment, running Xubuntu 18.04,
installed all the libav* dependencies, they are of version  7:3.4.4-1 from
the ubuntu 18.04 repository. The Octave version installed is also from the
ubuntu repository, which is version 4.2.2
For reference: https://packages.ubuntu.com/bionic/video/ffmpeg 

I then installed the video package from forge by running "pkg install -forge
video".

With the current install, the frames were still repeated, but the video was
read.

Next I removed the video package from the official repo (forge), cloned it
from here https://sourceforge.net/p/octave/video/ci/default/tree/ , built it
and installed it with "make install". It installed without problems, except
for the unsigned comparison, but that I got before too. I then ran my code
to read the video file and it failed at frame 40.

AVHandler: Error decoding video stream
error: aviread: cannot read frame 40
error: called from
    atest at line 11 column 7


If you look at the video and how the frames change, the next repeated frame
appears at number 40, which I am guessing is the next keyframe. picture:
https://i.imgur.com/1hVdNms.png




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Aviread not reading frames correctly from video, repeates key frames

Andreas Weber-6
Am 08.01.19 um 13:00 schrieb pecenastruca:
> If you look at the video and how the frames change, the next repeated frame
> appears at number 40, which I am guessing is the next keyframe. picture:
> https://i.imgur.com/1hVdNms.png

I can have a look at the weekend, please feel free to remind me if you
don't get response until sunday.

-- Andy