
Recherche avancée
Médias (91)
-
Spoon - Revenge !
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
My Morning Jacket - One Big Holiday
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Zap Mama - Wadidyusay ?
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
David Byrne - My Fair Lady
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Beastie Boys - Now Get Busy
15 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Granite de l’Aber Ildut
9 septembre 2011, par
Mis à jour : Septembre 2011
Langue : français
Type : Texte
Autres articles (52)
-
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 ;
-
Ecrire une actualité
21 juin 2013, parPrésentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
Vous pouvez personnaliser le formulaire de création d’une actualité.
Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)
Sur d’autres sites (9375)
-
avcodec_send_packet causing memory leak
23 juin 2020, par AleksaJanjatovicI'm trying to fetch a frame from an Rtsp stream, but it seems that I'm forgetting to free some element, causing my RAM to rapidly fill. Here are the code snippets :


Here is the initialization before frame fetching


bool CRtspStream::Init(void* _userData) {
 InitParam* param = (CBaseStream::InitParam*)_userData;
 m_InputPath = param->m_InputPath;
 m_OutputPath = param->m_OutputPath;
 m_Logger.SetLogLevel(param->m_LoggerLevel);

 av_register_all();
 avformat_network_init();

 int ffmpegFatalLogLevel = 8;
 av_log_set_level(ffmpegFatalLogLevel);

 AVCodec* codec = avcodec_find_decoder(param->m_CodecID);
 if(!codec)
 throw DetectionUtility::StreamException("Unable to open codec.");

 m_FormatContext = avformat_alloc_context();
 m_CodecContext = avcodec_alloc_context3(codec);

 if(avformat_open_input(&m_FormatContext, param->m_InputPath.c_str(), nullptr, nullptr) < 0)
 throw DetectionUtility::StreamException("Unable to open stream: " + param->m_InputPath);

 if(avformat_find_stream_info(m_FormatContext, nullptr) < 0)
 throw DetectionUtility::StreamException("Unable to get stream info into format context.");

 for(unsigned int i = 0;i < m_FormatContext->nb_streams; i++){
 if(m_FormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 m_VideoStreamIndex = i;
 }

 if (avcodec_open2(m_CodecContext, codec, nullptr) < 0)
 throw DetectionUtility::StreamException("Unable to open codec.");

 return m_InitSuccesful = true;
}



And here is the actual frame fetching, i made sure that retVal frame is being freed afterward. Main evidence that this is what causes memory leaks is that valgrind is also pointing to the avcodec_send_packet() line : valgrind_results


AVFrame* CRtspStream::RequestNewFrame() {
 AVPacket packet;
 AVFrame* retVal = av_frame_alloc();
 bool frameAvailable = false;

// avformat_flush(m_FormatContext);
// avcodec_flush_buffers(m_CodecContext);
 av_read_play(m_FormatContext);
 int readFrameRes;
 while(!frameAvailable) {
 if((readFrameRes = av_read_frame(m_FormatContext, &packet)) >= 0) {
 if(packet.stream_index == m_VideoStreamIndex) {
 int res = 1;
 if((res = avcodec_send_packet(m_CodecContext, &packet)) < 0) {
 av_packet_unref(&packet);
 continue;
 }
 av_packet_unref(&packet);
 res = 1;
 while(res > 0) {
 res = avcodec_receive_frame(m_CodecContext, retVal);
 if(res == AVERROR(EAGAIN)) {
 break;
 } else if (res < 0) {
 throw DetectionUtility::StreamException("Unable to receive a frame from the codec.");
 } else {
 frameAvailable = true;
 }
 }
 }
 }
 av_packet_unref(&packet);
 }

 if(readFrameRes < 0) {
 av_frame_free(&retVal);
 av_packet_unref(&packet);
 throw DetectionUtility::StreamException("Unable to fetcha a new frame.");
 } else {
 try {
 if(CheckOutputSupported())
 DetectionUtility::AVFrameHelper::SaveFrame(retVal, "Rtsp" + m_OutputPath, m_CurrentFrameNumber);
 ++m_CurrentFrameNumber;
 } catch (const Utility::BaseException& e) {
 m_Logger.Error(e.GetMessage());
 }
 }
 return retVal;
}



-
Encoding raw YUV420P to h264 with AVCodec on iOS
4 janvier 2013, par WadeI am trying to encode a single YUV420P image gathered from a
CMSampleBuffer
to anAVPacket
so that I can send h264 video over the network with RTMP.The posted code example seems to work as
avcodec_encode_video2
returns0
(Success) howevergot_output
is also0
(AVPacket
is empty).Does anyone have any experience with encoding video on iOS devices that might know what I am doing wrong ?
- (void) captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
// sampleBuffer now contains an individual frame of raw video frames
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
// access the data
int width = CVPixelBufferGetWidth(pixelBuffer);
int height = CVPixelBufferGetHeight(pixelBuffer);
int bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0);
unsigned char *rawPixelBase = (unsigned char *)CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
// Convert the raw pixel base to h.264 format
AVCodec *codec = 0;
AVCodecContext *context = 0;
AVFrame *frame = 0;
AVPacket packet;
//avcodec_init();
avcodec_register_all();
codec = avcodec_find_encoder(AV_CODEC_ID_H264);
if (codec == 0) {
NSLog(@"Codec not found!!");
return;
}
context = avcodec_alloc_context3(codec);
if (!context) {
NSLog(@"Context no bueno.");
return;
}
// Bit rate
context->bit_rate = 400000; // HARD CODE
context->bit_rate_tolerance = 10;
// Resolution
context->width = width;
context->height = height;
// Frames Per Second
context->time_base = (AVRational) {1,25};
context->gop_size = 1;
//context->max_b_frames = 1;
context->pix_fmt = PIX_FMT_YUV420P;
// Open the codec
if (avcodec_open2(context, codec, 0) < 0) {
NSLog(@"Unable to open codec");
return;
}
// Create the frame
frame = avcodec_alloc_frame();
if (!frame) {
NSLog(@"Unable to alloc frame");
return;
}
frame->format = context->pix_fmt;
frame->width = context->width;
frame->height = context->height;
avpicture_fill((AVPicture *) frame, rawPixelBase, context->pix_fmt, frame->width, frame->height);
int got_output = 0;
av_init_packet(&packet);
avcodec_encode_video2(context, &packet, frame, &got_output)
// Unlock the pixel data
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
// Send the data over the network
[self uploadData:[NSData dataWithBytes:packet.data length:packet.size] toRTMP:self.rtmp_OutVideoStream];
}Note : It is known that this code has memory leaks because I am not freeing the memory that is dynamically allocated.
UPDATE
I updated my code to use @pogorskiy method. I only try to upload the frame if got output returns 1 and clear the buffer once I am done encoding video frames.
-
FFmpeg on Xcode
4 octobre 2013, par user2741735I'm developing an app for ios which uses IP Camera to stream live videos to the user. I installed macports and ffmpeg using terminal on my mac. I have taken the IP Camera output and converted into .ts file using ffmpeg on terminal. Now I want the procedure to do the same using Xcode i.e. writing code in xcode to convert IP Camera output to .ts files.
Thanks in advance.