Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
(연관된 글이 1개 있습니다.)

AForge.Video.FFMPEG를 최신 버전의 ffmpeg 파일로 의존성을 변경하는 방법

AForge.Video.FFMPEG.dll의 소스 코드는 AForge.NET Framework에 포함되어 있기 때문에 이를 다운로드하면 됩니다.

소스코드 - AForge.NET Framework-2.2.5.zip
; https://code.google.com/archive/p/aforge/downloads
; https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/aforge/AForge.NET%20Framework-2.2.5.zip

압축 해제 후, AForge.Video.FFMPEG 빌드와 관련된 폴더는 다음과 같습니다.

\Externals\ffmpeg - 구 버전의 ffpeg bin, lib, includ 파일 포함
\Sources\Video.FFMPEG - Video.FFMPEG.sln 솔루션 파일까지 포함한 C++/CLI 프로젝트 (x86)

보는 바와 같이 Video.FFMPEG.vcxproj 프로젝트는 \Externals\ffmpeg 폴더 하위에 있는 ffmpeg 라이브러리에 의존성을 갖기 때문에 이 폴더의 내용을 최신으로 업데이트해 주면 됩니다.

(마지막으로 릴리스된) 2.2.5 버전의 AForge.NET Framework에 포함되어 있는 AForge.Video.FFMPEG 프로젝트는 다음의 ffmpeg 라이브러리에 의존성을 갖습니다.

  • avcodec-53.dll
  • avformat-53.dll
  • avutil-51.dll
  • swresample-0.dll
  • swscale-2.dll

그런데 현재(2016-10-29) ffmpeg 3.1.5 버전은,

Download FFmpeg for Windows
; https://ffmpeg.zeranoe.com/builds/

다음의 DLL들로 구성되므로,

  • avcodec-57.dll
  • avformat-57.dll
  • avutil-55.dll
  • swresample-2.dll
  • swscale-4.dll

이를 \Externals\ffmpeg\bin 폴더에 복사해야 할 뿐만 아니라 컴파일을 위해 include, lib 파일들을 구해야 합니다. 이 모든 것은 FFmpeg 라이브러리와, 개발자 용 버전을 통해 구할 수 있습니다.

  • ffmpeg-3.1.5-win32-shared.zip
  • ffmpeg-3.1.5-win32-dev.zip

따라서, AForge Framework의 \Externals\ffmpeg 폴더 내용을 모두 삭제하고, ffmpeg-3.1.5-win32-shared.zip의 압축을 \Externals\ffmpeg 폴더에 풀고, ffmpeg-3.1.5-win32-dev.zip 내용 중에서 "include", "lib" 폴더만 \Externals\ffmpeg 폴더에 넣어 주면 됩니다.



준비는 이것으로 끝났지만, 아쉽게도 하위 호환성이 깨진 부분이 있기 때문에 빌드 시에 맞춰주어야 할 부분이 있습니다.

우선, 다음의 코드에서 오류가 발생할 텐데요.

int video_codecs[] =
{
    libffmpeg::CODEC_ID_MPEG4,
    libffmpeg::CODEC_ID_WMV1,
    libffmpeg::CODEC_ID_WMV2,
    libffmpeg::CODEC_ID_MSMPEG4V2,
    libffmpeg::CODEC_ID_MSMPEG4V3,
    libffmpeg::CODEC_ID_H263P,
    libffmpeg::CODEC_ID_FLV1,
    libffmpeg::CODEC_ID_MPEG2VIDEO,
    libffmpeg::CODEC_ID_RAWVIDEO
};

int pixel_formats[] =
{
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_YUV420P,
    libffmpeg::PIX_FMT_BGR24,
};

CODEC_ID_???는 AV_CODEC_ID_???로 바꾸고, PIX_FMT_???은 AV_PIX_FMT_???로 바꿔주면 됩니다.

그 외의 함수들 변화는 다음의 글에 따라,

[ffmpeg.git / doc / APIchanges
; http://git.videolan.org/?p=ffmpeg.git;a=blob;f=doc/APIchanges;h=250088b24fd6597bcd3a2b50b53cbfe077d06cef;hb=1985c2e75c607ac51bfd8dc87d2957a5edf2b6f8

이런 식으로 적절하게 바꿔주면 됩니다.

av_open_input_file ==> avformat_open_input
av_find_stream_info ==> avformat_find_stream_info
avcodec_open ==> avcodec_open2
avcodec_alloc_frame ==> av_frame_alloc
av_close_input_file ==> avformat_close_input
av_write_header ==> avformat_write_header
avcodec_encode_video ==> avcodec_encode_video2
av_new_stream ==> avformat_new_stream
av_set_parameters ==> 호출 제거

그런데, 제가 ffmpeg 사용법을 잘 몰라 확신할 수 없는 것이 2가지 있습니다. 하나는 av_set_parameters 같은 경우 대응하는 함수가 없어 제거를 했다는 점과 나머지 하나는 avformat_open_input 함수가 사용법이 달라져서 (ffmpeg를 모르는 상태로) 고쳤다는 점입니다.

특히나 "av_open_input_file" 함수의 경우 "avformat_open_input"으로 대체하는데, 사용 전 반드시 다음과 같이 avformat_alloc_context를 이용해 할당을 해줘야 했습니다. (고맙게도 close 시에 avformat_free_context는 호출하지 않아도 된다고 합니다.)

static libffmpeg::AVFormatContext* open_file( char* fileName )
{
    libffmpeg::AVFormatContext* formatContext = libffmpeg::avformat_alloc_context();

    if ( libffmpeg::avformat_open_input( &formatContext, fileName, NULL, NULL) !=0 )
    {
        return NULL;
    }

    return formatContext;
}

이 정도 변경하고 빌드하면 정상적으로 동작하는 (것 같은) 바이너리를 얻을 수 있습니다.

(첨부 파일은 이 글의 Video.FFMPEG.vcxproj 프로젝트를 포함합니다. 또한 github에도 올려두었습니다.)






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

[연관 글]






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

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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  38  39  40  41  42  43  44  [45]  ...
NoWriterDateCnt.TitleFile(s)
12492정성태1/17/20217972오류 유형: 695. ASP.NET 0x80131620 Failed to bind to address
12491정성태1/16/20219556.NET Framework: 1008. 배열을 반환하는 C# COM 개체의 메서드를 C++에서 사용 시 메모리 누수 현상 [1]파일 다운로드1
12490정성태1/15/20219131.NET Framework: 1007. C# - foreach에서 열거 변수의 타입을 var로 쓰면 object로 추론하는 문제 [1]파일 다운로드1
12489정성태1/13/202110124.NET Framework: 1006. C# - DB에 저장한 텍스트의 (이모티콘을 비롯해) 유니코드 문자가 '?'로 보인다면? [1]
12488정성태1/13/202110343.NET Framework: 1005. C# - string 타입은 shallow copy일까요? deep copy일까요? [2]파일 다운로드1
12487정성태1/13/20218878.NET Framework: 1004. C# - GC Heap에 위치한 참조 개체의 주소를 알아내는 방법파일 다운로드1
12486정성태1/12/20219785.NET Framework: 1003. x64 환경에서 참조형의 기본 메모리 소비는 얼마나 될까요? [1]
12485정성태1/11/202110478Graphics: 38. C# - OpenCvSharp.VideoWriter에 BMP 파일을 1초씩 출력하는 예제파일 다운로드1
12484정성태1/9/202111149.NET Framework: 1002. C# - ReadOnlySequence<T> 소개파일 다운로드1
12483정성태1/8/20218352개발 환경 구성: 521. dotPeek - 훌륭한 역어셈블 소스 코드 생성 도구
12482정성태1/8/20219751.NET Framework: 1001. C# - 제네릭 타입/메서드에서 사용 시 경우에 따라 CS8377 컴파일 에러
12481정성태1/7/20219510.NET Framework: 1000. C# - CS8344 컴파일 에러: ref struct 타입의 사용 제한 메서드파일 다운로드1
12480정성태1/6/202112073.NET Framework: 999. C# - ArrayPool<T>와 MemoryPool<T> 소개파일 다운로드1
12479정성태1/6/20219447.NET Framework: 998. C# - OWIN 예제 프로젝트 만들기
12478정성태1/5/202111083.NET Framework: 997. C# - ArrayPool<T> 소개파일 다운로드1
12477정성태1/5/202113487기타: 79. github 코드 검색 방법 [1]
12476정성태1/5/202110139.NET Framework: 996. C# - 닷넷 코어에서 다른 스레드의 callstack을 구하는 방법파일 다운로드1
12475정성태1/5/202112723.NET Framework: 995. C# - Span<T>와 Memory<T> [1]파일 다운로드1
12474정성태1/4/202110284.NET Framework: 994. C# - (.NET Core 2.2부터 가능한) 프로세스 내부에서 CLR ETW 이벤트 수신 [1]파일 다운로드1
12473정성태1/4/20219069.NET Framework: 993. .NET 런타임에 따라 달라지는 정적 필드의 초기화 유무 [1]파일 다운로드1
12472정성태1/3/20219363디버깅 기술: 178. windbg - 디버그 시작 시 스크립트 실행
12471정성태1/1/20219827.NET Framework: 992. C# - .NET Core 3.0 이상부터 제공하는 runtimeOptions의 rollForward 옵션 [1]
12470정성태12/30/202010025.NET Framework: 991. .NET 5 응용 프로그램에서 WinRT API 호출 [1]파일 다운로드1
12469정성태12/30/202013615.NET Framework: 990. C# - SendInput Win32 API를 이용한 가상 키보드/마우스 [1]파일 다운로드1
12468정성태12/30/202010221Windows: 186. CMD Shell의 "Defaults"와 "Properties"에서 폰트 정보가 다른 문제 [1]
12467정성태12/29/202010137.NET Framework: 989. HttpContextAccessor를 통해 이해하는 AsyncLocal<T> [1]파일 다운로드1
... 31  32  33  34  35  36  37  38  39  40  41  42  43  44  [45]  ...