Hi Ronald, Thanks for the quick answer, following the code this was also my guess.
From my side I feel that it could be nice to use ffmpeg to decode SPS without any stream, I would like to avoid an other processing of the SPS. Is there a particular reason for hiding width/height before decoding ? and could it be a potential evolution of ffmpeg ? Best Regards, Michel. [@@ THALES GROUP INTERNAL @@] -----Message d'origine----- De : ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] De la part de Ronald S. Bultje Envoyé : jeudi 30 juillet 2015 14:52 À : FFmpeg development discussions and patches Objet : Re: [FFmpeg-devel] How to get width/height of an H264 stream using its SPS ? Hi, On Thu, Jul 30, 2015 at 5:16 AM, PROMONET Michel < michel.promo...@thalesgroup.com> wrote: > Hi, > > I don't know if this is the right place to ask for this kind of > information. > Basically I am trying to get width and height from the H264 SPS using > ffmpeg. > > Using a reduced sample like this : > > #include <libavcodec/avcodec.h> > #include <libavformat/avformat.h> > > int main() > { > const char sps[] = {0, 0, 0, 1, 0x67, 0x42, 0x00, 0x0a, > 0xf8, 0x41, 0xa2}; > > av_register_all(); > av_log_set_level(AV_LOG_DEBUG); > > AVCodec *const codec = avcodec_find_decoder(CODEC_ID_H264); > AVCodecContext* ctx = avcodec_alloc_context3(codec); > ctx->debug = ~0; > ctx->extradata = (uint8_t *)av_malloc(sizeof(sps) + > FF_INPUT_BUFFER_PADDING_SIZE); > ctx->extradata_size = sizeof(sps); > memcpy(ctx->extradata,sps,sizeof(sps)); > memset(&ctx->extradata[ctx->extradata_size], 0, > FF_INPUT_BUFFER_PADDING_SIZE); // zero padding > > avcodec_open2(ctx, codec, NULL); > char buf[1024]; > avcodec_string(buf,sizeof(buf),ctx,1); > fprintf(stderr, "%s\n", buf); fprintf(stderr, > "size:%dx%d\n", ctx->width, ctx->height); > > avcodec_close(ctx); > av_free(ctx); > } > > The output of this program is : > [h264 @ 0x68a010] NAL 7/3 at 4/11 length 6 > [h264 @ 0x68a010] sps:0 profile:66/10 poc:0 ref:0 8x6 FRM > crop:0/0/0/0 > 420 0/0 b8 reo:-1 > Video: h264, 1 reference frame, none(left), q=2-31, 200 kb/s > size:0x0 0x0 > > We can see the SPS is decoded and have the needed information to > compute width and height (it should be 128x96). > However the avcodec_open2 only fill the opaque H264Context, but does > not fill the AVCodecContext information. > > Is there a way to decode the SPS, without decoding a frame ? No, avctx->width is set upon slice header decoding. You'll have to decode one frame. Ronald _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel