[Ffmpeg-devel] Problems encoding H264 with a MP4 / MOV container with ffmpeg

admin major4
Thu Jun 16 06:17:31 CEST 2005


Hello,

Here is a little report about current ffmpeg problems in muxing x264's 
H264 in MP4 or MOV.

The standard way to distribute H264 is well to use a MP4 container. 
However, until now, AVI was mostly used due to mencoder being first to 
link to x264. Now that ffmpeg also links to x264, it should finally 
allow to encode with a MP4 container so as everyone is happy.

However, there are currently two problems preventing ffmpeg to encode 
H264 into compliant MP4:

a) The first is that CVS does not have proper identification for h264 
video in MOV and MP4 containers. The attached patch by Erik Slagter 
fixes this (at least for MP4), and I suggest it being included into 
CVS.

b) The second problem is that, even with the above, the resulting 
stream is NOT playable by Quicktime 7 (Mac OSX), despite the fact that 
Quicktime 7's H264 is perfectly decodable by ffmpeg.  However, 
interestingly, streams encoded with x264 but muxed to mp4 with libmp4v2 
(mpeg4ip) ARE playable by Quicktime 7.

So I guess that comparing such two streams may eventually lead to the 
solution. I uploaded the following to the mplayer ftp in a folder named 
"mp4_h264":

CH20.h264.mp4.zip ->
	Clip encoded with ffmpeg to mp4 x264 (using the attached patch)
	It is NOT playable in Quicktime 7!

qt7.x264.mp4.zip ->
	Clip encoded with x264 and muxed to mp4 with libmp4v2 (mpeg4ip)
	It is playable in Quicktime 7!

At first look, "avcC" data present in the working clip seem missing 
from the ffmpeg clip.
Thank you


Index: movenc.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/movenc.c,v
retrieving revision 1.37
diff -u -p -r1.37 movenc.c
--- movenc.c	27 Mar 2005 00:16:17 -0000	1.37
+++ movenc.c	7 May 2005 08:22:32 -0000
@@ -259,7 +259,7 @@ static int mov_write_wave_tag(ByteIOCont
      return updateSize (pb, pos);
  }

-const CodecTag codec_movaudio_tags[] = {
+static const CodecTag codec_movaudio_tags[] = {
      { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') },
      { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') },
      { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') },
@@ -489,11 +489,12 @@ static int mov_write_esds_tag(ByteIOCont
      return updateSize (pb, pos);
  }

-const CodecTag codec_movvideo_tags[] = {
+static const CodecTag codec_movvideo_tags[] = {
      { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
      { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
      { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
      { CODEC_ID_H263, MKTAG('s', '2', '6', '3') },
+    { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
      { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
      { 0, 0 },
  };
@@ -1313,24 +1314,31 @@ static int mov_write_header(AVFormatCont
      MOVContext *mov = s->priv_data;
      int i;

-    for(i=0; i<s->nb_streams; i++){
+    for(i=0; i<s->nb_streams; i++)
+	{
          AVCodecContext *c= &s->streams[i]->codec;

-        if      (c->codec_type == CODEC_TYPE_VIDEO){
-            if (!codec_get_tag(codec_movvideo_tags, c->codec_id)){
+        if(c->codec_type == CODEC_TYPE_VIDEO)
+		{
+            if (!codec_get_tag(codec_movvideo_tags, c->codec_id))
+			{
                  if(!codec_get_tag(codec_bmp_tags, c->codec_id))
                      return -1;
                  else
                      av_log(s, AV_LOG_INFO, "Warning, using MS style 
video codec tag, the file may be unplayable!\n");
              }
-        }else if(c->codec_type == CODEC_TYPE_AUDIO){
-            if (!codec_get_tag(codec_movaudio_tags, c->codec_id)){
-                if(!codec_get_tag(codec_wav_tags, c->codec_id))
-                    return -1;
-                else
-                    av_log(s, AV_LOG_INFO, "Warning, using MS style 
audio codec tag, the file may be unplayable!\n");
-            }
          }
+		else
+			if(c->codec_type == CODEC_TYPE_AUDIO)
+			{
+            	if (!codec_get_tag(codec_movaudio_tags, c->codec_id))
+				{
+                	if(!codec_get_tag(codec_wav_tags, c->codec_id))
+                    	return -1;
+                	else
+                    	av_log(s, AV_LOG_INFO, "Warning, using MS style 
audio codec tag, the file may be unplayable!\n");
+            	}
+        	}
      }

      /* Default mode == MP4 */





More information about the ffmpeg-devel mailing list