2

I write software C/C++ to recover deleted files, and I need to identify files according to their binary content, so my question is there a simple way to know if a particular file is H.264 format video? is H.264 has an signature?

I saw the code of FFMPEG here, but can it help me, how?

codeDom
  • 1,814
  • 10
  • 26

3 Answers3

3

The problem is that H.264 is not a file format, it is a video compression standard, and as such it can be found in multiple file formats. You can have a .f4v encoded with H.264 as much as you can have .mp4 with H.264.

So, how do you solve your issue? Well, I strongly advise you to use a library that does that for you. libavformat, for example, should do the trick (check the AVStream and AVFormatContext structures, and the avformat_open_input function).

Now, if you absolutely want to do it without libraries, you can check out the documentation for each video container format that supports H.264 to see how to retrieve the encoding information of the video stream, but expect this to take you at least a month or two.

blue
  • 125
  • 9
  • I work with Visual Studio and can not compile `libavformat`, do you know a solution? – codeDom Oct 05 '16 at 11:51
  • Unfortunately I could not find binaries to use with Visual Studio, but the guys from FFmpeg made a [wiki article](https://trac.ffmpeg.org/wiki/CompilationGuide/MSVC) about compiling the sources with the Visual Compiler. If that doesn't do the trick, I guess you could also use another library, but I don't know any other, unfortunately. I think [libVLC](http://www.videolan.org/vlc/libvlc.html) could eventually do what you want, but don't quote me on that. – blue Oct 05 '16 at 13:27
3

For those who encounter this question but are looking for a cli solution you can use ffprobe:

ffprobe -loglevel error -select_streams v -show_entries stream=codec_name -of default=nw=1:nk=1 input.mkv

Outputs:

h264
llogan
  • 87,794
  • 21
  • 166
  • 190
1

If you want to use FFmpeg - avformat_find_stream_info() should help you. An there is an example.

Sergio
  • 7,657
  • 2
  • 22
  • 45