
Recherche avancée
Médias (3)
-
Elephants Dream - Cover of the soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Image
-
Valkaama DVD Label
4 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Image
-
Publier une image simplement
13 avril 2011, par ,
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (55)
-
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 ) (...) -
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
Sur d’autres sites (8874)
-
FFMPEG - FFV1 frame encoding crashes on cleaning up
21 mai 2016, par YanI’m trying to implement a frame encoding functionality using the ffmpeg c-api. I am receiving frames from a camera which are in the Gray16le format. I want to convert encode them using the ffv1 encoder and copy the resulting frame into the variable "data". This is the code that I got so far. It seems to be working in a sense that it doesn’t crash until the part where I am freeing up my variables.
/* Video compression variables///////////////////////////////////*/
struct timeval stop, start;
AVCodec *codec;
AVCodecContext *context= NULL;
const AVPixFmtDescriptor *avPixDesc = NULL; // used to get bits per pixel
int ret, got_output;
int bufferSize = 0; // Size of encoded image frame in bytes
//uint8_t* outBuffer;
AVFrame *inFrame; //
AVPacket pkt;
Data* data;
/* Video compression ///////////////////////////////////*/
Frame* frame;
/////////////////////////////////////////////////////////////////////////
// start frame compression - current codec is ffv1
//////////////////////////////////////////////////////////////////////////
gettimeofday(&start, NULL); // get current time
avcodec_register_all(); // register all the codecs
codec = avcodec_find_encoder(AV_CODEC_ID_FFV1); // find the ffv1 encoder
if (!codec) {
fprintf(stderr, "Codec not found\n");
exit(1);
}
context = avcodec_alloc_context3(codec);
if (!context) {
fprintf(stderr, "Could not allocate video codec context\n");
exit(1);
}
frame = getFrame(); // get frame so we can set context params
/* put sample parameters */
context->bit_rate = 400000; // from example, half might also work
/* resolution must be a multiple of two */
context->width = frame->size[0];
context->height = frame->size[1];
/* frames per second */
context->time_base = (AVRational){1,22}; // 22 fps
context->gop_size = 1; // typical for ffv1 codec
context->max_b_frames = 1; // set to 1 for now, the higher the b-frames count, the higher the needed ressources
context->pix_fmt = AV_PIX_FMT_GRAY16LE ; // same as source, Y , 16bpp, little-endian, 12 of the 16 pixels are used
/* open it */
if (avcodec_open2(context, codec, NULL) < 0) {
fprintf(stderr, "Could not open codec\n");
exit(1);
}
inFrame = av_frame_alloc();
if(!inFrame)
{
printf("Could not allocate video frame\n! Exciting..");
exit(1);
}
// allocate image in inFrame
ret = av_image_alloc(inFrame->data, inFrame->linesize, context->width, context->height, context->pix_fmt, 16);
if(ret<0)
{
printf("Error allocating image of inFrame! Exiting..\n");
exit(1);
}
// copy data of frame of type Frame* into frame of type AVFrame* so we can use ffmpeg to encode it
int picFill = avpicture_fill((AVPicture*)inFrame, (uint8_t*)frame->image, context->pix_fmt, context->width, context->height);
if(picFill < 0)
{
printf("Error filling inFrame with frame->image! Exiting..\n");
exit(1);
}
else
{
printf("Successfully filled inFrame with frame->image..\n");
printf("Size of bytes filled: %d", picFill);
}
inFrame->width = context->width;
inFrame->height = context->height;
inFrame->format = context->pix_fmt;
if(frame->image[0] == NULL)
{
printf("Error! frame->image[0] == NULL.. Exiting..\n");
exit(1);
}
fflush(stdout);
int i=0;
// start encoding
while(!got_output) // while we didn't get a complete package
{
/* Start encoding the given frame */
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
i++;
/* encode the image */
ret = avcodec_encode_video2(context, &pkt, inFrame, &got_output);
if (ret < 0) {
fprintf(stderr, "Error encoding frame\n");
exit(1);
}
inFrame->pts = i;
if(got_output)
{
printf("Got a valid package after %d frames..\n", i);
// encoding of frame done, adapt "data"-field accordingly
avPixDesc = av_pix_fmt_desc_get(context->pix_fmt); // Get pixelFormat descriptor
bufferSize = av_image_get_buffer_size(context->pix_fmt, inFrame->width, inFrame->height,16);
if(bufferSize <= 0)
{
printf("Error! Buffersize of encoded frame is <= 0, exciting...\n");
}
else
{
printf("Buffersize determined to be %d\n", bufferSize);
}
data->m_size[0] = inFrame->width;
data->m_size[1] = inFrame->height;
data->m_bytesPerPixel = av_get_bits_per_pixel(avPixDesc)/8;
if (0 != av_get_bits_per_pixel(avPixDesc) % 8)
data->m_bytesPerPixel += 1;
printf("Buffersize is: %d, should be %d\n", bufferSize, inFrame->width * inFrame->height * data->m_bytesPerPixel);
data->m_image = malloc(bufferSize);
printf("copying data into final variable...\n");
memcpy(data->m_image, pkt.data, bufferSize); // copy data from ffmpeg frame
printf("copying of data done\n");
printf("Unrefing packet..\n");
av_packet_unref(&pkt);
printf("Unrefing packet done..\n");
}
else
{
printf("Didnt get package, so we get and encode next frame..\n");
frame = getFrame(); // get next frame
picFill = avpicture_fill((AVPicture*)inFrame, (uint8_t*)frame->image, context->pix_fmt, context->width, context->height);
if(!picFill)
{
printf("Error filling frame with data!!..\n");
exit(1);
}
else
{
printf("Size required to store received frame in AVFrame in bytes: %d", picFill);
}
}
}
printf("\nDone with encoding.. cleaning up..\n");
printf("Closing context...\n");
avcodec_close(context);
printf("Closing context done...\n");
printf("Freeing context...\n");
av_free(context);
printf("Freeing context done...\n");
if(inFrame->data[0] != NULL)
{
printf("avfreep() pointer to FFMPEG frame data...\n");
av_freep(&inFrame->data[0]);
printf("Freeing pointer to FFMPEG frame data done...\n");
}
else
{
printf("infRame->data[0] was not deleted because it was NULL\n");
}
printf("Freeing frame...\n");
av_frame_free(&inFrame);
printf("Freeing inFrame done...\n");
printf("Compression of frame done...\n");
gettimeofday(&stop, NULL);
printf("took %lu ms\n", (stop.tv_usec - start.tv_usec) / 1000);This is the output that I am getting when I run the program :
[ffv1 @ 0x75101970] bits_per_raw_sample > 8, forcing range coder
Successfully filled inFrame with frame->image..
Size of bytes filled: 1377792Got a valid package after 1 frames..
Buffersize determined to be 1377792
Buffersize is: 1377792, should be 1377792
copying data into final variable...
copying of data done
Unrefing packet..
Unrefing packet done..
Done with encoding.. cleaning up..
Closing context...
Closing context done...
Freeing context...
Freeing context done...
avfreep() pointer to FFMPEG frame data...
*** Error in `./encoding': free(): invalid pointer: 0x74a66428 ***
AbortedThe error seems to occur when calling the av_freep() function. If you could point me in the right direction, it would be greatly appreciated ! This is my first time working with the ffmpeg api and I feel that I am not so close to my goal, though I spent quite some time looking for the error already..
Best regards !
-
How to set up ffmpeg options for HLS ?
19 février 2015, par user1816574I have a streaming device that streams mpegts video and audio. I am trying to capture those streams and save them multiple .ts file using HLS of ffmpeg.
So, I have been successful in capturing and saving the streams in a single .ts file. It seems like when I send the output file to be .m3u8, ffmpeg automatically chooses hls demuxer. But, doing so I get a floating point exception.
Here is my simple code...static int ipcam_streaming_main_configure_input_parameters(const char *p_ifilename, AVFormatContext **ppx_ifmt_ctx)
{
AVStream *px_istream = NULL;
AVCodecContext *px_icodec_ctx = NULL;
int ret = -1;
unsigned int i = 0;
enum AVCodecID input_codec_id = AV_CODEC_ID_NONE;
AVCodec *p_decoder = NULL;
if (avformat_open_input(ppx_ifmt_ctx, p_ifilename, NULL, NULL) < 0)
{
printf("%s(): avformat_open_input() failed\n", __FUNCTION__);
}
else if (avformat_find_stream_info(*ppx_ifmt_ctx, NULL) < 0)
{
printf("%s(): avformat_find_stream_info() failed\n", __FUNCTION__);
}
else
{
/* find the input streams to be remuxed */
for (i = 0; i < (*ppx_ifmt_ctx)->nb_streams; i++)
{
/* get the stream, codec context for the stream */
px_istream = (*ppx_ifmt_ctx)->streams[i];
px_icodec_ctx = px_istream->codec;
if ((AVMEDIA_TYPE_VIDEO == px_icodec_ctx->codec_type)
|| (AVMEDIA_TYPE_AUDIO == px_icodec_ctx->codec_type))
{
/* get the codec_id for the audio/video stream */
input_codec_id = px_icodec_ctx->codec_id;
/* get the decoder for the input codec id */
p_decoder = avcodec_find_decoder(px_icodec_ctx->codec_id);
/* Open decoder for the input codec audio/video */
ret = avcodec_open2(px_icodec_ctx,
p_decoder,
NULL);
if (ret < 0)
{
printf("%s(): avcodec_open2() failed\n", __FUNCTION__);
}
else
{
printf("Input stream type <%d> with codec_id <%d> found and decoder opened\n", px_icodec_ctx->codec_type, input_codec_id);
}
}
}
}
/* dump the data into stdout */
av_dump_format(*ppx_ifmt_ctx, 0, p_ifilename, 0);
return ret;
}
static int ipcam_streaming_main_configure_output_parameters(const char *p_ofilename,
AVFormatContext *px_ifmt_ctx,
AVFormatContext **ppx_ofmt_ctx)
{
AVStream *px_ostream = NULL;
AVStream *px_istream = NULL;
AVCodecContext *px_dec_ctx = NULL;
AVCodecContext *px_enc_ctx = NULL;
int ret = -1;
unsigned int i = 0;
if ((NULL == p_ofilename) || (NULL == px_ifmt_ctx) || (NULL == ppx_ofmt_ctx))
{
printf("%s(): NULL arg(s) <%p, %p, %p>", __FUNCTION__, p_ofilename, px_ifmt_ctx, ppx_ofmt_ctx);
return -1;
}
/* remove the output file if already exists */
remove(p_ofilename);
/* allocate the output format context */
if (avformat_alloc_output_context2(ppx_ofmt_ctx, NULL, NULL, p_ofilename) < 0)
{
printf("%s(): avformat_alloc_output_context2() failed\n", __FUNCTION__);
}
else
{
for (i = 0; i < px_ifmt_ctx->nb_streams; i++)
{
if ((AVMEDIA_TYPE_VIDEO == px_ifmt_ctx->streams[i]->codec->codec_type)
|| (AVMEDIA_TYPE_AUDIO == px_ifmt_ctx->streams[i]->codec->codec_type))
{
printf("Stream <%d> is type <%d>: Adding to output stream\n", i, px_ifmt_ctx->streams[i]->codec->codec_type);
/* create a new output stream */
px_ostream = avformat_new_stream(*ppx_ofmt_ctx, NULL);
if (NULL == px_ostream)
{
printf("%s(): avformat_new_stream() failed\n", __FUNCTION__);
}
else
{
px_istream = px_ifmt_ctx->streams[i];
px_dec_ctx = px_istream->codec;
px_enc_ctx = px_ostream->codec;
/* Since, we do not need to encode the video stream, it is just remuxing
just copying the input codec context to output is sufficient */
ret = avcodec_copy_context((*ppx_ofmt_ctx)->streams[i]->codec,
px_ifmt_ctx->streams[i]->codec);
if ((*ppx_ofmt_ctx)->oformat->flags & AVFMT_GLOBALHEADER)
{
px_enc_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
}
}
else
{
printf("Stream <%d> is Unknown: Ignore it \n", i);
}
}
/* dump the output media file into stdout */
av_dump_format(*ppx_ofmt_ctx, 0, p_ofilename, 1);
if (0 == ((*ppx_ofmt_ctx)->oformat->flags & AVFMT_NOFILE))
{
/* open the output media file so that we can write the data into it */
ret = avio_open(&(*ppx_ofmt_ctx)->pb, p_ofilename, AVIO_FLAG_WRITE);
if (ret < 0)
{
printf("%s(): avio_open() failed\n", __FUNCTION__);
}
else
{
/* init muxer, write output file header */
ret = avformat_write_header((*ppx_ofmt_ctx), NULL);
if (ret < 0)
{
printf("%s(): avformat_write_header() failed\n", __FUNCTION__);
}
}
}
}
return ret;
}
int main(int argnum, char **argv)
{
AVFormatContext *px_ifmt_ctx = NULL;
AVFormatContext *px_ofmt_ctx = NULL;
AVPacket packet = {0};
enum AVMediaType type = AVMEDIA_TYPE_UNKNOWN;
unsigned int stream_index = -1;
unsigned int i = 0;
int ret = -1;
if (argnum != 3)
{
printf("Please enough number of parameters\n");
return -1;
}
/* register all the services requred */
av_register_all();
avformat_network_init();
if (0 != ipcam_streaming_main_configure_input_parameters(argv[1],
&px_ifmt_ctx))
{
printf("%s(): ipcam_streaming_main_configure_iput_parameters() failed\n", __FUNCTION__);
}
else if (0 != ipcam_streaming_main_configure_output_parameters(argv[2],
px_ifmt_ctx,
&px_ofmt_ctx))
{
printf("%s(): ipcam_streaming_main_configure_output_parameters() failed\n", __FUNCTION__);
}
else
{
printf("Input and output configuration done successfully: Now reading packets\n");
while (true)
{
if ((ret = av_read_frame(px_ifmt_ctx, &packet)) < 0)
{
printf("av_read_frame() failed with error <%d>: Exit\n", ret);
break;
}
/* get the stream index and codec type of the packet read */
stream_index = packet.stream_index;
type = px_ifmt_ctx->streams[stream_index]->codec->codec_type;
/* remux only if the type is video, otherwise ignore it */
if ((AVMEDIA_TYPE_VIDEO == type)
|| (AVMEDIA_TYPE_AUDIO == type))
{
printf("Remuxing the stream type <%d>, frame with stream index <%d>\n", type, stream_index);
/* remux this frame without reencoding */
packet.dts = av_rescale_q_rnd(packet.dts,
px_ifmt_ctx->streams[stream_index]->time_base,
px_ofmt_ctx->streams[stream_index]->time_base,
AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
packet.pts = av_rescale_q_rnd(packet.pts,
px_ifmt_ctx->streams[stream_index]->time_base,
px_ofmt_ctx->streams[stream_index]->time_base,
AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX);
/* write the frame into the output media file */
ret = av_write_frame(px_ofmt_ctx, &packet);
if (ret < 0)
{
printf("Ignoring video packet stream index <%d>\n", packet.stream_index);
}
/* free the packet for next use */
av_free_packet(&packet);
}
else
{
printf("Ignoring stream index <%d>, type <%d>\n", packet.stream_index, type);
}
}
}
/* write the trailer */
av_write_trailer(px_ofmt_ctx);
av_free_packet(&packet);
for (i = 0; i < px_ifmt_ctx->nb_streams; i++)
{
/* close the input codec that has been opened */
avcodec_close(px_ifmt_ctx->streams[i]->codec);
if ((NULL != px_ofmt_ctx) && (px_ofmt_ctx->nb_streams > i) &&
(NULL != px_ofmt_ctx->streams[i]) && ( NULL != px_ofmt_ctx->streams[i]->codec))
{
/* close the output code */
avcodec_close(px_ofmt_ctx->streams[i]->codec);
}
}
/* close the input */
avformat_close_input(&px_ifmt_ctx);
if ((NULL != px_ofmt_ctx) && (0 == (px_ofmt_ctx->oformat->flags & AVFMT_NOFILE)))
{
/* close the output context */
avio_close(px_ofmt_ctx->pb);
}
/* free the output context */
avformat_free_context(px_ofmt_ctx);
return ret;
}So, If i pass the output filename to be .m3u8 file, it gives a floating point exception.
-
Virginia Consumer Data Protection Act (VCDPA) Guide
27 septembre 2023, par Erin — Privacy