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

비밀번호

댓글 작성자
 




1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13818정성태11/15/20245267Windows: 272. Windows 11 24H2 - sudo 추가
13817정성태11/14/20244929Linux: 106. eBPF / bpf2go - (BPF_MAP_TYPE_HASH) Map을 이용한 전역 변수 구현
13816정성태11/14/20245386닷넷: 2312. C#, C++ - Windows / Linux 환경의 Thread Name 설정파일 다운로드1
13815정성태11/13/20244809Linux: 105. eBPF - bpf2go에서 전역 변수 설정 방법
13814정성태11/13/20245283닷넷: 2311. C# - Windows / Linux 환경에서 Native Thread ID 가져오기파일 다운로드1
13813정성태11/12/20245029닷넷: 2310. .NET의 Rune 타입과 emoji 표현파일 다운로드1
13812정성태11/11/20245263오류 유형: 933. Active Directory - The forest functional level is not supported.
13811정성태11/11/20244848Linux: 104. Linux - COLUMNS 환경변수가 언제나 80으로 설정되는 환경
13810정성태11/10/20245374Linux: 103. eBPF (bpf2go) - Tracepoint를 이용한 트레이스 (BPF_PROG_TYPE_TRACEPOINT)
13809정성태11/10/20245260Windows: 271. 윈도우 서버 2025 마이그레이션
13808정성태11/9/20245257오류 유형: 932. Linux - 커널 업그레이드 후 "error: bad shim signature" 오류 발생
13807정성태11/9/20244993Linux: 102. Linux - 커널 이미지 파일 서명 (Ubuntu 환경)
13806정성태11/8/20244902Windows: 270. 어댑터 상세 정보(Network Connection Details) 창의 내용이 비어 있는 경우
13805정성태11/8/20244736오류 유형: 931. Active Directory의 adprep 또는 복제가 안 되는 경우
13804정성태11/7/20245366Linux: 101. eBPF 함수의 인자를 다루는 방법
13803정성태11/7/20245319닷넷: 2309. C# - .NET Core에서 바뀐 DateTime.Ticks의 정밀도
13802정성태11/6/20245696Windows: 269. GetSystemTimeAsFileTime과 GetSystemTimePreciseAsFileTime의 차이점파일 다운로드1
13801정성태11/5/20245481Linux: 100. eBPF의 2가지 방식 - libbcc와 libbpf(CO-RE)
13800정성태11/3/20246321닷넷: 2308. C# - ICU 라이브러리를 활용한 문자열의 대소문자 변환 [2]파일 다운로드1
13799정성태11/2/20244907개발 환경 구성: 732. 모바일 웹 브라우저에서 유니코드 문자가 표시되지 않는 경우
13798정성태11/2/20245505개발 환경 구성: 731. 유니코드 - 출력 예시 및 폰트 찾기
13797정성태11/1/20245492C/C++: 185. C++ - 문자열의 대소문자를 변환하는 transform + std::tolower/toupper 방식의 문제점파일 다운로드1
13796정성태10/31/20245382C/C++: 184. C++ - ICU dll을 이용하는 예제 코드 (Windows)파일 다운로드1
13795정성태10/31/20245164Windows: 268. Windows - 리눅스 환경처럼 공백으로 끝나는 프롬프트 만들기
13794정성태10/30/20245261닷넷: 2307. C# - 윈도우에서 한글(및 유니코드)을 포함한 콘솔 프로그램을 컴파일 및 실행하는 방법
13793정성태10/28/20245134C/C++: 183. C++ - 윈도우에서 한글(및 유니코드)을 포함한 콘솔 프로그램을 컴파일 및 실행하는 방법
1  2  3  4  [5]  6  7  8  9  10  11  12  13  14  15  ...