
Recherche avancée
Autres articles (35)
-
Supporting all media types
13 avril 2011, parUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
-
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 (...) -
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 (6253)
-
avcodec/ffv1enc : Store run1start_mul_index instead of computing
25 mars, par Michael Niedermayer -
Read multiple frames in demuxer
22 décembre 2024, par AyconI use
FFmpeg.AutoGen
. This is C# wrapper offfmpeg
(7.0) C++ library for reading mediafiles and generate stream of frames for other application.
I want get n frames and hold pointers in memory indefinitely.
However, I am completely confused trying to figure out which API is deprecated and how I can tell ffmpeg to hold the pointers in memory until I tell it to.

I don't want to copy the frame after receiving it if I can avoid it.

I tried many ways.

My last attempt was to receive the frames usingffmpeg.avcodec_send_packet()
,ffmpeg.av_read_frame()
andffmpeg.avcodec_receive_frame()
functions as it is specified in the current manual.

My code fragment for reading frames :

using Core.Backends.FFmpeg.Helpers;
using Core.Backends.FFmpeg.UnsafeWrappers;
using Core.Enums;
using Core.Interfaces;
using FFmpeg.AutoGen.Abstractions;
using System.Diagnostics;
using System.Drawing;

namespace Core.Backends.FFmpeg.Internal;

internal class Video : IVideo
{
 private readonly AVFormatHandler p_format;
 private readonly AVCodecHandler p_codec;
 private readonly AVPacketWrapper p_packet;
 private readonly FramesPool p_framesPool;
 private readonly FramesPool p_framesBufferPool;
 private bool p_disposedValue;

 public Video(VideoMetadata _videoMetadata, AVFormatHandler _format, AVCodecHandler _codec, int _bufferizedFramesCount = 1)
 {
 Duration = _videoMetadata.Duration;
 FrameRate = _videoMetadata.FrameRate;
 FrameSize = _videoMetadata.FrameSize;
 PixelFormat = _videoMetadata.PixelFormat;
 SelectedStreamID = _videoMetadata.SelectedStreamID;
 p_format = _format;
 p_codec = _codec;
 p_packet = new AVPacketWrapper();
 var frame = new AVFrameWrapper(p_format, p_packet);
 p_framesPool = new(frame, _bufferizedFramesCount);
 p_framesBufferPool = new(frame, _bufferizedFramesCount);
 }

 /// <inheritdoc></inheritdoc>
 public long Duration { get; init; }

 /// <inheritdoc></inheritdoc>
 public (int num, int den) FrameRate { get; init; }

 /// <inheritdoc></inheritdoc>
 public Size FrameSize { get; init; }

 /// <inheritdoc></inheritdoc>
 public PixelFormat PixelFormat { get; init; }

 private int SelectedStreamID { get; init; }

 private unsafe int SendPacket(AVPacketWrapper? _packet)
 {
 if (_packet == null)
 return ffmpeg.avcodec_send_packet(p_codec.AVCodecContextPointer, null);

 return ffmpeg.avcodec_send_packet(p_codec.AVCodecContextPointer, _packet.AVPacketPointer);
 }

 private unsafe bool IsSelectedStream(AVPacketWrapper _packet)
 {
 return _packet.AVPacketPointer->stream_index == SelectedStreamID;
 }

 private unsafe int ReadFrame(AVPacketWrapper _packet)
 {
 return ffmpeg.av_read_frame(p_format.AVFormatPointer, _packet.AVPacketPointer);
 }

 private static unsafe void UnrefPacket(AVPacketWrapper _packet) => ffmpeg.av_packet_unref(_packet.AVPacketPointer);

 private IEnumerable<int> ReadToSelectedStream(AVPacketWrapper _packet)
 {
 do
 {
 UnrefPacket(p_packet);
 yield return ReadFrame(_packet);
 } while (!IsSelectedStream(_packet));
 }

 private unsafe void FlushBuffers() => ffmpeg.avcodec_flush_buffers(p_codec.AVCodecContextPointer);

 private IEnumerable<avpacketwrapper> GetNextPacketPrivate()
 {
 try
 {
 while (true)
 {
 foreach (int errorCodeRead in ReadToSelectedStream(p_packet))
 {
 if (errorCodeRead == ffmpeg.AVERROR_EOF)
 break;

 errorCodeRead.ThrowInvalidOperationExceptionIfError();
 }

 int errorCodeSend = SendPacket(p_packet);

 if (errorCodeSend == ffmpeg.AVERROR(ffmpeg.EAGAIN))
 {
 yield return p_packet;
 continue;
 }

 if (errorCodeSend == ffmpeg.AVERROR_EOF)
 {
 yield return p_packet;
 break;
 }

 errorCodeSend.ThrowInvalidOperationExceptionIfError();

 yield return p_packet;
 }

 // Last iteration special case handling
 int errorCodeSendLast = SendPacket(null);

 if (errorCodeSendLast != ffmpeg.AVERROR_EOF)
 errorCodeSendLast.ThrowInvalidOperationExceptionIfError();

 yield return p_packet;
 }
 finally
 {
 UnrefPacket(p_packet);
 FlushBuffers();
 }
 }

 private unsafe int ReceiveFrame(AVFrameWrapper _frame)
 {
 return ffmpeg.avcodec_receive_frame(p_codec.AVCodecContextPointer, _frame.AVFramePointer);
 }

 private unsafe AVFrameWrapper HWFrameCopyIfRequired(AVCodecHandler _codec, AVFrameWrapper _frame, AVFrameWrapper _buffer)
 {
 if (_codec.AVCodecContextPointer->hw_device_ctx != null)
 {
 int errorCode = ffmpeg.av_hwframe_transfer_data(_buffer.AVFramePointer, _frame.AVFramePointer, flags: 0);
 errorCode.ThrowInvalidOperationExceptionIfError();
 return _buffer;
 }

 return _frame;
 }

 private IEnumerable GetNextFramePrivate(AVFrameWrapper _fresh_frame, AVFrameWrapper _fresh_frameBuffer)
 {
 int readCode;

 while (true)
 {
 readCode = ReceiveFrame(_fresh_frame);

 if (readCode == ffmpeg.AVERROR(ffmpeg.EAGAIN) || readCode == ffmpeg.AVERROR_EOF)
 yield break;

 readCode.ThrowInvalidOperationExceptionIfError();
 
 yield return HWFrameCopyIfRequired(p_codec, _fresh_frame, _fresh_frameBuffer);
 }
 }

 private static void RefreshFrames
 (
 IEnumerator<avframewrapper> _framesEnumerator,
 IEnumerator<avframewrapper> _framesBufferEnumerator,
 out AVFrameWrapper _frame,
 out AVFrameWrapper _frameBuffer
 )
 {
 // Catch fresh frame from pool
 Debug.Assert(_framesEnumerator.MoveNext(), "Пул фреймов никогда не должен завершать предоставление фреймов.");
 _frame = _framesEnumerator.Current;

 // Catch fresh frame buffer from pool
 Debug.Assert(_framesBufferEnumerator.MoveNext(), "Пул фреймов никогда не должен завершать предоставление фреймов.");
 _frameBuffer = _framesBufferEnumerator.Current;
 }

 /// <inheritdoc></inheritdoc>
 public IEnumerable GetNextFrame()
 {
 IEnumerator<avframewrapper> framesEnumerator = p_framesPool.GetNextFrame().GetEnumerator();
 IEnumerator<avframewrapper> framesBufferEnumerator = p_framesBufferPool.GetNextFrame().GetEnumerator();
 RefreshFrames(framesEnumerator, framesBufferEnumerator, out AVFrameWrapper fresh_frame, out AVFrameWrapper fresh_frameBuffer);
 foreach (var packet in GetNextPacketPrivate())
 foreach (var frame in GetNextFramePrivate(fresh_frame, fresh_frameBuffer))
 {
 yield return frame;
 RefreshFrames(framesEnumerator, framesBufferEnumerator, out fresh_frame, out fresh_frameBuffer);
 }
 }

 protected virtual void Dispose(bool disposing)
 {
 if (!p_disposedValue)
 {
 if (disposing)
 {
 }

 p_packet.Dispose();
 p_framesPool.Flush();
 p_framesBufferPool.Flush();

 p_disposedValue = true;
 }
 }

 ~Video()
 {
 Dispose(disposing: false);
 }

 public void Dispose()
 {
 Dispose(disposing: true);
 GC.SuppressFinalize(this);
 }
}
</avframewrapper></avframewrapper></avframewrapper></avframewrapper></avpacketwrapper></int>


My
FramesPool
class :

using Core.Backends.FFmpeg.UnsafeWrappers;
using FFmpeg.AutoGen.Abstractions;

namespace Core.Backends.FFmpeg.Internal;

internal class FramesPool
{
 private readonly AVFrameWrapper p_frameWrapper;
 private readonly Queue<avframewrapper> p_frames;
 private readonly int p_count;

 public FramesPool(AVFrameWrapper _initframeWrapper, int _count = 1)
 {
 p_frameWrapper = _initframeWrapper;
 p_frames = new(_count);
 p_frames.Enqueue(p_frameWrapper);
 p_count = _count;
 }

 private static unsafe void UnrefFrame(AVFrameWrapper _frame) => ffmpeg.av_frame_unref(_frame.AVFramePointer);

 public IEnumerable<avframewrapper> GetNextFrame()
 {
 // First frame case
 UnrefFrame(p_frameWrapper);
 yield return p_frameWrapper;

 while (true)
 {
 if (p_frames.Count < p_count)
 {
 var new_frame = p_frameWrapper.Clone();
 p_frames.Enqueue(new_frame);
 yield return new_frame;
 }
 else
 {
 var frame = p_frames.Dequeue();
 UnrefFrame(frame);
 yield return frame;
 p_frames.Enqueue(frame);
 }
 }
 }

 public void Flush()
 {
 foreach(var frame in p_frames)
 {
 UnrefFrame(frame);
 frame.Dispose();
 }

 p_frames.Clear();
 }
}
</avframewrapper></avframewrapper>


Additional calls, among others :


ffmpeg.avformat_alloc_context();
ffmpeg.avformat_open_input(pptr, p_filePath, null, null);
ffmpeg.av_hwdevice_ctx_create(&p_avCodecHandler!.AVCodecContextPointer->hw_device_ctx, strongDevice, null, null, 0);
ffmpeg.av_find_best_stream(/*args*/);
ffmpeg.avcodec_alloc_context3(p_avCodec);
ffmpeg.avcodec_parameters_to_context(/*args*/);
ffmpeg.avcodec_open2(/*args*/);



Function
ffmpeg.av_hwframe_transfer_data(_buffer.AVFramePointer, _frame.AVFramePointer, flags: 0);
returns "-22" (message : "Invalid argument")

Please, help me)


-
bsf : use standard include paths
9 avril 2024, par Andrew Kelleybsf : use standard include paths
Removes the special -I flag specified in the avcodec/bsf/ subdirectory.
This makes code copy-pastable to other parts of the ffmpeg codebase, as
well as simplifying the build script.It also reduces ambiguity, since there are many instances of same-named
header files existing in both libavformat/ and libavcodec/
subdirectories.Reviewed-by : Lynne <dev@lynne.ee>
Signed-off-by : James Almer <jamrial@gmail.com>- [DH] libavcodec/bsf/Makefile
- [DH] libavcodec/bsf/aac_adtstoasc.c
- [DH] libavcodec/bsf/av1_frame_merge.c
- [DH] libavcodec/bsf/av1_frame_split.c
- [DH] libavcodec/bsf/av1_metadata.c
- [DH] libavcodec/bsf/chomp.c
- [DH] libavcodec/bsf/dca_core.c
- [DH] libavcodec/bsf/dts2pts.c
- [DH] libavcodec/bsf/dump_extradata.c
- [DH] libavcodec/bsf/dv_error_marker.c
- [DH] libavcodec/bsf/eac3_core.c
- [DH] libavcodec/bsf/evc_frame_merge.c
- [DH] libavcodec/bsf/extract_extradata.c
- [DH] libavcodec/bsf/filter_units.c
- [DH] libavcodec/bsf/h264_metadata.c
- [DH] libavcodec/bsf/h264_mp4toannexb.c
- [DH] libavcodec/bsf/h264_redundant_pps.c
- [DH] libavcodec/bsf/h265_metadata.c
- [DH] libavcodec/bsf/h266_metadata.c
- [DH] libavcodec/bsf/hapqa_extract.c
- [DH] libavcodec/bsf/hevc_mp4toannexb.c
- [DH] libavcodec/bsf/imx_dump_header.c
- [DH] libavcodec/bsf/media100_to_mjpegb.c
- [DH] libavcodec/bsf/mjpeg2jpeg.c
- [DH] libavcodec/bsf/mjpega_dump_header.c
- [DH] libavcodec/bsf/movsub.c
- [DH] libavcodec/bsf/mpeg2_metadata.c
- [DH] libavcodec/bsf/mpeg4_unpack_bframes.c
- [DH] libavcodec/bsf/noise.c
- [DH] libavcodec/bsf/null.c
- [DH] libavcodec/bsf/opus_metadata.c
- [DH] libavcodec/bsf/pcm_rechunk.c
- [DH] libavcodec/bsf/pgs_frame_merge.c
- [DH] libavcodec/bsf/prores_metadata.c
- [DH] libavcodec/bsf/remove_extradata.c
- [DH] libavcodec/bsf/setts.c
- [DH] libavcodec/bsf/showinfo.c
- [DH] libavcodec/bsf/trace_headers.c
- [DH] libavcodec/bsf/truehd_core.c
- [DH] libavcodec/bsf/vp9_metadata.c
- [DH] libavcodec/bsf/vp9_raw_reorder.c
- [DH] libavcodec/bsf/vp9_superframe.c
- [DH] libavcodec/bsf/vp9_superframe_split.c
- [DH] libavcodec/bsf/vvc_mp4toannexb.c