
Recherche avancée
Autres articles (82)
-
Mise à jour de la version 0.1 vers 0.2
24 juin 2013, parExplications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...) -
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Ecrire une actualité
21 juin 2013, parPrésentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
Vous pouvez personnaliser le formulaire de création d’une actualité.
Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)
Sur d’autres sites (17791)
-
Decoding a h264 (High) stream with OpenCV's ffmpeg on Ubuntu
9 janvier 2017, par arvidsI am working with a video stream (no audio) from an ip camera on Ubuntu 14.04. Also i am a beginner with Ubuntu and everything on it. Everything was going great with a camera that has these parameters (from FFMPEG) :
Input #0, rtsp, from 'rtsp://*private*:8900/live.sdp': 0B f=0/0
Metadata:
title : RTSP server
Stream #0:0: Video: h264 (Main), yuv420p(progressive), 352x192, 29.97 tbr, 90k tbn, 180k tbcBut then i changed to a newer camera, which has these parameters :
Input #0, rtsp, from 'rtsp://*private*/media/video2':0B f=0/0
Metadata:
title : VCP IPC Realtime stream
Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1280x720, 25 fps, 25 tbr, 90k tbn, 50 tbcMy C++ program uses OpenCV3 to process the stream. By default OpenCV uses ffmpeg to decode and display the stream with function VideoCapture.
VideoCapture vc;
vc.open(input_stream);
while ((vc >> frame), !frame.empty()) {
*do work*
}With the new camera stream i get errors like these (from ffmpeg) :
[h264 @ 0x7c6980] cabac decode of qscale diff failed at 41 38
[h264 @ 0x7c6980] error while decoding MB 41 38, bytestream (3572)
[h264 @ 0x7c6980] left block unavailable for requested intra mode at 0 44
[h264 @ 0x7c6980] error while decoding MB 0 44, bytestream (4933)
[h264 @ 0x7bc2c0] SEI type 25 truncated at 208
[h264 @ 0x7bfaa0] SEI type 25 truncated at 206
[h264 @ 0x7c6980] left block unavailable for requested intra mode at 0 18
[h264 @ 0x7c6980] error while decoding MB 0 18, bytestream (14717)The image sometimes is glitched, sometimes completely frozen. After a few seconds to a few minutes the stream freezes completely without an error. However on vlc it plays perfectly. I installed the newest version (3.2.2) of ffmpeg player with
./configure --enable-gpl --enable-libx264
Now playing directly with ffplay (instead of launching from source code with OpenCV function VideoCapture), the stream plays better, doesn’t freeze, but sometimes still displays warnings :
[NULL @ 0x7f834c008c00] SEI type 25 size 896 truncated at 320=1/1
[h264 @ 0x7f834c0d5d20] SEI type 25 size 896 truncated at 319=1/1
[rtsp @ 0x7f834c0008c0] max delay reached. need to consume packet
[rtsp @ 0x7f834c0008c0] RTP: missed 1 packets
[h264 @ 0x7f834c094740] concealing 675 DC, 675 AC, 675 MV errors in P frame
[NULL @ 0x7f834c008c00] SEI type 25 size 896 truncated at 320=1/1Changing the camera hardware is not an option. The camera can be set to encode to h265 or mjpeg. When encoding to mjpeg it can output 5 fps, which is not enough. Decoding to a static video is not an option either, because i need to display real time results about the stream. Here is a list of API backends that can be used in function VideoCapture. Maybe i should swithc to some other decoder and player ?
From my research i conclude that i have these options :-
Somehow get OpenCV to use the ffmpeg player from another directory, where it is compiled with libx264
-
Somehow get OpenCV to use libVlc instead of ffmpeg
One example of switching to vlc is here, but i don’t understand it well enough to say if that is what i need. Or maybe i should be parsing the stream in code ? I don’t rule out that this could be some basic problem due to a lack of dependencies, because, as i said, i’m a beginner with Ubuntu.
- Use vlc to preprocess the stream, as suggested here.
This is probably slow, which again is bad for real time results.
Any suggestions and coments will be appreciated. -
-
Why android ffmpeg takes so long time to resize mp4 video from high resolution ?
1er septembre 2018, par Kasim RangwalaI’m resizing 30 sec long ( 59.98 MB) mp4 video with resolution of 1920 X 1080 to 1280 X 720 using following
ffmpeg
command in android.["-i", inputVideo!!.path, "-vf", "scale=720:1280", outputVideo.path, "-hide_banner"]
converted video output is very good ( 6.6MB). but,
ffmpeg
conversion take so much time. Is there any options available that I can reduce the conversion time ?update
If output format is other than
mp4
. it is fine but, conversion time must be reduce.Thanks.
-
avcodec_encode_video2 the memory usage is very high
9 juin 2020, par 陆骁剑code :
 ```
 #include "pch.h"
 #include



extern "C"
{
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#include <libavcodec></libavcodec>avcodec.h>
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/avutil.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include <libavutil></libavutil>rational.h>
//#include "libavutil/avassert.h"


//#include "libavutil/attributes.h"
//#include "libavutil/avassert.h"
//#include "libavutil/frame.h"
//#include "libavutil/imgutils.h"
//#include "internal1.h"
//#include "libavutil/samplefmt.h"
}
#include 
//#include "avcodec.h"
//#include "frame_thread_encoder.h"
//#include "internal.h"

// Globals
AVCodec* m_pCodec = NULL;
AVStream *m_pStream = NULL;
AVOutputFormat* m_pFormat = NULL;
AVFormatContext* m_pFormatContext = NULL;
AVCodecContext* m_pCodecContext = NULL;
AVFrame* m_pFrame = NULL;
int m_frameIndex;

// Output format
AVPixelFormat m_pixType = AV_PIX_FMT_NV12;
// Use for mpeg4
//AVPixelFormat m_pixType = AV_PIX_FMT_YUV420P;

// Output frame rate
int m_frameRate = 30;
// Output image dimensions
int m_imageWidth = 256;
int m_imageHeight = 1537;
// Number of frames to export
int m_frameCount = 20000;
// Output file name
const char* m_fileName = "test.h264";
// Output file type
const char* m_fileType = "H264";
// Codec name used to encode
const char* m_encoderName = "h264_qsv";
// use for mpeg4
//const char* m_encoderName = "mpeg4";
// Target bit rate
int m_targetBitRate = 400000;

void addVideoStream()
{
 m_pStream = avformat_new_stream(m_pFormatContext, m_pCodec);
 m_pStream->id = m_pFormatContext->nb_streams - 1;
 m_pStream->time_base = m_pCodecContext->time_base;
 m_pStream->codec->pix_fmt = m_pixType;
 m_pStream->codec->flags = m_pCodecContext->flags;
 m_pStream->codec->width = m_pCodecContext->width;
 m_pStream->codec->height = m_pCodecContext->height;
 m_pStream->codec->time_base = m_pCodecContext->time_base;
 m_pStream->codec->bit_rate = m_pCodecContext->bit_rate;
}

AVFrame* allocatePicture(enum AVPixelFormat pix_fmt, int width, int height)
{
 AVFrame *frame;

 frame = av_frame_alloc();

 if (!frame)
 {
 return NULL;
 }

 frame->format = pix_fmt;
 frame->width = width;
 frame->height = height;

 int checkImage = av_image_alloc(frame->data, frame->linesize, width, height, pix_fmt, 32);

 if (checkImage < 0)
 {
 return NULL;
 }

 return frame;
}

bool initialize()
{
 AVRational frameRate;
 frameRate.den = m_frameRate;
 frameRate.num = 1;

 av_register_all();

 m_pCodec = avcodec_find_encoder_by_name(m_encoderName);

 if (!m_pCodec)
 {
 return false;
 }

 m_pCodecContext = avcodec_alloc_context3(m_pCodec);
 m_pCodecContext->width = m_imageWidth;
 m_pCodecContext->height = m_imageHeight;
 m_pCodecContext->time_base = frameRate;
 m_pCodecContext->gop_size = 0;
 m_pCodecContext->pix_fmt = m_pixType;
 m_pCodecContext->codec_id = m_pCodec->id;
 m_pCodecContext->bit_rate = m_targetBitRate;

 av_opt_set(m_pCodecContext->priv_data, "+CBR", "", 0);

 return true;
}

bool startExport()
{
 m_frameIndex = 0;
 char fakeFileName[512];
 int checkAllocContext = avformat_alloc_output_context2(&m_pFormatContext, NULL, m_fileType, fakeFileName);

 if (checkAllocContext < 0)
 {
 return false;
 }

 if (!m_pFormatContext)
 {
 return false;
 }

 m_pFormat = m_pFormatContext->oformat;

 if (m_pFormat->video_codec != AV_CODEC_ID_NONE)
 {
 addVideoStream();

 int checkOpen = avcodec_open2(m_pCodecContext, m_pCodec, NULL);

 if (checkOpen < 0)
 {
 return false;
 }

 m_pFrame = allocatePicture(m_pCodecContext->pix_fmt, m_pCodecContext->width, m_pCodecContext->height);
 if (!m_pFrame)
 {
 return false;
 }
 m_pFrame->pts = 0;
 }

 int checkOpen = avio_open(&m_pFormatContext->pb, m_fileName, AVIO_FLAG_WRITE);
 if (checkOpen < 0)
 {
 return false;
 }

 av_dict_set(&(m_pFormatContext->metadata), "title", "QS Test", 0);

 int checkHeader = avformat_write_header(m_pFormatContext, NULL);
 if (checkHeader < 0)
 {
 return false;
 }

 return true;
}

int processFrame(AVPacket& avPacket)
{
 avPacket.stream_index = 0;
 avPacket.pts = av_rescale_q(m_pFrame->pts, m_pStream->codec->time_base, m_pStream->time_base);
 avPacket.dts = av_rescale_q(m_pFrame->pts, m_pStream->codec->time_base, m_pStream->time_base);
 m_pFrame->pts++;

 int retVal = av_interleaved_write_frame(m_pFormatContext, &avPacket);
 return retVal;
}

bool exportFrame()
{
 int success = 1;
 int result = 0;

 AVPacket avPacket;

 av_init_packet(&avPacket);
 avPacket.data = NULL;
 avPacket.size = 0;

 AVPacket* avPacket1 = new AVPacket();

 av_init_packet(avPacket1);
 avPacket1->data = NULL;
 avPacket1->size = 0;

 fflush(stdout);

 std::cout << "Before avcodec_encode_video2 for frame: " << m_frameIndex << std::endl;
 success = avcodec_encode_video2(m_pCodecContext, &avPacket, m_pFrame, &result);
 std::cout << "After avcodec_encode_video2 for frame: " << m_frameIndex << std::endl;

 if (result)
 {
 success = processFrame(avPacket);
 }

 av_packet_unref(&avPacket);

 av_free_packet(&avPacket);
 //av_frame_free(&m_pFrame);

 m_frameIndex++;
 return (success == 0);
}

void endExport()
{
 int result = 0;
 int success = 0;

 if (m_pFrame)
 {
 while (success == 0)
 {
 AVPacket avPacket;
 av_init_packet(&avPacket);
 avPacket.data = NULL;
 avPacket.size = 0;

 fflush(stdout);
 success = avcodec_encode_video2(m_pCodecContext, &avPacket, NULL, &result);

 if (result)
 {
 success = processFrame(avPacket);
 }
 av_packet_unref(&avPacket);

 if (!result)
 {
 break;
 }
 }
 }

 if (m_pFormatContext)
 {
 av_write_trailer(m_pFormatContext);

 if (m_pFrame)
 {
 av_frame_free(&m_pFrame);
 }

 avio_closep(&m_pFormatContext->pb);
 avformat_free_context(m_pFormatContext);
 m_pFormatContext = NULL;
 }
}

void cleanup()
{
 if (m_pFrame || m_pCodecContext)
 {
 if (m_pFrame)
 {
 av_frame_free(&m_pFrame);
 }

 if (m_pCodecContext)
 {
 avcodec_close(m_pCodecContext);
 av_free(m_pCodecContext);
 }
 }
}

int main()
{
 bool success = true;
 if (initialize())
 {
 if (startExport())
 {
 for (int loop = 0; loop < m_frameCount; loop++)
 {
 if (!exportFrame())
 {
 std::cout << "Failed to export frame\n";
 success = false;
 break;
 }
 }
 endExport();
 }
 else
 {
 std::cout << "Failed to start export\n";
 success = false;
 }

 cleanup();
 }
 else
 {
 std::cout << "Failed to initialize export\n";
 success = false;
 }

 if (success)
 {
 std::cout << "Successfully exported file\n";
 }
 return 1;
}


 ```




When I set the m_imageHeight to 1536, the memory usage is very high. But when set to 1535 or 1537 or other values, the memory usage is normal, can you tell me why ?
I have navigated to avcodec_encode_video2
enter link description here
I am using the code from the link
I have updated to the latest Intel® Graphics Driver