ffmpeg_VideoTranscode.c
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* Includes ------------------------------------------------------------------*/
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
// 自建库
#include "JZsdkLib.h"
// 拍照转码函数
T_JZsdkReturnCode FFMPEG_ShootPhotoTransCode(int width, int height)
{
char ffmpegCmdStr[256]; //ffmpeg指令
int ret;
FILE *NUMBER_SET_fp;
//地址拼接
char str1[40] = "/root/sdcard/DCIM/Photos/PSDK_PHOTO";
char str2[6] = ".jpg";
char *InPutPath = "/root/sdcard/DCIM/Photos/temp.h264";
char OutPath[256];
int Numset;
//从文件中读取序号
NUMBER_SET_fp = fopen("/root/sdcard/DCIM/Photos/pthoto_number.txt","r");
//如果没有记录文件
if(NUMBER_SET_fp == NULL)
{
//新建一个记录文件,并写入0
NUMBER_SET_fp = fopen("/root/sdcard/DCIM/Photos/pthoto_number.txt","w");
fprintf(NUMBER_SET_fp, "%d", Numset);
}
// 从文件中读取Numset,并自增1
else
{
fscanf(NUMBER_SET_fp, "%d", &Numset);
Numset++;
fclose(NUMBER_SET_fp);
// 将新的LogNum写回文件中
NUMBER_SET_fp = fopen("/root/sdcard/DCIM/Photos/pthoto_number.txt", "w");
fprintf(NUMBER_SET_fp, "%d", Numset);
}
//关闭序号文件
fclose(NUMBER_SET_fp);
NUMBER_SET_fp = NULL;
//拼接出输入地址
snprintf(OutPath, 256, "%s_%05d%s", str1, Numset, str2);
JZSDK_LOG_INFO("ShootPhoto_OutPath:%s",OutPath);
//将h264照片转换为jpg格式
snprintf(ffmpegCmdStr, 256,
"echo \"y\" | ffmpeg -i \"%s\" -y -f image2 -t 0.001 -s %dx%d \"%s\" >/dev/null 2>&1",
InPutPath,
width,
height,
OutPath);
// snprintf(ffmpegCmdStr, 256,
// "echo \"y\" | ffmpeg -ss 00:00:01 -i \"%s\" -y -vframes 1 \"%s\" >/dev/null 2>&1",
// InPutPath,
// OutPath);
JZSDK_LOG_INFO("cmdstr:%s",ffmpegCmdStr);
//转码开始
JZsdk_RunSystemCmd(ffmpegCmdStr);
}
// 录像转码函数
T_JZsdkReturnCode FFMPEG_RecordVideoTransCode()
{
char ffmpegCmdStr[256]; //ffmpeg指令
int ret;
FILE *NUMBER_SET_fp;
//地址拼接
char str1[40] = "/root/sdcard/DCIM/Videos/PSDK_VIDEO";
char str2[6] = ".mp4";
char *InPutPath = "/root/sdcard/DCIM/Videos/temp.h264";
char OutPath[256];
int Numset;
//从文件中读取序号
NUMBER_SET_fp = fopen("/root/sdcard/DCIM/Videos/video_number.txt","r");
//如果没有记录文件
if(NUMBER_SET_fp == NULL)
{
//新建一个记录文件,并写入0
NUMBER_SET_fp = fopen("/root/sdcard/DCIM/Videos/video_number.txt","w");
fprintf(NUMBER_SET_fp, "%d", Numset);
}
// 从文件中读取Numset,并自增1
else
{
fscanf(NUMBER_SET_fp, "%d", &Numset);
Numset++;
fclose(NUMBER_SET_fp);
// 将新的LogNum写回文件中
NUMBER_SET_fp = fopen("/root/sdcard/DCIM/Videos/video_number.txt", "w");
fprintf(NUMBER_SET_fp, "%d", Numset);
}
//关闭序号文件
fclose(NUMBER_SET_fp);
NUMBER_SET_fp = NULL;
//拼接出输入地址
snprintf(OutPath, 256, "%s_%05d%s", str1, Numset, str2);
JZSDK_LOG_INFO("RecordVideo_OutPath:%s",OutPath);
//将h264照片转换为mp4格式
snprintf(ffmpegCmdStr, 256,
"echo \"y\" | ffmpeg -i \"%s\" -y -vcodec copy \"%s\" >/dev/null 2>&1",
InPutPath,
OutPath);
JZSDK_LOG_INFO("cmdstr:%s",ffmpegCmdStr);
//转码开始
JZsdk_RunSystemCmd(ffmpegCmdStr);
}
// // 连拍转码函数 暂不使用
// static void ShootPhoroBurst_transcode()
// {
// //ffmpeg指令
// char ffmpegCmdStr[FFMPEG_CMD_BUF_SIZE];
// char *H3_ShootPhoroBurst_InPath = "/root/sdcard/DCIM/Videos/temp.h264";
// char H3_ShootPhoroBurst_OutPath[FFMPEG_CMD_BUF_SIZE];
// //转码
// char str1[40] = "/root/sdcard/DCIM/Photos/video_";
// char str2[10] = ".mp4";
// //根据时间写名字
// snprintf(H3_ShootPhoroBurst_OutPath, 256, "%s_%d_%d%s", str1,GPS_Receive_Date,GPS_Receive_Time,str2);
// //将h264照片转换为jpg格式
// snprintf(ffmpegCmdStr, FFMPEG_CMD_BUF_SIZE,
// "echo \"y\" | ffmpeg -i \"%s\" -r 25 -f image2 -t 0.001 -s 1280*720 \"%s\" >/dev/null 2>&1",
// H3_ShootPhoroBurst_InPath,
// H3_ShootPhoroBurst_OutPath);
// //ffmpeg -i output.mp4 -r 30 -f image2 foo-%05d.jpeg
// USER_LOG_INFO("录像保存位置:%s",H3_ShootPhoroBurst_OutPath);
// RunSystemCmd(ffmpegCmdStr);
// }