
Recherche avancée
Médias (1)
-
Video d’abeille en portrait
14 mai 2011, par
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (41)
-
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
Contribute to a better visual interface
13 avril 2011MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community. -
Submit enhancements and plugins
13 avril 2011If you have developed a new extension to add one or more useful features to MediaSPIP, let us know and its integration into the core MedisSPIP functionality will be considered.
You can use the development discussion list to request for help with creating a plugin. As MediaSPIP is based on SPIP - or you can use the SPIP discussion list SPIP-Zone.
Sur d’autres sites (8845)
-
Problems to read frame using FFMPEG to OpenCV Mat
28 décembre 2022, par AlexI'm trying to read all frames from a video using FFMPEG library in C++, but I have got this exception :


Assertion desc failed at libswscale/swscale_internal.h:727



The code that I'm using is follow :


#include <iostream>
#include <string>
#include <vector>

extern "C" {
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>imgutils.h>
#include <libswscale></libswscale>swscale.h>
#include <libavcodec></libavcodec>avcodec.h>
}


#include <opencv2></opencv2>opencv.hpp>

// helper function to check for FFmpeg errors
inline void checkError(int error, const std::string &message) {
 if (error < 0) {
 std::cerr << message << ": " << av_err2str(error) << std::endl;
 exit(EXIT_FAILURE);
 }
}

int main() {
 // initialize FFmpeg
 av_log_set_level(AV_LOG_ERROR);
 avformat_network_init();

 // open the input file
 std::string fileName = "input.mp4";
 AVFormatContext *formatContext = nullptr;
 int error = avformat_open_input(&formatContext, fileName.c_str(), nullptr, nullptr);
 checkError(error, "Error opening input file");

 // find the video stream
 AVStream *videoStream = nullptr;
 for (unsigned int i = 0; i < formatContext->nb_streams; i++) {
 if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && !videoStream) {
 videoStream = formatContext->streams[i];
 }
 }
 if (!videoStream) {
 std::cerr << "Error: input file does not contain a video stream" << std::endl;
 exit(EXIT_FAILURE);
 }

 // create the video codec context
 const AVCodec *videoCodec = avcodec_find_decoder(videoStream->codecpar->codec_id);
 AVCodecContext *videoCodecContext = avcodec_alloc_context3(videoCodec);
 if (!videoCodecContext) {
 std::cerr << "Error allocating video codec context" << std::endl;
 exit(EXIT_FAILURE);
 }
 error = avcodec_parameters_to_context(videoCodecContext, videoStream->codecpar);
 checkError(error, "Error setting video codec context parameters");
 error = avcodec_open2(videoCodecContext, videoCodec, nullptr);
 checkError(error, "Error opening video codec");

 // create the frame scaler
 int width = videoCodecContext->width;
 int height = videoCodecContext->height;
 struct SwsContext *frameScaler = sws_getContext(width, height, videoCodecContext->pix_fmt, width, height, AV_PIX_FMT_BGR24, SWS_BICUBIC, nullptr, nullptr, nullptr);

 // read the packets and decode the video frames
 std::vector videoFrames;
 AVPacket packet;
 while (av_read_frame(formatContext, &packet) == 0) {
 if (packet.stream_index == videoStream->index) {
 // decode the video frame
 AVFrame *frame = av_frame_alloc();
 int gotFrame = 0;
 error = avcodec_send_packet(videoCodecContext, &packet);
 checkError(error, "Error sending packet to video codec");
 error = avcodec_receive_frame(videoCodecContext, frame);
 checkError(error, "Error receiving frame from video codec");
 if (error == 0) {
 gotFrame = 1;
 }
 if (gotFrame) {
 // scale the frame to the desired format
 AVFrame *scaledFrame = av_frame_alloc();
 av_image_alloc(scaledFrame->data, scaledFrame->linesize, width, height, AV_PIX_FMT_BGR24, 32);
 sws_scale(frameScaler, frame->data, frame->linesize, 0, height, scaledFrame->data, scaledFrame->linesize);

 // copy the frame data to a cv::Mat object
 cv::Mat mat(height, width, CV_8UC3, scaledFrame->data[0], scaledFrame->linesize[0]);
 videoFrames.push_back(mat.clone());

 // clean up
 av_freep(&scaledFrame->data[0]);
 av_frame_free(&scaledFrame);
 }
 av_frame_free(&frame);
 }
 av_packet_unref(&packet);
 }

 // clean up
 sws_freeContext(frameScaler);
 avcodec_free_context(&videoCodecContext);
 avformat_close_input(&formatContext);

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


The line that GDB says that occur the exception is this :


struct SwsContext *frameScaler = sws_getContext(width, height, videoCodecContext->pix_fmt, width, height, AV_PIX_FMT_BGR24, SWS_BICUBIC, nullptr, nullptr, nullptr);



-
How to extract frame types along with motion vectors using extract_mvs.c from ffmpeg
26 février 2018, par helmoI have been researching ways to get frame types (I, P, B) along with the motion vector data returned from extract_mvs.c in the examples folder in ffmpeg.
The extract_mvs.c file after it is compiled, returns information like this :
framenum,source,blockw,blockh,srcx,srcy,dstx,dsty,flags
2,-1,16,16, 8, 8, 8, 8,0x0
2, 1,16,16, 8, 8, 8, 8,0x0
2, 1,16,16, 24, 8, 24, 8,0x0
2, 1,16,16, 40, 8, 40, 8,0x0
2, 1,16,16, 56, 8, 56, 8,0x0
2, 1,16,16, 72, 8, 72, 8,0x0
2, 1,16,16, 88, 8, 88, 8,0x0
...
297, 1,16,16, 248, 280, 248, 280,0x0
297, 1,16,16, 264, 280, 264, 280,0x0
297,-1,16,16, 278, 279, 280, 280,0x0
297, 1,16,16, 280, 280, 280, 280,0x0
297, 1,16,16, 296, 280, 296, 280,0x0
297, 1,16,16, 312, 280, 312, 280,0x0
297, 1,16,16, 328, 280, 328, 280,0x0
297, 1,16,16, 344, 280, 344, 280,0x0Along with this information, I would like to output frame type so that I know framenum = 2 is, for example, a ’B’ frame.
I tried different things, one of which was using a separate command :
ffprobe input.mp4 -show_frames | grep -E 'pict_type|coded_picture_number'
But the problem with this command is that it returns data like :
pict_type=I
coded_picture_number=0
pict_type=B
coded_picture_number=2
pict_type=P
coded_picture_number=1
pict_type=B
coded_picture_number=4
pict_type=P
coded_picture_number=3
....
pict_type=P
coded_picture_number=293
pict_type=B
coded_picture_number=297
pict_type=B
coded_picture_number=296And there is no much I can relate here between coded_picture_number and framenum. The former starts counting from 0 and the later from 2. I assume framenum starting from 2, means the count from this variable is actually from 1, and it ignored 1 in the extraction process as it is maybe an I frame thus no motion vectors.
So, how can we use only extract_mvs.c to get not only that information it provides but also the frame types in the returned table. Any hints either syntax/command-wise or in editing the c file would be appreciated. Thanks in advance.
-
Merge commit ’72cebae0d981dde144340cf51f3c323f01e215e5’
31 mai 2015, par Michael NiedermayerMerge commit ’72cebae0d981dde144340cf51f3c323f01e215e5’
* commit ’72cebae0d981dde144340cf51f3c323f01e215e5’ :
ppc : avutil : Use the abriged vector typesConflicts :
libavutil/ppc/float_dsp_altivec.c
libavutil/ppc/util_altivec.hMerged-by : Michael Niedermayer <michaelni@gmx.at>