织梦CMS - 轻松建站从此开始!

罗索

ffmpeg实现转码一个普通视频文件为视频mpeg4,音频mp3的功能的程(2)

jackyhwei 发布于 2010-09-21 14:46 点击:次 
(oVcc-coded_frameoVcc-coded_frame-key_frame) pkt.flags|=PKT_FLAG_KEY; pkt.flags=packet.flags; pkt.stream_index=video_st-index; pkt.data=video_outbuf; pkt.size=out_size; ret=av_write_frame(oc,pkt); } f
TAG:

(oVcc->coded_frame && oVcc->coded_frame->key_frame)                                        
  • pkt.flags |= PKT_FLAG_KEY;                                         
  • pkt.flags = packet.flags;                       
  • pkt.stream_index= video_st->index;                                                
  • pkt.data= video_outbuf;                                                          
  • pkt.size= out_size;                                              
  • ret=av_write_frame(oc, &pkt);                                        
  •              frame_index++; 
  •          } 
  •          else 
  •              ret=av_write_frame(oc, &packet);  
  • if(ret!=0) 
  • printf("while write video frame error\n"); 
  • exit(0); 
  •       else if(packet.stream_index==audioindex) 
  •       { 
  • len=packet.size; 
  • ptr=packet.data; 
  • int ret=0; 
  • while(len>0) 
  • out_buf=NULL; 
  • out_size=0; 
  • if(&packet) 
  • samples=av_fast_realloc(samples,&samples_size,
  • FFMAX(packet.size*sizeof(*samples),
  • AVCODEC_MAX_AUDIO_FRAME_SIZE)); 
  • out_size=samples_size; 
  • ret=avcodec_decode_audio(aCodecCtx,samples,&out_size,ptr,len);
  • if(ret<0) 
  • printf("while decode audio failure\n"); 
  • exit(0); 
  • fflush(stdout); 
  • ptr+=ret; 
  • len-=ret; 
  • if(out_size<=0)  continue
  • out_buf=(uint8_t *)samples; 
  • AVPacket pkt; 
  • av_init_packet(&pkt); 
  • pkt.size= avcodec_encode_audio(oAcc, audio_outbuf, audio_outbuf_size, out_buf); 
  • pkt.pts= av_rescale_q(oAcc->coded_frame->pts, oAcc->time_base, audio_st->time_base); 
  • pkt.flags |= PKT_FLAG_KEY; 
  • pkt.stream_index= audioindex; 
  • pkt.data= audio_outbuf; 
  • if (av_write_frame(oc, &pkt) != 0)  
  • fprintf(stderr, "Error while writing audio frame\n"); 
  • exit(1); 
  • }  
  • av_free_packet(&packet); 
  • }  
  • av_write_trailer(oc); 
  • for(i = 0; i < oc->nb_streams; i++)  
  • {             
  •   av_freep(&oc->streams[i]->codec);                        
  •   av_freep(&oc->streams[i]);                            
  • url_fclose(oc); 
  • av_free(oc); 
  • av_free(oVFrame); 
  • av_free(out_buf); 
  • avcodec_close(vCodecCtx); 
  • avcodec_close(aCodecCtx); 
  • av_close_input_file(ic); 
  •  

    (秩名)
    本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201009/10193.html]
    本文出处:网络 作者:秩名
    顶一下
    (1)
    33.3%
    踩一下
    (2)
    66.7%
    ------分隔线----------------------------
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    评价:
    表情:
    用户名: 验证码:点击我更换图片
    栏目列表
    将本文分享到微信
    织梦二维码生成器
    推荐内容