상세 컨텐츠

본문 제목

ffmpeg (multiple audio) convert to m3u8

카테고리 없음

by 크리두 2020. 2. 5. 16:37

본문

반응형

Sample 영상 m3u8 정보

#EXTM3U
#EXT-X-VERSION:7
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="1",DEFAULT=YES,URI="chunklist_b128000_ao_sfm4s_t64MQ==.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="2",DEFAULT=FALSE,URI="chunklist_b128000_ao_sfm4s_t64Mg==.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="3",DEFAULT=FALSE,URI="chunklist_b128000_ao_sfm4s_t64Mw==.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="4",DEFAULT=FALSE,URI="chunklist_b128000_ao_sfm4s_t64NA==.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="5",DEFAULT=FALSE,URI="chunklist_b128000_ao_sfm4s_t64NQ==.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="aac",NAME="6",DEFAULT=FALSE,URI="chunklist_b128000_ao_sfm4s_t64Ng==.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=16500000,CODECS="avc1.42001e,mp4a.40.2",RESOLUTION=656x274,AUDIO="aac"
chunklist_b16500000_vo_sfm4s.m3u8

 

위와 같이 한 영상에 여러 오디오 채널을 묶는 방법을 찾는 중이다.

영상 하나에 멀티오디오로 구성된 영상을 플레이하기 위해서 playlist를 찾아야 한다.

 

ffprobe를 통한 영상 정보

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mtest.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.20.100
  Duration: 00:04:33.79, start: 0.000000, bitrate: 16644 kb/s
    Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuvj420p(pc, progressive), 11520x1088, 15871 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:4(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:5(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:6(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler

 

multiple audio 때문에 참조 중
HLS 내용 중에서 var_stream_map 을 이용하면 될것이라 보임

ffmpeg 3.4.6버전에서는 var_stream_map 옵션이 사용불가

https://ffmpeg.org/ffmpeg-formats.html

 

FFmpeg Formats Documentation

Table of Contents This document describes the supported formats (muxers and demuxers) provided by the libavformat library. The libavformat library provides some generic global options, which can be set on all the muxers and demuxers. In addition each muxer

ffmpeg.org

  • 명령어 정리

./ffmpeg -i mtest.mp4 \
-map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -map 0:5 -map 0:6 \
-c:v copy \
-c:a:0 copy -c:a:1 copy -c:a:2 copy -c:a:3 copy -c:a:4 copy -c:a:5 copy \
-var_stream_map "v:0 a:0,agroup:aac a:1,agroup:aac a:2,agroup:aac a:3,agroup:aac a:4,agroup:aac a:5,agroup:aac" \
-start_number 0 -hls_time 11 -hls_list_size 0 \
-f hls -master_pl_name mtest.m3u8 \
out_%v.m3u8
  • map : 스트림 파일에 나온 0:0, 0:1 등 파일이 가지고 있는 stream map 선택
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'mtest.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.20.100
  Duration: 00:04:33.79, start: 0.000000, bitrate: 16644 kb/s
    Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuvj420p(pc, progressive), 11520x1088, 15871 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:3(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:4(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:5(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
    Stream #0:6(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s
    Metadata:
      handler_name    : SoundHandler
  • var_stream_map : 오디오, 비디오 및 자막 스트림을 다른 변형 스트림으로 그룹화하는 방법을 지정하는 맵 문자열
  • master_pl_name : 파일 내 여러 스트림의 마스터 플레이리스트 지정
    • 아래는 mtest.m3u8 내용
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group_aac",NAME="audio_0",DEFAULT=YES,URI="out_1.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group_aac",NAME="audio_0",DEFAULT=YES,URI="out_2.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group_aac",NAME="audio_0",DEFAULT=YES,URI="out_3.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group_aac",NAME="audio_0",DEFAULT=YES,URI="out_4.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group_aac",NAME="audio_0",DEFAULT=YES,URI="out_5.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="group_aac",NAME="audio_0",DEFAULT=YES,URI="out_6.m3u8"
#EXT-X-STREAM-INF:BANDWIDTH=17458353,RESOLUTION=11520x1088
out_0.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=137927,CODECS="mp4a.40.2",AUDIO="group_aac"
out_1.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=137927,CODECS="mp4a.40.2",AUDIO="group_aac"
out_2.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=137927,CODECS="mp4a.40.2",AUDIO="group_aac"
out_3.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=137927,CODECS="mp4a.40.2",AUDIO="group_aac"
out_4.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=137927,CODECS="mp4a.40.2",AUDIO="group_aac"
out_5.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=137927,CODECS="mp4a.40.2",AUDIO="group_aac"
out_6.m3u8

 

Test한 결과를 보아하니 GROUP-ID를 통해서 오디오를 하나로 묶으면 동작하는것을 알게 되었다.

여러 playlist 형태에 따라 동작이 다양하니 같은걸 찾는다면 참고하면 좋을 것이다.

반응형

댓글 영역