2017-03-23 22 views
0

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.

+0

작동하지 않는 헤더 (바이트)를 표시 할 수 있다면 도움이됩니다. 어쩌면 코드가 엉망이거나 중요한 정보를 건너 뛰는 것일까 요? –

+0

확실히, 필요한 정보는 모두 mp4 파일의 헤더를 설정해야합니까? –

+0

MP4 헤더의 모든 항목은 여기에서 확인할 수 있습니다. [** MP4 Atoms **] (https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html). _ "코덱 매개 변수를 찾을 수 없습니다"- SPS 및 PPS를 추가하여 디코더가 실제로 이미지를 표시 할 수있게 도와 줍니까?더 나은 방법은 간단한 예제 파일 (몇 메가 이하)을 넣거나 _corrupt_ 헤더의 바이트를 복사하여 붙여 넣는 것입니다 (16 진수 편집기를 통해). 질문에 숫자 (바이트)를 붙일 수없는 경우 Pastebin.com을 사용하십시오. –

답변

0

가장 쉬운 것은 단지 (특정 O.S에 대한) 프리웨어 16 진수 편집기을 다운로드하는 것입니다.

  • 이 코드를 사용하여 변환 출처 : 다음 사용 바탕 화면 (커맨드)는 FFmpeg의 버전입니다

    • 사용 MP4에 소스를 변환 할 수있는 커맨드는 FFmpeg (mp4_ffmpeg.mp4예) (A 정적 빌드를 다운로드)
    • 열기 모두 mp4_ffmpeg.mp4 & mp4_code.mp4 바이트 비교 : MP4 (mp4_code.mp4예)합니다. 작동하는 코드는 mp4_ffmpeg.mp4이어야하며 코드로 생성 된 바이트와 다른 점은 무엇입니까? 모든 ftyp로 시작

      • :

      상황이를 찾기 위해?

    • moov

    • 헤더과에서 다시 한 덩어리의 모든 A/V 데이터를 보유 mdat 후 때때로 (시작해야 앞으로 어떤 MP4의 헤더를 이동하거나 다음 명령 줄 사용 예를 들어 -movflags +faststart을 사용하여 바이트를 시작하십시오. : 당신은 단어의 4 개 글자를 건너 후
      ffmpeg -i myfile.avi -movflags +faststart newfile.mp4) 단어 moov 또는 mdat의 각 전에

    • 이전 4 바이트) 바이트 (크기입니다 ...이 크기가 정확한지?

    • 모든 MP4 아톰 (메타 데이터 섹션)을 정의 했습니까? 그것들은 FFmpeg가 MP4 변환 버전을 위해 제작 한 것과 일치합니까?