
Recherche avancée
Médias (91)
-
Richard Stallman et le logiciel libre
19 octobre 2011, par
Mis à jour : Mai 2013
Langue : français
Type : Texte
-
Stereo master soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
Elephants Dream - Cover of the soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Image
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Autres articles (91)
-
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 ;
-
MediaSPIP v0.2
21 juin 2013, parMediaSPIP 0.2 est la première version de MediaSPIP stable.
Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Le profil des utilisateurs
12 avril 2011, parChaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)
Sur d’autres sites (10839)
-
Win32 : Only use large buffers when writing to disk
11 décembre 2015, par Erik de Castro LopoWin32 : Only use large buffers when writing to disk
Windows can suffer quite badly from disk fragmentations. To avoid
this, on Windows, the FILE* buffer size was set to 10Meg. However,
this huge buffer is undesireable when writing to a eg a pipe.This patch updates the behaviour to only use the huge buffer when
writing to disk.Patch-from : lvqcl <lvqcl.mail@gmail.com>
Closes : https://sourceforge.net/p/flac/feature-requests/114/ -
Prepending generated audio silence when merging audio w/ non-zero starting PTS and video with zero-based PTS for equal duration, aligned streams
20 juillet 2021, par hedgehog90When extracting segments from a media file with video and audio streams without re-encoding (-c copy), it is likely that the requested seek & end time specified will not land precisely on a keyframe in the source.


In this case, ffmpeg will grab the nearest keyframe of each track and position them with differing starting PTS values so that they remain in sync.


Video keyframes tend to be a lot more spaced apart, so you can often end up with something like this :




Viewing the clip in VLC, the audio will start at 5 seconds in.


However, in other video players or video editors I've noticed this can lead to some playback issues or a/v desync.


A solution would be to re-encode both streams when extracting the clip, allowing ffmpeg to precisely seek to the specified seek time and generating equal length & synced audio and video tracks.


However, in my case I do not want to re-encode the video, it is costly and produces lower quality video and/or greater file sizes. I would prefer to only re-encode the audio, filling the initial gap with generated silence.


This should be simple, but everything I've tried has failed to generate silence before the audio stream begins.


I've tried apad, aresample=sync=1, and using amerge to combine the audio with anullsrc. None of it works.


All I can think to possibly get around this is to use ffprobe on the misaligned source to retrieve the first audio PTS, and in a second ffmpeg process apply this value as a negative -itoffset, then concatting the audio track with generated silence lasting the duration of silence... But surely there's a better way, with just one instance of ffmpeg ?


Any ideas ?


-
How to encode resampled PCM-audio to AAC using ffmpeg-API when input pcm samples count not equal 1024
22 février 2023, par Aleksei2414904I am working on capturing and streaming audio to RTMP server at a moment. I work under MacOS (in Xcode), so for capturing audio sample-buffer I use AVFoundation-framework. But for encoding and streaming I need to use ffmpeg-API and libfaac encoder. So output format must be AAC (for supporting stream playback on iOS-devices).



And I faced with such problem : audio-capturing device (in my case logitech camera) gives me sample-buffer with 512 LPCM samples, and I can select input sample-rate from 16000, 24000, 36000 or 48000 Hz. When I give these 512 samples to AAC-encoder (configured for appropriate sample-rate), I hear a slow and jerking audio (seems as like pice of silence after each frame).



I figured out (maybe I am wrong), that libfaac encoder accepts audio frames only with 1024 samples. When I set input samplerate to 24000 and resample input sample-buffer to 48000 before encoding, I obtain 1024 resampled samples. After encoding these 1024 sampels to AAC, I hear proper sound on output. But my web-cam produce 512 samples in buffer for any input samplerate, when output sample-rate must be 48000 Hz. So I need to do resampling in any case, and I will not obtain exactly 1024 samples in buffer after resampling.



Is there a way to solve this problem within ffmpeg-API functionality ?



I would be grateful for any help.



PS :
I guess that I can accumulate resampled buffers until count of samples become 1024, and then encode it, but this is stream so there will be troubles with resulting timestamps and with other input devices, and such solution is not suitable.



The current issue came out of the problem described in [question] : How to fill audio AVFrame (ffmpeg) with the data obtained from CMSampleBufferRef (AVFoundation) ?



Here is a code with audio-codec configs (there also was video stream but video work fine) :



/*global variables*/
 static AVFrame *aframe;
 static AVFrame *frame;
 AVOutputFormat *fmt; 
 AVFormatContext *oc; 
 AVStream *audio_st, *video_st;
Init ()
{
 AVCodec *audio_codec, *video_codec;
 int ret;

 avcodec_register_all(); 
 av_register_all();
 avformat_network_init();
 avformat_alloc_output_context2(&oc, NULL, "flv", filename);
 fmt = oc->oformat;
 oc->oformat->video_codec = AV_CODEC_ID_H264;
 oc->oformat->audio_codec = AV_CODEC_ID_AAC;
 video_st = NULL;
 audio_st = NULL;
 if (fmt->video_codec != AV_CODEC_ID_NONE) 
 { //… /*init video codec*/}
 if (fmt->audio_codec != AV_CODEC_ID_NONE) {
 audio_codec= avcodec_find_encoder(fmt->audio_codec);

 if (!(audio_codec)) {
 fprintf(stderr, "Could not find encoder for '%s'\n",
 avcodec_get_name(fmt->audio_codec));
 exit(1);
 }
 audio_st= avformat_new_stream(oc, audio_codec);
 if (!audio_st) {
 fprintf(stderr, "Could not allocate stream\n");
 exit(1);
 }
 audio_st->id = oc->nb_streams-1;

 //AAC:
 audio_st->codec->sample_fmt = AV_SAMPLE_FMT_S16;
 audio_st->codec->bit_rate = 32000;
 audio_st->codec->sample_rate = 48000;
 audio_st->codec->profile=FF_PROFILE_AAC_LOW;
 audio_st->time_base = (AVRational){1, audio_st->codec->sample_rate };
 audio_st->codec->channels = 1;
 audio_st->codec->channel_layout = AV_CH_LAYOUT_MONO; 


 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
 audio_st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
 }

 if (video_st)
 {
 // …
 /*prepare video*/
 }
 if (audio_st)
 {
 aframe = avcodec_alloc_frame();
 if (!aframe) {
 fprintf(stderr, "Could not allocate audio frame\n");
 exit(1);
 }
 AVCodecContext *c;
 int ret;

 c = audio_st->codec;


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

 //…
}




And resampling and encoding audio :



if (mType == kCMMediaType_Audio)
{
 CMSampleTimingInfo timing_info;
 CMSampleBufferGetSampleTimingInfo(sampleBuffer, 0, &timing_info);
 double pts=0;
 double dts=0;
 AVCodecContext *c;
 AVPacket pkt = { 0 }; // data and size must be 0;
 int got_packet, ret;
 av_init_packet(&pkt);
 c = audio_st->codec;
 CMItemCount numSamples = CMSampleBufferGetNumSamples(sampleBuffer);

 NSUInteger channelIndex = 0;

 CMBlockBufferRef audioBlockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
 size_t audioBlockBufferOffset = (channelIndex * numSamples * sizeof(SInt16));
 size_t lengthAtOffset = 0;
 size_t totalLength = 0;
 SInt16 *samples = NULL;
 CMBlockBufferGetDataPointer(audioBlockBuffer, audioBlockBufferOffset, &lengthAtOffset, &totalLength, (char **)(&samples));

 const AudioStreamBasicDescription *audioDescription = CMAudioFormatDescriptionGetStreamBasicDescription(CMSampleBufferGetFormatDescription(sampleBuffer));

 SwrContext *swr = swr_alloc();

 int in_smprt = (int)audioDescription->mSampleRate;
 av_opt_set_int(swr, "in_channel_layout", AV_CH_LAYOUT_MONO, 0);

 av_opt_set_int(swr, "out_channel_layout", audio_st->codec->channel_layout, 0);

 av_opt_set_int(swr, "in_channel_count", audioDescription->mChannelsPerFrame, 0);
 av_opt_set_int(swr, "out_channel_count", audio_st->codec->channels, 0);

 av_opt_set_int(swr, "out_channel_layout", audio_st->codec->channel_layout, 0);
 av_opt_set_int(swr, "in_sample_rate", audioDescription->mSampleRate,0);

 av_opt_set_int(swr, "out_sample_rate", audio_st->codec->sample_rate,0);

 av_opt_set_sample_fmt(swr, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);

 av_opt_set_sample_fmt(swr, "out_sample_fmt", audio_st->codec->sample_fmt, 0);

 swr_init(swr);
 uint8_t **input = NULL;
 int src_linesize;
 int in_samples = (int)numSamples;
 ret = av_samples_alloc_array_and_samples(&input, &src_linesize, audioDescription->mChannelsPerFrame,
 in_samples, AV_SAMPLE_FMT_S16P, 0);


 *input=(uint8_t*)samples;
 uint8_t *output=NULL;


 int out_samples = av_rescale_rnd(swr_get_delay(swr, in_smprt) +in_samples, (int)audio_st->codec->sample_rate, in_smprt, AV_ROUND_UP);

 av_samples_alloc(&output, NULL, audio_st->codec->channels, out_samples, audio_st->codec->sample_fmt, 0);
 in_samples = (int)numSamples;
 out_samples = swr_convert(swr, &output, out_samples, (const uint8_t **)input, in_samples);


 aframe->nb_samples =(int) out_samples;


 ret = avcodec_fill_audio_frame(aframe, audio_st->codec->channels, audio_st->codec->sample_fmt,
 (uint8_t *)output,
 (int) out_samples *
 av_get_bytes_per_sample(audio_st->codec->sample_fmt) *
 audio_st->codec->channels, 1);

 aframe->channel_layout = audio_st->codec->channel_layout;
 aframe->channels=audio_st->codec->channels;
 aframe->sample_rate= audio_st->codec->sample_rate;

 if (timing_info.presentationTimeStamp.timescale!=0)
 pts=(double) timing_info.presentationTimeStamp.value/timing_info.presentationTimeStamp.timescale;

 aframe->pts=pts*audio_st->time_base.den;
 aframe->pts = av_rescale_q(aframe->pts, audio_st->time_base, audio_st->codec->time_base);

 ret = avcodec_encode_audio2(c, &pkt, aframe, &got_packet);

 if (ret < 0) {
 fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret));
 exit(1);
 }
 swr_free(&swr);
 if (got_packet)
 {
 pkt.stream_index = audio_st->index;

 pkt.pts = av_rescale_q(pkt.pts, audio_st->codec->time_base, audio_st->time_base);
 pkt.dts = av_rescale_q(pkt.dts, audio_st->codec->time_base, audio_st->time_base);

 // Write the compressed frame to the media file.
 ret = av_interleaved_write_frame(oc, &pkt);
 if (ret != 0) {
 fprintf(stderr, "Error while writing audio frame: %s\n",
 av_err2str(ret));
 exit(1);
 }

}