Opened 13 years ago

Closed 12 years ago

#542 closed defect (fixed)

Missing aac audio after encoding to mpeg-ts with very high video bitrate

Reported by: Terran Vigil Owned by: Michael Niedermayer
Priority: normal Component: avformat
Version: git-master Keywords: aac mpegts
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

When encoding from h264/aac mp4 to mpeg-ts, the audio stream is lost or corrupt. Mediainfo reports an audio stream but it appears to be empty. This *only* occurs when '-threads' set to 0. Using a specific thread size (e.g. -threads 4) prevents the issue.

I can consistently reproduce this with centos 5, but not with osx.

Note that both audio and video playback with -threads >0 as well as builds from August and earlier.

command used:

ffmpeg -i rehearsal.mp4 -threads 0 -s 1920x1080 -f mpegts -b:v 7000000 -qscale:v 1 -r 30.0 -g 30.0 -map_chapters -1 -vcodec libx264 -coder 0 -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method hex -subq 5 -me_range 16 -keyint_min 25 -sc_threshold 0 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -directpred 1 -wpredp 0 -fast-pskip 1 -vprofile baseline -acodec libfaac -b:a 48000 -ac 2 -ar 44100 -t 5 -y rehearsal.ts

output from ffmpeg -v 9 -loglevel 99 -i:

ffmpeg version N-33513-g3473639, Copyright (c) 2000-2011 the FFmpeg developers

built on Oct 11 2011 10:15:29 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
configuration: --enable-pthreads --enable-avfilter --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-libx264 --enable-libfaac
libavutil 51. 20. 1 / 51. 20. 1
libavcodec 53. 20. 1 / 53. 20. 1
libavformat 53. 15. 0 / 53. 15. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 43. 6 / 2. 43. 6
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x17a32780] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x17a32780] ISO: File Type Major Brand: mp42
[aac @ 0x17a3a7e0] Unsupported bit depth: 0
[h264 @ 0x17a39a40] no picture
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x17a32780] All info found

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (2997/100)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'rehearsal.mp4':

Metadata:

major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2011-08-17 04:36:21

Duration: 00:12:29.95, start: 0.000000, bitrate: 30155 kb/s

Stream #0:0(eng), 10, 1/29970: Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1001/60000, 29995 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 59.94 tbc
Metadata:

creation_time : 2011-08-17 04:36:21

Stream #0:1(eng), 1, 1/48000: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 157 kb/s
Metadata:

creation_time : 2011-08-17 04:36:21

Change History (55)

comment:1 by Terran Vigil, 13 years ago

I'm unable to upload to upload.ffmpeg.org/incoming:

Command: PASV
Response: 227 Entering Passive Mode (138,195,131,196,156,232)
Command: STOR ticket542.mp4
Response: 553-Can't open that file: Permission denied

comment:2 by Terran Vigil, 13 years ago

Please let me know if there is another secure way to provide the file or if any other debug info would be helpful.

comment:3 by Carl Eugen Hoyos, 13 years ago

Component: FFmpegundetermined
Priority: importantnormal

Is the problem also reproducible without an external library, i.e. without libx264 and without libfaac?

comment:4 by Carl Eugen Hoyos, 13 years ago

You can upload files to http://www.datafilehost.com/

comment:5 by Terran Vigil, 13 years ago

I recompiled without libx264 and without libfaac. Using "-vcodec copy -acodec copy" I am not able to reproduce the issue. The versions of both work with previous builds of ffmpeg though.

Also, as there were stream-specific changed to "-threads", I've also tested with "-threads:0 0 -threads:1 0" with also had the audio issue.

I cannot upload the file to datafilehost.com as the owner of the content does not want it made available to the general public. When I trim the file so that it is < 2.5Mb the bug is also not reproducible.

in reply to:  5 ; comment:6 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

Using "-vcodec copy -acodec copy" I am not able to reproduce the issue.

I meant more something like
ffmpeg -i rehearsal.mp4 -qscale 2 -threads 0 out.ts
(Definitely no need to recompile)

Is the problem only reproducible for ts, or also for mp4?
Is the problem perhaps only libfaac related? (ffmpeg -i rehearsal.mp4 -qscale 2 -threads 0 -acodec libfaac out.ts or ffmpeg -i rehearsal.mp4 -threads 0 -vn -acodec libfaac out.ts or ffmpeg -i rehearsal.mp4 -threads 0 -acodec libfaac out.aac)

Is the problem reproducible with any sample or really only with a specific one?

in reply to:  6 comment:7 by Terran Vigil, 13 years ago

I meant more something like
ffmpeg -i rehearsal.mp4 -qscale 2 -threads 0 out.ts
(Definitely no need to recompile)

Are there other params required? That command results in:

Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

Is the problem only reproducible for ts, or also for mp4?

It appears to be mpeg-ts only. Muxing to mp4 works. I dont know if it's related, but using libavformat to open the file shows a different format as well. With ts:

Output #0, mpegts, to :

Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080, q=2-31, 10015 kb/s, 90k tbn, 30 tbc
Stream #0:1: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, 33 kb/s

With mp4:

Output #0, mpegts, to 's':

Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p, 1920x1080, q=2-31, 90k tbn, 30 tbc
Stream #0:1: Audio: aac ([15][0][0][0] / 0x000F), 0 channels

Is the problem perhaps only libfaac related? (ffmpeg -i rehearsal.mp4 -qscale 2 -threads 0 -acodec libfaac out.ts or ffmpeg -i rehearsal.mp4 -threads 0 -vn -acodec libfaac out.ts or ffmpeg -i rehearsal.mp4 -threads 0 -acodec libfaac out.aac)

Doesn't look like it's libfaac. The following worked, verified the audio:

ffmpeg -i rehearsal.mp4 -threads 0 -f mpegts -vn -acodec libfaac -ab 48000 rehearsal.ts

Is the problem reproducible with any sample or really only with a specific one?

I've tried other files but haven't reproduced it with others.

comment:8 by Carl Eugen Hoyos, 13 years ago

Please provide at least complete, uncut output of your failing command, the command should be as short as possible and please do not use an external library if it is not needed to reproduce the problem.

comment:9 by Terran Vigil, 13 years ago

ffmpeg version N-33513-g3473639, Copyright (c) 2000-2011 the FFmpeg developers

built on Oct 11 2011 14:54:45 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
configuration: --enable-pthreads --enable-avfilter --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfaac --enable-libmp3lame
libavutil 51. 20. 1 / 51. 20. 1
libavcodec 53. 20. 1 / 53. 20. 1
libavformat 53. 15. 0 / 53. 15. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 43. 6 / 2. 43. 6
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (2997/100)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'rehearsal.mp4':

Metadata:

major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2011-08-17 04:36:21

Duration: 00:12:29.95, start: 0.000000, bitrate: 30155 kb/s

Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29995 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 59.94 tbc
Metadata:

creation_time : 2011-08-17 04:36:21

Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 157 kb/s
Metadata:

creation_time : 2011-08-17 04:36:21

[buffer @ 0x14785d20] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[libx264 @ 0x1478c180] using SAR=1/1
[libx264 @ 0x1478c180] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2
[libx264 @ 0x1478c180] profile Constrained Baseline, level 4.0
[mpegts @ 0x14754400] muxrate VBR, pcr every 3 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'rehearsal.ts':

Metadata:

major_brand : mp42
minor_version : 0
compatible_brands: mp42mp41
creation_time : 2011-08-17 04:36:21
encoder : Lavf53.15.0
Stream #0:0(eng): Video: h264, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=10-51, 7000 kb/s, 90k tbn, 30 tbc
Metadata:

creation_time : 2011-08-17 04:36:21

Stream #0:1(eng): Audio: aac, 44100 Hz, 2 channels, s16, 48 kb/s
Metadata:

creation_time : 2011-08-17 04:36:21

Stream mapping:

Stream #0.0 -> #0.0 (h264 -> libx264)
Stream #0.1 -> #0.1 (aac -> libfaac)

Press [q] to stop, ? for help
frame= 150 fps= 9 q=-1.0 Lsize= 6631kB time=00:00:04.96 bitrate=10937.8kbits/s dup=1 drop=0
video:6111kB audio:22kB global headers:0kB muxing overhead 8.124616%
[libx264 @ 0x1478c180] frame I:5 Avg QP:13.31 size: 89682
[libx264 @ 0x1478c180] frame P:145 Avg QP:18.54 size: 40064
[libx264 @ 0x1478c180] mb I I16..4: 70.3% 0.0% 29.7%
[libx264 @ 0x1478c180] mb P I16..4: 34.2% 0.0% 9.1% P16..4: 20.7% 7.6% 2.5% 0.0% 0.0% skip:26.0%
[libx264 @ 0x1478c180] final ratefactor: 19.93
[libx264 @ 0x1478c180] coded y,uvDC,uvAC intra: 25.1% 23.7% 7.0% inter: 12.6% 11.7% 1.2%
[libx264 @ 0x1478c180] i16 v,h,dc,p: 46% 28% 13% 13%
[libx264 @ 0x1478c180] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 23% 22% 5% 5% 5% 5% 4% 4%
[libx264 @ 0x1478c180] i8c dc,h,v,p: 66% 17% 13% 3%
[libx264 @ 0x1478c180] ref P L0: 68.3% 21.3% 10.4%
[libx264 @ 0x1478c180] kb/s:10012.22

comment:10 by Carl Eugen Hoyos, 13 years ago

Please always post a failing command line together with complete, uncut output and use "Code block" to make your output more readable.
Please test without -vcodec libx264, if ffmpeg -i rehearsal.mp4 -qscale 2 -threads 0 out.ts fails, please give me a chance to understand why.

comment:11 by Terran Vigil, 13 years ago

cehoyos: It looks like that command was failing because the libavcodec mpeg2 codec doesn't support thread number detection?

$ ffmpeg -i rehearsal.mp4 -qscale 2 -threads 0 out.ts
ffmpeg version N-33513-g3473639, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 11 2011 14:54:45 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  configuration: --enable-pthreads --enable-avfilter --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfaac --enable-libmp3lame
  libavutil    51. 20. 1 / 51. 20. 1
  libavcodec   53. 20. 1 / 53. 20. 1
  libavformat  53. 15. 0 / 53. 15. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 6 /  2. 43. 6
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (2997/100)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'rehearsal.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2011-08-17 04:36:21
  Duration: 00:12:29.95, start: 0.000000, bitrate: 30155 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29995 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 59.94 tbc
    Metadata:
      creation_time   : 2011-08-17 04:36:21
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 157 kb/s
    Metadata:
      creation_time   : 2011-08-17 04:36:21
File 'out.ts' already exists. Overwrite ? [y/N] y
w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[mpeg2video @ 0x1e091d20] automatic thread number detection not supported by codec, patch welcome
Output #0, mpegts, to 'out.ts':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2011-08-17 04:36:21
    Stream #0:0(eng): Video: mpeg2video, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
    Metadata:
      creation_time   : 2011-08-17 04:36:21
    Stream #0:1(eng): Audio: none, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 2011-08-17 04:36:21
Stream mapping:
  Stream #0.0 -> #0.0 (h264 -> mpeg2video)
  Stream #0.1 -> #0.1 (aac -> mp2)
Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

Changing to "-threads 1" worked and produced and mpeg-ts/mpeg2 that contained a valid audio stream:

fmpeg version N-33513-g3473639, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 11 2011 14:54:45 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  configuration: --enable-pthreads --enable-avfilter --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfaac --enable-libmp3lame
  libavutil    51. 20. 1 / 51. 20. 1
  libavcodec   53. 20. 1 / 53. 20. 1
  libavformat  53. 15. 0 / 53. 15. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 6 /  2. 43. 6
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (2997/100)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'rehearsal_long.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2011-08-17 04:36:21
  Duration: 00:12:29.95, start: 0.000000, bitrate: 30155 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29995 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 59.94 tbc
    Metadata:
      creation_time   : 2011-08-17 04:36:21
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 157 kb/s
    Metadata:
      creation_time   : 2011-08-17 04:36:21
[buffer @ 0xc02d160] w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[mpegts @ 0xbffb040] muxrate VBR, pcr every 2 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'out.ts':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2011-08-17 04:36:21
    encoder         : Lavf53.15.0
    Stream #0:0(eng): Video: mpeg2video, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 29.97 tbc
    Metadata:
      creation_time   : 2011-08-17 04:36:21
    Stream #0:1(eng): Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 2011-08-17 04:36:21
Stream mapping:
  Stream #0.0 -> #0.0 (h264 -> mpeg2video)
  Stream #0.1 -> #0.1 (aac -> mp2)
Press [q] to stop, [?] for help
frame=  150 fps= 25 q=2.0 Lsize=   13272kB time=00:00:04.97 bitrate=21868.3kbits/s dup=1 drop=0    
video:12215kB audio:78kB global headers:0kB muxing overhead 7.956972%
Last edited 13 years ago by Terran Vigil (previous) (diff)

comment:12 by Terran Vigil, 13 years ago

Something else that I found during testing just now ... "-threads 4" fails just like "-threads 0", though "-threads 1/2/3" all work. This is on a 4 core box, 64-bit.

comment:13 by Carl Eugen Hoyos, 13 years ago

Do -threads 5/6/7/8 work?

Does ffmpeg -i rehearsal.mp4 -qscale 2 -threads 4 out.ts work? Which option do you have to add to reproduce your original problem?

in reply to:  13 comment:14 by Terran Vigil, 13 years ago

Do -threads 5/6/7/8 work?

No. It looks like 0, 4+ fail. Sounds like if the threads are => than the core count, this bug is triggered.

Does ffmpeg -i rehearsal.mp4 -qscale 2 -threads 4 out.ts work?

Yes, that works. I have only reproduced this with x264 + mpeg-ts.

Which option do you have to add to reproduce your original problem?

The minimum set is:

-vcodec libx264 -b:v 7000000 -acodec libfaac -threads 0

Interestingly, I found that changing 7000000 to 700000 also eliminates the problem. I do need the 7Mbps encode though.

comment:15 by Carl Eugen Hoyos, 13 years ago

ffmpeg -i rehearsal.mp4 -vcodec libx264 -b:v 7000000 -strict experimental -acodec aac out.ts works fine?

Version 0, edited 13 years ago by Carl Eugen Hoyos (next)

in reply to:  15 ; comment:16 by Terran Vigil, 13 years ago

ffmpeg -i rehearsal.mp4 -threads 4 -vcodec libx264 -b:v 7000000 -strict experimental -acodec aac out.ts works fine?

It does work at the moment, as does the previous command with -threads 4, but changing to -threads 0 causes the failure again. The behavior is non-deterministic when -threads 4, but will always fail with -threads 0 apparently.

In other words, this fails too:

ffmpeg -i rehearsal.mp4 -threads 0 -vcodec libx264 -b:v 7000000 -strict experimental -acodec aac out.ts

But this does not:

ffmpeg -i rehearsal.mp4 -threads 4 -vcodec libx264 -b:v 7000000 -strict experimental -acodec aac out.ts

Also, I'm using 'git bisect' to narrow down the changelist that introduced the problem. So far, I can say that it happened between sept 5 and sept 10. I'll provide more details on that when I narrow further.

in reply to:  16 comment:17 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

In other words, this fails too:

ffmpeg -i rehearsal.mp4 -threads 0 -vcodec libx264 -b:v 7000000 -strict experimental -acodec aac out.ts

What about ffmpeg -i rehearsal.mp4 -threads 0 -vcodec libx264 -b:v 7000000 -acodec mp2 out.ts
and ffmpeg -i rehearsal.mp4 -threads 0 -vcodec libx264 -b:v 7000000 -acodec mp2 out.avi / out.mp4 ?

comment:18 by Terran Vigil, 13 years ago

Muxing to avi seems to work but ts and mp4 have problems - the dts' are off. That could be a red herring but thought I'd mention it.

Good news, I think, in that 'git bisect' narrowed down the checkin where this broke:

The instruction set changes for scaling seem like a good place to start - particularly since I don't see this issue on my mac.

[2fd49019210a9fbe430b1b94ff7a2f98a6d0fed1] Merge remote-tracking branch 'qatar/master'
qatar/master:

sws: implement MMX/SSE2/SSSE3/SSE4 versions for horizontal scaling.
include stdint.h in adpcm_data.h
mpeg12: reorder functions to avoid ugly forward declarations
Fixed off by one packet size allocation in the smacker demuxer.
Check for invalid packet size in the smacker demuxer.
ape demuxer: fix segfault on memory allocation failure.
xan: Add some buffer checks
xan: Remove extra trailing newline
Fixed size given to init_get_bits() in xan decoder.

comment:19 by Terran Vigil, 13 years ago

I'm not so certain that I've found the bad changelist. I found that I hadn't completely uninstalled he previous version's libraries. I'm improved my regression script and re-running. I'll update with the correct changelist when I find it.

comment:20 by Terran Vigil, 13 years ago

I've rerun all of my tests and confirmed that the changelist where this first breaks is:

2fd49019210a9fbe430b1b94ff7a2f98a6d0fed1: Merge remote-tracking branch 'qatar/master'
qatar/master

comment:21 by Terran Vigil, 13 years ago

Note that the changes I'd listed were different though - grabbed comments from a checkin that had the same title. This is the correct list:

Merge remote-tracking branch 'qatar/master'

  • qatar/master: libx264: add 'cplxblur' private option libx264: add 'deblock' private option libx264: add 'b-bias' private option libx264: fix setting some options. libx264: remove useless assignment ac3dec: avoid pointless alloc and indirection for input_buffer mpeg12: cosmetics: reformat as K&R

comment:22 by Terran Vigil, 13 years ago

I've further narrowed down the change to the file libavcodec/libx264.c. There were quite a few changes to this file, so if anyone monitoring git who has some familiarity with this code has a chance to look at the diff, I'd welcome any input.

Is it possible that with the addition of new private options that one of the defaults is causing the stream corruption?

comment:23 by Terran Vigil, 13 years ago

The regression seems to be related to the following change:

    x4->params.rc.i_qp_min                 = avctx->qmin;
    x4->params.rc.i_qp_max                 = avctx->qmax;
    x4->params.rc.i_qp_step                = avctx->max_qdiff;


became...

    if (avctx->qmin >= 0)
        x4->params.rc.i_qp_min          = avctx->qmin;
    if (avctx->qmax >= 0)
        x4->params.rc.i_qp_max          = avctx->qmax;
    if (avctx->max_qdiff >= 0)
        x4->params.rc.i_qp_step         = avctx->max_qdiff;

I imagine there may be other related changes but removing these eliminated the bug for me.

comment:25 by Terran Vigil, 13 years ago

I've found other issues with this checkin. For example, I set '-keyint_min 25' but the result is a keyint_min of 16. Note that I disabled scenecut detection: "-sc_threshold 0".

in reply to:  12 comment:26 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

Something else that I found during testing just now ... "-threads 4" fails just like "-threads 0"

Is this still correct or not? If yes, could you confirm if -vcodec libx264 is needed to reproduce the problem or if it is also reproducible with -vcodec mpeg4 -qscale 2?

And please try to repeat what the problem is (no sound?), what the shortest command line is to trigger this problem and how output looks like. Please test the native aac, the native mp2 and an external aac encoder and different containers.
Finally, please post complete, uncut output for the failing command (together with the short command line).

comment:27 by Terran Vigil, 13 years ago

The problem is that when I use libavformat to open the file, it doesn't find the audio stream:

Output #0, mpegts, to 's':

Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuv420p, 1920x1080, q=2-31, 90k tbn, 30 tbc
Stream #0:1: Audio: aac ([15][0][0][0] / 0x000F), 0 channels

[mpegts @ 0x18cf3ee0] sample rate not set

Per your other question, mpeg4 does not work with -threads 0:

[mpeg4 @ 0x36ea180] automatic thread number detection not supported by codec, patch welcome

I've provided a lot of other information, including isolating the changelist where this broke. Is any of this useful? It looks like it's triggered by the changes in sending qmin, qmax and sc_threshold. I disable scenecut detection with '-sc_threshold 0' which may also be related.

If you there is a private fpt host I could use to upload the file I would provide it so you can reproduce.

in reply to:  27 comment:28 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

I've provided a lot of other information, including isolating the changelist where this broke. Is any of this useful?

I guess so, but you also provided the information that "-threads 4" fails just like "-threads 0", so I asked you to test -threads 4 -vcodec mpeg4 if (and only if) this information was correct.
It happens often to me that I test and reports something and it turns out that my report was not correct, in such a case it is important to test and report again, indeterministic behaviour is very, very unlikely (if your memory isn't broken).

comment:29 by Terran Vigil, 13 years ago

Is there any other information I can provide that will help with this issue? I've retried ftp'ing to upload.ffmpeg.org but anonymous PUTs seem to still be broken.

comment:30 by Carl Eugen Hoyos, 13 years ago

Please clarify if "-threads 4" fails just like "-threads 0" was correct or not (similar for threads 5/6/7/8).

comment:31 by Carl Eugen Hoyos, 13 years ago

And isn't your problem reproducible with any input file?

in reply to:  30 ; comment:32 by Terran Vigil, 13 years ago

Replying to cehoyos:

Please clarify if "-threads 4" fails just like "-threads 0" was correct or not (similar for threads 5/6/7/8).

Yes, "-threads 4" fails as well as 5/6/7/8. When I use -threads 0, 6 threads are used.

in reply to:  32 ; comment:33 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

Replying to cehoyos:

Please clarify if "-threads 4" fails just like "-threads 0" was correct or not (similar for threads 5/6/7/8).

Yes, "-threads 4" fails as well as 5/6/7/8. When I use -threads 0, 6 threads are used.

Then please test ffmpeg -i rehearsal.mp4 -threads 4 -vcodec libx264 -b:v 7000000 -acodec mp2 out.ts

in reply to:  31 comment:34 by Terran Vigil, 13 years ago

Replying to cehoyos:

And isn't your problem reproducible with any input file?

No, I only have a couple files where this happens. Another interesting thing I've found is that if I only transcode the first 3 seconds of the video I do not see the issue. But if I go beyond that, it fails. The first few seconds of the video are silent because they are an intro screen before the video starts.

in reply to:  33 ; comment:35 by Terran Vigil, 13 years ago

Replying to cehoyos:

Replying to terran:

Replying to cehoyos:

Please clarify if "-threads 4" fails just like "-threads 0" was correct or not (similar for threads 5/6/7/8).

Yes, "-threads 4" fails as well as 5/6/7/8. When I use -threads 0, 6 threads are used.

Then please test ffmpeg -i rehearsal.mp4 -threads 4 -vcodec libx264 -b:v 7000000 -acodec mp2 out.ts

That command works and provides a valid audio stream, though I had to add '-b:a 48000 -ac 2 -ar 44100' to the command as required.

in reply to:  35 ; comment:36 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

Replying to cehoyos:

Then please test ffmpeg -i rehearsal.mp4 -threads 4 -vcodec libx264 -b:v 7000000 -acodec mp2 out.ts

That command works and provides a valid audio stream, though I had to add '-b:a 48000 -ac 2 -ar 44100' to the command as required.

What happened without the options you added? (Just curious.)

in reply to:  36 comment:37 by Terran Vigil, 13 years ago

Replying to cehoyos:

Replying to terran:

Replying to cehoyos:

Then please test ffmpeg -i rehearsal.mp4 -threads 4 -vcodec libx264 -b:v 7000000 -acodec mp2 out.ts

That command works and provides a valid audio stream, though I had to add '-b:a 48000 -ac 2 -ar 44100' to the command as required.

What happened without the options you added? (Just curious.)

I had already sync'd to head again and am not able to repro the error, but it was one of the generic:

"Error while opening encoder for output stream #0.1 - maybe incorrect parameters such as..."

comment:38 by Terran Vigil, 13 years ago

I've found that the bug will trigger for me when these two params are modified from their defaults:

-sc_threshold 40
-qmin 0

For example, if I hold sc_threshold at 40, I can raise qmin from 0-5. 6+ fails. And if I hold qmin at 0, I can lower sc_threshold down to 1.

Were there threading/instruction set/etc changes that relate to either of these params in the last couple of months? Could either of these somehow affect libfaad or muxing?

comment:39 by Terran Vigil, 13 years ago

I ruled out recent changes to mpegts.c by reverting to changelist 2e15305b7088c9dfe1c8d29c248a9b49bcf0b0a3 which was checked in on 4/29/2011. I was able to reproduce the bug with this older version of mpegts.c.

comment:40 by Terran Vigil, 13 years ago

cehoyos: I was able to get permission from the content owner to upload the file to datafilehost. Here is the link:

http://www.datafilehost.com/download-0160ff9a.html

comment:41 by Carl Eugen Hoyos, 13 years ago

Can't you reproduce with

ffmpeg -threads 1 -i rehearsal.mp4 -qscale 1 -strict experimental -acodec aac out.ts

?

comment:42 by Terran Vigil, 13 years ago

Yes, that will fail as well.

comment:43 by Terran Vigil, 13 years ago

To be clear, when I say "fail" I mean that using libavformat's av_dump_format(..) will report:

Stream #0:1: Audio: aac ([15][0][0][0] / 0x000F), 0 channels
Last edited 13 years ago by Terran Vigil (previous) (diff)

comment:44 by Terran Vigil, 13 years ago

Sorry, I missed your inclusion of "-threads 1". With the latest head it is not just the simple command you listed that will reproduce. Using the following two settings seems to trigger the bug:

-threads 0
-sc_threshold 40
-qmin 0

The exact command that fails is:

threads 0 -s 1920x1080 -f mpegts -b:v 7000000 -qscale:v 1 -r 30.0 -g 30.0 -map_chapters -1 -vcodec libx264 -coder 0 -loop 1 -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method hex -subq 5 -me_range 16 -keyint_min 25 -sc_threshold 0 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -directpred 1 -wpredp 0 -vprofile baseline -acodec libfaac -b:a 48000 -ac 2 -ar 44100

Changing this to the following also fails:

threads 0 -s 1920x1080 -f mpegts -b:v 7000000 -qscale:v 1 -r 30.0 -g 30.0 -map_chapters -1 -vcodec libx264 -coder 0 -loop 1 -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method hex -subq 5 -me_range 16 -keyint_min 25 -sc_threshold 0 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -directpred 1 -wpredp 0 -vprofile baseline -strict experimental -acodec aac -b:a 48000 -ac 2 -ar 44100

comment:45 by Carl Eugen Hoyos, 13 years ago

No encoding problem afaict, the resulting file plays fine with mplayer -demuxer lavf, mplayer -demuxer mpegts -tsprobe 1000000000 and vlc.

Difference to ticket #566 is that -analyzeduration 2000000000 does not help.

in reply to:  44 comment:46 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

Sorry, I missed your inclusion of "-threads 1". With the latest head it is not just the simple command you listed that will reproduce.

Then please post complete, uncut output of

$ ffmpeg -threads 1 -i rehearsal.mp4 -qscale 1 -strict experimental -acodec aac out.ts
$ ffmpeg -i out.ts

comment:47 by Terran Vigil, 13 years ago

That command does reproduce the issue:

ffmpeg -threads 1 -i ../rehearsal_short.mp4 -qscale 1 -strict experimental -acodec aac out.ts
ffmpeg version N-33726-g0556eee, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 17 2011 17:57:32 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  configuration: --enable-pthreads --enable-avfilter --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfaac
  libavutil    51. 21. 0 / 51. 21. 0
  libavcodec   53. 20. 1 / 53. 20. 1
  libavformat  53. 16. 0 / 53. 16. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 6 /  2. 43. 6
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '../rehearsal_short.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2011-08-17 05:00:00
    encoder         : Lavf53.15.0
  Duration: 00:00:05.03, start: 0.000000, bitrate: 9978 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 10015 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc
    Metadata:
      creation_time   : 2011-08-17 05:00:00
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 33 kb/s
    Metadata:
      creation_time   : 2011-08-17 05:00:00
File 'out.ts' already exists. Overwrite ? [y/N] y
w:1920 h:1080 pixfmt:yuv420p tb:1/1000000 sar:1/1 sws_param:
[mpegts @ 0xc1223c0] muxrate VBR, pcr every 3 pkts, sdt every 200, pat/pmt every 40 pkts
Output #0, mpegts, to 'out.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2011-08-17 05:00:00
    encoder         : Lavf53.16.0
    Stream #0:0(eng): Video: mpeg2video, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30 tbc
    Metadata:
      creation_time   : 2011-08-17 05:00:00
    Stream #0:1(eng): Audio: aac, 44100 Hz, stereo, s16, 128 kb/s
    Metadata:
      creation_time   : 2011-08-17 05:00:00
Stream mapping:
  Stream #0.0 -> #0.0 (h264 -> mpeg2video)
  Stream #0.1 -> #0.1 (aac -> aac)
Press [q] to stop, [?] for help
frame=  150 fps= 30 q=1.0 Lsize=   12148kB time=00:00:04.96 bitrate=20036.6kbits/s    
video:11218kB audio:32kB global headers:0kB muxing overhead 7.977625%
ffmpeg -i out.ts 
ffmpeg version N-33726-g0556eee, Copyright (c) 2000-2011 the FFmpeg developers
  built on Oct 17 2011 17:57:32 with gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  configuration: --enable-pthreads --enable-avfilter --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-libx264 --enable-libfaac
  libavutil    51. 21. 0 / 51. 21. 0
  libavcodec   53. 20. 1 / 53. 20. 1
  libavformat  53. 16. 0 / 53. 16. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 6 /  2. 43. 6
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[NULL @ 0xe3e1140] start time is not set in estimate_timings_from_pts
Input #0, mpegts, from 'out.ts':
  Duration: 00:00:04.96, start: 1.400000, bitrate: 20036 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 104857 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
    Stream #0:1[0x101](eng): Audio: aac ([15][0][0][0] / 0x000F), 0 channels, s16

comment:48 by Carl Eugen Hoyos, 13 years ago

Reproduced by developer: set
Status: newopen
Summary: Missing audio when encoding to mpeg-ts with "-threads 0"Missing aac audio after encoding to mpeg-ts with very high video bitrate

comment:49 by Terran Vigil, 13 years ago

cehoyos: As the analyzeduration workaround doesn't work for this file, are there any other options to work around this problem?

in reply to:  49 comment:50 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

cehoyos: As the analyzeduration workaround doesn't work for this file, are there any other options to work around this problem?

Lower video bitrate, different audio codec?
The tests in ticket #566 suggest libvo-aacenc as an alternative.

comment:51 by Terran Vigil, 13 years ago

Reverting the following checkin is also a workaround for the bug:

commit 2c5168afed8ddd798dae5909dba85ae3b611f894
Author: Jason Garrett-Glaser <darkshikari@gmail.com>
Date:   Thu Nov 11 14:34:27 2010 +0000

   Remove bitrate tolerance from libx264 interface
   Nobody ever uses it correctly, and ffmpeg sets it incorrectly, so we'll just
   leave it out.

   Originally committed as revision 25720 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 6da7f2a..f550c6a 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -273,9 +273,6 @@ static av_cold int X264_init(AVCodecContext *avctx)
    if (avctx->level > 0)
        x4->params.i_level_idc = avctx->level;

-    x4->params.rc.f_rate_tolerance =
-        (float)avctx->bit_rate_tolerance/avctx->bit_rate;
-
    if ((avctx->rc_buffer_size != 0) &&
        (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
        x4->params.rc.f_vbv_buffer_init =

in reply to:  51 comment:52 by Carl Eugen Hoyos, 13 years ago

Replying to terran:

Reverting the following checkin is also a workaround for the bug:

Given that we were both able to reproduce the problem without using libx264 (and, in my case, without even compiling libx264.c). this seems very unlikely.
What is very likely, though, is that when reverting that patch, the original problem is not triggered any more because the bit rate changes for x264 encoding.

comment:53 by Terran Vigil, 13 years ago

If you follow the code that relates to that change, it later touoches code that affects the threading model. Since we know that lowering the number of threads does work around the bug, it seems likely that there is a correlation.

Also, lowering the target bitrate from 7Mbps to, say, 5Mbps doesnt work around the bug for me. I can try other bitrates as well.

comment:54 by Carl Eugen Hoyos, 13 years ago

Keywords: aac ts added

comment:55 by Carl Eugen Hoyos, 12 years ago

Component: undeterminedavformat
Keywords: mpegts added; ts removed
Resolution: fixed
Status: openclosed

Fixed in current git head and 1.0.

Note: See TracTickets for help on using tickets.