[FFmpeg-devel] [PATCH] FLV meta injection (similar to FLVTOOLS2 but an addon patch for FFMPEG)

Michael Niedermayer michaelni
Sun Aug 12 10:56:40 CEST 2007


Hi

On Sun, Aug 12, 2007 at 12:14:57AM +0000, andrew wrote:
> I added FLV meta injection, I was working on a project similar to youtube a while ago and found ffmpeg didn't support meta tags for framing. This would mean flash actionscript couldnt get information on video points for scrolling. There is a tool which does the seperately called FLVTOOLS2 but is written in ruby and my webserver didnt have ruby installed so I added my own patch to FFMPEG and wanted to offer it.
> 
> Ive added a new argument called -flvmeta_inject , so people can toggle my patch or ignore it and use the old method without meta injection. example usage: 
> 
> ./ffmpeg -y -i einstein_redspot.avi -acodec mp3 -ar 22050 -flvmeta_inject -f flv einstein.flv

[...]

please read 8.5 and 8.6 from http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html


> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 10065)
> +++ ffmpeg.c	(working copy)
> @@ -33,6 +33,7 @@
>  #include "opt.h"
>  #include "fifo.h"
>  #include "avstring.h"
> +#include "flvenc.c"

are you serious?


>  
>  #if !defined(HAVE_GETRUSAGE) && defined(HAVE_GETPROCESSTIMES)
>  #include <windows.h>
> @@ -2404,6 +2405,11 @@
>          video_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24);
>  }
>  
> +static void opt_flvmeta_inject()
> +{
> +    flvmeta_inject = 1;        	
> +}

trailing whitespace and what is this option good for?


> +
>  #ifdef CONFIG_VHOOK
>  static void add_frame_hooker(const char *arg)
>  {
> @@ -2755,7 +2761,7 @@
>  
>          video_enc->codec_id = codec_id;
>          codec = avcodec_find_encoder(codec_id);
> -
> +        

cosmetic

>          for(i=0; i<opt_name_count; i++){
>               const AVOption *opt;
>               double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt);
> @@ -3675,7 +3681,8 @@
>      { "vtag", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_tag}, "force video tag/fourcc", "fourcc/tag" },
>      { "newvideo", OPT_VIDEO, {(void*)opt_new_video_stream}, "add a new video stream to the current output stream" },
>      { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" },
> -
> +    { "flvmeta_inject", 0, {(void*)opt_flvmeta_inject}, "add flv meta keyframe data" },

> +    

cosmetic


>      /* audio options */
>      { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" },
>      { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", },
> Index: cmdutils.c
> ===================================================================
> --- cmdutils.c	(revision 10065)
> +++ cmdutils.c	(working copy)
> @@ -66,7 +66,7 @@
>      const char *opt, *arg;
>      int optindex, handleoptions=1;
>      const OptionDef *po;
> -
> + 
>      /* parse options */

cosmetic


>      optindex = 1;
>      while (optindex < argc) {
> Index: libavformat/flvenc.c
> ===================================================================
> --- libavformat/flvenc.c	(revision 10065)
> +++ libavformat/flvenc.c	(working copy)
> @@ -25,6 +25,8 @@
>  #undef NDEBUG
>  #include <assert.h>
>  
> +static int flvmeta_inject = 0;   
> +

non constant static


>  static const AVCodecTag flv_video_codec_ids[] = {
>      {CODEC_ID_FLV1,    FLV_CODECID_H263  },
>      {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
> @@ -45,7 +47,13 @@
>  typedef struct FLVContext {
>      int hasAudio;
>      int hasVideo;
> +    int hasMetaData;
>      int reserved;

> +    

cosmetic

[...]
> @@ -163,6 +171,7 @@
>          }
>          av_set_pts_info(s->streams[i], 24, 1, 1000); /* 24 bit pts in ms */
>      }
> +    

cosmtic

>      put_tag(pb,"FLV");
>      put_byte(pb,1);
>      put_byte(pb,   FLV_HEADER_FLAG_HASAUDIO * flv->hasAudio
> @@ -183,7 +192,7 @@
>  
>      /* write meta_tag */
>      put_byte(pb, 18);         // tag type META
> -    metadata_size_pos= url_ftell(pb);
> +    metadata_size_pos = url_ftell(pb);

cosmetic


>      put_be24(pb, 0);          // size of data part (sum of all parts below)
>      put_be24(pb, 0);          // time stamp
>      put_be32(pb, 0);          // reserved
> @@ -201,7 +210,52 @@
>      put_amf_string(pb, "duration");
>      flv->duration_offset= url_ftell(pb);
>      put_amf_double(pb, 0); // delayed write
> +    
> +    flv->hasMetaData = flvmeta_inject;

cosmetic


[...]
> @@ -258,12 +312,41 @@
>      FLVContext *flv = s->priv_data;
>  
>      file_size = url_ftell(pb);
> +    
> +    int duration = flv->duration / (double)1000;
>  
>      /* update informations */
>      url_fseek(pb, flv->duration_offset, SEEK_SET);
> -    put_amf_double(pb, flv->duration / (double)1000);
> +    put_amf_double(pb, duration);

cosmetic



>      url_fseek(pb, flv->filesize_offset, SEEK_SET);
>      put_amf_double(pb, file_size);
> +    

cosmetic


[...]

> +        if (duration < flvduration)
> +            flvduration = (duration);
> +            
> +        int steptime = duration / flvduration;  

mixes declaration and statement, trailing whitespace


[...]

> -
> +    

cosmetic


[...]
> @@ -42,6 +42,13 @@
>  
>  #define AMF_END_OF_OBJECT         0x09
>  
> +#define NUM_OF_ENTRIES 20
> +
> +#define AMF_CHILDNODE       3
> +#define AMF_CHILDNODEVALUE  10
> +#define AMF_PARENTNODE      9
> +

these belong in the enum where the other AMF types are


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070812/02770e27/attachment.pgp>



More information about the ffmpeg-devel mailing list