Repository: youtube-dl
Issue: How should I download and get an m4a audio file from youtube video ?
Labels: question


- [x] I'm asking a question
- [x] I've looked through the README and FAQ for similar questions
- [x] I've searched the bugtracker for similar questions including closed ones


## Question


How can I download a youtube video to extract an audio to m4a container ?

I have written this python code 

```
from __future__ import unicode_literals
import youtube_dl
import argparse
import sys
import os


HOME = os.getenv("HOME")

DOWNLOAD_TO = os.path.join(
	HOME, "Music/iTunes/iTunes Media/Automatically Add to iTunes/")


def get_parser():
	"""Get options to parse.
	"""
	parser = argparse.ArgumentParser()
	parser.add_argument("urls", nargs="+")
	parser.add_argument(
		"--format", 
		choices=('mp3', 'm4a'),
		default="mp3",
		help="file format of audio song.")
	parser.add_argument(
		"--quality",
		default='192',
		help="Quality for selected format.")
	return parser.parse_args()


class MyLogger(object):
    def debug(self, msg):
        print("> " + msg)

    def warning(self, msg):
        print("> "+ msg)

    def error(self, msg):
        print(msg)


def my_hook(d):
    if d['status'] == 'finished':
        print('Done downloading, now converting ...')


def run():
	args = get_parser()

	ydl_opts = {
	    'format': 'bestaudio/best',
	    'postprocessors': [{
	        'key': 'FFmpegExtractAudio',
	        'preferredcodec': args.format,
	        'preferredquality': args.quality,
	    }],
	    'logger': MyLogger(),
	    'progress_hooks': [my_hook],
	}
	os.chdir(DOWNLOAD_TO)
	with youtube_dl.YoutubeDL(ydl_opts) as ydl:
	    ydl.download(args.urls)
```

I tried to download m4a with quality 192
`ydla https://www.youtube.com/watch?v=KkvSkWYobHk --format m4a`

I am getting this error


```
File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2018, in download
    res = self.extract_info(
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 808, in extract_info
    return self.process_ie_result(ie_result, download, extra_info)
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 863, in process_ie_result
    return self.process_video_result(ie_result, download=download)
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 1644, in process_video_result
    self.process_info(new_info)
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2000, in process_info
    self.post_process(filename, info_dict)
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2067, in post_process
    self.report_error(e.msg)
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 625, in report_error
    self.trouble(error_message, tb)
  File "/usr/local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 595, in trouble
    raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: audio conversion failed: [aac @ 0x7f973780f600] The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
```

I am not sure if I can add strict through ydl object ! or if my options are incorrect.

Thanks
san