ffmpeg键盘命令响应程序详解
- #include <termios.h>
- struct termios {
- tcflag_t c_iflag;
- tcflag_t c_oflag;
- tcflag_t c_cflag;
- tcflag_t c_lflag;
- cc_t c_cc[NCCS];
- };
- #include <termios.h>
- int tcgetattr(int fd, struct termios *termios_p);
- #include <termios.h>
- int tcsetattr(int fd, int actions, const struct termios *termios_p);
- #include <termios.h>
- speed_t cfgetispeed(const struct termios *);
- speed_t cfgetospeed(const struct termios *);
- int cfsetispeed(struct termios *, speed_t speed);
- int cfsetospeed(struct termios *, speed_t speed);
- #include <termios.h>
- int tcdrain(int fd);
- int tcflow(int fd, int flowtype);
- int tcflush(int fd, int in_out_selector);
- /*
- * \File
- * main.c
- * \Descript
- * Taken from ffmpeg,
- * implement for signal response function
- * \Author
- * Neo Yan
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <limits.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #include <termios.h>
- static struct termios oldtty;
- static int q_pressed = 0;
- static int verbose = 1;
- static int using_stdin = 0;
- static int run_as_daemon = 0;
- static volatile int received_sigterm = 0;
- static void term_init(void);
- static void term_exit(void);
- static void sigterm_handler(int sig);
- static int read_key(void);
- /*
- * \Func
- * main
- * \Descript
- *
- */
- int main(int argc, char **argv)
- {
- int index = 0;
- int key;
- if (!using_stdin)
- {
- if (verbose >= 0)
- printf("Perss [q] to stop, [?] for help\n");
- }
- term_init();
- for ( ; received_sigterm == 0; )
- {
- /* if 'q' pressed, exits */
- if (!using_stdin)
- {
- if (q_pressed)
- break;
- /* read_key() returns 0 on EOF */
- key = read_key();
- if (key == 'q')
- {
- printf("quit\n");
- break;
- }
- if (key == '+')
- {
- verbose++;
- printf("verbose = %d\n", verbose);
- }
- if (key == '-')
- {
- verbose--;
- printf("verbose = %d\n", verbose);
- }
- if (key == '?')
- {
- printf("key function\n"
- "? show this help\n"
- "+ increase verbosity\n"
- "- decrease verbosity\n"
- "q quit\n"
- );
- }
- }
- printf("index = %d\n", index++);
- sleep(1);
- }
- return 0;
- }
- static void term_init(void)
- {
- if (!run_as_daemon)
- {
- struct termios tty;
- tcgetattr(0, &tty);
- oldtty = tty;
- atexit(term_exit);
- tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
- |INLCR|IGNCR|ICRNL|IXON);
- tty.c_oflag |= OPOST;
- tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
- tty.c_cflag &= ~(CSIZE|PARENB);
- tty.c_cflag |= CS8;
- tty.c_cc[VMIN] = 1;
- tty.c_cc[VTIME] = 0;
- tcsetattr (0, TCSANOW, &tty);
- /* Quit (POSIX). */
- signal(SIGQUIT, sigterm_handler);
- }
- signal(SIGINT , sigterm_handler);
- signal(SIGTERM, sigterm_handler);
- }
- static void term_exit(void)
- {
- printf("%s\n", "TERMINATION");
- if (!run_as_daemon)
- tcsetattr(0, TCSANOW, &oldtty);
- }
- static void sigterm_handler(int sig)
- {
- received_sigterm = sig;
- q_pressed++;
- term_exit();
- }
- /*
- * \Func
- * read_key
- * \Descript
- * read a key without blocking
- */
- static int read_key(void)
- {
- int n = 1;
- unsigned char ch;
- struct timeval tv;
- fd_set rfds;
- if (run_as_daemon)
- return -1;
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- n = select(1, &rfds, NULL, NULL, &tv);
- if (n > 0)
- {
- n = read(0, &ch, 1);
- if (n == 1)
- return ch;
- return n;
- }
- return -1;
- }
- OBJECTS = main.o
- CC = gcc
- CFLAG = -g
- ffmpeg_signal : $(OBJECTS)
- $(CC) $(CFLAG) -o ffmpeg_signal $(OBJECTS)
- main.o:
- .PHONY:clean
- clean:
- rm ffmpeg_signal $(OBJECTS)
转载:http://blog.chinaunix.net/uid-26000296-id-3429028.html
ffmpeg键盘命令响应程序详解的更多相关文章
- telnet 命令使用方法详解,telnet命令怎么用
telnet 命令使用方法详解,telnet命令怎么用? 文章类型:电脑教程 原创:天诺时空 什么是Telnet? 对于Telnet的认识,不同的人持有不同的观点,可以把Telnet当成一种通信协 ...
- Linux开机启动程序详解
Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...
- Linux开机启动程序详解[转]
Linux开机启动程序详解 我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤 ...
- linux系统设置服务开机启动3种方法,Linux开机启动程序详解
linux系统设置服务开机启动 方法1:.利用ntsysv伪图形进行设置,利用root登陆 终端命令下输入ntsysv 回车:如下图 方法2:利用命令行chkconfig命令进行设置 简要说明 ...
- Linux如何实现开机启动程序详解(转)
Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...
- VLC命令行参数详解
VLC命令行参数详解 2012-11-29 14:00 6859人阅读 评论(0) 收藏 举报 Usage: vlc [options] [stream] ...You can specify mul ...
- FFmpeg开发笔记(五):ffmpeg解码的基本流程详解(ffmpeg3新解码api)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- ping命令执行过程详解
[TOC] ping命令执行过程详解 机器A ping 机器B 同一网段 ping通知系统建立一个固定格式的ICMP请求数据包 ICMP协议打包这个数据包和机器B的IP地址转交给IP协议层(一组后台运 ...
- Linux命令工具 top详解
Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不 ...
随机推荐
- SEO规范(部分)
1:尽量减少AJAX的使用搜索引擎无法检索ajax中的内容,也无法识别javascript代码. 2:拒绝iframe,frame标签iframe,frame会极大的阻碍搜索引擎爬取网站内容. 3:图 ...
- https://coderwall.com/p/7smjkq/multiple-ssh-keys-for-different-accounts-on-github-or-gitlab
Multiple SSH keys for different accounts on Github or Gitlab SSH GIT GITLAB GITHUB Sometimes you nee ...
- YARN环境搭建 之 二:CentOS7.0 JDK配置
Hadoop是Java写的,他无法使用Linux预安装的OpenJDK,因此安装hadoop前需要先安装JDK(1.6以上) 原材料:在Oracle官网下载的32位JDK: 说明: 1.C ...
- element-ui Cascader 级联选择器示例
<html> <head>test</head> <style> @import url("http://unpkg.com/element- ...
- RxSwift の Observable とは何か
Qiita にあげていた記事ですが.ここにもバックアップをとっておきます この記事は.2017/09/15〜17 に早稲田大学 理工学部 西早稲田キャンパスで開催される iOSDC Japan 201 ...
- Smallest Common Multiple FreeCodeCamp
题目:找出能被两个给定参数和它们之间的连续数字整除的最小公倍数. 范围是两个数字构成的数组,两个数字不一定按数字顺序排序. 分析:首先题目的意思求一个连续数列的所有数字的最小公倍数,这连续的数字序列 ...
- 初级模拟电路:1-2 PN结与二极管
回到目录 1. 掺杂半导体 上面我们分析了本征半导体的导电情况,但由于本征半导体的导电能力很低,没什么太大用处.所以,一般我们会对本征半导体材料进行掺杂,即使只添加了千分之一的杂质,也足以改变半导 ...
- SQL2012安装
SQL2012安装 1.打开SQL安装包,点击setup安装 2.选择安装界面,点击全新安装 3.验证通过后,点击确定 4.选择我接受,点击下一步 5.在外网环境,可进行在线更新,内网环境取消勾选产品 ...
- 路飞学城Python-Day150
最近由于在忙别的事情,所以路飞的课程就往后延期了,感觉很难受,不过我还是依然坚持学下去,必须的 最近在忙的事情 1.进入了数据分析行业,需要学习更多的知识 2.开始对数据收集负责,写各种爬虫 3.对数 ...
- 记Spring搭建功能完整的个人博客「Oyster」全过程[其二] Idea中Maven+SpringBoot多模块项目开发的设计和各种坑(模块间依赖和打包问题)
大家好嘞,今天闲着没事干开写写博客,记录一下Maven+SpringBoot的多模块设计和遇到的坑. 多模块设计 简单说明一下截止目前的需求: 需要RESTful API:对文章.标签.分类和评论等的 ...