
Recherche avancée
Médias (91)
-
MediaSPIP Simple : futur thème graphique par défaut ?
26 septembre 2013, par
Mis à jour : Octobre 2013
Langue : français
Type : Video
-
avec chosen
13 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
sans chosen
13 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
config chosen
13 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
SPIP - plugins - embed code - Exemple
2 septembre 2013, par
Mis à jour : Septembre 2013
Langue : français
Type : Image
-
GetID3 - Bloc informations de fichiers
9 avril 2013, par
Mis à jour : Mai 2013
Langue : français
Type : Image
Autres articles (111)
-
MediaSPIP 0.1 Beta version
25 avril 2011, parMediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
The zip file provided here only contains the sources of MediaSPIP in its standalone version.
To get a working installation, you must manually install all-software dependencies on the server.
If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...) -
Multilang : améliorer l’interface pour les blocs multilingues
18 février 2011, parMultilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela. -
HTML5 audio and video support
13 avril 2011, parMediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
For older browsers the Flowplayer flash fallback is used.
MediaSPIP allows for media playback on major mobile platforms with the above (...)
Sur d’autres sites (10061)
-
avformat_write_header() function call crashed when I try to save several RGB data to a output.mp4 file
1er mai 2023, par ollydbg23I try to save several image data(in memory, with BGR format) to a output.mp4 file, here is the C++ code to call the ffmpeg library, the code builds correctly, but will crash when I call the
ret = avformat_write_header(outFormatCtx, nullptr);
, do you know how to solve this crash issue ?

Thanks.


#include <iostream>
#include <vector>
#include <cstring>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <opencv2></opencv2>opencv.hpp>
extern "C" {
#include <libavutil></libavutil>imgutils.h>
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>opt.h>
}

using namespace std;
using namespace cv;

int main()
{
 // Set up input frames as BGR byte arrays
 vector<mat> frames;

 int width = 640;
 int height = 480;
 int num_frames = 100;
 Scalar black(0, 0, 0);
 Scalar white(255, 255, 255);
 int font = FONT_HERSHEY_SIMPLEX;
 double font_scale = 1.0;
 int thickness = 2;

 for (int i = 0; i < num_frames; i++) {
 Mat frame = Mat::zeros(height, width, CV_8UC3);
 putText(frame, std::to_string(i), Point(width / 2 - 50, height / 2), font, font_scale, white, thickness);
 frames.push_back(frame);
 }


 // Populate frames with BGR byte arrays

 // Initialize FFmpeg
 //av_register_all();

 // Set up output file
 AVFormatContext* outFormatCtx = nullptr;
 //AVCodec* outCodec = nullptr;
 AVCodecContext* outCodecCtx = nullptr;
 //AVStream* outStream = nullptr;
 AVPacket outPacket;

 const char* outFile = "output.mp4";
 int outWidth = frames[0].cols;
 int outHeight = frames[0].rows;
 int fps = 30;

 // Open output file
 avformat_alloc_output_context2(&outFormatCtx, nullptr, nullptr, outFile);
 if (!outFormatCtx) {
 cerr << "Error: Could not allocate output format context" << endl;
 return -1;
 }

 // Set up output codec
 const AVCodec* outCodec = avcodec_find_encoder(AV_CODEC_ID_H264);
 if (!outCodec) {
 cerr << "Error: Could not find H.264 codec" << endl;
 return -1;
 }

 outCodecCtx = avcodec_alloc_context3(outCodec);
 if (!outCodecCtx) {
 cerr << "Error: Could not allocate output codec context" << endl;
 return -1;
 }
 outCodecCtx->codec_id = AV_CODEC_ID_H264;
 outCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
 outCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
 outCodecCtx->width = outWidth;
 outCodecCtx->height = outHeight;
 outCodecCtx->time_base = { 1, fps };

 // Open output codec
 if (avcodec_open2(outCodecCtx, outCodec, nullptr) < 0) {
 cerr << "Error: Could not open output codec" << endl;
 return -1;
 }

 // Create output stream
 AVStream* outStream = avformat_new_stream(outFormatCtx, outCodec);
 if (!outStream) {
 cerr << "Error: Could not allocate output stream" << endl;
 return -1;
 }

 // Configure output stream parameters (e.g., time base, codec parameters, etc.)
 // ...

 // Connect output stream to format context
 outStream->codecpar->codec_id = outCodecCtx->codec_id;
 outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
 outStream->codecpar->width = outCodecCtx->width;
 outStream->codecpar->height = outCodecCtx->height;
 outStream->codecpar->format = outCodecCtx->pix_fmt;
 outStream->time_base = outCodecCtx->time_base;

 int ret = avcodec_parameters_from_context(outStream->codecpar, outCodecCtx);
 if (ret < 0) {
 cerr << "Error: Could not copy codec parameters to output stream" << endl;
 return -1;
 }

 outStream->avg_frame_rate = outCodecCtx->framerate;
 outStream->id = outFormatCtx->nb_streams++;


 ret = avformat_write_header(outFormatCtx, nullptr);
 if (ret < 0) {
 cerr << "Error: Could not write output header" << endl;
 return -1;
 }

 // Convert frames to YUV format and write to output file
 for (const auto& frame : frames) {
 AVFrame* yuvFrame = av_frame_alloc();
 if (!yuvFrame) {
 cerr << "Error: Could not allocate YUV frame" << endl;
 return -1;
 }
 av_image_alloc(yuvFrame->data, yuvFrame->linesize, outWidth, outHeight, AV_PIX_FMT_YUV420P, 32);

 // Convert BGR frame to YUV format
 Mat yuvMat;
 cvtColor(frame, yuvMat, COLOR_BGR2YUV_I420);
 memcpy(yuvFrame->data[0], yuvMat.data, outWidth * outHeight);
 memcpy(yuvFrame->data[1], yuvMat.data + outWidth * outHeight, outWidth * outHeight / 4);
 memcpy(yuvFrame->data[2], yuvMat.data + outWidth * outHeight * 5 / 4, outWidth * outHeight / 4);

 // Set up output packet
 av_init_packet(&outPacket);
 outPacket.data = nullptr;
 outPacket.size = 0;

 // Encode frame and write to output file
 int ret = avcodec_send_frame(outCodecCtx, yuvFrame);
 if (ret < 0) {
 cerr << "Error: Could not send frame to output codec" << endl;
 return -1;
 }
 while (ret >= 0) {
 ret = avcodec_receive_packet(outCodecCtx, &outPacket);
 if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
 break;
 } else if (ret < 0) {
 cerr << "Error: Could not receive packet from output codec" << endl;
 return -1;
 }

 av_packet_rescale_ts(&outPacket, outCodecCtx->time_base, outStream->time_base);
 outPacket.stream_index = outStream->index;

 ret = av_interleaved_write_frame(outFormatCtx, &outPacket);
 if (ret < 0) {
 cerr << "Error: Could not write packet to output file" << endl;
 return -1;
 }
 }

 av_frame_free(&yuvFrame);
 }

 // Write output trailer
 av_write_trailer(outFormatCtx);

 // Clean up
 avcodec_close(outCodecCtx);
 avcodec_free_context(&outCodecCtx);
 avformat_free_context(outFormatCtx);

 return 0;
}
</mat></stdexcept></sstream></fstream></cstring></vector></iostream>


In-fact, I try to solve my original question here : What is the best way to save an image sequence with different time intervals in a simgle file in C++, but in that discussion, it is difficult to write a c++ code for ffmpeg library.


-
ffmpeg wont "gracefully" terminate using q or kill -2
24 mai 2023, par Jeff ThompsonI am trying to run a bash command on Ubuntu to pull video from a stream and make an .mp4 with it. Here is the command I am using.


ffmpeg -rtsp_transport tcp -i 'rtsp://username:password!@ipaddress/?inst=1' -c copy -f segment -segment_time 180 -reset_timestamps 1 ipaddress_day_3_2_%d.mp4


It connects and begins copying the stream fine, the issue comes with trying to stop the process. It states press [q] to stop, which does not work. I have also tried kill -2 pid and kill -15 pid. Where pid is the process id. However kill -9 pid works and ctrl+c works. The issue with killing it this way is it corrupts the .mp4 rendering it useless. This is the error I get when using ctrl+c or kill -9.


av_interleaved_write_frame(): Immediate exit requested [segment @ 0x56337ec42980] Failure occurred when ending segment 'ipaddress_day_3_2_0.mp4' Error writing trailer of ipaddress_day_3_2_0%d.mp4: Immediate exit requested


One thing to note is pressing [q] did work once, when I first started working on this but has not since.


Thank You.


I have tried kill -2 pid, kill -15 pid and [q], which I expected to "gracefully" terminate it.
kill -9 pid and ctrl+c will forcefully terminate it but corrupt the file.


-
How to modify the bit_rate of AVFormatContext ?
27 mars 2023, par Zion LiuHello,I would like to know how to modify the bit_rate of AVFormatContext.


Here is the minimal reproducible example.This is a simple process for pushing rtmp video streams.Now I want to control the bitrate of the video it pushes.


I tried modifying the bitrate like this, but it didn't work.


AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
int64_t bit_rate = 400*1000;
....
ofmt_ctx->bit_rate = bit_rate;



Can be compiled by
g++ -Wall -o -g -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/include -L/usr/local/lib simplt_push_streaming.cpp -o test.out -lavformat -lavcodec -lavutil -lgobject-2.0 -lglib-2.0 -lpthread


And my ffmpeg version :
ffmpeg version 4.4.2-0ubuntu0.22.04.1


#include 
extern "C"
{
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>mathematics.h>
#include <libavutil></libavutil>time.h>
};

int main(int argc, char* argv[])
{
 AVOutputFormat *ofmt = NULL;
 //Input AVFormatContext and Output AVFormatContext
 AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
 AVPacket pkt;
 const char *in_filename, *out_filename;
 int ret, i;
 int videoindex=-1;
 int frame_index=0;
 int64_t start_time=0;
 int64_t bit_rate = 400*1000;
 in_filename = "/home/zion/video/mecha.flv";// Input file URL
 out_filename = "rtmp://localhost:1935/live/test";//Output URL [RTMP]
 av_register_all();
 avformat_network_init();
 avformat_open_input(&ifmt_ctx, in_filename, 0, 0);
 avformat_find_stream_info(ifmt_ctx, 0);
 for(i=0; inb_streams; i++) 
 if(ifmt_ctx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
 videoindex=i;
 break;
 }
 //Output
 avformat_alloc_output_context2(&ofmt_ctx, NULL, "flv", out_filename); //RTMP
 ofmt = ofmt_ctx->oformat;
 for (i = 0; i < ifmt_ctx->nb_streams; i++) {
 //Create output AVStream according to input AVStream
 AVStream *in_stream = ifmt_ctx->streams[i];
 AVStream *out_stream = avformat_new_stream(ofmt_ctx, in_stream->codec->codec);
 //Copy the settings of AVCodecContext
 ret = avcodec_copy_context(out_stream->codec, in_stream->codec);
 out_stream->codec->codec_tag = 0;
 if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
 out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
 }
 //Open output URL
 if (!(ofmt->flags & AVFMT_NOFILE)) {
 ret = avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE);
 }
 //Write file header
 avformat_write_header(ofmt_ctx, NULL);
 start_time=av_gettime();
 while (1) {
 AVStream *in_stream, *out_stream;
 //Get an AVPacket
 ret = av_read_frame(ifmt_ctx, &pkt);
 if (ret < 0)
 break;
 //Important:Delay
 if(pkt.stream_index==videoindex){
 AVRational time_base=ifmt_ctx->streams[videoindex]->time_base;
 AVRational time_base_q={1,AV_TIME_BASE};
 int64_t pts_time = av_rescale_q(pkt.dts, time_base, time_base_q);
 int64_t now_time = av_gettime() - start_time;
 if (pts_time > now_time)
 av_usleep(pts_time - now_time);
 }
 in_stream = ifmt_ctx->streams[pkt.stream_index];
 out_stream = ofmt_ctx->streams[pkt.stream_index];
 if(pkt.stream_index==videoindex){
 printf("Send %8d video frames to output URL\n",frame_index);
 frame_index++;
 }
/*I tried modifying the bitrate here and I'm not sure if this is the correct usage.*/
 ofmt_ctx->bit_rate = bit_rate;
 av_interleaved_write_frame(ofmt_ctx, &pkt);
 av_free_packet(&pkt);
 }
 //Write file trailer
 av_write_trailer(ofmt_ctx);
end:
 avformat_close_input(&ifmt_ctx);
 /* close output */
 if (ofmt_ctx && !(ofmt->flags & AVFMT_NOFILE))
 avio_close(ofmt_ctx->pb);
 avformat_free_context(ofmt_ctx);
 return 0;
}