To encode image using jbig2enc - compression

I am trying to encode image using JBIG2 encoder that I have installed using Macports.
https://ports.macports.org/port/jbig2enc/
I have also installed leptonica from Macports:
https://ports.macports.org/port/leptonica/
The system seems to have installed it:
% jbig2 -V --version
jbig2enc 0.28
Also, from jbig2 --help I am getting this
% jbig2 --help
Usage: jbig2 [options] <input filenames...>
Options:
-b <basename>: output file root name when using symbol coding
-d --duplicate-line-removal: use TPGD in generic region coder
-p --pdf: produce PDF ready data
-s --symbol-mode: use text region, not generic coder
-t <threshold>: set classification threshold for symbol coder (def: 0.85)
-T <bw threshold>: set 1 bpp threshold (def: 188)
-r --refine: use refinement (requires -s: lossless)
-O <outfile>: dump thresholded image as PNG
-2: upsample 2x before thresholding
-4: upsample 4x before thresholding
-S: remove images from mixed input and save separately
-j --jpeg-output: write images from mixed input as JPEG
-a --auto-thresh: use automatic thresholding in symbol encoder
--no-hash: disables use of hash function for automatic thresholding
-V --version: version info
-v: be verbose
As the encoder refers to https://github.com/agl/jbig2enc for encoding the images I tried the command they have mentioned for encoding:
$ jbig2 -s feyn.tif >feyn.jb2
I ran it for an image original.jpg, This is what I am getting:
> jbig2 -s original.jpg >original.jb2
[1] 43894
zsh: command not found: gt
zsh: command not found: original.jb2
sahilsharma#Sahils-Air ~ % JBIG2 compression complete. pages:1 symbols:5 log2:3
?JB2
?|?n6?Q?6?(m?զu? Y???_?&??1???<?CJ?????#Rᮛ?O?V??:?,??i4?A?????5?;ސA??-!????5Ѧ??/=n܄?*?#|J6#?J?6?N1?n??v?"E}?.~?+????ڜ?]HO_b??~?[??????S2p𩗩????fC?????X?Z?????X=?m?????
??jN?????i????S?,j6???Br?V??F???8?w?#?6? uK?V??R?s~F-?F%?j????]j???0?!GG"'?!??)2v??K???h-???1
[1] + done jbig2 -s original.jpg
According to '--help', '-s' will do the lossless encoding.
The execution shows JBIG2 compression completed but no jb2 files have been formed.
Please help me in getting to know if the compression has taken place? Then where can I get the encoded image?
I am running this encoder to get to know the compression ratio. So I just want to know the encoded image size.

Use >, not >. The result will then be in feyn.jb2.

Related

Odin FAIL! LZ4 is invalid

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).

youtube-dl command saves as flv and not mp3

So below is my command that I am running. It should be converting it to mp3 but it still exports as a video in flv. What am I doing wrong?
$cmd = '/usr/local/bin/youtube-dl -o "%(title)s.%(ext)s" -x --audio-format mp3 -- '.escapeshellarg($url).'';
youtube-dl will download the video before converting it. Most likely, you don't have ffprobe or ffmpeg installed. Make sure both programs are available (i.e. you get a sensible output for ffprobe --help and ffmpeg --help).
You can directly download the .mp3 file from the youtube site.
For e.g in ubuntu terminal youtube-dl youtube.com/watch?v=qn6CMz18lkQ -f 141 .Most probably 141 is the .mp3 file format code for better quality.

how to use sox to compress mp3?

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

How to generate a thumbnail of flash movie (.flv)

I'm using ColdFusion and need to generate a thumbnail from a flash movie stored on the server. I have heard of ffMpeg but have no idea how to use it. (Once you put it on your server what's the next step?)
You can use cfexecute to run a command line on the CF server.
Karthik linked a blog post that suggests the following syntax for ffmpeg:
ffmpeg -itsoffset -4 -i test.avi
-vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
So you could do something like this:
<cfexecute
name="c:\pathto\ffmpeg\ffmpeg.exe"
arguments="-itsoffset -4 -i #sourcevideo# -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 #thumbnaildestination" />
I haven't run ffmpeg like this and you'll likely need to experiment with the syntax to get a result you like, but once you do your workflow is pretty straightforward.
You may also run into issues executing fmpeg.exe depending on the user account your ColdFusion server instance is running as.
Documentation of FFMpeg: http://www.ffmpeg.org/documentation.html
You might want to check: http://blog.prashanthellina.com/2008/03/29/creating-video-thumbnails-using-ffmpeg/
http://www.flashcomguru.com/index.cfm/2006/4/25/ffmpegthumbs
with ColdFusion its not possible but check this: http://old.nabble.com/Create-a-thumbnail-image-from-.flv-video-file-once-uploaded-td22683497.html

Crop MP3 to first 30 seconds

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.