
Recherche avancée
Médias (91)
-
Head down (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
Echoplex (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
Discipline (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
Letting you (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
1 000 000 (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
-
999 999 (wav version)
26 septembre 2011, par
Mis à jour : Avril 2013
Langue : English
Type : Audio
Autres articles (51)
-
Organiser par catégorie
17 mai 2013, parDans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...) -
Encoding and processing into web-friendly formats
13 avril 2011, parMediaSPIP automatically converts uploaded files to internet-compatible formats.
Video files are encoded in MP4, Ogv and WebM (supported by HTML5) and MP4 (supported by Flash).
Audio files are encoded in MP3 and Ogg (supported by HTML5) and MP3 (supported by Flash).
Where possible, text is analyzed in order to retrieve the data needed for search engine detection, and then exported as a series of image files.
All uploaded files are stored online in their original format, so you can (...) -
MediaSPIP Core : La Configuration
9 novembre 2010, parMediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)
Sur d’autres sites (7361)
-
How to encode h264/hevc in real time with ffmpeg AMF, without delay ?
26 septembre 2023, par 21pagesamf encoding will delay one frame, I added the option but it doesn't work.

av_opt_set(codec_ctx->priv_data, "usage", "ultralowlatency", 0)


doc of
AMF Video Encode SDK
says :

In the Transcoding mode the encoder needs to accept at least 3 input frames before any output is produced. In low
latency modes output becomes available as soon as the first submitted frame is encoded.


-
How to estimate bandwidth / speed requirements for real-time streaming video ?
19 juin 2016, par Vivek SethFor a project I’m working on, I’m trying to stream video to an iPhone through its headphone jack. My estimated bitrate is about 200kbps (If i’m wrong about this, please ignore that).
I’d like to squeeze as much performance out of this bitrate as possible and sound is not important for me, only video. My understanding is that to stream a a real-time video I will need to encode it with some codec on-the-fly and send compressed frames to the iPhone for it to decode and render. Based on my research, it seems that H.265 is one of the most space efficient codecs available so i’m considering using that.
Assuming my basic understanding of live streaming is correct, how would I estimate the FPS I could achieve for a given resolution using the H.265 codec ?
The best solution I can think of it to take a video file, encode it with H.265 and trim it to 1 minute of length to see how large the file is. The issue I see with this approach is that I think my calculations would include some overhead from the video container format (AVI, MKV, etc) and from the audio channels that I don’t care about.
-
Capture and encode desktop with libav in real time not giving corect images
3 septembre 2022, par thoxeyAs part of a larger project I want to be able to capture and encode the desktop frame by frame in real time. I have the following test code to reproduce the issue shown in the screenshot :


#include 
#include 
#include <iostream>
#include <fstream>
#include <string>
#include 
#include 

extern "C"
{
#include "libavdevice/avdevice.h"
#include "libavutil/channel_layout.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
}


/* 5 seconds stream duration */
#define STREAM_DURATION 5.0
#define STREAM_FRAME_RATE 25 /* 25 images/s */
#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */

int videoStreamIndx;
int framerate = 30;

int width = 1920;
int height = 1080;

int encPacketCounter;

AVFormatContext* ifmtCtx;
AVCodecContext* avcodecContx;
AVFormatContext* ofmtCtx;
AVStream* videoStream;
AVCodecContext* avCntxOut;
AVPacket* avPkt;
AVFrame* avFrame;
AVFrame* outFrame;
SwsContext* swsCtx;

std::ofstream fs;


AVDictionary* ConfigureScreenCapture()
{

 AVDictionary* options = NULL;
 //Try adding "-rtbufsize 100M" as in https://stackoverflow.com/questions/6766333/capture-windows-screen-with-ffmpeg
 av_dict_set(&options, "rtbufsize", "100M", 0);
 av_dict_set(&options, "framerate", std::to_string(framerate).c_str(), 0);
 char buffer[16];
 sprintf(buffer, "%dx%d", width, height);
 av_dict_set(&options, "video_size", buffer, 0);
 return options;
}

AVCodecParameters* ConfigureAvCodec()
{
 AVCodecParameters* av_codec_par_out = avcodec_parameters_alloc();
 av_codec_par_out->width = width;
 av_codec_par_out->height = height;
 av_codec_par_out->bit_rate = 40000;
 av_codec_par_out->codec_id = AV_CODEC_ID_H264; //AV_CODEC_ID_MPEG4; //Try H.264 instead of MPEG4
 av_codec_par_out->codec_type = AVMEDIA_TYPE_VIDEO;
 av_codec_par_out->format = 0;
 return av_codec_par_out;
}

int GetVideoStreamIndex()
{
 int VideoStreamIndx = -1;
 avformat_find_stream_info(ifmtCtx, NULL);
 /* find the first video stream index . Also there is an API available to do the below operations */
 for (int i = 0; i < (int)ifmtCtx->nb_streams; i++) // find video stream position/index.
 {
 if (ifmtCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 {
 VideoStreamIndx = i;
 break;
 }
 }

 if (VideoStreamIndx == -1)
 {
 }

 return VideoStreamIndx;
}

void CreateFrames(AVCodecParameters* av_codec_par_in, AVCodecParameters* av_codec_par_out)
{

 avFrame = av_frame_alloc();
 avFrame->width = avcodecContx->width;
 avFrame->height = avcodecContx->height;
 avFrame->format = av_codec_par_in->format;
 av_frame_get_buffer(avFrame, 0);

 outFrame = av_frame_alloc();
 outFrame->width = avCntxOut->width;
 outFrame->height = avCntxOut->height;
 outFrame->format = av_codec_par_out->format;
 av_frame_get_buffer(outFrame, 0);
}

bool Init()
{
 AVCodecParameters* avCodecParOut = ConfigureAvCodec();

 AVDictionary* options = ConfigureScreenCapture();

 AVInputFormat* ifmt = av_find_input_format("gdigrab");
 auto ifmtCtxLocal = avformat_alloc_context();
 if (avformat_open_input(&ifmtCtxLocal, "desktop", ifmt, &options) < 0)
 {
 return false;
 }
 ifmtCtx = ifmtCtxLocal;

 videoStreamIndx = GetVideoStreamIndex();

 AVCodecParameters* avCodecParIn = avcodec_parameters_alloc();
 avCodecParIn = ifmtCtx->streams[videoStreamIndx]->codecpar;

 AVCodec* avCodec = avcodec_find_decoder(avCodecParIn->codec_id);
 if (avCodec == NULL)
 {
 return false;
 }

 avcodecContx = avcodec_alloc_context3(avCodec);
 if (avcodec_parameters_to_context(avcodecContx, avCodecParIn) < 0)
 {
 return false;
 }

 //av_dict_set
 int value = avcodec_open2(avcodecContx, avCodec, NULL); //Initialize the AVCodecContext to use the given AVCodec.
 if (value < 0)
 {
 return false;
 }

 AVOutputFormat* ofmt = av_guess_format("h264", NULL, NULL);

 if (ofmt == NULL)
 {
 return false;
 }

 auto ofmtCtxLocal = avformat_alloc_context();
 avformat_alloc_output_context2(&ofmtCtxLocal, ofmt, NULL, NULL);
 if (ofmtCtxLocal == NULL)
 {
 return false;
 }
 ofmtCtx = ofmtCtxLocal;

 AVCodec* avCodecOut = avcodec_find_encoder(avCodecParOut->codec_id);
 if (avCodecOut == NULL)
 {
 return false;
 }

 videoStream = avformat_new_stream(ofmtCtx, avCodecOut);
 if (videoStream == NULL)
 {
 return false;
 }

 avCntxOut = avcodec_alloc_context3(avCodecOut);
 if (avCntxOut == NULL)
 {
 return false;
 }

 if (avcodec_parameters_copy(videoStream->codecpar, avCodecParOut) < 0)
 {
 return false;
 }

 if (avcodec_parameters_to_context(avCntxOut, avCodecParOut) < 0)
 {
 return false;
 }

 avCntxOut->gop_size = 30; //3; //Use I-Frame frame every 30 frames.
 avCntxOut->max_b_frames = 0;
 avCntxOut->time_base.num = 1;
 avCntxOut->time_base.den = framerate;

 //avio_open(&ofmtCtx->pb, "", AVIO_FLAG_READ_WRITE);

 if (avformat_write_header(ofmtCtx, NULL) < 0)
 {
 return false;
 }

 value = avcodec_open2(avCntxOut, avCodecOut, NULL); //Initialize the AVCodecContext to use the given AVCodec.
 if (value < 0)
 {
 return false;
 }

 if (avcodecContx->codec_id == AV_CODEC_ID_H264)
 {
 av_opt_set(avCntxOut->priv_data, "preset", "ultrafast", 0);
 av_opt_set(avCntxOut->priv_data, "zerolatency", "1", 0);
 av_opt_set(avCntxOut->priv_data, "tune", "ull", 0);
 }

 if ((ofmtCtx->oformat->flags & AVFMT_GLOBALHEADER) != 0)
 {
 avCntxOut->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 }

 CreateFrames(avCodecParIn, avCodecParOut);

 swsCtx = sws_alloc_context();
 if (sws_init_context(swsCtx, NULL, NULL) < 0)
 {
 return false;
 }

 swsCtx = sws_getContext(avcodecContx->width, avcodecContx->height, avcodecContx->pix_fmt,
 avCntxOut->width, avCntxOut->height, avCntxOut->pix_fmt, SWS_FAST_BILINEAR,
 NULL, NULL, NULL);
 if (swsCtx == NULL)
 {
 return false;
 }

 return true;
}

void Encode(AVCodecContext* enc_ctx, AVFrame* frame, AVPacket* pkt)
{
 int ret;

 /* send the frame to the encoder */
 ret = avcodec_send_frame(enc_ctx, frame);
 if (ret < 0)
 {
 return;
 }

 while (ret >= 0)
 {
 ret = avcodec_receive_packet(enc_ctx, pkt);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
 return;
 if (ret < 0)
 {
 return;
 }

 fs.write((char*)pkt->data, pkt->size);
 av_packet_unref(pkt);
 }
}

void EncodeFrames(int noFrames)
{
 int frameCount = 0;
 avPkt = av_packet_alloc();
 AVPacket* outPacket = av_packet_alloc();
 encPacketCounter = 0;

 while (av_read_frame(ifmtCtx, avPkt) >= 0)
 {
 if (frameCount++ == noFrames)
 break;
 if (avPkt->stream_index != videoStreamIndx) continue;

 avcodec_send_packet(avcodecContx, avPkt);

 if (avcodec_receive_frame(avcodecContx, avFrame) >= 0) // Frame successfully decoded :)
 {
 outPacket->data = NULL; // packet data will be allocated by the encoder
 outPacket->size = 0;

 outPacket->pts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);
 if (outPacket->dts != AV_NOPTS_VALUE)
 outPacket->dts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);

 outPacket->dts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);
 outPacket->duration = av_rescale_q(1, avCntxOut->time_base, videoStream->time_base);

 outFrame->pts = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);
 outFrame->pkt_duration = av_rescale_q(encPacketCounter, avCntxOut->time_base, videoStream->time_base);
 encPacketCounter++;

 int sts = sws_scale(swsCtx,
 avFrame->data, avFrame->linesize, 0, avFrame->height,
 outFrame->data, outFrame->linesize);

 /* make sure the frame data is writable */
 auto ret = av_frame_make_writable(outFrame);
 if (ret < 0)
 break;
 Encode(avCntxOut, outFrame, outPacket);
 }
 av_frame_unref(avFrame);
 av_packet_unref(avPkt);
 }
}

void Dispose()
{
 fs.close();

 auto ifmtCtxLocal = ifmtCtx;
 avformat_close_input(&ifmtCtx);
 avformat_free_context(ifmtCtx);
 avcodec_free_context(&avcodecContx);

}

int main(int argc, char** argv)
{
 avdevice_register_all();

 fs.open("out.h264");

 if (Init())
 {
 EncodeFrames(300);
 }
 else
 {
 std::cout << "Failed to Init \n";
 } 

 Dispose();

 return 0;
}
</string></fstream></iostream>


As far as I can tell the setup of the encoding process is correct as it is largely unchanged from how the example given in the official documentation is working : https://libav.org/documentation/doxygen/master/encode__video_8c_source.html


However there is limited documentation around the desktop capture online so I am not sure if I have set that up correctly.