
Recherche avancée
Médias (91)
-
Les Miserables
9 décembre 2019, par
Mis à jour : Décembre 2019
Langue : français
Type : Textuel
-
VideoHandle
8 novembre 2019, par
Mis à jour : Novembre 2019
Langue : français
Type : Video
-
Somos millones 1
21 juillet 2014, par
Mis à jour : Juin 2015
Langue : français
Type : Video
-
Un test - mauritanie
3 avril 2014, par
Mis à jour : Avril 2014
Langue : français
Type : Textuel
-
Pourquoi Obama lit il mes mails ?
4 février 2014, par
Mis à jour : Février 2014
Langue : français
-
IMG 0222
6 octobre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Image
Autres articles (37)
-
Use, discuss, criticize
13 avril 2011, parTalk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
A discussion list is available for all exchanges between users. -
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
ANNEXE : Les plugins utilisés spécifiquement pour la ferme
5 mars 2010, parLe site central/maître de la ferme a besoin d’utiliser plusieurs plugins supplémentaires vis à vis des canaux pour son bon fonctionnement. le plugin Gestion de la mutualisation ; le plugin inscription3 pour gérer les inscriptions et les demandes de création d’instance de mutualisation dès l’inscription des utilisateurs ; le plugin verifier qui fournit une API de vérification des champs (utilisé par inscription3) ; le plugin champs extras v2 nécessité par inscription3 (...)
Sur d’autres sites (4055)
-
FFMPEG libx265 encoding leaves memory unfreed after avcodec_free_context
28 août 2020, par ahugeatI am working on H265 encoding software and, in my unit tests, I have some weird memory leaks. To found them, I have modified the
encode_video.c
example from FFMPEG documentation. I have changed the resolution to correspond at a 4K video, I have adapted the bitrate and I have added a pause before context allocation and another one before the final return :

#include 
#include 
#include 
#include 

#include <libavcodec></libavcodec>avcodec.h>

#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>imgutils.h>

static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
 FILE *outfile)
{
 int ret;

 /* send the frame to the encoder */
 if (frame)
 printf("Send frame %3"PRId64"\n", frame->pts);

 ret = avcodec_send_frame(enc_ctx, frame);
 if (ret < 0) {
 fprintf(stderr, "Error sending a frame for encoding\n");
 exit(1);
 }

 while (ret >= 0) {
 ret = avcodec_receive_packet(enc_ctx, pkt);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 return;
 else if (ret < 0) {
 fprintf(stderr, "Error during encoding\n");
 exit(1);
 }

 printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
 fwrite(pkt->data, 1, pkt->size, outfile);
 av_packet_unref(pkt);
 }
}

int main(int argc, char **argv)
{
 const char *filename, *codec_name;
 const AVCodec *codec;
 AVCodecContext *c= NULL;
 int i, ret, x, y;
 FILE *f;
 AVFrame *frame;
 AVPacket *pkt;
 uint8_t endcode[] = { 0, 0, 1, 0xb7 };

 if (argc <= 2) {
 fprintf(stderr, "Usage: %s <output file="file"> <codec>\n", argv[0]);
 exit(0);
 }
 filename = argv[1];
 codec_name = argv[2];

 sleep(10);

 /* find the mpeg1video encoder */
 codec = avcodec_find_encoder_by_name(codec_name);
 if (!codec) {
 fprintf(stderr, "Codec '%s' not found\n", codec_name);
 exit(1);
 }

 c = avcodec_alloc_context3(codec);
 if (!c) {
 fprintf(stderr, "Could not allocate video codec context\n");
 exit(1);
 }

 pkt = av_packet_alloc();
 if (!pkt)
 exit(1);

 /* put sample parameters */
 c->bit_rate = 1000000;
 /* resolution must be a multiple of two */
 c->width = 3840;
 c->height = 2160;
 /* frames per second */
 c->time_base = (AVRational){1, 25};
 c->framerate = (AVRational){25, 1};

 /* emit one intra frame every ten frames
 * check frame pict_type before passing frame
 * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
 * then gop_size is ignored and the output of encoder
 * will always be I frame irrespective to gop_size
 */
 c->gop_size = 10;
 c->max_b_frames = 1;
 c->pix_fmt = AV_PIX_FMT_YUV420P;

 if (codec->id == AV_CODEC_ID_H264)
 av_opt_set(c->priv_data, "preset", "slow", 0);

 /* open it */
 ret = avcodec_open2(c, codec, NULL);
 if (ret < 0) {
 fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
 exit(1);
 }

 f = fopen(filename, "wb");
 if (!f) {
 fprintf(stderr, "Could not open %s\n", filename);
 exit(1);
 }

 frame = av_frame_alloc();
 if (!frame) {
 fprintf(stderr, "Could not allocate video frame\n");
 exit(1);
 }
 frame->format = c->pix_fmt;
 frame->width = c->width;
 frame->height = c->height;

 ret = av_frame_get_buffer(frame, 0);
 if (ret < 0) {
 fprintf(stderr, "Could not allocate the video frame data\n");
 exit(1);
 }

 /* encode 1 second of video */
 for (i = 0; i < 25; i++) {
 fflush(stdout);

 /* make sure the frame data is writable */
 ret = av_frame_make_writable(frame);
 if (ret < 0)
 exit(1);

 /* prepare a dummy image */
 /* Y */
 for (y = 0; y < c->height; y++) {
 for (x = 0; x < c->width; x++) {
 frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
 }
 }

 /* Cb and Cr */
 for (y = 0; y < c->height/2; y++) {
 for (x = 0; x < c->width/2; x++) {
 frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
 frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
 }
 }

 frame->pts = i;

 /* encode the image */
 encode(c, frame, pkt, f);
 }

 /* flush the encoder */
 encode(c, NULL, pkt, f);

 /* add sequence end code to have a real MPEG file */
 if (codec->id == AV_CODEC_ID_MPEG1VIDEO || codec->id == AV_CODEC_ID_MPEG2VIDEO)
 fwrite(endcode, 1, sizeof(endcode), f);
 fclose(f);

 avcodec_free_context(&c);
 av_frame_free(&frame);
 av_packet_free(&pkt);

 sleep(10);

 return 0;
}
</codec></output>


I was expecting that the RAM memory usage at the first pause is the same as the second pause but there is about 55 Mo of difference. If I increase the number of encoded frames, this difference up to 390 Mo. I have tested this code under Linux Mint LMDE 4 (roughly same as Debian 10).


I guess this memory "leak" it isn't a real memory leak but that it's some internal values used by libx265 to be maybe reused for another encoding. But has there a way to free this memory through FFMPEG API ?


-
Wma decoding with ffmpeg
21 janvier 2012, par IzakI am new to ffmpeg and I tried using api-example.c to decode wma files. However when I run the program, it gave me an error saying
"frame_len overflow". Does anyone know how to fix this error ?
Here is my code :
extern "C" {
#include
#include "../libavcodec/avcodec.h"
#include
}
#include <iostream>
#include
#include
#include
#define INBUF_SIZE 4096
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096
int main(int argc, char *argv[]) {
avcodec_init();
avcodec_register_all();
//avdevice_register_all();
av_register_all();
AVCodec *codec;
AVCodecContext *c= NULL;
AVCodec *ocodec;
AVCodecContext *oc= NULL;
int out_size, len,out_size2;
FILE *f, *outfile;
uint8_t *outbuf;
uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
AVPacket avpkt;
char* outfilename="test.wma";
char* filename="Beethoven's.wma";
AVFormatContext *pFormatCtx;
WAVEFORMATEX* wfx=new WAVEFORMATEX;
int ret;
ret=av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL);
if(ret!=0)
{
std::cout<<"cannot open file!"</ Find the first video stream
audioStream=-1;
for(int i=0; inb_streams; i++)
if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO)
{
audioStream=i;
break;
}
if(audioStream==-1)
{
std::cout<<"cannot find audio!"</ Get a pointer to the codec context for the audio stream
pCodecCtx=pFormatCtx->streams[audioStream]->codec;
av_init_packet(&avpkt);
printf("Audio decoding\n");
/* find the suitable audio decoder */
codec = avcodec_find_decoder(pCodecCtx->codec_id);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
if(codec->capabilities & CODEC_CAP_TRUNCATED)
pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
//open the codec (for decoding)
int test = avcodec_open(pCodecCtx, codec);
if (test < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
//find mp3 encoder
ocodec = avcodec_find_encoder(CODEC_ID_MP3);
if (!ocodec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
//allocate context
oc= avcodec_alloc_context();
/* put sample parameters */
oc->bit_rate = 64000;
oc->sample_rate = 44100;
oc->channels = 1;
/* open it */
if (avcodec_open(oc, ocodec) < 0) {
fprintf(stderr, "could not open encoding codec\n");
exit(1);
}
//buffer
outbuf = (uint8_t*)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
//open inputfile
f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "could not open %s\n", filename);
exit(1);
}
//open outputfile
outfile = fopen(outfilename, "wb");
if (!outfile) {
av_free(c);
exit(1);
}
/* decode until eof */
avpkt.data = inbuf;
avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
//while there is still data
while (avpkt.size > 0) {
std::cout<<"decoding..."</decode
len = avcodec_decode_audio3(pCodecCtx, (short *)outbuf, &out_size, &avpkt);
if (len < 0) {
fprintf(stderr, "Error while decoding\n");
exit(1);
}
if (out_size > 0) {
/* if a frame has been decoded, output it */
std::cout<<"1 frame decoded!"</subtract data from whatever decode function returns
avpkt.size -= len;
avpkt.data += len;
if (avpkt.size < AUDIO_REFILL_THRESH) {
/* Refill the input buffer, to avoid trying to decode
* incomplete frames. Instead of this, one could also use
* a parser, or use a proper container format through
* libavformat. */
memmove(inbuf, avpkt.data, avpkt.size);
avpkt.data = inbuf;
len = fread(avpkt.data + avpkt.size, 1,
AUDIO_INBUF_SIZE - avpkt.size, f);
if (len > 0)
avpkt.size += len;
}
}
fclose(outfile);
fclose(f);
free(outbuf);
avcodec_close(c);
av_free(c);
}
</iostream>I have been stuck on this for quite a long time. Please help me.
anyone know whats wrong with my code ?Thanks,
Izak
-
Does anyone use go-av to parse mp4 audio and then use oto/portaudio to output it ?
27 juillet 2021, par sevenit is use go-av to get audio


func audio() (<-chan []byte, error) {
 buffer := make(chan []byte, 1024)
 go func() {
 ......
 for inCtx.AvReadFrame(pkt) >= 0 {
 if pkt.StreamIndex() == audioStreamIndex {
 l := pCodecCtx.AvcodecDecodeAudio4((*avcodec.Frame)(unsafe.Pointer(utilFrame)), &gotName, pkt)
 //fmt.Println("AvcodecDecodeAudio4:", l)
 if l < 0 {
 fmt.Println("codec decode audio4 error")
 os.Exit(1)
 }
 if gotName > 0 {

 fram := getFramBytes(utilFrame)
 fmt.Println("buf add:", index)
 buffer <- fram

 }
 }
 pkt.AvFreePacket()
 }
 go func() {
 for {
 if len(buffer) <= 0 {
 fmt.Println("close buf")
 close(buffer)
 break
 }
 }
 }()

 (*avcodec.Context)(unsafe.Pointer(pCodecCtxOrig)).AvcodecClose()
 }()
 return buffer, nil
}
func getFramBytes(f *avutil.Frame) []byte {
 data := avutil.Data(f)
 var bf = make([]byte, len(data))
 for i := 0; i < len(data); i++ {

 if data[i] != nil {
 bf = append(bf, *data[i])
 }
 }
 return bf
}




and it is output it


func main() {

 portaudio.Initialize()
 defer portaudio.Terminate()
 out := make([]int32, 8192)
 stream, err := portaudio.OpenDefaultStream(0, 1, 44100, len(out), &out)
 defer stream.Close()
 if err != nil {
 fmt.Println(err)
 return
 }
 err = stream.Start()
 if err != nil {
 fmt.Println(err)
 return
 }
 defer stream.Stop()
 buf, err := audio()
 if err != nil {
 fmt.Println(err)
 return
 }
 //index := 0
 //c, err := oto.NewContext(44100, 2, 2, 8192)
 //if err != nil {
 // return
 //}
 //defer c.Close()
 //
 //p := c.NewPlayer()
 //defer p.Close()
 for {
 select {
 case frame, ok := <-buf:
 if !ok {
 os.Exit(0)
 }
 //index += 1
 //fmt.Println("$$:", index)
 //if _, err := io.Copy(p, bytes.NewReader(frame)); err != nil {
 // fmt.Println(err)
 // return
 //}
 err := binary.Read(bytes.NewReader(frame), binary.BigEndian, out)
 if err != nil {
 fmt.Println("binary.Read:", err)
 os.Exit(0)
 }
 err = stream.Write()
 if err != nil {
 fmt.Println("stream.Write:", err)
 os.Exit(0)
 }
 }
 }

}




** the result is**


binary.Read : unexpected EOF


if use oto it has no effect


Has anyone used this method, or is there any other way to use go-av to play audio and video ?


Is there a problem in use ? I feel that there is a problem with the data conversion from the audio decoding.


Maybe there is a problem with getFramBytes