괜히 복잡하게 고민했네..
qaac64만 쓰더라도 MP4 파일은 m4a로 바꿀 수 있다. 굳이 mp3로 바꿀 필요가 없다면 여기서 멈춰도 되는 것 같다.
인 것 같다. 여기서 아트워크랑 날짜는 크롤링할 때 받아올 수 있으니까 넘기고 비트레이트 목표를 설정해줘야 하는데 이건 영상이 있으면 메타데이터에서 긁을 수 있다.
사실 메타데이터라는 단어를 못 떠올려서 how to get information in video 같은 검색어로 한참 고민한 건 좀 부끄럽다.
ffprobe는 ffmpeg랑 같이 쓸 수 있는 프로그램인 모양인데 실행해보면 이런 느낌으로 뜬다.
{ 'streams': [ { 'avg_frame_rate': '95700000/3189997',
'bit_rate': '2383781',
'bits_per_raw_sample': '8',
'chroma_location': 'left',
'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
'codec_name': 'h264',
'codec_tag': '0x31637661',
'codec_tag_string': 'avc1',
'codec_time_base': '3189997/191400000',
'codec_type': 'video',
'coded_height': 1088,
'coded_width': 1920,
'color_range': 'tv',
'color_space': 'smpte170m',
'disposition': { 'attached_pic': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'original': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '318.998333',
'duration_ts': 9579519950,
'has_b_frames': 2,
'height': 1080,
'index': 0,
'is_avc': 'true',
'level': 50,
'nal_length_size': '4',
'nb_frames': '9570',
'pix_fmt': 'yuv420p',
'profile': 'High',
'r_frame_rate': '30/1',
'refs': 1,
'start_pts': 0,
'start_time': '0.000000',
'tags': { 'creation_time': '2015-07-07T05:23:43.000000Z',
'encoder': 'AVC Coding',
'handler_name': 'L-SMASH Video Media Handler',
'language': 'und'},
'time_base': '1/30030000',
'width': 1920},
{ 'avg_frame_rate': '0/0',
'bit_rate': '189779',
'bits_per_sample': 0,
'channel_layout': 'stereo',
'channels': 2,
'codec_long_name': 'AAC (Advanced Audio Coding)',
'codec_name': 'aac',
'codec_tag': '0x6134706d',
'codec_tag_string': 'mp4a',
'codec_time_base': '1/44100',
'codec_type': 'audio',
'disposition': { 'attached_pic': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'original': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '319.065397',
'duration_ts': 14070784,
'index': 1,
'max_bit_rate': '201448',
'nb_frames': '13741',
'profile': 'LC',
'r_frame_rate': '0/0',
'sample_fmt': 'fltp',
'sample_rate': '44100',
'start_pts': 0,
'start_time': '0.000000',
'tags': { 'creation_time': '2015-07-06T05:24:06.000000Z',
'handler_name': 'GPAC ISO Audio Handler',
'language': 'und'},
'time_base': '1/44100'}]}
여기서 필요한 건 아래쪽의 bit_rate랑 codec_name이다. aac가 아니면 qaac으론 못 긁으니까 좀 곤란하다.
이런 느낌으로 고쳐주면 될 줄 알았는데 다른 파일 보니까 오디오가 비디오보다 먼저 나와서 비디오 코덱이랑 비트레이트가 추출되는 경우도 있더라...
그래서 codec_name = ffprobeOutput['streams'][i]['codec_name'] 로 적고 바로 앞줄에 적절한 i값을 찾을 수 있도록 했다.
이런 느낌으로.
단순화할 수 있을 거 같기는 한데 잘 모르겠다.
문제는 flv파일이었는데 내부 오디오 포맷이 mp3로 돼있더라. 그래서 qaac64로 못 빼내고 lame도 해보니까 분석 불가능해서 돌아돌아가는 방법을 써야 했다.