Closed lucas-aragno closed 7 years ago
I'm following the tutorial (updating things bc some of the methods/properties where deprecated )
#include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <stdlib.h> // #include <ffmpeg/swscale.h> // How to compile it: gcc -o stream stream.c -lavutil -lavformat -lavcodec -lz -lavutil -lm // How to run it ./stream <video> int main (int argc, char * argv []) { av_register_all(); AVFormatContext * pFormatCtx = NULL; // Open a video file if (avformat_open_input(&pFormatCtx, argv[1], NULL, 0) != 0) return -1; // Couldn't open the file if (avformat_find_stream_info(pFormatCtx, NULL) < 0) return -1; // Counldn't find the stream int i; int videoStream; AVCodecContext * pCodecCtxOrig = NULL; AVCodecParameters * pCodecCtx = NULL; AVCodecContext * pCodecRealCtx = NULL; videoStream = -1; // pFormatCtx->streams is an array of pointers // of size pFormatCtx->nb_strams for (i = 0; i < pFormatCtx->nb_streams; i++) if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { videoStream=i; break; } if (videoStream == -1) return -1; // get the pointer to the codec context for the video stream pCodecCtx = pFormatCtx->streams[videoStream]->codecpar; AVCodec *pCodec = NULL; // Find the decoder for the video stream pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if (pCodec == NULL) { fprintf(stderr, "Unsupported Codec \n"); return -1; // Codec not found } // Open Codec avcodec_parameters_to_context(pCodecRealCtx, pCodecCtx); if (avcodec_open2(pCodecRealCtx, pCodec, NULL) < 0) return -1; AVFrame *pFrame = NULL; AVFrame *pFrameRGB = NULL; // Allocate video frame pFrame = av_frame_alloc(); pFrameRGB = av_frame_alloc(); if (pFrameRGB == NULL) return -1; uint8_t *buffer = NULL; int numBytes; // numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 0); return 0; }
this is my code for now but for numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 0); I get:
numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 0);
stream.c:65:14: warning: implicit declaration of function 'av_image_get_buffer_size' is invalid in C99 [-Wimplicit-function-declaration]
but it should be defined on the imports right? based on this
found that i had to include this header #include <libavutil/imgutils.h> closing this now :)
#include <libavutil/imgutils.h>
I'm following the tutorial (updating things bc some of the methods/properties where deprecated )
this is my code for now but for
numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 0);
I get:stream.c:65:14: warning: implicit declaration of function 'av_image_get_buffer_size' is invalid in C99 [-Wimplicit-function-declaration]
but it should be defined on the imports right? based on this