
Recherche avancée
Médias (1)
-
Revolution of Open-source and film making towards open film making
6 octobre 2011, par
Mis à jour : Juillet 2013
Langue : English
Type : Texte
Autres articles (99)
-
Publier sur MédiaSpip
13 juin 2013Puis-je poster des contenus à partir d’une tablette Ipad ?
Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir -
Emballe médias : à quoi cela sert ?
4 février 2011, parCe plugin vise à gérer des sites de mise en ligne de documents de tous types.
Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ; -
Les formats acceptés
28 janvier 2010, parLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...)
Sur d’autres sites (5470)
-
Using Accord.Video.FFMPEG, I get parameter is not valid exception. How to solve it ?
14 avril 2023, par Sheron BlumentalI want to extract all the frames from a mp4 video file and display them on a PictureBox.


The original code comes from this Q&A :

How to time the presentation and extraction of frames from a video file ?

The exception happens after clicking the start button on the line :


var frame = videoReader.ReadVideoFrame();



the message


System.ArgumentException
 HResult=0x80070057
 Message=Parameter is not valid.
 Source=System.Drawing
 StackTrace:
 at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
 at Accord.Video.FFMPEG.VideoFileReader.DecodeVideoFrame(BitmapData bitmapData)
 at Accord.Video.FFMPEG.VideoFileReader.readVideoFrame(Int32 frameIndex, BitmapData output)
 at Accord.Video.FFMPEG.VideoFileReader.ReadVideoFrame()
 at Extract_Frames.Form1.<getvideoframesasync>d__15.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 114
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
 at Extract_Frames.Form1.d__17.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 151
</getvideoframesasync>


the full code


using Accord.IO;
using Accord.Video;
using Accord.Video.FFMPEG;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Extract_Frames
{
 public partial class Form1 : Form
 {
 Bitmap frame = null;
 Graphics frameGraphics = null;
 bool isVideoRunning = false;
 IProgress<bitmap> videoProgress = null;
 private CancellationTokenSource cts = null;
 private readonly object syncRoot = new object();
 private static long pause = 0;
 private int frameRate = 0;
 private List<bitmap> frames = new List<bitmap>();
 string fileName;

 public Form1()
 {
 InitializeComponent();
 
 }

 private void Form1_Load(object sender, EventArgs e)
 {

 }

 private void StopPlayback(bool cancel)
 {
 lock (syncRoot)
 {
 if (cancel) cts?.Cancel();
 cts?.Dispose();
 cts = null;
 }
 }

 int counter =1;
 private void Updater(Bitmap videoFrame)
 {
 frames.Add(videoFrame);

 label1.Text = "Current Frame Number : " + counter;
 trackBar1.Value = counter;
 counter++;

 //Size size = new Size(videoFrame.Width, videoFrame.Height);
 //pictureBox1.ClientSize = size;
 using (videoFrame) frameGraphics.DrawImage(videoFrame, Point.Empty);

 pictureBox1.Invalidate();
 }

 private async Task GetVideoFramesAsync(IProgress<bitmap> updater, string fileName, int intervalMs, CancellationToken token = default)
 {
 using (var videoReader = new VideoFileReader())
 {
 if (token.IsCancellationRequested) return;
 videoReader.Open(fileName);

 videoReader.ReadVideoFrame(1);
 trackBar1.Value = 1;

 label1.Text = "Current Frame Number : " + counter.ToString();

 while (true)
 {
 if (Interlocked.Read(ref pause) == 0)
 {
 var frame = videoReader.ReadVideoFrame();

 if (token.IsCancellationRequested || frame is null) break;
 updater.Report(frame);
 }
 await Task.Delay(frameRate).ConfigureAwait(false);
 }
 }
 }

 private void trackBar2_Scroll(object sender, EventArgs e)
 {
 frameRate = trackBar2.Value / 25;
 }

 private async void buttonStart_Click(object sender, EventArgs e)
 {
 string fileName = textBox1.Text;

 if (isVideoRunning) return;
 isVideoRunning = true;

 using (var videoReader = new VideoFileReader())
 {
 videoReader.Open(fileName);
 frame = new Bitmap(videoReader.Width + 2, videoReader.Height + 2);
 trackBar1.Maximum = (int)videoReader.FrameCount;
 }

 videoProgress = new Progress<bitmap>((bitmap) => Updater(bitmap));
 cts = new CancellationTokenSource();
 pictureBox1.Image = frame;
 try
 {
 frameGraphics = Graphics.FromImage(frame);
 // Set the fame rate to 25 frames per second
 //int frameRate = 1000 / 25;
 await GetVideoFramesAsync(videoProgress, fileName, frameRate, cts.Token);
 }
 finally
 {
 frameGraphics?.Dispose();
 StopPlayback(false);
 isVideoRunning = false;
 }
 }

 private void buttonPause_Click(object sender, EventArgs e)
 {
 if (pause == 0)
 {
 buttonPause.Text = "Resume";
 Interlocked.Increment(ref pause);
 }
 else
 {
 Interlocked.Decrement(ref pause);
 buttonPause.Text = "Pause";
 }
 }

 private void buttonStop_Click(object sender, EventArgs e)
 {
 StopPlayback(true);
 }

 protected override void OnFormClosing(FormClosingEventArgs e)
 {
 if (isVideoRunning) StopPlayback(true);
 pictureBox1.Image?.Dispose();
 base.OnFormClosing(e);
 }

 private void pictureBox1_Paint(object sender, PaintEventArgs e)
 {
 ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
 }

 private void trackBar1_Scroll(object sender, EventArgs e)
 {
 pictureBox1.Image = frames[trackBar1.Value];
 }

 private void button1_Click(object sender, EventArgs e)
 {
 using (OpenFileDialog openFileDialog = new OpenFileDialog())
 {
 openFileDialog.InitialDirectory = "c:\\";
 openFileDialog.Filter = "video files (*.mp4)|*.mp4|All files (*.*)|*.*";
 openFileDialog.FilterIndex = 2;
 openFileDialog.RestoreDirectory = true;

 if (openFileDialog.ShowDialog() == DialogResult.OK)
 {
 //Get the path of specified file
 textBox1.Text = openFileDialog.FileName;
 }
 }
 }
 }
}
</bitmap></bitmap></bitmap></bitmap></bitmap>


-
using Accord.Video.FFMPEG aka(AForge) give exception error paramter is not valid. how to solve it ?
12 avril 2023, par Sheron BlumentalI want to extract all the frames from a mp4 video file and display them on a pictureBox.


The exception happens after clicking the start button on the line :


var frame = videoReader.ReadVideoFrame();



the message


System.ArgumentException
 HResult=0x80070057
 Message=Parameter is not valid.
 Source=System.Drawing
 StackTrace:
 at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
 at Accord.Video.FFMPEG.VideoFileReader.DecodeVideoFrame(BitmapData bitmapData)
 at Accord.Video.FFMPEG.VideoFileReader.readVideoFrame(Int32 frameIndex, BitmapData output)
 at Accord.Video.FFMPEG.VideoFileReader.ReadVideoFrame()
 at Extract_Frames.Form1.<getvideoframesasync>d__15.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 114
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
 at Extract_Frames.Form1.d__17.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 151
</getvideoframesasync>


the full code


using Accord.IO;
using Accord.Video;
using Accord.Video.FFMPEG;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Extract_Frames
{
 public partial class Form1 : Form
 {
 Bitmap frame = null;
 Graphics frameGraphics = null;
 bool isVideoRunning = false;
 IProgress<bitmap> videoProgress = null;
 private CancellationTokenSource cts = null;
 private readonly object syncRoot = new object();
 private static long pause = 0;
 private int frameRate = 0;
 private List<bitmap> frames = new List<bitmap>();
 string fileName;

 public Form1()
 {
 InitializeComponent();
 
 }

 private void Form1_Load(object sender, EventArgs e)
 {

 }

 private void StopPlayback(bool cancel)
 {
 lock (syncRoot)
 {
 if (cancel) cts?.Cancel();
 cts?.Dispose();
 cts = null;
 }
 }

 int counter =1;
 private void Updater(Bitmap videoFrame)
 {
 frames.Add(videoFrame);

 label1.Text = "Current Frame Number : " + counter;
 trackBar1.Value = counter;
 counter++;

 //Size size = new Size(videoFrame.Width, videoFrame.Height);
 //pictureBox1.ClientSize = size;
 using (videoFrame) frameGraphics.DrawImage(videoFrame, Point.Empty);

 pictureBox1.Invalidate();
 }

 private async Task GetVideoFramesAsync(IProgress<bitmap> updater, string fileName, int intervalMs, CancellationToken token = default)
 {
 using (var videoReader = new VideoFileReader())
 {
 if (token.IsCancellationRequested) return;
 videoReader.Open(fileName);

 videoReader.ReadVideoFrame(1);
 trackBar1.Value = 1;

 label1.Text = "Current Frame Number : " + counter.ToString();

 while (true)
 {
 if (Interlocked.Read(ref pause) == 0)
 {
 var frame = videoReader.ReadVideoFrame();

 if (token.IsCancellationRequested || frame is null) break;
 updater.Report(frame);
 }
 await Task.Delay(frameRate).ConfigureAwait(false);
 }
 }
 }

 private void trackBar2_Scroll(object sender, EventArgs e)
 {
 frameRate = trackBar2.Value / 25;
 }

 private async void buttonStart_Click(object sender, EventArgs e)
 {
 string fileName = textBox1.Text;

 if (isVideoRunning) return;
 isVideoRunning = true;

 using (var videoReader = new VideoFileReader())
 {
 videoReader.Open(fileName);
 frame = new Bitmap(videoReader.Width + 2, videoReader.Height + 2);
 trackBar1.Maximum = (int)videoReader.FrameCount;
 }

 videoProgress = new Progress<bitmap>((bitmap) => Updater(bitmap));
 cts = new CancellationTokenSource();
 pictureBox1.Image = frame;
 try
 {
 frameGraphics = Graphics.FromImage(frame);
 // Set the fame rate to 25 frames per second
 //int frameRate = 1000 / 25;
 await GetVideoFramesAsync(videoProgress, fileName, frameRate, cts.Token);
 }
 finally
 {
 frameGraphics?.Dispose();
 StopPlayback(false);
 isVideoRunning = false;
 }
 }

 private void buttonPause_Click(object sender, EventArgs e)
 {
 if (pause == 0)
 {
 buttonPause.Text = "Resume";
 Interlocked.Increment(ref pause);
 }
 else
 {
 Interlocked.Decrement(ref pause);
 buttonPause.Text = "Pause";
 }
 }

 private void buttonStop_Click(object sender, EventArgs e)
 {
 StopPlayback(true);
 }

 protected override void OnFormClosing(FormClosingEventArgs e)
 {
 if (isVideoRunning) StopPlayback(true);
 pictureBox1.Image?.Dispose();
 base.OnFormClosing(e);
 }

 private void pictureBox1_Paint(object sender, PaintEventArgs e)
 {
 ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);
 }

 private void trackBar1_Scroll(object sender, EventArgs e)
 {
 pictureBox1.Image = frames[trackBar1.Value];
 }

 private void button1_Click(object sender, EventArgs e)
 {
 using (OpenFileDialog openFileDialog = new OpenFileDialog())
 {
 openFileDialog.InitialDirectory = "c:\\";
 openFileDialog.Filter = "video files (*.mp4)|*.mp4|All files (*.*)|*.*";
 openFileDialog.FilterIndex = 2;
 openFileDialog.RestoreDirectory = true;

 if (openFileDialog.ShowDialog() == DialogResult.OK)
 {
 //Get the path of specified file
 textBox1.Text = openFileDialog.FileName;
 }
 }
 }
 }
}
</bitmap></bitmap></bitmap></bitmap></bitmap>


-
How to get better video quality using Accord.Video.FFMPEG.DLL
31 juillet 2023, par HighwayRobI have developed a Visual Studio Winapp that produces a video file utilizing Accord.Video.FFMPEG.DLL.


The quality the video is less than the original images.
Here is the code and then a sample original image and snapshot of the resulting video.


What can I change to improve the video image ?


VideoFileWriter writer = new VideoFileWriter();
 writer.Open(outfile, width, height, 1, VideoCodec.Mpeg4);
 for (int i = firstrow; i <= testframes; i++)
 {
 Bitmap bitmap = new Bitmap(ffiles[i, 0].ToString());
 writer.WriteVideoFrame(bitmap);
 bitmap.Dispose();
 }



I tried Bitmap image = new Bitmap(width, height, PixelFormat.Format64bppArgb) ;