1、由于项目既需要USB串口通讯,又要用ffmpeg推流,所以选择64位操作系统: 操作系统下载地址
2、官方烧写工具下载地址
3、烧写工具下载完成后, 选择最底下的 然后再选择下载的系统镜像
4、选择TF卡
5、Write!
6、烧录完成后,在boot里添加SSH空文件
7、使用XShell连接
8、输入命令
ffmpeg
正常状态如下图所示: 参考rtsp转推rtmp命令如下:
ffmpeg -i "rtsp://admin:12345@192.168.1.77:554/h264/ch1/main/av_stream" -f flv -r 25 -s 640x480 -an "rtmp://localhost/oflaDemo/hello"
9、安装jdk11
说明: 1、由于pi4j的1.4版本才支持64位操作系统,且必须jdk11才能正常使用 2、安装jdk11时JRE_HOME需要与JDK_HOME一致 3、jdk11不自带jre,需要自己生成,命令如下(可能不需要) jlink --module-path jmods --add-modules java.desktop --output jre 4、或者直接 sudo apt-get install openjdk-11-jdk 我没试过…
10、安装tomcat9
具体内容参考我以前文章: https://blog.csdn.net/u014492512/article/details/101197876 以下两点需要根据现有环境修改
(1)catalina.sh添加如下内容,可以用idea来远程部署(注意修改ip地址):
export CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=192.168.50.85"
export JAVA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.rmi.port=1099"
(2)setclasspath.sh添加如下内容:
export JAVA_HOME=/home/pi/jdk1.8.0_321
export JRE_HOME=/home/pi/jdk1.8.0_321
11、下载pi4j-1.4 (1)jar下载地址:https://github.com/Pi4J/download/raw/main/pi4j-1.4.zip (2)解压pi4j-core.jar,将pi4j-core\lib文件夹中的内容复制到\lib中 (3)示例如下:
package cmcc.serial;
import cmcc.Parameter;
import cmcc.ParameterManager;
import cmcc.Util;
import cmcc.fc.DataLinkParserUtil;
import cmcc.fc.Device;
import cmcc.fc.datalink.MAVLinkPacket;
import cmcc.fc.datalink.common.MsgSerialNumberRequest;
import com.pi4j.io.serial.*;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
public class SerialPortManager
{
private static final SerialPortManager SERIAL_PORT_MANAGER = new SerialPortManager();
private static Serial serial;
private SerialDataEventListener listener;
public static SerialPortManager getInstance()
{
return SERIAL_PORT_MANAGER;
}
public void init()
{
if (connect())
{
Device.isConnect = true;
startReceiveData();
Parameter.threadPoolExecutor.execute(this::startSendData);
Parameter.threadPoolExecutor.execute(this::getSn);
return;
}
Device.isConnect = false;
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
new ParameterManager(false).start();
}
private void startReceiveData()
{
final DataLinkParserUtil parserUtil = new DataLinkParserUtil();
serial.addListener(listener = event ->
{
try
{
parserUtil.unpackData(event.length(), event.getBytes());
}
catch (IOException ignored)
{
System.out.println("[Serial]inputStream.read(readBuffer):ERROR!");
}
});
}
private void startSendData()
{
OutputStream outputStream = serial.getOutputStream();
while (Device.isConnect && serial.isOpen())
{
try
{
MAVLinkPacket packet = Device.sendCommandQueue.take();
outputStream.write(packet.encodePacket());
outputStream.flush();
}
catch (InterruptedException | IOException e)
{
e.printStackTrace();
}
}
try
{
outputStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
private boolean connect()
{
disconnect();
File file = new File(Parameter.PORT);
if (!file.exists())
{
System.out.println("端口不存在:" + Parameter.PORT);
return false;
}
SerialConfig config = new SerialConfig();
config.device(Parameter.PORT);
config.baud(Baud.getInstance(Parameter.RATE));
serial = SerialFactory.createInstance();
try
{
serial.open(config);
}
catch (IOException e)
{
e.printStackTrace();
return false;
}
System.out.println("端口已打开:" + Parameter.PORT);
return true;
}
public void disconnect()
{
System.out.println("串口断开连接");
Device.isConnect = false;
if (serial == null)
{
return;
}
if (listener != null)
{
serial.removeListener(listener);
}
try
{
serial.close();
serial = null;
}
catch (IOException e)
{
e.printStackTrace();
}
}
private void getSn()
{
int retryNum = 0;
while (Device.isConnect && Util.isEmpty(Device.sn))
{
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("[Serial]Send FCSN request");
Device.sendCommandQueue.offer(new MsgSerialNumberRequest().pack());
if (retryNum > 10)
{
init();
return;
}
retryNum++;
}
}
}
12、安装WiringPi
sudo apt-get remove wiringpi -y
sudo apt-get --yes install git-core gcc make
cd ~
git clone https://github.com/WiringPi/WiringPi --branch master --single-branch wiringpi
cd ~/wiringpi
sudo ./build
13、最终效果如下图
|