我运行ffmpeg命令将我的rails应用程序中的音频文件转换为mp3:
# Convert to MP3
conversion_result = `ffmpeg -i "#{Refile::cache.directory}/#{self.file.id}" -f mp3 "#{_path_to_mp3}" 2>&1`
转换后,conversion_result
的示例如下:
“ffmpeg version N-74748-gbaeb8f5 Copyright(c)2000-2015 the FFmpeg 开发人员\ n用gcc 4.8构建(Ubuntu 4.8.4-2ubuntu1~14.04)\ n 配置: - extra-libs = -ldl --prefix = / opt / ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder = amrnb --disable- decoder = amrwb --enable-libpulse --enable-libdcadec --enable-libfreetype --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab \ n libavutil 54. 31.100 / 54 .31.100 \ n libavcodec 56. 59.100 / 56. 59.100 \ n libavformat 56. 40.101 / 56. 40.101 \ n libavdevice 56. 4.100 / 56. 4.100 \ n libavfilter 5. 40.100 / 5. 40.100 \ n libavresample 2. 1. 0 / 2. 1. 0 \ n libswscale 3. 1.101 / 3. 1.101 \ n libswresample 1. 2.101 / 1. 2.101 \ n libpostproc 53. 3.100 / 53. 3.100 \ n输入#0,mov,mp4,m4a,3gp,3g2,mj2,来自'../mey_attachments/cache/25888dc028deaabaee4d4de19d4726573860dbce0b907131e9919d294113 “:\ n 元数据:\ n major_brand:3gp4 \ n minor_version:0 \ n compatible_brands:isom3gp4 \ n creation_time:2015-09-01 16:34:01 \ n 持续时间:00:00:08.57,开始:0.000000,比特率:426 kb / s \ n流
0:0(eng):音频:aac(LC)(mp4a / 0x6134706D),44100 Hz,单声道,fltp,48 kb / s(默认)\ n元数据:\ n creation_time:2015-09-01 16 :34:01 \ n
handler_name:SoundHandle \ nOutput#0,mp3,to '/tmp/Voice00045.mp3':\ n元数据:\ n major_brand:3gp4 \ n minor_version:0 \ n compatible_brands:isom3gp4 \ n TSSE: Lavf56.40.101 \ n流#0:0(eng):音频:mp3(libmp3lame),44100 Hz, mono,fltp(默认)\ n元数据:\ n creation_time:2015-09-01 16:34:01 \ n handler_name:SoundHandle \ n编码器:Lavc56.59.100 libmp3lame \ nStream映射:\ n流#0:0 - > #0:0(aac(native) - > mp3 (libmp3lame))\ n按[q]停止,[?]求助\ nsize = 67kB 时间= 00:00:08.56比特率= 64.5kbits / s \ nvideo:0kB音频:67kB 副标题:0kB其他流:0kB全局标头:0kB多路复用开销: 0.465427%\ n“个
如何在命令执行后确保转换成功?
答案 0 :(得分:2)
您需要命令的全文输出吗?
因为如果不是我建议您使用system command that will return true如果命令以退出代码0(成功)终止,则为假,如果失败则为nil。
conversion_success = system %Q[ffmpeg -i "#{Refile::cache.directory}/#{self.file.id}" -f mp3 "#{_path_to_mp3}" 2>&1]
请注意,在示例中,我使用%Q[...]
作为字符串,以避免必须转义"
并且能够对命令进行字符串插值。