
Recherche avancée
Médias (91)
-
GetID3 - Boutons supplémentaires
9 avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
-
Core Media Video
4 avril 2013, par
Mis à jour : Juin 2013
Langue : français
Type : Video
-
The pirate bay depuis la Belgique
1er avril 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Image
-
Bug de détection d’ogg
22 mars 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Video
-
Exemple de boutons d’action pour une collection collaborative
27 février 2013, par
Mis à jour : Mars 2013
Langue : français
Type : Image
-
Exemple de boutons d’action pour une collection personnelle
27 février 2013, par
Mis à jour : Février 2013
Langue : English
Type : Image
Autres articles (28)
-
Emballe médias : à quoi cela sert ?
4 février 2011, parCe plugin vise à gérer des sites de mise en ligne de documents de tous types.
Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ; -
Librairies et logiciels spécifiques aux médias
10 décembre 2010, parPour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...) -
Menus personnalisés
14 novembre 2010, parMediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
Menus créés à l’initialisation du site
Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)
Sur d’autres sites (4973)
-
ffmpeg how to ignore initial empty audio frames when decoding to loop a sound
1er décembre 2020, par cs guyI am trying to loop a ogg sound file. The goal is to make a loopable audio interface for my mobile app.


I decode the given ogg file into a buffer and that buffer is sent to audio card for playing. All good until it the audio finishes (end of file). When it finishes I use
av_seek_frame(avFormatContext, streamInfoIndex, 0, AVSEEK_FLAG_FRAME);
to basically loop back to beginning. And continue decoding into writing to the same buffer. At first sight I thought this would give me perfect loops. One problem I had was, the decoder in the end gives me extra empty frames. So I ignored them by keeping track of how many samples are decoded :

durationInMillis = avFormatContext->duration * 1000;
numOfTotalSamples =
 (uint64_t) avFormatContext->duration *
 (uint64_t) pLocalCodecParameters->sample_rate *
 (uint64_t) pLocalCodecParameters->channels /
 (uint64_t) AV_TIME_BASE;



When the threshold is reached I ignore the frames sent by the codec. I thought this was it and ran some test. I recorded 5 minutes of my app and in the end I compared the results in FL studio by customly adding the same sound clip several times to match the length of my audio recording :


Here it is after 5 minutes :




In the first loops the difference is very low I thought it was working and I used this for several days until I tested this on 5 minute recording. As the looping approached to 5 minutes mark the difference got very huge. My code is not looping the audio correctly. I suspect that the codec is adding 1 or 2 empty frames at the very beginning in each loop caused by
av_seek_frame
knowing that a frame can contain up several audio samples. These probably accumulate and cause the mismatch.

My question is : how can I drop the empty frames that is sent by codec while decoding so that I can create a perfect loop of the audio ?


My code is below here. Please be aware that I deleted lots of if checks that was inteded for safety to make it more readable in the code below, these removed checks are always false so it doesnt matter for the reader.


helper.cpp


int32_t
outputAudioFrame(AVCodecContext *avCodecContext, AVFrame *avResampledDecFrame, int32_t &ret,
 LockFreeQueue<float> *&buffer, int8_t *&mediaLoadPointer,
 AVFrame *avDecoderFrame, SwrContext *swrContext,
 std::atomic_bool *&signalExitFuture,
 uint64_t &currentNumSamples, uint64_t &numOfTotalSamples) {
 // resampling is done here but its boiler code so I removed it.
 auto *floatArrPtr = (float *) (avResampledDecFrame->data[0]);

 int32_t numOfSamples = avResampledDecFrame->nb_samples * avResampledDecFrame->channels;

 for (int32_t i = 0; i < numOfSamples; i++) {
 if (currentNumSamples == numOfTotalSamples) {
 break;
 }

 buffer->push(*floatArrPtr);
 currentNumSamples++;
 floatArrPtr++;
 }

 return 0;
}



int32_t decode(int32_t &ret, AVCodecContext *avCodecContext, AVPacket *avPacket,
 LockFreeQueue<float> *&buffer,
 AVFrame *avDecoderFrame,
 AVFrame *avResampledDecFrame,
 std::atomic_bool *&signalExitFuture,
 int8_t *&mediaLoadPointer, SwrContext *swrContext,
 uint64_t &currentNumSamples, uint64_t &numOfTotalSamples) {
 
 ret = avcodec_send_packet(avCodecContext, avPacket);
 if (ret < 0) {
 LOGE("decode: Error submitting a packet for decoding %s", av_err2str(ret));
 return ret;
 }

 // get all the available frames from the decoder
 while (ret >= 0) {

 // submit the packet to the decoder
 ret = avcodec_receive_frame(avCodecContext, avDecoderFrame);
 if (ret < 0) {
 // those two return values are special and mean there is no output
 // frame available, but there were no errors during decoding
 if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN)) {
 //LOGD("avcodec_receive_frame returned special %s", av_err2str(ret));
 return 0;
 }

 LOGE("avcodec_receive_frame Error during decoding %s", av_err2str(ret));
 return ret;
 }

 ret = outputAudioFrame(avCodecContext, avResampledDecFrame, ret, buffer,
 mediaLoadPointer, avDecoderFrame, swrContext, signalExitFuture,
 currentNumSamples, numOfTotalSamples);

 av_frame_unref(avDecoderFrame);
 av_frame_unref(avResampledDecFrame);

 if (ret < 0)
 return ret;
 }

 return 0;
}
</float></float>


Main.cpp


while (!*signalExitFuture) {
 while ((ret = av_read_frame(avFormatContext, avPacket)) >= 0) {

 ret = decode(ret, avCodecContext, avPacket, buffer, avDecoderFrame,
 avResampledDecFrame, signalExitFuture,
 mediaLoadPointer, swrContext,
 currentNumSamples, numOfTotalSamples);

 // The packet must be freed with av_packet_unref() when it is no longer needed.
 av_packet_unref(avPacket);

 if (ret < 0) {
 LOGE("Error! %s", av_err2str(ret));

 goto cleanup;
 }
 }

 if (ret == AVERROR_EOF) {

 ret = av_seek_frame(avFormatContext, streamInfoIndex, 0, AVSEEK_FLAG_FRAME);

 currentNumSamples = 0;
 avcodec_flush_buffers(avCodecContext);
 }
 }



-
opencv c api video writer query
28 janvier 2015, par monikaI am working on opencv. I have written a c code using video writer that converts the video which is coming from camera. But, the output that i am getting containing no audio. So my question is how to compress the audio as well. What library i can use for it. I have googled it and came to know opencv_ffmpeg can be used but i dont know how to use. So please can u help me in resolvimg this.
My code is :
#include
#include
#include
#include
#include
#include
#include
int main()
{
int key = 0,j,k,fps,frameH,frameW,height;
int c=1,d=1;
char buffer[1000];
int count = 0;
IplImage* color=0;
IplImage* ChangedImage=0;
char special[200];
CvCapture* capture=0;
CvVideoWriter* writer;
IplImage* img=0;
//to capture video
capture = cvCreateCameraCapture(1);
/* capture = cvCreateFileCapture("F:\Wildlife.wmv");*/
if ( !capture )
{
fprintf( stderr, "Cannot open file!\n" );
}
img = cvQueryFrame( capture );
frameH = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
frameW = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
// to create a video file
writer=cvCreateVideoWriter("F:/logitechhighresolutioncompressed.avi",CV_FOURCC('M','J','P','G'),fps,cvSize(frameW, frameH ),1);
if (!writer) {
printf("!!! Failed cvCreateVideoWriter");
return;
}
if( !img )
{
exit;
}
if(img)
{
/* img = cvQueryFrame( capture );*/
cvShowImage( "video", img );
cvWriteFrame(writer, img);
/* cvWaitKey(0);*/
/*cvWriteFrame(writer, img);*/
d++;
/*if (cvWaitKey(100)== 27) break;*/
}/*while(img);*/
/* mytime1 = time(NULL);
printf(ctime(&mytime1));*/
cvReleaseVideoWriter(&writer);
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
cvWaitKey(0);
return 0; enter code here
system("PAUSE");
} -
Embedding Audio File to Video
19 septembre 2022, par Hamza NaeemI had a special .wav file with some encodings in it and i want to insert this into video file. I tried this with moviepy using the following method but it doesn't helped me as the audio get distorted.


import moviepy
from moviepy.editor import VideoFileClip, AudioFileClip, CompositeAudioClip, concatenate_audioclips


if __name__ == "__main__":
audio_file = f'audios/a1.wav'
 video_file = f'videos/v1.mp4'
 audio_clip = AudioFileClip(audio_file)
 video_clip = VideoFileClip(video_file)

 final_audio = CompositeAudioClip([video_clip.audio, audio_clip])
 video_clip.write_videofile(f'results/out.mp4')
 video_clip.close()
 audio_clip.close()



nothing with ffmpeg as :


import ffmpeg

if __name__ == "__main__":
 video = ffmpeg.input(f'videos/v1.mp4').video # get only video channel
 audio = ffmpeg.input(f'audios/a1.wav').audio # get only audio channel
 output = ffmpeg.output(video, audio, f'results/output.mp4', vcodec='copy', acodec='aac', strict='experimental')
 ffmpeg.run(output)



although I can extract the perfect mp3 file using pydub, but again inserting this into video distort the audio. it may due to miss match of fps or something else. The pydub stuff is as follows :


import pydub
from pydub import AudioSegment

audio_file = f'audios/a1.wav'
sound = pydub.AudioSegment.from_mp3(audio_file)
sound.export("results/apple.mp3", format="wav")



can anyone here to guide me with the correct method.


Thanks in advance.