FFmpeg 保存 h264 acc为 ts文件

时间: 2023-09-20 17:11:07 浏览: 62
要使用 FFmpeg 将 H.264 和 AAC 流保存为 TS 文件,可以使用以下命令: ``` ffmpeg -i input.mp4 -c:v copy -c:a copy -f mpegts output.ts ``` 这将从 `input.mp4` 中提取 H.264 视频和 AAC 音频流,并将它们复制到一个 TS 文件 `output.ts` 中。 如果输入文件中包含多个音频流,你可以使用 `-map` 参数选择要复制的音频流。例如,如果你想要选择第二个音频流: ``` ffmpeg -i input.mp4 -c:v copy -c:a:1 copy -f mpegts output.ts ``` 在上面的命令中,`-c:a:1` 表示选择第二个音频流。 如果你想要将 H.264 视频重新编码为另一种视频编解码器,例如 H.265,可以使用以下命令: ``` ffmpeg -i input.mp4 -c:v libx265 -c:a copy -f mpegts output.ts ``` 这将使用 libx265 编码器将 H.264 视频重新编码为 H.265,并将音频流复制到 TS 文件中。 注意:如果你想要在 Android 应用程序中使用 FFmpeg,你需要将 FFmpeg 编译为 Android 平台上的静态库,并在你的应用程序中使用它。
相关问题

Java FFmpeg 把h264 acc实时流 保存 ts格式文件

要在Java中使用FFmpeg将H264和AAC实时流保存为ts格式文件,可以参考以下步骤: 1. 首先,需要在Java项目中引入FFmpeg库,可以使用JavaCV库,或者自己编译FFmpeg库。 2. 接下来,使用FFmpeg库的API进行实时流转换和保存。可以使用如下命令将H264和AAC实时流转换为ts格式并保存: ``` ffmpeg -i rtmp://input_stream_url -c:v copy -c:a copy -f mpegts -mpegts_flags initial_discontinuity -y output.ts ``` 其中,`rtmp://input_stream_url`是输入的实时流地址,`output.ts`是输出的ts文件路径。 在Java中,可以使用JavaCV库的`FFmpegFrameGrabber`和`FFmpegFrameRecorder`类来实现实时流的抓取和保存。 3. 最后,需要在Java中编写相应的代码,将实时流抓取和保存的过程连接起来,实现实时流转换和保存。 ``` FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtmp://input_stream_url"); grabber.start(); FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("output.ts", grabber.getImageWidth(), grabber.getImageHeight(), grabber.getAudioChannels()); recorder.setFormat("mpegts"); recorder.setFrameRate(grabber.getFrameRate()); recorder.setPixelFormat(grabber.getPixelFormat()); recorder.setSampleRate(grabber.getSampleRate()); recorder.setAudioChannels(grabber.getAudioChannels()); recorder.start(); Frame frame; while ((frame = grabber.grabFrame()) != null) { recorder.record(frame); } recorder.stop(); grabber.stop(); ``` 注意:在使用JavaCV库的API时,需要注意库的版本和API的使用方法,以免造成不必要的错误。同时,也需要注意实时流的格式和编码方式,以保证转换和保存的正确性。

android把h264 acc保存为ts文件

要在 Android 上使用 FFmpeg 将 H.264 和 AAC 流保存为 TS 文件,你需要将 FFmpeg 编译为 Android 平台上的静态库,并在你的应用程序中使用它。 以下是一个使用 FFmpeg 在 Android 上将 H.264 和 AAC 流保存为 TS 文件的示例代码: ```java import java.io.IOException; public class FFmpegConverter { static { System.loadLibrary("ffmpeg"); } public native int convertToTS(String inputFilePath, String outputFilePath); public void convert(String inputFilePath, String outputFilePath) throws IOException { int result = convertToTS(inputFilePath, outputFilePath); if (result != 0) { throw new IOException("Failed to convert to TS: " + result); } } } ``` 在上面的代码中,`convertToTS()` 方法使用 JNI 调用 FFmpeg 库来执行转换操作。以下是 `convertToTS()` 方法的实现: ```c #include <jni.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include "libavutil/opt.h" #include "libavutil/samplefmt.h" #include "libavformat/avformat.h" #include "libswresample/swresample.h" #include "libavcodec/avcodec.h" JNIEXPORT jint JNICALL Java_com_example_ffmpegconverter_FFmpegConverter_convertToTS(JNIEnv *env, jobject thiz, jstring input_file_path, jstring output_file_path) { const char *input_path = (*env)->GetStringUTFChars(env, input_file_path, 0); const char *output_path = (*env)->GetStringUTFChars(env, output_file_path, 0); AVFormatContext *input_format_context = NULL; int ret = avformat_open_input(&input_format_context, input_path, NULL, NULL); if (ret < 0) { goto end; } ret = avformat_find_stream_info(input_format_context, NULL); if (ret < 0) { goto end; } AVFormatContext *output_format_context = NULL; ret = avformat_alloc_output_context2(&output_format_context, NULL, "mpegts", output_path); if (ret < 0) { goto end; } for (int i = 0; i < input_format_context->nb_streams; i++) { AVStream *input_stream = input_format_context->streams[i]; AVCodecParameters *input_codec_parameters = input_stream->codecpar; AVCodec *input_codec = avcodec_find_decoder(input_codec_parameters->codec_id); if (!input_codec) { goto end; } AVStream *output_stream = avformat_new_stream(output_format_context, input_codec); if (!output_stream) { goto end; } ret = avcodec_parameters_copy(output_stream->codecpar, input_codec_parameters); if (ret < 0) { goto end; } output_stream->codecpar->codec_tag = 0; if (output_format_context->oformat->flags & AVFMT_GLOBALHEADER) { output_stream->codecpar->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; } } ret = avio_open(&output_format_context->pb, output_path, AVIO_FLAG_WRITE); if (ret < 0) { goto end; } ret = avformat_write_header(output_format_context, NULL); if (ret < 0) { goto end; } AVPacket packet; av_init_packet(&packet); while (av_read_frame(input_format_context, &packet) == 0) { AVStream *input_stream = input_format_context->streams[packet.stream_index]; AVStream *output_stream = output_format_context->streams[packet.stream_index]; packet.pts = av_rescale_q_rnd(packet.pts, input_stream->time_base, output_stream->time_base, AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); packet.dts = av_rescale_q_rnd(packet.dts, input_stream->time_base, output_stream->time_base, AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); packet.duration = av_rescale_q(packet.duration, input_stream->time_base, output_stream->time_base); packet.pos = -1; ret = av_interleaved_write_frame(output_format_context, &packet); if (ret < 0) { goto end; } av_packet_unref(&packet); } ret = av_write_trailer(output_format_context); if (ret < 0) { goto end; } end: if (output_format_context) { avio_closep(&output_format_context->pb); avformat_free_context(output_format_context); } if (input_format_context) { avformat_close_input(&input_format_context); } (*env)->ReleaseStringUTFChars(env, input_file_path, input_path); (*env)->ReleaseStringUTFChars(env, output_file_path, output_path); return ret; } ``` 在 `convertToTS()` 方法中,我们首先打开输入文件并读取流信息,然后创建一个输出格式上下文和输出流,并将输入流的编解码参数复制到输出流中。然后我们打开输出文件并写入头部信息,接着从输入文件中读取数据包,并将其转换为输出流的时间基。最后,我们将包写入输出文件,并在完成后写入尾部信息。 编译 FFmpeg 静态库的详细步骤超出了本回答的范围,但你可以参考一些在线资源,例如 FFmpeg 官方文档和博客,以帮助你完成此任务。

相关推荐

最新推荐

recommend-type

Linux服务器安装ffmpeg+libx264+libmp3lame

ffmpeg既可以播放视频,也提供命令行工具来处理视频,另外还有强大的视频处理库用于开发,下面是以Linux为例介绍ffmpeg的安装流程的简单的命令行对视频进行转码操作。 Linux服务器安装ffmpeg+libx264+libmp3lame
recommend-type

ffmpeg H264解码decode_mb_cavlc函数参数解释

ffmpeg H264解码slice的decode_mb_cavlc函数参数解释
recommend-type

使用 FFmpeg 命令拼接mp3音频文件异常问题及解决方法

主要介绍了使用 FFmpeg 命令拼接mp3音频文件异常问题及解决方法,本文给大家介绍的非常详细,对大家的工作或学习具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用matlab绘制高斯色噪声情况下的频率估计CRLB,其中w(n)是零均值高斯色噪声,w(n)=0.8*w(n-1)+e(n),e(n)服从零均值方差为se的高斯分布

以下是用matlab绘制高斯色噪声情况下频率估计CRLB的代码: ```matlab % 参数设置 N = 100; % 信号长度 se = 0.5; % 噪声方差 w = zeros(N,1); % 高斯色噪声 w(1) = randn(1)*sqrt(se); for n = 2:N w(n) = 0.8*w(n-1) + randn(1)*sqrt(se); end % 计算频率估计CRLB fs = 1; % 采样频率 df = 0.01; % 频率分辨率 f = 0:df:fs/2; % 频率范围 M = length(f); CRLB = zeros(M,1); for
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这