
Advanced search
Medias (2)
-
Valkaama DVD Label
4 October 2011, by
Updated: February 2013
Language: English
Type: Picture
-
Podcasting Legal guide
16 May 2011, by
Updated: May 2011
Language: English
Type: Text
Other articles (84)
-
Websites made with MediaSPIP
2 May 2011, byThis page lists some websites based on MediaSPIP.
-
Ajouter des informations spécifiques aux utilisateurs et autres modifications de comportement liées aux auteurs
12 April 2011, byLa manière la plus simple d’ajouter des informations aux auteurs est d’installer le plugin Inscription3. Il permet également de modifier certains comportements liés aux utilisateurs (référez-vous à sa documentation pour plus d’informations).
Il est également possible d’ajouter des champs aux auteurs en installant les plugins champs extras 2 et Interface pour champs extras. -
Possibilité de déploiement en ferme
12 April 2011, byMediaSPIP peut être installé comme une ferme, avec un seul "noyau" hébergé sur un serveur dédié et utilisé par une multitude de sites différents.
Cela permet, par exemple : de pouvoir partager les frais de mise en œuvre entre plusieurs projets / individus; de pouvoir déployer rapidement une multitude de sites uniques; d’éviter d’avoir à mettre l’ensemble des créations dans un fourre-tout numérique comme c’est le cas pour les grandes plate-formes tout public disséminées sur le (...)
On other websites (17960)
-
Anomalie #4357 (Fermé): page ’contact.html’ différente ?
27 June 2019, by AnonymeAppliqué par commit r115799.
-
Anomalie #4268: Désélectionner un article choisi préalablement par le sélecteur d’article
10 January 2019, by chan kalanPar exemple dans le squelette Editorial, le paramétrage propose de choisir un article "héro" pour le mettre en avant sur l’accueil en utilisant le sélecteur d’article :
[(#SAISIEselecteur_article, hero,
label=<:html5up:hero:>,
explication=<:html5up:hero_explications:>)]Ce qui appelle le fichier cité ci-dessus...
-
How to save video data in a vector using ffmpeg? (C++)
25 October 2022, by noklaI'm new to ffmpeg and I am trying to write a program for video editing.


I want to import a video file and save it somehow in a vector so I could edit its frames later.
When I saved all the decoded AVFrames in a vector I saw it takes a lot of memory and that I need to find a better way to do so.


The function I used for reading a video:


** the function is in a class that representing video,
source
type isstd::vector<avframe></avframe>


void VideoSource::ReadSource(std::string path)
{
 // Open the file using libavformat
 AVFormatContext* av_format_ctx = avformat_alloc_context();
 if (!av_format_ctx) {
 printf("Couldn't create AVFormatContext\n");
 return; 
 }
 if (avformat_open_input(&av_format_ctx, path.c_str(), NULL, NULL) != 0) {
 printf("Couldn't open video file\n");
 return;
 }

 // Find the first valid video stream inside the file
 int video_stream_index = -1;
 AVCodecParameters* av_codec_params = NULL;
 const AVCodec* av_codec = NULL;
 for (int i = 0; i < av_format_ctx->nb_streams; i)
 {
 av_codec_params = av_format_ctx->streams[i]->codecpar;
 av_codec = avcodec_find_decoder(av_codec_params->codec_id);

 if (!av_codec) {
 continue;
 }
 if (av_codec_params->codec_type == AVMEDIA_TYPE_VIDEO) {
 video_stream_index = i;
 break;
 }
 }

 if (video_stream_index == -1) {
 printf("Couldn't find valid video stream inside file\n");
 return;
 }

 // Set up a codec context for the decoder
 AVCodecContext* av_codec_ctx = avcodec_alloc_context3(av_codec);
 if (!av_codec_ctx) {
 printf("Couldn't create AVCpdecContext\n");
 return;
 }

 if (avcodec_parameters_to_context(av_codec_ctx, av_codec_params) < 0)
 {
 printf("Couldn't initialize AVCodecContext\n");
 return;
 }
 if (avcodec_open2(av_codec_ctx, av_codec, NULL) < 0) {
 printf("Couldn't open codec\n");
 return;
 }

 AVFrame* av_frame = av_frame_alloc();
 if (!av_frame) {
 printf("Couldn't allocate AVFrame\n");
 return;
 }
 AVPacket* av_packet = av_packet_alloc();
 if (!av_packet) {
 printf("Couldn't allocate AVPacket\n");
 return;
 }
 int response;

 while (av_read_frame(av_format_ctx, av_packet) >= 0) {
 if (av_packet->stream_index != video_stream_index) {
 av_packet_unref(av_packet);
 continue;
 }
 response = avcodec_send_packet(av_codec_ctx, av_packet);
 if (response < 0) {
 printf("Failed to decode packet: %s\n", av_err2str(response));
 return;
 }
 response = avcodec_receive_frame(av_codec_ctx, av_frame);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {
 av_packet_unref(av_packet);
 continue;
 }
 else if (response < 0) {
 printf("Failed to decode frame: %s\n", av_err2str(response));
 return;
 }
 av_packet_unref(av_packet);

 av_packet = av_packet_alloc();

 // response = avcodec_send_frame(av_codec_ctx, av_frame);

 source.push_back(*new AVFrame);
 source.back() = *av_frame_clone(av_frame);

 av_frame_unref(av_frame);
 }
 

 avformat_close_input(&av_format_ctx);
 avformat_free_context(av_format_ctx);
 av_frame_free(&av_frame);
 av_packet_free(&av_packet);
 avcodec_free_context(&av_codec_ctx);
}



I thought maybe I should save it as a vector of encoded AVFrames or as a vector of encoded packet that contains some frames in it.


When I tried to encode a single AVFrame, I added this line

response = avcodec_send_frame(av_codec_ctx, av_frame);
before pushing the frame into the vector (You can see it marked as a comment in the code above).

It returned invalid argument (-22) and I am not sure why.

Questions:


- 

- Why did I get that error (-22)?
- How to save an encoded packet with multiple AVFrame in it?
- Is there a better way of working on a video that won't take as much memory?