LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Any s/w to cut/add audio files, convert video to audio? (https://www.linuxquestions.org/questions/linux-software-2/any-s-w-to-cut-add-audio-files-convert-video-to-audio-4175474083/)

ravisingh1 08-20-2013 09:53 PM

Any s/w to cut/add audio files, convert video to audio?
 
I have below 2 queries please:

a) There are audio files from where I want to cut some portions. for ex.
Suppose there is 30 minutes audio file. I want to extract audio from
5 minutes to 8 minutes and from 20 minutes to 24 minutes.
Then I want to add these 2 extractions;i.e. it w'd become 7 minutes
continues audio [(8-5) + (24-20) = 7 minutes ]

b) Also, I want to extract from one video file only audio matter, i.e. convert video to audio.

I searched a lot in google a few months back when I was using Windows7.
Now I am working on ubuntu13.04.
(for my solution, command line from terminal is more preferred)

TobiSGD 08-20-2013 10:15 PM

a) For these tasks I use Audacity, easy to use, but powerful
b) You can do that with ffmpeg, for example with
Code:

ffmpeg -i /path/to/videofile audio.wav

ravisingh1 08-20-2013 11:30 PM

Thanks TobiSGD. I w'd install both audacity and ffmpeg and see how they work.

matrixworld 08-21-2013 02:49 PM

You can try something like this:
Code:

ffmpeg -ss 00:05:00 -t 00:03:00 -i inputfile -acodec copy outputfile1.ext

ffmpeg -ss 00:20:00 -t 00:04:00 -i inputfile -acodec copy outputfile2.ext

To combine

sox outputfile1.ext outputfile2.ext final.ext

To extract audio only from a video

ffmpeg -i inputfile -vn output.mp3

the -ss tells ffmpeg to start at 5 mins in the audio and encode up to 3 mins with the -t option.

inputfile is the source file and outputfile.ext is the output file and extension you desire it to be.

lastly, the -vn tells ffmpeg to rip audio only minus the video.

FrancesAppiah 08-22-2013 04:11 AM

Thank you for your sharing. It works!

matrixworld 08-22-2013 03:53 PM

Quote:

Originally Posted by FrancesAppiah (Post 5013673)
Thank you for your sharing. It works!

You're welcome.

ravisingh1 08-26-2013 10:13 AM

Quote:

Originally Posted by matrixworld (Post 5013311)
You can try something like this:
Code:

ffmpeg -ss 00:05:00 -t 00:03:00 -i inputfile -acodec copy outputfile1.ext

ffmpeg -ss 00:20:00 -t 00:04:00 -i inputfile -acodec copy outputfile2.ext

To combine

sox outputfile1.ext outputfile2.ext final.ext

To extract audio only from a video

ffmpeg -i inputfile -vn output.mp3

the -ss tells ffmpeg to start at 5 mins in the audio and encode up to 3 mins with the -t option.

inputfile is the source file and outputfile.ext is the output file and extension you desire it to be.

lastly, the -vn tells ffmpeg to rip audio only minus the video.

Thanks for your valuable input. But I faced issue. I got the below error when executed the command to rip audio from video.
Code:

ravbholua@ravbholua-Aspire-5315:~$ ffmpeg -i ./Mus*/14082012205--.mp4 -vn check.mp3
ffmpeg version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
  built on Mar 30 2013 22:23:21 with gcc 4.7.2
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 15.00 (15/1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './Music/14082012205--.mp4':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    creation_time  : 2012-08-14 17:02:54
  Duration: 00:27:58.28, start: 0.000000, bitrate: 813 kb/s
    Stream #0.0(und): Video: mpeg4 (Simple Profile), yuv420p, 352x288 [PAR 1:1 DAR 11:9], 763 kb/s, 13.57 fps, 15 tbr, 30k tbn, 30k tbc
    Metadata:
      creation_time  : 2012-08-14 17:02:54
    Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 48 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
Output #0, mp3, to 'check.mp3':
    Stream #0.0(und): Audio: [0][0][0][0] / 0x0000, 16000 Hz, mono, s16, 200 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
Stream mapping:
  Stream #0.1 -> #0.0
Encoder (codec id 86017) not found for output stream #0.0
ravbholua@ravbholua-Aspire-5315:~$

Then I changed the output file extension to .wav and it worked.
But here the problem is the file size of the output file is 54 MB. For nearly 28 minutes audio, 54 MB is very much. I have many files of .amr extensions whose sizes are only 1 MB for the same amount of time. When I give the output file name as .amr extension, it shows the same error.

matrixworld 08-26-2013 11:13 AM

@ ravisingh1

When you export a file to wav format they will produce large files, There's no overcoming that.

For the second issue, the mp3 format should have worked. It is the most popular codec. I convert videos to mp3 files with ffmpeg with no problem.

On some distros ffmpeg is slowly phasing out with it's successor avconv. Have you tried avconv.

Also, did you install the ubuntu restricted extras package, This includes the codecs for playing and encoding multimedia files.

As for the amr, I have no clue. Sorry

ravisingh1 08-26-2013 01:48 PM

Quote:

Originally Posted by matrixworld (Post 5016332)
@ ravisingh1
On some distros ffmpeg is slowly phasing out with it's successor avconv. Have you tried avconv.

Just now I tried avconv but to no avail. Please see the output below
Code:

ravbholua@ravbholua-Aspire-5315:~$ avconv -i ./Mus*/14082012205--.mp4  check.mp3
avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
  built on Mar 30 2013 22:23:21 with gcc 4.7.2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './Music/14082012205--.mp4':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    creation_time  : 2012-08-14 17:02:54
  Duration: 00:27:58.28, start: 0.000000, bitrate: 813 kb/s
    Stream #0.0(und): Video: mpeg4 (Simple Profile), yuv420p, 352x288 [PAR 1:1 DAR 11:9], 763 kb/s, 13.57 fps, 15 tbr, 30k tbn, 30k tbc
    Metadata:
      creation_time  : 2012-08-14 17:02:54
    Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 48 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
Output #0, mp3, to 'check.mp3':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    creation_time  : 2012-08-14 17:02:54
    Stream #0.0(und): Audio: [0][0][0][0] / 0x0000, 16000 Hz, mono, s16, 200 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> ?)
Encoder (codec id 0) not found for output stream #0:0
ravbholua@ravbholua-Aspire-5315:~$

Also I executed
Code:

avconv -codecs
There mp3 was mentioned in the output. A part of the output is as below:
Code:

D A D  mp3            MP3 (MPEG audio layer 3)
 D A D  mp3adu          ADU (Application Data Unit) MP3 (MPEG audio layer 3)
 D A D  mp3adufloat    ADU (Application Data Unit) MP3 (MPEG audio layer 3)
 D A D  mp3float        MP3 (MPEG audio layer 3)
 D A D  mp3on4          MP3onMP4
 D A D  mp3on4float    MP3onMP4

Quote:

Originally Posted by matrixworld (Post 5016332)
Also, did you install the ubuntu restricted extras package, This includes the codecs for playing and encoding multimedia files.

I haven't installed the ubuntu restricted extras package. Please share how to install.

matrixworld 08-26-2013 03:48 PM

Hi ravisingh1

To install type this

Code:

sudo apt-get update
sudo apt-get install ubuntu-restricted-extras

Additional info about the package is found from the link below, it also covers installing libdvdcss to play encrypted DVDs.

https://help.ubuntu.com/community/RestrictedFormats

ravisingh1 08-27-2013 02:46 AM

1 Attachment(s)
Quote:

Originally Posted by matrixworld (Post 5016479)
Hi ravisingh1

To install type this

Code:

sudo apt-get update
sudo apt-get install ubuntu-restricted-extras


Thanks for the info. It worked for me. But some issues I w'd like to address.
1) After running the above command, after some time a window popped up mentioning "end user aggrement". I scrolled down. in bottom 'OK' was written but clicking it doesn't result in anything. I pressed enter and nothing happened. I did wait for 30 minutes but the same window was in screen and didn't proceed ahead. Then I opened another terminal and via ps -ef command, killed the window. Then the other terminal command proceeded ahead. Please see the result in the screen shot attached. Later I got a message from ubuntu saying that something wasn't isntalled and I clicked "install now" in that message to install the remaining.
2)The command which wasn't earlier working now worked. Please have a look below:
Code:

ravbholua@ravbholua-Aspire-5315:~$ avconv -i ./Mus*/14082012205--.mp4  check1.mp3
avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
  built on Mar 30 2013 22:23:21 with gcc 4.7.2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './Music/14082012205--.mp4':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    creation_time  : 2012-08-14 17:02:54
  Duration: 00:27:58.28, start: 0.000000, bitrate: 813 kb/s
    Stream #0.0(und): Video: mpeg4 (Simple Profile), yuv420p, 352x288 [PAR 1:1 DAR 11:9], 763 kb/s, 13.57 fps, 15 tbr, 30k tbn, 30k tbc
    Metadata:
      creation_time  : 2012-08-14 17:02:54
    Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 48 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
[mp3 @ 0x9f12e80] Unsupported sample rate.
Output #0, mp3, to 'check1.mp3':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    TDEN            : 2012-08-14 17:02:54
    TSSE            : Lavf53.21.1
    Stream #0.0(und): Audio: libmp3lame, 16000 Hz, mono, s16, 200 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libmp3lame)
Press ctrl-c to stop encoding
size=  32781kB time=1678.36 bitrate= 160.0kbits/s   
video:0kB audio:32780kB global headers:0kB muxing overhead 0.000480%
ravbholua@ravbholua-Aspire-5315:~$

Please note the output above in bold red.

The output file check1.mp3 created having size of 33.6 MB. But again the same issue of size. You also can understand this is a big size for 28 minutes audio. It's better than .wav file which consumes 54 MB. But still this audio should't be more than 1 MB. The .amr file takes only 1MB. Please see the output of the command when the output file is .amr. This time it hasn't given the previous error (earlier it was saying :no encoder found). But a diff. error. Please see if you can say a solution.
Code:

ravbholua@ravbholua-Aspire-5315:~$ avconv -i ./Mus*/14082012205--.mp4  check1.amr
avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
  built on Mar 30 2013 22:23:21 with gcc 4.7.2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './Music/14082012205--.mp4':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    creation_time  : 2012-08-14 17:02:54
  Duration: 00:27:58.28, start: 0.000000, bitrate: 813 kb/s
    Stream #0.0(und): Video: mpeg4 (Simple Profile), yuv420p, 352x288 [PAR 1:1 DAR 11:9], 763 kb/s, 13.57 fps, 15 tbr, 30k tbn, 30k tbc
    Metadata:
      creation_time  : 2012-08-14 17:02:54
    Stream #0.1(und): Audio: aac, 16000 Hz, mono, s16, 48 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
[libopencore_amrnb @ 0x9bfba40] Only 8000Hz sample rate supported
Output #0, amr, to 'check1.amr':
  Metadata:
    major_brand    : mp42
    minor_version  : 0
    compatible_brands: mp423gp4isom
    creation_time  : 2012-08-14 17:02:54
    Stream #0.0(und): Audio: libopencore_amrnb, 16000 Hz, mono, s16, 200 kb/s
    Metadata:
      creation_time  : 2012-08-14 17:02:56
Stream mapping:
  Stream #0:1 -> #0:0 (aac -> libopencore_amrnb)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
ravbholua@ravbholua-Aspire-5315:~$


ravisingh1 08-27-2013 03:11 AM

Quote:

Originally Posted by matrixworld (Post 5013311)
You can try something like this:
Code:

To combine

sox outputfile1.ext outputfile2.ext final.ext


Whenever I run the above, it show the below error. I tried for .mp3 and .amr.
Code:

ravbholua@ravbholua-Aspire-5315:~$ sox out1.mp3 out2.mp3 final.mp3
sox FAIL formats: no handler for file extension `mp3'
ravbholua@ravbholua-Aspire-5315:~$ sox outputfile1.amr outputfile2.amr final.amr
sox FAIL formats: no handler for file extension `amr'
ravbholua@ravbholua-Aspire-5315:~$


matrixworld 08-27-2013 03:58 PM

Hi ravisingh1

I'm not familiar with amr and its compression scheme. An mp3 file will be larger than amr format.

An average sample rate of 128k will produce 1MB per minute. For example a 4 minute song at 128k will have a file size of around 3 to 5 megabytes.

Your 33MB file is just about average for a 28 minute audio. You can however lower the file size by adjusting the sample and bit rates. Fair warn, the lower the sample and bit rate, the audio quality will degarde as well.

Try this to resample sample rate and bit rate

Code:

ffmpeg -i ./Mus*/14082012205--.mp4 -acodec libmp3lame -ar 22050 -ab 64k check1.mp3
Or

Code:

ffmpeg -i ./Mus*/14082012205--.mp4 -acodec libmp3lame -fs 5M check1.mp3
The last one tells ffmpeg to keep the file size to around 5MB or less using the -fs option. If the length of the audio is too long to fit at 5M, it may go over the 5MB size.

As for sox, I don't think amr is supported. I also tried to convert a wav file to amr and got the same error as well. However, it does support mp3 files as I've use it sometimes to combine mp3 files together.

ravisingh1 08-27-2013 10:20 PM

Quote:

Originally Posted by matrixworld (Post 5017052)
As for sox, I don't think amr is supported. I also tried to convert a wav file to amr and got the same error as well. However, it does support mp3 files as I've use it sometimes to combine mp3 files together.

Thanks for your very valuable info.
Yes you may be right, then it may be a problem from my side which I didn't mention in my last post. That is, the 2 .mp3 files that I was trying to add using "sox" were made from .amr files as shown below:

Code:

ravbholua@ravbholua-Aspire-5315:~$ avconv -i out1.amr out1.mp3
ravbholua@ravbholua-Aspire-5315:~$ avconv -i out2.amr out2.mp3

I only had amr files which didn't work with 'sox'. so I converted them to mp3 as above and ran sox. So, what you say, the resultant output file from the above commands (out1.mp3 and out2.mp3) aren't really .mp3 files??? If they are, then sox should run on them!!!

matrixworld 08-27-2013 11:55 PM

Hi

Can you try this code with avconv on the mp4 file again. To save time, just encode 1 minute of it for a test.

Code:

avconv -ss 0 -t 60 -i ./Mus*/14082012205--.mp4 -vn -c:a libmp3lame -b:a 64k testfile1.mp3
avconv -ss 90 -t 60 -i ./Mus*/14082012205--.mp4 -vn -c:a libmp3lame -b:a 64k testfile2.mp3

sox testfile1.mp3 testfile2.mp3 finalversion.mp3

If avconv and sox goes successfully, than you can do the real encoding of your video file by omitting the -ss and -t parts. Like so

Code:

avconv -i ./Mus*/14082012205--.mp4 -vn -c:a libmp3lame -b:a 64k audio_version.mp3
If you get any errors from avconv or sox, than it's possible the culprit is the mp4 file. It may have something that avconv doesn't recognize or the file is bad or some unknown reason.


All times are GMT -5. The time now is 04:43 AM.