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)
13237정성태1/30/202314295.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
13236정성태1/29/202313049개발 환경 구성: 663. openssl을 이용해 인트라넷 IIS 사이트의 SSL 인증서 생성
13235정성태1/29/202312529개발 환경 구성: 662. openssl - 윈도우 환경의 명령행에서 SAN 적용하는 방법
13234정성태1/28/202314942개발 환경 구성: 661. dnSpy를 이용해 소스 코드가 없는 .NET 어셈블리의 코드를 변경하는 방법 [1]
13233정성태1/28/202316128오류 유형: 840. C# - WebClient로 https 호출 시 "The request was aborted: Could not create SSL/TLS secure channel" 예외 발생
13232정성태1/27/202312042스크립트: 43. uwsgi의 --processes와 --threads 옵션
13231정성태1/27/202311266오류 유형: 839. python - TypeError: '...' object is not callable
13230정성태1/26/202312018개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
13229정성태1/25/202313898.NET Framework: 2090. C# - UDP Datagram의 최대 크기
13228정성태1/24/202314452.NET Framework: 2089. C# - WMI 논리 디스크가 속한 물리 디스크의 정보를 얻는 방법 [2]파일 다운로드1
13227정성태1/23/202313354개발 환경 구성: 659. Windows - IP MTU 값을 바꿀 수 있을까요? [1]
13226정성태1/23/202312310.NET Framework: 2088. .NET 5부터 지원하는 GetRawSocketOption 사용 시 주의할 점
13225정성태1/21/202311646개발 환경 구성: 658. Windows에서 실행 중인 소켓 서버를 다른 PC 또는 WSL에서 접속할 수 없는 경우
13224정성태1/21/202312148Windows: 221. Windows - Private/Public/Domain이 아닌 네트워크 어댑터 단위로 방화벽을 on/off하는 방법
13223정성태1/20/202312064오류 유형: 838. RDP 연결 오류 - The two computers couldn't connect in the amount of time allotted
13222정성태1/20/202311925개발 환경 구성: 657. WSL - DockerDesktop.vhdx 파일 위치를 옮기는 방법
13221정성태1/19/202312122Linux: 57. C# - 리눅스 프로세스 메모리 정보파일 다운로드1
13220정성태1/19/202311786오류 유형: 837. NETSDK1045 The current .NET SDK does not support targeting .NET ...
13219정성태1/18/202311406Windows: 220. 네트워크의 인터넷 접속 가능 여부에 대한 판단 기준
13218정성태1/17/202311272VS.NET IDE: 178. Visual Studio 17.5 (Preview 2) - 포트 터널링을 이용한 웹 응용 프로그램의 외부 접근 허용
13217정성태1/13/202311988디버깅 기술: 185. windbg - 64비트 운영체제에서 작업 관리자로 뜬 32비트 프로세스의 덤프를 sos로 디버깅하는 방법
13216정성태1/12/202311900디버깅 기술: 184. windbg - 32비트 프로세스의 메모리 덤프인 경우 !peb 명령어로 나타나지 않는 환경 변수
13215정성태1/11/202314929Linux: 56. 리눅스 - /proc/pid/stat 정보를 이용해 프로세스의 CPU 사용량 구하는 방법 [1]
13214정성태1/10/202313830.NET Framework: 2087. .NET 6부터 SourceGenerator와 통합된 System.Text.Json [1]파일 다운로드1
13213정성태1/9/202312181오류 유형: 836. docker 이미지 빌드 시 "RUN apt install ..." 명령어가 실패하는 이유
13212정성태1/8/202313560기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
... 16  17  18  19  20  21  22  23  24  25  26  27  [28]  29  30  ...