{"id":303036,"date":"2020-05-05T09:00:23","date_gmt":"2020-05-05T09:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=303036"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=303036","title":{"rendered":"[\u0427\u0430\u0441\u0442\u044c 1\/2] \u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e FFmpeg \u0438 SDL \u0438\u043b\u0438 \u041a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e\u043f\u043b\u0435\u0435\u0440 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0432 1000 \u0441\u0442\u0440\u043e\u043a"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/500402\/\"><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/500402\/\"><\/p>\n<div style=\"text-align:center;\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"325\" src=\"https:\/\/habrastorage.org\/webt\/8g\/lm\/9b\/8glm9bxivqkvscmah31ojdjmzci.png\"><\/div>\n<p><\/a><br \/>  \u0425\u043e\u0442\u044f \u0434\u0430\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0430, \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0438 \u043f\u043e \u0441\u0435\u0439 \u0434\u0435\u043d\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043f\u043e \u0442\u0435\u043c\u0435 FFmpeg. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435\u0442. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u0441\u0430\u0434\u043d\u043e\u0435 \u0443\u043f\u0443\u0449\u0435\u043d\u0438\u0435, \u0438\u0431\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0437\u0434\u043d\u043e, \u0447\u0435\u043c \u043d\u0438\u043a\u043e\u0433\u0434\u0430.<\/p>\n<p>  \u0418 \u0445\u043e\u0442\u044f \u043c\u044b \u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c, \u0432 \u0442\u0430\u043a\u043e\u043c \u043e\u0431\u044a\u0451\u043c\u043d\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u044b <i>\u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430<\/i>. \u0421\u043e\u043e\u0431\u0449\u0430\u0439\u0442\u0435 \u043e \u043d\u0435\u0434\u043e\u0447\u0451\u0442\u0430\u0445 (\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 \u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445) \u2014 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <a name=\"menu\"><\/a><\/p>\n<h3>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h3>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<th align=\"center\">\u0427\u0430\u0441\u0442\u044c 1<\/th>\n<th align=\"center\">\u0427\u0430\u0441\u0442\u044c 2 (\u0432\u044b\u0439\u0434\u0435\u0442 \u0443\u0442\u0440\u043e\u043c 7 \u043c\u0430\u044f)<\/th>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/habr.com\/ru\/post\/500402\/#preamble\">\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#screencaps\">\u0423\u0440\u043e\u043a 1: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043d\u043a\u0430\u043f\u0441\u043e\u0432<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#outputting\">\u0423\u0440\u043e\u043a 2: \u0412\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#sound\">\u0423\u0440\u043e\u043a 3: \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#threads\">\u0423\u0440\u043e\u043a 4: \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0440\u0435\u0434\u044b<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#video\">\u0423\u0440\u043e\u043a 5: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0438\u0434\u0435\u043e<\/a>  <\/td>\n<td align=\"left\">\u0423\u0440\u043e\u043a 6: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0443\u0434\u0438\u043e<br \/>  \u0423\u0440\u043e\u043a 7: \u041f\u043e\u0438\u0441\u043a<br \/>  \u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<br \/>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 1. \u0421\u043f\u0438\u0441\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439<br \/>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 2. \u0421\u043f\u0438\u0441\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445<br \/>  \u0421\u0441\u044b\u043b\u043a\u0438<\/td>\n<\/tr>\n<\/table>\n<\/div>\n<p><a name=\"habracut\"><\/a><a name=\"preamble\"><\/a><\/p>\n<blockquote><p><a href=\"https:\/\/www.edsd.ru\/\" title=\"EDISON Software - web-development\"><img loading=\"lazy\" decoding=\"async\" align=\"left\" width=\"153\" height=\"75\" src=\"https:\/\/habrastorage.org\/webt\/w0\/zl\/to\/w0zltoxvysbr0yeinstkfvw1wbg.png\" alt=\"EDISON Software - web-development\"><\/a><br clear=\"right\">  \u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u0430 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 EDISON.<\/p>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 <a href=\"https:\/\/www.edsd.ru\/ru\/portfolio\/tehnologiya\/video\">\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0438\u0434\u0435\u043e<\/a>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0447\u0430\u0441\u0442\u043e \u043f\u0438\u0448\u0435\u043c <a href=\"https:\/\/www.edsd.ru\/razrabotka-programm-na-c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0438\u0434\u0435\u043e \u043d\u0430 C \u0438 C++<\/a>.<\/p>\n<p>  \u041c\u044b \u043e\u0447\u0435\u043d\u044c \u043b\u044e\u0431\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u0438\u0434\u0435\u043e! \ud83d\ude09<\/p><\/blockquote>\n<p>  <\/p>\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 <a href=\"#menu\">\u2191<\/a><\/h2>\n<p>  <b>UPD: \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043f\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u043d\u0430 \u0444\u0435\u0432\u0440\u0430\u043b\u044c 2015 \u0433\u043e\u0434\u0430.<\/b><\/p>\n<p>  <b>FFmpeg<\/b> \u2014 \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0438\u0434\u0435\u043e\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0442\u0438\u043b\u0438\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. FFmpeg \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u044e \u0440\u0443\u0442\u0438\u043d\u0443 \u043f\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0432\u0438\u0434\u0435\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0432\u0441\u0451 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0434\u0435\u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0427\u0442\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0435\u0434\u0438\u0430-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0412\u0441\u0451 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e-\u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0430 C, \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u0434\u0435\u043a, \u0438\u043c\u0435\u044e\u0449\u0438\u0445\u0441\u044f \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b.<\/p>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0437\u0430\u0433\u0432\u043e\u0437\u0434\u043a\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442. \u0415\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u0443\u0447\u0435\u0431\u043d\u0438\u043a (<i>\u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 \u0442\u0443\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0436\u0435 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u2014 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u043a\u0430<\/i>), \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u043e\u0441\u043d\u043e\u0432\u044b FFmpeg \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 doxygen-\u0434\u043e\u043a\u043e\u0432. \u0418 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0438\u0447\u0435\u0433\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0442\u0435\u043c \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FFmpeg \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0446\u0438\u0444\u0440\u043e\u0432\u044b\u0435 \u0432\u0438\u0434\u0435\u043e- \u0438 \u0430\u0443\u0434\u0438\u043e-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0437\u0430\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0432\u0438\u0434\u0435 \u0443\u0447\u0435\u0431\u043d\u0438\u043a\u0430.<\/p>\n<p>  \u0415\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 FFplay, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f \u0441 FFmpeg. \u041e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043d\u0430 C, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0435\u043e\u043f\u043b\u0435\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c FFmpeg. \u041f\u0435\u0440\u0432\u044b\u0439 \u043c\u043e\u0439 \u0443\u0440\u043e\u043a \u2014 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u0430 \u041c\u0430\u0440\u0442\u0438\u043d\u0430 \u0411\u0451\u043c\u0435 (<i>\u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0435 \u0442\u0443\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0436\u0435 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0432\u0435\u0431-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u2014 \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u043a\u0430<\/i>) \u2014 \u044f \u0443\u0442\u0430\u0449\u0438\u043b \u043a\u043e\u0435-\u043a\u0430\u043a\u0438\u0435 \u043a\u0443\u0441\u043a\u0438 \u043e\u0442\u0442\u0443\u0434\u0430. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0432 \u0441\u0435\u0440\u0438\u0438 \u043c\u043e\u0438\u0445 \u0443\u0440\u043e\u043a\u043e\u0432 \u043f\u043e\u043a\u0430\u0436\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043e\u043f\u043b\u0435\u0435\u0440\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <b>ffplay.c<\/b> \u0424\u0430\u0431\u0440\u0438\u0441\u0430 \u0411\u0435\u043b\u043b\u0430\u0440\u0434\u0430. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0438\u0434\u0435\u044f (\u0430 \u0442\u043e \u0438 \u0434\u0432\u0435) \u0441 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435\u043c \u0435\u0451 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041a \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u043b\u0430\u0432\u0435 \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u043d\u0430 C, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u043e\u043a\u0430\u0436\u0443\u0442, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0435\u0451 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0432\u0442\u043e\u0440\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438, \u043d\u0435 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435. \u041a\u043e\u0433\u0434\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u043f\u043b\u0435\u0435\u0440, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0435 \u0447\u0435\u043c \u0432 1000 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430!<\/p>\n<p>  \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043b\u0435\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SDL \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0430\u0443\u0434\u0438\u043e \u0438 \u0432\u0438\u0434\u0435\u043e \u043c\u0435\u0434\u0438\u0430-\u0444\u0430\u0439\u043b\u0430. SDL \u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0432\u043e\u0441\u0445\u043e\u0434\u043d\u0430\u044f \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u0435\u0434\u0438\u0439\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f MPEG, \u044d\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430\u0445 \u0438 \u043c\u043d\u043e\u0433\u0438\u0445 \u0432\u0438\u0434\u0435\u043e\u0438\u0433\u0440\u0430\u0445. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f SDL \u0432 \u0432\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430.<\/p>\n<p>  \u042d\u0442\u043e\u0442 \u0443\u0447\u0435\u0431\u043d\u0438\u043a \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043b\u044e\u0434\u0435\u0439 \u0441 \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c C, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u0445, \u043a\u0430\u043a \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u044b \u0438 \u0442.\u0434. \u0414\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u0435\u0434\u0438\u0430; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e \u0442\u0430\u043a\u0438\u0445 \u0432\u0435\u0449\u0430\u0445, \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430 \u0432\u043e\u043b\u043d\u044b \u0438 \u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u044b\u0442\u044c \u0433\u0443\u0440\u0443 \u0432 \u044d\u0442\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u0445 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043f\u043e \u0445\u043e\u0434\u0443 \u0443\u0440\u043e\u043a\u043e\u0432.<\/p>\n<p>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c, \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0439\u0442\u0435 \u043c\u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0438\u0434\u0435\u0438, \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u0430 \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e, \u043d\u0430 Dranger \u0441\u043e\u0431\u0430\u0447\u043a\u0430 Gmail \u0442\u043e\u0447\u043a\u0430 Com.<\/p>\n<hr>\n<hr>\n<hr>\n<hr>\n<hr>\n<p><a name=\"screencaps\"><\/a><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/495614\/\"><img loading=\"lazy\" decoding=\"async\" align=\"right\" width=\"420\" height=\"125\" src=\"https:\/\/habrastorage.org\/webt\/co\/i3\/m0\/coi3m0tliby9r5uxtiydjoeaqkm.png\"><\/a><br clear=\"left\">  <\/p>\n<h4>\u0427\u0438\u0442\u0430\u0439\u0442\u0435 \u0442\u0430\u043a\u0436\u0435 \u0432 \u0431\u043b\u043e\u0433\u0435<br \/>  \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 EDISON:<\/h4>\n<p>  <a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/495614\/\"><b>\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e FFmpeg libav<\/b><\/a>  <\/p>\n<hr>\n<hr>\n<hr>\n<hr>\n<hr>\n<p>  <\/p>\n<h2>\u0423\u0440\u043e\u043a 1: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043d\u043a\u0430\u043f\u0441\u043e\u0432 <a href=\"#menu\">\u2191<\/a><\/h2>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433: tutorial01.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/ tutorial01.c \/\/ Code based on a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) \/\/ Tested on Gentoo, CVS version 5\/01\/07 compiled with GCC 4.1.1 \/\/ With updates from https:\/\/github.com\/chelyaev\/ffmpeg-tutorial \/\/ Updates tested on: \/\/ LAVC 54.59.100, LAVF 54.29.104, LSWS 2.1.101  \/\/ on GCC 4.7.2 in Debian February 2015  \/\/ A small sample program that shows how to use libavformat and libavcodec to \/\/ read video from a file. \/\/ \/\/ Use \/\/ \/\/ gcc -o tutorial01 tutorial01.c -lavformat -lavcodec -lswscale -lz \/\/ \/\/ to build (assuming libavformat and libavcodec are correctly installed \/\/ your system). \/\/ \/\/ Run using \/\/ \/\/ tutorial01 myvideofile.mpg \/\/ \/\/ to write the first five frames from &quot;myvideofile.mpg&quot; to disk in PPM \/\/ format.  #include &lt;libavcodec\/avcodec.h&gt; #include &lt;libavformat\/avformat.h&gt; #include &lt;libswscale\/swscale.h&gt;  #include &lt;stdio.h&gt;  \/\/ compatibility with newer API #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1) #define av_frame_alloc avcodec_alloc_frame #define av_frame_free avcodec_free_frame #endif  void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {   FILE *pFile;   char szFilename[32];   int  y;      \/\/ Open file   sprintf(szFilename, &quot;frame%d.ppm&quot;, iFrame);   pFile=fopen(szFilename, &quot;wb&quot;);   if(pFile==NULL)     return;      \/\/ Write header   fprintf(pFile, &quot;P6\\n%d %d\\n255\\n&quot;, width, height);      \/\/ Write pixel data   for(y=0; y&lt;height; y++)     fwrite(pFrame-&gt;data[0]+y*pFrame-&gt;linesize[0], 1, width*3, pFile);      \/\/ Close file   fclose(pFile); }  int main(int argc, char *argv[]) {   \/\/ Initalizing these to NULL prevents segfaults!   AVFormatContext   *pFormatCtx = NULL;   int               i, videoStream;   AVCodecContext    *pCodecCtxOrig = NULL;   AVCodecContext    *pCodecCtx = NULL;   AVCodec           *pCodec = NULL;   AVFrame           *pFrame = NULL;   AVFrame           *pFrameRGB = NULL;   AVPacket          packet;   int               frameFinished;   int               numBytes;   uint8_t           *buffer = NULL;   struct SwsContext *sws_ctx = NULL;    if(argc &lt; 2) {     printf(&quot;Please provide a movie file\\n&quot;);     return -1;   }   \/\/ Register all formats and codecs   av_register_all();      \/\/ Open video file   if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL)!=0)     return -1; \/\/ Couldn't open file      \/\/ Retrieve stream information   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)     return -1; \/\/ Couldn't find stream information      \/\/ Dump information about file onto standard error   av_dump_format(pFormatCtx, 0, argv[1], 0);      \/\/ Find the first video stream   videoStream=-1;   for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++)     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO) {       videoStream=i;       break;     }   if(videoStream==-1)     return -1; \/\/ Didn't find a video stream      \/\/ Get a pointer to the codec context for the video stream   pCodecCtxOrig=pFormatCtx-&gt;streams[videoStream]-&gt;codec;   \/\/ Find the decoder for the video stream   pCodec=avcodec_find_decoder(pCodecCtxOrig-&gt;codec_id);   if(pCodec==NULL) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1; \/\/ Codec not found   }   \/\/ Copy context   pCodecCtx = avcodec_alloc_context3(pCodec);   if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }    \/\/ Open codec   if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0)     return -1; \/\/ Could not open codec      \/\/ Allocate video frame   pFrame=av_frame_alloc();      \/\/ Allocate an AVFrame structure   pFrameRGB=av_frame_alloc();   if(pFrameRGB==NULL)     return -1;    \/\/ Determine required buffer size and allocate buffer   numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx-&gt;width, \t\t\t      pCodecCtx-&gt;height);   buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));      \/\/ Assign appropriate parts of buffer to image planes in pFrameRGB   \/\/ Note that pFrameRGB is an AVFrame, but AVFrame is a superset   \/\/ of AVPicture   avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, \t\t pCodecCtx-&gt;width, pCodecCtx-&gt;height);      \/\/ initialize SWS context for software scaling   sws_ctx = sws_getContext(pCodecCtx-&gt;width, \t\t\t   pCodecCtx-&gt;height, \t\t\t   pCodecCtx-&gt;pix_fmt, \t\t\t   pCodecCtx-&gt;width, \t\t\t   pCodecCtx-&gt;height, \t\t\t   PIX_FMT_RGB24, \t\t\t   SWS_BILINEAR, \t\t\t   NULL, \t\t\t   NULL, \t\t\t   NULL \t\t\t   );    \/\/ Read frames and save first five frames to disk   i=0;   while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {     \/\/ Is this a packet from the video stream?     if(packet.stream_index==videoStream) {       \/\/ Decode video frame       avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);              \/\/ Did we get a video frame?       if(frameFinished) { \t\/\/ Convert the image from its native format to RGB \tsws_scale(sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t\t  pFrame-&gt;linesize, 0, pCodecCtx-&gt;height, \t\t  pFrameRGB-&gt;data, pFrameRGB-&gt;linesize); \t \t\/\/ Save the frame to disk \tif(++i&lt;=5) \t  SaveFrame(pFrameRGB, pCodecCtx-&gt;width, pCodecCtx-&gt;height,  \t\t    i);       }     }          \/\/ Free the packet that was allocated by av_read_frame     av_free_packet(&amp;packet);   }      \/\/ Free the RGB image   av_free(buffer);   av_frame_free(&amp;pFrameRGB);      \/\/ Free the YUV frame   av_frame_free(&amp;pFrame);      \/\/ Close the codecs   avcodec_close(pCodecCtx);   avcodec_close(pCodecCtxOrig);    \/\/ Close the video file   avformat_close_input(&amp;pFormatCtx);      return 0; }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h3>\u041e\u0431\u0437\u043e\u0440<\/h3>\n<p>  \u0424\u0430\u0439\u043b\u044b \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u0430\u043c \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <b>\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c<\/b>, \u0438 \u0442\u0438\u043f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0430\u0439\u043b\u0435. \u041f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f <b>AVI<\/b> \u0438 <b>Quicktime<\/b>. \u0414\u0430\u043b\u0435\u0435, \u0432 \u0444\u0430\u0439\u043b\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432; \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043e\u0431\u044b\u0447\u043d\u043e \u0435\u0441\u0442\u044c <b>\u0430\u0443\u0434\u0438\u043e\u043f\u043e\u0442\u043e\u043a<\/b> \u0438 <b>\u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a<\/b>. (\u00ab\u041f\u043e\u0442\u043e\u043a\u00bb \u2014 \u044d\u0442\u043e \u0437\u0430\u0431\u0430\u0432\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0434\u043b\u044f \u00ab\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0301\u0439 \u0448\u043a\u0430\u043b\u043e\u0439\u00bb.) \u042d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <b>\u043a\u0430\u0434\u0440\u0430\u043c\u0438<\/b>. \u041a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0438\u043b\u0438 \u0438\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c <b>\u043a\u043e\u0434\u0435\u043a\u0430<\/b>. \u041a\u043e\u0434\u0435\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 <b>\u043a\u043e<\/b>\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438 <b>\u0434\u0435\u043a<\/b>\u043e\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u2014 \u043e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0435\u043a. \u041f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0434\u0435\u043a\u043e\u0432 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f DivX \u0438 MP3. \u041f\u0430\u043a\u0435\u0442\u044b \u0437\u0430\u0442\u0435\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430. <b>\u041f\u0430\u043a\u0435\u0442\u044b<\/b> \u2014 \u044d\u0442\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <b>\u0431\u0438\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u0434\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u043e\u0436\u0435\u043c \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0414\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u043b\u043d\u044b\u0435 \u043a\u0430\u0434\u0440\u044b (\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u0434\u0440\u043e\u0432, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0430\u0443\u0434\u0438\u043e).<\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u0438\u0434\u0435\u043e \u0438 \u0430\u0443\u0434\u0438\u043e \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435:<\/p>\n<pre><code class=\"vbscript\">10 OPEN video_stream FROM video.avi 20 READ packet FROM video_stream INTO frame 30 IF frame NOT COMPLETE GOTO 20 40 DO SOMETHING WITH frame 50 GOTO 20<\/code><\/pre>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u0435\u0434\u0438\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FFmpeg \u043f\u043e\u0447\u0442\u0438 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u043f\u0440\u043e\u0441\u0442\u0430, \u043a\u0430\u043a \u0438 \u0432 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u0445\u043e\u0442\u044f \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0448\u0430\u0433 \u00ab\u0421\u0414\u0415\u041b\u0410\u0422\u042c [&#8230;]\u00bb \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043b\u043e\u0436\u043d\u044b\u043c. \u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b, \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a \u0432\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e, \u0438 \u043d\u0430\u0448 \u00ab\u0421\u0414\u0415\u041b\u0410\u0422\u042c [&#8230;]\u00bb \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u0434\u0440 \u0432 \u0444\u0430\u0439\u043b PPM.<\/p>\n<h3>\u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0444\u0430\u0439\u043b\u0430<\/h3>\n<p>  \u041f\u0435\u0440\u0432\u043e-\u043d\u0430\u043f\u0435\u0440\u0432\u043e, \u043f\u043e\u0433\u043b\u044f\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0444\u0430\u0439\u043b\u0430. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FFmpeg \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443:<\/p>\n<pre><code class=\"cpp\">#include &lt;libavcodec\/avcodec.h&gt; #include &lt;libavformat\/avformat.h&gt; #include &lt;ffmpeg\/swscale.h&gt; ... int main(int argc, charg *argv[]) { av_register_all();<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043a\u043e\u0434\u0435\u043a\u0438 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c\/\u043a\u043e\u0434\u0435\u043a\u043e\u043c. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c <b>av_register_all<\/b>() \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0437\u0434\u0435\u0441\u044c, \u0432 <b>main<\/b>(). \u041f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043a\u043e\u0434\u0435\u043a\u0438, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435\u0442 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u0438\u0447\u0438\u043d, \u0447\u0442\u043e\u0431\u044b \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b:  <\/p>\n<pre><code class=\"cpp\">AVFormatContext *pFormatCtx = NULL;  \/\/ Open video file if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, 0, NULL)!=0)   return -1; \/\/ Couldn't open file<\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0444\u0430\u0439\u043b\u0430 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <b>AVFormatContext<\/b>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u043b\u0438. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0442\u0440\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0444\u0430\u0439\u043b\u0430, \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0443\u0444\u0435\u0440\u0430 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0430. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u0432 \u043d\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f NULL \u0438\u043b\u0438 0, <b>libavformat<\/b> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0432\u0441\u0451 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u0442\u0430\u043a \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u0442\u043e\u043a\u0435 \u0432 \u0444\u0430\u0439\u043b\u0435:<\/p>\n<pre><code class=\"cpp\">\/\/ Retrieve stream information if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)   return -1; \/\/ Couldn't find stream information<\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0432 <b>pFormatCtx<\/b>-&gt;<b>streams<\/b> \u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041c\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u043e\u0442\u043b\u0430\u0434\u043a\u0438, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u043d\u0430\u043c, \u0447\u0442\u043e \u0442\u0430\u043c \u0432\u043d\u0443\u0442\u0440\u0438:<\/p>\n<pre><code class=\"cpp\">\/\/ Dump information about file onto standard error av_dump_format(pFormatCtx, 0, argv[1], 0);<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c <b>pFormatCtx<\/b>-&gt;<b>streams<\/b> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c <b>pFormatCtx<\/b>-&gt;<b>nb_streams<\/b>. \u041f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e \u043d\u0435\u043c\u0443, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a:<\/p>\n<pre><code class=\"cpp\">int i; AVCodecContext *pCodecCtxOrig = NULL; AVCodecContext *pCodecCtx = NULL;  \/\/ Find the first video stream videoStream=-1; for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++)   if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO) {     videoStream=i;     break;   } if(videoStream==-1)   return -1; \/\/ Didn't find a video stream  \/\/ Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtx-&gt;streams[videoStream]-&gt;codec;<\/code><\/pre>\n<p>  \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043a\u043e\u0434\u0435\u043a\u0435 \u0432 \u043f\u043e\u0442\u043e\u043a\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043c\u0435\u0441\u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u00ab<b>\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043a\u043e\u0434\u0435\u043a\u0430<\/b>\u00bb. \u041e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u0434\u0435\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0433\u043e. \u041d\u043e \u043c\u044b \u0432\u0441\u0451 \u0435\u0449\u0451 \u0434\u043e\u043b\u0436\u043d\u044b \u043d\u0430\u0439\u0442\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434\u0435\u043a \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"cpp\">AVCodec *pCodec = NULL;  \/\/ Find the decoder for the video stream pCodec=avcodec_find_decoder(pCodecCtx-&gt;codec_id); if(pCodec==NULL) {   fprintf(stderr, &quot;Unsupported codec!\\n&quot;);   return -1; \/\/ Codec not found } \/\/ Copy context pCodecCtx = avcodec_alloc_context3(pCodec); if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {   fprintf(stderr, &quot;Couldn't copy codec context&quot;);   return -1; \/\/ Error copying codec context } \/\/ Open codec if(avcodec_open2(pCodecCtx, pCodec)&lt;0)   return -1; \/\/ Could not open codec<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <b>AVCodecContext<\/b> \u0438\u0437 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0430! \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c a<b>vcodec_copy_context<\/b>(), \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u043e\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e (\u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430 \u043f\u0430\u043c\u044f\u0442\u044c).<\/p>\n<h3>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u0434\u0440\u0430:<\/p>\n<pre><code class=\"cpp\">AVFrame *pFrame = NULL;  \/\/ Allocate video frame pFrame=av_frame_alloc();<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b PPM, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 24-\u0431\u0438\u0442\u043d\u043e\u043c RGB, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u0430\u0434\u0440 \u0438\u0437 \u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0432 RGB. FFmpeg \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e \u0437\u0430 \u043d\u0430\u0441. \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0438 \u044d\u0442\u043e\u0442) \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0430\u0434\u0440 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442. \u0412\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u0430\u0434\u0440 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430:<\/p>\n<pre><code class=\"cpp\">\/\/ Allocate an AVFrame structure pFrameRGB=av_frame_alloc(); if(pFrameRGB==NULL)   return -1;<\/code><\/pre>\n<p>  \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0438 \u0444\u0440\u0435\u0439\u043c, \u043d\u0430\u043c \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0438\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>avpicture_get_size<\/b>, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432 \u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e:<\/p>\n<pre><code class=\"cpp\">uint8_t *buffer = NULL; int numBytes; \/\/ Determine required buffer size and allocate buffer numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx-&gt;width,                             pCodecCtx-&gt;height); buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));<\/code><\/pre>\n<p>  <b>av_malloc<\/b> \u2014 \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433 C-\u0448\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>malloc<\/b> \u043e\u0442 FFmpeg, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0449\u0430\u044f \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0432\u043e\u043a\u0440\u0443\u0433 <b>malloc<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0442.\u043f. \u041a\u0441\u0442\u0430\u0442\u0438, \u044d\u0442\u043e \u043d\u0435 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u0434\u0432\u043e\u0439\u043d\u043e\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u0441 <b>malloc<\/b>.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>avpicture_fill<\/b>, \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043a\u0430\u0434\u0440 \u0441 \u043d\u0430\u0448\u0438\u043c \u0432\u043d\u043e\u0432\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c. \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f <b>AVPicture<\/b>: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <b>AVPicture<\/b> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b <b>AVFrame<\/b> \u2014 \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b <b>AVFrame<\/b> \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <b>AVPicture<\/b>.<\/p>\n<pre><code class=\"cpp\">\/\/ Assign appropriate parts of buffer to image planes in pFrameRGB \/\/ Note that pFrameRGB is an AVFrame, but AVFrame is a superset \/\/ of AVPicture avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,                 pCodecCtx-&gt;width, pCodecCtx-&gt;height);<\/code><\/pre>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u043d\u0430 \u0444\u0438\u043d\u0438\u0448\u043d\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0439! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u0442\u043e\u043a\u0430!<\/p>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a, \u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043f\u0430\u043a\u0435\u0442, \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u0430\u0434\u0440\u0435, \u0438 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0434\u0440 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"cpp\">struct SwsContext *sws_ctx = NULL; int frameFinished; AVPacket packet; \/\/ initialize SWS context for software scaling sws_ctx = sws_getContext(pCodecCtx-&gt;width,     pCodecCtx-&gt;height,     pCodecCtx-&gt;pix_fmt,     pCodecCtx-&gt;width,     pCodecCtx-&gt;height,     PIX_FMT_RGB24,     SWS_BILINEAR,     NULL,     NULL,     NULL     );  i=0; while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {   \/\/ Is this a packet from the video stream?   if(packet.stream_index==videoStream) { \t\/\/ Decode video frame     avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);          \/\/ Did we get a video frame?     if(frameFinished) {     \/\/ Convert the image from its native format to RGB         sws_scale(sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t\t  pFrame-&gt;linesize, 0, pCodecCtx-&gt;height, \t\t  pFrameRGB-&gt;data, pFrameRGB-&gt;linesize); \t         \/\/ Save the frame to disk         if(++i&lt;=5)           SaveFrame(pFrameRGB, pCodecCtx-&gt;width,                      pCodecCtx-&gt;height, i);     }   }        \/\/ Free the packet that was allocated by av_read_frame   av_free_packet(&amp;packet); }<\/code><\/pre>\n<p>  \u041d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e: <b>av_read_frame<\/b>() \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <b>AVPacket<\/b>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0430\u043a\u0435\u0442\u0430 \u2014 FFmpeg \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 <b>packet.data<\/b>. \u042d\u0442\u043e \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 <b>av_free_packet<\/b>(). <b>avcodec_decode_video<\/b>() \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 \u0432 \u043a\u0430\u0434\u0440. \u041e\u0434\u043d\u0430\u043a\u043e \u0443 \u043d\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0431\u044b\u0442\u044c \u0432\u0441\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u043a\u0430\u0434\u0440\u0430 \u043f\u043e\u0441\u043b\u0435 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 <b>avcodec_decode_video<\/b>() \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 <b>frameFinished<\/b>, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>sws_scale<\/b>() \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0430 (<nobr><b>pCodecCtx<\/b>-&gt;<b>pix_fmt<\/b><\/nobr>) \u0432 RGB. \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c <b>AVFrame<\/b> \u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e <b>AVPicture<\/b>. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u0434\u0440\u0435, \u0432\u044b\u0441\u043e\u0442\u0435 \u0438 \u0448\u0438\u0440\u0438\u043d\u0435 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>SaveFrame<\/b>.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0451, \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>SaveFrame<\/b> \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 RGB \u0432 \u0444\u0430\u0439\u043b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 PPM. \u0425\u043e\u0442\u044f \u043c\u044b \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u043e \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 \u0441\u0430\u043c\u0438\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u043c PPM; \u043f\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0442\u0443\u0442 \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {   FILE *pFile;   char szFilename[32];   int  y;      \/\/ Open file   sprintf(szFilename, &quot;frame%d.ppm&quot;, iFrame);   pFile=fopen(szFilename, &quot;wb&quot;);   if(pFile==NULL)     return;      \/\/ Write header   fprintf(pFile, &quot;P6\\n%d %d\\n255\\n&quot;, width, height);      \/\/ Write pixel data   for(y=0; y&lt;height; y++)     fwrite(pFrame-&gt;data[0]+y*pFrame-&gt;linesize[0], 1, width*3, pFile);      \/\/ Close file   fclose(pFile); }<\/code><\/pre>\n<p>  \u041c\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043f\u0440. \u0410 \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 RGB. \u0424\u0430\u0439\u043b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e. \u0424\u0430\u0439\u043b PPM \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f RGB \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0446\u0432\u0435\u0442\u0430 HTML, \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443 \u0446\u0432\u0435\u0442\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043e\u043d\u0446\u0430 \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e, \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 <nobr>#ff0000#ff0000&#8230;.<\/nobr>, \u043a\u0430\u043a \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e \u044d\u043a\u0440\u0430\u043d\u0430. (\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0430\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0438 \u0431\u0435\u0437 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f, \u043d\u043e, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0438\u0434\u0435\u044e \u0432\u044b \u0443\u043b\u043e\u0432\u0438\u043b\u0438.) \u0412 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0448\u0438\u0440\u043e\u043a\u0438\u043c \u0438 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 RGB.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>main<\/b>(). \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0430, \u043d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435 \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">\/\/ Free the RGB image av_free(buffer); av_free(pFrameRGB);  \/\/ Free the YUV frame av_free(pFrame);  \/\/ Close the codecs avcodec_close(pCodecCtx); avcodec_close(pCodecCtxOrig);  \/\/ Close the video file avformat_close_input(&amp;pFormatCtx);  return 0;<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>av_free<\/b> \u0434\u043b\u044f \u043f\u0430\u043c\u044f\u0442\u0438, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <b>avcode_alloc_frame<\/b> \u0438 <b>av_malloc<\/b>.<\/p>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0435\u0441\u044c \u043a\u043e\u0434! \u0422\u0435\u043f\u0435\u0440\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Linux \u0438\u043b\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443, \u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435:<\/p>\n<pre><code class=\"bash\">gcc -o tutorial01 tutorial01.c -lavutil -lavformat -lavcodec -lz -lavutil -lm<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0431\u043e\u043b\u0435\u0435 \u0434\u0440\u0435\u0432\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f FFmpeg, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0434\u0430\u043b\u0438\u0442\u044c <b>-lavutil<\/b>:<\/p>\n<pre><code class=\"bash\">gcc -o tutorial01 tutorial01.c -lavformat -lavcodec -lz -lm<\/code><\/pre>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442 PPM. \u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u044d\u0442\u043e \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0444\u0430\u0439\u043b\u0430\u0445 \u0444\u0438\u043b\u044c\u043c\u0430, \u0441\u043a\u0440\u0438\u043d\u043a\u0430\u043f\u0441\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>  <a name=\"outputting\"><\/a><\/p>\n<h2>\u0423\u0440\u043e\u043a 2: \u0412\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d <a href=\"#menu\">\u2191<\/a><\/h2>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433: tutorial02.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/ tutorial02.c \/\/ A pedagogical video player that will stream through every video frame as fast as it can. \/\/ \/\/ Code based on FFplay, Copyright (c) 2003 Fabrice Bellard,  \/\/ and a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) \/\/ Tested on Gentoo, CVS version 5\/01\/07 compiled with GCC 4.1.1 \/\/ With updates from https:\/\/github.com\/chelyaev\/ffmpeg-tutorial \/\/ Updates tested on: \/\/ LAVC 54.59.100, LAVF 54.29.104, LSWS 2.1.101, SDL 1.2.15 \/\/ on GCC 4.7.2 in Debian February 2015 \/\/ \/\/ Use \/\/  \/\/ gcc -o tutorial02 tutorial02.c -lavformat -lavcodec -lswscale -lz -lm `sdl-config --cflags --libs` \/\/ to build (assuming libavformat and libavcodec are correctly installed,  \/\/ and assuming you have sdl-config. Please refer to SDL docs for your installation.) \/\/ \/\/ Run using \/\/ tutorial02 myvideofile.mpg \/\/ \/\/ to play the video stream on your screen.  #include &lt;libavcodec\/avcodec.h&gt; #include &lt;libavformat\/avformat.h&gt; #include &lt;libswscale\/swscale.h&gt;  #include &lt;SDL.h&gt; #include &lt;SDL_thread.h&gt;  #ifdef __MINGW32__ #undef main \/* Prevents SDL from overriding main() *\/ #endif  #include &lt;stdio.h&gt;  \/\/ compatibility with newer API #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1) #define av_frame_alloc avcodec_alloc_frame #define av_frame_free avcodec_free_frame #endif  int main(int argc, char *argv[]) {   AVFormatContext *pFormatCtx = NULL;   int             i, videoStream;   AVCodecContext  *pCodecCtxOrig = NULL;   AVCodecContext  *pCodecCtx = NULL;   AVCodec         *pCodec = NULL;   AVFrame         *pFrame = NULL;   AVPacket        packet;   int             frameFinished;   float           aspect_ratio;   struct SwsContext *sws_ctx = NULL;    SDL_Overlay     *bmp;   SDL_Surface     *screen;   SDL_Rect        rect;   SDL_Event       event;    if(argc &lt; 2) {     fprintf(stderr, &quot;Usage: test &lt;file&gt;\\n&quot;);     exit(1);   }   \/\/ Register all formats and codecs   av_register_all();      if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {     fprintf(stderr, &quot;Could not initialize SDL - %s\\n&quot;, SDL_GetError());     exit(1);   }    \/\/ Open video file   if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL)!=0)     return -1; \/\/ Couldn't open file      \/\/ Retrieve stream information   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)     return -1; \/\/ Couldn't find stream information      \/\/ Dump information about file onto standard error   av_dump_format(pFormatCtx, 0, argv[1], 0);      \/\/ Find the first video stream   videoStream=-1;   for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++)     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO) {       videoStream=i;       break;     }   if(videoStream==-1)     return -1; \/\/ Didn't find a video stream      \/\/ Get a pointer to the codec context for the video stream   pCodecCtxOrig=pFormatCtx-&gt;streams[videoStream]-&gt;codec;   \/\/ Find the decoder for the video stream   pCodec=avcodec_find_decoder(pCodecCtxOrig-&gt;codec_id);   if(pCodec==NULL) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1; \/\/ Codec not found   }    \/\/ Copy context   pCodecCtx = avcodec_alloc_context3(pCodec);   if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }    \/\/ Open codec   if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0)     return -1; \/\/ Could not open codec      \/\/ Allocate video frame   pFrame=av_frame_alloc();    \/\/ Make a screen to put our video #ifndef __DARWIN__         screen = SDL_SetVideoMode(pCodecCtx-&gt;width, pCodecCtx-&gt;height, 0, 0); #else         screen = SDL_SetVideoMode(pCodecCtx-&gt;width, pCodecCtx-&gt;height, 24, 0); #endif   if(!screen) {     fprintf(stderr, &quot;SDL: could not set video mode - exiting\\n&quot;);     exit(1);   }      \/\/ Allocate a place to put our YUV image on that screen   bmp = SDL_CreateYUVOverlay(pCodecCtx-&gt;width, \t\t\t\t pCodecCtx-&gt;height, \t\t\t\t SDL_YV12_OVERLAY, \t\t\t\t screen);    \/\/ initialize SWS context for software scaling   sws_ctx = sws_getContext(pCodecCtx-&gt;width, \t\t\t   pCodecCtx-&gt;height, \t\t\t   pCodecCtx-&gt;pix_fmt, \t\t\t   pCodecCtx-&gt;width, \t\t\t   pCodecCtx-&gt;height, \t\t\t   PIX_FMT_YUV420P, \t\t\t   SWS_BILINEAR, \t\t\t   NULL, \t\t\t   NULL, \t\t\t   NULL \t\t\t   );      \/\/ Read frames and save first five frames to disk   i=0;   while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {     \/\/ Is this a packet from the video stream?     if(packet.stream_index==videoStream) {       \/\/ Decode video frame       avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);              \/\/ Did we get a video frame?       if(frameFinished) { \tSDL_LockYUVOverlay(bmp);  \tAVPicture pict; \tpict.data[0] = bmp-&gt;pixels[0]; \tpict.data[1] = bmp-&gt;pixels[2]; \tpict.data[2] = bmp-&gt;pixels[1];  \tpict.linesize[0] = bmp-&gt;pitches[0]; \tpict.linesize[1] = bmp-&gt;pitches[2]; \tpict.linesize[2] = bmp-&gt;pitches[1];  \t\/\/ Convert the image into YUV format that SDL uses \tsws_scale(sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t\t  pFrame-&gt;linesize, 0, pCodecCtx-&gt;height, \t\t  pict.data, pict.linesize);  \tSDL_UnlockYUVOverlay(bmp); \t \trect.x = 0; \trect.y = 0; \trect.w = pCodecCtx-&gt;width; \trect.h = pCodecCtx-&gt;height; \tSDL_DisplayYUVOverlay(bmp, &amp;rect);              }     }          \/\/ Free the packet that was allocated by av_read_frame     av_free_packet(&amp;packet);     SDL_PollEvent(&amp;event);     switch(event.type) {     case SDL_QUIT:       SDL_Quit();       exit(0);       break;     default:       break;     }    }      \/\/ Free the YUV frame   av_frame_free(&amp;pFrame);      \/\/ Close the codec   avcodec_close(pCodecCtx);   avcodec_close(pCodecCtxOrig);      \/\/ Close the video file   avformat_close_input(&amp;pFormatCtx);      return 0; }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h3>SDL \u0438 \u0432\u0438\u0434\u0435\u043e<\/h3>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SDL. SDL \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a <b>Simple Direct Layer<\/b>. \u042d\u0442\u043e \u043f\u0440\u0435\u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u0435\u0434\u0438\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 \u0438\u043b\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0434\u043b\u044f \u0441\u0432\u043e\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0439 \u0435\u0441\u0442\u044c. \u041f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430 (\u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0440\u043e\u043a\u043e\u0432 \u044d\u0442\u043e, \u043a\u0441\u0442\u0430\u0442\u0438, \u0442\u043e\u0436\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f).<\/p>\n<p>  \u0423 SDL \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u2014 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <b>\u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c YUV<\/b>. <\/p>\n<p>  <i>\u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0434\u0430\u0436\u0435 \u043d\u0435 YUV, \u0430 <b>YCbCr<\/b>. \u0423 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445, \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0447\u0438\u043c, \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0440\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u00abYCbCr\u00bb \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a \u00abYUV\u00bb. \u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, YUV \u2014 \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442, \u0430 YCbCr \u2014 \u044d\u0442\u043e \u0446\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442. FFmpeg \u0438 SDL \u0432 \u0441\u0432\u043e\u0451\u043c \u043a\u043e\u0434\u0435 \u0438 \u0432 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u0445 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 YCbCr \u043a\u0430\u043a YUV, \u043d\u043e \u0442\u043e \u0442\u0430\u043a\u043e\u0435.<\/i><\/p>\n<p>  <b>YUV<\/b> \u2014 \u0441\u043f\u043e\u0441\u043e\u0431 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a RGB. \u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, <b>Y<\/b> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c <b>\u044f\u0440\u043a\u043e\u0441\u0442\u0438<\/b>, \u0430 <b>U<\/b> \u0438 <b>V<\/b> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 <b>\u0446\u0432\u0435\u0442\u0430<\/b>. (\u042d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e, \u0447\u0435\u043c RGB, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0446\u0432\u0435\u0442\u0435 \u043e\u0442\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u0437\u0430\u043c\u0435\u0440 <b>U<\/b> \u0438 <b>V<\/b> \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 2 \u0437\u0430\u043c\u0435\u0440\u0430 <b>Y<\/b>). <b>\u041d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0435 YUV<\/b> \u0432 SDL \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 YUV \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0435\u0433\u043e. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 4 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0438\u0434\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 YUV, \u043d\u043e <b>YV12<\/b> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u043d\u0438\u0445 \u0441\u0430\u043c\u044b\u043c \u0431\u044b\u0441\u0442\u0440\u044b\u043c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 YUV, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 <b>YUV420P<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 YV12, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u044b <b>U<\/b> \u0438 <b>V<\/b> \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0441\u0442\u0430\u043c\u0438. 420 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0441\u044f \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 4:2:0, \u0442.\u0435., \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0435 4 \u0437\u0430\u043c\u0435\u0440\u0430 \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f 1 \u0437\u0430\u043c\u0435\u0440 \u0446\u0432\u0435\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0446\u0432\u0435\u0442\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u0438. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u043b\u0430\u0437 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0437\u0430\u043c\u0435\u0447\u0430\u0435\u0442 \u044d\u0442\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041b\u0430\u0442\u0438\u043d\u0441\u043a\u0430\u044f \u0431\u0443\u043a\u0432\u0430 \u00abP\u00bb \u0432 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0430\u0442 \u00ab\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u043d\u043e\u0439\u00bb (planar), \u044d\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0441\u0442\u0443 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b <b>Y<\/b>, <b>U<\/b> \u0438 <b>V<\/b> \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u0445. FFmpeg \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 <b>YUV420P<\/b>, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043a\u0441\u0442\u0430\u0442\u0438, \u0438\u0431\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0438 \u0443\u0436\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u0438\u043b\u0438 \u043b\u0435\u0433\u043a\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043d\u0435\u0433\u043e.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043b\u0430\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>SaveFrame<\/b>() \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0440\u043e\u043a\u0430 \u0438 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430\u0448 \u043a\u0430\u0434\u0440 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d. \u041d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 SDL. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c SDL:<\/p>\n<pre><code class=\"cpp\">#include &lt;SDL.h&gt; #include &lt;SDL_thread.h&gt;  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {   fprintf(stderr, &quot;Could not initialize SDL - %s\\n&quot;, SDL_GetError());   exit(1); }<\/code><\/pre>\n<p>  <b>SDL_Init<\/b>(), \u043f\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443, \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435, \u043a\u0430\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. <b>SDL_GetError<\/b>(), \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 \u0434\u0435\u043b\u043e, \u044d\u0442\u043e \u043d\u0430\u0448\u0430 \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0438\u0441\u043f\u043b\u0435\u044f<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u0441\u0442\u043e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0441 SDL \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <b>\u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c\u044e<\/b>:<\/p>\n<pre><code class=\"cpp\">SDL_Surface *screen;  screen = SDL_SetVideoMode(pCodecCtx-&gt;width, pCodecCtx-&gt;height, 0, 0); if(!screen) {   fprintf(stderr, &quot;SDL: could not set video mode - exiting\\n&quot;);   exit(1); }<\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u0438\u043b\u0438 \u044d\u043a\u0440\u0430\u043d \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u043e\u0439 \u0438 \u0432\u044b\u0441\u043e\u0442\u043e\u0439. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043e\u043f\u0446\u0438\u044f \u2014 \u0431\u0438\u0442\u043e\u0432\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0430 \u2014 0 \u2014 \u044d\u0442\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u00ab\u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u0438\u0441\u043f\u043b\u0435\u0439\u00bb. <\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c <b>YUV-\u043e\u0432\u0435\u0440\u043b\u0435\u0439<\/b> \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u043a\u0440\u0430\u043d\u0435, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043e, \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448 <b>SWSContext<\/b> \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 <b>YUV420<\/b>:<\/p>\n<pre><code class=\"cpp\">SDL_Overlay     *bmp = NULL; struct SWSContext *sws_ctx = NULL;  bmp = SDL_CreateYUVOverlay(pCodecCtx-&gt;width, pCodecCtx-&gt;height,                            SDL_YV12_OVERLAY, screen);  \/\/ initialize SWS context for software scaling sws_ctx = sws_getContext(pCodecCtx-&gt;width,                          pCodecCtx-&gt;height, \t\t\t pCodecCtx-&gt;pix_fmt, \t\t\t pCodecCtx-&gt;width, \t\t\t pCodecCtx-&gt;height, \t\t\t PIX_FMT_YUV420P, \t\t\t SWS_BILINEAR, \t\t\t NULL, \t\t\t NULL, \t\t\t NULL \t\t\t );<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>YV12<\/b> \u0434\u043b\u044f \u043f\u043e\u043a\u0430\u0437\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 <b>YUV420<\/b> \u0438\u0437 FFmpeg.<\/p>\n<h3>\u041f\u043e\u043a\u0430\u0437 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>  \u041d\u0443, \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0439\u0434\u0435\u043c \u0432\u0435\u0441\u044c \u043f\u0443\u0442\u044c \u0434\u043e \u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u0433\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u0430\u0434\u0440. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0432\u0441\u0435\u0433\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u0434\u043b\u044f \u0444\u0440\u0435\u0439\u043c\u0430 RGB, \u0438 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c <b>SaveFrame<\/b>() \u043d\u0430\u0448\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>AVPicture<\/b> \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0451 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u043b\u0438\u043d\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e <b>\u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u044f YUV<\/b>:<\/p>\n<pre><code class=\"cpp\">  if(frameFinished) {     SDL_LockYUVOverlay(bmp);      AVPicture pict;     pict.data[0] = bmp-&gt;pixels[0];     pict.data[1] = bmp-&gt;pixels[2];     pict.data[2] = bmp-&gt;pixels[1];      pict.linesize[0] = bmp-&gt;pitches[0];     pict.linesize[1] = bmp-&gt;pitches[2];     pict.linesize[2] = bmp-&gt;pitches[1];      \/\/ Convert the image into YUV format that SDL uses     sws_scale(sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t      pFrame-&gt;linesize, 0, pCodecCtx-&gt;height, \t      pict.data, pict.linesize);          SDL_UnlockYUVOverlay(bmp);<\/code><\/pre>\n<p>  \u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 \u043c\u044b \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043e\u0432\u0435\u0440\u043b\u0435\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043d\u0435\u0433\u043e. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u0440\u0438\u0432\u044b\u0447\u043a\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0437\u0436\u0435 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u043b\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <b>AVPicture<\/b>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0438\u043c\u0435\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 4-\u0445 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 <b>YUV420P<\/b>, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 3 \u043a\u0430\u043d\u0430\u043b\u0430 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e 3 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u0440\u0443\u0433\u0438\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u043b\u044f \u0430\u043b\u044c\u0444\u0430-\u043a\u0430\u043d\u0430\u043b\u0430 \u0438\u043b\u0438 \u0447\u0435\u0433\u043e-\u0442\u043e \u0435\u0449\u0451. \u0420\u0430\u0437\u043c\u0435\u0440 \u043b\u0438\u043d\u0438\u0438 \u2014 \u0432\u043e\u0442 \u043d\u0430 \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u043d\u0430\u0448\u0435\u043c <b>\u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0438 YUV<\/b> \u2014 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439 \u0438 \u0432\u044b\u0441\u043e\u0442. (\u041f\u0438\u0442\u0447\u0438, pitches \u2014 \u0435\u0441\u043b\u0438 \u0438\u0437\u044a\u044f\u0441\u043d\u044f\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 SDL \u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0448\u0438\u0440\u0438\u043d\u044b \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.) \u0418\u0442\u0430\u043a, \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0440\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <b>pict.data<\/b> \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u043e\u0432\u0435\u0440\u043b\u0435\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0432 <b>pict<\/b>, \u043c\u044b \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043d\u0430\u0448\u0435 \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e. \u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u0445 \u043b\u0438\u043d\u0438\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0432\u0435\u0440\u043b\u0435\u044f. \u041c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 <b>PIX_FMT_YUV420P<\/b> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>sws_scale<\/b>, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435.<\/p>\n<h3>\u041f\u0440\u043e\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>  \u041d\u043e \u043d\u0430\u043c \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043b\u044f SDL, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0435\u043c\u0443 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0443\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0434\u0442\u0438 \u0444\u0438\u043b\u044c\u043c, \u0434\u043e \u043a\u0430\u043a\u043e\u0439 \u0448\u0438\u0440\u0438\u043d\u044b \u0438 \u0432\u044b\u0441\u043e\u0442\u044b \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, SDL \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0438 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u0448\u0435\u043c\u0443 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0443 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">SDL_Rect rect;    if(frameFinished) {     \/* ... code ... *\/     \/\/ Convert the image into YUV format that SDL uses     sws_scale(sws_ctx, (uint8_t const * const *)pFrame-&gt;data,               pFrame-&gt;linesize, 0, pCodecCtx-&gt;height, \t      pict.data, pict.linesize);          SDL_UnlockYUVOverlay(bmp); \trect.x = 0; \trect.y = 0; \trect.w = pCodecCtx-&gt;width; \trect.h = pCodecCtx-&gt;height; \tSDL_DisplayYUVOverlay(bmp, &amp;rect);   }<\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448\u0435 \u0432\u0438\u0434\u0435\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f!<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043a\u0430\u0436\u0435\u043c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c SDL: <b>\u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/b>. SDL \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u0432\u043e\u0434\u0435 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043c\u044b\u0448\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 SDL \u0438\u043b\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0435\u043c\u0443 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u2014 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u0417\u0430\u0442\u0435\u043c \u0432\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 SDL. \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 SDL, \u0447\u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0432 \u0443\u0440\u043e\u043a\u0435 \u21164. \u0412 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 <b>SDL_QUIT<\/b>, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u044b\u0439\u0442\u0438:  <\/p>\n<pre><code class=\"cpp\">SDL_Event       event;      av_free_packet(&amp;packet);     SDL_PollEvent(&amp;event);     switch(event.type) {     case SDL_QUIT:       SDL_Quit();       exit(0);       break;     default:       break;     }<\/code><\/pre>\n<p>  \u0418 \u0432\u043e\u0442 \u0442\u0430\u043a \u0438 \u0436\u0438\u0432\u0451\u043c! \u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u043c\u0443\u0441\u043e\u0440\u0430 \u0438 \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Linux \u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043b\u0438\u043d\u0443\u043a\u0441\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435, \u043b\u0443\u0447\u0448\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a SDL:<\/p>\n<pre><code class=\"bash\">gcc -o tutorial02 tutorial02.c -lavformat -lavcodec -lswscale -lz -lm \\ `sdl-config --cflags --libs`<\/code><\/pre>\n<p>  <b>sdl-config <\/b>\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u0444\u043b\u0430\u0433\u0438 \u0434\u043b\u044f <b>gcc<\/b>, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 SDL. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0432\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435; \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u043f\u043e\u0436\u0430\u0440\u043d\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e SDL \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0439\u0442\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0439\u0442\u0435.<\/p>\n<p>  \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u044d\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443? \u0412\u0438\u0434\u0435\u043e \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0431\u044b \u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0443\u043c\u0430! \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0434\u0440\u044b \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0444\u0438\u043b\u044c\u043c\u0430. \u0423 \u043d\u0430\u0441 \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435\u0442 \u043a\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 (\u0432 \u0443\u0440\u043e\u043a\u0435 \u21165) \u043c\u044b \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0438\u0434\u0435\u043e. \u041d\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u0443\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0435-\u0447\u0442\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0435: \u0437\u0432\u0443\u043a!<\/p>\n<p>  <a name=\"sound\"><\/a><\/p>\n<h2>\u0423\u0440\u043e\u043a 3: \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430 <a href=\"#menu\">\u2191<\/a><\/h2>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433: tutorial03.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/ tutorial03.c \/\/ A pedagogical video player that will stream through every video frame as fast as it can \/\/ and play audio (out of sync). \/\/ \/\/ Code based on FFplay, Copyright (c) 2003 Fabrice Bellard,  \/\/ and a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) \/\/ Tested on Gentoo, CVS version 5\/01\/07 compiled with GCC 4.1.1 \/\/ With updates from https:\/\/github.com\/chelyaev\/ffmpeg-tutorial \/\/ Updates tested on: \/\/ LAVC 54.59.100, LAVF 54.29.104, LSWS 2.1.101, SDL 1.2.15 \/\/ on GCC 4.7.2 in Debian February 2015 \/\/ \/\/ Use \/\/ \/\/ gcc -o tutorial03 tutorial03.c -lavformat -lavcodec -lswscale -lz -lm `sdl-config --cflags --libs` \/\/ to build (assuming libavformat and libavcodec are correctly installed,  \/\/ and assuming you have sdl-config. Please refer to SDL docs for your installation.) \/\/ \/\/ Run using \/\/ tutorial03 myvideofile.mpg \/\/ \/\/ to play the stream on your screen.  #include &lt;libavcodec\/avcodec.h&gt; #include &lt;libavformat\/avformat.h&gt; #include &lt;libswscale\/swscale.h&gt;  #include &lt;SDL.h&gt; #include &lt;SDL_thread.h&gt;  #ifdef __MINGW32__ #undef main \/* Prevents SDL from overriding main() *\/ #endif  #include &lt;stdio.h&gt; #include &lt;assert.h&gt;  \/\/ compatibility with newer API #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1) #define av_frame_alloc avcodec_alloc_frame #define av_frame_free avcodec_free_frame #endif  #define SDL_AUDIO_BUFFER_SIZE 1024 #define MAX_AUDIO_FRAME_SIZE 192000  typedef struct PacketQueue {   AVPacketList *first_pkt, *last_pkt;   int nb_packets;   int size;   SDL_mutex *mutex;   SDL_cond *cond; } PacketQueue;  PacketQueue audioq;  int quit = 0;  void packet_queue_init(PacketQueue *q) {   memset(q, 0, sizeof(PacketQueue));   q-&gt;mutex = SDL_CreateMutex();   q-&gt;cond = SDL_CreateCond(); } int packet_queue_put(PacketQueue *q, AVPacket *pkt) {    AVPacketList *pkt1;   if(av_dup_packet(pkt) &lt; 0) {     return -1;   }   pkt1 = av_malloc(sizeof(AVPacketList));   if (!pkt1)     return -1;   pkt1-&gt;pkt = *pkt;   pkt1-&gt;next = NULL;         SDL_LockMutex(q-&gt;mutex);      if (!q-&gt;last_pkt)     q-&gt;first_pkt = pkt1;   else     q-&gt;last_pkt-&gt;next = pkt1;   q-&gt;last_pkt = pkt1;   q-&gt;nb_packets++;   q-&gt;size += pkt1-&gt;pkt.size;   SDL_CondSignal(q-&gt;cond);      SDL_UnlockMutex(q-&gt;mutex);   return 0; } static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) {   AVPacketList *pkt1;   int ret;      SDL_LockMutex(q-&gt;mutex);      for(;;) {          if(quit) {       ret = -1;       break;     }      pkt1 = q-&gt;first_pkt;     if (pkt1) {       q-&gt;first_pkt = pkt1-&gt;next;       if (!q-&gt;first_pkt) \tq-&gt;last_pkt = NULL;       q-&gt;nb_packets--;       q-&gt;size -= pkt1-&gt;pkt.size;       *pkt = pkt1-&gt;pkt;       av_free(pkt1);       ret = 1;       break;     } else if (!block) {       ret = 0;       break;     } else {       SDL_CondWait(q-&gt;cond, q-&gt;mutex);     }   }   SDL_UnlockMutex(q-&gt;mutex);   return ret; }  int audio_decode_frame(AVCodecContext *aCodecCtx, uint8_t *audio_buf, int buf_size) {    static AVPacket pkt;   static uint8_t *audio_pkt_data = NULL;   static int audio_pkt_size = 0;   static AVFrame frame;    int len1, data_size = 0;    for(;;) {     while(audio_pkt_size &gt; 0) {       int got_frame = 0;       len1 = avcodec_decode_audio4(aCodecCtx, &amp;frame, &amp;got_frame, &amp;pkt);       if(len1 &lt; 0) { \t\/* if error, skip frame *\/ \taudio_pkt_size = 0; \tbreak;       }       audio_pkt_data += len1;       audio_pkt_size -= len1;       data_size = 0;       if(got_frame) { \tdata_size = av_samples_get_buffer_size(NULL,  \t\t\t\t\t       aCodecCtx-&gt;channels, \t\t\t\t\t       frame.nb_samples, \t\t\t\t\t       aCodecCtx-&gt;sample_fmt, \t\t\t\t\t       1); \tassert(data_size &lt;= buf_size); \tmemcpy(audio_buf, frame.data[0], data_size);       }       if(data_size &lt;= 0) { \t\/* No data yet, get more frames *\/ \tcontinue;       }       \/* We have data, return it and come back for more later *\/       return data_size;     }     if(pkt.data)       av_free_packet(&amp;pkt);      if(quit) {       return -1;     }      if(packet_queue_get(&amp;audioq, &amp;pkt, 1) &lt; 0) {       return -1;     }     audio_pkt_data = pkt.data;     audio_pkt_size = pkt.size;   } }  void audio_callback(void *userdata, Uint8 *stream, int len) {    AVCodecContext *aCodecCtx = (AVCodecContext *)userdata;   int len1, audio_size;    static uint8_t audio_buf[(MAX_AUDIO_FRAME_SIZE * 3) \/ 2];   static unsigned int audio_buf_size = 0;   static unsigned int audio_buf_index = 0;    while(len &gt; 0) {     if(audio_buf_index &gt;= audio_buf_size) {       \/* We have already sent all our data; get more *\/       audio_size = audio_decode_frame(aCodecCtx, audio_buf, sizeof(audio_buf));       if(audio_size &lt; 0) { \t\/* If error, output silence *\/ \taudio_buf_size = 1024; \/\/ arbitrary? \tmemset(audio_buf, 0, audio_buf_size);       } else { \taudio_buf_size = audio_size;       }       audio_buf_index = 0;     }     len1 = audio_buf_size - audio_buf_index;     if(len1 &gt; len)       len1 = len;     memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1);     len -= len1;     stream += len1;     audio_buf_index += len1;   } }  int main(int argc, char *argv[]) {   AVFormatContext *pFormatCtx = NULL;   int             i, videoStream, audioStream;   AVCodecContext  *pCodecCtxOrig = NULL;   AVCodecContext  *pCodecCtx = NULL;   AVCodec         *pCodec = NULL;   AVFrame         *pFrame = NULL;   AVPacket        packet;   int             frameFinished;   struct SwsContext *sws_ctx = NULL;      AVCodecContext  *aCodecCtxOrig = NULL;   AVCodecContext  *aCodecCtx = NULL;   AVCodec         *aCodec = NULL;    SDL_Overlay     *bmp;   SDL_Surface     *screen;   SDL_Rect        rect;   SDL_Event       event;   SDL_AudioSpec   wanted_spec, spec;    if(argc &lt; 2) {     fprintf(stderr, &quot;Usage: test &lt;file&gt;\\n&quot;);     exit(1);   }   \/\/ Register all formats and codecs   av_register_all();      if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {     fprintf(stderr, &quot;Could not initialize SDL - %s\\n&quot;, SDL_GetError());     exit(1);   }    \/\/ Open video file   if(avformat_open_input(&amp;pFormatCtx, argv[1], NULL, NULL)!=0)     return -1; \/\/ Couldn't open file      \/\/ Retrieve stream information   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)     return -1; \/\/ Couldn't find stream information      \/\/ Dump information about file onto standard error   av_dump_format(pFormatCtx, 0, argv[1], 0);        \/\/ Find the first video stream   videoStream=-1;   audioStream=-1;   for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++) {     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO &amp;&amp;        videoStream &lt; 0) {       videoStream=i;     }     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_AUDIO &amp;&amp;        audioStream &lt; 0) {       audioStream=i;     }   }   if(videoStream==-1)     return -1; \/\/ Didn't find a video stream   if(audioStream==-1)     return -1;       aCodecCtxOrig=pFormatCtx-&gt;streams[audioStream]-&gt;codec;   aCodec = avcodec_find_decoder(aCodecCtxOrig-&gt;codec_id);   if(!aCodec) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    \/\/ Copy context   aCodecCtx = avcodec_alloc_context3(aCodec);   if(avcodec_copy_context(aCodecCtx, aCodecCtxOrig) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }    \/\/ Set audio settings from codec info   wanted_spec.freq = aCodecCtx-&gt;sample_rate;   wanted_spec.format = AUDIO_S16SYS;   wanted_spec.channels = aCodecCtx-&gt;channels;   wanted_spec.silence = 0;   wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;   wanted_spec.callback = audio_callback;   wanted_spec.userdata = aCodecCtx;      if(SDL_OpenAudio(&amp;wanted_spec, &amp;spec) &lt; 0) {     fprintf(stderr, &quot;SDL_OpenAudio: %s\\n&quot;, SDL_GetError());     return -1;   }    avcodec_open2(aCodecCtx, aCodec, NULL);    \/\/ audio_st = pFormatCtx-&gt;streams[index]   packet_queue_init(&amp;audioq);   SDL_PauseAudio(0);    \/\/ Get a pointer to the codec context for the video stream   pCodecCtxOrig=pFormatCtx-&gt;streams[videoStream]-&gt;codec;      \/\/ Find the decoder for the video stream   pCodec=avcodec_find_decoder(pCodecCtxOrig-&gt;codec_id);   if(pCodec==NULL) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1; \/\/ Codec not found   }    \/\/ Copy context   pCodecCtx = avcodec_alloc_context3(pCodec);   if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }    \/\/ Open codec   if(avcodec_open2(pCodecCtx, pCodec, NULL)&lt;0)     return -1; \/\/ Could not open codec      \/\/ Allocate video frame   pFrame=av_frame_alloc();    \/\/ Make a screen to put our video  #ifndef __DARWIN__         screen = SDL_SetVideoMode(pCodecCtx-&gt;width, pCodecCtx-&gt;height, 0, 0); #else         screen = SDL_SetVideoMode(pCodecCtx-&gt;width, pCodecCtx-&gt;height, 24, 0); #endif   if(!screen) {     fprintf(stderr, &quot;SDL: could not set video mode - exiting\\n&quot;);     exit(1);   }      \/\/ Allocate a place to put our YUV image on that screen   bmp = SDL_CreateYUVOverlay(pCodecCtx-&gt;width, \t\t\t\t pCodecCtx-&gt;height, \t\t\t\t SDL_YV12_OVERLAY, \t\t\t\t screen);    \/\/ initialize SWS context for software scaling   sws_ctx = sws_getContext(pCodecCtx-&gt;width, \t\t\t   pCodecCtx-&gt;height, \t\t\t   pCodecCtx-&gt;pix_fmt, \t\t\t   pCodecCtx-&gt;width, \t\t\t   pCodecCtx-&gt;height, \t\t\t   PIX_FMT_YUV420P, \t\t\t   SWS_BILINEAR, \t\t\t   NULL, \t\t\t   NULL, \t\t\t   NULL \t\t\t   );    \/\/ Read frames and save first five frames to disk   i=0;   while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {     \/\/ Is this a packet from the video stream?     if(packet.stream_index==videoStream) {       \/\/ Decode video frame       avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished, &amp;packet);              \/\/ Did we get a video frame?       if(frameFinished) { \tSDL_LockYUVOverlay(bmp);  \tAVPicture pict; \tpict.data[0] = bmp-&gt;pixels[0]; \tpict.data[1] = bmp-&gt;pixels[2]; \tpict.data[2] = bmp-&gt;pixels[1];  \tpict.linesize[0] = bmp-&gt;pitches[0]; \tpict.linesize[1] = bmp-&gt;pitches[2]; \tpict.linesize[2] = bmp-&gt;pitches[1];  \t\/\/ Convert the image into YUV format that SDL uses\t \tsws_scale(sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t\t  pFrame-&gt;linesize, 0, pCodecCtx-&gt;height, \t\t  pict.data, pict.linesize); \t \tSDL_UnlockYUVOverlay(bmp); \t \trect.x = 0; \trect.y = 0; \trect.w = pCodecCtx-&gt;width; \trect.h = pCodecCtx-&gt;height; \tSDL_DisplayYUVOverlay(bmp, &amp;rect); \tav_free_packet(&amp;packet);       }     } else if(packet.stream_index==audioStream) {       packet_queue_put(&amp;audioq, &amp;packet);     } else {       av_free_packet(&amp;packet);     }     \/\/ Free the packet that was allocated by av_read_frame     SDL_PollEvent(&amp;event);     switch(event.type) {     case SDL_QUIT:       quit = 1;       SDL_Quit();       exit(0);       break;     default:       break;     }    }    \/\/ Free the YUV frame   av_frame_free(&amp;pFrame);      \/\/ Close the codecs   avcodec_close(pCodecCtxOrig);   avcodec_close(pCodecCtx);   avcodec_close(aCodecCtxOrig);   avcodec_close(aCodecCtx);      \/\/ Close the video file   avformat_close_input(&amp;pFormatCtx);      return 0; }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h3>\u0410\u0443\u0434\u0438\u043e<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e\u0431 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u043b \u0437\u0432\u0443\u043a. SDL \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0437\u0432\u0443\u043a\u0430. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <b>SDL_OpenAudio<\/b>() \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u0430\u0443\u0434\u0438\u043e\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>SDL_AudioSpec<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0430\u0443\u0434\u0438\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438.<\/p>\n<p>  \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a \u0432\u043e\u043e\u0431\u0449\u0435 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e. \u0426\u0438\u0444\u0440\u043e\u0432\u043e\u0435 \u0430\u0443\u0434\u0438\u043e \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u043b\u0438\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 <b>\u0441\u044d\u043c\u043f\u043b\u043e\u0432<\/b>, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u043e\u0432\u043e\u0439 \u0432\u043e\u043b\u043d\u044b. \u0417\u0432\u0443\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u044d\u043c\u043f\u043b, \u0438 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u044d\u043c\u043f\u043b\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443. \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 <nobr>22 050<\/nobr> \u0438 <nobr>44 100<\/nobr> \u0441\u044d\u043c\u043f\u043b\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0434\u043b\u044f \u0440\u0430\u0434\u0438\u043e \u0438 CD \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0430\u0443\u0434\u0438\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u0434\u043b\u044f \u0441\u0442\u0435\u0440\u0435\u043e \u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0432\u0443\u0447\u0430\u043d\u0438\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0441\u044d\u043c\u043f\u043b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0435\u0440\u0435\u043e, \u0441\u044d\u043c\u043f\u043b\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e \u0434\u0432\u0430 \u0437\u0430 \u0440\u0430\u0437. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0444\u0438\u043b\u044c\u043c\u0430, \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u044d\u043c\u043f\u043b\u043e\u0432 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u043d\u043e FFmpeg \u043d\u0435 \u0432\u044b\u0434\u0430\u0451\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u044b\u0445 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0441\u044d\u043c\u043f\u043b\u043e\u0432 \u2014 \u044d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442 \u0438 \u0441\u0442\u0435\u0440\u0435\u043e-\u0441\u044d\u043c\u043f\u043b.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0430\u0443\u0434\u0438\u043e \u0432 SDL \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c. \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0432\u0443\u043a\u0430: \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0438 \u0442.\u0434. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u0432\u0443\u043a, SDL \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0438 \u043f\u0440\u043e\u0441\u0438\u0442\u044c \u0435\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0430\u0443\u0434\u0438\u043e-\u0431\u0443\u0444\u0435\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0431\u0430\u0439\u0442\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043c \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>SDL_AudioSpec<\/b>, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>SDL_OpenAudio<\/b>(), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043a\u0440\u043e\u0435\u0442 \u0430\u0443\u0434\u0438\u043e\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0438 \u0432\u0435\u0440\u043d\u0451\u0442 \u043d\u0430\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>AudioSpec<\/b>. \u042d\u0442\u043e \u0442\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u2014 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0438, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u043e \u0447\u0451\u043c \u043f\u0440\u043e\u0441\u0438\u043b\u0438!<\/p>\n<h3>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u0443\u0434\u0438\u043e<\/h3>\n<p>  \u041f\u043e\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 \u0433\u043e\u043b\u043e\u0432\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043f\u043e\u043a\u0430 \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u0443\u0434\u0438\u043e\u043f\u043e\u0442\u043e\u043a\u0430\u0445! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0442\u043e\u043c\u0443 \u043c\u0435\u0441\u0442\u0443 \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u0434\u0435, \u0433\u0434\u0435 \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a \u0438 \u0432\u044b\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0443\u0434\u0438\u043e\u043f\u043e\u0442\u043e\u043a\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">\/\/ Find the first video stream videoStream=-1; audioStream=-1; for(i=0; i &lt; pFormatCtx-&gt;nb_streams; i++) {   if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO      &amp;&amp;        videoStream &lt; 0) {     videoStream=i;   }   if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_AUDIO &amp;&amp;      audioStream &lt; 0) {     audioStream=i;   } } if(videoStream==-1)   return -1; \/\/ Didn't find a video stream if(audioStream==-1)   return -1;<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0445\u043e\u0442\u0438\u043c \u043e\u0442 <b>AVCodecContext<\/b> \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430, \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0441 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">AVCodecContext *aCodecCtxOrig; AVCodecContext *aCodecCtx;  aCodecCtxOrig=pFormatCtx-&gt;streams[audioStream]-&gt;codec;<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0443\u0440\u043e\u043a\u0430\u0445, \u043d\u0430\u043c \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c \u0430\u0443\u0434\u0438\u043e\u043a\u043e\u0434\u0435\u043a. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">AVCodec         *aCodec;  aCodec = avcodec_find_decoder(aCodecCtx-&gt;codec_id); if(!aCodec) {   fprintf(stderr, &quot;Unsupported codec!\\n&quot;);   return -1; } \/\/ Copy context aCodecCtx = avcodec_alloc_context3(aCodec); if(avcodec_copy_context(aCodecCtx, aCodecCtxOrig) != 0) {   fprintf(stderr, &quot;Couldn't copy codec context&quot;);   return -1; \/\/ Error copying codec context } \/* set up SDL Audio here *\/  avcodec_open2(aCodecCtx, aCodec, NULL);<\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u0434\u0435\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u0443\u0434\u0438\u043e:<\/p>\n<pre><code class=\"cpp\">wanted_spec.freq = aCodecCtx-&gt;sample_rate; wanted_spec.format = AUDIO_S16SYS; wanted_spec.channels = aCodecCtx-&gt;channels; wanted_spec.silence = 0; wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; wanted_spec.callback = audio_callback; wanted_spec.userdata = aCodecCtx;  if(SDL_OpenAudio(&amp;wanted_spec, &amp;spec) &lt; 0) {   fprintf(stderr, &quot;SDL_OpenAudio: %s\\n&quot;, SDL_GetError());   return -1; }<\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0431\u0435\u0436\u0438\u043c\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0443\u043d\u043a\u0442\u0443:  <\/p>\n<ul>\n<li><b>freq<\/b> (\u0447\u0430\u0441\u0442\u043e\u0442\u0430): \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435.<\/li>\n<li><b>format<\/b> (\u0444\u043e\u0440\u043c\u0430\u0442): \u044d\u0442\u043e SDL \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u043a\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0435\u043c\u0443 \u0434\u0430\u0432\u0430\u0442\u044c. \u00ab<b>S<\/b>\u00bb \u0432 \u00ab<b>S16SYS<\/b>\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u00ab\u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439\u00bb, <b>16<\/b> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 16 \u0431\u0438\u0442\u043e\u0432, \u0430 \u00ab<b>SYS<\/b>\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u043e\u0432\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435\u0441\u044c. \u042d\u0442\u043e \u0444\u043e\u0440\u043c\u0430\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c <b>avcodec_decode_audio2<\/b> \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0430\u0443\u0434\u0438\u043e.<\/li>\n<li><b>channels<\/b> (\u043a\u0430\u043d\u0430\u043b\u044b): \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0443\u0434\u0438\u043e\u043a\u0430\u043d\u0430\u043b\u043e\u0432.<\/li>\n<li><b>silence<\/b> (\u0442\u0438\u0448\u0438\u043d\u0430): \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0435 \u0442\u0438\u0448\u0438\u043d\u0443. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0.<\/li>\n<li><b>samples<\/b> (\u0441\u044d\u043c\u043f\u043b\u044b): \u044d\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u0430\u0443\u0434\u0438\u043e \u0431\u0443\u0444\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b, \u0447\u0442\u043e\u0431\u044b SDL \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u043d\u0430\u043c, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0430\u0443\u0434\u0438\u043e. \u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0434\u0435\u0441\u044c \u0433\u0434\u0435-\u0442\u043e \u043c\u0435\u0436\u0434\u0443 512 \u0438 8192; FFplay, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 1024.<\/li>\n<li><b>callback<\/b> (\u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432): \u0437\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435.<\/li>\n<li><b>userdata<\/b> (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435): SDL \u0434\u0430\u0441\u0442 \u043d\u0430\u0448\u0435\u043c\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c\u0443 \u0432\u044b\u0437\u043e\u0432\u0443 \u043f\u0443\u0441\u0442\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043b\u044e\u0431\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0445\u043e\u0442\u0438\u043c. \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u0430\u0442\u044c \u0435\u043c\u0443 \u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u0434\u0435\u043a\u0430; \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u044f\u0441\u043d\u043e \u0437\u0430\u0447\u0435\u043c.<\/li>\n<\/ul>\n<p>  \u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0430\u0443\u0434\u0438\u043e \u0441 <b>SDL_OpenAudio<\/b>.<\/p>\n<h3>\u041e\u0447\u0435\u0440\u0435\u0434\u0438<\/h3>\n<p>  \u0418 \u043d\u0430\u0434\u043e \u0436\u0435! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u044d\u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439? \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0444\u0438\u043b\u044c\u043c\u0430, \u043d\u043e \u0432 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f SDL \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430! \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u043f\u0430\u043a\u0435\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0448\u0435\u0433\u043e <b>audio_callback<\/b> \u0431\u044b\u043b\u043e \u0447\u0442\u043e-\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0443\u0434\u0438\u043e\u0434\u0430\u043d\u043d\u044b\u0445! \u0418\u0442\u0430\u043a, \u0432\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432. FFmpeg \u0434\u0430\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432 \u044d\u0442\u043e\u043c: <b>AVPacketList<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u043c \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0434\u043b\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0412\u043e\u0442 \u043d\u0430\u0448\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<pre><code class=\"cpp\">typedef struct PacketQueue {   AVPacketList *first_pkt, *last_pkt;   int nb_packets;   int size;   SDL_mutex *mutex;   SDL_cond *cond; } PacketQueue;<\/code><\/pre>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e <b>nb_packets<\/b> \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0431\u0430\u0439\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 <nobr>packet-&gt;size<\/nobr>. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e SDL \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0430\u0443\u0434\u0438\u043e\u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a. \u0415\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043e\u043b\u0436\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0443\u0432\u0430\u0436\u0430\u044e\u0449\u0438\u0439 \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043d\u043e \u043c\u044b \u0442\u043e\u0436\u0435 \u043f\u043e\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0432\u0430\u043c \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 SDL.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438:<\/p>\n<pre><code class=\"cpp\">void packet_queue_init(PacketQueue *q) {   memset(q, 0, sizeof(PacketQueue));   q-&gt;mutex = SDL_CreateMutex();   q-&gt;cond = SDL_CreateCond(); }<\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043d\u0430\u0448\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c:<\/p>\n<pre><code class=\"cpp\">int packet_queue_put(PacketQueue *q, AVPacket *pkt) {    AVPacketList *pkt1;   if(av_dup_packet(pkt) &lt; 0) {     return -1;   }   pkt1 = av_malloc(sizeof(AVPacketList));   if (!pkt1)     return -1;   pkt1-&gt;pkt = *pkt;   pkt1-&gt;next = NULL;         SDL_LockMutex(q-&gt;mutex);      if (!q-&gt;last_pkt)     q-&gt;first_pkt = pkt1;   else     q-&gt;last_pkt-&gt;next = pkt1;   q-&gt;last_pkt = pkt1;   q-&gt;nb_packets++;   q-&gt;size += pkt1-&gt;pkt.size;   SDL_CondSignal(q-&gt;cond);      SDL_UnlockMutex(q-&gt;mutex);   return 0; }<\/code><\/pre>\n<p>  <b>SDL_LockMutex<\/b>() \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0430 \u0437\u0430\u0442\u0435\u043c <b>SDL_CondSignal<\/b>() \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>get<\/b> (\u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0433\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442) \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0448\u0443 \u0443\u0441\u043b\u043e\u0432\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c \u0435\u0439, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0435\u0441\u0442\u044c \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c, \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430.<\/p>\n<p>  \u0412\u043e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>get<\/b>. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a <b>SDL_CondWait<\/b>() \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0431\u043b\u043e\u043a (\u0442.\u0435. \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u0430\u0443\u0437\u0443, \u043f\u043e\u043a\u0430 \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435), \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043a\u0430\u0436\u0435\u043c \u0435\u0451 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">int quit = 0;  static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) {   AVPacketList *pkt1;   int ret;      SDL_LockMutex(q-&gt;mutex);      for(;;) {          if(quit) {       ret = -1;       break;     }      pkt1 = q-&gt;first_pkt;     if (pkt1) {       q-&gt;first_pkt = pkt1-&gt;next;       if (!q-&gt;first_pkt) \tq-&gt;last_pkt = NULL;       q-&gt;nb_packets--;       q-&gt;size -= pkt1-&gt;pkt.size;       *pkt = pkt1-&gt;pkt;       av_free(pkt1);       ret = 1;       break;     } else if (!block) {       ret = 0;       break;     } else {       SDL_CondWait(q-&gt;cond, q-&gt;mutex);     }   }   SDL_UnlockMutex(q-&gt;mutex);   return ret; }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0432\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u0437\u0430\u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u041c\u044b \u0438\u0437\u0431\u0435\u0433\u0430\u0435\u043c \u0437\u0430\u0446\u0438\u043a\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>SDL_CondWait<\/b>(). \u041f\u043e \u0441\u0443\u0442\u0438, \u0432\u0441\u0451, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 <b>CondWait<\/b>, \u2014 \u044d\u0442\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u043e\u0442 <b>SDL_CondSignal<\/b>() (\u0438\u043b\u0438 <b>SDL_CondBroadcast<\/b>()) \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043f\u043e\u0445\u043e\u0436\u0435, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0439\u043c\u0430\u043b\u0438 \u0435\u0433\u043e \u0432 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u2014 \u0435\u0441\u043b\u0438 \u043c\u044b \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443, \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>put<\/b> \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c! \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u043e, \u0447\u0442\u043e <b>SDL_CondWait<\/b>() \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0441, \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u043c\u044c\u044e\u0442\u0435\u043a\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0435\u043c\u0443 \u0434\u0430\u0451\u043c, \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u043d\u043e\u0432\u0430 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b.<\/p>\n<h3>\u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u043f\u043e\u0436\u0430\u0440\u043d\u044b\u0439<\/h3>\n<p>  \u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <b>quit<\/b>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0441\u0438\u0433\u043d\u0430\u043b \u0432\u044b\u0445\u043e\u0434\u0430 (SDL \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044b <b>TERM<\/b> \u0438 \u0442.\u043f.). \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u0442\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f \u0432\u0435\u0447\u043d\u043e, \u0438 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u0440\u0438\u0431\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c <b>kill -9<\/b>:<\/p>\n<pre><code class=\"cpp\">  SDL_PollEvent(&amp;event);   switch(event.type) {   case SDL_QUIT:     quit = 1;<\/code><\/pre>\n<p>  \u041c\u044b \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0444\u043b\u0430\u0433 \u0432\u044b\u0445\u043e\u0434\u0430 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 1.<\/p>\n<h3>\u0421\u043a\u0430\u0440\u043c\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442\u044b<\/h3>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c:<\/p>\n<pre><code class=\"cpp\">PacketQueue audioq; main() { ...   avcodec_open2(aCodecCtx, aCodec, NULL);    packet_queue_init(&amp;audioq);   SDL_PauseAudio(0);<\/code><\/pre>\n<p>  <b>SDL_PauseAudio<\/b>() \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e. \u041e\u043d \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0442\u0438\u0448\u0438\u043d\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445; \u043d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435 \u0441\u0440\u0430\u0437\u0443.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0435\u0439 \u043f\u0430\u043a\u0435\u0442\u044b. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u0446\u0438\u043a\u043b\u0443 \u0447\u0442\u0435\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cpp\">while(av_read_frame(pFormatCtx, &amp;packet)&gt;=0) {   \/\/ Is this a packet from the video stream?   if(packet.stream_index==videoStream) {     \/\/ Decode video frame     ....     }   } else if(packet.stream_index==audioStream) {     packet_queue_put(&amp;audioq, &amp;packet);   } else {     av_free_packet(&amp;packet);   }<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041c\u044b \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0437\u0436\u0435, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u0443\u0435\u043c.<\/p>\n<h3>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442\u044b<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>audio_callback<\/b> \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438. \u041e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434:<\/p>\n<pre><code class=\"cpp\">void callback(void *userdata, Uint8 *stream, int len)<\/code><\/pre>\n<p>  <b>userdata<\/b>, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u0430\u043b\u0438 SDL, <b>stream<\/b> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0443\u0444\u0435\u0440\u043e\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u0434\u0430\u043d\u043d\u044b\u0435, \u0430 <b>len<\/b> \u044d\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430. \u0412\u043e\u0442 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">void audio_callback(void *userdata, Uint8 *stream, int len) {    AVCodecContext *aCodecCtx = (AVCodecContext *)userdata;   int len1, audio_size;    static uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) \/ 2];   static unsigned int audio_buf_size = 0;   static unsigned int audio_buf_index = 0;    while(len &gt; 0) {     if(audio_buf_index &gt;= audio_buf_size) {       \/* We have already sent all our data; get more *\/       audio_size = audio_decode_frame(aCodecCtx, audio_buf,                                       sizeof(audio_buf));       if(audio_size &lt; 0) { \t\/* If error, output silence *\/ \taudio_buf_size = 1024; \tmemset(audio_buf, 0, audio_buf_size);       } else { \taudio_buf_size = audio_size;       }       audio_buf_index = 0;     }     len1 = audio_buf_size - audio_buf_index;     if(len1 &gt; len)       len1 = len;     memcpy(stream, (uint8_t *)audio_buf + audio_buf_index, len1);     len -= len1;     stream += len1;     audio_buf_index += len1;   } }<\/code><\/pre>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0430\u043c\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e, <b>audio_decode_frame<\/b>(), \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u0435, \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c <b>len<\/b> \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 \u043f\u043e\u0442\u043e\u043a \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u0438\u0445 \u0443 \u043d\u0430\u0441 \u0435\u0449\u0451 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u043d\u0430 \u043f\u043e\u0442\u043e\u043c, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0447\u0442\u043e-\u0442\u043e \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f. \u0420\u0430\u0437\u043c\u0435\u0440 <b>audio_buf<\/b> \u0432 1,5 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0430\u0443\u0434\u0438\u043e\u043a\u0430\u0434\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u0434\u0430\u0441\u0442 FFmpeg, \u0447\u0442\u043e \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0437\u0430\u043f\u0430\u0441.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u043a\u0430 \u0430\u0443\u0434\u0438\u043e<\/h3>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0434\u0435\u043a\u043e\u0434\u0435\u0440\u0430 <b>audio_decode_frame<\/b>:<\/p>\n<pre><code class=\"cpp\">int audio_decode_frame(AVCodecContext *aCodecCtx, uint8_t *audio_buf,                        int buf_size) {    static AVPacket pkt;   static uint8_t *audio_pkt_data = NULL;   static int audio_pkt_size = 0;   static AVFrame frame;    int len1, data_size = 0;    for(;;) {     while(audio_pkt_size &gt; 0) {       int got_frame = 0;       len1 = avcodec_decode_audio4(aCodecCtx, &amp;frame, &amp;got_frame, &amp;pkt);       if(len1 &lt; 0) { \t\/* if error, skip frame *\/ \taudio_pkt_size = 0; \tbreak;       }       audio_pkt_data += len1;       audio_pkt_size -= len1;       data_size = 0;       if(got_frame) { \tdata_size = av_samples_get_buffer_size(NULL,  \t\t\t\t\t       aCodecCtx-&gt;channels, \t\t\t\t\t       frame.nb_samples, \t\t\t\t\t       aCodecCtx-&gt;sample_fmt, \t\t\t\t\t       1); \tassert(data_size &lt;= buf_size); \tmemcpy(audio_buf, frame.data[0], data_size);       }       if(data_size &lt;= 0) { \t\/* No data yet, get more frames *\/ \tcontinue;       }       \/* We have data, return it and come back for more later *\/       return data_size;     }     if(pkt.data)       av_free_packet(&amp;pkt);      if(quit) {       return -1;     }      if(packet_queue_get(&amp;audioq, &amp;pkt, 1) &lt; 0) {       return -1;     }     audio_pkt_data = pkt.data;     audio_pkt_size = pkt.size;   } }<\/code><\/pre>\n<p>  \u0412\u0435\u0441\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u043a \u043a\u043e\u043d\u0446\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0433\u0434\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>packet_queue_get<\/b>(). \u041c\u044b \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u043d\u0435\u0433\u043e. \u0417\u0430\u0442\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>avcodec_decode_audio4<\/b>(), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e \u043c\u043d\u043e\u0433\u043e\u043c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u0432\u043e\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u0441\u0435\u0441\u0442\u0440\u0443 <b>avcodec_decode_video<\/b>(), \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0430\u043a\u0435\u0442 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043a\u0430\u0434\u0440, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448 \u0430\u0443\u0434\u0438\u043e-\u0431\u0443\u0444\u0435\u0440, \u0443\u0431\u0435\u0434\u0438\u0432\u0448\u0438\u0441\u044c, \u0447\u0442\u043e <b>data_size<\/b> \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u0443\u0434\u0438\u043e-\u0431\u0443\u0444\u0435\u0440\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043f\u0440\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 <b>audio_buf<\/b> \u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e SDL \u0434\u0430\u0435\u0442 8-\u0431\u0438\u0442\u043d\u044b\u0439 int-\u0431\u0443\u0444\u0435\u0440, \u0430 FFmpeg \u0434\u0430\u0435\u0442 \u043d\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 16-\u0431\u0438\u0442\u043d\u043e\u043c int-\u0431\u0443\u0444\u0435\u0440\u0435. \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 <b>len1<\/b> \u0438 <b>data_size<\/b>. <b>len1<\/b> \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0451\u043c \u043f\u0430\u043a\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438, \u0430 <b>data_size<\/b> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043c\u044b \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u043d\u0443\u0436\u043d\u043e \u043b\u0438 \u043d\u0430\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u043b\u0438 \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u0415\u0441\u043b\u0438 \u043d\u0430\u043c \u0435\u0449\u0451 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e. \u0415\u0441\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0438 \u0441 \u043f\u0430\u043a\u0435\u0442\u043e\u043c, \u0442\u043e \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0435\u0433\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c.<\/p>\n<p>  \u0418 \u044d\u0442\u043e \u0432\u0441\u0451! \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0430\u0443\u0434\u0438\u043e, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0435 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0447\u0442\u0435\u043d\u0438\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u0442\u0435\u043c \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <b>audio_callback<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 SDL, \u0430 SDL \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u043d\u0430 \u0432\u0430\u0448\u0443 \u0437\u0432\u0443\u043a\u043e\u0432\u0443\u044e \u043a\u0430\u0440\u0442\u0443. \u0418\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code class=\"bash\">gcc -o tutorial03 tutorial03.c -lavutil -lavformat -lavcodec -lswscale -lz -lm \\ `sdl-config --cflags --libs`<\/code><\/pre>\n<p>  \u0413\u0438\u043f-\u0433\u0438\u043f-\u0443\u0440\u0430! \u0412\u0438\u0434\u0435\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435\u0441\u0451\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u043d\u043e \u0437\u0432\u0443\u043a \u0443\u0436\u0435 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0430\u0434\u043e. \u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a? \u0414\u0430 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0430\u0443\u0434\u0438\u043e\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u043c\u044b \u0432\u044b\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0430\u0443\u0434\u0438\u043e\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u0430\u0443\u0434\u0438\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u041c\u044b \u043f\u043e\u0447\u0442\u0438 \u0441\u043e\u0437\u0440\u0435\u043b\u0438 \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0438\u0434\u0435\u043e \u0438 \u0430\u0443\u0434\u0438\u043e, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0440\u0435\u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041c\u0435\u0442\u043e\u0434 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0432\u0443\u043a\u0430 \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e: \u043e\u043d \u0434\u0435\u043b\u0430\u043b \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u043d\u0451\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u0430\u0443\u0434\u0438\u043e, \u043d\u0443\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0435\u0440\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u043b\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f!<\/p>\n<p>  <a name=\"threads\"><\/a><\/p>\n<h2>\u0423\u0440\u043e\u043a 4: \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0440\u0435\u0434\u044b <a href=\"#menu\">\u2191<\/a><\/h2>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 tutorial04.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/ tutorial04.c \/\/ A pedagogical video player that will stream through every video frame as fast as it can, \/\/ and play audio (out of sync). \/\/ \/\/ Code based on FFplay, Copyright (c) 2003 Fabrice Bellard,  \/\/ and a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) \/\/ Tested on Gentoo, CVS version 5\/01\/07 compiled with GCC 4.1.1 \/\/ With updates from https:\/\/github.com\/chelyaev\/ffmpeg-tutorial \/\/ Updates tested on: \/\/ LAVC 54.59.100, LAVF 54.29.104, LSWS 2.1.101, SDL 1.2.15 \/\/ on GCC 4.7.2 in Debian February 2015 \/\/ Use \/\/ \/\/ gcc -o tutorial04 tutorial04.c -lavformat -lavcodec -lswscale -lz -lm `sdl-config --cflags --libs` \/\/ to build (assuming libavformat and libavcodec are correctly installed,  \/\/ and assuming you have sdl-config. Please refer to SDL docs for your installation.) \/\/ \/\/ Run using \/\/ tutorial04 myvideofile.mpg \/\/ \/\/ to play the video stream on your screen.  #include &lt;libavcodec\/avcodec.h&gt; #include &lt;libavformat\/avformat.h&gt; #include &lt;libswscale\/swscale.h&gt;  #include &lt;SDL.h&gt; #include &lt;SDL_thread.h&gt;  #ifdef __MINGW32__ #undef main \/* Prevents SDL from overriding main() *\/ #endif  #include &lt;stdio.h&gt; #include &lt;assert.h&gt; #include &lt;math.h&gt;  \/\/ compatibility with newer API #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1) #define av_frame_alloc avcodec_alloc_frame #define av_frame_free avcodec_free_frame #endif  #define SDL_AUDIO_BUFFER_SIZE 1024 #define MAX_AUDIO_FRAME_SIZE 192000  #define MAX_AUDIOQ_SIZE (5 * 16 * 1024) #define MAX_VIDEOQ_SIZE (5 * 256 * 1024)  #define FF_REFRESH_EVENT (SDL_USEREVENT) #define FF_QUIT_EVENT (SDL_USEREVENT + 1)  #define VIDEO_PICTURE_QUEUE_SIZE 1  typedef struct PacketQueue {   AVPacketList *first_pkt, *last_pkt;   int nb_packets;   int size;   SDL_mutex *mutex;   SDL_cond *cond; } PacketQueue;   typedef struct VideoPicture {   SDL_Overlay *bmp;   int width, height; \/* source height &amp; width *\/   int allocated; } VideoPicture;  typedef struct VideoState {    AVFormatContext *pFormatCtx;   int             videoStream, audioStream;   AVStream        *audio_st;   AVCodecContext  *audio_ctx;   PacketQueue     audioq;   uint8_t         audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) \/ 2];   unsigned int    audio_buf_size;   unsigned int    audio_buf_index;   AVFrame         audio_frame;   AVPacket        audio_pkt;   uint8_t         *audio_pkt_data;   int             audio_pkt_size;   AVStream        *video_st;   AVCodecContext  *video_ctx;   PacketQueue     videoq;   struct SwsContext *sws_ctx;    VideoPicture    pictq[VIDEO_PICTURE_QUEUE_SIZE];   int             pictq_size, pictq_rindex, pictq_windex;   SDL_mutex       *pictq_mutex;   SDL_cond        *pictq_cond;      SDL_Thread      *parse_tid;   SDL_Thread      *video_tid;    char            filename[1024];   int             quit; } VideoState;  SDL_Surface     *screen; SDL_mutex       *screen_mutex;  \/* Since we only have one decoding thread, the Big Struct    can be global in case we need it. *\/ VideoState *global_video_state;  void packet_queue_init(PacketQueue *q) {   memset(q, 0, sizeof(PacketQueue));   q-&gt;mutex = SDL_CreateMutex();   q-&gt;cond = SDL_CreateCond(); } int packet_queue_put(PacketQueue *q, AVPacket *pkt) {    AVPacketList *pkt1;   if(av_dup_packet(pkt) &lt; 0) {     return -1;   }   pkt1 = av_malloc(sizeof(AVPacketList));   if (!pkt1)     return -1;   pkt1-&gt;pkt = *pkt;   pkt1-&gt;next = NULL;      SDL_LockMutex(q-&gt;mutex);    if (!q-&gt;last_pkt)     q-&gt;first_pkt = pkt1;   else     q-&gt;last_pkt-&gt;next = pkt1;   q-&gt;last_pkt = pkt1;   q-&gt;nb_packets++;   q-&gt;size += pkt1-&gt;pkt.size;   SDL_CondSignal(q-&gt;cond);      SDL_UnlockMutex(q-&gt;mutex);   return 0; } static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) {   AVPacketList *pkt1;   int ret;    SDL_LockMutex(q-&gt;mutex);      for(;;) {          if(global_video_state-&gt;quit) {       ret = -1;       break;     }      pkt1 = q-&gt;first_pkt;     if (pkt1) {       q-&gt;first_pkt = pkt1-&gt;next;       if (!q-&gt;first_pkt) \tq-&gt;last_pkt = NULL;       q-&gt;nb_packets--;       q-&gt;size -= pkt1-&gt;pkt.size;       *pkt = pkt1-&gt;pkt;       av_free(pkt1);       ret = 1;       break;     } else if (!block) {       ret = 0;       break;     } else {       SDL_CondWait(q-&gt;cond, q-&gt;mutex);     }   }   SDL_UnlockMutex(q-&gt;mutex);   return ret; }  int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int buf_size) {    int len1, data_size = 0;   AVPacket *pkt = &amp;is-&gt;audio_pkt;    for(;;) {     while(is-&gt;audio_pkt_size &gt; 0) {       int got_frame = 0;       len1 = avcodec_decode_audio4(is-&gt;audio_ctx, &amp;is-&gt;audio_frame, &amp;got_frame, pkt);       if(len1 &lt; 0) { \t\/* if error, skip frame *\/ \tis-&gt;audio_pkt_size = 0; \tbreak;       }       data_size = 0;       if(got_frame) { \tdata_size = av_samples_get_buffer_size(NULL,  \t\t\t\t\t       is-&gt;audio_ctx-&gt;channels, \t\t\t\t\t       is-&gt;audio_frame.nb_samples, \t\t\t\t\t       is-&gt;audio_ctx-&gt;sample_fmt, \t\t\t\t\t       1); \tassert(data_size &lt;= buf_size); \tmemcpy(audio_buf, is-&gt;audio_frame.data[0], data_size);       }       is-&gt;audio_pkt_data += len1;       is-&gt;audio_pkt_size -= len1;       if(data_size &lt;= 0) { \t\/* No data yet, get more frames *\/ \tcontinue;       }       \/* We have data, return it and come back for more later *\/       return data_size;     }     if(pkt-&gt;data)       av_free_packet(pkt);      if(is-&gt;quit) {       return -1;     }     \/* next packet *\/     if(packet_queue_get(&amp;is-&gt;audioq, pkt, 1) &lt; 0) {       return -1;     }     is-&gt;audio_pkt_data = pkt-&gt;data;     is-&gt;audio_pkt_size = pkt-&gt;size;   } }  void audio_callback(void *userdata, Uint8 *stream, int len) {    VideoState *is = (VideoState *)userdata;   int len1, audio_size;    while(len &gt; 0) {     if(is-&gt;audio_buf_index &gt;= is-&gt;audio_buf_size) {       \/* We have already sent all our data; get more *\/       audio_size = audio_decode_frame(is, is-&gt;audio_buf, sizeof(is-&gt;audio_buf));       if(audio_size &lt; 0) { \t\/* If error, output silence *\/ \tis-&gt;audio_buf_size = 1024; \tmemset(is-&gt;audio_buf, 0, is-&gt;audio_buf_size);       } else { \tis-&gt;audio_buf_size = audio_size;       }       is-&gt;audio_buf_index = 0;     }     len1 = is-&gt;audio_buf_size - is-&gt;audio_buf_index;     if(len1 &gt; len)       len1 = len;     memcpy(stream, (uint8_t *)is-&gt;audio_buf + is-&gt;audio_buf_index, len1);     len -= len1;     stream += len1;     is-&gt;audio_buf_index += len1;   } }  static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque) {   SDL_Event event;   event.type = FF_REFRESH_EVENT;   event.user.data1 = opaque;   SDL_PushEvent(&amp;event);   return 0; \/* 0 means stop timer *\/ }  \/* schedule a video refresh in 'delay' ms *\/ static void schedule_refresh(VideoState *is, int delay) {   SDL_AddTimer(delay, sdl_refresh_timer_cb, is); }  void video_display(VideoState *is) {    SDL_Rect rect;   VideoPicture *vp;   float aspect_ratio;   int w, h, x, y;   int i;    vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];   if(vp-&gt;bmp) {     if(is-&gt;video_ctx-&gt;sample_aspect_ratio.num == 0) {       aspect_ratio = 0;     } else {       aspect_ratio = av_q2d(is-&gt;video_ctx-&gt;sample_aspect_ratio) * \tis-&gt;video_ctx-&gt;width \/ is-&gt;video_ctx-&gt;height;     }     if(aspect_ratio &lt;= 0.0) {       aspect_ratio = (float)is-&gt;video_ctx-&gt;width \/ \t(float)is-&gt;video_ctx-&gt;height;     }     h = screen-&gt;h;     w = ((int)rint(h * aspect_ratio)) &amp; -3;     if(w &gt; screen-&gt;w) {       w = screen-&gt;w;       h = ((int)rint(w \/ aspect_ratio)) &amp; -3;     }     x = (screen-&gt;w - w) \/ 2;     y = (screen-&gt;h - h) \/ 2;          rect.x = x;     rect.y = y;     rect.w = w;     rect.h = h;     SDL_LockMutex(screen_mutex);     SDL_DisplayYUVOverlay(vp-&gt;bmp, &amp;rect);     SDL_UnlockMutex(screen_mutex);    } }  void video_refresh_timer(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;      if(is-&gt;video_st) {     if(is-&gt;pictq_size == 0) {       schedule_refresh(is, 1);     } else {       vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];       \/* Now, normally here goes a ton of code \t about timing, etc. we're just going to \t guess at a delay for now. You can \t increase and decrease this value and hard code \t the timing - but I don't suggest that ;) \t We'll learn how to do it for real later.       *\/       schedule_refresh(is, 40);              \/* show the picture! *\/       video_display(is);              \/* update queue for next picture! *\/       if(++is-&gt;pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { \tis-&gt;pictq_rindex = 0;       }       SDL_LockMutex(is-&gt;pictq_mutex);       is-&gt;pictq_size--;       SDL_CondSignal(is-&gt;pictq_cond);       SDL_UnlockMutex(is-&gt;pictq_mutex);     }   } else {     schedule_refresh(is, 100);   } }        void alloc_picture(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;    vp = &amp;is-&gt;pictq[is-&gt;pictq_windex];   if(vp-&gt;bmp) {     \/\/ we already have one make another, bigger\/smaller     SDL_FreeYUVOverlay(vp-&gt;bmp);   }   \/\/ Allocate a place to put our YUV image on that screen   SDL_LockMutex(screen_mutex);   vp-&gt;bmp = SDL_CreateYUVOverlay(is-&gt;video_ctx-&gt;width, \t\t\t\t is-&gt;video_ctx-&gt;height, \t\t\t\t SDL_YV12_OVERLAY, \t\t\t\t screen);   SDL_UnlockMutex(screen_mutex);    vp-&gt;width = is-&gt;video_ctx-&gt;width;   vp-&gt;height = is-&gt;video_ctx-&gt;height;   vp-&gt;allocated = 1;  }  int queue_picture(VideoState *is, AVFrame *pFrame) {    VideoPicture *vp;   int dst_pix_fmt;   AVPicture pict;    \/* wait until we have space for a new pic *\/   SDL_LockMutex(is-&gt;pictq_mutex);   while(is-&gt;pictq_size &gt;= VIDEO_PICTURE_QUEUE_SIZE &amp;&amp; \t!is-&gt;quit) {     SDL_CondWait(is-&gt;pictq_cond, is-&gt;pictq_mutex);   }   SDL_UnlockMutex(is-&gt;pictq_mutex);    if(is-&gt;quit)     return -1;    \/\/ windex is set to 0 initially   vp = &amp;is-&gt;pictq[is-&gt;pictq_windex];    \/* allocate or resize the buffer! *\/   if(!vp-&gt;bmp ||      vp-&gt;width != is-&gt;video_ctx-&gt;width ||      vp-&gt;height != is-&gt;video_ctx-&gt;height) {     SDL_Event event;      vp-&gt;allocated = 0;     alloc_picture(is);     if(is-&gt;quit) {       return -1;     }   }    \/* We have a place to put our picture on the queue *\/    if(vp-&gt;bmp) {      SDL_LockYUVOverlay(vp-&gt;bmp);          dst_pix_fmt = PIX_FMT_YUV420P;     \/* point pict at the queue *\/      pict.data[0] = vp-&gt;bmp-&gt;pixels[0];     pict.data[1] = vp-&gt;bmp-&gt;pixels[2];     pict.data[2] = vp-&gt;bmp-&gt;pixels[1];          pict.linesize[0] = vp-&gt;bmp-&gt;pitches[0];     pict.linesize[1] = vp-&gt;bmp-&gt;pitches[2];     pict.linesize[2] = vp-&gt;bmp-&gt;pitches[1];          \/\/ Convert the image into YUV format that SDL uses     sws_scale(is-&gt;sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t      pFrame-&gt;linesize, 0, is-&gt;video_ctx-&gt;height, \t      pict.data, pict.linesize);          SDL_UnlockYUVOverlay(vp-&gt;bmp);     \/* now we inform our display thread that we have a pic ready *\/     if(++is-&gt;pictq_windex == VIDEO_PICTURE_QUEUE_SIZE) {       is-&gt;pictq_windex = 0;     }     SDL_LockMutex(is-&gt;pictq_mutex);     is-&gt;pictq_size++;     SDL_UnlockMutex(is-&gt;pictq_mutex);   }   return 0; }  int video_thread(void *arg) {   VideoState *is = (VideoState *)arg;   AVPacket pkt1, *packet = &amp;pkt1;   int frameFinished;   AVFrame *pFrame;    pFrame = av_frame_alloc();    for(;;) {     if(packet_queue_get(&amp;is-&gt;videoq, packet, 1) &lt; 0) {       \/\/ means we quit getting packets       break;     }     \/\/ Decode video frame     avcodec_decode_video2(is-&gt;video_ctx, pFrame, &amp;frameFinished, packet);     \/\/ Did we get a video frame?     if(frameFinished) {       if(queue_picture(is, pFrame) &lt; 0) { \tbreak;       }           }     av_free_packet(packet);   }   av_frame_free(&amp;pFrame);   return 0; }  int stream_component_open(VideoState *is, int stream_index) {    AVFormatContext *pFormatCtx = is-&gt;pFormatCtx;   AVCodecContext *codecCtx = NULL;   AVCodec *codec = NULL;   SDL_AudioSpec wanted_spec, spec;    if(stream_index &lt; 0 || stream_index &gt;= pFormatCtx-&gt;nb_streams) {     return -1;   }    codec = avcodec_find_decoder(pFormatCtx-&gt;streams[stream_index]-&gt;codec-&gt;codec_id);   if(!codec) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    codecCtx = avcodec_alloc_context3(codec);   if(avcodec_copy_context(codecCtx, pFormatCtx-&gt;streams[stream_index]-&gt;codec) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }     if(codecCtx-&gt;codec_type == AVMEDIA_TYPE_AUDIO) {     \/\/ Set audio settings from codec info     wanted_spec.freq = codecCtx-&gt;sample_rate;     wanted_spec.format = AUDIO_S16SYS;     wanted_spec.channels = codecCtx-&gt;channels;     wanted_spec.silence = 0;     wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;     wanted_spec.callback = audio_callback;     wanted_spec.userdata = is;          if(SDL_OpenAudio(&amp;wanted_spec, &amp;spec) &lt; 0) {       fprintf(stderr, &quot;SDL_OpenAudio: %s\\n&quot;, SDL_GetError());       return -1;     }   }   if(avcodec_open2(codecCtx, codec, NULL) &lt; 0) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    switch(codecCtx-&gt;codec_type) {   case AVMEDIA_TYPE_AUDIO:     is-&gt;audioStream = stream_index;     is-&gt;audio_st = pFormatCtx-&gt;streams[stream_index];     is-&gt;audio_ctx = codecCtx;     is-&gt;audio_buf_size = 0;     is-&gt;audio_buf_index = 0;     memset(&amp;is-&gt;audio_pkt, 0, sizeof(is-&gt;audio_pkt));     packet_queue_init(&amp;is-&gt;audioq);     SDL_PauseAudio(0);     break;   case AVMEDIA_TYPE_VIDEO:     is-&gt;videoStream = stream_index;     is-&gt;video_st = pFormatCtx-&gt;streams[stream_index];     is-&gt;video_ctx = codecCtx;     packet_queue_init(&amp;is-&gt;videoq);     is-&gt;video_tid = SDL_CreateThread(video_thread, is);     is-&gt;sws_ctx = sws_getContext(is-&gt;video_ctx-&gt;width, is-&gt;video_ctx-&gt;height, \t\t\t\t is-&gt;video_ctx-&gt;pix_fmt, is-&gt;video_ctx-&gt;width, \t\t\t\t is-&gt;video_ctx-&gt;height, PIX_FMT_YUV420P, \t\t\t\t SWS_BILINEAR, NULL, NULL, NULL \t\t\t\t );     break;   default:     break;   } }  int decode_thread(void *arg) {    VideoState *is = (VideoState *)arg;   AVFormatContext *pFormatCtx;   AVPacket pkt1, *packet = &amp;pkt1;    int video_index = -1;   int audio_index = -1;   int i;    is-&gt;videoStream=-1;   is-&gt;audioStream=-1;    global_video_state = is;    \/\/ Open video file   if(avformat_open_input(&amp;pFormatCtx, is-&gt;filename, NULL, NULL)!=0)     return -1; \/\/ Couldn't open file    is-&gt;pFormatCtx = pFormatCtx;      \/\/ Retrieve stream information   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)     return -1; \/\/ Couldn't find stream information      \/\/ Dump information about file onto standard error   av_dump_format(pFormatCtx, 0, is-&gt;filename, 0);      \/\/ Find the first video stream    for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++) {     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO &amp;&amp;        video_index &lt; 0) {       video_index=i;     }     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_AUDIO &amp;&amp;        audio_index &lt; 0) {       audio_index=i;     }   }   if(audio_index &gt;= 0) {     stream_component_open(is, audio_index);   }   if(video_index &gt;= 0) {     stream_component_open(is, video_index);   }       if(is-&gt;videoStream &lt; 0 || is-&gt;audioStream &lt; 0) {     fprintf(stderr, &quot;%s: could not open codecs\\n&quot;, is-&gt;filename);     goto fail;   }    \/\/ main decode loop    for(;;) {     if(is-&gt;quit) {       break;     }     \/\/ seek stuff goes here     if(is-&gt;audioq.size &gt; MAX_AUDIOQ_SIZE ||        is-&gt;videoq.size &gt; MAX_VIDEOQ_SIZE) {       SDL_Delay(10);       continue;     }     if(av_read_frame(is-&gt;pFormatCtx, packet) &lt; 0) {       if(is-&gt;pFormatCtx-&gt;pb-&gt;error == 0) { \tSDL_Delay(100); \/* no error; wait for user input *\/ \tcontinue;       } else { \tbreak;       }     }     \/\/ Is this a packet from the video stream?     if(packet-&gt;stream_index == is-&gt;videoStream) {       packet_queue_put(&amp;is-&gt;videoq, packet);     } else if(packet-&gt;stream_index == is-&gt;audioStream) {       packet_queue_put(&amp;is-&gt;audioq, packet);     } else {       av_free_packet(packet);     }   }   \/* all done - wait for it *\/   while(!is-&gt;quit) {     SDL_Delay(100);   }   fail:   if(1){     SDL_Event event;     event.type = FF_QUIT_EVENT;     event.user.data1 = is;     SDL_PushEvent(&amp;event);   }   return 0; }  int main(int argc, char *argv[]) {    SDL_Event       event;    VideoState      *is;    is = av_mallocz(sizeof(VideoState));    if(argc &lt; 2) {     fprintf(stderr, &quot;Usage: test &lt;file&gt;\\n&quot;);     exit(1);   }   \/\/ Register all formats and codecs   av_register_all();      if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {     fprintf(stderr, &quot;Could not initialize SDL - %s\\n&quot;, SDL_GetError());     exit(1);   }    \/\/ Make a screen to put our video #ifndef __DARWIN__         screen = SDL_SetVideoMode(640, 480, 0, 0); #else         screen = SDL_SetVideoMode(640, 480, 24, 0); #endif   if(!screen) {     fprintf(stderr, &quot;SDL: could not set video mode - exiting\\n&quot;);     exit(1);   }    screen_mutex = SDL_CreateMutex();    av_strlcpy(is-&gt;filename, argv[1], sizeof(is-&gt;filename));    is-&gt;pictq_mutex = SDL_CreateMutex();   is-&gt;pictq_cond = SDL_CreateCond();    schedule_refresh(is, 40);    is-&gt;parse_tid = SDL_CreateThread(decode_thread, is);   if(!is-&gt;parse_tid) {     av_free(is);     return -1;   }   for(;;) {      SDL_WaitEvent(&amp;event);     switch(event.type) {     case FF_QUIT_EVENT:     case SDL_QUIT:       is-&gt;quit = 1;       SDL_Quit();       return 0;       break;     case FF_REFRESH_EVENT:       video_refresh_timer(event.user.data1);       break;     default:       break;     }   }   return 0;  }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h3>\u041e\u0431\u0437\u043e\u0440<\/h3>\n<p>  \u0412 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0440\u0430\u0437 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0430\u0443\u0434\u0438\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0430\u0443\u0434\u0438\u043e\u0444\u0443\u043d\u043a\u0446\u0438\u0438 SDL. SDL \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u043f\u043e\u0442\u043e\u043a, \u0434\u0435\u043b\u0430\u044e\u0449\u0438\u0439 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u043b\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f \u0437\u0432\u0443\u043a. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441 \u0432\u0438\u0434\u0435\u043e\u0434\u0438\u0441\u043f\u043b\u0435\u0435\u043c. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u043c \u0438 \u0441 \u043d\u0438\u043c \u043f\u0440\u043e\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u2014 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e. \u0422\u0430\u043a \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u043d\u0451\u043c?<\/p>\n<p>  \u0417\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e: \u043e\u043d\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0446\u0438\u043a\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442\u044b \u0438 \u200b\u200b\u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u0432\u0438\u0434\u0435\u043e. \u0427\u0442\u043e \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u0441\u0451 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438: \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0442\u043e\u043a, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u043e\u0432; \u0437\u0430\u0442\u0435\u043c \u044d\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0430\u0443\u0434\u0438\u043e- \u0438 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438. \u0410\u0443\u0434\u0438\u043e\u043f\u043e\u0442\u043e\u043a \u043c\u044b \u0443\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u0442\u0430\u043a, \u043a\u0430\u043a \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f; \u0441 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u043a\u0430\u0437 \u0432\u0438\u0434\u0435\u043e \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u0438\u043b\u0430\u043c\u0438. \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0434\u0438\u0441\u043f\u043b\u0435\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0446\u0438\u043a\u043b. \u041d\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0446\u0438\u043a\u043b, \u043c\u044b \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0435\u043e \u0432 \u0446\u0438\u043a\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0418\u0434\u0435\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u0434\u0440 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0437\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 (<b>FF_REFRESH_EVENT<\/b>), \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0437\u0430\u0442\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u0446\u0438\u043a\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0443\u0432\u0438\u0434\u0438\u0442 \u044d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043e\u043d \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438., \u0412\u043e\u0442 \u0443\u0434\u043e\u0431\u043d\u0430\u044f ASCII-\u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442:<\/p>\n<div style=\"text-align:center;\"><img loading=\"lazy\" decoding=\"async\" width=\"335\" height=\"221\" src=\"https:\/\/habrastorage.org\/webt\/nf\/ej\/gq\/nfejgqoqpypds3quordh_x2qgwa.png\"><\/div>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0447\u0435\u0440\u0435\u0437 \u0446\u0438\u043a\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u0442\u043e\u043a\u0430 <b>SDL_Delay<\/b> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0442\u043e\u0447\u043d\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0434\u0440 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b, \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0443\u0440\u043e\u043a\u0435, \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0435\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f.<\/p>\n<h3>\u0423\u043f\u0440\u043e\u0449\u0430\u0435\u043c \u043a\u043e\u0434<\/h3>\n<p>  \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0447\u0438\u0441\u0442\u0438\u043c \u043a\u043e\u0434. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u044f \u044d\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0431 \u0430\u0443\u0434\u0438\u043e- \u0438 \u0432\u0438\u0434\u0435\u043e\u043a\u043e\u0434\u0435\u043a\u0430\u0445, \u0438 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0431\u0443\u0444\u0435\u0440\u044b, \u0438 \u0411\u043e\u0433 \u0432\u0435\u0441\u0442\u044c \u0447\u0442\u043e \u0435\u0449\u0451. \u0412\u0441\u0435 \u044d\u0442\u0438 \u0448\u0442\u0443\u043a\u0438 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0439 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0435\u0434\u0438\u043d\u0438\u0446\u044b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u2014 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u0430. \u0418\u0442\u0430\u043a, \u043c\u044b \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0432\u0441\u044e \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e <b>VideoState<\/b>.<\/p>\n<pre><code class=\"cpp\">typedef struct VideoState {    AVFormatContext *pFormatCtx;   int             videoStream, audioStream;   AVStream        *audio_st;   AVCodecContext  *audio_ctx;   PacketQueue     audioq;   uint8_t         audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) \/ 2];   unsigned int    audio_buf_size;   unsigned int    audio_buf_index;   AVPacket        audio_pkt;   uint8_t         *audio_pkt_data;   int             audio_pkt_size;   AVStream        *video_st;   AVCodecContext  *video_ctx;   PacketQueue     videoq;    VideoPicture    pictq[VIDEO_PICTURE_QUEUE_SIZE];   int             pictq_size, pictq_rindex, pictq_windex;   SDL_mutex       *pictq_mutex;   SDL_cond        *pictq_cond;      SDL_Thread      *parse_tid;   SDL_Thread      *video_tid;    char            filename[1024];   int             quit; } VideoState;<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043d\u0430\u043c\u0451\u043a\u0438 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0438\u0442\u043e\u0433\u0435. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0438\u0434\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u2014 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0430\u0443\u0434\u0438\u043e- \u0438 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b <b>AVStream<\/b>. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0430\u0443\u0434\u0438\u043e\u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u044b \u0432 \u044d\u0442\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u041e\u043d\u0438 (<b>audio_buf<\/b>, <b>audio_buf_size<\/b> \u0438 \u0442.\u0434.) \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u043b\u0438\u0441\u044c \u0434\u043b\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u0443\u0434\u0438\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0442\u0430\u043c (\u0438\u043b\u0438 \u0436\u0435 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e). \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043b\u044f \u0432\u0438\u0434\u0435\u043e \u0438 \u0431\u0443\u0444\u0435\u0440 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438; \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u044d\u043a\u0441\u0442\u0440\u0430\u0432\u0430\u0433\u0430\u043d\u0442\u043d\u044b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b) \u0434\u043b\u044f \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u0434\u0440\u043e\u0432 (\u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043a\u0430\u043a \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0435). \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <b>VideoPicture<\/b> \u2014 \u044d\u0442\u043e \u043d\u0430\u0448\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0435 (\u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u0431\u0443\u0434\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0434\u0451\u043c \u043a \u043d\u0435\u0439). \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u043b\u0430\u0433 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438 \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0444\u0438\u043b\u044c\u043c\u0430.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0434\u0430\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u0442 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>VideoState<\/b>:<\/p>\n<pre><code class=\"cpp\">int main(int argc, char *argv[]) {    SDL_Event       event;    VideoState      *is;    is = av_mallocz(sizeof(VideoState));<\/code><\/pre>\n<p>  <b>av_mallocz<\/b>() \u2014 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u043e\u0431\u043d\u0443\u043b\u044f\u0442\u044c \u0435\u0451.<\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0434\u043b\u044f \u0431\u0443\u0444\u0435\u0440\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (<b>pictq<\/b>), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0446\u0438\u043a\u043b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u2014 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u0430\u0434\u0440\u044b \u0438\u0437 <b>pictq<\/b>. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0448 \u0432\u0438\u0434\u0435\u043e\u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u2014 \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u0435\u043c, \u043a\u0442\u043e \u0442\u0443\u0434\u0430 \u0434\u043e\u0431\u0435\u0440\u0451\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u044b\u043c. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0433\u043e\u043d\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0441\u0435\u0439\u0447\u0430\u0441, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0442\u0435\u043c\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0430\u043a\u0436\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0438\u043b\u044c\u043c\u0430 \u0432 <b>VideoState<\/b>:<\/p>\n<pre><code class=\"cpp\">av_strlcpy(is-&gt;filename, argv[1], sizeof(is-&gt;filename));  is-&gt;pictq_mutex = SDL_CreateMutex(); is-&gt;pictq_cond = SDL_CreateCond();<\/code><\/pre>\n<p>  <b>av_strlcpy<\/b> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437 FFmpeg, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0433\u0440\u0430\u043d\u0438\u0446 \u043f\u043e\u043c\u0438\u043c\u043e <b>strncpy<\/b>.<\/p>\n<h3>\u041d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0440\u0435\u0434<\/h3>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0435:<\/p>\n<pre><code class=\"cpp\">schedule_refresh(is, 40);  is-&gt;parse_tid = SDL_CreateThread(decode_thread, is); if(!is-&gt;parse_tid) {   av_free(is);   return -1; }<\/code><\/pre>\n<p>  <b>schedule_refresh<\/b> \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u043e\u0437\u0436\u0435. \u0427\u0442\u043e \u043e\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442, \u0442\u0430\u043a \u044d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 <b>FF_REFRESH_EVENT<\/b> \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434. \u042d\u0442\u043e, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0435\u043e, \u043a\u043e\u0433\u0434\u0430 \u0443\u0432\u0438\u0434\u0438\u043c \u0435\u0451 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 <b>SDL_CreateThread<\/b>().<\/p>\n<p>  <b>SDL_CreateThread<\/b>() \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u2014 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043a, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0435\u043c\u0443 \u0434\u0430\u0451\u043c. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>decode_thread<\/b>() \u0438 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>VideoState<\/b>. \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e; \u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044e \u0444\u0430\u0439\u043b\u0430 \u0438 \u043f\u043e\u0438\u0441\u043a\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0430\u0443\u0434\u0438\u043e \u0438 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0438\u043d\u0430\u0447\u0435 \u2014 \u044d\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435. \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043d\u0430\u0448\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, <b>stream_component_open<\/b>(). \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f, \u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0432\u0435\u0449\u0435\u0439 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u0438\u0434\u0435\u043e \u0438 \u0430\u0443\u0434\u0438\u043e\u043a\u043e\u0434\u0435\u043a\u0430, \u0442\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u0434, \u0434\u0435\u043b\u0430\u044f \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439.<\/p>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u044f <b>stream_component_open<\/b>() \u2014 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u043d\u0430\u0448 \u0434\u0435\u043a\u043e\u0434\u0435\u0440 \u043a\u043e\u0434\u0435\u043a\u0430, \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0432\u0443\u043a\u0430, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432\u0430\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u0448\u0438 \u0430\u0443\u0434\u0438\u043e \u0438 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0438. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0435\u043a\u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0435\u0433\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u0442.\u0434. \u0412\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cpp\">int stream_component_open(VideoState *is, int stream_index) {    AVFormatContext *pFormatCtx = is-&gt;pFormatCtx;   AVCodecContext *codecCtx;   AVCodec *codec;   SDL_AudioSpec wanted_spec, spec;    if(stream_index &lt; 0 || stream_index &gt;= pFormatCtx-&gt;nb_streams) {     return -1;   }    codec = avcodec_find_decoder(pFormatCtx-&gt;streams[stream_index]-&gt;codec-&gt;codec_id);   if(!codec) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    codecCtx = avcodec_alloc_context3(codec);   if(avcodec_copy_context(codecCtx, pFormatCtx-&gt;streams[stream_index]-&gt;codec) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }     if(codecCtx-&gt;codec_type == AVMEDIA_TYPE_AUDIO) {     \/\/ Set audio settings from codec info     wanted_spec.freq = codecCtx-&gt;sample_rate;     \/* ...etc... *\/     wanted_spec.callback = audio_callback;     wanted_spec.userdata = is;          if(SDL_OpenAudio(&amp;wanted_spec, &amp;spec) &lt; 0) {       fprintf(stderr, &quot;SDL_OpenAudio: %s\\n&quot;, SDL_GetError());       return -1;     }   }   if(avcodec_open2(codecCtx, codec, NULL) &lt; 0) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    switch(codecCtx-&gt;codec_type) {   case AVMEDIA_TYPE_AUDIO:     is-&gt;audioStream = stream_index;     is-&gt;audio_st = pFormatCtx-&gt;streams[stream_index];     is-&gt;audio_ctx = codecCtx;     is-&gt;audio_buf_size = 0;     is-&gt;audio_buf_index = 0;     memset(&amp;is-&gt;audio_pkt, 0, sizeof(is-&gt;audio_pkt));     packet_queue_init(&amp;is-&gt;audioq);     SDL_PauseAudio(0);     break;   case AVMEDIA_TYPE_VIDEO:     is-&gt;videoStream = stream_index;     is-&gt;video_st = pFormatCtx-&gt;streams[stream_index];     is-&gt;video_ctx = codecCtx;          packet_queue_init(&amp;is-&gt;videoq);     is-&gt;video_tid = SDL_CreateThread(video_thread, is);     is-&gt;sws_ctx = sws_getContext(is-&gt;video_st-&gt;codec-&gt;width, is-&gt;video_st-&gt;codec-&gt;height, \t\t\t\t is-&gt;video_st-&gt;codec-&gt;pix_fmt, is-&gt;video_st-&gt;codec-&gt;width, \t\t\t\t is-&gt;video_st-&gt;codec-&gt;height, PIX_FMT_YUV420P, \t\t\t\t SWS_BILINEAR, NULL, NULL, NULL \t\t\t\t );     break;   default:     break;   } }<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0443 \u043d\u0430\u0441 \u0440\u0430\u043d\u044c\u0448\u0435, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u043e\u0431\u043e\u0431\u0449\u0451\u043d \u0434\u043b\u044f \u0430\u0443\u0434\u0438\u043e \u0438 \u0432\u0438\u0434\u0435\u043e. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e<b> aCodecCtx<\/b> \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0430\u0448\u0443 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0437\u0432\u0443\u043a\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 \u0441\u0430\u043c\u0438 \u043f\u043e\u0442\u043e\u043a\u0438 \u043a\u0430\u043a <b>audio_st<\/b> \u0438 <b>video_st<\/b>. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043d\u0430\u0448\u0443 \u0432\u0438\u0434\u0435\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u0435\u0435 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u043d\u0430\u0448\u0443 \u0430\u0443\u0434\u0438\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0421\u0443\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0438 \u0430\u0443\u0434\u0438\u043e\u043f\u043e\u0442\u043e\u043a\u0438. \u042d\u0442\u0438 \u0431\u0438\u0442\u044b \u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u044d\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">    SDL_PauseAudio(0);     break;  \/* ...... *\/      is-&gt;video_tid = SDL_CreateThread(video_thread, is);<\/code><\/pre>\n<p>  \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c <b>SDL_PauseAudio<\/b>() \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430. <b>SDL_CreateThread<\/b>() \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>video_thread<\/b>().<\/p>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0435 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>decode_thread<\/b>(). \u041f\u043e \u0441\u0443\u0442\u0438, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0446\u0438\u043a\u043b for, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u043d\u0443\u0436\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c:<\/p>\n<pre><code class=\"cpp\">  for(;;) {     if(is-&gt;quit) {       break;     }     \/\/ seek stuff goes here     if(is-&gt;audioq.size &gt; MAX_AUDIOQ_SIZE ||        is-&gt;videoq.size &gt; MAX_VIDEOQ_SIZE) {       SDL_Delay(10);       continue;     }     if(av_read_frame(is-&gt;pFormatCtx, packet) &lt; 0) {       if((is-&gt;pFormatCtx-&gt;pb-&gt;error) == 0) { \tSDL_Delay(100); \/* no error; wait for user input *\/ \tcontinue;       } else { \tbreak;       }     }     \/\/ Is this a packet from the video stream?     if(packet-&gt;stream_index == is-&gt;videoStream) {       packet_queue_put(&amp;is-&gt;videoq, packet);     } else if(packet-&gt;stream_index == is-&gt;audioStream) {       packet_queue_put(&amp;is-&gt;audioq, packet);     } else {       av_free_packet(packet);     }   }<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0430\u0443\u0434\u0438\u043e- \u0438 \u0432\u0438\u0434\u0435\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0447\u0442\u0435\u043d\u0438\u044f. \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 \u0438\u043c\u0435\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <b>ByteIOContext<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <b>pb<\/b>. <b>ByteIOContext<\/b> \u2014 \u044d\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0444\u0430\u0439\u043b\u0430\u0445 \u043d\u0438\u0437\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0446\u0438\u043a\u043b\u0430 for \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431 \u044d\u0442\u043e\u043c. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u043e\u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043d, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u043c\u044b \u043f\u0440\u043e\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u2014 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u043e\u0437\u0436\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0432\u0438\u0434\u0435\u043e:<\/p>\n<pre><code class=\"cpp\">  while(!is-&gt;quit) {     SDL_Delay(100);   }   fail:   if(1){     SDL_Event event;     event.type = FF_QUIT_EVENT;     event.user.data1 = is;     SDL_PushEvent(&amp;event);   }   return 0;<\/code><\/pre>\n<p>  \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 SDL <b>SDL_USEREVENT<\/b>. \u041f\u0435\u0440\u0432\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>SDL_USEREVENT<\/b>, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 <nobr><b>SDL_USEREVENT<\/b> + 1<\/nobr> \u0438 \u0442.\u0434. <b>FF_QUIT_EVENT<\/b> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043a\u0430\u043a <nobr><b>SDL_USEREVENT<\/b> + 1<\/nobr>. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u0438 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043d\u0430\u0448 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>SDL_PushEvent<\/b>(). \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u0435\u043b\u0435 \u0446\u0438\u043a\u043b\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u044d\u0442\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b <b>SDL_QUIT_EVENT<\/b>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0440\u0430\u043d\u044c\u0448\u0435. \u041c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448 \u0446\u0438\u043a\u043b \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e; \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u0443\u0434\u044c\u0442\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0436\u043c\u0451\u043c <b>FF_QUIT_EVENT<\/b>, \u043c\u044b \u0441\u043b\u043e\u0432\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0437\u0436\u0435 \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u043c \u0444\u043b\u0430\u0433 \u0432\u044b\u0445\u043e\u0434\u0430.<\/p>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0434\u0440\u0430: video_thread<\/h3>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u043a\u043e\u0434\u0435\u043a, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0443. \u042d\u0442\u043e\u0442 \u043f\u043e\u0442\u043e\u043a \u0447\u0438\u0442\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442\u044b \u0438\u0437 \u0432\u0438\u0434\u0435\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442 \u0432\u0438\u0434\u0435\u043e \u0432 \u043a\u0430\u0434\u0440\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>queue_picture<\/b> \u0434\u043b\u044f \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">int video_thread(void *arg) {   VideoState *is = (VideoState *)arg;   AVPacket pkt1, *packet = &amp;pkt1;   int frameFinished;   AVFrame *pFrame;    pFrame = av_frame_alloc();    for(;;) {     if(packet_queue_get(&amp;is-&gt;videoq, packet, 1) &lt; 0) {       \/\/ means we quit getting packets       break;     }     \/\/ Decode video frame     avcodec_decode_video2(is-&gt;video_st-&gt;codec, pFrame, &amp;frameFinished, packet);      \/\/ Did we get a video frame?     if(frameFinished) {       if(queue_picture(is, pFrame) &lt; 0) { \tbreak;       }     }     av_free_packet(packet);   }   av_free(pFrame);   return 0; }<\/code><\/pre>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u0430 \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443. \u041c\u044b \u0441\u044e\u0434\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>avcodec_decode_video2<\/b>, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b; \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c <b>AVStream<\/b>, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434\u0435\u043a \u043e\u0442\u0442\u0443\u0434\u0430. \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u0432\u0438\u0434\u0435\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0435 \u0441\u043a\u0430\u0436\u0435\u0442 \u043d\u0430\u043c \u0432\u044b\u0439\u0442\u0438 \u0438\u043b\u0438 \u043c\u044b \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<h3>\u041a\u0430\u0434\u0440 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438<\/h3>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442 \u043d\u0430\u0448 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u0434\u0440 <b>pFrame<\/b> \u0432 \u043d\u0430\u0448\u0435\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0435 SDL (\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0435\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439), \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u0430\u0434\u0440 \u0432 \u043d\u0435\u0451. \u0414\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0436\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u043b\u0438:<\/p>\n<pre><code class=\"cpp\">typedef struct VideoPicture {   SDL_Overlay *bmp;   int width, height; \/* source height &amp; width *\/   int allocated; } VideoPicture;<\/code><\/pre>\n<p>  \u041d\u0430\u0448\u0430 \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u0443\u0444\u0435\u0440 \u044d\u0442\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0445 \u0445\u0440\u0430\u043d\u0438\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <b>SDL_Overlay<\/b> \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0444\u043b\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043b\u0438 \u043c\u044b \u044d\u0442\u043e \u0438\u043b\u0438 \u043d\u0435\u0442).<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u2014 \u0438\u043d\u0434\u0435\u043a\u0441 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u0447\u0442\u0435\u043d\u0438\u044f. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0431\u0443\u0444\u0435\u0440\u0435. \u0414\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043e\u0436\u0434\u0435\u043c, \u043f\u043e\u043a\u0430 \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u0441\u044f \u043d\u0430\u0448 \u0431\u0443\u0444\u0435\u0440, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u043c\u0435\u0441\u0442\u043e \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e <b>VideoPicture<\/b>. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u2014 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 \u043b\u0438 \u043c\u044b \u0436\u0435 \u043d\u0430\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0448\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438? \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0431\u0443\u0444\u0435\u0440, \u0435\u0441\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f!<\/p>\n<pre><code class=\"cpp\">int queue_picture(VideoState *is, AVFrame *pFrame) {    VideoPicture *vp;   int dst_pix_fmt;   AVPicture pict;    \/* wait until we have space for a new pic *\/   SDL_LockMutex(is-&gt;pictq_mutex);   while(is-&gt;pictq_size &gt;= VIDEO_PICTURE_QUEUE_SIZE &amp;&amp; \t!is-&gt;quit) {     SDL_CondWait(is-&gt;pictq_cond, is-&gt;pictq_mutex);   }   SDL_UnlockMutex(is-&gt;pictq_mutex);    if(is-&gt;quit)     return -1;    \/\/ windex is set to 0 initially   vp = &amp;is-&gt;pictq[is-&gt;pictq_windex];    \/* allocate or resize the buffer! *\/   if(!vp-&gt;bmp ||      vp-&gt;width != is-&gt;video_st-&gt;codec-&gt;width ||      vp-&gt;height != is-&gt;video_st-&gt;codec-&gt;height) {     SDL_Event event;      vp-&gt;allocated = 0;     alloc_picture(is);     if(is-&gt;quit) {       return -1;     }   }<\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>alloc_picture<\/b>():<\/p>\n<pre><code class=\"cpp\">void alloc_picture(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;    vp = &amp;is-&gt;pictq[is-&gt;pictq_windex];   if(vp-&gt;bmp) {     \/\/ we already have one make another, bigger\/smaller     SDL_FreeYUVOverlay(vp-&gt;bmp);   }   \/\/ Allocate a place to put our YUV image on that screen   SDL_LockMutex(screen_mutex);   vp-&gt;bmp = SDL_CreateYUVOverlay(is-&gt;video_st-&gt;codec-&gt;width, \t\t\t\t is-&gt;video_st-&gt;codec-&gt;height, \t\t\t\t SDL_YV12_OVERLAY, \t\t\t\t screen);   SDL_UnlockMutex(screen_mutex);   vp-&gt;width = is-&gt;video_st-&gt;codec-&gt;width;   vp-&gt;height = is-&gt;video_st-&gt;codec-&gt;height;     vp-&gt;allocated = 1; }<\/code><\/pre>\n<p>  \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>SDL_CreateYUVOverlay<\/b>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u043b\u0438 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043a \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u0432\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d! \u042d\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>alloc_picture<\/b> \u043f\u043e\u043c\u0435\u0448\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443. (\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u044d\u0442\u0443 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u043a\u0430\u043a \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0435\u0435 \u0432 <b>main<\/b>(); \u0441\u043c. \u043a\u043e\u0434.) \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0448\u0438\u0440\u0438\u043d\u0443 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <b>VideoPicture<\/b>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u0435.<br \/>  \u0425\u043e\u0440\u043e\u0448\u043e, \u043c\u044b \u0432\u0441\u0435 \u0443\u043b\u0430\u0434\u0438\u043b\u0438, \u0438 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430\u0448 \u043e\u0432\u0435\u0440\u043b\u0435\u0439 <b>YUV<\/b>, \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a <b>queue_picture<\/b> \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0434\u0440 \u0432 \u043e\u0432\u0435\u0440\u043b\u0435\u0439. \u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0432\u0430\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0430:<\/p>\n<pre><code class=\"cpp\">int queue_picture(VideoState *is, AVFrame *pFrame) {    \/* Allocate a frame if we need it... *\/   \/* ... *\/   \/* We have a place to put our picture on the queue *\/    if(vp-&gt;bmp) {      SDL_LockYUVOverlay(vp-&gt;bmp);          dst_pix_fmt = PIX_FMT_YUV420P;     \/* point pict at the queue *\/      pict.data[0] = vp-&gt;bmp-&gt;pixels[0];     pict.data[1] = vp-&gt;bmp-&gt;pixels[2];     pict.data[2] = vp-&gt;bmp-&gt;pixels[1];          pict.linesize[0] = vp-&gt;bmp-&gt;pitches[0];     pict.linesize[1] = vp-&gt;bmp-&gt;pitches[2];     pict.linesize[2] = vp-&gt;bmp-&gt;pitches[1];          \/\/ Convert the image into YUV format that SDL uses     sws_scale(is-&gt;sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t      pFrame-&gt;linesize, 0, is-&gt;video_st-&gt;codec-&gt;height, \t      pict.data, pict.linesize);          SDL_UnlockYUVOverlay(vp-&gt;bmp);     \/* now we inform our display thread that we have a pic ready *\/     if(++is-&gt;pictq_windex == VIDEO_PICTURE_QUEUE_SIZE) {       is-&gt;pictq_windex = 0;     }     SDL_LockMutex(is-&gt;pictq_mutex);     is-&gt;pictq_size++;     SDL_UnlockMutex(is-&gt;pictq_mutex);   }   return 0; }<\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0432\u0435\u0440\u043b\u0435\u0439 <b>YUV<\/b> \u043d\u0430\u0448\u0438\u043c \u0444\u0440\u0435\u0439\u043c\u043e\u043c. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0431\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u00ab\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u00bb \u043d\u0430\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u041e\u0447\u0435\u0440\u0435\u0434\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043d\u0435\u0451 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043e\u043d\u0430 \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f, \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 \u043d\u0435\u0451 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u043a\u0430 \u0432 \u043d\u0435\u0439 \u0445\u043e\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0435\u0441\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <nobr><b>is<\/b>-&gt;<b>pictq_size<\/b><\/nobr>, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0442 \u043d\u0430\u0441 \u0435\u0433\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438. \u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0434\u0435\u0441\u044c: \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043f\u0438\u0441\u0438 (\u0430 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0437\u0430\u043d\u043e\u0432\u043e), \u0437\u0430\u0442\u0435\u043c \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0435\u0451 \u0440\u0430\u0437\u043c\u0435\u0440. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0438 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0430\u0448\u0443 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0439, \u0438 \u043d\u0430\u0448 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0437\u043d\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c.<\/p>\n<h3>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0435\u043e<\/h3>\n<p>  \u0412\u043e\u0442 \u0438 \u0432\u0441\u0451 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043e\u0442\u0440\u0435\u0434\u0430! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0438 \u0432\u0441\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0435 \u0442\u0440\u0435\u0434\u044b, \u043a\u0440\u043e\u043c\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u2014 \u043f\u0440\u0438\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u043c\u044b \u0434\u0430\u0432\u043d\u044b\u043c-\u0434\u0430\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>schedule_refresh<\/b>()? \u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e:<\/p>\n<pre><code class=\"cpp\">\/* schedule a video refresh in 'delay' ms *\/ static void schedule_refresh(VideoState *is, int delay) {   SDL_AddTimer(delay, sdl_refresh_timer_cb, is); }<\/code><\/pre>\n<p>  <b>SDL_AddTimer<\/b>() \u2014 \u044d\u0442\u043e SDL-\u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0430\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434 (\u0438, \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e, \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435). \u0411\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u0432\u0438\u0434\u0435\u043e \u2014 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0435\u0451 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c, \u043e\u043d\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>main<\/b>() \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u043a\u0430\u0434\u0440 \u0438\u0437 \u043d\u0430\u0448\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0435\u0435! \u0423\u0444! \u0422\u0440\u0438 \u00ab\u043a\u043e\u0442\u043e\u0440\u044b\u0439\/\u043a\u043e\u0442\u043e\u0440\u043e\u0435\/\u043a\u043e\u0442\u043e\u0440\u0430\u044f\u00bb \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438! \u0418\u0442\u0430\u043a, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0434\u0430\u043d\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u042d\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u043a:<\/p>\n<pre><code class=\"cpp\">static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque) {   SDL_Event event;   event.type = FF_REFRESH_EVENT;   event.user.data1 = opaque;   SDL_PushEvent(&amp;event);   return 0; \/* 0 means stop timer *\/ }<\/code><\/pre>\n<p>  \u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u0430\u0448 \u0441\u0442\u0430\u0440\u044b\u0439 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439. <b>FF_REFRESH_EVENT<\/b> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0434\u0435\u0441\u044c \u043a\u0430\u043a <nobr><b>SDL_USEREVENT<\/b> + 1<\/nobr>. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 0, SDL \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043c\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u043d\u043e\u0432\u0430.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0432\u043d\u043e\u0432\u044c \u043f\u0440\u0438\u0437\u0432\u0430\u043b\u0438 <b>FF_REFRESH_EVENT<\/b>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0446\u0438\u043a\u043b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">for(;;) {    SDL_WaitEvent(&amp;event);   switch(event.type) {   \/* ... *\/   case FF_REFRESH_EVENT:     video_refresh_timer(event.user.data1);     break;<\/code><\/pre>\n<p>  \u0447\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0441 \u0432\u043e\u0442 \u043a \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">void video_refresh_timer(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;      if(is-&gt;video_st) {     if(is-&gt;pictq_size == 0) {       schedule_refresh(is, 1);     } else {       vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];       \/* Timing code goes here *\/        schedule_refresh(is, 80);              \/* show the picture! *\/       video_display(is);              \/* update queue for next picture! *\/       if(++is-&gt;pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { \tis-&gt;pictq_rindex = 0;       }       SDL_LockMutex(is-&gt;pictq_mutex);       is-&gt;pictq_size--;       SDL_CondSignal(is-&gt;pictq_cond);       SDL_UnlockMutex(is-&gt;pictq_mutex);     }   } else {     schedule_refresh(is, 100);   } }<\/code><\/pre>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e-\u0442\u0430\u043a\u0438 \u043f\u0440\u043e\u0441\u0442\u0430: \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u0447\u0442\u043e-\u0442\u043e \u0435\u0441\u0442\u044c, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0442\u0430\u0439\u043c\u0435\u0440 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0434\u0440\u0430, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <b>video_display<\/b>, \u0447\u0442\u043e\u0431\u044b \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435, \u0437\u0430\u0442\u0435\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u043d\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0451 \u0440\u0430\u0437\u043c\u0435\u0440. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0441 <b>vp<\/b> \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0438 \u0432\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443: \u044d\u0442\u043e \u0432\u043f\u0435\u0440\u0435\u0434\u0438. \u041d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0436\u0435. \u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0447\u043d\u0451\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u0430\u0443\u0434\u0438\u043e. \u0412\u043e\u0442, \u0432\u0437\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u043d\u0430 \u0442\u043e \u043c\u0435\u0441\u0442\u043e \u043a\u043e\u0434\u0430, \u0433\u0434\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u00ab\u041a\u043e\u0434 \u0442\u0430\u0439\u043c\u0438\u043d\u0433\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0442\u0443\u0442\u00bb (\u00abTiming code goes here\u00bb). \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0441\u043a\u043e\u0440\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0434\u0440, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u0432\u0435\u0441\u0442\u0438 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>schedule_refresh<\/b>(). \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0432\u043e\u0434\u0438\u043c \u0444\u0438\u043a\u0442\u0438\u0432\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 80. \u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u0443\u0433\u0430\u0434\u0430\u0442\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0438 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0438\u043b\u044c\u043c\u0430, \u043d\u043e: 1) \u043d\u0430\u0447\u043d\u0451\u0442 \u0442\u043e\u0440\u043c\u043e\u0437\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 2) \u044d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u043b\u0443\u043f\u043e. \u0425\u043e\u0442\u044f, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0435\u0449\u0451 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443.<\/p>\n<p>  \u041c\u044b \u043f\u043e\u0447\u0442\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e: \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e! \u0412\u043e\u0442 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>video_display<\/b>:<\/p>\n<pre><code class=\"cpp\">void video_display(VideoState *is) {    SDL_Rect rect;   VideoPicture *vp;   float aspect_ratio;   int w, h, x, y;   int i;    vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];   if(vp-&gt;bmp) {     if(is-&gt;video_st-&gt;codec-&gt;sample_aspect_ratio.num == 0) {       aspect_ratio = 0;     } else {       aspect_ratio = av_q2d(is-&gt;video_st-&gt;codec-&gt;sample_aspect_ratio) * \tis-&gt;video_st-&gt;codec-&gt;width \/ is-&gt;video_st-&gt;codec-&gt;height;     }     if(aspect_ratio &lt;= 0.0) {       aspect_ratio = (float)is-&gt;video_st-&gt;codec-&gt;width \/ \t(float)is-&gt;video_st-&gt;codec-&gt;height;     }     h = screen-&gt;h;     w = ((int)rint(h * aspect_ratio)) &amp; -3;     if(w &gt; screen-&gt;w) {       w = screen-&gt;w;       h = ((int)rint(w \/ aspect_ratio)) &amp; -3;     }     x = (screen-&gt;w - w) \/ 2;     y = (screen-&gt;h - h) \/ 2;          rect.x = x;     rect.y = y;     rect.w = w;     rect.h = h;     SDL_LockMutex(screen_mutex);     SDL_DisplayYUVOverlay(vp-&gt;bmp, &amp;rect);     SDL_UnlockMutex(screen_mutex);   } }<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u043a\u0440\u0430\u043d \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (\u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438 640&#215;480, \u0438 \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u043b \u0440\u0430\u0437\u043c\u0435\u0440\u044b), \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0443\u0433\u043e\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0438\u043b\u044c\u043c\u0430. \u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0434\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0438\u043b\u044c\u043c\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0448\u0438\u0440\u0438\u043d\u0430, \u0440\u0430\u0437\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f \u043d\u0430 \u0432\u044b\u0441\u043e\u0442\u0443. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u0434\u0435\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0447\u0451\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0448\u0438\u0440\u0438\u043d\u0443\/\u0432\u044b\u0441\u043e\u0442\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f \u0438\u043b\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u044b\u0441\u043e\u0442\u044b \u0438 \u0448\u0438\u0440\u0438\u043d\u044b \u0432 \u043d\u0430\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u0434\u0435\u043a\u0430 \u0438\u0437\u043c\u0435\u0440\u044f\u044e\u0442\u0441\u044f \u0432 \u043f\u0438\u043a\u0441\u0435\u043b\u044f\u0445, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d \u0440\u0430\u0432\u043d\u043e \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u0441\u0442\u043e\u0440\u043e\u043d, \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u043d\u043e\u043c\u0443 \u043d\u0430 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u0434\u0435\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d 0, \u0438 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 1&#215;1. \u0417\u0430\u0442\u0435\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c \u0444\u0438\u043b\u044c\u043c \u0442\u0430\u043a\u0438\u043c \u043c\u0430\u043a\u0430\u0440\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u0449\u0430\u043b\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u0411\u0438\u0442\u043e\u0432\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 <nobr><b>&amp; -3<\/b><\/nobr> \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043e \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e, \u043a\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0447\u0435\u0442\u044b\u0440\u0451\u043c. \u0417\u0430\u0442\u0435\u043c \u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0438\u043b\u044c\u043c \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <b>SDL_DisplayYUVOverlay<\/b>(), \u0434\u0430\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u044d\u043a\u0440\u0430\u043d\u043d\u044b\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043d\u0435\u043c\u0443.<\/p>\n<p>  \u0418 \u044d\u0442\u043e \u0432\u0441\u0435? \u041c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438? \u0412\u0441\u0451 \u0435\u0449\u0451 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 <b>VideoStruct<\/b>, \u043d\u043e \u044d\u0442\u043e \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430\u0448 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u00ab\u0432\u044b\u0445\u043e\u0434\u00bb \u0432 FFmpeg:<\/p>\n<pre><code class=\"cpp\">VideoState *global_video_state;  int decode_interrupt_cb(void) {   return (global_video_state &amp;&amp; global_video_state-&gt;quit); }<\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <b>global_video_state<\/b> \u0432 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 <b>main<\/b>().<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u044d\u0442\u043e \u0432\u0441\u0451! \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code class=\"bash\">gcc -o tutorial04 tutorial04.c -lavutil -lavformat -lavcodec -lswscale -lz -lm \\ `sdl-config --cflags --libs`<\/code><\/pre>\n<p>  \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0439\u0442\u0435\u0441\u044c \u0444\u0438\u043b\u044c\u043c\u043e\u043c \u0431\u0435\u0437 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438! \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c <i>\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439<\/i> \u0432\u0438\u0434\u0435\u043e\u043f\u043b\u0435\u0435\u0440!<\/p>\n<p>  <a name=\"video\"><\/a><\/p>\n<h2>\u0423\u0440\u043e\u043a 5: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0438\u0434\u0435\u043e <a href=\"#menu\">\u2191<\/a><\/h2>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u043b\u043d\u044b\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 tutorial05.c<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">\/\/ tutorial05.c \/\/ A pedagogical video player that really works! \/\/ \/\/ Code based on FFplay, Copyright (c) 2003 Fabrice Bellard,  \/\/ and a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de) \/\/ Tested on Gentoo, CVS version 5\/01\/07 compiled with GCC 4.1.1 \/\/ With updates from https:\/\/github.com\/chelyaev\/ffmpeg-tutorial \/\/ Updates tested on: \/\/ LAVC 54.59.100, LAVF 54.29.104, LSWS 2.1.101, SDL 1.2.15 \/\/ on GCC 4.7.2 in Debian February 2015 \/\/ Use \/\/ \/\/ gcc -o tutorial05 tutorial05.c -lavformat -lavcodec -lswscale -lz -lm `sdl-config --cflags --libs` \/\/ to build (assuming libavformat and libavcodec are correctly installed,  \/\/ and assuming you have sdl-config. Please refer to SDL docs for your installation.) \/\/ \/\/ Run using \/\/ tutorial04 myvideofile.mpg \/\/ \/\/ to play the video stream on your screen.  #include &lt;libavcodec\/avcodec.h&gt; #include &lt;libavformat\/avformat.h&gt; #include &lt;libswscale\/swscale.h&gt;  #include &lt;SDL.h&gt; #include &lt;SDL_thread.h&gt;  #ifdef __MINGW32__ #undef main \/* Prevents SDL from overriding main() *\/ #endif  #include &lt;stdio.h&gt; #include &lt;assert.h&gt; #include &lt;math.h&gt;  \/\/ compatibility with newer API #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55,28,1) #define av_frame_alloc avcodec_alloc_frame #define av_frame_free avcodec_free_frame #endif  #define SDL_AUDIO_BUFFER_SIZE 1024 #define MAX_AUDIO_FRAME_SIZE 192000  #define MAX_AUDIOQ_SIZE (5 * 16 * 1024) #define MAX_VIDEOQ_SIZE (5 * 256 * 1024)  #define AV_SYNC_THRESHOLD 0.01 #define AV_NOSYNC_THRESHOLD 10.0  #define FF_REFRESH_EVENT (SDL_USEREVENT) #define FF_QUIT_EVENT (SDL_USEREVENT + 1)  #define VIDEO_PICTURE_QUEUE_SIZE 1  typedef struct PacketQueue {   AVPacketList *first_pkt, *last_pkt;   int nb_packets;   int size;   SDL_mutex *mutex;   SDL_cond *cond; } PacketQueue;   typedef struct VideoPicture {   SDL_Overlay *bmp;   int width, height; \/* source height &amp; width *\/   int allocated;   double pts; } VideoPicture;  typedef struct VideoState {    AVFormatContext *pFormatCtx;   int             videoStream, audioStream;    double          audio_clock;   AVStream        *audio_st;   AVCodecContext  *audio_ctx;   PacketQueue     audioq;   uint8_t         audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) \/ 2];   unsigned int    audio_buf_size;   unsigned int    audio_buf_index;   AVFrame         audio_frame;   AVPacket        audio_pkt;   uint8_t         *audio_pkt_data;   int             audio_pkt_size;   int             audio_hw_buf_size;     double          frame_timer;   double          frame_last_pts;   double          frame_last_delay;   double          video_clock; \/\/\/&lt;pts of last decoded frame \/ predicted pts of next decoded frame   AVStream        *video_st;   AVCodecContext  *video_ctx;   PacketQueue     videoq;   struct SwsContext *sws_ctx;    VideoPicture    pictq[VIDEO_PICTURE_QUEUE_SIZE];   int             pictq_size, pictq_rindex, pictq_windex;   SDL_mutex       *pictq_mutex;   SDL_cond        *pictq_cond;      SDL_Thread      *parse_tid;   SDL_Thread      *video_tid;    char            filename[1024];   int             quit; } VideoState;  SDL_Surface     *screen; SDL_mutex       *screen_mutex;  \/* Since we only have one decoding thread, the Big Struct    can be global in case we need it. *\/ VideoState *global_video_state;  void packet_queue_init(PacketQueue *q) {   memset(q, 0, sizeof(PacketQueue));   q-&gt;mutex = SDL_CreateMutex();   q-&gt;cond = SDL_CreateCond(); } int packet_queue_put(PacketQueue *q, AVPacket *pkt) {    AVPacketList *pkt1;   if(av_dup_packet(pkt) &lt; 0) {     return -1;   }   pkt1 = av_malloc(sizeof(AVPacketList));   if (!pkt1)     return -1;   pkt1-&gt;pkt = *pkt;   pkt1-&gt;next = NULL;      SDL_LockMutex(q-&gt;mutex);    if (!q-&gt;last_pkt)     q-&gt;first_pkt = pkt1;   else     q-&gt;last_pkt-&gt;next = pkt1;   q-&gt;last_pkt = pkt1;   q-&gt;nb_packets++;   q-&gt;size += pkt1-&gt;pkt.size;   SDL_CondSignal(q-&gt;cond);      SDL_UnlockMutex(q-&gt;mutex);   return 0; } static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) {   AVPacketList *pkt1;   int ret;    SDL_LockMutex(q-&gt;mutex);      for(;;) {          if(global_video_state-&gt;quit) {       ret = -1;       break;     }      pkt1 = q-&gt;first_pkt;     if (pkt1) {       q-&gt;first_pkt = pkt1-&gt;next;       if (!q-&gt;first_pkt) \tq-&gt;last_pkt = NULL;       q-&gt;nb_packets--;       q-&gt;size -= pkt1-&gt;pkt.size;       *pkt = pkt1-&gt;pkt;       av_free(pkt1);       ret = 1;       break;     } else if (!block) {       ret = 0;       break;     } else {       SDL_CondWait(q-&gt;cond, q-&gt;mutex);     }   }   SDL_UnlockMutex(q-&gt;mutex);   return ret; }  double get_audio_clock(VideoState *is) {   double pts;   int hw_buf_size, bytes_per_sec, n;      pts = is-&gt;audio_clock; \/* maintained in the audio thread *\/   hw_buf_size = is-&gt;audio_buf_size - is-&gt;audio_buf_index;   bytes_per_sec = 0;   n = is-&gt;audio_ctx-&gt;channels * 2;   if(is-&gt;audio_st) {     bytes_per_sec = is-&gt;audio_ctx-&gt;sample_rate * n;   }   if(bytes_per_sec) {     pts -= (double)hw_buf_size \/ bytes_per_sec;   }   return pts; }  int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int buf_size, double *pts_ptr) {    int len1, data_size = 0;   AVPacket *pkt = &amp;is-&gt;audio_pkt;   double pts;   int n;    for(;;) {     while(is-&gt;audio_pkt_size &gt; 0) {       int got_frame = 0;       len1 = avcodec_decode_audio4(is-&gt;audio_ctx, &amp;is-&gt;audio_frame, &amp;got_frame, pkt);       if(len1 &lt; 0) { \t\/* if error, skip frame *\/ \tis-&gt;audio_pkt_size = 0; \tbreak;       }       data_size = 0;       if(got_frame) { \tdata_size = av_samples_get_buffer_size(NULL,  \t\t\t\t\t       is-&gt;audio_ctx-&gt;channels, \t\t\t\t\t       is-&gt;audio_frame.nb_samples, \t\t\t\t\t       is-&gt;audio_ctx-&gt;sample_fmt, \t\t\t\t\t       1); \tassert(data_size &lt;= buf_size); \tmemcpy(audio_buf, is-&gt;audio_frame.data[0], data_size);       }       is-&gt;audio_pkt_data += len1;       is-&gt;audio_pkt_size -= len1;       if(data_size &lt;= 0) { \t\/* No data yet, get more frames *\/ \tcontinue;       }       pts = is-&gt;audio_clock;       *pts_ptr = pts;       n = 2 * is-&gt;audio_ctx-&gt;channels;       is-&gt;audio_clock += (double)data_size \/ \t(double)(n * is-&gt;audio_ctx-&gt;sample_rate);       \/* We have data, return it and come back for more later *\/       return data_size;     }     if(pkt-&gt;data)       av_free_packet(pkt);      if(is-&gt;quit) {       return -1;     }     \/* next packet *\/     if(packet_queue_get(&amp;is-&gt;audioq, pkt, 1) &lt; 0) {       return -1;     }     is-&gt;audio_pkt_data = pkt-&gt;data;     is-&gt;audio_pkt_size = pkt-&gt;size;     \/* if update, update the audio clock w\/pts *\/     if(pkt-&gt;pts != AV_NOPTS_VALUE) {       is-&gt;audio_clock = av_q2d(is-&gt;audio_st-&gt;time_base)*pkt-&gt;pts;     }   } }  void audio_callback(void *userdata, Uint8 *stream, int len) {    VideoState *is = (VideoState *)userdata;   int len1, audio_size;   double pts;    while(len &gt; 0) {     if(is-&gt;audio_buf_index &gt;= is-&gt;audio_buf_size) {       \/* We have already sent all our data; get more *\/       audio_size = audio_decode_frame(is, is-&gt;audio_buf, sizeof(is-&gt;audio_buf), &amp;pts);       if(audio_size &lt; 0) { \t\/* If error, output silence *\/ \tis-&gt;audio_buf_size = 1024; \tmemset(is-&gt;audio_buf, 0, is-&gt;audio_buf_size);       } else { \tis-&gt;audio_buf_size = audio_size;       }       is-&gt;audio_buf_index = 0;     }     len1 = is-&gt;audio_buf_size - is-&gt;audio_buf_index;     if(len1 &gt; len)       len1 = len;     memcpy(stream, (uint8_t *)is-&gt;audio_buf + is-&gt;audio_buf_index, len1);     len -= len1;     stream += len1;     is-&gt;audio_buf_index += len1;   } }  static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque) {   SDL_Event event;   event.type = FF_REFRESH_EVENT;   event.user.data1 = opaque;   SDL_PushEvent(&amp;event);   return 0; \/* 0 means stop timer *\/ }  \/* schedule a video refresh in 'delay' ms *\/ static void schedule_refresh(VideoState *is, int delay) {   SDL_AddTimer(delay, sdl_refresh_timer_cb, is); }  void video_display(VideoState *is) {    SDL_Rect rect;   VideoPicture *vp;   float aspect_ratio;   int w, h, x, y;   int i;    vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];   if(vp-&gt;bmp) {     if(is-&gt;video_ctx-&gt;sample_aspect_ratio.num == 0) {       aspect_ratio = 0;     } else {       aspect_ratio = av_q2d(is-&gt;video_ctx-&gt;sample_aspect_ratio) * \tis-&gt;video_ctx-&gt;width \/ is-&gt;video_ctx-&gt;height;     }     if(aspect_ratio &lt;= 0.0) {       aspect_ratio = (float)is-&gt;video_ctx-&gt;width \/ \t(float)is-&gt;video_ctx-&gt;height;     }     h = screen-&gt;h;     w = ((int)rint(h * aspect_ratio)) &amp; -3;     if(w &gt; screen-&gt;w) {       w = screen-&gt;w;       h = ((int)rint(w \/ aspect_ratio)) &amp; -3;     }     x = (screen-&gt;w - w) \/ 2;     y = (screen-&gt;h - h) \/ 2;          rect.x = x;     rect.y = y;     rect.w = w;     rect.h = h;     SDL_LockMutex(screen_mutex);     SDL_DisplayYUVOverlay(vp-&gt;bmp, &amp;rect);     SDL_UnlockMutex(screen_mutex);    } }  void video_refresh_timer(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;   double actual_delay, delay, sync_threshold, ref_clock, diff;      if(is-&gt;video_st) {     if(is-&gt;pictq_size == 0) {       schedule_refresh(is, 1);     } else {       vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];        delay = vp-&gt;pts - is-&gt;frame_last_pts; \/* the pts from last time *\/       if(delay &lt;= 0 || delay &gt;= 1.0) { \t\/* if incorrect delay, use previous one *\/ \tdelay = is-&gt;frame_last_delay;       }       \/* save for next time *\/       is-&gt;frame_last_delay = delay;       is-&gt;frame_last_pts = vp-&gt;pts;        \/* update delay to sync to audio *\/       ref_clock = get_audio_clock(is);       diff = vp-&gt;pts - ref_clock;        \/* Skip or repeat the frame. Take delay into account \t FFPlay still doesn't &quot;know if this is the best guess.&quot; *\/       sync_threshold = (delay &gt; AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD;       if(fabs(diff) &lt; AV_NOSYNC_THRESHOLD) { \tif(diff &lt;= -sync_threshold) { \t  delay = 0; \t} else if(diff &gt;= sync_threshold) { \t  delay = 2 * delay; \t}       }       is-&gt;frame_timer += delay;       \/* computer the REAL delay *\/       actual_delay = is-&gt;frame_timer - (av_gettime() \/ 1000000.0);       if(actual_delay &lt; 0.010) { \t\/* Really it should skip the picture instead *\/ \tactual_delay = 0.010;       }       schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));              \/* show the picture! *\/       video_display(is);              \/* update queue for next picture! *\/       if(++is-&gt;pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { \tis-&gt;pictq_rindex = 0;       }       SDL_LockMutex(is-&gt;pictq_mutex);       is-&gt;pictq_size--;       SDL_CondSignal(is-&gt;pictq_cond);       SDL_UnlockMutex(is-&gt;pictq_mutex);     }   } else {     schedule_refresh(is, 100);   } }        void alloc_picture(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;    vp = &amp;is-&gt;pictq[is-&gt;pictq_windex];   if(vp-&gt;bmp) {     \/\/ we already have one make another, bigger\/smaller     SDL_FreeYUVOverlay(vp-&gt;bmp);   }   \/\/ Allocate a place to put our YUV image on that screen   SDL_LockMutex(screen_mutex);   vp-&gt;bmp = SDL_CreateYUVOverlay(is-&gt;video_ctx-&gt;width, \t\t\t\t is-&gt;video_ctx-&gt;height, \t\t\t\t SDL_YV12_OVERLAY, \t\t\t\t screen);   SDL_UnlockMutex(screen_mutex);    vp-&gt;width = is-&gt;video_ctx-&gt;width;   vp-&gt;height = is-&gt;video_ctx-&gt;height;   vp-&gt;allocated = 1;  }  int queue_picture(VideoState *is, AVFrame *pFrame, double pts) {    VideoPicture *vp;   int dst_pix_fmt;   AVPicture pict;    \/* wait until we have space for a new pic *\/   SDL_LockMutex(is-&gt;pictq_mutex);   while(is-&gt;pictq_size &gt;= VIDEO_PICTURE_QUEUE_SIZE &amp;&amp; \t!is-&gt;quit) {     SDL_CondWait(is-&gt;pictq_cond, is-&gt;pictq_mutex);   }   SDL_UnlockMutex(is-&gt;pictq_mutex);    if(is-&gt;quit)     return -1;    \/\/ windex is set to 0 initially   vp = &amp;is-&gt;pictq[is-&gt;pictq_windex];    \/* allocate or resize the buffer! *\/   if(!vp-&gt;bmp ||      vp-&gt;width != is-&gt;video_ctx-&gt;width ||      vp-&gt;height != is-&gt;video_ctx-&gt;height) {     SDL_Event event;      vp-&gt;allocated = 0;     alloc_picture(is);     if(is-&gt;quit) {       return -1;     }   }    \/* We have a place to put our picture on the queue *\/    if(vp-&gt;bmp) {      SDL_LockYUVOverlay(vp-&gt;bmp);     vp-&gt;pts = pts;          dst_pix_fmt = PIX_FMT_YUV420P;     \/* point pict at the queue *\/      pict.data[0] = vp-&gt;bmp-&gt;pixels[0];     pict.data[1] = vp-&gt;bmp-&gt;pixels[2];     pict.data[2] = vp-&gt;bmp-&gt;pixels[1];          pict.linesize[0] = vp-&gt;bmp-&gt;pitches[0];     pict.linesize[1] = vp-&gt;bmp-&gt;pitches[2];     pict.linesize[2] = vp-&gt;bmp-&gt;pitches[1];          \/\/ Convert the image into YUV format that SDL uses     sws_scale(is-&gt;sws_ctx, (uint8_t const * const *)pFrame-&gt;data, \t      pFrame-&gt;linesize, 0, is-&gt;video_ctx-&gt;height, \t      pict.data, pict.linesize);          SDL_UnlockYUVOverlay(vp-&gt;bmp);     \/* now we inform our display thread that we have a pic ready *\/     if(++is-&gt;pictq_windex == VIDEO_PICTURE_QUEUE_SIZE) {       is-&gt;pictq_windex = 0;     }     SDL_LockMutex(is-&gt;pictq_mutex);     is-&gt;pictq_size++;     SDL_UnlockMutex(is-&gt;pictq_mutex);   }   return 0; }  double synchronize_video(VideoState *is, AVFrame *src_frame, double pts) {    double frame_delay;    if(pts != 0) {     \/* if we have pts, set video clock to it *\/     is-&gt;video_clock = pts;   } else {     \/* if we aren't given a pts, set it to the clock *\/     pts = is-&gt;video_clock;   }   \/* update the video clock *\/   frame_delay = av_q2d(is-&gt;video_ctx-&gt;time_base);   \/* if we are repeating a frame, adjust clock accordingly *\/   frame_delay += src_frame-&gt;repeat_pict * (frame_delay * 0.5);   is-&gt;video_clock += frame_delay;   return pts; }  int video_thread(void *arg) {   VideoState *is = (VideoState *)arg;   AVPacket pkt1, *packet = &amp;pkt1;   int frameFinished;   AVFrame *pFrame;   double pts;    pFrame = av_frame_alloc();    for(;;) {     if(packet_queue_get(&amp;is-&gt;videoq, packet, 1) &lt; 0) {       \/\/ means we quit getting packets       break;     }     if(packet_queue_get(&amp;is-&gt;videoq, packet, 1) &lt; 0) {       \/\/ means we quit getting packets       break;     }     pts = 0;      \/\/ Decode video frame     avcodec_decode_video2(is-&gt;video_ctx, pFrame, &amp;frameFinished, packet);      if((pts = av_frame_get_best_effort_timestamp(pFrame)) == AV_NOPTS_VALUE) {       pts = 0;     }     pts *= av_q2d(is-&gt;video_st-&gt;time_base);      \/\/ Did we get a video frame?     if(frameFinished) {       pts = synchronize_video(is, pFrame, pts);       if(queue_picture(is, pFrame, pts) &lt; 0) { \tbreak;       }     }     av_free_packet(packet);   }   av_frame_free(&amp;pFrame);   return 0; }  int stream_component_open(VideoState *is, int stream_index) {    AVFormatContext *pFormatCtx = is-&gt;pFormatCtx;   AVCodecContext *codecCtx = NULL;   AVCodec *codec = NULL;   SDL_AudioSpec wanted_spec, spec;    if(stream_index &lt; 0 || stream_index &gt;= pFormatCtx-&gt;nb_streams) {     return -1;   }    codec = avcodec_find_decoder(pFormatCtx-&gt;streams[stream_index]-&gt;codec-&gt;codec_id);   if(!codec) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    codecCtx = avcodec_alloc_context3(codec);   if(avcodec_copy_context(codecCtx, pFormatCtx-&gt;streams[stream_index]-&gt;codec) != 0) {     fprintf(stderr, &quot;Couldn't copy codec context&quot;);     return -1; \/\/ Error copying codec context   }     if(codecCtx-&gt;codec_type == AVMEDIA_TYPE_AUDIO) {     \/\/ Set audio settings from codec info     wanted_spec.freq = codecCtx-&gt;sample_rate;     wanted_spec.format = AUDIO_S16SYS;     wanted_spec.channels = codecCtx-&gt;channels;     wanted_spec.silence = 0;     wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;     wanted_spec.callback = audio_callback;     wanted_spec.userdata = is;          if(SDL_OpenAudio(&amp;wanted_spec, &amp;spec) &lt; 0) {       fprintf(stderr, &quot;SDL_OpenAudio: %s\\n&quot;, SDL_GetError());       return -1;     }     is-&gt;audio_hw_buf_size = spec.size;   }   if(avcodec_open2(codecCtx, codec, NULL) &lt; 0) {     fprintf(stderr, &quot;Unsupported codec!\\n&quot;);     return -1;   }    switch(codecCtx-&gt;codec_type) {   case AVMEDIA_TYPE_AUDIO:     is-&gt;audioStream = stream_index;     is-&gt;audio_st = pFormatCtx-&gt;streams[stream_index];     is-&gt;audio_ctx = codecCtx;     is-&gt;audio_buf_size = 0;     is-&gt;audio_buf_index = 0;     memset(&amp;is-&gt;audio_pkt, 0, sizeof(is-&gt;audio_pkt));     packet_queue_init(&amp;is-&gt;audioq);     SDL_PauseAudio(0);     break;   case AVMEDIA_TYPE_VIDEO:     is-&gt;videoStream = stream_index;     is-&gt;video_st = pFormatCtx-&gt;streams[stream_index];     is-&gt;video_ctx = codecCtx;      is-&gt;frame_timer = (double)av_gettime() \/ 1000000.0;     is-&gt;frame_last_delay = 40e-3;          packet_queue_init(&amp;is-&gt;videoq);     is-&gt;video_tid = SDL_CreateThread(video_thread, is);     is-&gt;sws_ctx = sws_getContext(is-&gt;video_ctx-&gt;width, is-&gt;video_ctx-&gt;height, \t\t\t\t is-&gt;video_ctx-&gt;pix_fmt, is-&gt;video_ctx-&gt;width, \t\t\t\t is-&gt;video_ctx-&gt;height, PIX_FMT_YUV420P, \t\t\t\t SWS_BILINEAR, NULL, NULL, NULL \t\t\t\t );     break;   default:     break;   } }  int decode_thread(void *arg) {    VideoState *is = (VideoState *)arg;   AVFormatContext *pFormatCtx;   AVPacket pkt1, *packet = &amp;pkt1;    int video_index = -1;   int audio_index = -1;   int i;    is-&gt;videoStream=-1;   is-&gt;audioStream=-1;    global_video_state = is;    \/\/ Open video file   if(avformat_open_input(&amp;pFormatCtx, is-&gt;filename, NULL, NULL)!=0)     return -1; \/\/ Couldn't open file    is-&gt;pFormatCtx = pFormatCtx;      \/\/ Retrieve stream information   if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)     return -1; \/\/ Couldn't find stream information      \/\/ Dump information about file onto standard error   av_dump_format(pFormatCtx, 0, is-&gt;filename, 0);      \/\/ Find the first video stream    for(i=0; i&lt;pFormatCtx-&gt;nb_streams; i++) {     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_VIDEO &amp;&amp;        video_index &lt; 0) {       video_index=i;     }     if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type==AVMEDIA_TYPE_AUDIO &amp;&amp;        audio_index &lt; 0) {       audio_index=i;     }   }   if(audio_index &gt;= 0) {     stream_component_open(is, audio_index);   }   if(video_index &gt;= 0) {     stream_component_open(is, video_index);   }       if(is-&gt;videoStream &lt; 0 || is-&gt;audioStream &lt; 0) {     fprintf(stderr, &quot;%s: could not open codecs\\n&quot;, is-&gt;filename);     goto fail;   }    \/\/ main decode loop    for(;;) {     if(is-&gt;quit) {       break;     }     \/\/ seek stuff goes here     if(is-&gt;audioq.size &gt; MAX_AUDIOQ_SIZE ||        is-&gt;videoq.size &gt; MAX_VIDEOQ_SIZE) {       SDL_Delay(10);       continue;     }     if(av_read_frame(is-&gt;pFormatCtx, packet) &lt; 0) {       if(is-&gt;pFormatCtx-&gt;pb-&gt;error == 0) { \tSDL_Delay(100); \/* no error; wait for user input *\/ \tcontinue;       } else { \tbreak;       }     }     \/\/ Is this a packet from the video stream?     if(packet-&gt;stream_index == is-&gt;videoStream) {       packet_queue_put(&amp;is-&gt;videoq, packet);     } else if(packet-&gt;stream_index == is-&gt;audioStream) {       packet_queue_put(&amp;is-&gt;audioq, packet);     } else {       av_free_packet(packet);     }   }   \/* all done - wait for it *\/   while(!is-&gt;quit) {     SDL_Delay(100);   }   fail:   if(1){     SDL_Event event;     event.type = FF_QUIT_EVENT;     event.user.data1 = is;     SDL_PushEvent(&amp;event);   }   return 0; }  int main(int argc, char *argv[]) {    SDL_Event       event;    VideoState      *is;    is = av_mallocz(sizeof(VideoState));    if(argc &lt; 2) {     fprintf(stderr, &quot;Usage: test &lt;file&gt;\\n&quot;);     exit(1);   }   \/\/ Register all formats and codecs   av_register_all();      if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {     fprintf(stderr, &quot;Could not initialize SDL - %s\\n&quot;, SDL_GetError());     exit(1);   }    \/\/ Make a screen to put our video #ifndef __DARWIN__         screen = SDL_SetVideoMode(640, 480, 0, 0); #else         screen = SDL_SetVideoMode(640, 480, 24, 0); #endif   if(!screen) {     fprintf(stderr, &quot;SDL: could not set video mode - exiting\\n&quot;);     exit(1);   }    screen_mutex = SDL_CreateMutex();    av_strlcpy(is-&gt;filename, argv[1], sizeof(is-&gt;filename));    is-&gt;pictq_mutex = SDL_CreateMutex();   is-&gt;pictq_cond = SDL_CreateCond();    schedule_refresh(is, 40);    is-&gt;parse_tid = SDL_CreateThread(decode_thread, is);   if(!is-&gt;parse_tid) {     av_free(is);     return -1;   }   for(;;) {      SDL_WaitEvent(&amp;event);     switch(event.type) {     case FF_QUIT_EVENT:     case SDL_QUIT:       is-&gt;quit = 1;       SDL_Quit();       return 0;       break;     case FF_REFRESH_EVENT:       video_refresh_timer(event.user.data1);       break;     default:       break;     }   }   return 0;  } <\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<h3>\u041f\u0420\u0415\u0414\u041e\u0421\u0422\u0415\u0420\u0415\u0416\u0415\u041d\u0418\u0415<\/h3>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u044f \u0442\u043e\u043b\u044c\u043a\u043e-\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u044d\u0442\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e, \u0432\u0435\u0441\u044c \u043c\u043e\u0439 \u043a\u043e\u0434 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u043b \u0432\u0437\u044f\u0442 \u0438\u0437 \u0442\u043e\u0433\u0434\u0430\u0448\u043d\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 <b>ffplay.c<\/b>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044d\u0442\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 FFmpeg (\u0434\u0430 \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c ffplay.c) \u043f\u0440\u0438\u0432\u0435\u043b\u0438 \u043a \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c. \u0425\u043e\u0442\u044f \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432\u0441\u0451 \u0435\u0449\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043e\u043d \u0443\u0436\u0435 \u043c\u043e\u0440\u0430\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u0440\u0435\u043b, \u0438 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435.<\/p>\n<h3>\u041a\u0430\u043a \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u0438\u0434\u0435\u043e<\/h3>\n<p>  \u0414\u043e \u0441\u0435\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0442\u0435\u043b\u044c \u0444\u0438\u043b\u044c\u043c\u043e\u0432. \u0414\u0430, \u043e\u043d \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0432\u0438\u0434\u0435\u043e, \u0438 \u0434\u0430, \u043e\u043d \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0430\u0443\u0434\u0438\u043e, \u043d\u043e \u044d\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0431\u044b \u043d\u0430\u0437\u0432\u0430\u043b\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u043c. \u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0435 \u043d\u0430\u043c \u0442\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<h4>PTS \u0438 DTS<\/h4>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0430\u0443\u0434\u0438\u043e- \u0438 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0432 \u043a\u0430\u043a\u0438\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f. \u0423 \u0430\u0443\u0434\u0438\u043e\u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0435\u0441\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u0438\u0437\u0430\u0446\u0438\u0438, \u0430 \u0443 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0434\u0440\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0434\u0435\u043e, \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0434\u0440\u043e\u0432 \u0438 \u0443\u043c\u043d\u043e\u0436\u0438\u0432 \u043d\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043a\u0430\u0434\u0440\u043e\u0432, \u0435\u0441\u0442\u044c \u043d\u0435\u043c\u0430\u043b\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u043e \u043d\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043e \u0437\u0432\u0443\u043a\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u043e\u0439\u0434\u0451\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0443\u0442\u0451\u043c. \u041f\u0430\u043a\u0435\u0442\u044b \u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e <b>\u043c\u0435\u0442\u043a\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/b> (<b>DTS<\/b> \u2014 \u043e\u0442 <i><b>d<\/b>ecoding <b>t<\/b>ime <b>s<\/b>tamp<\/i>) \u0438 <b>\u043c\u0435\u0442\u043a\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/b> (<b>PTS<\/b> \u2014 \u043e\u0442 <i><b>p<\/b>resentation <b>t<\/b>ime <b>s<\/b>tamp<\/i>). \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u044d\u0442\u0438 \u0434\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0444\u0438\u043b\u044c\u043c\u044b. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b, \u0432\u0440\u043e\u0434\u0435 MPEG, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 <b>B-\u043a\u0430\u0434\u0440\u0430\u043c\u0438<\/b> (<i>B<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439, \u043f\u043e \u0430\u043d\u0433\u043b. <i>bidirectional<\/i>). \u0414\u0432\u0430 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u0430 \u043a\u0430\u0434\u0440\u043e\u0432 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f <b>I-\u043a\u0430\u0434\u0440\u0430\u043c\u0438<\/b> \u0438 <b>P-\u043a\u0430\u0434\u0440\u0430\u043c\u0438<\/b> (<i>I<\/i> \u044d\u0442\u043e <i>\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439<\/i>, <i><b>i<\/b>nner<\/i>, \u0430 <i>P<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 <i>\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0439<\/i>, <i><b>p<\/b>redicted<\/i>). <b>I-\u043a\u0430\u0434\u0440\u044b<\/b> \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. <b>P-\u043a\u0430\u0434\u0440\u044b<\/b> \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 I- \u0438 P-\u043a\u0430\u0434\u0440\u043e\u0432 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0442 \u043d\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043e\u0442 \u043f\u0440\u0435\u044b\u0434\u0443\u0449\u0438\u0445 \u043a\u0430\u0434\u0440\u043e\u0432, \u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u2014 \u0434\u0435\u043b\u044c\u0442\u044b. <b>B-\u043a\u0430\u0434\u0440\u044b<\/b> \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 P-\u043a\u0430\u0434\u0440\u044b, \u043d\u043e \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439\u0441\u044f \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445, \u0442\u0430\u043a \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043a\u0430\u0434\u0440\u0430\u0445! \u0422\u043e \u0447\u0442\u043e \u043a\u0430\u0434\u0440 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0435 \u0441\u0430\u043c\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u0430\u0434\u0440\u0430\u043c\u0438 \u2014 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442, \u043f\u043e\u0447\u0435\u043c\u0443 \u0443 \u043d\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0431\u044b\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 <b>avcodec_decode_video2<\/b>.<\/p>\n<p>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0444\u0438\u043b\u044c\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c 4 \u043a\u0430\u0434\u0440\u0430 \u0432 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438: <nobr>I B B P<\/nobr>. \u0422\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e P-\u043a\u0430\u0434\u0440\u0430, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0441\u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 B-\u043a\u0430\u0434\u0440\u043e\u0432. \u0418\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0439 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: <nobr>I P B B<\/nobr>. \u0412\u043e\u0442 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00e1\u044f \u043c\u0435\u0442\u043a\u0430 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00e1\u044f \u043c\u0435\u0442\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430. \u041e\u0442\u043c\u0435\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 \u043e\u0442\u043c\u0435\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u043c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c. \u0418\u0442\u0430\u043a, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u0448 \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  &nbsp;&nbsp;&nbsp;<b>PTS:<\/b> 1 4 2 3<br \/>  &nbsp;&nbsp;&nbsp;<b>DTS:<\/b> 1 2 3 4<br \/>  <b>\u041f\u043e\u0442\u043e\u043a:<\/b> I P B B<\/p>\n<p>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, PTS \u0438 DTS \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 B-\u043a\u0430\u0434\u0440\u044b.<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442 \u043e\u0442 <b>av_read_frame<\/b>(), \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f PTS \u0438 DTS \u0434\u043b\u044f \u0442\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0447\u0442\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043a\u0435\u0442\u0430. \u041d\u043e \u0447\u0442\u043e \u043d\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e, \u0442\u0430\u043a \u044d\u0442\u043e PTS \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0430\u0434\u0440\u0430, \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u043d\u0430\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c.<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, FFmpeg \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u00ab\u0441\u0430\u043c\u0443\u044e \u043b\u0443\u0447\u0448\u0435\u0435 \u0438\u0437 \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445\u00bb \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u00fd\u044e \u043c\u0435\u0442\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>av_frame_get_best_effort_timestamp<\/b>().<\/p>\n<h4>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043a\u0430\u0434\u0440\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0438\u0441\u044c \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0437\u043d\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0434\u0440. \u041d\u043e \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c? \u0418\u0434\u0435\u044f \u0442\u0430\u043a\u043e\u0432\u0430: \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0434\u0440, \u043c\u044b \u0432\u044b\u044f\u0441\u043d\u044f\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0430\u0443\u0437\u0443, \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 PTS \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u0430\u0434\u0440\u0430 \u043f\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0447\u0430\u0441\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f. \u042d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0435\u0448\u0438\u0442\u044c.<\/p>\n<p>  \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u044d\u0442\u043e \u0432\u043e\u043f\u0440\u043e\u0441 \u043e \u0442\u043e\u043c, \u043a\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 PTS? \u0412\u044b \u0441\u043a\u0430\u0436\u0435\u0442\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0432\u0438\u0434\u0435\u043e \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u0439 PTS \u2014 \u0438 \u0431\u0443\u0434\u0435\u0442\u0435, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043f\u0440\u0430\u0432\u044b. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0432\u0438\u0434\u0435\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u044f \u043a\u0430\u0434\u0440\u043e\u0432. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u0430\u0434\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0440\u0430\u043d\u043e. \u042d\u0442\u043e \u043d\u0430\u0434\u043e \u0443\u0447\u0435\u0441\u0442\u044c.<\/p>\n<p>  \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u0432 \u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0432\u0438\u0434\u0435\u043e \u0438 \u0430\u0443\u0434\u0438\u043e, \u0440\u0430\u0434\u043e\u0441\u0442\u043d\u043e \u043d\u0435\u0441\u0443\u0442\u0441\u044f \u0432\u043f\u0435\u0440\u0451\u0434, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0443\u0434\u043e\u0441\u0443\u0436\u0438\u0432\u0430\u044f\u0441\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043e\u043e\u0431\u0449\u0435. \u041d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u0441\u0451 \u0441\u0430\u043c\u043e \u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e. \u041d\u043e \u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u0435\u043d, \u0440\u0430\u0432\u043d\u043e \u043a\u0430\u043a \u0438 \u043c\u043d\u043e\u0433\u0438\u0435 \u0432\u0438\u0434\u0435\u043e\u0444\u0430\u0439\u043b\u044b. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430: \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0443\u0434\u0438\u043e \u0441 \u0432\u0438\u0434\u0435\u043e, \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u0430\u0443\u0434\u0438\u043e \u0438\u043b\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0430\u0443\u0434\u0438\u043e \u0438 \u0432\u0438\u0434\u0435\u043e \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0447\u0430\u0441\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u043c). \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u0430\u0443\u0434\u0438\u043e.<\/p>\n<h3>\u041a\u043e\u0434\u0438\u043d\u0433: \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 PTS \u043a\u0430\u0434\u0440\u0430<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c. \u041d\u0430\u043c \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u0435\u0439 \u0432 \u043d\u0430\u0448\u0443 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0438 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043d\u0430\u0448 \u0432\u0438\u0434\u0435\u043e\u0442\u0440\u0435\u0434. \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u044b \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u0448\u0438\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f? \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c PTS \u0434\u043b\u044f \u043a\u0430\u0434\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043c \u0434\u0430\u043b <b>avcodec_decode_video2<\/b>. \u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438, \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 DTS \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430, \u0447\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"cpp\">  double pts;    for(;;) {     if(packet_queue_get(&amp;is-&gt;videoq, packet, 1) &lt; 0) {       \/\/ means we quit getting packets       break;     }     pts = 0;     \/\/ Decode video frame     len1 = avcodec_decode_video2(is-&gt;video_st-&gt;codec,                                 pFrame, &amp;frameFinished, packet);     if(packet-&gt;dts != AV_NOPTS_VALUE) {       pts = av_frame_get_best_effort_timestamp(pFrame);     } else {       pts = 0;     }     pts *= av_q2d(is-&gt;video_st-&gt;time_base);<\/code><\/pre>\n<p>  \u041c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c PTS \u043d\u0430 \u043d\u043e\u043b\u044c, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041d\u0443, \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e. \u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u043c\u0430\u0440\u043a\u0430: \u043a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <b>int64<\/b> \u0434\u043b\u044f PTS. \u042d\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e PTS \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u043a \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043a\u043e\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 <b>timebb<\/b>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u043e\u043a \u0438\u043c\u0435\u0435\u0442 24 \u043a\u0430\u0434\u0440\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443, PTS \u043e\u0442 42 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043a\u0430\u0434\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043c, \u0433\u0434\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c 42-\u0439 \u043a\u0430\u0434\u0440, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u043a\u0430\u0434\u0440\u044b \u0441\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0435 1\/24 \u0441\u0435\u043a\u0443\u043d\u0434\u044b (\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435).<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u0443\u0442\u0451\u043c \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043a\u0430\u0434\u0440\u043e\u0432. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>time_base<\/b> \u043f\u043e\u0442\u043e\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e 1 \u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043d\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043a\u0430\u0434\u0440\u043e\u0432 (\u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0441 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u043a\u0430\u0434\u0440\u043e\u0432), \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c PTS \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043c\u044b \u0443\u043c\u043d\u043e\u0436\u0430\u0435\u043c \u043d\u0430 <b>time_base<\/b>.<\/p>\n<h3>\u041a\u043e\u0434\u0438\u043c \u0434\u0430\u043b\u044c\u0448\u0435: \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 PTS<\/h3>\n<p>  \u0422\u0430\u043a \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 PTS. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u043c\u0441\u044f \u043e \u0442\u0435\u0445 \u0434\u0432\u0443\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435. \u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>synchronize_video<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c PTS \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e \u0432\u0441\u0435\u043c. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u0435\u043b\u043e \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u044f\u043c\u0438, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 PTS \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u0430\u0434\u0440\u0430. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0433\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>video_clock<\/b>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u043e\u0448\u043b\u043e \u0434\u043b\u044f \u0432\u0438\u0434\u0435\u043e. \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0448\u0443 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"cpp\">typedef struct VideoState {   double          video_clock; \/\/ pts of last decoded frame \/ predicted pts of next decoded frame<\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>synchronize_video<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u0430:<\/p>\n<pre><code class=\"cpp\">double synchronize_video(VideoState *is, AVFrame *src_frame, double pts) {    double frame_delay;    if(pts != 0) {     \/* if we have pts, set video clock to it *\/     is-&gt;video_clock = pts;   } else {     \/* if we aren't given a pts, set it to the clock *\/     pts = is-&gt;video_clock;   }   \/* update the video clock *\/   frame_delay = av_q2d(is-&gt;video_st-&gt;codec-&gt;time_base);   \/* if we are repeating a frame, adjust clock accordingly *\/   frame_delay += src_frame-&gt;repeat_pict * (frame_delay * 0.5);   is-&gt;video_clock += frame_delay;   return pts; }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043c\u044b \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u043a\u0430\u0434\u0440\u044b \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0430\u0448 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 PTS \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043a\u0430\u0434\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <b>queue_picture<\/b>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043d\u043e\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <b>pts<\/b>:<\/p>\n<pre><code class=\"cpp\">    \/\/ Did we get a video frame?     if(frameFinished) {       pts = synchronize_video(is, pFrame, pts);       if(queue_picture(is, pFrame, pts) &lt; 0) { \tbreak;       }     }<\/code><\/pre>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 <b>queue_picture<\/b> \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>pts<\/b> \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 <b>VideoPicture<\/b>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <b>pts<\/b> \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">typedef struct VideoPicture {   ...   double pts; } int queue_picture(VideoState *is, AVFrame *pFrame, double pts) {   ... stuff ...   if(vp-&gt;bmp) {     ... convert picture ...     vp-&gt;pts = pts;     ... alert queue ...   }<\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u0442\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0432\u044b\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 PTS, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0435\u043e. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u043b\u0430\u043b\u0438 \u0435\u0433\u043e \u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 80 \u043c\u0441. \u0427\u0442\u043e \u0436, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043c \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435.<\/p>\n<p>  \u041d\u0430\u0448\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e PTS, \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u0440\u044f\u044f \u0432\u0440\u0435\u043c\u044f \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u043a\u0443\u0449\u0438\u043c <b>pts<\/b> \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u0430\u0443\u0434\u0438\u043e. \u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c <b>\u0430\u0443\u0434\u0438\u043e\u0447\u0430\u0441\u044b<\/b>: \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442, \u0432 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0430\u0443\u0434\u0438\u043e, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c. \u042d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0446\u0438\u0444\u0440\u043e\u0432\u043e\u0435 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043b\u044e\u0431\u043e\u043c mp3-\u043f\u043b\u0435\u0435\u0440\u0435. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0441\u043e \u0437\u0432\u0443\u043a\u043e\u043c, \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u0430\u043b\u0435\u043a\u043e \u0432\u043f\u0435\u0440\u0435\u0434\u0438 \u0438\u043b\u0438 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u0430\u043b\u0435\u043a\u043e \u043f\u043e\u0437\u0430\u0434\u0438.<\/p>\n<p>  \u041c\u044b \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0437\u0436\u0435; \u0441\u0435\u0439\u0447\u0430\u0441 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f <b>get_audio_clock<\/b>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0430\u0441\u0442 \u043d\u0430\u043c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0430\u0443\u0434\u0438\u043e\u0447\u0430\u0441\u0430\u0445. \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u0438\u0434\u0435\u043e \u0438 \u0430\u0443\u0434\u0438\u043e \u043d\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b? \u0411\u044b\u043b\u043e \u0431\u044b \u0433\u043b\u0443\u043f\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u044b\u0433\u043d\u0443\u0442\u044c \u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u0430\u043a\u0435\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0438\u0441\u043a \u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043b\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f: \u0435\u0441\u043b\u0438 PTS \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u0442\u0441\u0442\u0430\u0435\u0442 \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0430\u0443\u0434\u0438\u043e, \u043c\u044b \u0443\u0434\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448\u0443 \u0440\u0430\u0441\u0447\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443. \u0415\u0441\u043b\u0438 PTS \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0437\u0432\u0443\u0447\u0430\u043d\u0438\u044f, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435. \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438, \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0441 \u0447\u0430\u0441\u0430\u043c\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0439 <b>frame_timer<\/b>. \u042d\u0442\u043e\u0442 \u0442\u0430\u0439\u043c\u0435\u0440 \u043a\u0430\u0434\u0440\u043e\u0432 \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u043d\u044b\u0435 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u043c\u0430. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044d\u0442\u043e\u0442 <b>frame_timer<\/b> \u2014 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u0430\u0434\u0440. \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0432 \u0442\u0430\u0439\u043c\u0435\u0440 \u043a\u0430\u0434\u0440\u043e\u0432, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0435\u0451 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043d\u0430 \u0447\u0430\u0441\u0430\u0445 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0431\u0438\u0432\u0430\u0442\u044c \u0441 \u0442\u043e\u043b\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u0435 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">void video_refresh_timer(void *userdata) {    VideoState *is = (VideoState *)userdata;   VideoPicture *vp;   double actual_delay, delay, sync_threshold, ref_clock, diff;      if(is-&gt;video_st) {     if(is-&gt;pictq_size == 0) {       schedule_refresh(is, 1);     } else {       vp = &amp;is-&gt;pictq[is-&gt;pictq_rindex];        delay = vp-&gt;pts - is-&gt;frame_last_pts; \/* the pts from last time *\/       if(delay &lt;= 0 || delay &gt;= 1.0) { \t\/* if incorrect delay, use previous one *\/ \tdelay = is-&gt;frame_last_delay;       }       \/* save for next time *\/       is-&gt;frame_last_delay = delay;       is-&gt;frame_last_pts = vp-&gt;pts;        \/* update delay to sync to audio *\/       ref_clock = get_audio_clock(is);       diff = vp-&gt;pts - ref_clock;        \/* Skip or repeat the frame. Take delay into account \t FFPlay still doesn't &quot;know if this is the best guess.&quot; *\/       sync_threshold = (delay &gt; AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD;       if(fabs(diff) &lt; AV_NOSYNC_THRESHOLD) { \tif(diff &lt;= -sync_threshold) { \t  delay = 0; \t} else if(diff &gt;= sync_threshold) { \t  delay = 2 * delay; \t}       }       is-&gt;frame_timer += delay;       \/* computer the REAL delay *\/       actual_delay = is-&gt;frame_timer - (av_gettime() \/ 1000000.0);       if(actual_delay &lt; 0.010) { \t\/* Really it should skip the picture instead *\/ \tactual_delay = 0.010;       }       schedule_refresh(is, (int)(actual_delay * 1000 + 0.5));       \/* show the picture! *\/       video_display(is);              \/* update queue for next picture! *\/       if(++is-&gt;pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { \tis-&gt;pictq_rindex = 0;       }       SDL_LockMutex(is-&gt;pictq_mutex);       is-&gt;pictq_size--;       SDL_CondSignal(is-&gt;pictq_cond);       SDL_UnlockMutex(is-&gt;pictq_mutex);     }   } else {     schedule_refresh(is, 100);   } }<\/code><\/pre>\n<p>  \u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a: \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u043b\u0435\u0434\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 PTS \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 PTS \u0438\u043c\u0435\u043b\u0430 \u0441\u043c\u044b\u0441\u043b. \u0415\u0441\u043b\u0438 \u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0432 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0435 \u043d\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442, \u0430\u0443\u0434\u0438\u043e \u0438 \u0432\u0438\u0434\u0435\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0432\u043f\u0430\u043b\u0438 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443. \u0417\u0430\u0442\u0435\u043c \u0443\u0434\u043e\u0441\u0442\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0440\u043e\u0433 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u0431\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0438\u043a\u043e\u0433\u0434\u0430. FFplay \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 0,01 \u0434\u043b\u044f \u043f\u043e\u0440\u043e\u0433\u0430. \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0438\u043c \u0437\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0440\u043e\u0433 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u044b\u043b \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 PTS. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432 10 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434 (\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0437\u0434\u0435\u0441\u044c \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u0430\u0434\u0440, \u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0431 \u044d\u0442\u043e\u043c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f).<\/p>\n<p>  \u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a\u0443\u0447\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043a\u043e\u0434. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u0439\u043c\u0435\u0440 \u043a\u0430\u0434\u0440\u0430 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043a\u0430\u0434\u0440\u0430 \u0432 <b>stream_component_open<\/b>:<\/p>\n<pre><code class=\"cpp\">    is-&gt;frame_timer = (double)av_gettime() \/ 1000000.0;     is-&gt;frame_last_delay = 40e-3;<\/code><\/pre>\n<p>  <\/p>\n<h3>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f: \u0430\u0443\u0434\u0438\u043e \u0447\u0430\u0441\u044b<\/h3>\n<p>  \u041d\u0430\u0441\u0442\u0430\u043b \u0447\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0443\u0434\u0438\u043e\u0447\u0430\u0441\u044b. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0432 \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>audio_decode_frame<\/b>, \u0433\u0434\u0435 \u043c\u044b \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0430\u0443\u0434\u0438\u043e. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u043a\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0443\u0447\u0430\u0441\u0442\u043a\u0430, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0447\u0430\u0441\u044b. \u041f\u0435\u0440\u0432\u043e\u0435 \u043c\u0435\u0441\u0442\u043e, \u044d\u0442\u043e \u0433\u0434\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u043a\u0435\u0442: \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0432\u0443\u043a\u043e\u0432\u044b\u0435 \u0447\u0430\u0441\u044b \u043d\u0430 PTS \u043f\u0430\u043a\u0435\u0442\u0430. \u0417\u0430\u0442\u0435\u043c, \u0435\u0441\u043b\u0438 \u043f\u0430\u043a\u0435\u0442 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u0434\u0440\u043e\u0432, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0437\u0432\u0443\u043a\u0430, \u0441\u0447\u0438\u0442\u0430\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0438 \u0443\u043c\u043d\u043e\u0436\u0430\u044f \u0438\u0445 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443. \u0418\u0442\u0430\u043a, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0430\u043a\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">    \/* if update, update the audio clock w\/pts *\/     if(pkt-&gt;pts != AV_NOPTS_VALUE) {       is-&gt;audio_clock = av_q2d(is-&gt;audio_st-&gt;time_base)*pkt-&gt;pts;     }<\/code><\/pre>\n<p>  \u0418 \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0430\u043a\u0435\u0442:<\/p>\n<pre><code class=\"cpp\">      \/* Keep audio_clock up-to-date *\/       pts = is-&gt;audio_clock;       *pts_ptr = pts;       n = 2 * is-&gt;audio_st-&gt;codec-&gt;channels;       is-&gt;audio_clock += (double)data_size \/ \t(double)(n * is-&gt;audio_st-&gt;codec-&gt;sample_rate);<\/code><\/pre>\n<p>  \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u043b\u043a\u0438\u0445 \u043d\u044e\u0430\u043d\u0441\u043e\u0432: \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u044b\u043b \u0438\u0437\u043c\u0435\u043d\u0435\u043d \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 <b>pts_ptr<\/b>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0435\u0433\u043e. <b>pts_ptr<\/b> \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c <b>audio_callback<\/b> \u0430\u0443\u0434\u0438\u043e\u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 <b>pts<\/b>. \u042d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0443\u0434\u0438\u043e \u0441 \u0432\u0438\u0434\u0435\u043e.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>get_audio_clock<\/b>. \u042d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <nobr><b>is<\/b>-&gt;<b>audio_clock<\/b><\/nobr>, \u0435\u0441\u043b\u0438 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0430\u0443\u0434\u0438\u043e PTS \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>audio_callback<\/b>, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u0430\u0443\u0434\u0438\u043e\u043f\u0430\u043a\u0435\u0442\u0430 \u0432 \u043d\u0430\u0448 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0431\u0443\u0444\u0435\u0440. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0448\u0438\u0445 \u0430\u0443\u0434\u0438\u043e\u0447\u0430\u0441\u0430\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u0430\u043b\u0435\u043a\u043e \u0443\u0439\u0442\u0438 \u0432\u043f\u0435\u0440\u0451\u0434. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c. \u0412\u043e\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"cpp\">double get_audio_clock(VideoState *is) {   double pts;   int hw_buf_size, bytes_per_sec, n;      pts = is-&gt;audio_clock; \/* maintained in the audio thread *\/   hw_buf_size = is-&gt;audio_buf_size - is-&gt;audio_buf_index;   bytes_per_sec = 0;   n = is-&gt;audio_st-&gt;codec-&gt;channels * 2;   if(is-&gt;audio_st) {     bytes_per_sec = is-&gt;audio_st-&gt;codec-&gt;sample_rate * n;   }   if(bytes_per_sec) {     pts -= (double)hw_buf_size \/ bytes_per_sec;   }   return pts; }<\/code><\/pre>\n<p>  \u0412\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0443\u0436\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \ud83d\ude09<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u044d\u0442\u043e \u0432\u0441\u0435! \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code class=\"bash\">gcc -o tutorial05 tutorial05.c -lavutil -lavformat -lavcodec -lswscale -lz -lm \\ `sdl-config --cflags --libs`<\/code><\/pre>\n<p>  \u0421\u0432\u0435\u0440\u0448\u0438\u043b\u043e\u0441\u044c! \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0444\u0438\u043b\u044c\u043c \u043d\u0430 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0442\u0435\u043b\u0435, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0443\u0440\u043e\u043a\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u0430\u0443\u0434\u0438\u043e, \u0430 \u0437\u0430\u0442\u0435\u043c \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a.<\/p>\n<h3>\u041f\u0435\u0440\u0435\u0432\u043e\u0434\u044b \u0432 \u0431\u043b\u043e\u0433\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u042d\u0434\u0438\u0441\u043e\u043d:<\/h3>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<td align=\"center\"><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/498836\/\"><img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"180\" src=\"https:\/\/habrastorage.org\/webt\/fr\/yz\/q7\/fryzq72v0ik0irt2q4orchflxvs.jpeg\"><\/a><\/td>\n<td align=\"center\"><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/495612\/\"><img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"180\" src=\"https:\/\/habrastorage.org\/webt\/jv\/3k\/-f\/jv3k-f5vi9drztohsh-e0t-puru.jpeg\"><\/a><\/td>\n<\/tr>\n<tr>\n<th align=\"center\"><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/498836\/\">\u0422\u043e\u043f-50 \u0438\u0433\u0440\u043e\u0432\u044b\u0445 \u0444\u0440\u0430\u043d\u0448\u0438\u0437<br \/>  \u0441 \u0434\u043e\u0445\u043e\u0434\u043e\u043c \u0431\u043e\u043b\u0435\u0435 \u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434\u0430<\/a><\/th>\n<th align=\"center\"><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/495612\/\">\u041f\u0435\u0440\u0435\u0436\u0438\u0432\u0451\u0442 \u043b\u0438 Airbnb \u043a\u043e\u0440\u043e\u043d\u0430\u0432\u0438\u0440\u0443\u0441?<br \/>  [\u0441\u043f\u043e\u0439\u043b\u0435\u0440: \u0434\u0430]<\/a><\/th>\n<\/tr>\n<\/table>\n<\/div>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/500402\/\"> https:\/\/habr.com\/ru\/company\/edison\/blog\/500402\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/500402\/\"><a href=\"https:\/\/habr.com\/ru\/company\/edison\/blog\/500402\/\"><\/p>\n<div style=\"text-align:center;\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"325\" src=\"https:\/\/habrastorage.org\/webt\/8g\/lm\/9b\/8glm9bxivqkvscmah31ojdjmzci.png\"><\/div>\n<p><\/a><br \/>  \u0425\u043e\u0442\u044f \u0434\u0430\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u0440\u0435\u043b\u0430, \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0438 \u043f\u043e \u0441\u0435\u0439 \u0434\u0435\u043d\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u043f\u043e \u0442\u0435\u043c\u0435 FFmpeg. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435\u0442. \u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u0441\u0430\u0434\u043d\u043e\u0435 \u0443\u043f\u0443\u0449\u0435\u043d\u0438\u0435, \u0438\u0431\u043e \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0437\u0434\u043d\u043e, \u0447\u0435\u043c \u043d\u0438\u043a\u043e\u0433\u0434\u0430.<\/p>\n<p>  \u0418 \u0445\u043e\u0442\u044f \u043c\u044b \u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c, \u0432 \u0442\u0430\u043a\u043e\u043c \u043e\u0431\u044a\u0451\u043c\u043d\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435 \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u044b <i>\u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430<\/i>. \u0421\u043e\u043e\u0431\u0449\u0430\u0439\u0442\u0435 \u043e \u043d\u0435\u0434\u043e\u0447\u0451\u0442\u0430\u0445 (\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 \u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u0445) \u2014 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043b\u0443\u0447\u0448\u0435.<\/p>\n<p>  <a name=\"menu\"><\/a><\/p>\n<h3>\u041e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h3>\n<div class=\"scrollable-table\">\n<table>\n<tr>\n<th align=\"center\">\u0427\u0430\u0441\u0442\u044c 1<\/th>\n<th align=\"center\">\u0427\u0430\u0441\u0442\u044c 2 (\u0432\u044b\u0439\u0434\u0435\u0442 \u0443\u0442\u0440\u043e\u043c 7 \u043c\u0430\u044f)<\/th>\n<\/tr>\n<tr>\n<td align=\"left\"><a href=\"https:\/\/habr.com\/ru\/post\/500402\/#preamble\">\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#screencaps\">\u0423\u0440\u043e\u043a 1: \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043d\u043a\u0430\u043f\u0441\u043e\u0432<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#outputting\">\u0423\u0440\u043e\u043a 2: \u0412\u044b\u0432\u043e\u0434 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#sound\">\u0423\u0440\u043e\u043a 3: \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#threads\">\u0423\u0440\u043e\u043a 4: \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0440\u0435\u0434\u044b<\/a><br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/500402\/#video\">\u0423\u0440\u043e\u043a 5: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0438\u0434\u0435\u043e<\/a>  <\/td>\n<td align=\"left\">\u0423\u0440\u043e\u043a 6: \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0443\u0434\u0438\u043e<br \/>  \u0423\u0440\u043e\u043a 7: \u041f\u043e\u0438\u0441\u043a<br \/>  \u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<br \/>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 1. \u0421\u043f\u0438\u0441\u043e\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439<br \/>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 2. \u0421\u043f\u0438\u0441\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445<br \/>  \u0421\u0441\u044b\u043b\u043a\u0438<\/td>\n<\/tr>\n<\/table>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-303036","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303036"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/303036\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}