2012-06-16 16:51:47 +00:00
using System ;
using System.Windows.Forms ;
2013-10-25 00:57:23 +00:00
using BizHawk.Client.Common ;
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2012-06-16 16:51:47 +00:00
{
/// <summary>
/// configures the FFmpegWriter
/// </summary>
public partial class FFmpegWriterForm : Form
{
/// <summary>
/// stores a single format preset
/// </summary>
public class FormatPreset : IDisposable
{
/// <summary>
2017-04-18 17:27:44 +00:00
/// Gets the name for the listbox
2012-06-16 16:51:47 +00:00
/// </summary>
2017-04-18 17:27:44 +00:00
public string Name { get ; }
2012-06-16 16:51:47 +00:00
/// <summary>
2017-04-18 17:27:44 +00:00
/// Gets the long human readable description
2012-06-16 16:51:47 +00:00
/// </summary>
2017-04-18 17:27:44 +00:00
public string Desc { get ; }
2012-06-16 16:51:47 +00:00
/// <summary>
2017-04-18 17:27:44 +00:00
/// Gets the actual portion of the ffmpeg commandline
2012-06-16 16:51:47 +00:00
/// </summary>
2017-04-18 17:27:44 +00:00
public string Commandline { get ; set ; }
2012-06-16 16:51:47 +00:00
/// <summary>
2017-04-18 17:27:44 +00:00
/// Gets a value indicating whether or not it can be edited
2012-06-16 16:51:47 +00:00
/// </summary>
2017-04-18 17:27:44 +00:00
public bool Custom { get ; }
2012-06-16 16:51:47 +00:00
/// <summary>
2017-04-18 17:27:44 +00:00
/// Gets the default file extension
2012-06-16 16:51:47 +00:00
/// </summary>
2018-09-15 21:31:09 +00:00
public string Extension { get ; set ; }
2012-06-16 16:51:47 +00:00
/// <summary>
/// get a list of canned presets
/// </summary>
public static FormatPreset [ ] GetPresets ( )
{
2017-04-18 17:27:44 +00:00
return new [ ]
2012-06-16 16:51:47 +00:00
{
2018-09-15 21:31:09 +00:00
new FormatPreset ( "AVI Lossless AVC" , "Lossless AVC video and uncompressed audio in an AVI container. High speed and compression, compatible with AVISource()." ,
"-c:a pcm_s16le -c:v libx264rgb -qp 0 -preset ultrafast -g 10 -pix_fmt rgb24 -f avi" , false , "avi" ) ,
new FormatPreset ( "AVI Lossless FFV1" , "Lossless FFV1 video and uncompressed audio in an AVI container. Compatible with AVISource(), if ffmpeg based decoder is installed." ,
"-c:a pcm_s16le -c:v ffv1 -pix_fmt bgr0 -level 1 -g 1 -coder 1 -context 1 -f avi" , false , "avi" ) ,
2018-08-23 17:08:43 +00:00
new FormatPreset ( "AVI Uncompressed" , "Uncompressed video and audio in an AVI container. Very large, don't use!" ,
2018-02-25 12:03:24 +00:00
"-c:a pcm_s16le -c:v rawvideo -f avi" , false , "avi" ) ,
new FormatPreset ( "Matroska Lossless" , "Lossless AVC video and uncompressed audio in a Matroska container." ,
2018-08-23 17:08:43 +00:00
"-c:a pcm_s16le -c:v libx264rgb -qp 0 -pix_fmt rgb24 -f matroska" , false , "mkv" ) ,
2018-02-25 12:03:24 +00:00
new FormatPreset ( "Matroska" , "AVC video and Vorbis audio in a Matroska container." ,
"-c:a libvorbis -c:v libx264 -f matroska" , false , "mkv" ) ,
new FormatPreset ( "MP4" , "AVC video and AAC audio in an MP4 container." ,
2019-01-20 14:20:52 +00:00
"-c:a aac -c:v libx264 -f mp4" , false , "mp4" ) ,
2018-02-25 12:03:24 +00:00
new FormatPreset ( "WebM" , "VP8 video and Vorbis audio in a WebM container." ,
2019-02-05 20:29:40 +00:00
"-c:a libvorbis -c:v libvpx -auto-alt-ref 0 -f webm" , false , "webm" ) ,
2018-02-25 12:03:24 +00:00
new FormatPreset ( "Ogg" , "Theora video and Vorbis audio in an Ogg contrainer." ,
"-c:a libvorbis -c:v libtheora -f ogg" , false , "ogg" ) ,
new FormatPreset ( "Xvid" , "Xvid video and MP3 audio in an AVI container." ,
"-c:a libmp3lame -c:v libxvid -f avi" , false , "avi" ) ,
new FormatPreset ( "QuickTime" , "AVC video and AAC audio in a QuickTime container." ,
2019-01-20 14:20:52 +00:00
"-c:a aac -c:v libx264 -f mov" , false , "mov" ) ,
2018-02-25 12:03:24 +00:00
new FormatPreset ( "FLV" , "AVC video and AAC audio in a Flash Video container." ,
2019-01-20 14:20:52 +00:00
"-c:a aac -c:v libx264 -f flv" , false , "flv" ) ,
2018-02-25 12:03:24 +00:00
new FormatPreset ( "[Custom]" , "Write your own ffmpeg command. For advanced users only." ,
"-c:a foo -c:v bar -f baz" , true , "foobar" ) ,
2012-06-16 16:51:47 +00:00
} ;
}
2012-07-23 00:33:30 +00:00
/// <summary>
/// get the default format preset (from config files)
/// </summary>
public static FormatPreset GetDefaultPreset ( )
{
FormatPreset [ ] fps = GetPresets ( ) ;
foreach ( var fp in fps )
{
2014-10-10 18:09:00 +00:00
if ( fp . ToString ( ) = = Global . Config . FFmpegFormat )
2012-07-23 00:33:30 +00:00
{
2017-04-18 17:27:44 +00:00
if ( fp . Custom )
{
2012-07-23 00:33:30 +00:00
return fp ;
2017-04-18 17:27:44 +00:00
}
2012-07-23 00:33:30 +00:00
}
}
2017-04-18 17:27:44 +00:00
2012-07-23 00:33:30 +00:00
// default to xvid?
return fps [ 1 ] ;
}
2017-04-18 17:27:44 +00:00
public override string ToString ( )
{
return Name ;
}
2012-06-16 16:51:47 +00:00
public void Dispose ( )
{
}
2017-04-18 17:27:44 +00:00
2018-09-15 21:31:09 +00:00
public void DeduceFormat ( string commandline )
{
string formatkey = "-f " ;
Extension = commandline . Substring ( commandline . IndexOf ( formatkey ) + formatkey . Length ) ;
// are there other formats that don't match their file extensions?
if ( Extension = = "matroska" )
{
Extension = "mkv" ;
}
}
private FormatPreset ( string name , string desc , string commandline , bool custom , string ext )
2017-04-18 17:27:44 +00:00
{
Name = name ;
Desc = desc ;
Custom = custom ;
Commandline = Custom
? Global . Config . FFmpegCustomCommand
: commandline ;
2018-09-15 21:31:09 +00:00
DeduceFormat ( Commandline ) ;
2017-04-18 17:27:44 +00:00
}
2012-06-16 16:51:47 +00:00
}
2017-04-18 17:27:44 +00:00
private FFmpegWriterForm ( )
2012-06-16 16:51:47 +00:00
{
InitializeComponent ( ) ;
}
2017-04-18 17:27:44 +00:00
private void ListBox1_SelectedIndexChanged ( object sender , EventArgs e )
2012-06-16 16:51:47 +00:00
{
if ( listBox1 . SelectedIndex ! = - 1 )
{
2017-04-18 17:27:44 +00:00
var f = ( FormatPreset ) listBox1 . SelectedItem ;
2019-03-18 14:06:37 +00:00
label5 . Text = $"Extension: {f.Extension}" ;
2017-04-18 17:27:44 +00:00
label3 . Text = f . Desc ;
textBox1 . Text = f . Commandline ;
2012-06-16 16:51:47 +00:00
}
}
/// <summary>
2017-04-18 17:27:44 +00:00
/// return a FormatPreset corresponding to the user's choice
2012-06-16 16:51:47 +00:00
/// </summary>
public static FormatPreset DoFFmpegWriterDlg ( IWin32Window owner )
{
FFmpegWriterForm dlg = new FFmpegWriterForm ( ) ;
dlg . listBox1 . Items . AddRange ( FormatPreset . GetPresets ( ) ) ;
2012-06-17 15:04:41 +00:00
int i = dlg . listBox1 . FindStringExact ( Global . Config . FFmpegFormat ) ;
if ( i ! = ListBox . NoMatches )
2017-04-18 17:27:44 +00:00
{
2012-06-17 15:04:41 +00:00
dlg . listBox1 . SelectedIndex = i ;
2017-04-18 17:27:44 +00:00
}
2012-06-17 15:04:41 +00:00
2012-06-16 16:51:47 +00:00
DialogResult result = dlg . ShowDialog ( owner ) ;
FormatPreset ret ;
if ( result ! = DialogResult . OK | | dlg . listBox1 . SelectedIndex = = - 1 )
2017-04-18 17:27:44 +00:00
{
2012-06-16 16:51:47 +00:00
ret = null ;
2017-04-18 17:27:44 +00:00
}
2012-06-16 16:51:47 +00:00
else
{
ret = ( FormatPreset ) dlg . listBox1 . SelectedItem ;
2012-06-17 15:04:41 +00:00
Global . Config . FFmpegFormat = ret . ToString ( ) ;
2017-04-18 17:27:44 +00:00
if ( ret . Custom )
2012-06-17 15:04:41 +00:00
{
2018-09-15 21:31:09 +00:00
ret . Commandline =
Global . Config . FFmpegCustomCommand =
dlg . textBox1 . Text ;
ret . DeduceFormat ( ret . Commandline ) ;
2012-06-17 15:04:41 +00:00
}
2012-06-16 16:51:47 +00:00
}
2017-04-18 17:27:44 +00:00
2012-06-16 16:51:47 +00:00
dlg . Dispose ( ) ;
return ret ;
}
}
}