I want to exchange 16kHz pcm --> 48kHz wav using sox.
however, pcm file isn't applied in sox.
so, I just changed pcm to raw,
and then
sox -r 16000 -e signed -b 16 -c 1 test.raw -r 48000 out.wav
Can I apply for pcm file not convert raw?
For the PCM file, since PCM's are headerless, you need to add '-t raw' as the first argument.
sox -t raw -r 16000 -e signed -b 16 -c 1 test.raw -r 48000 out.wav
Try that out.
Also try the different Endian settings; -L; -B; -x
though only use one at a time, and only if not using one doesn't work.
There is no need to convert the input file into raw. Sox can handle pcm files.
sox input.pcm -r 48000 output.wav
The input file can either be a .pcm or .wav.
Since .wav files have a header containing audio metadata (such as sample rate, bit precision, file length, etc), you don't have to pass any information about the input file. Hence, non need to use:
-r 16000 -e signed -b 16 -c 1
Converting pcm to raw you have just stripped down the file header.
Related
I have a ROM that I can flash on Samsung S10 5G(Qualcomm) successfully. My goal is to check whether I can modify system.img file of the ROM or not but before modification, I just want to verify that the AP file can be flashed after unpacking and packing of the system.img. To check this I have tried following:
Unpack-Pack AP file:
A) tar flashing:
Extracted AP file using tar -xf AP...tar.md5 command.
Compress the extracted files using tar -cvf AP...tar *
Flash it with Odin3 v3.13.
B) tar.md5 flashing:
- Get tar by following steps in A) and then run md5sum -t AP...tar >> AP...tar and mv AP...tar AP...tar.md5
Both Ap...tar and AP...tar.md5 flashed successfully.
Unpack-Pack system.img.ext4.lz4
Extracted AP file using tar -xf AP...tar.md5 command. Extracted files are "boot.img.lz4, meta-data, userdata.img.ext4.lz4, carrier.img.ext4.lz4, persist.img.ext4.lz4, vbmeta.img.lz4, dqmdbg.img.ext4.lz4, recovery.img.lz4, vendor.img.ext4.lz4, dtbo.img.lz4, system.img.ext4.lz4".
Extract system file using unlz4 system.img.ext4.lz4 command. This is giving me a system.img.ext4 Android sparse image.
Tried following commands to compress system.img.ext4 without doing any modification:
lz4 system.img.ext4 system.img.ext4.lz4 - Default Compression
lz4 -9 system.img.ext4 system.img.ext4.lz4 - High Compression
lz4 -l system.img.ext4 system.img.ext4.lz4 - Default Compression in Legacy format
lz4 -l -9 system.img.ext4 system.img.ext4.lz4 - High Compression in Legacy format
lz4 -0 -l system.img.ext4 system.img.ext4.lz4 - No Compression in Legacy format
lz4 -B4 system.img.ext4 system.img.ext4.lz4 - Default Compression with Block size 4
lz4 -B5 system.img.ext4 system.img.ext4.lz4 - Default Compression with Block size 5
lz4 -B6 system.img.ext4 system.img.ext4.lz4 - Default Compression with Block size 6
lz4 --no-frame-crc system.img.ext4 system.img.ext4.lz4 - Default Compression with no crc frame
and make an AP file by replacing the original system.img.ext4.lz4 file with the compressed file from above command(one at one time) and tried to flash it but every time it fails with "Odin FAIL! LZ4 is invalid"
LZ4 command detail:
1. Working on Ubuntu 18
2. Using "LZ4 command line interface 64-bits r128, by Yann Collet (Apr 3 2018)"
Tried with "LZ4 command line interface 64-bits v1.9.2, by Yann Collet" but get the same result.
file system.img.ext4.lz4 output:
Original file: system.img.ext4.lz4: LZ4 compressed data (v1.4+).
My version with both LZ4 (r128 and v1.9.2):
For file compressed with legacy flag(-l): system.img.ext4.lz4: LZ4 compressed data (v0.1-v0.9)
For file compressed without legacy flag(-l): system.img.ext4.lz4: LZ4 compressed data (v1.4+)
So, I think it means the file should be compressed without legacy flag.
Size
With -9 flag i.e. High Compression the output file is of 3.3 GB.
Without -9 flag i.e. Default Compression the output file is of 3.6 GB.
The Original file is of size 3.6 GB so, I think high compression should not be used.
But still the same error throws by Odin.
Any suggestion why it is happening?
Use This:
lz4 -B6 --content-size in.img out.img.lz4
For More Info: https://www.mankier.com/1/lz4
Found this solution from: https://forum.xda-developers.com/galaxy-s9/help/how-to-compress-samsung-images-lz4-t3844760
Assuming that system.img.ext4 isn't modified,
lz4 -l -9 system.img.ext4 system.img.ext4.lz4
is supposed to work.
It's strange that it doesn't, although I notice in your example that you are compressing system.img, not system.img.ext4, so it's unclear if it's the same file.
Suggestion 1 : there might be a checksum somewhere that disallow playing with the lz4 payload. That part is system specific, so it can be difficult to know. You'll have to look around.
Suggestion 2 : compare your original system.img.ext4.lz4 with the one produced by recompressing with lz4. Try to figure out the differences (especially, smaller, larger ?)
Suggestion 3 : use a more recent version of lz4. r128 is actually very old. You could locally compile a more recent version such as v1.9.2, which contains ultra modes, able to compress more that -9 (the compression level can be upgraded to -12).
I am using this
passthru("youtube-dl -o '../temp/%(title)s.%(ext)s' --restrict-
filenames --no-part --no-progress --newline --extract-audio --audio-format mp3 -w --audio-quality 0 http://www.youtube.com$vid");
as a part of my code where I download song from youtube-dl, but after downloading it takes 14-15 seconds to convert that to mp3. Is there any way to improve that and make the conversion faster ? Like make avconv use all cores. If so, then how ?
Thank you.
try this:
avconv -i File.webm -threads 2 -acodec libmp3lame -ab 128k -vn -f mp3 file.mp3
You can use 2 or more threads and change bitrate to improve speed of Your script.
Regards
I am trying to stream an audio file in mp3 format using the FFMPEG library to a remote computer, located on the same LAN as the sender. The command i used to stream at the sender is given below:
ffmpeg -re -f mp3 -i sender.mp3 -ar 8000 -f mulaw -f rtp rtp://10.14.35.23:1234
I got the below command on FFMPEG documentation page that generates audio and streams it to port number 1234 on remote computer
ffmpeg -re -f lavfi -i aevalsrc="sin(400*2*PI*t)" -ar 8000 -f mulaw -f rtp rtp://10.14.35.23:1234
I thought i had made relevant changes to this so that the mp3 streaming command will work, but only to know encounter the error which reads
"Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height"
Can anyone tell me what is the wrong parameter here and how to rectify it?
I could figure out the way to stream an audio file using FFMPEG. The command for the same is given below:
ffmpeg -re -f mp3 -i sender.mp3 -acodec libmp3lame -ab 128k -ac 2 -ar 44100 -f rtp rtp://10.14.35.23
Here the audio file 'sender.mp3' is located in the same folder as ffmpeg.exe. In case of a different folder, the full path should be mentioned in the command.
I'd like to reduce the file size of some mp3 audios with sox. I think I can reduce stereo to only 1 channel (i.e. mono), reduce the sample rate and reduce the bit-depth. I find it seems sox can do none of that. Is this true or did I have done it correctly?
$ sox -r 8000 -c 1 2008-12-28-2.MP3 foo.mp3
sox WARN formats: can't set sample rate 8000; using 44100
sox WARN formats: can't set 1 channels; using 2
The arguments should go before the output file:
sox 2008-12-28-2.MP3 -r 8000 -c 1 foo.mp3
They can also be supplied as effects:
sox 2008-12-28-2.MP3 foo.mp3 remix 1 rate 8000
Original Question
I want to be able to generate a new (fully valid) MP3 file from an existing MP3 file to be used as a preview -- try-before-you-buy style. The new file should only contain the first n seconds of the track.
Now, I know I could just "chop the stream" at n seconds (calculating from the bitrate and header size) when delivering the file, but this is a bit dirty and a real PITA on a VBR track. I'd like to be able to generate a proper MP3 file.
Anyone any ideas?
Answers
Both mp3split and ffmpeg are both good solutions. I chose ffmpeg as it is commonly installed on linux servers and is also easily available for windows. Here's some more good command line parameters for generating previews with ffmpeg
-t <seconds> chop after specified number of seconds
-y force file overwrite
-ab <bitrate> set bitrate e.g. -ab 96k
-ar <rate Hz> set sampling rate e.g. -ar 22050 for 22.05kHz
-map_meta_data <outfile>:<infile> copy track metadata from infile to outfile
instead of setting -ab and -ar, you can copy the original track settings, as Tim Farley suggests, with:
-acodec copy
I also recommend ffmpeg, but the command line suggested by John Boker has an unintended side effect: it re-encodes the file to the default bitrate (which is 64 kb/s in the version I have here at least). This might give your customers a false impression of the quality of your sound files, and it also takes longer to do.
Here's a command line that will slice to 30 seconds without transcoding:
ffmpeg -t 30 -i inputfile.mp3 -acodec copy outputfile.mp3
The -acodec switch tells ffmpeg to use the special "copy" codec which does not transcode. It is lightning fast.
NOTE: the command was updated based on comment from Oben Sonne
If you wish to REMOVE the first 30 seconds (and keep the remainder) then use this:
ffmpeg -ss 30 -i inputfile.mp3 -acodec copy outputfile.mp3
try:
ffmpeg -t 30 -i inputfile.mp3 outputfile.mp3
This command also works perfectly.
I cropped my music files from 20 to 40 seconds.
-y : force output file to overwrite.
ffmpeg -i test.mp3 -ss 00:00:20 -to 00:00:40 -c copy -y temp.mp3
you can use mp3cut:
cutmp3 -i foo.mp3 -O 30s.mp3 -a 0:00.0 -b 0:30.0
It's in ubuntu repo, so just: sudo apt-get install cutmp3.
You might want to try Mp3Splt.
I've used it before in a C# service that simply wrapped the mp3splt.exe win32 process. I assume something similar could be done in your Linux/PHP scenario.
I have got an error while doing the same
Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argumentStream mapping:
Fix for me was:
ffmpeg -ss 00:02:43.00 -t 00:00:10 -i input.mp3 -codec:a libmp3lame out.mp3
My package medipack is a very simple command-line app as a wrapper over ffmpeg.
you can achieve trimming your video using these commands:
medipack trim input.mp3 -s 00:00 -e 00:30 -o output.mp3
medipack trim input.mp3 -s 00:00 -t 00:30 -o output.mp3
you can view options of trim subcommand as:
srb#srb-pc:$ medipack trim -h
usage: medipack trim [-h] [-s START] [-e END | -t TIME] [-o OUTPUT] [inp]
positional arguments:
inp input video file ex: input.mp4
optional arguments:
-h, --help show this help message and exit
-s START, --start START
start time for cuting in format hh:mm:ss or mm:ss
-e END, --end END end time for cuting in format hh:mm:ss or mm:ss
-t TIME, --time TIME clip duration in format hh:mm:ss or mm:ss
-o OUTPUT, --output OUTPUT
you could also explore other options using medipack -h
srb#srb-pc:$ medipack --help
usage: medipack.py [-h] [-v] {trim,crop,resize,extract} ...
positional arguments:
{trim,crop,resize,extract}
optional arguments:
-h, --help show this help message and exit
-v, --version Display version number
you may visit my repo https://github.com/srbcheema1/medipack and checkout examples in README.