
Recherche avancée
Médias (3)
-
MediaSPIP Simple : futur thème graphique par défaut ?
26 septembre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Video
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
-
GetID3 - Boutons supplémentaires
9 avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (53)
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
La sauvegarde automatique de canaux SPIP
1er avril 2010, parDans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...)
Sur d’autres sites (10279)
-
Linker error by trying example program with ffmpeg
11 mars, par ChrisI think this might be a stupid question and I'm just blind but that thing is driving me nuts for hours now.
I downloaded ffmpeg and build it. Now I want to try the thing out in a program but I can't setup cmake to link ffmpeg properly and have no idea what is wrong.


The linker always tells me this :


christoph@christoph-ThinkPad-T490:~/develop/ffmpg_example/build$ make
[ 50%] Linking CXX executable test
CMakeFiles/test.dir/main.cxx.o: In function `main':
main.cxx:(.text+0x180): undefined reference to `av_register_all()'
main.cxx:(.text+0x1a7): undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)'
main.cxx:(.text+0x1ce): undefined reference to `avformat_find_stream_info(AVFormatContext*, AVDictionary**)'
main.cxx:(.text+0x206): undefined reference to `av_dump_format(AVFormatContext*, int, char const*, int)'
main.cxx:(.text+0x2bb): undefined reference to `avcodec_find_decoder(AVCodecID)'
main.cxx:(.text+0x2fc): undefined reference to `avcodec_alloc_context3(AVCodec const*)'
main.cxx:(.text+0x316): undefined reference to `avcodec_copy_context(AVCodecContext*, AVCodecContext const*)'
main.cxx:(.text+0x361): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
main.cxx:(.text+0x377): undefined reference to `av_frame_alloc()'
main.cxx:(.text+0x383): undefined reference to `av_frame_alloc()'
main.cxx:(.text+0x3ba): undefined reference to `avpicture_get_size(AVPixelFormat, int, int)'
main.cxx:(.text+0x3d0): undefined reference to `av_malloc(unsigned long)'
main.cxx:(.text+0x3ff): undefined reference to `avpicture_fill(AVPicture*, unsigned char const*, AVPixelFormat, int, int)'
main.cxx:(.text+0x43d): undefined reference to `sws_getContext(int, int, AVPixelFormat, int, int, AVPixelFormat, int, SwsFilter*, SwsFilter*, double const*)'
main.cxx:(.text+0x465): undefined reference to `av_read_frame(AVFormatContext*, AVPacket*)'
main.cxx:(.text+0x49f): undefined reference to `avcodec_decode_video2(AVCodecContext*, AVFrame*, int*, AVPacket const*)'
main.cxx:(.text+0x4fd): undefined reference to `sws_scale(SwsContext*, unsigned char const* const*, int const*, int, int, unsigned char* const*, int const*)'
main.cxx:(.text+0x545): undefined reference to `av_free_packet(AVPacket*)'
main.cxx:(.text+0x556): undefined reference to `av_free(void*)'
main.cxx:(.text+0x565): undefined reference to `av_frame_free(AVFrame**)'
main.cxx:(.text+0x574): undefined reference to `av_frame_free(AVFrame**)'
main.cxx:(.text+0x580): undefined reference to `avcodec_close(AVCodecContext*)'
main.cxx:(.text+0x58f): undefined reference to `avcodec_close(AVCodecContext*)'
main.cxx:(.text+0x59e): undefined reference to `avformat_close_input(AVFormatContext**)'
collect2: error: ld returned 1 exit status
CMakeFiles/test.dir/build.make:87: recipe for target 'test' failed
make[2]: *** [test] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/test.dir/all' failed
make[1]: *** [CMakeFiles/test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2



The cmake list looks like this :


cmake_minimum_required(VERSION 3.16)

project(ffmpeg_test)

add_library(avformat STATIC IMPORTED)
set_target_properties(avformat
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libavformat.a
)
add_library(avcodec STATIC IMPORTED)
set_target_properties(avcodec
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libavcodec.a
)
add_library(swscale STATIC IMPORTED)
set_target_properties(swscale
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libswscale.a
)
add_library(avutil STATIC IMPORTED)
set_target_properties(avutil
 PROPERTIES IMPORTED_LOCATION /home/christoph/develop/FFmpeg/build/lib/libavutil.a
)
add_executable(test main.cxx)

target_link_libraries(test PRIVATE
 /home/christoph/develop/FFmpeg/build/lib/libavformat.a
 avcodec
 swscale
 avutil
)
target_include_directories(test PRIVATE /home/christoph/develop/FFmpeg/build/include)



And here are the ffmpeg libs :


christoph@christoph-ThinkPad-T490:~/develop/FFmpeg/build/lib$ ll
total 277840
drwxr-xr-x 3 christoph christoph 4096 Dez 7 23:59 ./
drwxr-xr-x 17 christoph christoph 4096 Dez 7 23:59 ../
-rw-r--r-- 1 christoph christoph 173479270 Dez 7 23:59 libavcodec.a
-rw-r--r-- 1 christoph christoph 2174910 Dez 7 23:59 libavdevice.a
-rw-r--r-- 1 christoph christoph 37992438 Dez 7 23:59 libavfilter.a
-rw-r--r-- 1 christoph christoph 59222040 Dez 7 23:59 libavformat.a
-rw-r--r-- 1 christoph christoph 4759514 Dez 7 23:59 libavutil.a
-rw-r--r-- 1 christoph christoph 695698 Dez 7 23:59 libswresample.a
-rw-r--r-- 1 christoph christoph 6164398 Dez 7 23:59 libswscale.a
drwxr-xr-x 2 christoph christoph 4096 Dez 7 23:59 pkgconfig/



And this is the example code :


#include

#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>

// compatibility with newer API
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
#define av_frame_alloc avcodec_alloc_frame
#define av_frame_free avcodec_free_frame
#endif

void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
 FILE *pFile;
 char szFilename[32];
 int y;
 
 // Open file
 sprintf(szFilename, "frame%d.ppm", iFrame);
 pFile=fopen(szFilename, "wb");
 if(pFile==NULL)
 return;
 
 // Write header
 fprintf(pFile, "P6\n%d %d\n255\n", width, height);
 
 // Write pixel data
 for(y=0; ydata[0]+y*pFrame->linesize[0], 1, width*3, pFile);
 
 // Close file
 fclose(pFile);
}

int main(int argc, char *argv[]) {
 // Initalizing these to NULL prevents segfaults!
 AVFormatContext *pFormatCtx = NULL;
 int i, videoStream;
 AVCodecContext *pCodecCtxOrig = NULL;
 AVCodecContext *pCodecCtx = NULL;
 AVCodec *pCodec = NULL;
 AVFrame *pFrame = NULL;
 AVFrame *pFrameRGB = NULL;
 AVPacket packet;
 int frameFinished;
 int numBytes;
 uint8_t *buffer = NULL;
 struct SwsContext *sws_ctx = NULL;

 if(argc < 2) {
 printf("Please provide a movie file\n");
 return -1;
 }
 // Register all formats and codecs
 av_register_all();
 
 // Open video file
 if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)
 return -1; // Couldn't open file
 
 // Retrieve stream information
 if(avformat_find_stream_info(pFormatCtx, NULL)<0)
 return -1; // Couldn't find stream information
 
 // Dump information about file onto standard error
 av_dump_format(pFormatCtx, 0, argv[1], 0);
 
 // Find the first video stream
 videoStream=-1;
 for(i=0; inb_streams; i++)
 if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
 videoStream=i;
 break;
 }
 if(videoStream==-1)
 return -1; // Didn't find a video stream
 
 // Get a pointer to the codec context for the video stream
 pCodecCtxOrig=pFormatCtx->streams[videoStream]->codec;
 // Find the decoder for the video stream
 pCodec=avcodec_find_decoder(pCodecCtxOrig->codec_id);
 if(pCodec==NULL) {
 fprintf(stderr, "Unsupported codec!\n");
 return -1; // Codec not found
 }
 // Copy context
 pCodecCtx = avcodec_alloc_context3(pCodec);
 if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {
 fprintf(stderr, "Couldn't copy codec context");
 return -1; // Error copying codec context
 }

 // Open codec
 if(avcodec_open2(pCodecCtx, pCodec, NULL)<0)
 return -1; // Could not open codec
 
 // Allocate video frame
 pFrame=av_frame_alloc();
 
 // Allocate an AVFrame structure
 pFrameRGB=av_frame_alloc();
 if(pFrameRGB==NULL)
 return -1;

 // Determine required buffer size and allocate buffer
 numBytes=avpicture_get_size(AV_PIX_FMT_RGB24, pCodecCtx->width,
 pCodecCtx->height);
 buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
 
 // Assign appropriate parts of buffer to image planes in pFrameRGB
 // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
 // of AVPicture
 avpicture_fill((AVPicture *)pFrameRGB, buffer, AV_PIX_FMT_RGB24,
 pCodecCtx->width, pCodecCtx->height);
 
 // initialize SWS context for software scaling
 sws_ctx = sws_getContext(pCodecCtx->width,
 pCodecCtx->height,
 pCodecCtx->pix_fmt,
 pCodecCtx->width,
 pCodecCtx->height,
 AV_PIX_FMT_RGB24,
 SWS_BILINEAR,
 NULL,
 NULL,
 NULL
 );

 // Read frames and save first five frames to disk
 i=0;
 while(av_read_frame(pFormatCtx, &packet)>=0) {
 // Is this a packet from the video stream?
 if(packet.stream_index==videoStream) {
 // Decode video frame
 avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
 
 // Did we get a video frame?
 if(frameFinished) {
 // Convert the image from its native format to RGB
 sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data,
 pFrame->linesize, 0, pCodecCtx->height,
 pFrameRGB->data, pFrameRGB->linesize);
 
 // Save the frame to disk
 if(++i<=5)
 SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, 
 i);
 }
 }
 
 // Free the packet that was allocated by av_read_frame
 av_free_packet(&packet);
 }
 
 // Free the RGB image
 av_free(buffer);
 av_frame_free(&pFrameRGB);
 
 // Free the YUV frame
 av_frame_free(&pFrame);
 
 // Close the codecs
 avcodec_close(pCodecCtx);
 avcodec_close(pCodecCtxOrig);

 // Close the video file
 avformat_close_input(&pFormatCtx);
 
 return 0;
}



-
How to increase conversions to meet your business goals
8 septembre 2020, par Joselyn Khor — Analytics Tips, Marketing -
C++ ffmpeg and SDL2 video rendering memory leak
10 avril 2017, par kj192I have made a small program what plays a video in SDL2.0 and FFmpeg.
The software does work and do it is purpose.
I have left the software running and I have faced a huge memory consumption and started to look online what can I do against it.
I have used the following tutorials :
http://www.developersite.org/906-59411-FFMPEG
http://ardrone-ailab-u-tokyo.blogspot.co.uk/2012/07/212-ardrone-20-video-decording-ffmpeg.htmlI wonder if someone can give advice what do I do wrong. I have tried valgrind but I can’t find any information. I have did try to comment out sections and what I have seen even if I’m not rendering to the display the memory usage is growing and after delete something still not been freed up :
if (av_read_frame(pFormatCtx, &packet) >= 0)
the whole source code is here :
main :#include
#include <ios>
#include <iostream>
#include <fstream>
#include
#include <sdl2></sdl2>SDL.h>
#include "video.h"
using namespace std;
void memory()
{
using std::ios_base;
using std::ifstream;
using std::string;
double vm_usage = 0.0;
double resident_set = 0.0;
// 'file' stat seems to give the most reliable results
//
ifstream stat_stream("/proc/self/stat",ios_base::in);
// dummy vars for leading entries in stat that we don't care about
//
string pid, comm, state, ppid, pgrp, session, tty_nr;
string tpgid, flags, minflt, cminflt, majflt, cmajflt;
string utime, stime, cutime, cstime, priority, nice;
string O, itrealvalue, starttime;
// the two fields we want
//
unsigned long vsize;
long rss;
stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
>> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
>> utime >> stime >> cutime >> cstime >> priority >> nice
>> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
stat_stream.close();
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
vm_usage = vsize / 1024.0;
resident_set = rss * page_size_kb;
std::cout<<"VM: " << vm_usage << " RE:"<< resident_set << std::endl;
}
int main()
{
//This example using 1280x800 video
av_register_all();
if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ))
{
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
SDL_Window* sdlWindow = SDL_CreateWindow("Video Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 800, SDL_WINDOW_OPENGL);
if( !sdlWindow )
{
fprintf(stderr, "SDL: could not set video mode - exiting\n");
exit(1);
}
SDL_Renderer* sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
SDL_Texture* sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, 1280, 800);
if(!sdlTexture)
{
return -1;
}
SDL_SetTextureBlendMode(sdlTexture,SDL_BLENDMODE_BLEND );
//VIDEO RESOLUTION
SDL_Rect sdlRect;
sdlRect.x = 0;
sdlRect.y = 0;
sdlRect.w = 1280;
sdlRect.h = 800;
memory();
for(int i = 1; i < 6; i++)
{
memory();
video* vid = new video("vid.mp4");
while (!vid -> getFinished())
{
memory();
vid -> Update(sdlTexture);
SDL_RenderCopy(sdlRenderer,sdlTexture,&sdlRect,&sdlRect);
SDL_RenderPresent(sdlRenderer);
}
delete vid;
memory();
}
SDL_DestroyTexture(sdlTexture);
SDL_DestroyRenderer(sdlRenderer);
SDL_DestroyWindow(sdlWindow);
SDL_Quit();
return 0;
}
</fstream></iostream></ios>video.cpp
#include "video.h"
video::video(const std::string& name) : _finished(false)
{
av_register_all();
pFormatCtx = NULL;
pCodecCtxOrig = NULL;
pCodecCtx = NULL;
pCodec = NULL;
pFrame = NULL;
sws_ctx = NULL;
if (avformat_open_input(&pFormatCtx, name.c_str(), NULL, NULL) != 0)
{
_finished = true; // Couldn't open file
}
// Retrieve stream information
if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
{
_finished = true; // Couldn't find stream information
}
videoStream = -1;
for (i = 0; i < pFormatCtx->nb_streams; i++)
{
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStream = i;
break;
}
}
if (videoStream == -1)
{
_finished = true; // Didn't find a video stream
}
// Get a pointer to the codec context for the video stream
pCodecCtxOrig = pFormatCtx->streams[videoStream]->codec;
// Find the decoder for the video stream
pCodec = avcodec_find_decoder(pCodecCtxOrig->codec_id);
if (pCodec == NULL)
{
fprintf(stderr, "Unsupported codec!\n");
_finished = true; // Codec not found
}
pCodecCtx = avcodec_alloc_context3(pCodec);
if (avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0)
{
fprintf(stderr, "Couldn't copy codec context");
_finished = true; // Error copying codec context
}
// Open codec
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{
_finished = true; // Could not open codec
}
// Allocate video frame
pFrame = av_frame_alloc();
sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,
AV_PIX_FMT_YUV420P,
SWS_BILINEAR,
NULL,
NULL,
NULL);
yPlaneSz = pCodecCtx->width * pCodecCtx->height;
uvPlaneSz = pCodecCtx->width * pCodecCtx->height / 4;
yPlane = (Uint8*)malloc(yPlaneSz);
uPlane = (Uint8*)malloc(uvPlaneSz);
vPlane = (Uint8*)malloc(uvPlaneSz);
if (!yPlane || !uPlane || !vPlane)
{
fprintf(stderr, "Could not allocate pixel buffers - exiting\n");
exit(1);
}
uvPitch = pCodecCtx->width / 2;
}
void video::Update(SDL_Texture* texture)
{
if (av_read_frame(pFormatCtx, &packet) >= 0)
{
// Is this a packet from the video stream?
if (packet.stream_index == videoStream)
{
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
// Did we get a video frame?
if (frameFinished)
{
AVPicture pict;
pict.data[0] = yPlane;
pict.data[1] = uPlane;
pict.data[2] = vPlane;
pict.linesize[0] = pCodecCtx->width;
pict.linesize[1] = uvPitch;
pict.linesize[2] = uvPitch;
// Convert the image into YUV format that SDL uses
sws_scale(sws_ctx, (uint8_t const * const *) pFrame->data,pFrame->linesize, 0, pCodecCtx->height, pict.data,pict.linesize);
SDL_UpdateYUVTexture(texture,NULL,yPlane,pCodecCtx->width,uPlane,uvPitch,vPlane,uvPitch);
}
}
// Free the packet that was allocated by av_read_frame
av_packet_unref(&packet);
av_freep(&packet);
}
else
{
av_packet_unref(&packet);
av_freep(&packet);
_finished = true;
}
}
bool video::getFinished()
{
return _finished;
}
video::~video()
{
av_packet_unref(&packet);
av_freep(&packet);
av_frame_free(&pFrame);
av_freep(&pFrame);
free(yPlane);
free(uPlane);
free(vPlane);
// Close the codec
avcodec_close(pCodecCtx);
avcodec_close(pCodecCtxOrig);
sws_freeContext(sws_ctx);
// Close the video file
for (int i = 0; i < pFormatCtx->nb_streams; i++)
{
AVStream *stream = pFormatCtx->streams[i];
avcodec_close(stream->codec);
}
avformat_close_input(&pFormatCtx);
/*av_dict_free(&optionsDict);
sws_freeContext(sws_ctx);
av_free_packet(&packet);
av_free(pFrameYUV);
av_free(buffer);
avcodec_close(pCodecCtx);
avformat_close_input(&pFormatCtx);*/
}video.h
#include <string>
#include <sdl2></sdl2>SDL.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libswscale></libswscale>swscale.h>
#ifdef __cplusplus
}
#endif
class video
{
private:
bool _finished;
AVFormatContext *pFormatCtx;
int videoStream;
unsigned i;
AVCodecContext *pCodecCtxOrig;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame;
AVPacket packet;
int frameFinished;
struct SwsContext *sws_ctx;
Uint8 *yPlane, *uPlane, *vPlane;
size_t yPlaneSz, uvPlaneSz;
int uvPitch;
public:
video(const std::string& name);
~video();
void Update(SDL_Texture* texture);
bool getFinished();
};
</string>I’m looking forward to your answers