[FFmpeg-user] Use ffmpeg to convert stereo audio to mono

Wesley Wen delbin.wen at gmail.com
Fri Dec 5 05:30:15 CET 2014


Hi,

Could we know how ffmpeg determine audio channel number from MP4 file? MP4
container indicates it's channel count is 2, but ffprobe shows mono as
expected.

--
I use ffmpeg to convert a audio into mono by the following command:

ffmpeg -y -t 30 -i audio.mp4 -dn -sn -vn -map 0 -c:a libfdk_aac -b:a 48k
-ar 44100 -ac 1 audio_48k_mono.mp4

Then I use ffprobe to check the file. It shows the audio stream is mono
(channels: 1).
-------------
{
    "streams": [
        {
            "index": 0,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "codec_type": "audio",
            "codec_time_base": "1/44100",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "44100",
            "channels": 1,
            "channel_layout": "mono",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/44100",
            "start_pts": -2048,
            "start_time": "-0.046440",
            "duration_ts": 1325048,
            "duration": "30.046440",
            "bit_rate": "48085",
            "nb_frames": "1294",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "format": {
        "filename": "INTERNET_tid_9900011_m_audio_48k_mono.mp4",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "-0.046440",
        "duration": "30.047000",
        "size": "186776",
        "bit_rate": "49729",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2mp41",
            "title": "Big Buck Bunny",
            "artist": "Blender Foundation 2008, Janus Bager Kristensen
2013",
            "composer": "Sacha Goedegebure",
            "encoder": "Lavf55.48.100",
            "comment": "sourceURL=http://www.bigbuckbunny.org/",
            "genre": "Animation"
        }
    }
}
----------

And I also use Bento4's mp4dump to check the file. But in "stsd" box, it
says "channel_count":2. Are there something wrong?
---------------
[
{
  "name":"ftyp",
  "header_size":8,
  "size":28,
  "major_brand":"isom",
  "minor_version":512,
  "compatible_brand":"isom",
  "compatible_brand":"iso2",
  "compatible_brand":"mp41"
},
{
  "name":"free",
  "header_size":8,
  "size":8
},
{
  "name":"mdat",
  "header_size":8,
  "size":180608
},
{
  "name":"moov",
  "header_size":8,
  "size":6132,
  "children":[
  {
    "name":"mvhd",
    "header_size":12,
    "size":108,
    "timescale":1000,
    "duration":30047,
    "duration(ms)":30047
  },
  {
    "name":"trak",
    "header_size":8,
    "size":5668,
    "children":[
    {
      "name":"tkhd",
      "header_size":12,
      "size":92,
      "enabled":1,
      "id":1,
      "duration":30047,
      "width":0.000000,
      "height":0.000000
    },
    {
      "name":"edts",
      "header_size":8,
      "size":36,
      "children":[
      {
        "name":"elst",
        "header_size":12,
        "size":28,
        "entry count":1,
        "entry/segment duration":30000,
        "entry/media time":2048,
        "entry/media rate":1
      }]
    },
    {
      "name":"mdia",
      "header_size":8,
      "size":5532,
      "children":[
      {
        "name":"mdhd",
        "header_size":12,
        "size":32,
        "timescale":44100,
        "duration":1325048,
        "duration(ms)":30046,
        "language":"und"
      },
      {
        "name":"hdlr",
        "header_size":12,
        "size":45,
        "handler_type":"soun",
        "handler_name":"SoundHandler"
      },
      {
        "name":"minf",
        "header_size":8,
        "size":5447,
        "children":[
        {
          "name":"smhd",
          "header_size":12,
          "size":16,
          "balance":0
        },
        {
          "name":"dinf",
          "header_size":8,
          "size":36,
          "children":[
          {
            "name":"dref",
            "header_size":12,
            "size":28,
            "children":[
            {
              "name":"url ",
              "header_size":12,
              "size":12,
              "location":"[local to file]"
            }]
          }]
        },
        {
          "name":"stbl",
          "header_size":8,
          "size":5387,
          "children":[
          {
            "name":"stsd",
            "header_size":12,
            "size":103,
            "entry-count":1,
            "children":[
            {
              "name":"mp4a",
              "header_size":8,
              "size":87,
              "data_reference_index":1,
              "channel_count":2,
              "sample_size":16,
              "sample_rate":44100,
              "children":[
              {
                "name":"esds",
                "header_size":12,
                "size":51,
                "children":[
                {
                  "name":"ESDescriptor",
                  "header_size":5,
                  "size":39,
                  "es_id":1,
                  "stream_priority":0,
                  "children":[
                  {
                    "name":"DecoderConfig",
                    "header_size":5,
                    "size":25,
                    "stream_type":5,
                    "object_type":64,
                    "up_stream":0,
                    "buffer_size":0,
                    "max_bitrate":48085,
                    "avg_bitrate":48085,
                    "DecoderSpecificInfo":"12 08 "
                  },
                  {
                    "name":"Descriptor:06",
                    "header_size":5,
                    "size":6
                  }]
                }]
              }]
            }]
          },
          {
            "name":"stts",
            "header_size":12,
            "size":32,
            "entry_count":2,
            "entry        0":"sample_count=1293, sample_duration=1024",
            "entry        1":"sample_count=1, sample_duration=1016"
          },
          {
            "name":"stsc",
            "header_size":12,
            "size":28,
            "entry_count":1,
            "entry        0":"first_chunk=1, first_sample*=1,
chunk_count*=0, samples_per_chunk=1294, sample_desc_index=1"
          },
          {
            "name":"stsz",
            "header_size":12,
            "size":5196,
            "sample_size":0,
            "sample_count":1294,
            "entry        0":139,
            ...
          },
          {
            "name":"stco",
            "header_size":12,
            "size":20,
            "entry_count":1,
            "entry        0":44
          }]
        }]
      }]
    }]
  },
  {
    "name":"udta",
    "header_size":8,
    "size":348,
    "children":[
    {
      "name":"meta",
      "header_size":12,
      "size":340,
      "children":[
      {
        "name":"hdlr",
        "header_size":12,
        "size":33,
        "handler_type":"mdir",
        "handler_name":""
      },
      {
        "name":"ilst",
        "header_size":8,
        "size":295,
        "children":[
        {
          "name":".nam",
          "header_size":8,
          "size":38,
          "children":[
          {
            "name":"data",
            "header_size":8,
            "size":30,
            "type":1,
            "lang":0,
            "value":"Big Buck Bunny"
          }]
        },
        {
          "name":".ART",
          "header_size":8,
          "size":76,
          "children":[
          {
            "name":"data",
            "header_size":8,
            "size":68,
            "type":1,
            "lang":0,
            "value":"Blender Foundation 2008, Janus Bager Kristensen 2013"
          }]
        },
        {
          "name":".wrt",
          "header_size":8,
          "size":41,
          "children":[
          {
            "name":"data",
            "header_size":8,
            "size":33,
            "type":1,
            "lang":0,
            "value":"Sacha Goedegebure"
          }]
        },
        {
          "name":".too",
          "header_size":8,
          "size":37,
          "children":[
          {
            "name":"data",
            "header_size":8,
            "size":29,
            "type":1,
            "lang":0,
            "value":"Lavf55.48.100"
          }]
        },
        {
          "name":".cmt",
          "header_size":8,
          "size":62,
          "children":[
          {
            "name":"data",
            "header_size":8,
            "size":54,
            "type":1,
            "lang":0,
            "value":"sourceURL=http://www.bigbuckbunny.org/"
          }]
        },
        {
          "name":".gen",
          "header_size":8,
          "size":33,
          "children":[
          {
            "name":"data",
            "header_size":8,
            "size":25,
            "type":1,
            "lang":0,
            "value":"Animation"
          }]
        }]
      }]
    }]
  }]
}
]
--------

Testing audio file
URL:
https://www.dropbox.com/s/gjpm7fx496oj5mj/INTERNET_tid_9900011_m_audio_48k_mono.mp4?dl=0
Length: 30s
Container: MP4
Codec: AAC
44100 Hz
mono
48kb/s


More information about the ffmpeg-user mailing list