[FFmpeg-devel] [Ffmpeg-user] difference between h263 and h264

Hassan Adeel hadeel
Thu Nov 1 08:29:51 CET 2007


Thanks for your iintrest!!

here is my code where i use avcodec_decode_video()...but i got "got_picture"
always false...why???

int write_output(AVStream *ist,AVFormatContext *oc,AVPacket* pkt)
        {
            uint8_t *ptr;
            int len, ret, got_picture, data_size, /*i,*/st_index;
            static short *samples= NULL;
            uint8_t *data_buf;
            static unsigned int samples_size= 0;
            int64_t ist_pts;
            int are_we_at_eof = 0;
            //printf("write_output: 1\n");
            if(!pkt)
            {
                  if(ist->codec->codec_type==CODEC_TYPE_VIDEO)
                  {
                     ivideo_pts= ivideo_next_pts; // needed for last
packet if vsync=0
                         ist_pts = ivideo_pts;
                  }
                  else
                  if(ist->codec->codec_type==CODEC_TYPE_AUDIO )
                  {
                        iaudio_pts= iaudio_next_pts;
                        ist_pts =iaudio_pts;
                  }
            }
            else
            if ( pkt->dts != AV_NOPTS_VALUE )
            { //FIXME seems redundant, as libavformat does this too
                if(ist->codec->codec_type==CODEC_TYPE_VIDEO)
                {
                      ivideo_next_pts = ivideo_pts = av_rescale_q(pkt->dts,
ist->time_base, AV_TIME_BASE_Q);
                          ist_pts = ivideo_pts;
                    }
                    else
                    if(ist->codec->codec_type==CODEC_TYPE_AUDIO )
                    {
                   iaudio_next_pts = iaudio_pts = av_rescale_q(pkt->dts,
ist->time_base, AV_TIME_BASE_Q);
                           ist_pts = iaudio_pts;
                    }
            }

            if (pkt == NULL)
            {
                /* EOF handling */
                ptr = NULL;
                len = 1;
                        st_index = ist->index;
                are_we_at_eof=1;
            }
            else
            {
                    len = pkt->size;
                    ptr = pkt->data;
                    st_index = pkt->stream_index;
            }
            while (len > 0)
            {
                    if(are_we_at_eof)
                    {
                            len=0;
                            are_we_at_eof=0;
                    }
                //        printf("write_output: WHILE START\n");
                    data_buf = NULL; /* fail safe */
                data_size = 0;
                    switch(ist->codec->codec_type)
                    {
                           case CODEC_TYPE_VIDEO:
                       /* XXX: allocate picture correctly */
                           if(ist->codec->codec->capabilities &
CODEC_CAP_TRUNCATED)
                      ist->codec->flags|=CODEC_FLAG_TRUNCATED;

        //                   printf("write_output: before video decode\n");
                       ret = avcodec_decode_video(ist->codec,picture,
&got_picture, ptr,
len);
        //                   printf("write_output: after video decode\n");

                                if (ret < 0)
                                        return -1;
                      if (!got_picture)
                      {
                   /* no picture yet */
                   if(pkt==NULL)
                          ///// handling last frames////////
                                           write_last_frames(oc,ist,(uint16_t*)samples);
                                    continue;
                }
                        if (ist->codec->time_base.num != 0)
                        {
                        ivideo_next_pts += ((int64_t)AV_TIME_BASE *
ist->codec->time_base.num) / ist->codec->time_base.den;
                    }

                    len = 0;
                break;

                            case CODEC_TYPE_AUDIO:
        //                           printf("write_output: AUDIO
DECODING\n");
                           /* XXX: could avoid copy if PCM 16 bits with same
                       endianness as CPU */
                           if(pkt)
                                samples= av_fast_realloc(samples,
&samples_size,
FFMAX(pkt->size, AVCODEC_MAX_AUDIO_FRAME_SIZE));

                       ret = avcodec_decode_audio(ist->codec, samples,
&data_size,ptr, len );
                       //                        printf("write_output:
After decode\n");
                                   if (ret < 0)
                                          return -1;

                           ptr += ret;
                       len -= ret;
                           /* Some bug in mpeg audio decoder gives */
                           /* data_size < 0, it seems they are overflows */
                       if (data_size <= 0)
                       {
                                /* no audio frame */
                                continue;
                       }
                           data_buf = (uint8_t *)samples;
                           iaudio_next_pts += ((int64_t)AV_TIME_BASE/2 *
data_size) /
(ist->codec->sample_rate * ist->codec->channels);
                           break;
                           default:
                                   return -1;
                                break;
                  }



if i forcefully make "got_picture = 0" after calling avcode_decode_video()
then got(converted) movie with complete sound but with messy frames...can
u tell me how can i convert this movie through my own code.

Note: ffmepeg on command line converts movie properly with following
command..

ffmpeg -i soruceFile destinationFile



> On Wed, Oct 31, 2007 at 11:19:08PM -0700, Hassan Adeel wrote:
>>
>> Hi, whats the difference between h263 and h264,
>
> h263 is essentially the same thing as mpeg4 asp, what ffmpeg calls
> plain "mpeg4", the same format used by xvid, divx4+, and many other
> popular implementations. officially they're not quite the same, and
> each (h263 vs mpeg4 asp) has some minor features that the other lacks.
>
> h264 is mpeg4 avc, a heap of relatively-high-cost micro-improvements
> piled on top of mpeg4 which, taken all together, can give something
> like a 30% improvement in overall compression (maybe more on
> pathological content) at a computational cost of something like 300%.
> the improvements include things like complex trees of bidirectionally
> predicted frames, new macroblock encoding modes, cabac encoding for
> the bitstream, bit-exact specifications for the dct and motion
> algorithms, etc.
>
>> becoz i have a .3gp with
>> h264 codecs thats not going to be converted, but other 3gps with h.263
>> are
>> working, ffmpeg command line  converting both video but i can't do it
>> with
>> my own written code.
>>
>> I want to know whats codecs parameters should be used for h264 ( those
>> are
>> different from h263), during decoding??
>
> for decoding, any modern version of ffmpeg supports both. there may be
> some h264 features that aren't yet supported though.
>
>> Note: during conversion of .3gp with h.264 i am unable to get "picture"
>> even for a single frame.
>
> strange...
>
> rich





More information about the ffmpeg-devel mailing list