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

비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  38  39  40  [41]  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
12913정성태1/11/202216558.NET Framework: 1133. C# - byte * (바이트 포인터)를 FileStream으로 쓰는 방법 [1]
12912정성태1/11/202216527개발 환경 구성: 623. ffmpeg.exe를 사용해 비디오 파일의 이미지를 PGM(Portable Gray Map) 파일 포맷으로 출력하는 방법 [1]
12911정성태1/11/202213025VS.NET IDE: 171. 비주얼 스튜디오 - 더 이상 만들 수 없는 "ASP.NET Core 3.1 Web Application (.NET Framework)" 프로젝트
12910정성태1/10/202213737제니퍼 .NET: 30. 제니퍼 닷넷 적용 사례 (8) - CPU high와 DB 쿼리 성능에 문제가 함께 있는 사이트
12909정성태1/10/202215093오류 유형: 782. Visual Studio 2022 설치 시 "Couldn't install Microsoft.VisualCpp.Redist.14.Latest"
12908정성태1/10/202212396.NET Framework: 1132. C# - ref/out 매개변수의 IL 코드 처리
12907정성태1/9/202213978오류 유형: 781. (youtube-dl.exe) 실행 시 "This app can't run on your PC" / "Access is denied." 오류 발생
12906정성태1/9/202215255.NET Framework: 1131. C# - 네임스페이스까지 동일한 타입을 2개의 DLL에서 제공하는 경우 충돌을 우회하는 방법 [1]파일 다운로드1
12905정성태1/8/202214458오류 유형: 780. Could not load file or assembly 'Microsoft.VisualStudio.TextTemplating.VSHost.15.0, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
12904정성태1/8/202216445개발 환경 구성: 623. Visual Studio 2022 빌드 환경을 위한 github Actions 설정 [1]
12903정성태1/7/202215419.NET Framework: 1130. C# - ELEMENT_TYPE_INTERNAL 유형의 사용 예
12902정성태1/7/202215147오류 유형: 779. SQL 서버 로그인 에러 - provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.
12901정성태1/5/202215545오류 유형: 778. C# - .NET 5+에서 warning CA1416: This call site is reachable on all platforms. '...' is only supported on: 'windows' 경고 발생
12900정성태1/5/202217441개발 환경 구성: 622. vcpkg로 ffmpeg를 빌드하는 경우 생성될 구성 요소 제어하는 방법
12899정성태1/3/202216905개발 환경 구성: 621. windbg에서 python 스크립트 실행하는 방법 - pykd (2)
12898정성태1/2/202217646.NET Framework: 1129. C# - ffmpeg(FFmpeg.AutoGen)를 이용한 비디오 인코딩 예제(encode_video.c) [1]파일 다운로드1
12897정성태1/2/202215561.NET Framework: 1128. C# - 화면 캡처한 이미지를 ffmpeg(FFmpeg.AutoGen)로 동영상 처리 [4]파일 다운로드1
12896정성태1/1/202220777.NET Framework: 1127. C# - FFmpeg.AutoGen 라이브러리를 이용한 기본 프로젝트 구성파일 다운로드1
12895정성태12/31/202117658.NET Framework: 1126. C# - snagit처럼 화면 캡처를 연속으로 수행해 동영상 제작 [1]파일 다운로드1
12894정성태12/30/202115685.NET Framework: 1125. C# - DefaultObjectPool<T>의 IDisposable 개체에 대한 풀링 문제 [3]파일 다운로드1
12893정성태12/27/202117436.NET Framework: 1124. C# - .NET Platform Extension의 ObjectPool<T> 사용법 소개파일 다운로드1
12892정성태12/26/202114269기타: 83. unsigned 형의 이전 값이 최댓값을 넘어 0을 지난 경우, 값의 차이를 계산하는 방법
12891정성태12/23/202114928스크립트: 38. 파이썬 - uwsgi의 --master 옵션
12890정성태12/23/202115193VC++: 152. Golang - (문자가 아닌) 바이트 위치를 반환하는 strings.IndexRune 함수
12889정성태12/22/202118003.NET Framework: 1123. C# - (SharpDX + DXGI) 화면 캡처한 이미지를 빠르게 JPG로 변환하는 방법파일 다운로드1
12888정성태12/21/202115158.NET Framework: 1122. C# - ImageCodecInfo 사용 시 System.Drawing.Image와 System.Drawing.Bitmap에 따른 Save 성능 차이파일 다운로드1
... 31  32  33  34  35  36  37  38  39  40  [41]  42  43  44  45  ...