
Recherche avancée
Autres articles (58)
-
La file d’attente de SPIPmotion
28 novembre 2010, parUne file d’attente stockée dans la base de donnée
Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...) -
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 (5394)
-
How to get 1 frame per second in ffmpeg video to images ? Getting more images than expected
15 septembre 2021, par code0x00I am trying to extract images from a video 1 frame per second but i am getting more images than i expect.


for eg. :


When i run below command :


ffmpeg -i filename.mp4 -r 1 img%d.jpg



It is a 20 second video but creating 22 images.


it should create 21 images.


Why it is creating one extra image ?


-
libavformat/libavcodec : Why am I getting a significantly shorter video than expected ?
2 mars 2023, par itzjackyscodeThe MVE below is a simple test program that should encode 6 s (360 frames) of video. When I import the exported video (
output.mkv
) into a video editor, I see that it is only a fraction of a second. Why is this ? How do I fix it ?

MVE


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

namespace av {
 // ERROR HANDLING
 // ==============

 class av_category_t final : public std::error_category {
 public:
 inline const char* name() const noexcept override { return "av_category"; }

 inline std::string message(int code) const noexcept override {
 thread_local static char msg_buffer[AV_ERROR_MAX_STRING_SIZE];
 av_strerror(code, msg_buffer, sizeof(msg_buffer));
 return std::string(msg_buffer);
 }
 };

 inline const std::error_category& av_category() {
 static av_category_t result;
 return result;
 }

 // helper function to create a std::system_error.
 inline std::system_error av_error(int code) {
 return std::system_error(code, av_category());
 }

 // Allocate or reallocate buffers in a video frame.
 inline void alloc_video_frame(
 AVFrame* frame, int width, int height, AVPixelFormat pix_fmt
 ) {
 int err;
 if (frame->width != width || frame->height != height || 
 frame->format != pix_fmt || !av_frame_is_writable(frame)) {
 // unref the old data if any
 if (frame->buf[0] != nullptr) {
 av_frame_unref(frame);
 }

 // reset parameters
 frame->width = width;
 frame->height = height;
 frame->format = pix_fmt;

 // reallocate
 if ((err = av_frame_get_buffer(frame, 0)) < 0)
 throw av_error(err);
 }
 }
 inline void alloc_video_frame(AVFrame* frame, const AVCodecContext* ctx) {
 alloc_video_frame(frame, ctx->width, ctx->height, ctx->pix_fmt);
 }
} // namespace av

void fill_rgb(AVFrame* tmp, AVFrame* dst, uint32_t col) {
 static SwsContext* sws = nullptr;
 int err;
 
 av::alloc_video_frame(tmp, dst->width, dst->height, AV_PIX_FMT_0RGB32);
 for (int i = 0; i < tmp->height; i++) {
 for (int j = 0; j < tmp->width; j++) {
 void* p = tmp->data[0] + (i * tmp->linesize[0]) + (j * 4);
 *((uint32_t*) p) = col;
 }
 }
 
 sws = sws_getCachedContext(sws,
 // src params
 tmp->width, tmp->height, (AVPixelFormat) tmp->format,
 // dst params
 dst->width, dst->height, (AVPixelFormat) dst->format,
 // stuff
 0, nullptr, nullptr, nullptr
 );
 if ((err = sws_scale_frame(sws, dst, tmp)) < 0)
 throw av::av_error(err);
}

int32_t hue_c(int deg) {
 deg %= 360;
 int rem = deg % 60;
 switch (deg / 60) {
 case 0: return 0xFF0000 | ((deg * 256 / 60) << 8);
 case 1: return 0x00FF00 | (((60 - deg) * 256 / 60) << 16);
 case 2: return 0x00FF00 | ((deg * 256 / 60) << 0);
 case 3: return 0x0000FF | (((60 - deg) * 256 / 60) << 8);
 case 4: return 0x00FF00 | ((deg * 256 / 60) << 16);
 case 5: return 0xFF0000 | (((60 - deg) * 256 / 60) << 0);
 }
 return 0xFFFFFF;
}

int main() {
 int res;

 AVFormatContext* fmt_ctx;
 AVStream* vstream;
 const AVCodec* vcodec;
 AVCodecContext* vcodec_ctx;

 AVFrame* vframe;
 AVFrame* vframe2;
 AVPacket* vpacket;

 int64_t pts = 0;

 // init frame
 res = avformat_alloc_output_context2(&fmt_ctx, NULL, NULL, "output.mkv");
 if (res < 0)
 return 1;

 // get encoder
 vcodec = avcodec_find_encoder(AV_CODEC_ID_VP8);

 // allocate everything else
 vstream = avformat_new_stream(fmt_ctx, vcodec);
 vcodec_ctx = avcodec_alloc_context3(vcodec);
 vframe = av_frame_alloc();
 vframe2 = av_frame_alloc();
 vpacket = av_packet_alloc();
 if (!vstream || !vcodec_ctx || !vframe || !vpacket) {
 return 1;
 }

 // set PTS counter
 pts = 0;

 // codec: size parameters
 vcodec_ctx->width = 640;
 vcodec_ctx->height = 480;
 vcodec_ctx->sample_aspect_ratio = {1, 1};

 // codec: pixel formats
 vcodec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;

 // codec: bit rate et al.
 vcodec_ctx->bit_rate = 2e6;
 vcodec_ctx->rc_buffer_size = 4e6;
 vcodec_ctx->rc_max_rate = 2e6;
 vcodec_ctx->rc_min_rate = 2.5e6;

 // codec: frame rate
 vcodec_ctx->time_base = {1, 60};
 vstream->time_base = {1, 60};
 vstream->avg_frame_rate = {60, 1};

 // open codec
 res = avcodec_open2(vcodec_ctx, vcodec, NULL);
 if (res < 0)
 throw av::av_error(res);
 res = avcodec_parameters_from_context(vstream->codecpar, vcodec_ctx);
 if (res < 0)
 throw av::av_error(res);
 
 // open file
 if (!(fmt_ctx->oformat->flags & AVFMT_NOFILE)) {
 res = avio_open(&fmt_ctx->pb, "output.mkv", AVIO_FLAG_WRITE);
 if (res < 0)
 throw av::av_error(res);
 }
 
 // write format header
 res = avformat_write_header(fmt_ctx, NULL);
 if (res < 0)
 throw av::av_error(res);

 // encode loop
 for (int i = 0; i < 360; i++) {
 av::alloc_video_frame(vframe, vcodec_ctx);

 // gen data and store to vframe
 fill_rgb(vframe2, vframe, hue_c(i));
 
 // set timing info
 vframe->time_base = vcodec_ctx->time_base;
 vframe->pts = i;

 // send to encoder
 avcodec_send_frame(vcodec_ctx, vframe);
 while ((res = avcodec_receive_packet(vcodec_ctx, vpacket)) == 0) {
 printf("DTS: %ld, PTS: %ld\n", vpacket->dts, vpacket->pts);
 
 if ((res = av_interleaved_write_frame(fmt_ctx, vpacket)) < 0)
 throw av::av_error(res);
 
 }
 if (res != AVERROR_EOF && res != AVERROR(EAGAIN))
 return -1;
 }
 
 if ((res = av_write_trailer(fmt_ctx)) < 0)
 throw av::av_error(res);
 
 av_frame_free(&vframe);
 av_frame_free(&vframe2);
 av_packet_free(&vpacket);
 avcodec_free_context(&vcodec_ctx);
 
 avformat_free_context(fmt_ctx);
}
</iostream></cstdio></cstddef>


-
FFMPEG - Scale video filter not providing expected results
11 novembre 2011, par dpasseraApologies if this question has been asked. I couldn't find it, but if it has, please let me know and I'll close this out.
I'm attempting a simple scale of a video whose original dimensions are 480x360 and whose target dimensions are 400x300. The video starts as an FLV and eventually needs to end up as an MPEG. I'm using the following command line to do this :
ffmpeg -i user.flv -vf "scale=400:300" user_scaled.mpg
When I play the scaled video in MPEG Streamclip, the scale is correct and the video info shows that the dimensions are 400x300. However, when I play the scaled video in Quicktime, the video is scaled to 478x359. More importantly, FFMPEG, itself, treats the video as being 478x359, so any future commands (trimming, conversion, overlaying, etc) executed on it result in a video of 478x359.
The initial workflow required an FLV to MPEG conversion, but I've tried this with several different in and out formats (FLV -> FLV, FLV -> MPEG, MPEG -> MPEG, etc) all with the same results. As long as I can end up with an MPEG, though, I can deal with however many steps and conversions it would take to get this scaling working.
I'll paste the command-line output below, and a sample input video is also linked below, if you'd like it. Thank you very much for any help.
http://www.monkeydriver.com/dpassera/stack_flv.zip
Command-line output :
ffmpeg -i user.flv -vf "scale=400:300" user_scaled.mpg
ffmpeg version 0.7-rc1, Copyright (c) 2000-2011 the FFmpeg developers
built on May 21 2011 22:13:19 with gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64
--mandir=/usr/share/man --incdir=/usr/include --disable-avisynth
--extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC'
--enable-avfilter --enable-libdirac --enable-libgsm --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264
--enable-gpl --enable-postproc --enable-pthreads --enable-shared
--enable-swscale --enable-vdpau --enable-version3 --enable-x11grab
--disable-yasm --enable-filters --enable-filter=movie
libavutil 50. 40. 1 / 50. 40. 1
libavcodec 52.120. 0 / 52.120. 0
libavformat 52.108. 0 / 52.108. 0
libavdevice 52. 4. 0 / 52. 4. 0
libavfilter 1. 77. 0 / 1. 77. 0
libswscale 0. 13. 0 / 0. 13. 0
libpostproc 51. 2. 0 / 51. 2. 0
[flv @ 0x11dd3b30] Estimating duration from bitrate, this may be inaccurate
Input #0, flv, from 'user.flv':
Metadata:
duration : 5
videocodecid : 2
audiocodecid : 6
canSeekToEnd : true
createdby : FMS 4.0
creationdate : Mon Oct 31 11:43:44 2011
Duration: 00:00:04.62, start: 0.000000, bitrate: N/A
Stream #0.0: Video: flv, yuv420p, 640x480, 1k tbr, 1k tbn, 1k tbc
Stream #0.1: Audio: nellymoser, 44100 Hz, mono, s16
[buffer @ 0x11ddc950] w:640 h:480 pixfmt:yuv420p
[scale @ 0x11dda610] w:640 h:480 fmt:yuv420p -> w:400 h:300 fmt:yuv420p flags:0xa0000004
[mpeg @ 0x11dd6bd0] VBV buffer size not set, muxing may fail
Output #0, mpeg, to 'user_scaled.mpg':
Metadata:
duration : 5
videocodecid : 2
audiocodecid : 6
canSeekToEnd : true
createdby : FMS 4.0
creationdate : Mon Oct 31 11:43:44 2011
encoder : Lavf52.108.0
Stream #0.0: Video: mpeg1video, yuv420p, 400x300, q=2-31, 200 kb/s, 90k tbn, 60 tbc
Stream #0.1: Audio: mp2, 44100 Hz, mono, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 230 fps= 0 q=10.2 size= 366kB time=3.82 bitrate= 785.6kbits/s dup=175 drop=0
frame= 267 fps= 0 q=10.7 Lsize= 412kB time=4.43 bitrate= 761.3kbits/s dup=203 drop=0
video:370kB audio:36kB global headers:0kB muxing overhead 1.568959%