Advertisement
sbaldovi

fmfconv_find_encoder.diff

Feb 17th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.14 KB | None | 0 0
  1. Index: fmfconv_ff.c
  2. ===================================================================
  3. --- fmfconv_ff.c    (revision 4888)
  4. +++ fmfconv_ff.c    (working copy)
  5. @@ -264,21 +264,13 @@
  6.  }
  7.  
  8.  static int
  9. -open_audio( void )
  10. +open_audio( AVCodec *codec )
  11.  {
  12.    AVCodecContext *c;
  13. -  AVCodec *codec;
  14.    int ret;
  15.  
  16.    c = audio_st->codec;
  17.  
  18. -    /* find the audio encoder */
  19. -  codec = avcodec_find_encoder( c->codec_id );
  20. -  if( !codec ) {
  21. -    printe( "FFMPEG: audio codec not found\n" );
  22. -    return 1;
  23. -  }
  24. -
  25.      /* open it */
  26.  #ifdef HAVE_FFMPEG_AVCODEC_OPEN2
  27.    ret = avcodec_open2( c, codec, NULL );
  28. @@ -532,21 +524,13 @@
  29.  }
  30.  
  31.  static int
  32. -open_video( void )
  33. +open_video( AVCodec *codec )
  34.  {
  35. -  AVCodec *codec;
  36.    AVCodecContext *c;
  37.    int ret;
  38.  
  39.    c = video_st->codec;
  40.  
  41. -    /* find the video encoder */
  42. -  codec = avcodec_find_encoder( c->codec_id );
  43. -  if( !codec ) {
  44. -    printe( "FFMPEG: video codec not found\n" );
  45. -    return 1;
  46. -  }
  47. -
  48.    if( codec->pix_fmts == NULL )
  49.       c->pix_fmt = PIX_FMT_YUV420P;
  50.    else
  51. @@ -689,7 +673,7 @@
  52.  out_write_ffmpegheader( void )
  53.  {
  54.  
  55. -  AVCodec *c;
  56. +  AVCodec *ac, *vc;
  57.    enum CodecID acodec, vcodec;
  58.  
  59.    ff_picture = NULL;
  60. @@ -736,19 +720,32 @@
  61.         and initialize the codecs */
  62.    video_st = NULL;
  63.    audio_st = NULL;
  64. +  vc = NULL;
  65. +  ac = NULL;
  66.    vcodec = fmt->video_codec;
  67.    acodec = fmt->audio_codec;
  68. +
  69.    if( out_t == TYPE_FFMPEG && vcodec != CODEC_ID_NONE ) {
  70. -    AVCodec *c;
  71. +
  72. +    /* Find the video encoder requested by user selection */
  73.      if( ffmpeg_vcodec != NULL && *ffmpeg_vcodec != 0 ) {
  74. -      c = avcodec_find_encoder_by_name( ffmpeg_vcodec );
  75. -      if( c && c->type == AVMEDIA_TYPE_VIDEO ) {
  76. -        vcodec = c->id;
  77. +      vc = avcodec_find_encoder_by_name( ffmpeg_vcodec );
  78. +      if( vc && vc->type == AVMEDIA_TYPE_VIDEO ) {
  79. +        vcodec = vc->id;
  80.        } else {
  81.          printe( "FFMPEG: Unknown video encoder '%s'.\n", ffmpeg_vcodec );
  82.          return 1;
  83.        }
  84. +    } else {
  85. +      /* Find the video encoder suggested by file format */
  86. +      vc = avcodec_find_encoder( vcodec );
  87.      }
  88. +
  89. +    if( !vc || vc->type != AVMEDIA_TYPE_VIDEO ) {
  90. +      printe( "FFMPEG: video codec not found.\n" );
  91. +      return 1;
  92. +    }
  93. +
  94.      if( ffmpeg_rescale == TYPE_NONE ) {
  95.        out_w = frm_w; out_h = frm_h;
  96.      } else if( ffmpeg_rescale == TYPE_RESCALE_X ) {
  97. @@ -760,24 +757,39 @@
  98.      if( add_video_stream( vcodec, out_w, out_h, machine_timing[frm_mch - 'A'] ) )
  99.        return 1;
  100.    }
  101. +
  102.    if( snd_t == TYPE_FFMPEG && acodec != CODEC_ID_NONE ) {
  103. +
  104. +    /* Find the audio encoder requested by user selection */
  105.      if( ffmpeg_acodec != NULL && *ffmpeg_acodec != 0 ) {
  106. -      c = avcodec_find_encoder_by_name( ffmpeg_acodec );
  107. +      ac = avcodec_find_encoder_by_name( ffmpeg_acodec );
  108.  
  109. -      if( c && c->type == AVMEDIA_TYPE_AUDIO ) {
  110. -        acodec = c->id;
  111. +      if( ac && ac->type == AVMEDIA_TYPE_AUDIO ) {
  112. +        acodec = ac->id;
  113.        } else {
  114.          printe( "FFMPEG: Unknown audio encoder '%s'.\n", ffmpeg_acodec );
  115. +        close_video();
  116. +        return 1;
  117.        }
  118. +    } else {
  119. +      /* Find the audio encoder suggested by file format */
  120. +      ac = avcodec_find_encoder( acodec );
  121. +    }
  122.  
  123. -        /* check that the encoder supports s16 pcm input */
  124. -      if( !check_sample_fmt( c, AV_SAMPLE_FMT_S16 ) ) {
  125. -        printe( "FFMPEG: Encoder %s does not support sample format %s\n",
  126. -                ffmpeg_acodec, av_get_sample_fmt_name( AV_SAMPLE_FMT_S16 ) );
  127. -        exit(1);
  128. -      }
  129. +    if( !ac || ac->type != AVMEDIA_TYPE_AUDIO ) {
  130. +      printe( "FFMPEG: audio codec not found.\n" );
  131. +      close_video();
  132. +      return 1;
  133. +    }
  134.  
  135. +    /* check that the encoder supports s16 pcm input */
  136. +    if( !check_sample_fmt( ac, AV_SAMPLE_FMT_S16 ) ) {
  137. +      printe( "FFMPEG: Encoder %s does not support sample format %s\n",
  138. +              ac->name, av_get_sample_fmt_name( AV_SAMPLE_FMT_S16 ) );
  139. +      close_video();
  140. +      return 1;
  141.      }
  142. +
  143.      if( add_audio_stream( acodec, snd_rte, snd_chn > 1 ? 1 : 0 ) ) {
  144.        close_video();
  145.        return 1;
  146. @@ -794,16 +806,16 @@
  147.      return 1;
  148.    }
  149.  #endif
  150. -/* dump_format( oc, 0, out_name, 1 ); */
  151. +/* av_dump_format( oc, 0, out_name, 1 ); */
  152.  
  153.      /* now that all the parameters are set, we can open the audio and
  154.         video codecs and allocate the necessary encode buffers */
  155. -  if( video_st && open_video() ) {
  156. +  if( video_st && open_video( vc ) ) {
  157.      close_video();
  158.      close_audio();
  159.      return 1;
  160.    }
  161. -  if( audio_st && open_audio() ) {
  162. +  if( audio_st && open_audio( ac ) ) {
  163.      close_video();
  164.      close_audio();
  165.      return 1;
  166. Index: fmfconv.c
  167. ===================================================================
  168. --- fmfconv.c   (revision 4888)
  169. +++ fmfconv.c   (working copy)
  170. @@ -1743,7 +1743,6 @@
  171.        } else if( !strcmp( optarg, "ipod" ) ) {
  172.     ffmpeg_rescale = TYPE_RESCALE_WH;
  173.     out_w = 320; out_h = 240; out_fps = 30000;
  174. -   ffmpeg_acodec = "aac"; ffmpeg_vcodec = "libx264";
  175.     ffmpeg_format = "ipod"; ffmpeg_arate = 128000;ffmpeg_vrate = 256000;
  176.     out_rte = 44100; sound_stereo = 1; ffmpeg_libx264 = 1;
  177.        } else {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement