Microsoft MVP성태의 닷넷 이야기
.NET Framework: 617. C# - AForge.NET을 이용한 MP4 동영상 파일 재생 [링크 복사], [링크+제목 복사]
조회: 23401
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일

C# - AForge.NET을 이용한 MP4 동영상 파일 재생

AForge.NET에는 Video 파일 처리와 관련해 2개의 라이브러리가 있습니다.

  • AForge.Video.DirectShow
  • AForge.Video.FFMPEG

DirectShow를 이용한 경우, AVI 파일과 같은 것만 재생할 수 있을 뿐 MP4 등의 파일을 재생하려고 하면 "Did not find acceptable output video pin in the given source AForge.NET"와 같은 예외가 발생합니다.

예상할 수 있듯이 MP4 파일 등의 재생은 AForge.Video.FFMPEG로 해야 합니다. 이 때문에 의존성이 좀 복잡해지는데요. 우선 기본적인 것은 NuGet으로 해결하고,

Install-Package AForge.Controls

AForge.Video.FFMPEG.dll은 "AForge.NET Framework"을 내려받아 그 안에서 구해야 합니다.

AForge.NET Framework is 2.2.5.
; http://www.aforgenet.com/framework/downloads.html

(2.2.5 버전에 포함된 AForge.Video.FFMPEG 프로젝트는 예전 버전의 ffmpeg 라이브러리에 의존합니다. 만약 이를 바꾸고 싶다면 "AForge.Video.FFMPEG를 최신 버전의 ffmpeg 파일로 의존성을 변경하는 방법"을 참고하세요.)

이렇게 참조를 해결하면 이제 나머지 작업은 지난번과 마찬가지로 어렵지 않습니다.

이번엔 PictureBox 대신 AForge.Controls에서 제공하는 AForge.Controls.VideoSourcePlayer 컨트롤을 WinForm 위에 올리고, 다음과 같이 mp4 비디오 파일 경로를 VideFileSource에 제공하는 것으로 동영상 재생을 할 수 있습니다.

VideoFileSource _videoFile;

private void button1_Click(object sender, EventArgs e)
{
    if (this.button1.Text == "Start")
    {
        string filePath = @"F:\frozen\IdinaMenzel.mp4";
        _videoFile = new VideoFileSource(filePath);

        this.videoSourcePlayer1.VideoSource = _videoFile;
        this.videoSourcePlayer1.Start();

        this.button1.Text = "Stop";
    }
    else
    {
        this.button1.Text = "Start";
        _videoFile.Stop();
    }
}

아래는 실행 화면을 보여줍니다.

video_file_aforge_1.png

(첨부 파일은 이 글의 예제를 포함합니다.)




유의할 것은, AForge.Video.FFMPEG 라이브러리는 오로지 "영상"만을 재생할 뿐 음성 데이터는 처리하지 않습니다. (즉, 소리가 들리지 않습니다.) AForge 2.2.5 라이브러리 당시 AForge.Video.FFMPEG에서는 음성 처리에 대한 지원을 추가할 생각이 없다고 분명히 밝혔기 때문에 향후로도 그럴 가능성은 별로 없어 보입니다.

// AForge.Video.FFMPEG Namespace
// http://www.aforgenet.com/framework/docs/html/e478f635-9b18-278b-8378-99e5531b3007.htm

Note: the API allows writing and reading video data only. Reading and writing of sound data is not supported and is not planned for now.



만약 아래와 같은 오류가 발생한다면?

System.IO.FileNotFoundException was unhandled
  FileName=AForge.Video.FFMPEG.dll
  FusionLog=""
  HResult=-2147024770
  Message=Could not load file or assembly 'AForge.Video.FFMPEG.dll' or one of its dependencies. The specified module could not be found.
  Source=WindowsFormsApplication1
  StackTrace:
       at WindowsFormsApplication1.Form1.Form1_Load(Object sender, EventArgs e)
       at System.Windows.Forms.Form.OnLoad(EveArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

에러 메시지처럼 EXE 파일이 있는 폴더에 AForge.Video.FFMPEG.dll 파일이 없기 때문일 수도 있지만, FFMPEG 관련 라이브러리가 없는 경우일 수도 있습니다. 실제로 AForge.Video.FFMPEG.dll 파일은 avformat-??.dll, avcodec-??.dll, avutil-??.dll, swscale-?.dll에 대한 직접적인 의존성을 가지고 있습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 11/1/2016]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2017-03-20 06시35분
정성태
2018-01-09 03시08분
[이지순] 잘 보고 갑니다.
[guest]
2019-04-29 09시49분
[정근화] 안녕하세요. 항상 잘보고있습니다.
한 가지 궁금한 점이 생겨 질문 남깁니다. 동영상이 끝나고 바로 반복 재생할 수 있는 방법이 있을까요?
[guest]
2019-04-29 10시44분
videoSourcePlayer1 변수의 클래스를 조사해 보세요. 동영상이 끝났다는 것에 대한 이벤트나 자동 재생 등에 대한 속성을 제공하고 있을 것입니다.
정성태
2019-04-30 01시29분
[정근화] finish옵션이 있어 동영상 반복재생은 해결 했는데 exe 파일을 배포하고 실행하니 위에 오류가 뜨네요.. exe 파일에 dll들을 같은 폴더에서 실행을 해도..
[guest]
2020-11-25 01시29분
[ㅁㄴㅇㄴㅁ] 폼 디자인을 볼 수 없는데 어떻게해야되나요?
[guest]
2020-11-25 08시22분
끝인가요?
정성태

1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13576정성태3/8/20241543닷넷: 2228. .NET Profiler - IMetaDataEmit2::DefineMethodSpec 사용법
13575정성태3/7/20241676닷넷: 2227. 최신 C# 문법을 .NET Framework 프로젝트에 쓸 수 있을까요?
13574정성태3/6/20241557닷넷: 2226. C# - "Docker Desktop for Windows" Container 환경에서의 IPv6 DualMode 소켓
13573정성태3/5/20241563닷넷: 2225. Windbg - dumasync로 분석하는 async/await 호출
13572정성태3/4/20241641닷넷: 2224. C# - WPF의 Dispatcher Queue로 알아보는 await 호출의 hang 현상파일 다운로드1
13571정성태3/1/20241618닷넷: 2223. C# - await 호출과 WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13570정성태2/29/20241631닷넷: 2222. C# - WPF의 Dispatcher Queue 동작 확인파일 다운로드1
13569정성태2/28/20241545닷넷: 2221. C# - LoadContext, LoadFromContext 그리고 GAC파일 다운로드1
13568정성태2/27/20241606닷넷: 2220. C# - .NET Framework 프로세스의 LoaderOptimization 설정을 확인하는 방법파일 다운로드1
13567정성태2/27/20241617오류 유형: 898. .NET Framework 3.5 이하에서 mscoree.tlb 참조 시 System.BadImageFormatException파일 다운로드1
13566정성태2/27/20241630오류 유형: 897. Windows 7 SDK 설치 시 ".NET Development" 옵션이 비활성으로 선택이 안 되는 경우
13565정성태2/23/20241478닷넷: 2219. .NET CLR2 보안 모델에서의 개별 System.Security.Permissions 제어
13564정성태2/22/20241614Windows: 259. Hyper-V Generation 1 유형의 VM을 Generation 2 유형으로 바꾸는 방법
13563정성태2/21/20241644디버깅 기술: 196. windbg - async/await 비동기인 경우 메모리 덤프 분석의 어려움
13562정성태2/21/20241644오류 유형: 896. ASP.NET - .NET Framework 기본 예제에서 System.Web에 대한 System.IO.FileNotFoundException 예외 발생
13561정성태2/20/20241742닷넷: 2218. C# - (예를 들어, Socket) 비동기 I/O에 대한 await 호출 시 CancellationToken을 이용한 취소파일 다운로드1
13560정성태2/19/20241746디버깅 기술: 195. windbg 분석 사례 - Semaphore 잠금으로 인한 Hang 현상 (닷넷)
13559정성태2/19/20242623오류 유형: 895. ASP.NET - System.Security.SecurityException: 'Requested registry access is not allowed.'
13558정성태2/18/20241819닷넷: 2217. C# - 최댓값이 1인 SemaphoreSlim 보다 Mutex 또는 lock(obj)를 선택하는 것이 나은 이유
13557정성태2/18/20241619Windows: 258. Task Scheduler의 Author 속성 값을 변경하는 방법
13556정성태2/17/20241684Windows: 257. Windows - Symbolic (hard/soft) Link 및 Junction 차이점
13555정성태2/15/20241952닷넷: 2216. C# - SemaphoreSlim 사용 시 주의점
13554정성태2/15/20241708VS.NET IDE: 189. Visual Studio - 닷넷 소스코드 디컴파일 찾기가 안 될 때
13553정성태2/14/20241735닷넷: 2215. windbg - thin/fat lock 없이 동작하는 Monitor.Wait + Pulse
13552정성태2/13/20241685닷넷: 2214. windbg - Monitor.Enter의 thin lock과 fat lock
13551정성태2/12/20242016닷넷: 2213. ASP.NET/Core 웹 응용 프로그램 - 2차 스레드의 예외로 인한 비정상 종료
1  [2]  3  4  5  6  7  8  9  10  11  12  13  14  15  ...