On Thu, Oct 11, 2012 at 4:06 PM, Carl Eugen Hoyos <ceho...@ag.or.at> wrote: > Michael Bradshaw <mbradshaw@...> writes: > >> I've just been hunting down a bug in one of our programs, and I >> tracked it down to the number of channels reported by ffmpeg. When I >> first open the AVFormatContext and do avformat_find_stream_info(), I >> can see that my audio stream's AVCodecContext has a reported >> channel_layout of 3 (stereo) and channels == 2. However, when I call >> avcodec_open2() to start decoding, it changes the streams' >> AVCodecContext channel info so that channel_layout is 4 (mono) and >> channels == 1! This is causing a crash in a later part of the program, >> as one part of the program expects two channels and the other part >> expects 1 channel. >> >> Two questions: >> >> 1) Is this "expected behavior" in any case, or is it a bug? > > While I cannot really answer the question, I wonder > what you expect when the number of channels really change: > At least for AC-3 and AAC, this is not only allowed, > but happens regularly (for example on DVB).
Really? That's useful to know. I suppose I should rely on AVFrame.channels, correct? While that's useful to know, I don't think it this AAC stream changes channels. I just used ffprobe to look at this file. You'll see that when it dumps the format (dump_format), it shows the aac stream as being stereo, but the [STREAM] info from ffprobe says channels=1. ./ffprobe -show_streams -select_streams 0 ~/MP4-Apple264-AACPlus.mp4 ffprobe version N-45341-g3632f35 Copyright (c) 2007-2012 the FFmpeg developers built on Oct 11 2012 16:10:23 with gcc 4.2.1 (GCC) (Apple Inc. build 5666) (dot 3) configuration: --enable-libopenjpeg --enable-libx264 --enable-gpl libavutil 51. 74.100 / 51. 74.100 libavcodec 54. 65.100 / 54. 65.100 libavformat 54. 32.100 / 54. 32.100 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 19.102 / 3. 19.102 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 16.100 / 0. 16.100 libpostproc 52. 1.100 / 52. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/mjbshaw/MP4-Apple264-AACPlus.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42isomavc1 creation_time : 2012-01-16 21:01:41 encoder : Sorenson Squeeze Duration: 00:00:11.19, start: 0.000000, bitrate: 789 kb/s Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 32 kb/s Metadata: creation_time : 2012-01-16 21:01:41 handler_name : soun Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 480x360, 765 kb/s, 23.98 fps, 23.98 tbr, 23976 tbn, 47952 tbc Metadata: creation_time : 2012-01-16 21:01:41 handler_name : vide Stream #0:2(und): Data: none (mp4s / 0x7334706D) Metadata: creation_time : 2012-01-16 21:01:57 handler_name : sdsm Stream #0:3(und): Data: none (mp4s / 0x7334706D) Metadata: creation_time : 2012-01-16 21:01:57 handler_name : odsm Unsupported codec with id 0 for input stream 2 Unsupported codec with id 0 for input stream 3 [STREAM] index=0 codec_name=aac codec_long_name=AAC (Advanced Audio Coding) profile=unknown codec_type=audio codec_time_base=1/22050 codec_tag_string=mp4a codec_tag=0x6134706d sample_fmt=s16 sample_rate=44100 channels=1 bits_per_sample=0 id=N/A r_frame_rate=0/0 avg_frame_rate=0/0 time_base=1/44100 start_pts=0 start_time=0.000000 duration_ts=493568 duration=11.192018 bit_rate=32000 nb_frames=241 nb_read_frames=N/A nb_read_packets=N/A DISPOSITION:default=0 DISPOSITION:dub=0 DISPOSITION:original=0 DISPOSITION:comment=0 DISPOSITION:lyrics=0 DISPOSITION:karaoke=0 DISPOSITION:forced=0 DISPOSITION:hearing_impaired=0 DISPOSITION:visual_impaired=0 DISPOSITION:clean_effects=0 DISPOSITION:attached_pic=0 TAG:creation_time=2012-01-16 21:01:41 TAG:language=und TAG:handler_name=soun [/STREAM] But all of the frames have channels=2: $ ./ffprobe -show_frames -select_streams 0 ~/MP4-Apple264-AACPlus.mp4 ffprobe version N-45341-g3632f35 Copyright (c) 2007-2012 the FFmpeg developers built on Oct 11 2012 16:10:23 with gcc 4.2.1 (GCC) (Apple Inc. build 5666) (dot 3) configuration: --enable-libopenjpeg --enable-libx264 --enable-gpl libavutil 51. 74.100 / 51. 74.100 libavcodec 54. 65.100 / 54. 65.100 libavformat 54. 32.100 / 54. 32.100 libavdevice 54. 3.100 / 54. 3.100 libavfilter 3. 19.102 / 3. 19.102 libswscale 2. 1.101 / 2. 1.101 libswresample 0. 16.100 / 0. 16.100 libpostproc 52. 1.100 / 52. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/mjbshaw/MP4-Apple264-AACPlus.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42isomavc1 creation_time : 2012-01-16 21:01:41 encoder : Sorenson Squeeze Duration: 00:00:11.19, start: 0.000000, bitrate: 789 kb/s Stream #0:0(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 32 kb/s Metadata: creation_time : 2012-01-16 21:01:41 handler_name : soun Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 480x360, 765 kb/s, 23.98 fps, 23.98 tbr, 23976 tbn, 47952 tbc Metadata: creation_time : 2012-01-16 21:01:41 handler_name : vide Stream #0:2(und): Data: none (mp4s / 0x7334706D) Metadata: creation_time : 2012-01-16 21:01:57 handler_name : sdsm Stream #0:3(und): Data: none (mp4s / 0x7334706D) Metadata: creation_time : 2012-01-16 21:01:57 handler_name : odsm Unsupported codec with id 0 for input stream 2 Unsupported codec with id 0 for input stream 3 [FRAME] media_type=audio key_frame=1 pkt_pts=0 pkt_pts_time=0.000000 pkt_dts=0 pkt_dts_time=0.000000 pkt_duration=2048 pkt_duration_time=0.046440 pkt_pos=6211 sample_fmt=s16 nb_samples=2048 channels=2 channel_layout=stereo [/FRAME] [FRAME] media_type=audio key_frame=1 pkt_pts=2048 pkt_pts_time=0.046440 pkt_dts=2048 pkt_dts_time=0.046440 pkt_duration=2048 pkt_duration_time=0.046440 pkt_pos=24505 sample_fmt=s16 nb_samples=2048 channels=2 channel_layout=stereo [/FRAME] [...and so on; every frame has channels=2...] Any thoughts? Thanks, Michael _______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user