
Recherche avancée
Médias (1)
-
The pirate bay depuis la Belgique
1er avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
Autres articles (90)
-
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 ;
-
Mediabox : ouvrir les images dans l’espace maximal pour l’utilisateur
8 février 2011, parLa visualisation des images est restreinte par la largeur accordée par le design du site (dépendant du thème utilisé). Elles sont donc visibles sous un format réduit. Afin de profiter de l’ensemble de la place disponible sur l’écran de l’utilisateur, il est possible d’ajouter une fonctionnalité d’affichage de l’image dans une boite multimedia apparaissant au dessus du reste du contenu.
Pour ce faire il est nécessaire d’installer le plugin "Mediabox".
Configuration de la boite multimédia
Dès (...) -
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 (15334)
-
asm : FF_-prefix internal macros used in inline assembly
25 mai 2016, par Diego Biurrunasm : FF_-prefix internal macros used in inline assembly
These warnings conflict with system macros on Solaris, producing
truckloads of warnings about macro redefinition.- [DBH] libavcodec/x86/blockdsp.c
- [DBH] libavcodec/x86/cabac.h
- [DBH] libavcodec/x86/fpel_mmx.c
- [DBH] libavcodec/x86/h264_i386.h
- [DBH] libavcodec/x86/hpeldsp_rnd_template.c
- [DBH] libavcodec/x86/me_cmp_init.c
- [DBH] libavcodec/x86/mpegvideo.c
- [DBH] libavcodec/x86/mpegvideoenc_template.c
- [DBH] libavcodec/x86/rnd_template.c
- [DBH] libavcodec/x86/vc1dsp_mmx.c
- [DBH] libavutil/x86/asm.h
- [DBH] libavutil/x86/cpu.c
- [DBH] libswscale/utils.c
- [DBH] libswscale/x86/rgb2rgb_template.c
- [DBH] libswscale/x86/swscale_template.c
-
How to resample an audio with ffmpeg API ?
13 mai 2016, par tangrenI’d like to decode audio file(.wav .aac etc.) into raw data(pcm) and then resample it with ffmpeg API.
I try to do it with the help of the official examples. However, the result file always loses a little data at the end of the file compared to the file generated by ffmpeg command :
ffmpeg -i audio.wav -f s16le -ac 1 -ar 8000 -acodec pcm_s16le out.pcm
.In this case, the input audio metadata :
pcm_s16le, 16000 Hz, 1 channels, s16, 256 kb/s
And there are 32 bites lost at the end of result file.
What’s more, I’d like to process audios in memory, so how do I calculate the size of audio’s raw data (pcm) ?
My code :
#include <libavutil></libavutil>opt.h>
#include <libavutil></libavutil>imgutils.h>
#include <libavutil></libavutil>samplefmt.h>
#include <libavutil></libavutil>timestamp.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>channel_layout.h>
#include <libswresample></libswresample>swresample.h>
int convert_to_PCM(const char* src_audio_filename, const char* dst_pcm_filename, int dst_sample_rate)
{
FILE *audio_dst_file = NULL;
// for demuxing and decoding
int ret = 0, got_frame, decoded, tmp;
AVFormatContext *fmt_ctx = NULL;
AVCodecContext *audio_dec_ctx;
AVStream *audio_stream = NULL;
int audio_stream_idx = -1;
AVFrame *frame = NULL;
AVPacket pkt;
// for resampling
struct SwrContext *swr_ctx = NULL;
int src_sample_rate;
uint8_t **dst_data = NULL;
int dst_nb_samples, max_dst_nb_samples;
enum AVSampleFormat src_sample_fmt, dst_sample_fmt = AV_SAMPLE_FMT_S16;
int nb_channels = 1;
int dst_bufsize, dst_linesize;
int64_t src_ch_layout, dst_ch_layout;
dst_ch_layout = src_ch_layout = av_get_default_channel_layout(1);
av_register_all();
if (avformat_open_input(&fmt_ctx, src_audio_filename, NULL, NULL) < 0) {
fprintf(stderr, "Could not open source file %s\n", src_audio_filename);
return 1;
}
/* retrieve stream information */
if (avformat_find_stream_info(fmt_ctx, NULL) < 0) {
fprintf(stderr, "Could not find stream information\n");
return 1;
}
if (open_codec_context(&audio_stream_idx, fmt_ctx, AVMEDIA_TYPE_AUDIO) >= 0) {
audio_stream = fmt_ctx->streams[audio_stream_idx];
audio_dec_ctx = audio_stream->codec;
audio_dst_file = fopen(dst_pcm_filename, "wb");
if (!audio_dst_file) {
fprintf(stderr, "Could not open destination file %s\n", dst_pcm_filename);
ret = 1;
goto end;
}
}
/* dump input information to stderr */
av_dump_format(fmt_ctx, 0, src_audio_filename, 0);
if (!audio_stream) {
fprintf(stderr, "Could not find audio stream in the input, aborting\n");
ret = 1;
goto end;
}
src_sample_rate = audio_dec_ctx->sample_rate;
if (src_sample_rate != dst_sample_rate) {
/* create resampler context */
swr_ctx = swr_alloc();
if (!swr_ctx) {
fprintf(stderr, "Could not allocate resampler context\n");
ret = AVERROR(ENOMEM);
goto end;
}
src_sample_fmt = audio_dec_ctx->sample_fmt;
/* set options */
av_opt_set_int(swr_ctx, "in_channel_layout", src_ch_layout, 0);
av_opt_set_int(swr_ctx, "in_sample_rate", src_sample_rate, 0);
av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", src_sample_fmt, 0);
av_opt_set_int(swr_ctx, "out_channel_layout", dst_ch_layout, 0);
av_opt_set_int(swr_ctx, "out_sample_rate", dst_sample_rate, 0);
av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", dst_sample_fmt, 0);
/* initialize the resampling context */
if ((ret = swr_init(swr_ctx)) < 0) {
fprintf(stderr, "Failed to initialize the resampling context\n");
goto end;
}
}
frame = av_frame_alloc();
if (!frame) {
fprintf(stderr, "Could not allocate frame\n");
ret = AVERROR(ENOMEM);
goto end;
}
/* initialize packet, set data to NULL, let the demuxer fill it */
av_init_packet(&pkt);
pkt.data = NULL;
pkt.size = 0;
printf("Convert audio from file '%s' into '%s'\n", src_audio_filename, dst_pcm_filename);
/* read frames from the file */
while (av_read_frame(fmt_ctx, &pkt) >= 0) {
AVPacket orig_pkt = pkt;
do {
decoded = pkt.size;
got_frame = 0;
tmp = 0;
/* decode audio frame */
tmp = avcodec_decode_audio4(audio_dec_ctx, frame, &got_frame, &pkt);
if (tmp < 0) {
fprintf(stderr, "Error decoding audio frame (%s)\n", av_err2str(tmp));
break;
}
decoded = FFMIN(tmp, pkt.size);
if (got_frame) {
if (swr_ctx) {
if (dst_data == NULL) {
max_dst_nb_samples = dst_nb_samples = av_rescale_rnd(frame->nb_samples, dst_sample_rate, src_sample_rate, AV_ROUND_UP);
ret = av_samples_alloc_array_and_samples(&dst_data, &dst_linesize, nb_channels,
dst_nb_samples, dst_sample_fmt, 0);
if (ret < 0) {
fprintf(stderr, "Could not allocate destination samples\n");
goto end;
}
}
dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx, src_sample_rate) + frame->nb_samples, dst_sample_rate, src_sample_rate, AV_ROUND_UP);
if (dst_nb_samples > max_dst_nb_samples) {
av_freep(&dst_data[0]);
ret = av_samples_alloc(dst_data, &dst_linesize, nb_channels, dst_nb_samples, dst_sample_fmt, 1);
if (ret < 0)
break;
max_dst_nb_samples = dst_nb_samples;
}
/* convert to destination format */
ret = swr_convert(swr_ctx, dst_data, dst_nb_samples, (const uint8_t **)frame->data, frame->nb_samples);
if (ret < 0) {
fprintf(stderr, "Error while converting\n");
goto end;
}
dst_bufsize = av_samples_get_buffer_size(&dst_linesize, nb_channels, ret, dst_sample_fmt, 1);
if (dst_bufsize < 0) {
fprintf(stderr, "Could not get sample buffer size\n");
goto end;
}
printf("Decoded size: %d, dst_nb_samples: %d, converted size: %d, sample buffer size: %d\n", decoded, dst_nb_samples, ret, dst_bufsize);
fwrite(dst_data[0], 1, dst_bufsize, audio_dst_file);
}
else {
size_t unpadded_linesize = frame->nb_samples * av_get_bytes_per_sample(frame->format);
fwrite(frame->extended_data[0], 1, unpadded_linesize, audio_dst_file);
}
}
if (decoded < 0)
break;
pkt.data += tmp;
pkt.size -= tmp;
} while (pkt.size > 0);
av_packet_unref(&orig_pkt);
}
printf("Convert succeeded.\n");
end:
avcodec_close(audio_dec_ctx);
avformat_close_input(&fmt_ctx);
if (audio_dst_file)
fclose(audio_dst_file);
av_frame_free(&frame);
if (dst_data)
av_freep(&dst_data[0]);
av_freep(&dst_data);
swr_free(&swr_ctx);
return ret;
}
static int open_codec_context(int *stream_idx,
AVFormatContext *fmt_ctx, enum AVMediaType type)
{
int ret, stream_index;
AVStream *st;
AVCodecContext *dec_ctx = NULL;
AVCodec *dec = NULL;
AVDictionary *opts = NULL;
ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0);
if (ret < 0) {
fprintf(stderr, "Could not find %s stream in input file.\n",
av_get_media_type_string(type));
return ret;
} else {
stream_index = ret;
st = fmt_ctx->streams[stream_index];
/* find decoder for the stream */
dec_ctx = st->codec;
dec = avcodec_find_decoder(dec_ctx->codec_id);
if (!dec) {
fprintf(stderr, "Failed to find %s codec\n",
av_get_media_type_string(type));
return AVERROR(EINVAL);
}
if ((ret = avcodec_open2(dec_ctx, dec, &opts)) < 0) {
fprintf(stderr, "Failed to open %s codec\n",
av_get_media_type_string(type));
return ret;
}
*stream_idx = stream_index;
}
return 0;
}
static int get_format_from_sample_fmt(const char **fmt,
enum AVSampleFormat sample_fmt)
{
int i;
struct sample_fmt_entry {
enum AVSampleFormat sample_fmt; const char *fmt_be, *fmt_le;
} sample_fmt_entries[] = {
{ AV_SAMPLE_FMT_U8, "u8", "u8" },
{ AV_SAMPLE_FMT_S16, "s16be", "s16le" },
{ AV_SAMPLE_FMT_S32, "s32be", "s32le" },
{ AV_SAMPLE_FMT_FLT, "f32be", "f32le" },
{ AV_SAMPLE_FMT_DBL, "f64be", "f64le" },
};
*fmt = NULL;
for (i = 0; i < FF_ARRAY_ELEMS(sample_fmt_entries); i++) {
struct sample_fmt_entry *entry = &sample_fmt_entries[i];
if (sample_fmt == entry->sample_fmt) {
*fmt = AV_NE(entry->fmt_be, entry->fmt_le);
return 0;
}
}
fprintf(stderr,
"sample format %s is not supported as output format\n",
av_get_sample_fmt_name(sample_fmt));
return -1;
} -
[FFmpeg]what is replacements of avpicture_alloc,avpicture::data which were deprecated
12 avril 2016, par YJJI am modifying example source code(muxing.c) from FFmpeg site.
I changed old functions to new ones and tried to build the code.
then, there are several errrors said AVPicture was declared deprecated.I did some research on the internet but couldn’t find the answer how to fix it.
/* Allocate the encoded raw picture. */
ret = avpicture_alloc(&dst_picture, c->pix_fmt, c->width, c->height);
if (ret < 0)
{
//fprintf(stderr, "Could not allocate picture: %s\n", av_err2str(ret));
char buf[256];
av_strerror(ret, buf, sizeof(buf));
printf("Could not allocate picture: %s,ret:%d\n", buf, ret);
exit(1);
}