
Recherche avancée
Médias (1)
-
Bug de détection d’ogg
22 mars 2013, par
Mis à jour : Avril 2013
Langue : français
Type : Video
Autres articles (97)
-
Qu’est ce qu’un éditorial
21 juin 2013, parEcrivez votre de point de vue dans un article. Celui-ci sera rangé dans une rubrique prévue à cet effet.
Un éditorial est un article de type texte uniquement. Il a pour objectif de ranger les points de vue dans une rubrique dédiée. Un seul éditorial est placé à la une en page d’accueil. Pour consulter les précédents, consultez la rubrique dédiée.
Vous pouvez personnaliser le formulaire de création d’un éditorial.
Formulaire de création d’un éditorial Dans le cas d’un document de type éditorial, les (...) -
Contribute to translation
13 avril 2011You can help us to improve the language used in the software interface to make MediaSPIP more accessible and user-friendly. You can also translate the interface into any language that allows it to spread to new linguistic communities.
To do this, we use the translation interface of SPIP where the all the language modules of MediaSPIP are available. Just subscribe to the mailing list and request further informantion on translation.
MediaSPIP is currently available in French and English (...) -
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.
Sur d’autres sites (7077)
-
Record Audio using ALSA in mp4 format
18 novembre 2024, par teena meherenI am working on to record audio using ALSA library. I am able to record the audio using the same library in .wav file, but what I need is to record an
.mp4
file. For that I initialize the FFmpeg encoder to create MP4 file and trying to record the audio by writing the audio frames into the file. The result which I am getting is an empty MP4 file with no audio.

Here I am attaching the code which I have tried


#include 
#include 
#include 
#include <alsa></alsa>asoundlib.h>
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>opt.h>
#include <libswresample></libswresample>swresample.h>

int terminate = 0;
int channels = 2;

// Function to handle termination signal
void sigint_handler(int sig) {
 terminate = 1;
}

// Function to initialize the FFmpeg encoder and writer
AVFormatContext* init_ffmpeg_writer(const char *filename, AVCodecContext **audio_codec_ctx) {
 AVFormatContext *fmt_ctx = NULL;
 AVCodec *audio_codec = NULL;
 AVStream *audio_stream = NULL;

 // Initialize the output format context
 if (avformat_alloc_output_context2(&fmt_ctx, NULL, "mp4", filename) < 0) {
 fprintf(stderr, "Could not create output context\n");
 exit(1);
 }

 // Find the codec
 audio_codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
 if (!audio_codec) {
 fprintf(stderr, "Codec not found\n");
 exit(1);
 }

 // Create a new stream
 audio_stream = avformat_new_stream(fmt_ctx, audio_codec);
 if (!audio_stream) {
 fprintf(stderr, "Could not create audio stream\n");
 exit(1);
 }

 // Set up codec context
 *audio_codec_ctx = avcodec_alloc_context3(audio_codec);
 (*audio_codec_ctx)->channels = 2;
 (*audio_codec_ctx)->channel_layout = AV_CH_LAYOUT_STEREO;
 (*audio_codec_ctx)->sample_rate = 44100;
 (*audio_codec_ctx)->sample_fmt = AV_SAMPLE_FMT_FLTP; // 32-bit float for input format
 (*audio_codec_ctx)->bit_rate = 128000; // Bitrate for AAC encoding

 // Open the codec
 if (avcodec_open2(*audio_codec_ctx, audio_codec, NULL) < 0) {
 fprintf(stderr, "Could not open codec\n");
 exit(1);
 }

 // Copy codec parameters from codec context to the stream
 if (avcodec_parameters_from_context(audio_stream->codecpar, *audio_codec_ctx) < 0) {
 fprintf(stderr, "Could not copy codec parameters\n");
 exit(1);
 }

 // Open the output file
 if (!(fmt_ctx->oformat->flags & AVFMT_NOFILE)) {
 if (avio_open(&fmt_ctx->pb, filename, AVIO_FLAG_WRITE) < 0) {
 fprintf(stderr, "Could not open output file\n");
 exit(1);
 }
 }

 // Write the file header
 if (avformat_write_header(fmt_ctx, NULL) < 0) {
 fprintf(stderr, "Error occurred when writing header\n");
 exit(1);
 }

 return fmt_ctx;
}

void write_audio_frame(AVFormatContext *fmt_ctx, AVCodecContext *audio_codec_ctx, uint8_t *buffer, int buffer_size) {
 AVPacket pkt;
 AVFrame *frame;
 int ret;
 static int64_t frame_count = 0; // Ensure this is initialized correctly
 static double stream_time = 0;

 // Initialize the packet
 av_init_packet(&pkt);
 pkt.data = NULL;
 pkt.size = 0;

 // Allocate and set up frame
 frame = av_frame_alloc();
 frame->nb_samples = audio_codec_ctx->frame_size;
 frame->channel_layout = audio_codec_ctx->channel_layout;
 frame->format = audio_codec_ctx->sample_fmt;
 frame->sample_rate = audio_codec_ctx->sample_rate;

 ret = av_frame_get_buffer(frame, 0);
 if (ret < 0) {
 fprintf(stderr, "Could not allocate frame buffer\n");
 exit(1);
 }

 // Initialize swresample context
 SwrContext *swr_ctx = swr_alloc();
 av_opt_set_int(swr_ctx, "in_channel_layout", frame->channel_layout, 0);
 av_opt_set_int(swr_ctx, "out_channel_layout", frame->channel_layout, 0);
 av_opt_set_int(swr_ctx, "in_sample_rate", 44100, 0);
 av_opt_set_int(swr_ctx, "out_sample_rate", 44100, 0);
 av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
 av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);

 if (swr_init(swr_ctx) < 0) {
 fprintf(stderr, "Error initializing swresample context\n");
 exit(1);
 }

 // Calculate the number of samples based on buffer size and format
 int num_samples = buffer_size / (2 * channels); // 2 bytes per sample (S16)
 uint8_t *out_buffer = (uint8_t *)malloc(num_samples * 4); // 4 bytes per sample (float)

 // Resample audio data
 ret = swr_convert(swr_ctx, &out_buffer, num_samples, (const uint8_t **)&buffer, num_samples);
 if (ret < 0) {
 fprintf(stderr, "Error during resampling\n");
 exit(1);
 }

 // Copy resampled data to the frame's buffer
 int out_size = num_samples * av_get_bytes_per_sample(audio_codec_ctx->sample_fmt);
 memcpy(frame->data[0], out_buffer, out_size);

 if (frame->data[0] == NULL) {
 fprintf(stderr, "Frame data is NULL\n");
 }

 // Set timestamps for the packet
 pkt.pts = pkt.dts = (frame_count * audio_codec_ctx->frame_size * AV_TIME_BASE) / audio_codec_ctx->sample_rate;
 stream_time += (double)frame->nb_samples / audio_codec_ctx->sample_rate;

 // Send the frame for encoding
 ret = avcodec_send_frame(audio_codec_ctx, frame);
 if (ret < 0) {
 if (ret == AVERROR(EAGAIN)) {
 // Encoder is temporarily unavailable, wait or retry
 fprintf(stderr, "Encoder temporarily unavailable, retrying...\n");
 return;
 } else {
 // Another error occurred
 fprintf(stderr, "Error sending audio frame to encoder: %s\n", av_err2str(ret));
 exit(1);
 }
 }

 // Receive the encoded packet
 ret = avcodec_receive_packet(audio_codec_ctx, &pkt);
 if (ret < 0) {
 if (ret == AVERROR(EAGAIN)) {
 // No packet is available yet, maybe retry later
 fprintf(stderr, "No packet available, retrying...\n");
 return;
 } else {
 fprintf(stderr, "Error encoding audio frame: %s\n", av_err2str(ret));
 exit(1);
 }
 }

 pkt.stream_index = 0;

 // Write the packet to the output
 ret = av_interleaved_write_frame(fmt_ctx, &pkt);
 if (ret < 0) {
 fprintf(stderr, "Error while writing frame\n");
 exit(1);
 }else if (ret==0){

 printf("Writing frames successfully\n");
}

 // Clean up
 av_frame_free(&frame);
 av_packet_unref(&pkt);
 free(out_buffer);

 frame_count++; // Increment the frame count to track timestamps
}




int main() {
 snd_pcm_t *capture_handle;
 snd_pcm_hw_params_t *hw_params;
 int err;
 unsigned int sample_rate = 44100;
 snd_pcm_uframes_t frames = 32;
 char *buffer;
 int buffer_size;

 // Register signal handler for termination (Ctrl+C)
 signal(SIGINT, sigint_handler);

 // Open the PCM device for recording (capture)
 if ((err = snd_pcm_open(&capture_handle, "default", SND_PCM_STREAM_CAPTURE, 0)) < 0) {
 fprintf(stderr, "cannot open audio device %s (%s)\n", "default", snd_strerror(err));
 exit(1);
 }

 // Allocate the hardware parameters structure
 if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) {
 fprintf(stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
 exit(1);
 }

 // Initialize the hardware parameters with default values
 if ((err = snd_pcm_hw_params_any(capture_handle, hw_params)) < 0) {
 fprintf(stderr, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
 exit(1);
 }

 // Set the desired hardware parameters
 if ((err = snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
 fprintf(stderr, "cannot set access type (%s)\n", snd_strerror(err));
 exit(1);
 }

 if ((err = snd_pcm_hw_params_set_format(capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
 fprintf(stderr, "cannot set sample format (%s)\n", snd_strerror(err));
 exit(1);
 }

 if ((err = snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &sample_rate, 0)) < 0) {
 fprintf(stderr, "cannot set sample rate (%s)\n", snd_strerror(err));
 exit(1);
 }

 if ((err = snd_pcm_hw_params_set_channels(capture_handle, hw_params, channels)) < 0) {
 fprintf(stderr, "cannot set channel count (%s)\n", snd_strerror(err));
 exit(1);
 }

 if ((err = snd_pcm_hw_params(capture_handle, hw_params)) < 0) {
 fprintf(stderr, "cannot set parameters (%s)\n", snd_strerror(err));
 exit(1);
 }

 // Free the hardware parameters structure
 snd_pcm_hw_params_free(hw_params);

 // Prepare the PCM device for use
 if ((err = snd_pcm_prepare(capture_handle)) < 0) {
 fprintf(stderr, "cannot prepare audio interface for use (%s)\n", snd_strerror(err));
 exit(1);
 }

 // Calculate buffer size
 buffer_size = frames * channels * 2; // 2 bytes/sample, 2 channels
 buffer = (char *) malloc(buffer_size);

 // Initialize FFmpeg
 av_register_all();

 // Initialize the output file and codec
 AVCodecContext *audio_codec_ctx = NULL;
 AVFormatContext *fmt_ctx = init_ffmpeg_writer("recorded_audio.mp4", &audio_codec_ctx);

 printf("Recording...\n");

 // Record audio data until termination signal is received
 while (!terminate) {
 printf("entered while\n");
 if ((err = snd_pcm_readi(capture_handle, buffer, frames)) != frames) {
 fprintf(stderr, "read from audio interface failed (%s)\n", snd_strerror(err));
 exit(1);
 }

 // Write audio frame to the MP4 file
 write_audio_frame(fmt_ctx, audio_codec_ctx, (uint8_t *)buffer, buffer_size);
 }

 printf("Recording finished.\n");

 // Write the file footer and close
 av_write_trailer(fmt_ctx);
 avcodec_free_context(&audio_codec_ctx);
 avformat_close_input(&fmt_ctx);
 avformat_free_context(fmt_ctx);

 // Clean up ALSA resources
 snd_pcm_close(capture_handle);
 free(buffer);

 return 0;
}



Here I am attaching the logs too


Recording...
entered while
No packet available, retrying...
entered while
[mp4 @ 0x611490ddeb40] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[mp4 @ 0x611490ddeb40] Encoder did not produce proper pts, making some up.
Writing frames successfully
entered while
Writing frames successfully
entered while
Writing frames successfully
entered while
Writing frames successfully



Can anyone help me how to resolve the above error by setting up the timestamp properly and record audio in mp4 file using ALSA .


-
7 Fintech Marketing Strategies to Maximise Profits in 2024
24 juillet 2024, par Erin -
How to make Matomo GDPR compliant in 12 steps
3 avril 2018, par InnoCraftImportant note : this blog post has been written by digital analysts, not lawyers. The purpose of this article is to briefly show you where Matomo is entering into play within the GDPR process. This work comes from our interpretation of the UK privacy commission : ICO. It cannot be considered as professional legal advice. So as GDPR, this information is subject to change. We strongly advise you to have a look at the different privacy authorities in order to have up to date information.
The General Data Protection Regulation (EU) 2016/679, also referred to RGPD in French, Datenschutz-Grundverordnung, DS-GVO in German, is a regulation on data protection and privacy for all individuals within the European Union. It concerns organizations worldwide dealing with EU citizens and will come into force on the 25th May 2018.
The GDPR applies to ‘personal data’ meaning any information relating to an identifiable person who can be directly or indirectly identified in particular by reference to an identifier. It includes cookies, IP addresses, User ID, location, and any other data you may have collected.
We will list below the 12 steps recommended by the UK privacy commissioner in order to be GDPR compliant and what you need to do for each step.
The 12 steps of GDPR compliance according to ICO and how it fit with Matomo
As mentioned in one of our previous blog post about GDPR, if you are not collecting any personal data with Matomo, then you are not concerned about what is written below.
If you are processing personal data in any way, here are the 12 steps to follow along with some recommendations on how to be GDPR compliant with Matomo :
1 – Awareness
Make sure that people within your organization know that you are using Matomo in order to analyze traffic on the website/app. If needed, send them the link to the “What is Matomo ?” page.
2 – Information you hold
List all the personal data you are processing with Matomo within your record of processing activities. We are personally using the template provided by ICO which is composed of a set of 30 questions you need to answer regarding your use of Matomo. We have published an article which walks you through the list of questions specifically in the use case of Matomo Analytics. Please be aware that personal data may be also tracked in non-obvious ways for example as part of page URLs or page titles.
3 – Communicating privacy information
a – Add a privacy notice
Add a privacy notice wherever you are using Matomo in order to collect personal data. Please refer to the ICO documentation in order to learn how to write a privacy notice. You can learn more in our article about creating your privacy notice for Matomo Analytics. Make sure that a privacy policy link is always available on your website or app.
b – Add Matomo to your privacy policy page
Add Matomo to the list of technologies you are using on your privacy policy page and add all the necessary information to it as requested in the following checklist. To learn more check out our article about Privacy policy.
4 – Individuals’ rights
Make sure that your Matomo installation respects all the individuals’ rights. To make it short, you will need to know the features in Matomo that you need to use to respect user rights (right of access, right of rectification, right of erasure…). These features are available starting in Matomo 3.5.0 released on May 8th : GDPR tools for Matomo (User guide).
5 – Subject access requests
Make sure that you are able to answer an access request from a data subject for Matomo. For example, when a person would like to access her or his personal data that you have collected about her or him, then you will need to be you able to provide her or him with this information. We recommend you design a process for this like “Who is dealing with it ?” and check that it is working. If you can answer to the nightmare letter, then you are ready. The needed features for this in Matomo will be available soon.
6 – Lawful basis for processing personal data
There are different lawful basis you can use under GDPR. It can be either “Legitimate interest” or “Explicit consent”. Do not forget to mention it within your privacy policy page. Read more in our article about lawful basis.
7 – Consent
Users should be able to remove their consent at any time. By chance, Matomo is providing a feature in order to do just that : add the opt-out feature to your privacy policy page.
We are also offering a tool that allows you optionally to require consent before any data is tracked. This will be useful if a person should be only tracked after she or he has given explicit consent to be tracked.8 – Children
If your website or app is targeted for children and you are using Matomo, extra measures will need to be taken. For example you will need to write your privacy policy even more clear and moreover getting parents consent if the child is below 13. As it is a very specific case, we strongly recommend you to follow this link for further information.
9 – Data breaches
As you may be collecting personal data with Matomo, you should also check your “data breach procedure” to define if a leak may have consequences on the privacy of the data subject. Please consult ICO’s website for further information.
10 – Data Protection by Design and Data Protection Impact Assessments
Ask yourself if you really need to process personal data within Matomo. If the data you are processing within Matomo is sensitive, we strongly recommend you to make a Data Protection Impact Assessment. A software is available from the The open source PIA software helps to carry out data protection impact assessment, by French Privacy Commissioner : CNIL.
11 – Data Protection Officers
If you are reading this article and you are the Data Protection Officer (DPO), you will not be concerned by this step. If that’s not the case, your duty is to provide to the DPO (if your business has a DPO) our blog post in order for her or him to ask you questions regarding your use of Matomo. Note that your DPO can also be interested in the different data that Matomo can process : “What data does Matomo track ?” (FAQ).
12 – International
Matomo data is hosted wherever you want. So according to the location of the data, you will need to show specific safeguard except for EU. For example regarding the USA, you will have to check if your web hosting platform is registered to the Privacy Shield : privacyshield.gov/list
Note : our Matomo cloud infrastructure is based in France.That’s the end of this blog post. As GDPR is a huge topic, we will release many more blog posts in the upcoming weeks. If there are any Matomo GDPR topic related posts you would like us to write, please feel free to contact us.
The post How to make Matomo GDPR compliant in 12 steps appeared first on Analytics Platform - Matomo.