2013-08-22 4 views
1

나는 mp2에서 비디오를 디코딩하고 mp4로 인코딩합니다.FFmpeg - C - 인코딩 비디오 - 가로 세로 비율 설정

원본 파일 :

Video: mpeg2video (Main) ([2][0][0][0]/0x0002), yuv420p, 720x576 [SAR 64:45 DAR 16:9]

결과 파일 :

Video: mpeg4 (Simple Profile) (mp4v/0x7634706D), yuv420p, 720x576 [SAR 1:1 DAR 5:4]

당신이 볼 수 있듯이, 해상도가 변경되지 않았습니다 만, 가로 세로 비율이 있습니다.

제 질문은 어떻게 이러한 값 (SAR 및/또는 DAR)을 설정할 수 있습니까?

답변

1

출력 가로 세로 비율을 설정하려면 '-aspect'옵션을 사용할 수 있습니다 (ffmpeg documentation 참조).

-aspect[:stream_specifier] aspect (output,per-stream)’ 

    Set the video display aspect ratio specified by aspect. 

    aspect can be a floating point number string, or a string of the form num:den, where num and den are the numerator and denominator of the aspect ratio. For example "4:3", "16:9", "1.3333", and "1.7777" are valid argument values. 

    If used together with ‘-vcodec copy’, it will affect the aspect ratio stored at container level, but not the aspect ratio stored in encoded frames, if it exists. 
+0

, 나는 그래 난 태그를 참조 C. – Knossos

+0

Oups 함께 일하고,하지만 당신이는 FFmpeg 라이브러리를 사용하는 솔루션을 필요로하는 질문 자체가 너무 분명하지 않다 .. 어쩌면 인코더 초기화에 사용 된 코드를 추가하고 libav, libavcodec, libavformat ...에 대한 태그를 추가하십시오. – alexbuisson

+0

태그가 추가되었습니다. 행운을 빌어 요 – alexbuisson

0

인코딩 할 새 비디오 스트림을 추가하려고 할 때 설정할 수 있습니다. avformat_new_stream()을 사용하여 새 스트림을 추가 한 직후입니다. 명령 행는 FFmpeg에만 관련이

AVOutputFormat *outfmt = NULL; 
AVStream *out_vid_strm; 
AVCodec *out_vid_codec; 
outformat = avformat_alloc_context(); 
if(outformat) 
{ 
    PRINT_MSG("Got Output context ") 
     outformat->oformat = outfmt; 
    _snprintf(outformat->filename, sizeof(outformat->filename), "%s", (const char*)outfile); 
    if(outfmt->video_codec != AV_CODEC_ID_NONE) 
    { 
     out_vid_codec = avcodec_find_encoder(outfmt->video_codec); 
     if(NULL == out_vid_codec) 
     { 
      PRINT_MSG("Could Not Find Vid Encoder") 
     } 
     else 
     { 
      PRINT_MSG("Found Out Vid Encoder ") 
       out_vid_strm = avformat_new_stream(outformat, out_vid_codec); 
      if(NULL == out_vid_strm) 
      { 
       PRINT_MSG("Failed to Allocate Output Vid Strm ") 
      } 
      else 
      { 
       out_vid_strm->sample_aspect_ratio.den = 1; 
       out_vid_strm->sample_aspect_ratio.num = 1; 
       out_vid_strm->time_base.num = in_vid_strm->time_base.num; 
       out_vid_strm->time_base.den = in_vid_strm->time_base.den; 
       out_vid_strm->r_frame_rate.den = in_vid_strm->r_frame_rate.den; 
       out_vid_strm->r_frame_rate.num = in_vid_strm->r_frame_rate.num; 
      } 
     } 
    } 
} 
+0

코드의 어느 부분에서 디스플레이 종횡비를 설정합니까? 그것은 귀하의 발췌 문장에 다른 변수를 설정하는 부분으로 자동 완성됩니까? – Knossos

+0

out_vid_strm-> sample_aspect_ratio.den = 1; out_vid_strm-> sample_aspect_ratio.num = 1입니다. 이것은 종횡비를 설정해야합니다. – praks411

관련 문제