
Recherche avancée
Médias (1)
-
The Great Big Beautiful Tomorrow
28 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Texte
Autres articles (81)
-
Organiser par catégorie
17 mai 2013, parDans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...) -
Récupération d’informations sur le site maître à l’installation d’une instance
26 novembre 2010, parUtilité
Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...) -
Le plugin : Podcasts.
14 juillet 2010, parLe problème du podcasting est à nouveau un problème révélateur de la normalisation des transports de données sur Internet.
Deux formats intéressants existent : Celui développé par Apple, très axé sur l’utilisation d’iTunes dont la SPEC est ici ; Le format "Media RSS Module" qui est plus "libre" notamment soutenu par Yahoo et le logiciel Miro ;
Types de fichiers supportés dans les flux
Le format d’Apple n’autorise que les formats suivants dans ses flux : .mp3 audio/mpeg .m4a audio/x-m4a .mp4 (...)
Sur d’autres sites (4846)
-
Concert MP4 Version - FFmpeg
25 avril 2017, par LuzwitzI have two mp4 File :
- out.mp4 : ISO Media, MP4 Base Media v1 [IS0 14496-12:2003]
- video/rio2016/finale/brasse/200.mp4 : ISO Media, MP4 v2 [ISO 14496-14]
How can I convert 1 to 2 (mp41 to mp42) ?
Thanks !
-
Getting Access Violations Exceptions in FFmpeg when trying to free IO buffer
26 juin 2015, par PatrikI’ve been trying to create an audio stream extractor/demuxer using FFmpeg.AutoGen and C#. While the code actually works (in the sense that it extracts the audio stream correctly), I can’t seem to clean up the resources afterwards. Whenever I try to free my input buffer (allocated using av_malloc) I get an Access Violation Exception, and if I don’t free it, I seem to be leaking memory corresponding to the size of the allocated input buffer.
This is my code (from a console application I used for testing) :
class Program
{
static void Main(string[] args)
{
using (var videoStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FFmpeg.Demux.test.mp4"))
using (MemoryStream output = new MemoryStream())
{
FFmpegAudioExtractor audioExtractor = new FFmpegAudioExtractor();
audioExtractor.Extract(videoStream, output);
Debug.Assert(1331200 == output.Length);
//File.WriteAllBytes(@"c:\temp\out.pcm", output.ToArray());
}
Console.WriteLine("Done");
Console.ReadLine();
}
}
public class FFmpegAudioExtractor
{
public FFmpegAudioExtractor()
{
FFmpegInvoke.av_register_all();
FFmpegInvoke.avcodec_register_all();
}
public unsafe void Extract(Stream input, Stream output)
{
AVFormatContext* inFormatContextPtr = null;
int inFomatContextOpenResult = -1;
byte* inIoBuffer = null;
AVIOContext* inIoContextPtr = null;
SwrContext* swrContextPtr = null;
AVFrame* inFramePtr = null;
AVFrame* outFramePtr = null;
AVCodecContext* inCodecContextPtr = null;
try
{
/* 1 */
inFormatContextPtr = FFmpegInvoke.avformat_alloc_context();
if (inFormatContextPtr == null)
throw new ApplicationException("Failed to allocate the input format context (AVFormatContext).");
// HACK this should alloc a fixed buffer and use callbacks to fill it
if (input.Length > int.MaxValue)
throw new ArgumentException("Data too large.", "input");
// TEST alloc a 10MB buffer to make the memory leak real obvious
int inIoBufferSize = 1024 * 1024 * 10; //(int)input.Length;
/* 2 */
inIoBuffer = (byte*)FFmpegInvoke.av_malloc((uint)inIoBufferSize);
if (inIoBuffer == null)
throw new ApplicationException("Failed to allocate the input IO buffer.");
// HACK continued, fill buffer
IntPtr inIoBufferPtr = new IntPtr(inIoBuffer);
byte[] buffer = new byte[4096];
int read, offset = 0;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
Marshal.Copy(buffer, 0, inIoBufferPtr + offset, read);
offset += read;
}
/* 3 */
inIoContextPtr = FFmpegInvoke.avio_alloc_context((sbyte*)inIoBuffer,
inIoBufferSize,
0 /* writable */,
null,
IntPtr.Zero,
IntPtr.Zero,
IntPtr.Zero);
if (inIoContextPtr == null)
throw new ApplicationException("Failed to allocate the input IO context (AVIOContext).");
// configure the format context to use our custom IO contect
inFormatContextPtr->pb = inIoContextPtr;
inFormatContextPtr->flags = FFmpegInvoke.AVFMT_FLAG_CUSTOM_IO;
/* 35 */
inFomatContextOpenResult = FFmpegInvoke.avformat_open_input(&inFormatContextPtr, "", null, null);
if (inFomatContextOpenResult != 0)
throw new ApplicationException("Could not open input: " + inFomatContextOpenResult.ToString(CultureInfo.InvariantCulture));
// retrieve stream information
int avformatFindStreamInfoResult = FFmpegInvoke.avformat_find_stream_info(inFormatContextPtr, null);
if (avformatFindStreamInfoResult < 0)
throw new ApplicationException("Failed to locate stream info: " + avformatFindStreamInfoResult.ToString(CultureInfo.InvariantCulture));
// find audio stream
int inAudioStreamIndex = FFmpegInvoke.av_find_best_stream(inFormatContextPtr,
AVMediaType.AVMEDIA_TYPE_AUDIO,
-1 /* wanted_stream_nb */,
-1 /* related_stream */,
null /* [out] decoder */,
0 /* flags */);
if (inAudioStreamIndex < 0)
throw new ApplicationException("Failed to find audio stream: " + inAudioStreamIndex.ToString(CultureInfo.InvariantCulture));
// get audio stream pointer
AVStream* inAudioStreamPtr = inFormatContextPtr->streams[inAudioStreamIndex];
Contract.Assume(inAudioStreamPtr != null);
// find the decoder
AVCodec* inCodecPtr = FFmpegInvoke.avcodec_find_decoder(inAudioStreamPtr->codec->codec_id);
if (inCodecPtr == null)
throw new ApplicationException("Failed to find decoder with codec_id: " + inAudioStreamPtr->codec->codec_id.ToString());
/* 36 */
inCodecContextPtr = FFmpegInvoke.avcodec_alloc_context3(inCodecPtr);
if (FFmpegInvoke.avcodec_copy_context(inCodecContextPtr, inAudioStreamPtr->codec) != 0)
throw new ApplicationException("Failed to copy context.");
// open codec
/* 37 */
if (FFmpegInvoke.avcodec_open2(inCodecContextPtr, inCodecPtr, null) < 0)
{
string codecName = Marshal.PtrToStringAuto(new IntPtr(inCodecPtr->name));
throw new Exception("Failed to open codec: " + codecName);
}
// alloc frame
/* 38 */
inFramePtr = FFmpegInvoke.av_frame_alloc();
if (inFramePtr == null)
throw new ApplicationException("Could not allocate frame");
// initialize packet, set data to NULL, let the demuxer fill it
AVPacket packet = new AVPacket();
AVPacket* packetPtr = &packet;
FFmpegInvoke.av_init_packet(packetPtr);
packetPtr->data = null;
packetPtr->size = 0;
// alloc SWR
/* 4 */
swrContextPtr = FFmpegInvoke.swr_alloc();
AVSampleFormat outSampleFormat = AVSampleFormat.AV_SAMPLE_FMT_S16;
long outChannelLayout = FFmpegInvoke.AV_CH_FRONT_LEFT | FFmpegInvoke.AV_CH_FRONT_RIGHT;
// configure SWR
FFmpegInvoke.av_opt_set_sample_fmt(swrContextPtr, "in_sample_fmt", inCodecContextPtr->sample_fmt, 0);
FFmpegInvoke.av_opt_set_sample_fmt(swrContextPtr, "out_sample_fmt", outSampleFormat, 0);
// setting the in_channel_layout seems to break things
//FFmpegInvoke.av_opt_set_channel_layout(swrContextPtr, "in_channel_layout", (long)inCodecContextPtr->channel_layout, 0);
FFmpegInvoke.av_opt_set_channel_layout(swrContextPtr, "out_channel_layout", outChannelLayout, 0);
FFmpegInvoke.av_opt_set_int(swrContextPtr, "in_sample_rate", inCodecContextPtr->sample_rate, 0);
FFmpegInvoke.av_opt_set_int(swrContextPtr, "out_sample_rate", 44100, 0);
// allock output frane
/* 45 */
outFramePtr = FFmpegInvoke.av_frame_alloc();
outFramePtr->channel_layout = (ulong)outChannelLayout;
outFramePtr->sample_rate = 44100;
outFramePtr->format = (int)outSampleFormat;
// config done, init
FFmpegInvoke.swr_init(swrContextPtr);
bool frameFinished;
// read frames from the file
while (FFmpegInvoke.av_read_frame(inFormatContextPtr, packetPtr) >= 0)
{
AVPacket* origPacketPtr = packetPtr;
try
{
if (packetPtr->stream_index != inAudioStreamIndex)
continue;
do
{
byte[] decodedFrame;
int decodedBytes = this.DecodePacket(inCodecContextPtr,
packetPtr,
inFramePtr,
swrContextPtr,
outFramePtr,
out frameFinished,
out decodedFrame);
if (decodedBytes < 0)
break;
output.Write(decodedFrame, 0, decodedFrame.Length);
packetPtr->data += decodedBytes;
packetPtr->size -= decodedBytes;
} while (packetPtr->size > 0);
}
finally
{
FFmpegInvoke.av_free_packet(origPacketPtr);
}
}
// flush cached frames
packetPtr->data = null;
packetPtr->size = 0;
do
{
byte[] decodedFrame;
this.DecodePacket(inCodecContextPtr, packetPtr, inFramePtr, swrContextPtr, outFramePtr, out frameFinished, out decodedFrame);
if (decodedFrame != null)
output.Write(decodedFrame, 0, decodedFrame.Length);
} while (frameFinished);
}
finally
{
/* 45 */
if (outFramePtr != null)
FFmpegInvoke.av_frame_free(&outFramePtr);
/* 4 */
if (swrContextPtr != null)
FFmpegInvoke.swr_free(&swrContextPtr);
/* 38 */
if (inFramePtr != null)
FFmpegInvoke.av_frame_free(&inFramePtr);
/* 37 */
if (inCodecContextPtr != null)
FFmpegInvoke.avcodec_close(inCodecContextPtr);
/* 36 */
if (inCodecContextPtr != null)
FFmpegInvoke.avcodec_free_context(&inCodecContextPtr);
/* 35 */
if (inFomatContextOpenResult == 0)
FFmpegInvoke.avformat_close_input(&inFormatContextPtr);
/* 3 */
if (inIoContextPtr != null)
FFmpegInvoke.av_freep(&inIoContextPtr);
//* 2 */
if (inIoBuffer != null)
FFmpegInvoke.av_freep(&inIoBuffer);
/* 1 */
// This is called by avformat_close_input
if (inFormatContextPtr != null)
FFmpegInvoke.avformat_free_context(inFormatContextPtr);
}
}
private unsafe int DecodePacket(AVCodecContext* audioDecoderContextPtr, AVPacket* packetPtr, AVFrame* inFramePtr, SwrContext* swrContextPtr, AVFrame* outFramePtr, out bool frameDecoded, out byte[] decodedFrame)
{
decodedFrame = null;
/* decode audio frame */
int gotFrame;
int readBytes = FFmpegInvoke.avcodec_decode_audio4(audioDecoderContextPtr, inFramePtr, &gotFrame, packetPtr);
if (readBytes < 0)
throw new ApplicationException("Error decoding audio frame: " + readBytes.ToString(CultureInfo.InvariantCulture));
frameDecoded = gotFrame != 0;
/* Some audio decoders decode only part of the packet, and have to be
* called again with the remainder of the packet data.
* Sample: fate-suite/lossless-audio/luckynight-partial.shn
* Also, some decoders might over-read the packet. */
int decoded = Math.Min(readBytes, packetPtr->size);
if (frameDecoded)
{
if (FFmpegInvoke.swr_convert_frame(swrContextPtr, outFramePtr, inFramePtr) != 0)
throw new ApplicationException("Failed to convert frame.");
long delay;
do
{
int unpaddedLinesize = outFramePtr->nb_samples * outFramePtr->channels * FFmpegInvoke.av_get_bytes_per_sample((AVSampleFormat)outFramePtr->format);
IntPtr dataPtr = new IntPtr(outFramePtr->extended_data[0]);
decodedFrame = new byte[unpaddedLinesize];
Marshal.Copy(dataPtr, decodedFrame, 0, unpaddedLinesize);
// check if we have more samples to convert for this frame
delay = FFmpegInvoke.swr_get_delay(swrContextPtr, 44100);
if (delay > 0)
{
if (FFmpegInvoke.swr_convert_frame(swrContextPtr, outFramePtr, null) != 0)
throw new ApplicationException("Failed to convert frame.");
}
} while (delay > 0);
}
return decoded;
}
}The failing line is :
FFmpegInvoke.av_freep(&inIoBuffer);
-
Dockerized ffmpeg stops for no reason
2 mai 2023, par Arthur AttoutI'm trying to fire up a container that reads a video stream via
ffmpeg
and saves the stream as 30 seconds segments.

When I run the container, it stops after 20-ish seconds and returns with no error.


Here is my Dockerfile


FROM linuxserver/ffmpeg
ENTRYPOINT ffmpeg -i rtsp://192.168.1.85:8554/camera -f v4l2 -c copy -reset_timestamps 1 -map 0 -f segment -segment_time 30 -segment_format mp4 "output/out%03d.mp4" -loglevel debug



Here is the output when I run
sudo docker run -it --rm -v /data/camera:/output --name camera_recorder camera_recorder:latest


[+] Building 1.8s (5/5) FINISHED
 => [internal] load build definition from Dockerfile 0.3s
 => => transferring dockerfile: 777B 0.0s
 => [internal] load .dockerignore 0.5s
 => => transferring context: 2B 0.0s
 => [internal] load metadata for docker.io/linuxserver/ffmpeg:latest 1.2s
 => CACHED [1/1] FROM docker.io/linuxserver/ffmpeg@sha256:823c611e0af82b864608c21d96bf363403310d92f154e238f6d51fe3d783e53b 0.0s
 => exporting to image 0.1s
 => => exporting layers 0.0s
 => => writing image sha256:f0509ccf0b07ff53d4aafa0d3b80fd50ed53e96db906c9a1e0e8c44e163dce94 0.1s
 => => naming to docker.io/library/camera_recorder 0.0s
ffmpeg version 5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
 built with gcc 11 (Ubuntu 11.3.0-1ubuntu1~22.04)
 configuration: --disable-debug --disable-doc --disable-ffplay --enable-ffprobe --enable-cuvid --enable-gpl --enable-libaom --enable-libass --enable-libfdk_aac --enable-libfreetype --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libxml2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-nonfree --enable-nvdec --enable-nvenc --enable-opencl --enable-openssl --enable-small --enable-stripping --enable-vaapi --enable-vdpau --enable-version3
 libavutil 57. 28.100 / 57. 28.100
 libavcodec 59. 37.100 / 59. 37.100
 libavformat 59. 27.100 / 59. 27.100
 libavdevice 59. 7.100 / 59. 7.100
 libavfilter 8. 44.100 / 8. 44.100
 libswscale 6. 7.100 / 6. 7.100
 libswresample 4. 7.100 / 4. 7.100
 libpostproc 56. 6.100 / 56. 6.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'rtsp://192.168.1.85:8554/camera'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'v4l2'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-reset_timestamps' ... matched as AVOption 'reset_timestamps' with argument '1'.
Reading option '-map' ... matched as option 'map' (set input stream mapping) with argument '0'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'segment'.
Reading option '-segment_time' ... matched as AVOption 'segment_time' with argument '30'.
Reading option '-segment_format' ... matched as AVOption 'segment_format' with argument 'mp4'.
Reading option 'output/out%03d.mp4' ... matched as output url.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input url rtsp://192.168.1.85:8554/camera.
Successfully parsed a group of options.
Opening an input file: rtsp://192.168.1.85:8554/camera.
[tcp @ 0x55c15e3eb040] No default whitelist set
[tcp @ 0x55c15e3eb040] Original list of addresses:
[tcp @ 0x55c15e3eb040] Address 192.168.1.85 port 8554
[tcp @ 0x55c15e3eb040] Interleaved list of addresses:
[tcp @ 0x55c15e3eb040] Address 192.168.1.85 port 8554
[tcp @ 0x55c15e3eb040] Starting connection attempt to 192.168.1.85 port 8554
[tcp @ 0x55c15e3eb040] Successfully connected to 192.168.1.85 port 8554
[rtsp @ 0x55c15e3e8300] SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=Stream
c=IN IP4 0.0.0.0
t=0 0
m=video 0 RTP/AVP 96
a=control:rtsp://192.168.1.85:8554/camera/trackID=0
a=rtpmap:96 MP4V-ES/90000
a=fmtp:96 config=000001B001000001B58913000001000000012000C48D88002D3C04871443000001B24C61766335392E33372E313030; profile-level-id=1

[rtsp @ 0x55c15e3e8300] video codec set to: mpeg4
[rtp @ 0x55c15e3ef600] No default whitelist set
[udp @ 0x55c15e3f0200] No default whitelist set
[udp @ 0x55c15e3f0200] end receive buffer size reported is 425984
[udp @ 0x55c15e3eff40] No default whitelist set
[udp @ 0x55c15e3eff40] end receive buffer size reported is 425984
[rtsp @ 0x55c15e3e8300] setting jitter buffer size to 500
[rtsp @ 0x55c15e3e8300] hello state=0
[rtsp @ 0x55c15e3e8300] Could not find codec parameters for stream 0 (Video: mpeg4, 1 reference frame, none(left), 1920x1080 [SAR 1:1 DAR 16:9], 1/5): unspecified pixel format
Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
Input #0, rtsp, from 'rtsp://192.168.1.85:8554/camera':
 Metadata:
 title : Stream
 Duration: N/A, bitrate: N/A
 Stream #0:0, 0, 1/90000: Video: mpeg4, 1 reference frame, none(left), 1920x1080 [SAR 1:1 DAR 16:9], 0/1, 5 tbr, 90k tbn
Successfully opened the file.
Parsing a group of options: output url output/out%03d.mp4.
Applying option f (force format) with argument v4l2.
Applying option c (codec name) with argument copy.
Applying option map (set input stream mapping) with argument 0.
Applying option f (force format) with argument segment.
Successfully parsed a group of options.
Opening an output file: output/out%03d.mp4.
Successfully opened the file.
[segment @ 0x55c15e415a80] Selected stream id:0 type:video
[segment @ 0x55c15e415a80] Opening 'output/out000.mp4' for writing
[file @ 0x55c15e42d840] Setting default whitelist 'file,crypto,data'
Output #0, segment, to 'output/out%03d.mp4':
 Metadata:
 title : Stream
 encoder : Lavf59.27.100
 Stream #0:0, 0, 1/10240: Video: mpeg4, 1 reference frame, none(left), 1920x1080 (0x0) [SAR 1:1 DAR 16:9], 0/1, q=2-31, 5 tbr, 10240 tbn
Stream mapping:
 Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
No more output streams to write to, finishing.:00.00 bitrate=N/A speed= 0x
[segment @ 0x55c15e415a80] segment:'output/out000.mp4' count:0 ended
[AVIOContext @ 0x55c15e42d8c0] Statistics: 292 bytes written, 2 seeks, 3 writeouts
frame= 0 fps=0.0 q=-1.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (rtsp://192.168.1.85:8554/camera):
 Input stream #0:0 (video): 0 packets read (0 bytes);
 Total: 0 packets (0 bytes) demuxed
Output file #0 (output/out%03d.mp4):
 Output stream #0:0 (video): 0 packets muxed (0 bytes);
 Total: 0 packets (0 bytes) muxed
0 frames successfully decoded, 0 decoding errors



Additional info :


- 

- The stream is up and running.
ffplay rtsp://192.168.1.85:8554/camera
opens normally - The exact command (from
ENTRYPOINT
) on the host, works perfectly fine (it generates files for every 30 seconds). - From inside the container, I can ping 192.168.1.85 (it is actually
localhost
) - Setting
-analyzeduration 1000
does not fix the issue










Why is the container stopping for no reason ?


- The stream is up and running.