Cherry-picked commits for Release/1.2

Commits cherry-picked from master:

088ed5314694031e07e02e9d364c9d486a60e704 - lavf/matroskaenc: Check for valid metadata before creating tags
066111bf19518a9f4d836991b34dbfc5ab72a41a - matroskaenc: simplify mkv_check_tag()
af248fa1174200acb537a6ab1198bb2fed38e884 - matroskadec: Improve TTA duration calculation
338f8b2eaf36f078eb5cc26ac10e651dc4c48243 - avformat/matroskadec: check out_samplerate before using it in av_rescale()