Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

ffmpeg / YoutubeExplode - mp4 동영상 파일로부터 Audio 파일 추출

YoutubeExplode를 이용해 다운로드한 동영상으로부터,

C# MAUI - 유튜브 동영상을 MediaElement로 재생하는 방법
; https://www.sysnet.pe.kr/2/0/13637#youtube_explode

ffmpeg를 이용해 오디오를 추출하려는데요,

How can I extract audio from video with ffmpeg?
; https://stackoverflow.com/questions/65308648/unsupported-input-sample-rate-set-error-while-converting-mkv-to-mp3-with-ffmpe

ffmpeg -i sample.mp4 -q:a 0 -map a sample.mp3

대체로 저 명령어를 이용해 mp3 파일이 잘 추출됩니다. 그런데, 특정 mp4 파일의 경우 이런 오류가 발생합니다.

C:\temp> ffmpeg -i "test_video.mp4" -q:a 0 -map a "test_video.mp3"
...[생략]...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2022-03-03T07:56:42.000000Z
  Duration: 00:03:24.01, start: 0.000000, bitrate: 156 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 25 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2022-03-03T07:56:42.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/02/2022.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2022-03-03T07:56:42.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/02/2022.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:1 -> #0:0 (aac (native) -> mp3 (mp3_mf))
Press [q] to stop, [?] for help
[mp3_mf @ 000001FBC4DD6F40] MFT name: 'MP3 Encoder ACM Wrapper MFT'
Output #0, mp3, to 'test_video.mp3':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    TSSE            : Lavf58.76.100
  Stream #0:0(eng): Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s (default)
    Metadata:
      creation_time   : 2022-03-03T07:56:42.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/02/2022.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 mp3_mf
[mp3_mf @ 000001FBC4DD6F40] nb_samples (1024) != frame_size (0)
Audio encoding failed
Conversion failed!

아~~~ 현란해서 무슨 오류인지 잘 모르겠습니다. ^^; 단지, mp4의 audio 스트림을 보니까 "Audio: aac ..."라고 나오는데요, 혹시나 싶어 mp3가 아니라 확장자를 aac로 주니 잘 동작합니다.

c:temp> ffmpeg -i test_video.mp4 -q:a 0 -map a test_video.aac
ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  ...[생략]...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_video.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2022-03-03T07:56:42.000000Z
  Duration: 00:03:24.01, start: 0.000000, bitrate: 156 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 25 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2022-03-03T07:56:42.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/02/2022.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2022-03-03T07:56:42.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/02/2022.
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:1 -> #0:0 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, adts, to 'test_video.aac':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf58.76.100
  Stream #0:0(eng): Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2022-03-03T07:56:42.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 03/02/2022.
      vendor_id       : [0][0][0][0]
      encoder         : Lavc58.134.100 aac
size=    2446kB time=00:03:23.98 bitrate=  98.2kbits/s speed= 145x
video:0kB audio:2386kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.517594%
[aac @ 0000024B3EC656C0] Qavg: 120.000

그런데, 재미있는 건 다른 컴퓨터에 있는 ffmpeg로 mp4 -> mp3 변환을 하니 거기선 또 잘됩니다. ^^ 도대체 무슨 까닭일까요?




이에 대해 검색해 보면,

'unsupported input sample rate set' error while converting mkv to mp3 with ffmpeg on python
; https://stackoverflow.com/questions/65308648/unsupported-input-sample-rate-set-error-while-converting-mkv-to-mp3-with-ffmpe

입력 파일의 샘플 레이트가 96kHz인 반면 mp3는 48kHz까지만 지원해서 그렇다고 하는데, 제 오류 화면에 보면 입력 Stream #0:1의 샘플 레이트는 44100 Hz로 나오기 때문에 저 오류라고 볼 수는 없습니다. (실제로 그의 답변에 따라 -ar 44100 옵션을 줘도 동일한 오류가 발생합니다.)

또 다른 답글을 보면, MediaFoundation MP3 encoder에 해당하는 mp3_mf 인코더를 사용해서 그렇다고 합니다. (실제로 제 오류 화면에서도 "MP3 Encoder ACM Wrapper MFT", "mp3_mf"라는 문자열이 나옵니다.) 그리곤 해법으로 "libmp3lame" 인코더를 사용하라고 하는데 그렇다면 이제 추측이 가능합니다.

즉, "nb_samples (1024) != frame_size (0)" 오류가 발생했던 PC의 ffmpeg를 실행했을 때 보이는 configuration 옵션에,

configuration: --prefix=/e/git_clone/vcpkg/packages/ffmpeg_x64-windows --toolchain=msvc --enable-pic --disable-doc --enable-debug --enable-runtime-cpudetect --enable-asm --enable-x86asm --enable-nonfree --enable-gpl --enable-ffmpeg --enable-ffplay --enable-ffprobe --disable-alsa --enable-avcodec --enable-avdevice --enable-avformat --enable-avfilter --enable-postproc --enable-swresample --enable-swscale --disable-libaom --disable-libass --disable-avisynth --disable-bzlib --disable-libdav1d --disable-libfdk-aac --disable-libfontconfig --disable-libfreetype --disable-libfribidi --disable-iconv --disable-libilbc --disable-lzma --disable-libmp3lame --disable-libmodplug --enable-cuda --enable-nvenc --enable-nvdec --enable-cuvid --enable-ffnvcodec --enable-opencl --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-openssl --disable-libopus --enable-sdl2 --disable-libsnappy --disable-libsoxr --disable-libspeex --disable-libssh --disable-libtensorflow --disable-libtesseract --disable-libtheora --disable-libvorbis --disable-libvpx --disable-libwebp --disable-libx264 --disable-libx265 --disable-libxml2 --disable-zlib --disable-static --enable-shared --extra-cflags='-DHAVE_UNISTD_H=0' --extra-cflags=-MD --extra-cxxflags=-MD


저렇게 --disable-libmp3lame 옵션을 포함해 빌드가 되었기 때문에 mp3 인코더로 MediaFoundation의 것이 선택된 것입니다. 반면, mp3 변환이 잘 된 PC에서는 해당 인코더를 포함하고 있었던 것이고!

configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint


뭔가 옵션을 추가하면 될지 모르겠지만, 일단 오늘은 여기서 마무리하겠습니다. ^^




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







[최초 등록일: ]
[최종 수정일: 8/7/2024]

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

비밀번호

댓글 작성자
 




... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13490정성태12/19/202310109개발 환경 구성: 698. Golang - GLIBC 의존을 없애는 정적 빌드 방법
13489정성태12/19/202310068개발 환경 구성: 697. GoLand에서 ldflags 지정 방법
13488정성태12/18/20239532오류 유형: 884. HTTP 500.0 - 명령행에서 실행한 ASP.NET Core 응용 프로그램을 실행하는 방법
13487정성태12/16/202310635개발 환경 구성: 696. C# - 리눅스용 AOT 빌드를 docker에서 수행 [1]
13486정성태12/15/20239750개발 환경 구성: 695. Nuget config 파일에 값 설정/삭제 방법
13485정성태12/15/20239433오류 유형: 883. dotnet build/restore - error : Root element is missing
13484정성태12/14/202310166개발 환경 구성: 694. Windows 디렉터리 경로를 WSL의 /mnt 포맷으로 구하는 방법
13483정성태12/14/202310423닷넷: 2184. C# - 하나의 resource 파일을 여러 프로그램에서 (AOT 시에도) 사용하는 방법파일 다운로드1
13482정성태12/13/202311654닷넷: 2183. C# - eFriend Expert OCX 예제를 .NET Core/5+ Console App에서 사용하는 방법 [2]파일 다운로드1
13481정성태12/13/202310545개발 환경 구성: 693. msbuild - .NET Core/5+ 프로젝트에서 resgen을 이용한 리소스 파일 생성 방법파일 다운로드1
13480정성태12/12/202312395개발 환경 구성: 692. Windows WSL 2 + Chrome 웹 브라우저 설치
13479정성태12/11/202310039개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/202310675닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/202310535닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/202310803닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/202310367개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/202310710닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/202310116C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/202310662Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/202311276닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입 [1]파일 다운로드1
13469정성태12/1/202311186닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/202310207닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/202310946오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/202310768닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/202310475개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/202310390닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...