Update to MP4 or H264 and the constraints of containers

After a reader identified that a re-wrap method wasn’t working, they kindly supplied a test file to analyse.

In the original post I detailed how easy it was to re-wrap the DVR export streams so that they could be dealt with for any purpose. That post was written in Nov 2013. After receiving the test file, I attempted the documented method again and it failed.

It all comes down to a number of issues. The version of FFmpeg, the type of H264 Bitstream and the type of container used to house the H264 Bitsream.


Above is a FFmpeg version from March 2014. The exact version number is at the top.

Using the same command as on the previous post, the placing of the H264 stream into an AVI container worked.

ffmpeg -f h264 -i thefile.mp4 -vcodec copy -fflags genpts -f avi thefile.avi

As can be seen below, the avi has been created successfully and the thumbnail is displayed:


What about a recent version of FFmpeg?


Above is the FFmpeg version from June 2014.

This time – problems!

june-ffmpeg conversion failed

Various error messages appear but the clue lies in the red lines at the bottom. This detailed a problem with the bitstream. The last red line is a common error message which, in my experience, suggests that that the frames cannot be placed inside a specific container.

If we change the stream by transcoding, will it go into an AVI? – Yes. By transcoding to Raw Uncompressed – it worked.

If we change the Container Format, will it work? – Yes. By retaining the original H264 Bitstream and placing it into either the M4V Container or the MKV Container – it worked. Example:

ffmpeg -f h264 -i thefile.mp4 -c:v copy thefile.m4v

In summary, the older FFmpeg allows the bitstream type used by the DVR to be placed into the avi container. The newer FFmpeg does not. This is not a fault with FFmpeg. This is down to the AVI Container format being old and not really designed for the H264 video format.

Transcoding is fine, whether to uncompressed for editing and then further transcoding or direct to another format such as Windows Media. Example for High Quality WMV..

ffmpeg -f h264 -i thefile.mp4 -qscale 2 thefile.wmv

There are various documents online regarding the bitstream types and the suitable containers but I found this one particularly helpful.

www.szatmary.org/blog/25 – The h.264 Bitstream

As always, hope it helps….


By Spreadys Posted in EEPIP

9 comments on “Update to MP4 or H264 and the constraints of containers

  1. Pingback: MP4 or H264? | Spreadys.com

  2. Hi Spready
    Thanks for this post, I have the same issues from a Zmodo DVR however, I need to convert the audio stream as well, the above (and previous method as per your first post) will only converts the video stream and does the trick. Could you possibly point me in the right direction?

    Many Thanks

    • Hi there,
      Audio can be a much bigger challenge. Although the stream can usually be seen and isolated, identifying the sample rate, the bit rate and encoding can be a huge task. If you stick the player, associated files and an export file into some secure online storage and, I will take a look and see if anything jumps out! No promises though!! david (at) spreadys.com

  3. HI there, I’ve been using the command to convert a SEC file. The transcoding seems to be fine but the m4v file (played in VLC) is blank. Any idea what the reason could be? thanks in advance for any help!

    • Hi nix,
      Are you referring to the files that are associated with an .exe, derived from Samsung DVR’s? Its a bit difficult to assess without seeing the file but usually, if it were the FFmpeg version, then the transcode / rewrap just would not work. Being left with purely black frames is a mystery.
      You could try an older version which may be less fussy.

      Is the SEC detected by software as a video stream – does MediaInfo accept it and understand it?

      You may need to force the input format in FFmpeg. Usually -f h264 before the -i

      Sorry can’t be much more help – anything more just drop us an email on the link at http://www.forensicvideo.training

  4. Your post has been helpful and I feel closer to converting my files from SEC but having some issues still. MediaInfo is reporting a stream found. AVI fails, and MP4 generates a file but is unable to play in any player. The file also contains audio. Trying to get them converted for use in Premier and Audience for audio clean up. Have tried current and older version of ffmpeg. I also read the H264 post as well and the container direction did not help improve my efforts. DVR is Samsung SDR-C75300.

    Container and general info
    AVG: 71.0 MiB
    1 video stream: AVC

    First video stream
    704*480 (3:2), AVC(High@L3)(CABAC/1 Ref Frames)

    ffmpeg -f h264 -r 4 -i source.sec -vcodec copy -vsync drop -fflags genpts -f mp4 new.mp4

    Getting this message multiple times: [h264 @ 0382c460] Invalid NAL unit 0, skipping. (RED)

    As well as in yellow: [mp4 @ 0382e9e0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
    [mp4 @ 0382e9e0] Encoder did not produce proper pts, making some up.

    Any help would be great. Thanks.

    • Try an older version of FFmpeg from Zeranoes site. Try Ver 2.1.1, from late 2013.
      You also may not have any luck with audio. I had some Audio from another samsung unit recently and this could not be easily extracted.
      The Audio streams are not detected correctly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s