1. jave-2.0.jar 파일 다운로드 (첨부파일)


   1.1 maven 이 지원되지 않는 것 같으므로 프로젝트의 Build Path 에서 Add External JARs를 통해 다운받은 jave2.0.jar 파일을 추가해 준다.


0879a19b4459ce425826875d862c5a54_1545880306_6486.png
 



1.2  프로젝트의 속성에서 Deployment Assembly 에도 추가해 준다.


0879a19b4459ce425826875d862c5a54_1545880384_2366.png
 


Java Build Path에 추가했으므로 Java Build Path Entries를 선택하고 다음


0879a19b4459ce425826875d862c5a54_1545880436_849.png
 


jave-2.0.jar 파일이 보일 것이다.


0879a19b4459ce425826875d862c5a54_1545880506_3494.png
 






2. wav파일과 mp3 파일이 저장된 경로 설정 (context-properties.xml)


<entry key="Globals.wavFileStorePath" value="/Users/ellord/Downloads/Neon3Workspace/ict_uae/src/test/" />



3. ffmpeg 파일을 다운받는다.(ffmpeg.org)


  3.1 OSX경우 brew 로 설치하면 편리함.


brew install ffmpeg



  3.2 Windows의 경우 stable 버전을 다운받는다.


다운로드위치 : https://ffmpeg.zeranoe.com/builds/ 





4. 컨트롤러에서 작업(TestController.java)



import it.sauronsoftware.jave.AudioAttributes;

import it.sauronsoftware.jave.Encoder;

import it.sauronsoftware.jave.EncoderException;

import it.sauronsoftware.jave.EncodingAttributes;

import it.sauronsoftware.jave.FFMPEGLocator;





@Controller

public class TestController {



    @Resource(name = "propertiesService")

    protected EgovPropertyService propertyService;



    @RequestMapping(value = "/test/waveomp3.do", method = RequestMethod.GET)

    public String convert(final ModelMap model) throws Exception {

    

  //경로확인

        String storePathString = propertyService.getString("Globals.wavFileStorePath");

        try{

        

        File source = new File(storePathString + "source.wav");//변환전 파일

        File target = new File(storePathString + "target.mp3");//변환후 파일

        

        AudioAttributes audio = new AudioAttributes();

        audio.setCodec("libmp3lame");

        audio.setBitRate(new Integer(128000));

        audio.setChannels(new Integer(2));

        audio.setSamplingRate(new Integer(44100));

        

        EncodingAttributes attrs = new EncodingAttributes();

        attrs.setFormat("mp3");

        attrs.setAudioAttributes(audio);

        

        //Encoder encoder = new Encoder();

        Encoder encoder = new Encoder(new MyFFMPEGExecutableLocator());

        encoder.encode(source, target, attrs);

        

        }catch(EncoderException e) {

         e.printStackTrace();

        

        }


model.addAttribute("mp3location"torePathString + "target.mp3");//변환된 mp3 파일 경로


  return "뷰파일 경로";

    }




    //ffmpeg 경로

    class MyFFMPEGExecutableLocator extends FFMPEGLocator{

        @Override

        protected String getFFMPEGExecutablePath() {

            // TODO Auto-generated method stub

      String path = "/usr/local/bin/ffmpeg";  //OSX, Linux기준

//String path = "C:\ffmpeg-win64-static\bin\ffmpeg.exe";//Windows 기준

            return path;


        }

    }

    

}




5. 해당 폴더에 mp3파일이 생성되는지 확인



0879a19b4459ce425826875d862c5a54_1545880732_4634.png
 



문의 : apps@ellord.net

jave-2.0.jar.zip


블로그 이미지

엘로드넷

,