
Recherche avancée
Autres articles (63)
-
Ajouter notes et légendes aux images
7 février 2011, parPour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
Modification lors de l’ajout d’un média
Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...) -
Configuration spécifique d’Apache
4 février 2011, parModules spécifiques
Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
Création d’un (...) -
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 (8228)
-
C++ ffmpeg Queue input is backward in time while encoding
15 août 2022, par TurgutI've made a program that takes a video as an input, decodes it's video and audio data, then edits the video data and encodes both video and audio (audio remains unedited). I've managed to successfully get the edited video as an output so far, but when I add in the audio, I get an error that says
Queue input is backward in time
. I used the muxing example from ffmpegs doc/examples for encoding, here is what it looks like (I'm not including the video encoding parts since its working just fine) :

typedef struct {
 OutputStream video_st, audio_st;
 const AVOutputFormat *fmt;
 AVFormatContext *oc;
 int have_video, have_audio, encode_video, encode_audio;
 std::string name;
 } encode_info;

encode_info enc_inf;

void video_encoder::open_audio(AVFormatContext *oc, const AVCodec *codec,
 OutputStream *ost, AVDictionary *opt_arg)
{
 AVCodecContext *c;
 int nb_samples;
 int ret;
 AVDictionary *opt = NULL;

 c = ost->enc;

 /* open it */
 av_dict_copy(&opt, opt_arg, 0);
 ret = avcodec_open2(c, codec, &opt);
 av_dict_free(&opt);
 if (ret < 0) {
 fprintf(stderr, "Could not open audio codec: %s\n", ret);
 exit(1);
 }

 /* init signal generator */
 ost->t = 0;
 ost->tincr = 2 * M_PI * 110.0 / c->sample_rate;
 /* increment frequency by 110 Hz per second */
 ost->tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;

 if (c->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
 nb_samples = 10000;
 else
 nb_samples = c->frame_size;

 ost->frame = alloc_audio_frame(c->sample_fmt, c->channel_layout,
 c->sample_rate, nb_samples);
 ost->tmp_frame = alloc_audio_frame(AV_SAMPLE_FMT_S16, c->channel_layout,
 c->sample_rate, nb_samples);

 /* copy the stream parameters to the muxer */
 ret = avcodec_parameters_from_context(ost->st->codecpar, c);
 if (ret < 0) {
 fprintf(stderr, "Could not copy the stream parameters\n");
 exit(1);
 }

 /* create resampler context */
 ost->swr_ctx = swr_alloc();
 if (!ost->swr_ctx) {
 fprintf(stderr, "Could not allocate resampler context\n");
 exit(1);
 }

 /* set options */
 av_opt_set_int (ost->swr_ctx, "in_channel_count", c->channels, 0);
 av_opt_set_int (ost->swr_ctx, "in_sample_rate", c->sample_rate, 0);
 av_opt_set_sample_fmt(ost->swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
 av_opt_set_int (ost->swr_ctx, "out_channel_count", c->channels, 0);
 av_opt_set_int (ost->swr_ctx, "out_sample_rate", c->sample_rate, 0);
 av_opt_set_sample_fmt(ost->swr_ctx, "out_sample_fmt", c->sample_fmt, 0);

 /* initialize the resampling context */
 if ((ret = swr_init(ost->swr_ctx)) < 0) {
 fprintf(stderr, "Failed to initialize the resampling context\n");
 exit(1);
 }
}


void video_encoder::encode_one_frame()
{
 if (enc_inf.encode_video || enc_inf.encode_audio) {
 /* select the stream to encode */
 if (enc_inf.encode_video &&
 (!enc_inf.encode_audio || av_compare_ts(enc_inf.video_st.next_pts, enc_inf.video_st.enc->time_base,
 enc_inf.audio_st.next_pts, enc_inf.audio_st.enc->time_base) <= 0)) {
 enc_inf.encode_video = !write_video_frame(enc_inf.oc, &enc_inf.video_st);
 } else {
 std::cout << "Encoding audio" << std::endl;
 enc_inf.encode_audio = !write_audio_frame(enc_inf.oc, &enc_inf.audio_st);
 }
 }
}

int video_encoder::write_audio_frame(AVFormatContext *oc, OutputStream *ost)
{
 AVCodecContext *c;
 AVFrame *frame;
 int ret;
 int dst_nb_samples;

 c = ost->enc;

 frame = audio_frame;//get_audio_frame(ost);

 if (frame) {
 /* convert samples from native format to destination codec format, using the resampler */
 /* compute destination number of samples */
 dst_nb_samples = av_rescale_rnd(swr_get_delay(ost->swr_ctx, c->sample_rate) + frame->nb_samples,
 c->sample_rate, c->sample_rate, AV_ROUND_UP);
 //av_assert0(dst_nb_samples == frame->nb_samples);

 /* when we pass a frame to the encoder, it may keep a reference to it
 * internally;
 * make sure we do not overwrite it here
 */
 ret = av_frame_make_writable(ost->frame);
 if (ret < 0)
 exit(1);

 /* convert to destination format */
 ret = swr_convert(ost->swr_ctx,
 ost->frame->data, dst_nb_samples,
 (const uint8_t **)frame->data, frame->nb_samples);
 if (ret < 0) {
 fprintf(stderr, "Error while converting\n");
 exit(1);
 }
 frame = ost->frame;

 frame->pts = av_rescale_q(ost->samples_count, (AVRational){1, c->sample_rate}, c->time_base);
 ost->samples_count += dst_nb_samples;
 }

 return write_frame(oc, c, ost->st, frame, ost->tmp_pkt);
}
void video_encoder::set_audio_frame(AVFrame* frame)
{
 audio_frame = frame;
}



Normally the muxing example above uses
get_audio_frame(ost)
for frame insdewrite_audio_frame
to create a dummy audio frame, but I want to use the audio that I have decoded from my input video. After decoding the audio frame I pass it to the encoder usingset_audio_frame
so my encoder can use it. Then I removedget_audio_frame(ost)
and simply replaced it withaudio_frame
. So here is what my main loop looks like :

...
open_audio(args);
...
while(current_second < ouput_duration)
{
...
 video_reader_read_frame(buffer, &pts, start_ts);
 edit_decoded_video(buffer);
 ...
 if(frame_type == 2)
 encoder->set_audio_frame(audio_test->get_frame());
 encoder->encode_one_frame();
}



And here is what my decoder looks like :


int video_decode::decode_audio(AVCodecContext *dec, const AVPacket *pkt)
 {
 auto& frame= state.av_frame;
 int ret = 0;
 
 // submit the packet to the decoder
 ret = avcodec_send_packet(dec, pkt);
 if (ret < 0) {
 std::cout << "Error submitting a packet for decoding" << std::endl;
 return ret;
 }
 
 // get all the available frames from the decoder
 while (ret >= 0) {
 ret = avcodec_receive_frame(dec, frame);
 if (ret < 0) {
 // those two return values are special and mean there is no output
 // frame available, but there were no errors during decoding
 if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
 return 0;
 
 std::cout << "Decode err" << std::endl;
 return ret;
 }
 
 if (ret < 0)
 return ret;
 }
 
 return 0;
 }

 int video_decode::video_reader_read_frame(uint8_t* frame_buffer, int64_t* pts, double seg_start) 
 {
 // Unpack members of state
 auto& width = state.width;
 auto& height = state.height;
 auto& av_format_ctx = state.av_format_ctx;
 auto& av_codec_ctx = state.av_codec_ctx;
 auto& audio_codec_ctx = state.audio_codec_ctx;
 auto& video_stream_index = state.video_stream_index;
 auto& audio_stream_index = state.audio_stream_index;
 auto& av_frame = state.av_frame;
 auto& av_packet = state.av_packet;
 auto& sws_scaler_ctx = state.sws_scaler_ctx;

 // Decode one frame
 //double pt_in_seconds = (*pts) * (double)state.time_base.num / (double)state.time_base.den;
 if (!this->skipped) {
 this->skipped = true;
 *pts = (int64_t)(seg_start * (double)state.time_base.den / (double)state.time_base.num);
 video_reader_seek_frame(*pts);
 }

 int response;
 while (av_read_frame(av_format_ctx, av_packet) >= 0) {
 // Audio decode

 if (av_packet->stream_index == video_stream_index){
 std::cout << "Decoded VIDEO" << std::endl;

 response = avcodec_send_packet(av_codec_ctx, av_packet);
 if (response < 0) {
 printf("Failed to decode packet: %s\n", av_make_error(response));
 return false;
 }


 response = avcodec_receive_frame(av_codec_ctx, av_frame);
 if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {
 av_packet_unref(av_packet);
 continue;
 } else if (response < 0) {
 printf("Failed to decode packet: %s\n", av_make_error(response));
 return false;
 }


 *pts = av_frame->pts;
 // Set up sws scaler
 if (!sws_scaler_ctx) {
 auto source_pix_fmt = correct_for_deprecated_pixel_format(av_codec_ctx->pix_fmt);
 sws_scaler_ctx = sws_getContext(width, height, source_pix_fmt,
 width, height, AV_PIX_FMT_RGB0,
 SWS_BICUBIC, NULL, NULL, NULL);
 }
 if (!sws_scaler_ctx) {
 printf("Couldn't initialize sw scaler\n");
 return false;
 }

 uint8_t* dest[4] = { frame_buffer, NULL, NULL, NULL };
 int dest_linesize[4] = { width * 4, 0, 0, 0 };
 sws_scale(sws_scaler_ctx, av_frame->data, av_frame->linesize, 0, height, dest, dest_linesize);
 av_packet_unref(av_packet);
 return 1;
 }
 if (av_packet->stream_index == audio_stream_index){
 std::cout << "Decoded AUDIO" << std::endl;
 decode_audio(audio_codec_ctx, av_packet);
 av_packet_unref(av_packet);
 return 2;
 }else {
 av_packet_unref(av_packet);
 continue;
 }

 av_packet_unref(av_packet);
 break;
 }


 return true;
 }
void init()
{
...
if (open_codec_context(&audio_stream_index, &audio_dec_ctx, av_format_ctx, AVMEDIA_TYPE_AUDIO) >= 0) {
 audio_stream = av_format_ctx->streams[audio_stream_index];
}
...
}



My decoder uses the same format context, packet and frame for video and audio decoding and uses separate stream and codec context.


Why am I getting
Queue input is backward in time
error and how can I propperly encode the audio ? I'm not sure but from the looks of it decodes the audio just fine. And again there are no problems on video encoding/decoding whatsoever.

-
FFMPEG + HW Acceleration + Kepler GPU Lossless encoding not supported ?
11 juillet 2022, par user2522885I'm curious about FFMPEG and GPU hardware acceleration. My Windows 10 system uses the Asus / nVidia GTX 760 graphics card and Intel i5-2500K CPU. My graphics card claims to be of the Kepler architecture with CUDA 3.0 as shown here.


Instead of going through the hassles of compiling FFMPEG with hw acceleration support i downloaded a pre-compiled binary from here and here.


Next, i tried running a test with hw acceleration options as recommended here :


ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i "input.mkv" -c:a copy -c:v h264_nvenc "output.mp4"



I then received the error message :


[h264_nvenc @ 000001c34eeda8c0] Lossless encoding not supported
[h264_nvenc @ 000001c34eeda8c0] Provided device doesn't support required NVENC features
Error initializing output stream 0:0 — Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height


What am i doing wrong ? For the record i install the CUDA setup file but it made no difference. I am using the latest nVidia drivers.


UPDATE


ffmpeg -h encoder=h264_nvenc


ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
 built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
 configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
 libavutil 56. 70.100 / 56. 70.100
 libavcodec 58.134.100 / 58.134.100
 libavformat 58. 76.100 / 58. 76.100
 libavdevice 58. 13.100 / 58. 13.100
 libavfilter 7.110.100 / 7.110.100
 libswscale 5. 9.100 / 5. 9.100
 libswresample 3. 9.100 / 3. 9.100
 libpostproc 55. 9.100 / 55. 9.100
Encoder h264_nvenc [NVIDIA NVENC H.264 encoder]:
 General capabilities: dr1 delay hardware
 Threading capabilities: none
 Supported hardware devices: cuda cuda d3d11va d3d11va
 Supported pixel formats: yuv420p nv12 p010le yuv444p p016le yuv444p16le bgr0 rgb0 cuda d3d11
h264_nvenc AVOptions:
 -preset <int> E..V....... Set the encoding preset (from 0 to 18) (default p4)
 default 0 E..V.......
 slow 1 E..V....... hq 2 passes
 medium 2 E..V....... hq 1 pass
 fast 3 E..V....... hp 1 pass
 hp 4 E..V.......
 hq 5 E..V.......
 bd 6 E..V.......
 ll 7 E..V....... low latency
 llhq 8 E..V....... low latency hq
 llhp 9 E..V....... low latency hp
 lossless 10 E..V.......
 losslesshp 11 E..V.......
 p1 12 E..V....... fastest (lowest quality)
 p2 13 E..V....... faster (lower quality)
 p3 14 E..V....... fast (low quality)
 p4 15 E..V....... medium (default)
 p5 16 E..V....... slow (good quality)
 p6 17 E..V....... slower (better quality)
 p7 18 E..V....... slowest (best quality)
 -tune <int> E..V....... Set the encoding tuning info (from 1 to 4) (default hq)
 hq 1 E..V....... High quality
 ll 2 E..V....... Low latency
 ull 3 E..V....... Ultra low latency
 lossless 4 E..V....... Lossless
 -profile <int> E..V....... Set the encoding profile (from 0 to 3) (default main)
 baseline 0 E..V.......
 main 1 E..V.......
 high 2 E..V.......
 high444p 3 E..V.......
 -level <int> E..V....... Set the encoding level restriction (from 0 to 62) (default auto)
 auto 0 E..V.......
 1 10 E..V.......
 1.0 10 E..V.......
 1b 9 E..V.......
 1.0b 9 E..V.......
 1.1 11 E..V.......
 1.2 12 E..V.......
 1.3 13 E..V.......
 2 20 E..V.......
 2.0 20 E..V.......
 2.1 21 E..V.......
 2.2 22 E..V.......
 3 30 E..V.......
 3.0 30 E..V.......
 3.1 31 E..V.......
 3.2 32 E..V.......
 4 40 E..V.......
 4.0 40 E..V.......
 4.1 41 E..V.......
 4.2 42 E..V.......
 5 50 E..V.......
 5.0 50 E..V.......
 5.1 51 E..V.......
 5.2 52 E..V.......
 6.0 60 E..V.......
 6.1 61 E..V.......
 6.2 62 E..V.......
 -rc <int> E..V....... Override the preset rate-control (from -1 to INT_MAX) (default -1)
 constqp 0 E..V....... Constant QP mode
 vbr 1 E..V....... Variable bitrate mode
 cbr 2 E..V....... Constant bitrate mode
 vbr_minqp 8388612 E..V....... Variable bitrate mode with MinQP (deprecated)
 ll_2pass_quality 8388616 E..V....... Multi-pass optimized for image quality (deprecated)
 ll_2pass_size 8388624 E..V....... Multi-pass optimized for constant frame size (deprecated)
 vbr_2pass 8388640 E..V....... Multi-pass variable bitrate mode (deprecated)
 cbr_ld_hq 8388616 E..V....... Constant bitrate low delay high quality mode
 cbr_hq 8388624 E..V....... Constant bitrate high quality mode
 vbr_hq 8388640 E..V....... Variable bitrate high quality mode
 -rc-lookahead <int> E..V....... Number of frames to look ahead for rate-control (from 0 to INT_MAX) (default 0)
 -surfaces <int> E..V....... Number of concurrent surfaces (from 0 to 64) (default 0)
 -cbr <boolean> E..V....... Use cbr encoding mode (default false)
 -2pass <boolean> E..V....... Use 2pass encoding mode (default auto)
 -gpu <int> E..V....... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from -2 to INT_MAX) (default any)
 any -1 E..V....... Pick the first device available
 list -2 E..V....... List the available devices
 -delay <int> E..V....... Delay frame output by the given amount of frames (from 0 to INT_MAX) (default INT_MAX)
 -no-scenecut <boolean> E..V....... When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts (default false)
 -forced-idr <boolean> E..V....... If forcing keyframes, force them as IDR frames. (default false)
 -b_adapt <boolean> E..V....... When lookahead is enabled, set this to 0 to disable adaptive B-frame decision (default true)
 -spatial-aq <boolean> E..V....... set to 1 to enable Spatial AQ (default false)
 -spatial_aq <boolean> E..V....... set to 1 to enable Spatial AQ (default false)
 -temporal-aq <boolean> E..V....... set to 1 to enable Temporal AQ (default false)
 -temporal_aq <boolean> E..V....... set to 1 to enable Temporal AQ (default false)
 -zerolatency <boolean> E..V....... Set 1 to indicate zero latency operation (no reordering delay) (default false)
 -nonref_p <boolean> E..V....... Set this to 1 to enable automatic insertion of non-reference P-frames (default false)
 -strict_gop <boolean> E..V....... Set 1 to minimize GOP-to-GOP rate fluctuations (default false)
 -aq-strength <int> E..V....... When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive) (from 1 to 15) (default 8)
 -cq <float> E..V....... Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0)
 -aud <boolean> E..V....... Use access unit delimiters (default false)
 -bluray-compat <boolean> E..V....... Bluray compatibility workarounds (default false)
 -init_qpP <int> E..V....... Initial QP value for P frame (from -1 to 51) (default -1)
 -init_qpB <int> E..V....... Initial QP value for B frame (from -1 to 51) (default -1)
 -init_qpI <int> E..V....... Initial QP value for I frame (from -1 to 51) (default -1)
 -qp <int> E..V....... Constant quantization parameter rate control method (from -1 to 51) (default -1)
 -weighted_pred <int> E..V....... Set 1 to enable weighted prediction (from 0 to 1) (default 0)
 -coder <int> E..V....... Coder type (from -1 to 2) (default default)
 default -1 E..V.......
 auto 0 E..V.......
 cabac 1 E..V.......
 cavlc 2 E..V.......
 ac 1 E..V.......
 vlc 2 E..V.......
 -b_ref_mode <int> E..V....... Use B frames as references (from 0 to 2) (default disabled)
 disabled 0 E..V....... B frames will not be used for reference
 each 1 E..V....... Each B frame will be used for reference
 middle 2 E..V....... Only (number of B frames)/2 will be used for reference
 -a53cc <boolean> E..V....... Use A53 Closed Captions (if available) (default true)
 -dpb_size <int> E..V....... Specifies the DPB size used for encoding (0 means automatic) (from 0 to INT_MAX) (default 0)
 -multipass <int> E..V....... Set the multipass encoding (from 0 to 2) (default disabled)
 disabled 0 E..V....... Single Pass
 qres 1 E..V....... Two Pass encoding is enabled where first Pass is quarter resolution
 fullres 2 E..V....... Two Pass encoding is enabled where first Pass is full resolution
 -ldkfs <int> E..V....... Low delay key frame scale; Specifies the Scene Change frame size increase allowed in case of single frame VBV and CBR (from 0 to 255) (default 0)
</int></int></int></boolean></int></int></int></int></int></int></int></boolean></boolean></float></int></boolean></boolean></boolean></boolean></boolean></boolean></boolean></boolean></boolean></boolean></int></int></boolean></boolean></int></int></int></int></int></int></int>


-
Encoding issue with Lagarith in ffmpeg
20 juin 2022, par tms99I want to edit some old videos that I converted with the Lagarith codec using "ffmpeg - mpdecimate" in Windows. Unfortunately, Lagarith is only allowed for decoding with ffmpeg, not for encoding. Any simple solutions for that ?


Otherwise I have to encode the videos in Huffyuv-codec but then back to Lagarith for another processing step. Can anyone tell me if I'm going to cause any visible or noticeable data loss in this process (Lagarith -> Huffyuv -> Lagarith) ?