
Recherche avancée
Médias (1)
-
Richard Stallman et le logiciel libre
19 octobre 2011, par
Mis à jour : Mai 2013
Langue : français
Type : Texte
Autres articles (66)
-
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 -
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs -
Librairies et binaires spécifiques au traitement vidéo et sonore
31 janvier 2010, parLes logiciels et librairies suivantes sont utilisées par SPIPmotion d’une manière ou d’une autre.
Binaires obligatoires FFMpeg : encodeur principal, permet de transcoder presque tous les types de fichiers vidéo et sonores dans les formats lisibles sur Internet. CF ce tutoriel pour son installation ; Oggz-tools : outils d’inspection de fichiers ogg ; Mediainfo : récupération d’informations depuis la plupart des formats vidéos et sonores ;
Binaires complémentaires et facultatifs flvtool2 : (...)
Sur d’autres sites (8029)
-
conversion from cv::mat to avframe, encode in h264 dont writing correctly [on hold]
15 novembre 2014, par danicsi create a method for converting between cv::mat to avframe with PIX_FMT_YUV420P format (oframe format) but _convCtx always return null, whats wrong ? thanks in advance ! ((i solve this)) but i have another probelm in end of this question please
void processToFrame(cv::Mat* _mat, AVFrame* oframe)
{
// Create and allocate the conversion frame.
if (_oframe == nullptr) {
_oframe = avcodec_alloc_frame();
if (_oframe == nullptr)
throw std::runtime_error("Matrix Converter: Could not allocate the output frame.");
avpicture_alloc(reinterpret_cast(_oframe),
PIX_FMT_BGR24, _mat->cols, _mat->rows);
}
avpicture_fill(reinterpret_cast(_oframe),
(uint8_t *)_mat->data,
AV_PIX_FMT_BGR24,
_mat->cols,
_mat->rows);
// Convert the image from its native format to BGR.
if (_convCtx == nullptr) {
_convCtx = sws_getContext(
oframe->width, oframe->height, (enum AVPixelFormat) oframe->format,
_oframe->width, _oframe->height, PIX_FMT_BGR24,
SWS_BICUBIC, nullptr, nullptr, nullptr);
}
if (_convCtx == nullptr)
throw std::runtime_error("Matrix Converter: Unable to initialize the conversion context.");
// Scales the source data according to our SwsContext settings.
if (sws_scale(_convCtx,
_oframe->data, _oframe->linesize, 0, _oframe->height,
oframe->data, oframe->linesize) < 0)
throw std::runtime_error("Matrix Converter: Pixel format conversion not supported.");
}create oframe
void createVideoFile(const char* filename, int w, int h, int codec_id, int fps)
{
/* find the mpeg1 video encoder */
if(codec == nullptr)
{
/* find the mpeg1 video encoder */
codec = avcodec_find_encoder((AVCodecID)codec_id);
if (!codec) {
throw std::runtime_error("codec not found\n");
}
}
if(c == nullptr)
{
c = avcodec_alloc_context3(codec);
if(!c)
{
throw std::runtime_error("Could not allocate video codec context\n");
}
/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 2 * (w / 2);
c->height = 2 * (h / 2);
/* frames per second */
AVRational ar;
ar.den = 1;
ar.num = fps;
c->time_base= ar; //(AVRational){1,25};
c->gop_size = 10; /* emit one intra frame every ten frames */
c->max_b_frames=1;
c->pix_fmt = PIX_FMT_YUV420P;
if(codec_id == AV_CODEC_ID_H264)
av_opt_set(c->priv_data, "preset", "slow", 0);
/* open it */
if (avcodec_open2(c, codec, NULL) < 0) {
throw std::runtime_error("Could not open codec\n");
}
f = fopen(filename, "wb");
if (!f) {
throw std::runtime_error("could not open file\n");
}
frame = avcodec_alloc_frame();
if (!frame) {
throw std::runtime_error("Could not allocate video frame\n");
}
frame->format = c->pix_fmt;
frame->width = c->width;
frame->height = c->height;
/* the image can be allocated by any means and av_image_alloc() is
* just the most convenient way if av_malloc() is to be used */
int ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);
if (ret < 0) {
throw std::runtime_error("Could not allocate raw picture buffer\n");
}
}
}read mat images
void video_encode_example(const cv::Mat& fin)
{
AVPacket pkt;
/* encode 1 second of video */
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
fflush(stdout);
cv::Mat res;
cv::resize(fin, res, cv::Size(c->width, c->height));
processToFrame(&res, frame);
frame->pts = i;
/* encode the image */
int ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
if (ret < 0) {
throw std::runtime_error("Error encoding frame\n");
}
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
}
i++;
}update :
i can solve the conversion problem by setting of _oframe.width = _mat.cols and _oframe.height = _mat.rows, avpicture_alloc dont set this value itself.
now i have the other problem my videowriting class seems write ok because windows slideshow show one of frames, but i cant view video in my players, this is my release function, i dont know whats wrong endcoding or endcoder structure parameter like pts and else.
void video_release()
{
/* get the delayed frames */
for (got_output = 1; got_output; i++) {
fflush(stdout);
int ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
if (ret < 0) {
throw std::runtime_error("Error encoding frame\n");
}
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
}
}
uint8_t endcode[] = { 0, 0, 1, 0xb7 };
/* add sequence end code to have a real mpeg file */
fwrite(endcode, 1, sizeof(endcode), f);
fclose(f);
avcodec_close(c);
av_free(c);
av_freep(&frame->data[0]);
avcodec_free_frame(&frame);
c = nullptr;
codec = nullptr;
frame = nullptr;
if (_convCtx)
sws_freeContext(_convCtx);
if (_oframe) {
//if (_oframe->data)
//av_free(_oframe->data[0]);
av_free(_oframe);
}
_oframe = nullptr;
_convCtx = nullptr;
} -
conversion from cv::mat to avframe
14 novembre 2014, par danicsi create a method for converting between cv::mat to avframe with PIX_FMT_YUV420P format (oframe format) but _convCtx always return null, whats wrong ? thanks in advance !
void processToFrame(cv::Mat* _mat, AVFrame* oframe)
{
// Create and allocate the conversion frame.
if (_oframe == nullptr) {
_oframe = avcodec_alloc_frame();
if (_oframe == nullptr)
throw std::runtime_error("Matrix Converter: Could not allocate the output frame.");
avpicture_alloc(reinterpret_cast(_oframe),
PIX_FMT_BGR24, _mat->cols, _mat->rows);
}
avpicture_fill(reinterpret_cast(_oframe),
(uint8_t *)_mat->data,
AV_PIX_FMT_BGR24,
_mat->cols,
_mat->rows);
// Convert the image from its native format to BGR.
if (_convCtx == nullptr) {
_convCtx = sws_getContext(
oframe->width, oframe->height, (enum AVPixelFormat) oframe->format,
_oframe->width, _oframe->height, PIX_FMT_BGR24,
SWS_BICUBIC, nullptr, nullptr, nullptr);
}
if (_convCtx == nullptr)
throw std::runtime_error("Matrix Converter: Unable to initialize the conversion context.");
// Scales the source data according to our SwsContext settings.
if (sws_scale(_convCtx,
_oframe->data, _oframe->linesize, 0, _oframe->height,
oframe->data, oframe->linesize) < 0)
throw std::runtime_error("Matrix Converter: Pixel format conversion not supported.");
}edit : create oframe
void createVideoFile(const char* filename, int w, int h, int codec_id, int fps)
{
/* find the mpeg1 video encoder */
if(codec == nullptr)
{
/* find the mpeg1 video encoder */
codec = avcodec_find_encoder((AVCodecID)codec_id);
if (!codec) {
throw std::runtime_error("codec not found\n");
}
}
if(c == nullptr)
{
c = avcodec_alloc_context3(codec);
if(!c)
{
throw std::runtime_error("Could not allocate video codec context\n");
}
/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = 2 * (w / 2);
c->height = 2 * (h / 2);
/* frames per second */
AVRational ar;
ar.den = 1;
ar.num = fps;
c->time_base= ar; //(AVRational){1,25};
c->gop_size = 10; /* emit one intra frame every ten frames */
c->max_b_frames=1;
c->pix_fmt = PIX_FMT_YUV420P;
if(codec_id == AV_CODEC_ID_H264)
av_opt_set(c->priv_data, "preset", "slow", 0);
/* open it */
if (avcodec_open2(c, codec, NULL) < 0) {
throw std::runtime_error("Could not open codec\n");
}
f = fopen(filename, "wb");
if (!f) {
throw std::runtime_error("could not open file\n");
}
frame = avcodec_alloc_frame();
if (!frame) {
throw std::runtime_error("Could not allocate video frame\n");
}
frame->format = c->pix_fmt;
frame->width = c->width;
frame->height = c->height;
/* the image can be allocated by any means and av_image_alloc() is
* just the most convenient way if av_malloc() is to be used */
int ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);
if (ret < 0) {
throw std::runtime_error("Could not allocate raw picture buffer\n");
}
}
}read mat images
void video_encode_example(const cv::Mat& fin)
{
AVPacket pkt;
/* encode 1 second of video */
av_init_packet(&pkt);
pkt.data = NULL; // packet data will be allocated by the encoder
pkt.size = 0;
fflush(stdout);
cv::Mat res;
cv::resize(fin, res, cv::Size(c->width, c->height));
processToFrame(&res, frame);
frame->pts = i;
/* encode the image */
int ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
if (ret < 0) {
throw std::runtime_error("Error encoding frame\n");
}
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
}
i++;
/* get the delayed frames */
/*for (got_output = 1; got_output; i++) {
fflush(stdout);
ret = avcodec_encode_video2(c, &pkt, NULL, &got_output);
if (ret < 0) {
throw std::runtime_error("Error encoding frame\n");
}
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
}
}*/
} -
rtpdec_h263_rfc2190 : Clear the stored bits if discarding buffered data
17 décembre 2014, par Martin Storsjörtpdec_h263_rfc2190 : Clear the stored bits if discarding buffered data
If we throw away the buffered incomplete frame, make sure to also
throw away the buffered bits of an incomplete byte at the same
time.CC : libav-stable@libav.org
Signed-off-by : Martin Storsjö <martin@martin.st>