
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 (55)
-
La sauvegarde automatique de canaux SPIP
1er avril 2010, parDans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...) -
Les vidéos
21 avril 2011, parComme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...) -
Les formats acceptés
28 janvier 2010, parLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...)
Sur d’autres sites (5342)
-
Updated version number.
3 avril 2012, par Sebastian Tschanm server/php/upload.class.php Updated version number.
-
Create an audio file and fill it with the RTP package payload using ffmpeg
24 août 2020, par WithoutExperienceMy task is to extract the payload of an
RTP
packet and save it as an audio file. In my case, I get the payload type - 8 (PCMA). I processRTP
packets and store all the payload in a separate buffer. After that, I have to process this buffer and create an audio file. And that's my problem :(

First, the specification says that in payload 8 (PCMA), audio samples are U8(bitRate / clockRate = 64000 / 8000) in size. But I can't even find a decoder for this sample size. What might be the problem ?


Second, if I create synthetic sound, I can't record it in mka audio format.


As a cheat sheet, I use this link.


Based on this example, I wrote something similar :



class AudioGenerater
{
public:

 enum AudioFormatType
 {
 AudioFormat_WAV,
 AudioFormat_MP3
 };

public:

 AudioGenerater();
 ~AudioGenerater() = default;

 void generateAudioFileWithOptions(
 QString fileName,
 QByteArray pcmData,
 AVCodecID codecID,
 int channel,
 int bitRate,
 int sampleRate,
 AVSampleFormat format);

private:

 // init Format
 bool initFormat(QString audioFileName);

private:

 AVCodec *m_AudioCodec = nullptr;
 AVCodecContext *m_AudioCodecContext = nullptr;
 AVFormatContext *m_FormatContext = nullptr;
 AVOutputFormat *m_OutputFormat = nullptr;
};




Cpp file :


AudioGenerater::AudioGenerater()
{
 av_register_all();
 avcodec_register_all();
}

bool AudioGenerater::initFormat(QString audioFileName)
{
 // Create an output Format context
 int result = avformat_alloc_output_context2(&m_FormatContext, nullptr, nullptr, audioFileName.toLocal8Bit().data());
 if (result < 0) {
 return false;
 }

 m_OutputFormat = m_FormatContext->oformat;

 // Create an audio stream
 AVStream *audioStream = avformat_new_stream(m_FormatContext, m_AudioCodec);
 if (audioStream == nullptr) {
 avformat_free_context(m_FormatContext);
 return false;
 }

 // Set the parameters in the stream
 audioStream->id = m_FormatContext->nb_streams - 1;
 audioStream->time_base = { 1, 64000 };
 result = avcodec_parameters_from_context(audioStream->codecpar, m_AudioCodecContext);
 if (result < 0) {
 avformat_free_context(m_FormatContext);
 return false;
 }

 // Print FormatContext information
 av_dump_format(m_FormatContext, 0, audioFileName.toLocal8Bit().data(), 1);

 // Open file IO
 if (!(m_OutputFormat->flags & AVFMT_NOFILE)) {
 result = avio_open(&m_FormatContext->pb, audioFileName.toLocal8Bit().data(), AVIO_FLAG_WRITE);
 if (result < 0) {
 avformat_free_context(m_FormatContext);
 return false;
 }
 }

 return true;
}

void AudioGenerater::generateAudioFileWithOptions(
 QString _fileName,
 QByteArray _pcmData,
 AVCodecID _codecID,
 int _channel,
 int _bitRate,
 int _sampleRate,
 AVSampleFormat _format)
{
 AVCodecID codecID = _codecID;
 // Find Codec
 m_AudioCodec = avcodec_find_encoder(codecID);
 if (m_AudioCodec == nullptr) {
 return;
 }

 // Create an encoder context
 m_AudioCodecContext = avcodec_alloc_context3(m_AudioCodec);
 if (m_AudioCodecContext == nullptr){
 return;
 }

 // Setting parameters
 m_AudioCodecContext->bit_rate = _bitRate;
 m_AudioCodecContext->sample_rate = _sampleRate;
 m_AudioCodecContext->sample_fmt = _format;
 m_AudioCodecContext->channels = _channel;


 m_AudioCodecContext->channel_layout = av_get_default_channel_layout(_channel);
 m_AudioCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

 // Turn on the encoder
 int result = avcodec_open2(m_AudioCodecContext, m_AudioCodec, nullptr);
 if (result < 0) {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }

 // Create a package
 if (!initFormat(_fileName)) {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }

 // write to the file header
 result = avformat_write_header(m_FormatContext, nullptr);
 if (result < 0) {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }

 // Create Frame
 AVFrame *frame = av_frame_alloc();
 if (frame == nullptr) {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }

 int nb_samples = 0;
 if (m_AudioCodecContext->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) {
 nb_samples = 10000;
 }
 else {
 nb_samples = m_AudioCodecContext->frame_size;
 }

 // Set the parameters of the Frame
 frame->nb_samples = nb_samples;
 frame->format = m_AudioCodecContext->sample_fmt;
 frame->channel_layout = m_AudioCodecContext->channel_layout;

 // Apply for data memory
 result = av_frame_get_buffer(frame, 0);
 if (result < 0)
 {
 av_frame_free(&frame); {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }
 }

 // Set the Frame to be writable
 result = av_frame_make_writable(frame);
 if (result < 0)
 {
 av_frame_free(&frame); {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }
 }

 int perFrameDataSize = frame->linesize[0];
 int count = _pcmData.size() / perFrameDataSize;
 bool needAddOne = false;
 if (_pcmData.size() % perFrameDataSize != 0)
 {
 count++;
 needAddOne = true;
 }

 int frameCount = 0;
 for (int i = 0; i < count; ++i)
 {
 // Create a Packet
 AVPacket *pkt = av_packet_alloc();
 if (pkt == nullptr) {
 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
 return;
 }
 av_init_packet(pkt);

 if (i == count - 1)
 perFrameDataSize = _pcmData.size() % perFrameDataSize;

 // Synthesize WAV files
 memset(frame->data[0], 0, perFrameDataSize);
 memcpy(frame->data[0], &(_pcmData.data()[perFrameDataSize * i]), perFrameDataSize);


 frame->pts = frameCount++;
 // send Frame
 result = avcodec_send_frame(m_AudioCodecContext, frame);
 if (result < 0)
 continue;

 // Receive the encoded Packet
 result = avcodec_receive_packet(m_AudioCodecContext, pkt);
 if (result < 0)
 {
 av_packet_free(&pkt);
 continue;
 }

 // write to file
 av_packet_rescale_ts(pkt, m_AudioCodecContext->time_base, m_FormatContext->streams[0]->time_base);
 pkt->stream_index = 0;
 result = av_interleaved_write_frame(m_FormatContext, pkt);
 if (result < 0)
 continue;

 av_packet_free(&pkt);
 }

 // write to the end of the file
 av_write_trailer(m_FormatContext);
 // Close file IO
 avio_closep(&m_FormatContext->pb);
 // Release Frame memory
 av_frame_free(&frame);

 avcodec_free_context(&m_AudioCodecContext);
 if (m_FormatContext != nullptr)
 avformat_free_context(m_FormatContext);
}



Main :


int main(int argc, char *argv[])
{
 QCoreApplication a(argc, argv);
 AudioGenerater generator;
 
 av_log_set_level(AV_LOG_DEBUG);
 av_log_set_flags(av_log_get_flags());
 
 QFile file("pcma.raw");
 if (!file.open(QIODevice::ReadOnly)) {
 return EXIT_FAILURE;
 }
 QByteArray pcmaData(file.readAll());
 
 generator.generateAudioFileWithOptions(
 "test.mka",
 pcmaData,
 AV_CODEC_ID_PCM_ALAW,
 1, 64000, 8000,
 AV_SAMPLE_FMT_U8);

 return a.exec();
}




After I run the program, here are the errors that come out :


[pcm_alaw @ 0x19229a0] Specified sample format u8 is invalid or not supported



But if I set s16p instead of U8 format :


generator.generateAudioFileWithOptions(
 "test.mka",
 pcmaData,
 AV_CODEC_ID_PCM_ALAW,
 1, 64000, 8000,
 AV_SAMPLE_FMT_S16P);



I get twice as fast audio track, with a lot of noise. I need a sequential instruction encoding raw audio data into an audio file. Unfortunately, I don't understand what my error is.


-
Identify a specific frame number of a video file
23 février 2017, par James CramptonI have a video file from which I’ve extracted a specific frame to analyze. However, I want to know what the frame number of this frame is.
I can’t seem to find anything. I’ve had a look atffmpeg showinfo
, but that doesn’t seem to work.
I’ve also looked intoexifread
, which produced information about the frame - except for the frame number.Any ideas ?