Opened 4 years ago

Closed 4 years ago

#7446 closed defect (fixed)

x264 init race/corruption

Reported by: lukealonso Owned by: Marton Balint
Priority: important Component: avcodec
Version: git-master Keywords: libx264 regression
Cc: Marton Balint Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:

I have a program that creates many concurrent instances of x264 via AVCodecContext. Occasionally, I'll get the following output:

x264 [error]: invalid tune '[RANDOM JUNK]'

and avcodec_open2 will fail.

I've attached a stripped down program that reproduces the issue, at least on Ubuntu 16.04.

This appears to happen with all x264 versions, I tried the latest stable commit, and one from several years ago.

This does *NOT* happen with older FFmpeg versions. I git bisected and found that the problem started happening on commit:

[abaa12263e08ae7b2099f00fa4597ae6a86d7a9c] avcodec: Don't lock during open if the codec has threadsafe init]

.... which is not surprising, but not terribly helpful in finding what exactly is happening in X264_init that causes the issue.

Hopefully this is just me being dumb, any pointers would be appreciated.

How to reproduce:

Build enc_test.c:

gcc -o enc_test enc_test.c -lavcodec -lavformat -lavutil -lpthread

Run 1-10 times, with num_threads between 4-32, whatever is appropriate for your machine. Happens more often with higher thread counts. It should happen early on, so ctrl-c and try again if it hasn't happened with in a few seconds.

./enc_test [num_threads]

Attachments (1)

enc_test.c (1.6 KB ) - added by lukealonso 4 years ago.

Download all attachments as: .zip

Change History (6)

by lukealonso, 4 years ago

Attachment: enc_test.c added


comment:1 by Carl Eugen Hoyos, 4 years ago

Keywords: libx264 added

Please confirm that the issue is reproducible with current FFmpeg git head and current libx264 git head.

comment:2 by lukealonso, 4 years ago

Replying to cehoyos:
Yes, it occurs with ffmpeg git head and libx264 git head.

Last edited 4 years ago by lukealonso (previous) (diff)

comment:3 by Carl Eugen Hoyos, 4 years ago

Keywords: regression added
Priority: normalimportant
Version: unspecifiedgit-master

Reproducible with both old and current x264.

comment:4 by Marton Balint, 4 years ago

Cc: Marton Balint added
Owner: set to Marton Balint
Status: newopen

comment:5 by Marton Balint, 4 years ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.