How can I convert raw h264 file from IP camera to something playable on a PC?

2

My security camera (Victure PC730) stores short videos on the SD card if it detects any motion.

The files are named xx.h264.

No player (VLC, MPlayer, …) is able to play it.

It seems to be a some kind of h264 compression.

I tried to convert it with FFmpeg like

ffmpeg -i 00.264 -bsf h264_mp4toannexb -vcodec libx264 out00.mp4

And also with a lot of other options. The conversion always generates a lot of errors like this:

out00.h264: corrupt decoded frame in stream 0
[h264 @ 0000000000509a00] concealing 7804 DC, 7804 AC, 7804 MV errors in P frame

out00.h264: corrupt decoded frame in stream 0
[h264 @ 00000000036e2a00] concealing 8045 DC, 8045 AC, 8045 MV errors in P frame

[h264 @ 000000000366fc80] top block unavailable for requested intra mode -1
[h264 @ 000000000366fc80] error while decoding MB 78 0, bytestream 1153
[h264 @ 000000000366fc80] concealing 8131 DC, 8131 AC, 8131 MV errors in P frame

out00.h264: corrupt decoded frame in stream 0
[h264 @ 0000000002bf0e40] concealing 7930 DC, 7930 AC, 7930 MV errors in P frame

[NULL @ 00000000004f2980] illegal POC type 10
out00.h264: corrupt decoded frame in stream 0
[h264 @ 00000000036e2a00] illegal POC type 10
frame= 1489 fps= 12 q=28.0 size=    5888kB time=00:00:57.44 bitrate= 839.7kbits/
[h264 @ 00000000036e2a00] illegal POC type 10
    Last message repeated 1 times
out00.h264: corrupt decoded frame in stream 0
[h264 @ 00000000004e2bc0] top block unavailable for requested intra mode -1
[h264 @ 00000000004e2bc0] error while decoding MB 62 0, bytestream 1441

Here is the beginning of the file:

image of a hexdump of the first bytes

You can see the NAL unit delimiter 00 00 01 very often, so the file seems to contain NAL units, but I am not familiar with the payload inside the NAL units.

Any idea how to convert that to a playable format is welcome.

Winf

Posted 2020-02-19T00:18:39.357

Reputation: 21

1That is not a standard/valid h264 stream. It has some sort of proprietary header I don’t recognize. Everything before 00 00 01 67 is header that makes it invalid. – szatmary – 2020-02-19T01:05:14.673

Answers

1

Instead of converting the video, you most likely need to get that stream into an MP4 video container. So use a command like this:

ffmpeg -i input.h264 -c copy output.mp4

That will simply copy the raw contents of the input.h264 into output.mp4. But it will now be in an MP4 container that should playback as expected in all compatible players. Maybe even force a frame rate like this:

ffmpeg -framerate 30 -i input.h264 -c copy output.mp4

And if somehow the video stream is genuinely damaged, try this command which basically does similar stuff as the first command, but in this case it ignores errors:

ffmpeg -err_detect ignore_err -i input.h264 -c copy output.mp4

JakeGould

Posted 2020-02-19T00:18:39.357

Reputation: 38 217

Instead of output.mp4 (a file which might easily be overwritten), you might instead use "$(date +"%Y%m_%d_%I_%M_%p").mp4"_ as the destination file name. – K7AAY – 2020-02-19T00:52:28.720

So far I had no success with the recommendations.

Based on the comment of szatmary I now tried to remove NAL units that may be corrupt / invalid.

NAL units start with "00 00 01" followed by a header byte, e.g. "67". I now removed NAL units depending on the header byte. The larger NAL units have header bytes of "65" and "41". They seem to contain the video information. "67" also seems to be relevant.

Then I use ffmpeg as suggested. Without success.

Is the payload of the NAL units not standard conform? At address 0x7E a NAL unit containing video starts, is it valid? – Winf – 2020-02-19T21:58:18.537