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)
13262정성태2/15/202313485디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
13261정성태2/15/202312963Windows: 224. Visual Studio - 영문 폰트가 Fullwidth Latin Character로 바뀌는 문제
13260정성태2/14/202312212오류 유형: 847. ilasm.exe 컴파일 오류 - error : syntax error at token '-' in ... -inf
13259정성태2/14/202312162.NET Framework: 2095. C# - .NET5부터 도입된 CollectionsMarshal
13258정성태2/13/202312922오류 유형: 846. .NET Framework 4.8 Developer Pack 설치 실패 - 0x81f40001
13257정성태2/13/202312336.NET Framework: 2094. C# - Job에 Process 포함하는 방법 [1]파일 다운로드1
13256정성태2/10/202312465개발 환경 구성: 665. WSL 2의 네트워크 통신 방법 - 두 번째 이야기
13255정성태2/10/202312685오류 유형: 845. gihub - windows2022 이미지에서 .NET Framework 4.5.2 미만의 프로젝트에 대한 빌드 오류
13254정성태2/10/202312566Windows: 223. (WMI 쿼리를 위한) PowerShell 문자열 escape 처리
13253정성태2/9/202313705Windows: 222. C# - 다른 윈도우 프로그램이 실행되었음을 인식하는 방법파일 다운로드1
13252정성태2/9/202311603오류 유형: 844. ssh로 명령어 수행 시 멈춤 현상
13251정성태2/8/202312188스크립트: 44. 파이썬의 3가지 스레드 ID
13250정성태2/8/202313775오류 유형: 843. System.InvalidOperationException - Unable to configure HTTPS endpoint
13249정성태2/7/202314384오류 유형: 842. 리눅스 - You must wait longer to change your password
13248정성태2/7/202311051오류 유형: 841. 리눅스 - [사용자 계정] is not in the sudoers file. This incident will be reported.
13247정성태2/7/202312613VS.NET IDE: 180. Visual Studio - 닷넷 소스 코드 디버깅 중 "Decompile source code"가 동작하는 않는 문제
13246정성태2/6/202312433개발 환경 구성: 664. Hyper-V에 설치한 리눅스 VM의 VHD 크기 늘리는 방법 - 두 번째 이야기
13245정성태2/6/202312976.NET Framework: 2093. C# - PKCS#8 PEM 파일을 이용한 RSA 개인키/공개키 설정 방법파일 다운로드1
13244정성태2/5/202312090VS.NET IDE: 179. Visual Studio - External Tools에 Shell 내장 명령어 등록
13243정성태2/5/202313227디버깅 기술: 190. windbg - Win32 API 호출 시점에 BP 거는 방법 [1]
13242정성태2/4/202312073디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
13241정성태2/3/202310658디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
13240정성태2/1/202311338디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
13239정성태2/1/202310700디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
13238정성태1/31/202314997.NET Framework: 2092. IIS 웹 사이트를 TLS 1.2 또는 TLS 1.3 프로토콜로만 운영하는 방법
13237정성태1/30/202314295.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...