ÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐжàýÌåÎļþµÄתÂëºÍ¼ô¼£¿
ÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐжàýÌåÎļþµÄתÂëºÍ¼ô¼£¿
Ëæ×ÅÊý×Ö»¯Ê±´úµÄÉú³¤£¬¶àýÌåÎļþµÄʹÓÃÒѾ³ÉΪÎÒÃÇÒ»Ñùƽ³£ÉúÑÄÖв»¿É»òȱµÄÒ»²¿·Ö¡£È»¶ø£¬¶àýÌåÎļþµÄÃûÌú;Þϸ¶àÖÖ¶àÑù£¬ÓÐʱÎÒÃÇÐèÒª¶ÔÆä¾ÙÐÐתÂëºÍ¼ô¼ÒÔ˳Ӧ²î±ðµÄÐèÇó¡£÷è÷ë²Ù×÷ϵͳ×÷Ϊһ¿î¿ªÔ´µÄ²Ù×÷ϵͳ£¬ÌṩÁ˸»ºñµÄ¹¤¾ßºÍ¿â£¬Ê¹µÃ¶àýÌåÎļþµÄתÂëºÍ¼ô¼±äµÃÔ½·¢¼òÆӺ͸ßЧ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐжàýÌåÎļþµÄתÂëºÍ¼ô¼£¬²¢ÌṩÏà¹ØµÄ´úÂëʾÀý¡£
Ò»¡¢¶àýÌåÎļþתÂë
×°ÖÃFFmpeg¿â
FFmpegÊÇÒ»¿îÇ¿Ê¢µÄ¶àýÌå´¦Àí¿â£¬¹ØÓÚ¶àýÌåÎļþתÂëÊ®·ÖÀû±ã¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚ÷è÷ë²Ù×÷ϵͳÉÏ×°ÖÃFFmpeg¿â£º
sudo apt-get install ffmpeg
µÇ¼ºó¸´ÖÆ
ʹÓÃFFmpeg¿â¾ÙÐÐתÂë
תÂë²Ù×÷¿ÉÒÔͨ¹ýFFmpeg¿âÌṩµÄÏÂÁîÐй¤¾ßʵÏÖ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃFFmpeg¾ÙÐÐÊÓƵÎļþתÂëµÄʾÀý£º
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict experimental output.mp4
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬-i²ÎÊýÖ¸¶¨ÊäÈëÎļþ£¬-c:v²ÎÊýÖ¸¶¨ÊÓƵ±àÂëÆ÷£¬-c:a²ÎÊýÖ¸¶¨ÒôƵ±àÂëÆ÷£¬-strict experimental²ÎÊýÓÃÓÚÖ§³ÖAACÒôƵ±àÂë¡£Çëƾ֤ÐèÒªÐ޸IJÎÊýºÍÎļþ·¾¶¡£
¶þ¡¢¶àýÌåÎļþ¼ô¼
×°ÖÃOpenCV¿â
OpenCVÊÇÒ»¸öÆÕ±éÓ¦ÓÃÓÚͼÏñºÍÊÓƵ´¦ÀíµÄ¿ªÔ´¿â£¬¿ÉÒÔÓÃÓÚ¶àýÌåÎļþµÄ¼ô¼¡£ÔÚ÷è÷ë²Ù×÷ϵͳÉÏ×°ÖÃOpenCV¿â£º
sudo apt-get install libopencv-dev
µÇ¼ºó¸´ÖÆ
ʹÓÃOpenCV¿â¾ÙÐмô¼
ʹÓÃOpenCV¿â¾ÙÐжàýÌåÎļþµÄ¼ô¼¿ÉÒÔͨ¹ý¶ÁÈ¡ºÍдÈëÏñËØÊý¾ÝÀ´ÊµÏÖ¡£ÒÔÏÂÊÇÒ»¸öʹÓÃOpenCV¾ÙÐÐÊÓƵ¼ô¼µÄʾÀý£º
#include <opencv2/opencv.hpp> int main() { cv::VideoCapture cap("input.mp4"); int frameCount = cap.get(CV_CAP_PROP_FRAME_COUNT); int fps = cap.get(CV_CAP_PROP_FPS); cv::VideoWriter writer("output.mp4", CV_FOURCC('M', 'P', '4', 'V'), fps, cv::Size(cap.get(CV_CAP_PROP_FRAME_WIDTH), cap.get(CV_CAP_PROP_FRAME_HEIGHT))); for(int i=0; i<frameCount; i++) { cv::Mat frame; cap >> frame; // ÔÚÕâÀï¶ÔÊÓƵ֡¾ÙÐмô¼´¦Àí writer.write(frame); } cap.release(); writer.release(); return 0; }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂëʹÓÃOpenCV¿â¶ÁÈ¡ÊäÈëÊÓƵÎļþ£¬²¢ÖðÖ¡¾ÙÐмô¼´¦Àí£¬×îºó½«´¦ÀíºóµÄ֡дÈëÊä³öÊÓƵÎļþ¡£Çëƾ֤ÐèÒªÐÞ¸ÄÎļþ·¾¶ºÍ¼ô¼´¦Àí²¿·ÖµÄ´úÂë¡£
×ÛÉÏËùÊö£¬÷è÷ë²Ù×÷ϵͳÌṩÁËÇ¿Ê¢µÄ¹¤¾ßºÍ¿â£¬Ê¹µÃ¶àýÌåÎļþµÄתÂëºÍ¼ô¼±äµÃÔ½·¢¼òÆӺ͸ßЧ¡£Í¨¹ý×°ÖúÍʹÓÃFFmpegºÍOpenCV¿â£¬ÎÒÃÇ¿ÉÒÔÇáËɵØʵÏÖ¶àýÌåÎļþµÄתÂëºÍ¼ô¼²Ù×÷¡£Ï£Íû±¾ÎĶÔÄúÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐжàýÌåÎļþµÄתÂëºÍ¼ô¼ÌṩÁË×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐжàýÌåÎļþµÄתÂëºÍ¼ô¼£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡