我正在使用FFMPEG进行mp4文件创建项目,我尝试基于FFMPEG转换视频数据包的流信息,重新编译代码,但是在转换成这样的文件后头部会损坏。
/* this code used to set the stream information */
AVFormatContext *input_context,*output_context;
AVDictionary *opt;
AVStream *out_stream;
AVCodecContext *newcontext = NULL;
out_stream= avformat_new_stream(output_context,NULL);
newcontext = avcodec_alloc_context3(codec);
newcontext->codec_id=Output_fmt->video_codec;
newcontext->bit_rate =in_stream->codec->bit_rate;
newcontext->width = in_stream->codec->width;
newcontext->height = in_stream->codec->height;
newcontext->timecode_frame_start = in_stream->codec->timecode_frame_start;
newcontext->gop_size = in_stream->codec->gop_size;
newcontext->profile = in_stream->codec->profile;
newcontext->level = in_stream->codec->level;
newcontext->pix_fmt = PIX_FMT_YUV420P;
newcontext->frame_size = in_stream->codec->frame_size;
newcontext->sample_fmt = in_stream->codec->sample_fmt;
newcontext->sample_rate = in_stream->codec->sample_rate;
time_base = (double)in_stream->time_base.num / (double)in_stream->time_base.den;
duration = (double)in_stream->duration * time_base * 1000.0;
if (!out_stream) {
fprintf(stderr, "Failed allocating output stream\n");
ret = AVERROR_UNKNOWN;
return;
}
ret = avcodec_copy_context(out_stream->codec,newcontext);
if (ret < 0) {
fprintf(stderr, "Failed to copy context from input to output stream codec context\n");
goto end;
}
out_stream->codec->codec_tag = 0;
if (output_context->oformat->flags & AVFMT_GLOBALHEADER)
out_stream->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;使用以下方法更改标题信息:
/* this code used to set the metadata */
av_dict_set(&opt, "major_brand", "mp42", 0);
av_dict_set(&opt, "minor_version","512" , 0);
av_dict_set(&opt, "compatible_brands","isomiso2avc1mp41",0);
av_dict_set(&opt, "comment","Hash=855738390",0);
output_context->metadata = opt;
ret = avformat_write_header(output_context,NULL);创建mp4文件后,在终端中使用ffmpeg检查文件。出现这样的错误:
/this错误消息/
mpeg4 @ 0x7ff2b9811c00报头重复了39次mov、mp4、m4a、3GP、3G2、mj2 @ 0x7ff2ba800000对流0失败的mov解码,mp4、m4a、3GP、3G2、mj2 @ 0x7ff2ba800000无法为流0找到编解码器参数(视频: mpeg4 (mp4v / 0x7634706D)、none、376 kb/s):未指定的大小考虑增加“分析”和“预配置”选项的值。
发布于 2017-03-26 17:55:19
最简单的方法就是下载一个免费的十六进制编辑器(针对特定的O.S)。接下来是使用FFmpeg的桌面(命令行)版本(下载静态构建)。
mp4_ffmpeg.mp4)mp4_code.mp4)mp4_ffmpeg.mp4和mp4_code.mp4并比较字节。工作的应该是mp4_ffmpeg.mp4,所以与代码生成的字节有什么不同?需要寻找的东西:
ftyp开始moov是头,应该在开始时(有时是在mdat后面,它将所有a/v数据放在一个块中)。要将任何mp4的头移动到前面或开始字节,然后在命令行中使用-movflags +faststart,例如在命令行中:
ffmpeg -i myfile.avi -movflags +faststart newfile.mp4)moov或mdat之前,前4个字节是跳过单词的4个字母之后的大小(以字节为单位).这些尺码对吗?https://stackoverflow.com/questions/42973869
复制相似问题