FFMPEG를 사용하여 mp4 파일 생성 프로젝트를 진행 중입니다. FFMPEG muxing, remuxing 코드를 기반으로하는 비디오 패킷의 스트림 정보를 변환하려고 시도했지만 파일이 손상되어 손상된 것으로 간주됩니다. . 사용하여 헤더 정보 변경avformat_write_header가 ffmepg에서 제대로 작동하지 않습니다.
/* 사용이 코드 세트 스트림 정보 */
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;
: 은/*이 코드/
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를 사용합니다. 이 같은 오류가 :
/이 오류 메시지/
[mpeg4 @ 0x7ff2b9811c00] header damaged Last message repeated 39 times [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ff2ba800000] decoding for stream 0 failed [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ff2ba800000] Could not find codec parameters for stream 0 (Video: mpeg4 (mp4v/0x7634706D), none, 376 kb/s): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options.
작동하지 않는 헤더 (바이트)를 표시 할 수 있다면 도움이됩니다. 어쩌면 코드가 엉망이거나 중요한 정보를 건너 뛰는 것일까 요? –
확실히, 필요한 정보는 모두 mp4 파일의 헤더를 설정해야합니까? –
MP4 헤더의 모든 항목은 여기에서 확인할 수 있습니다. [** MP4 Atoms **] (https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html). _ "코덱 매개 변수를 찾을 수 없습니다"- SPS 및 PPS를 추가하여 디코더가 실제로 이미지를 표시 할 수있게 도와 줍니까?더 나은 방법은 간단한 예제 파일 (몇 메가 이하)을 넣거나 _corrupt_ 헤더의 바이트를 복사하여 붙여 넣는 것입니다 (16 진수 편집기를 통해). 질문에 숫자 (바이트)를 붙일 수없는 경우 Pastebin.com을 사용하십시오. –