
Recherche avancée
Médias (91)
-
999,999
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
The Slip - Artworks
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
-
Demon seed (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
The four of us are dying (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
Corona radiata (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
Lights in the sky (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
Autres articles (79)
-
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 (...) -
Des sites réalisés avec MediaSPIP
2 mai 2011, parCette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page. -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs
Sur d’autres sites (14500)
-
avcodec_open2 error -542398533 : "Generic error in an external library"
15 février 2017, par bot1131357I am encountering an error when trying to open the codec with
avcodec_open2()
. I have tried the same code without any problems if I specifyavi
instead ofh264
in theav_guess_format()
function.I don’t know what to make of it. Has anyone else encountered a similar problem ?
The library that I’m using is ffmpeg-20160219-git-98a0053-win32-dev. I would really really appreciate if you could help me out of this confusion.
This is my console output :
Video encoding
[libx264 @ 01383460] broken ffmpeg default settings detected
[libx264 @ 01383460] use an encoding preset (e.g. -vpre medium)
[libx264 @ 01383460] preset usage : -vpre -vpre
[libx264 @ 01383460] speed presets are listed in x264 —help
[libx264 @ 01383460] profile is optional ; x264 defaults to high
Cannot open video codec, -542398533This is the code that I’m working with :
// Video encoding sample
AVCodec *codec = NULL;
AVCodecContext *codecCtx= NULL;
AVFormatContext *pFormatCtx = NULL;
AVOutputFormat *pOutFormat = NULL;
AVStream * pVideoStream = NULL;;
AVFrame *picture = NULL;;
int i, x, y, ret;
printf("Video encoding\n");
// Register all formats and codecs
av_register_all();
// guess format from file extension
pOutFormat = av_guess_format("h264", NULL, NULL);
if (NULL==pOutFormat){
cerr << "Could not guess output format" << endl;
return -1;
}
// allocate context
pFormatCtx = avformat_alloc_context();
pFormatCtx->oformat = pOutFormat;
memcpy(pFormatCtx->filename,filename,
min(strlen(filename), sizeof(pFormatCtx->filename)));
// Add stream to pFormatCtx
pVideoStream = avformat_new_stream(pFormatCtx, 0);
if (!pVideoStream)
{
printf("Cannot add new video stream\n");
return -1;
}
// Set stream's codec context
codecCtx = pVideoStream->codec;
codecCtx->codec_id = (AVCodecID)pOutFormat->video_codec;
codecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
codecCtx->frame_number = 0;
// Put sample parameters.
codecCtx->bit_rate = 2000000;
// Resolution must be a multiple of two.
codecCtx->width = 320;
codecCtx->height = 240;
codecCtx->time_base.den = 10;
codecCtx->time_base.num = 1;
pVideoStream->time_base.den = 10;
pVideoStream->time_base.num = 1;
codecCtx->gop_size = 12; // emit one intra frame every twelve frames at most
codecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
if (codecCtx->codec_id == AV_CODEC_ID_H264)
{
// Just for testing, we also add B frames
codecCtx->mb_decision = 2;
}
// Some formats want stream headers to be separate.
if(pFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
{
codecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
if(codecCtx->codec_id == AV_CODEC_ID_H264)
av_opt_set(codecCtx->priv_data, "preset", "slow", 0);
// Open the codec.
codec = avcodec_find_encoder(codecCtx->codec_id);
if (codec == NULL) {
fprintf(stderr, "Codec not found\n");
return -1;
}
ret = avcodec_open2(codecCtx, codec, NULL); // returns -542398533 here
if (ret < 0)
{
printf("Cannot open video codec, %d\n",ret);
return -1;
} -
"Application provided invalid, non monotonically increasing dts to muxer in stream 0 : 47104 >= -4251" in C ffmpeg video & audio streams processing
30 décembre 2023, par M.HakimFor an input.mp4 file containing a video stream and an audio stream, intend to convert the video stream into h264 codec and the audio stream into aac codec and combine the two streams in output.mp4 file using C and ffmpeg libraries.
Am getting an error [mp4 @ 0x5583c88fd340] Application provided invalid, non monotonically increasing dts to muxer in stream 0 : 47104 >= -4251
How do i solve that error ?


#include 
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h> 
#include <libavutil></libavutil>opt.h>

int encodeVideoAndAudio4(char *pInName, char *pOutName) {

 AVFormatContext *format_ctx = avformat_alloc_context();

 AVCodecContext *video_dec_ctx = NULL;
 AVCodecContext *video_enc_ctx = NULL;
 AVCodec *video_dec_codec = NULL;
 AVCodec *video_enc_codec = NULL;
 AVDictionary *video_enc_opts = NULL;

 AVCodecContext *audio_dec_ctx = NULL;
 AVCodecContext *audio_enc_ctx = NULL;
 AVCodec *audio_dec_codec = NULL;
 AVCodec *audio_enc_codec = NULL;


 if (avformat_open_input(&format_ctx, pInName, NULL, NULL) < 0) {
 fprintf(stderr, "Error: Could not open input file\n");
 return 1;
 }

 if (avformat_find_stream_info(format_ctx, NULL) < 0) {
 fprintf(stderr, "Error: Could not find stream information\n");
 return 1;
 }

 for (int i = 0; i < format_ctx->nb_streams; i++) {
 AVStream *stream = format_ctx->streams[i];
 const char *media_type_str = av_get_media_type_string(stream->codecpar->codec_type);
 AVRational time_base = stream->time_base;

 }

 int video_stream_index = -1;
 for (int i = 0; i < format_ctx->nb_streams; i++) {
 if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
 video_stream_index = i;
 break;
 }
 }
 if (video_stream_index == -1) {
 fprintf(stderr, "Error: Could not find a video stream\n");
 return 1;
 }

 AVStream *videoStream = format_ctx->streams[video_stream_index];
 video_dec_ctx = avcodec_alloc_context3(NULL);
 avcodec_parameters_to_context(video_dec_ctx, videoStream->codecpar);

 video_dec_codec = avcodec_find_decoder(video_dec_ctx->codec_id);

 if (!video_dec_codec) {
 fprintf(stderr, "Unsupported video codec!\n");
 return 1;
 }

 if (avcodec_open2(video_dec_ctx, video_dec_codec, NULL) < 0) {
 fprintf(stderr, "Error: Could not open a video decoder codec\n");
 return 1;
 }

 video_enc_codec = avcodec_find_encoder(AV_CODEC_ID_H264);
 if (!video_enc_codec) {
 fprintf(stderr, "Error: Video Encoder codec not found\n");
 return 1;
 }

 video_enc_ctx = avcodec_alloc_context3(video_enc_codec);
 if (!video_enc_ctx) {
 fprintf(stderr, "Error: Could not allocate video encoder codec context\n");
 return 1;
 }

 videoStream->time_base = (AVRational){1, 25};

 video_enc_ctx->bit_rate = 1000; 
 video_enc_ctx->width = video_dec_ctx->width;
 video_enc_ctx->height = video_dec_ctx->height;
 video_enc_ctx->time_base = (AVRational){1, 25};
 video_enc_ctx->gop_size = 10;
 video_enc_ctx->max_b_frames = 1;
 video_enc_ctx->pix_fmt = AV_PIX_FMT_YUV420P;

 if (avcodec_open2(video_enc_ctx, video_enc_codec, NULL) < 0) {
 fprintf(stderr, "Error: Could not open encoder codec\n");
 return 1;
 }

 av_dict_set(&video_enc_opts, "preset", "medium", 0);
 av_opt_set_dict(video_enc_ctx->priv_data, &video_enc_opts);

 AVPacket video_pkt;
 av_init_packet(&video_pkt);
 video_pkt.data = NULL;
 video_pkt.size = 0;

 AVPacket pkt;
 av_init_packet(&pkt);
 pkt.data = NULL;
 pkt.size = 0;

 AVFrame *video_frame = av_frame_alloc();
 if (!video_frame) {
 fprintf(stderr, "Error: Could not allocate video frame\n");
 return 1;
 }

 video_frame->format = video_enc_ctx->pix_fmt;
 video_frame->width = video_enc_ctx->width;
 video_frame->height = video_enc_ctx->height;
 
 int audio_stream_index = -1;
 for (int i = 0; i < format_ctx->nb_streams; i++) {
 if (format_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
 audio_stream_index = i;
 break;
 }
 }

 if (audio_stream_index == -1) {
 fprintf(stderr, "Error: Could not find an audio stream\n");
 return 1;
 }
 
 AVStream *audioStream = format_ctx->streams[audio_stream_index];
 audio_dec_ctx = avcodec_alloc_context3(NULL);
 avcodec_parameters_to_context(audio_dec_ctx, audioStream->codecpar);
 
 audio_dec_codec = avcodec_find_decoder(audio_dec_ctx->codec_id);
 
 if (!audio_dec_codec) {
 fprintf(stderr, "Unsupported audio codec!\n");
 return 1;
 }
 
 if (avcodec_open2(audio_dec_ctx, audio_dec_codec, NULL) < 0) {
 fprintf(stderr, "Error: Could not open Audio decoder codec\n");
 return 1;
 }
 
 audio_enc_codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
 if (!audio_enc_codec) {
 fprintf(stderr, "Error: Audio Encoder codec not found\n");
 return 1;
 }
 
 audio_enc_ctx = avcodec_alloc_context3(audio_enc_codec);
 if (!audio_enc_ctx) {
 fprintf(stderr, "Error: Could not allocate audio encoder codec context\n");
 return 1;
 }

 audioStream->time_base = (AVRational){1, audio_dec_ctx->sample_rate};
 
 audio_enc_ctx->bit_rate = 64000; 
 audio_enc_ctx->sample_rate = audio_dec_ctx->sample_rate;
 audio_enc_ctx->channels = audio_dec_ctx->channels;
 audio_enc_ctx->channel_layout = av_get_default_channel_layout(audio_enc_ctx->channels);
 audio_enc_ctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 audio_enc_ctx->profile = FF_PROFILE_AAC_LOW;
 
 if (avcodec_open2(audio_enc_ctx, audio_enc_codec, NULL) < 0) {
 fprintf(stderr, "Error: Could not open encoder codec\n");
 return 1;
 }
 
 AVPacket audio_pkt;
 av_init_packet(&audio_pkt);
 audio_pkt.data = NULL;
 audio_pkt.size = 0;
 
 AVFrame *audio_frame = av_frame_alloc();
 if (!audio_frame) {
 fprintf(stderr, "Error: Could not allocate audio frame\n");
 return 1;
 }

 audio_frame->format = audio_enc_ctx->sample_fmt;
 audio_frame->sample_rate = audio_enc_ctx->sample_rate;
 audio_frame->channels = audio_enc_ctx->channels;
 
 AVFormatContext *output_format_ctx = NULL;
 if (avformat_alloc_output_context2(&output_format_ctx, NULL, NULL, pOutName) < 0) {
 fprintf(stderr, "Error: Could not create output context\n");
 return 1;
 }
 
 if (avio_open(&output_format_ctx->pb, pOutName, AVIO_FLAG_WRITE) < 0) {
 fprintf(stderr, "Error: Could not open output file\n");
 return 1;
 }
 
 AVStream *video_stream = avformat_new_stream(output_format_ctx, video_enc_codec);
 if (!video_stream) {
 fprintf(stderr, "Error: Could not create video stream\n");
 return 1;
 }
 
 av_dict_set(&video_stream->metadata, "rotate", "90", 0);
 
 if (avcodec_parameters_from_context(video_stream->codecpar, video_enc_ctx) < 0) {
 fprintf(stderr, "Error: Could not copy video codec parameters\n");
 return 1;
 }
 
 AVStream *audio_stream = avformat_new_stream(output_format_ctx, audio_enc_codec);
 if (!audio_stream) {
 fprintf(stderr, "Error: Could not create audio stream\n");
 return 1;
 }
 
 if (avcodec_parameters_from_context(audio_stream->codecpar, audio_enc_ctx) < 0) {
 fprintf(stderr, "Error: Could not copy audio codec parameters\n");
 return 1;
 }
 
 if (avformat_write_header(output_format_ctx, NULL) < 0) {
 fprintf(stderr, "Error: Could not write header\n");
 return 1;
 }
 
 int video_frame_count = 0, audio_frame_count = 0;
 
 while (1) {

 if (av_read_frame(format_ctx, &pkt) < 0) {
 fprintf(stderr, "BREAK FROM MAIN WHILE LOOP\n");
 break;
 }

 if (pkt.stream_index == video_stream_index) {

 if (avcodec_send_packet(video_dec_ctx, &pkt) < 0) {
 fprintf(stderr, "Error: Could not send video packet for decoding\n");
 return 1;
 }

 while (avcodec_receive_frame(video_dec_ctx, video_frame) == 0) { 

 if (avcodec_send_frame(video_enc_ctx, video_frame) < 0) {
 fprintf(stderr, "Error: Could not send video frame for encoding\n");
 return 1;
 }

 while (avcodec_receive_packet(video_enc_ctx, &video_pkt) == 0) {
 
 if (av_write_frame(output_format_ctx, &video_pkt) < 0) {
 fprintf(stderr, "Error: Could not write video packet to output file.\n");
 return 1;
 }

 av_packet_unref(&video_pkt);
 }

 video_frame_count++;
 }
 } else if (pkt.stream_index == audio_stream_index) {

 if (avcodec_send_packet(audio_dec_ctx, &pkt) < 0) {
 fprintf(stderr, "Error: Could not send audio packet for decoding\n");
 return 1;
 }

 while (avcodec_receive_frame(audio_dec_ctx, audio_frame) == 0) { 
 
 if (avcodec_send_frame(audio_enc_ctx, audio_frame) < 0) {
 fprintf(stderr, "Error: Could not send audio frame for encoding\n");
 return 1;
 }

 while (avcodec_receive_packet(audio_enc_ctx, &audio_pkt) == 0) { if (av_write_frame(output_format_ctx, &audio_pkt) < 0) {
 fprintf(stderr, "Error: Could not write audio packet to output file\n");
 return 1;
 }

 av_packet_unref(&audio_pkt);
 }

 audio_frame_count++;
 }
 }

 av_packet_unref(&pkt);
 }

 if (av_write_trailer(output_format_ctx) < 0) {
 fprintf(stderr, "Error: Could not write trailer\n");
 return 1;
 } 
 
 avformat_close_input(&format_ctx);
 avio_close(output_format_ctx->pb);
 avformat_free_context(output_format_ctx);
 
 av_frame_free(&video_frame);
 avcodec_free_context(&video_dec_ctx);
 avcodec_free_context(&video_enc_ctx);
 av_dict_free(&video_enc_opts);
 
 av_frame_free(&audio_frame);
 avcodec_free_context(&audio_dec_ctx);
 avcodec_free_context(&audio_enc_ctx);

 printf("Conversion complete. %d video frames processed and %d audio frames processed.\n",video_frame_count, audio_frame_count);

 return 0;
}


int main(int argc, char *argv[]) {
 if (argc != 3) {
 printf("Usage: %s \n", argv[0]);
 return 1;
 }

 const char *input_filename = argv[1];
 const char *output_filename = argv[2];

 avcodec_register_all();
 av_register_all();

 int returnValue = encodeVideoAndAudio4(input_filename, output_filename);
 
 return 0;
}




When i comment out the blocks that process one of the two streams, the other stream is converted and written to the output.mp4 successfully.
When each stream is processed in a separate loop, only the first stream is processed and written to the output.mp4 file and the other stream is skipped.
When both streams are processed in a common loop as it is in the code above, the above mentioned error appears.


-
bgmc : fix sizeof arguments (should fix CIDs : 700724 and 608084)
14 octobre 2012, par Thilo Borgmannbgmc : fix sizeof arguments (should fix CIDs : 700724 and 608084)