■ 동영상 파일 오디오 증폭 레벨 변경하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using Microsoft.Expression.Encoder;

using System;

using System.IO;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            #region 이벤트를 설정한다.

 

 

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        //////////////////////////////////////////////////////////////////////////////// Function

 

        #region 동영상 텍스트 박스 텍스트 변경시 처리하기 - movieTextBox_TextChanged(sender, e)

 

        /// <summary>

        /// 동영상 텍스트 박스 텍스트 변경시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void movieTextBox_TextChanged(object sender, EventArgs e)

        {

            this.createButton.Enabled = File.Exists(this.movieTextBox.Text);

        }

 

        #endregion

        #region 동영상 버튼 클릭시 처리하기 - movieButton_Click(sender, e)

 

        /// <summary>

        /// 동영상 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void movieButton_Click(object sender, EventArgs e)

        {

            this.openFileDialog.FileName = this.movieTextBox.Text;

 

            if(this.openFileDialog.ShowDialog() == DialogResult.OK)

            {

                this.movieTextBox.Text = this.openFileDialog.FileName;

            }

        }

 

        #endregion

        #region 오디오 증폭 레벨 트랙바 스크롤시 처리하기 - audioGainLavelTrackBar_Scroll(sender, e)

 

        /// <summary>

        /// 오디오 증폭 레벨 트랙바 스크롤시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void audioGainLavelTrackBar_Scroll(object sender, EventArgs e)

        {

            this.audioGainLevelTextBox.Text = this.audioGainLevelTrackBar.Value.ToString();

        }

 

        #endregion

        #region 생성하기 버튼 클릭시 처리하기 - createButton_Click(sender, e)

 

        /// <summary>

        /// 생성하기 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void createButton_Click(object sender, EventArgs e)

        {

            if(this.saveFileDialog.ShowDialog() != DialogResult.OK)

            {

                return;

            }

 

            Cursor = Cursors.WaitCursor;

 

            this.progressBar.Value   = 0;

            this.progressBar.Visible = true;

 

            Refresh();

 

            try

            {

                using(Job job = new Job())

                {

                    MediaItem mediaItem = new MediaItem(this.movieTextBox.Text);

 

                    job.MediaItems.Add(mediaItem);

 

                    mediaItem.OutputFormat.VideoProfile.Size = mediaItem.OriginalVideoSize;

 

                    double audioGainLevel;

 

                    if(this.audioGainLevelTrackBar.Value <= 0)

                    {

                        audioGainLevel = (10.0 + this.audioGainLevelTrackBar.Value) / 10.0;

                    }

                    else

                    {

                        audioGainLevel = audioGainLevelTrackBar.Value;

                    }

 

                    mediaItem.AudioGainLevel = audioGainLevel;

 

                    FileInfo fileInfo = new FileInfo(this.saveFileDialog.FileName);

 

                    job.OutputDirectory = fileInfo.DirectoryName;

 

                    mediaItem.OutputFileName = fileInfo.Name;

 

                    job.CreateSubfolder = false;

 

                    job.EncodeProgress += job_EncodeProgress;

 

                    job.Encode();

                }

            }

            catch(Exception exception)

            {

                MessageBox.Show(exception.Message);

            }

 

            Cursor = Cursors.Default;

 

            this.progressBar.Visible = false;

        }

 

        #endregion

        #region 작업 인코딩 진행시 처리하기 - job_EncodeProgress(sender, e)

 

        /// <summary>

        /// 작업 인코딩 진행시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void job_EncodeProgress(object sender, EncodeProgressEventArgs e)

        {

            this.progressBar.Value = (int)e.Progress;

 

            Refresh();

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

※ 프로그램 컴파일을 위해 아래 링크에서 Microsoft Expression Encoder 4를 설치한다.

 

https://www.microsoft.com/en-us/download/details.aspx?id=18974

 

Posted by 사용자 icodebroker

댓글을 달아 주세요