
Recherche avancée
Médias (2)
-
Valkaama DVD Label
4 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Image
-
Podcasting Legal guide
16 mai 2011, par
Mis à jour : Mai 2011
Langue : English
Type : Texte
Autres articles (39)
-
Personnaliser les catégories
21 juin 2013, parFormulaire de création d’une catégorie
Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
On peut modifier ce formulaire dans la partie :
Administration > Configuration des masques de formulaire.
Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...) -
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 -
Contribute to documentation
13 avril 2011Documentation is vital to the development of improved technical capabilities.
MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
To contribute, register to the project users’ mailing (...)
Sur d’autres sites (6552)
-
Decoding and resampling audio with FFmpeg for output with libao
13 mai 2020, par DoctorSelarI'm trying to write a program to read and play an audio file using FFmpeg and libao. I've been following the procedure outlined in the FFmpeg documentation for decoding audio using the new
avcodec_send_packet
andavcodec_receive_frame
functions, but the examples I've been able to find are few and far between (the ones in the FFmpeg documentation either don't use libavformat or use the deprecatedavcodec_decode_audio4
). I've based a lot of my program off of the transcode_aac.c example (up toinit_resampler
) in the FFmpeg documentation, but that also uses the deprecated decoding function.


I believe I have the decoding part of the program working, but I need to resample the audio in order to convert it into an interleaved format to send to libao, for which I'm attempting to use libswresample. Whenever the program is run in its current state, it outputs (many times) "Error resampling : Output changed". The test file I've been using is just a YouTube rip that I had on hand. ffprobe reports the only stream as :



Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)




This is my first program with FFmpeg (and I'm still relatively new to C), so any advice on how to improve/fix other parts of the program would be welcome.



#include
#include<libavcodec></libavcodec>avcodec.h>
#include<libavformat></libavformat>avformat.h>
#include<libavutil></libavutil>avutil.h>
#include<libswresample></libswresample>swresample.h>
#include<ao></ao>ao.h>

#define OUTPUT_CHANNELS 2
#define OUTPUT_RATE 44100
#define BUFFER_SIZE 192000
#define OUTPUT_BITS 16
#define OUTPUT_FMT AV_SAMPLE_FMT_S16

static char *errtext (int err) {
 static char errbuff[256];
 av_strerror(err,errbuff,sizeof(errbuff));
 return errbuff;
}

static int open_audio_file (const char *filename, AVFormatContext **context, AVCodecContext **codec_context) {
 AVCodecContext *avctx;
 AVCodec *codec;
 int ret;
 int stream_id;
 int i;

 // Open input file
 if ((ret = avformat_open_input(context,filename,NULL,NULL)) < 0) {
 fprintf(stderr,"Error opening input file '%s': %s\n",filename,errtext(ret));
 *context = NULL;
 return ret;
 }

 // Get stream info
 if ((ret = avformat_find_stream_info(*context,NULL)) < 0) {
 fprintf(stderr,"Unable to find stream info: %s\n",errtext(ret));
 avformat_close_input(context);
 return ret;
 }

 // Find the best stream
 if ((stream_id = av_find_best_stream(*context,AVMEDIA_TYPE_AUDIO,-1,-1,&codec,0)) < 0) {
 fprintf(stderr,"Unable to find valid audio stream: %s\n",errtext(stream_id));
 avformat_close_input(context);
 return stream_id;
 }

 // Allocate a decoding context
 if (!(avctx = avcodec_alloc_context3(codec))) {
 fprintf(stderr,"Unable to allocate decoder context\n");
 avformat_close_input(context);
 return AVERROR(ENOMEM);
 }

 // Initialize stream parameters
 if ((ret = avcodec_parameters_to_context(avctx,(*context)->streams[stream_id]->codecpar)) < 0) {
 fprintf(stderr,"Unable to get stream parameters: %s\n",errtext(ret));
 avformat_close_input(context);
 avcodec_free_context(&avctx);
 return ret;
 }

 // Open the decoder
 if ((ret = avcodec_open2(avctx,codec,NULL)) < 0) {
 fprintf(stderr,"Could not open codec: %s\n",errtext(ret));
 avformat_close_input(context);
 avcodec_free_context(&avctx);
 return ret;
 }

 *codec_context = avctx;
 return 0;
}

static void init_packet (AVPacket *packet) {
 av_init_packet(packet);
 packet->data = NULL;
 packet->size = 0;
}

static int init_resampler (AVCodecContext *codec_context, SwrContext **resample_context) {
 int ret;

 // Set resampler options
 *resample_context = swr_alloc_set_opts(NULL,
 av_get_default_channel_layout(OUTPUT_CHANNELS),
 OUTPUT_FMT,
 codec_context->sample_rate,
 av_get_default_channel_layout(codec_context->channels),
 codec_context->sample_fmt,
 codec_context->sample_rate,
 0,NULL);
 if (!(*resample_context)) {
 fprintf(stderr,"Unable to allocate resampler context\n");
 return AVERROR(ENOMEM);
 }

 // Open the resampler
 if ((ret = swr_init(*resample_context)) < 0) {
 fprintf(stderr,"Unable to open resampler context: %s\n",errtext(ret));
 swr_free(resample_context);
 return ret;
 }

 return 0;
}

static int init_frame (AVFrame **frame) {
 if (!(*frame = av_frame_alloc())) {
 fprintf(stderr,"Could not allocate frame\n");
 return AVERROR(ENOMEM);
 }
 return 0;
}

int main (int argc, char *argv[]) {
 AVFormatContext *context = 0;
 AVCodecContext *codec_context;
 SwrContext *resample_context = NULL;
 AVPacket packet;
 AVFrame *frame = 0;
 AVFrame *resampled = 0;
 int16_t *buffer;
 int ret, packet_ret, finished;

 ao_device *device;
 ao_sample_format format;
 int default_driver;

 if (argc != 2) {
 fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
 return 1;
 }

 av_register_all();
 printf("Opening file...\n");
 if (open_audio_file(argv[1],&context,&codec_context) < 0)
 return 1;

 printf("Initializing resampler...\n");
 if (init_resampler(codec_context,&resample_context) < 0) {
 avformat_close_input(&context);
 avcodec_free_context(&codec_context);
 return 1;
 }

 // Setup libao
 printf("Starting audio device...\n");
 ao_initialize();
 default_driver = ao_default_driver_id();
 format.bits = OUTPUT_BITS;
 format.channels = OUTPUT_CHANNELS;
 format.rate = codec_context->sample_rate;
 format.byte_format = AO_FMT_NATIVE;
 format.matrix = 0;
 if ((device = ao_open_live(default_driver,&format,NULL)) == NULL) {
 fprintf(stderr,"Error opening audio device\n");
 avformat_close_input(&context);
 avcodec_free_context(&codec_context);
 swr_free(&resample_context);
 return 1;
 }

 // Mainloop
 printf("Beginning mainloop...\n");
 init_packet(&packet);
 // Read packets until done
 while (1) {
 packet_ret = av_read_frame(context,&packet);
 // Send a packet
 if ((ret = avcodec_send_packet(codec_context,&packet)) < 0)
 fprintf(stderr,"Error sending packet to decoder: %s\n",errtext(ret));

 av_packet_unref(&packet);

 while (1) {
 if (!frame)
 frame = av_frame_alloc();

 ret = avcodec_receive_frame(codec_context,frame);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) // Need more input
 break;
 else if (ret < 0) {
 fprintf(stderr,"Error receiving frame: %s\n",errtext(ret));
 break;
 }
 // We have a valid frame, need to resample it
 if (!resampled)
 resampled = av_frame_alloc();

 resampled->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);
 resampled->sample_rate = codec_context->sample_rate;
 resampled->format = OUTPUT_FMT;

 if ((ret = swr_convert_frame(resample_context,resampled,frame)) < 0) {
 fprintf(stderr,"Error resampling: %s\n",errtext(ret));
 } else {
 ao_play(device,(char*)resampled->extended_data[0],resampled->linesize[0]);
 }
 av_frame_unref(resampled);
 av_frame_unref(frame);
 }

 if (packet_ret == AVERROR_EOF)
 break;
 }

 printf("Closing file and freeing contexts...\n");
 avformat_close_input(&context);
 avcodec_free_context(&codec_context);
 swr_free(&resample_context);

 printf("Closing audio device...\n");
 ao_close(device);
 ao_shutdown();

 return 0;
}
</filename>



UPDATE : I've got it playing sound now, but it sounds like samples are missing (and MP3 files warn that "Could not update timestamps for skipped samples"). The issue was that the
resampled
frame needed to have certain attributes set before being passed toswr_convert_frame
. I've also addedav_packet_unref
andav_frame_unref
, but I'm still unsure as to where to best locate them.

-
run ffmpeg commands from my own project
28 octobre 2013, par brunoI'm starting a project where I want ppl to upload videos of a talk and a the video of slides for that talk and want to merge them (to play at the same time) and then show results.
My question is :
Is it possible to do that from code ? if it is, can you point me to the right doc ?
I was able to do it running command line, but as I want this to run on a server with different ppl uploading their videos I think this would not be the best approach.
I have a preference for Java if it's possible to do it, but I can manage to use other languages what do you guys suggest ?The idea would be to have a service where I can point the urls of the videos stored in my server and it would merge them and save file where I can later stream. With different ppl uploading videos at the same time and being able to watch the result in a reasonable amount of time.
I used this tutorial to test :
https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videosThanks for your time
-
avcodec/x86/videodsp : Small speedups in ff_emulated_edge_mc x86 SIMD.
26 octobre 2013, par Ronald S. Bultjeavcodec/x86/videodsp : Small speedups in ff_emulated_edge_mc x86 SIMD.
Don’t use word-size multiplications if size == 2, and if we’re using
SIMD instructions (size >= 8), complete leftover 4byte sets using movd,
not mov. Both of these changes lead to minor speedups.Signed-off-by : Michael Niedermayer <michaelni@gmx.at>