Reading video file compressed losslessly with x264

3 views (last 30 days)
Till on 27 Nov 2014
Answered: Walter on 19 Jun 2019
As the title suggests, I have a problem reading video frames from a video file compressed losslessly with x264. I am using MATLAB 2014b.
I have used x264 lossless compression in VirtualDub. The result is a video file that plays fine in VLC and can also be reopened in VirtualDub. I can also succesfully create a VideoReader object referencing to this video file. The VideoReader object gives me the correct video properties like FrameRate, Width, Height, and so forth. It even has the correct NumberOfFrames property.
However, when I first try to read frames from the object, MATLAB generates an error:
Error using VideoReader/readFrame (line 105)
No more frames available to read from file.
The same happens when I try the older command "read" and explicitly refer to frames I want to read (i.e. the first frame or the last frame, using Inf).
Interestingly, when I compress the same source video file with x264 and use the highest quality setting, i.e. almost lossless while keeping the other settings the same, then MATLAB is able to read frames from the compressed video.
Is that a bug? Do I need to adjust some settings in my codecs or is there another workaround?
Thanks in advance!
  1 Comment
Gaszton on 29 Jan 2016
i just ran into the exact same problem.
Must be a bug.

Sign in to comment.

Answers (2)

Sergey Salishev
Sergey Salishev on 24 May 2018
It seems that the problem is due to pixel format yuv444.
I converted using the ffmpeg with the following command line and it magically works
ffmpeg -i %1.mkv -c:v libx264 -pix_fmt yuv420p -map 0:v:%2 %1_%2.mkv

Walter on 19 Jun 2019
THe recommendation by Sergey did not work for me on R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!