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是一个动态显示过程,即可以通过用户按键来不 ...
随机推荐
- CSS 三栏布局入门
首先,我是CSS盲[只听说过box model],没动手实践过,关于margin padding只知名称,不明细节.刚看过一叶斋大哥关于css布局的博文,再动手实践,动手记录下点滴积累以备后用. &l ...
- sql server<> != 从数据类型varchar转换为numeric 时出错
sql server 数据类型转换出错 字段percentcomplete 是 varchar 类型, 都是存的数字 用 where cast(percentcomplete as numeric(1 ...
- go开发和运行环境的配置
1.运行环境的下载.安装.配置: 下载:http://www.golangtc.com/download 官网下载经常被墙屏蔽,所以就从golang中国下载; 安装及其配置:http://jingy ...
- vue2 阻止时间冒泡
click.stop.prevent <div class="content-right" @click.stop.prevent="pay" > ...
- TRS矩阵分解
transform = TRS T就是transform的最后一列.关于R和S的分解,PBRT给了一个公式:M_(i+1) = (M_i + ((M_i)^T)^(-1))*0.5,直到M收敛.M初始 ...
- 【技术累积】【点】【java】【4】日志级别
闲聊 水文也是文,写总比不写好. 日志级别 虽然对其他语言的日志系统也不甚了解,但还是感觉Java的日志有些麻烦,当然也可以说是发展已久,多有变化,多有完善吧. 从日志级别来说,有从高到低的八个级别: ...
- 前端web通过flask操作数据库-增删改查
后端python代码: #coding:utf8 from flask import Flask,request,render_template import pymysql as mysql imp ...
- getopt函数
getopt -- 解析命令的可选项 [说明]getopt只是一个简单的解析命令可选项的函数,只能进行简单的格式命令解析,格式如下: 1.形如:cmd [-a][-b] //对短选项的解析: ...
- python二级登陆菜单
""" 1.三级菜单 注册 登陆 注销 2.进入每一个一级菜单,都会有下一级的菜单"""user_item = dict()try: whi ...
- Vue学习之路第十六篇:车型列表的添加、删除与检索项目
又到了大家最喜欢的项目练习阶段,学以致用,今天我们要用前几篇的学习内容实现列表的添加与删除. 学前准备: ①:JavaScript中的splice(index,i)方法:从已知数组的index下标开始 ...