
Recherche avancée
Autres articles (57)
-
Contribute to documentation
13 avril 2011Documentation is vital to the development of improved technical capabilities.
MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
To contribute, register to the project users’ mailing (...) -
Submit bugs and patches
13 avril 2011Unfortunately a software is never perfect.
If you think you have found a bug, report it using our ticket system. Please to help us to fix it by providing the following information : the browser you are using, including the exact version as precise an explanation as possible of the problem if possible, the steps taken resulting in the problem a link to the site / page in question
If you think you have solved the bug, fill in a ticket and attach to it a corrective patch.
You may also (...) -
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 (...)
Sur d’autres sites (4131)
-
libav how to change stream codec
9 novembre 2018, par Rodolfo PicoretiI am trying to reproduce with libav the same thing that the following ffmpeg command does :
ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video 0 -f
mpegts -codec:v mpeg1video -s 640x480 -b:v 1000k -bf 0 -muxdelay
0.001 http://localhost:8081/supersecretI manage to reproduce most part of it. The problem is that when allocating the "mpegts" stream (line 23) the codec that is selected is "mpeg2video", but I need it to be "mpeg1video". I tried forcing the codec_id variable to be "mpeg1video" (line 25) and it kinda worked, although I get a lot of artifacts in the image so I am guessing this is not how you do it. How can I properly change the codec in this case (that is, the "-codec:v mpeg1video" part of the ffmpeg command) ?
C++ code being used :
#include <exception>
#include <opencv2></opencv2>core.hpp>
#include <opencv2></opencv2>highgui.hpp>
#include <opencv2></opencv2>imgproc.hpp>
extern "C" {
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>error.h>
#include <libavutil></libavutil>frame.h>
#include <libavutil></libavutil>imgutils.h>
}
struct AVStreamer {
AVFormatContext* format_context;
AVStream* stream;
AVCodecContext* codec_context;
AVCodec* codec;
AVFrame* frame;
int64_t next_pts;
void init_format_context(const char* url) {
avformat_alloc_output_context2(&format_context, nullptr, "mpegts", url);
if (format_context == nullptr) throw std::runtime_error("Could not create output context");
format_context->oformat->video_codec = AV_CODEC_ID_MPEG1VIDEO;
}
void init_codec() {
auto codec_id = format_context->oformat->video_codec;
codec = avcodec_find_encoder(codec_id);
if (codec == nullptr) throw std::runtime_error("Could not find encoder");
}
void init_stream() {
stream = avformat_new_stream(format_context, nullptr);
if (stream == nullptr) throw std::runtime_error("Failed to alloc stream");
stream->id = format_context->nb_streams - 1;
}
void init_codec_context() {
codec_context = avcodec_alloc_context3(codec);
if (codec_context == nullptr) throw std::runtime_error("Failed to alloc encoding context");
auto codec_id = format_context->oformat->video_codec;
codec_context->codec_id = codec_id;
codec_context->bit_rate = 400000;
codec_context->width = 640;
codec_context->height = 480;
stream->time_base = AVRational{1, 30};
codec_context->time_base = stream->time_base;
codec_context->gop_size = 30; // one intra frame every gop_size
// codec_context->max_b_frames = 0; // output delayed by max_b_frames
codec_context->pix_fmt = AV_PIX_FMT_YUV420P;
if (codec_context->codec_id == AV_CODEC_ID_MPEG1VIDEO) { codec_context->mb_decision = 2; }
if (format_context->oformat->flags & AVFMT_GLOBALHEADER) {
codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
}
void init_frame() {
frame = av_frame_alloc();
if (frame == nullptr) throw std::runtime_error("Failed to alloc frame");
frame->format = codec_context->pix_fmt;
frame->width = codec_context->width;
frame->height = codec_context->height;
auto status = av_frame_get_buffer(frame, 32);
if (status < 0) { throw std::runtime_error("Could not allocate frame data.\n"); }
}
void open_stream(const char* url) {
int status = avcodec_open2(codec_context, codec, nullptr);
if (status != 0) throw std::runtime_error("Failed to open codec");
// copy the stream parameters to the muxer
status = avcodec_parameters_from_context(stream->codecpar, codec_context);
if (status < 0) throw std::runtime_error("Could not copy the stream parameters");
av_dump_format(format_context, 0, url, 1);
if (!(format_context->oformat->flags & AVFMT_NOFILE)) {
status = avio_open(&format_context->pb, url, AVIO_FLAG_WRITE);
if (status < 0) throw std::runtime_error("Could not open output file");
}
// Write the stream header, if any.
status = avformat_write_header(format_context, nullptr);
if (status < 0) throw std::runtime_error("Error occurred when opening output file");
}
AVStreamer(const char* url) : next_pts(0) {
init_format_context(url);
init_codec();
init_stream();
init_codec_context();
init_frame();
open_stream(url);
}
virtual ~AVStreamer() {
avformat_free_context(format_context);
avcodec_free_context(&codec_context);
av_frame_free(&frame);
}
void send(cv::Mat const& image) {
cv::cvtColor(image, image, CV_BGR2YUV);
cv::Mat planes[3];
cv::split(image, planes);
cv::pyrDown(planes[1], planes[1]);
cv::pyrDown(planes[2], planes[2]);
if (av_frame_make_writable(frame) < 0) {
throw std::runtime_error("Failed to make frame writable");
}
frame->data[0] = planes[0].data;
frame->linesize[0] = planes[0].step;
frame->data[1] = planes[1].data;
frame->linesize[1] = planes[1].step;
frame->data[2] = planes[2].data;
frame->linesize[2] = planes[2].step;
frame->pts = next_pts++;
AVPacket packet;
av_init_packet(&packet);
int status = avcodec_send_frame(codec_context, frame);
if (status < 0) throw std::runtime_error("Send frame failed");
status = avcodec_receive_packet(codec_context, &packet);
if (status == AVERROR(EAGAIN)) { return; }
if (status < 0) throw std::runtime_error("Receive packet failed");
av_packet_rescale_ts(&packet, codec_context->time_base, stream->time_base);
packet.stream_index = stream->index;
av_interleaved_write_frame(format_context, &packet);
}
};
int main(int argc, char** argv) {
av_register_all();
avformat_network_init();
auto url = argc == 2 ? argv[1] : "http://localhost:8081/supersecret";
AVStreamer streamer(url);
cv::VideoCapture video(0);
assert(video.isOpened() && "Failed to open video");
for (;;) {
cv::Mat image;
video >> image;
streamer.send(image);
}
}
</exception> -
Create movie programatically with ffmpeg
16 janvier 2019, par Martin DelilleI would like to create a movie programatically with ffmpeg.
Here is my code :
QString fileName = "test.mov";
static char errorString[AV_ERROR_MAX_STRING_SIZE];
printf("Video encoding\n");
AVOutputFormat *outputFormat = av_guess_format(nullptr, fileName.toStdString().c_str(), nullptr);
if (outputFormat == nullptr) {
qDebug() << "Could not find suitable format for" << fileName;
return false;
}
enum AVCodecID codec_id = AV_CODEC_ID_MJPEG;
qDebug() << "Format Name:" << outputFormat->name;
qDebug() << "Format Video Codec:" << outputFormat->video_codec;
outputFormat->video_codec = codec_id;
/// allocate the output media context, formatContext
AVFormatContext *formatContext = avformat_alloc_context();
formatContext->oformat = outputFormat;
// find the mpeg1 video encoder
AVCodec *codec = avcodec_find_encoder(codec_id);
if (!codec) {
qDebug() << "codec not found";
return false;
}
qDebug() << "Codec name:" << codec->name;
AVStream *videoStream = avformat_new_stream(formatContext, codec);
// put sample parameters
videoStream->codecpar->bit_rate = 400000;
videoStream->codecpar->width = width;
videoStream->codecpar->height = height;
videoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
videoStream->codecpar->format = AV_PIX_FMT_YUVJ422P;
videoStream->time_base.num = 1;
videoStream->time_base.den = 25;
AVCodecContext *codecContext = avcodec_alloc_context3(nullptr);
codecContext->codec_id = codec_id;
codecContext->codec_type = AVMEDIA_TYPE_VIDEO;
codecContext->width = width;
codecContext->height = height;
codecContext->time_base.num = 1;
codecContext->time_base.den = 25;
codecContext->pix_fmt = AV_PIX_FMT_YUVJ422P;
if (int error = avcodec_parameters_to_context(codecContext, videoStream->codecpar)) {
qDebug() << "Error parameting the context:" << av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
return false;
}
// open it
if (int error = avcodec_open2(codecContext, codec, nullptr)) {
qDebug() << "Could not open codec:" << av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
return false;
}
// alloc image and output buffer
AVFrame *frame = av_frame_alloc();
frame->format = codecContext->pix_fmt;
frame->width = codecContext->width;
frame->height = codecContext->height;
if (int error = av_image_alloc(frame->data, frame->linesize, frame->width, frame->height, static_cast<enum avpixelformat="avpixelformat">(frame->format), 0)) {
qDebug() << "Error allocating image data:" << av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
return false;
}
// Open the output file, if needed
if (!(outputFormat->flags & AVFMT_NOFILE)) {
if (avio_open(&formatContext->pb, fileName.toStdString().c_str(), AVIO_FLAG_WRITE) < 0) {
qDebug() << "Could not open" << fileName;
return false;
}
}
// some formats want stream headers to be separate
if (formatContext->oformat->flags & AVFMT_GLOBALHEADER) {
codecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
if (int error = avformat_write_header(formatContext, nullptr)) {
qDebug() << "error writing header:" << av_make_error_string(errorString, AV_ERROR_MAX_STRING_SIZE, error);
return false;
}
</enum>Unfortunately, when I execute it I have the following output :
Format Name: mov
Format Video Codec: 27
Codec name: mjpeg
[mov @ 0x1048c7000] Could not find tag for codec none in stream #0, codec not currently supported in container
error writing header: Invalid argumentWhat am I doing wrong ?
-
Live555 truncates encoded data of FFMpeg
22 novembre 2019, par Harshil MakwanaI am trying to stream H264 based data using Live555 over RTSP.
I am capturing data using V4L2, and then encodes it using FFMPEG and then passing data to Live555’s DeviceSource file, in that I using H264VideoStreamFramer class,
Below is my codec settings to configure AVCodecContext of encoder,
codec = avcodec_find_encoder_by_name(CODEC_NAME);
if (!codec) {
cerr << "Codec " << codec_name << " not found\n";
exit(1);
}
c = avcodec_alloc_context3(codec);
if (!c) {
cerr << "Could not allocate video codec context\n";
exit(1);
}
pkt = av_packet_alloc();
if (!pkt)
exit(1);
/* put sample parameters */
c->bit_rate = 400000;
/* resolution must be a multiple of two */
c->width = PIC_HEIGHT;
c->height = PIC_WIDTH;
/* frames per second */
c->time_base = (AVRational){1, FPS};
c->framerate = (AVRational){FPS, 1};
c->gop_size = 10;
c->max_b_frames = 1;
c->pix_fmt = AV_PIX_FMT_YUV420P;
c->rtp_payload_size = 30000;
if (codec->id == AV_CODEC_ID_H264)
av_opt_set(c->priv_data, "preset", "fast", 0);
av_opt_set_int(c->priv_data, "slice-max-size", 30000, 0);
/* open it */
ret = avcodec_open2(c, codec, NULL);
if (ret < 0) {
cerr << "Could not open codec\n";
exit(1);
}And I am getting encoded data using avcodec_receive_packet() function. which will return AVPacket.
And I am passing AVPacket’s data into DeviceSource file below is code snippet of my Live555 code :
void DeviceSource::deliverFrame() {
if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet
u_int8_t* newFrameDataStart = (u_int8_t*) pkt->data;
unsigned newFrameSize = pkt->size; //%%% TO BE WRITTEN %%%
// Deliver the data here:
if (newFrameSize > fMaxSize) { // Condition becomes true many times
fFrameSize = fMaxSize;
fNumTruncatedBytes = newFrameSize - fMaxSize;
} else {
fFrameSize = newFrameSize;
}
gettimeofday(&fPresentationTime, NULL); // If you have a more accurate time - e.g., from an encoder - then use that instead.
// If the device is *not* a 'live source' (e.g., it comes instead from a file or buffer), then set "fDurationInMicroseconds" here.
memmove(fTo, newFrameDataStart, fFrameSize);
}But here, sometimes my packet’s size is getting more than fMaxSize value and as per LIVE555 logic it will truncate frame data, so that sometimes I am getting bad frames on my VLC,
From Live555 forum, I get to know that encoder should not send packet whose size is more than fMaxSize value, so my question is :
How to restrict encoder to limit size of packet ?
Thanks in Advance,
Harshil