FFmpeg does not copy the default and forced track flags for matroka files

Description

The first output is from a sample file I have created with mmg from mkvtoolnix with every possible combination of the forced and default flags. mmg allows one default track for all video, audio and subtitle tracks but multiple forced tracks.

The second/third/fourth output is the result from "ffmpeg -i test_orig.mkv -c: copy -map 0 -f matroska test_ffmpeg_*.mkv". Currently ffmpeg seems to drop the forced flag and every stream which has no flag gets the default flag.

I took a look at libavformat/matroskaenc.c applied the changes from the attached patch. The patch only works if I add the forced flag before the default flag with put_ebml_uint. If I add it afterwards I get the third output. Here existing flags were kept but all streams without flags still get the default flags.

Adding the forced flag before adding the default flag gives the desired fourth output. All flags are copied correctly.

I do not have any experience in c programming, so I am not sure if this is the correct fix so I would be glad if somebody could take a look at this.

Furthermore is it possible to add a way of setting this flags with ffmpeg, currently this seems not doable.

The failing command line including the output. Note the flags are displayed correctly in the input and output block when copying but issuing "ffmpeg -i" for the output file shows that the flags are not copied.