Home > Uncategorized > Convert #3gp to #wav in c# using #ffmpeg

Convert #3gp to #wav in c# using #ffmpeg

3gp

I recently found today that Android’s native audio recording format is 3GP ( 3rd Generation Partnership Project ), which may need to be decoded to a decompressed raw format like WAV before you do certain processing on it. My first google searches led me to Alvas, which seemed good, but their trial version has a nag screen that would break IIS, and I didn’t want to pay.

So, I turned to FFMPEG, a free tool, that’s typically used for Video conversion, but also works on audio. The command from the CLI is

ffmpeg -i bible.3gp bible.wav

Which generates the following dump of data;

ffmpeg version N-93863-g58d167bcd5 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.3.1 (GCC) 20190414
configuration: –enable-gpl –enable-version3 –enable-sdl2 –enable-fontconfig –enable-gnutls –enable-iconv –enable-libass –enable-libdav1d –enable-libbluray –enable-libfreetype –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libopenjpeg –enable-libopus –enable-libshine –enable-libsnappy –enable-libsoxr –enable-libtheora –enable-libtwolame –enable-libvpx –enable-libwavpack –enable-libwebp –enable-libx264 –enable-libx265 –enable-libxml2 –enable-libzimg –enable-lzma –enable-zlib –enable-gmp –enable-libvidstab –enable-libvorbis –enable-libvo-amrwbenc –enable-libmysofa –enable-libspeex –enable-libxvid –enable-libaom –enable-libmfx –enable-amf –enable-ffnvcodec –enable-cuvid –enable-d3d11va –enable-nvenc –enable-nvdec –enable-dxva2 –enable-avisynth –enable-libopenmpt
libavutil 56. 27.100 / 56. 27.100
libavcodec 58. 52.101 / 58. 52.101
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 53.100 / 7. 53.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘bible.3gp’:
Metadata:
major_brand : 3gp6
minor_version : 256
compatible_brands: isom3gp6
creation_time : 2015-07-24T19:40:33.000000Z
Duration: 00:04:03.30, start: 0.000000, bitrate: 229 kb/s
Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 320×180 [SAR 1:1 DAR 16:9], 193 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
Metadata:
creation_time : 2015-07-24T19:40:33.000000Z
handler_name : IsoMedia File Produced by Google, 5-11-2011
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, mono, fltp, 32 kb/s (default)
Metadata:
creation_time : 2015-07-24T19:40:33.000000Z
handler_name : IsoMedia File Produced by Google, 5-11-2011
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, wav, to ‘bible.wav’:
Metadata:
major_brand : 3gp6
minor_version : 256
compatible_brands: isom3gp6
ISFT : Lavf58.27.103
Stream #0:0(eng): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s (default)
Metadata:
creation_time : 2015-07-24T19:40:33.000000Z
handler_name : IsoMedia File Produced by Google, 5-11-2011
encoder : Lavc58.52.101 pcm_s16le
size= 10478kB time=00:04:03.29 bitrate= 352.8kbits/s speed=22.7x
video:0kB audio:10478kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000727%

To, write the same code in C# it’s

Process p = new Process
{
StartInfo =
{
FileName = @”D:\Research\ffmpeg.exe”,
Arguments = @”-i d:\research\bible.3gp d:\research\bible.wav”,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true,
UseShellExecute = false
}
};
p.Start();
p.WaitForExit();

.. And yes, I’m using a file called bible.3gp, not that I’m in any way religious, it was just the first 3gp file I could find online.

This code also works in a ASP.NET page, hosted by IIS, without elevated privileges.

FYI, this code is going to be used in an upcomming Android app for www.cloudansweringmachine.com

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: