LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-22-2022, 02:01 AM   #1
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Any command to only keep the first 10 seconds of a MIDI file?


Hi.

I've tried some editors. They're very confusing. Is there a terminal command to just keep the first 10 seconds of a .mid file and remove the rest?

Thanks.
 
Old 01-22-2022, 12:09 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,694

Rep: Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716Reputation: 2716
Quote:
Originally Posted by linustalman View Post
Hi.

I've tried some editors. They're very confusing. Is there a terminal command to just keep the first 10 seconds of a .mid file and remove the rest?

Thanks.
Not that I know about, at least not directly.
What editors have you tried? This should be somewhat simple for any decent editor as it is a pretty basic cut job.

Might use midicomp to gen a text file, trim it, then convert it back. I have not tried that.
 
Old 01-22-2022, 12:41 PM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
Debian meta-package multimedia-midi recommends/suggests a lot of tools that have something to do with MIDI. Perhaps, you'll find among them what you're looking for.
 
Old 01-22-2022, 01:00 PM   #4
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Post

Quote:
Originally Posted by wpeckham View Post
Not that I know about, at least not directly.
What editors have you tried? This should be somewhat simple for any decent editor as it is a pretty basic cut job.

Might use midicomp to gen a text file, trim it, then convert it back. I have not tried that.
I've tried MuseScore2+3 & Rosegarden.
 
Old 01-22-2022, 02:34 PM   #5
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
I don't have a .mid at the moment. I think that sox will convert mid to wav.
Code:
sox -t raw -r 44100 -e signed -b 16 -c 1 raw_audio audio.wav
Then you can slice and dice the wav however you wish with ffmpeg.

timidity will too.

Let me find one...
https://www.midiworld.com/download/3964

Code:
file rdeer.mid
rdeer.mid: Standard MIDI data (format 1) using 13 tracks at 1/120
Actually ffmpeg was able to read that ok.
Code:
ffmpeg -i rdeer.mid -vn -c:a libmp3lame rdeer.mp3

ffmpeg -i rdeer.mid -vn out.wav

file out.wav
out.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
See:
man ffmpeg
man sox
man file
 
1 members found this post helpful.
Old 01-23-2022, 02:45 AM   #6
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Quote:
sox -t raw -r 44100 -e signed -b 16 -c 1 raw_audio audio.wav
It made a wav file but the playback was just noise.
 
Old 01-23-2022, 03:32 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Midi isn't an audio format per se, it's a set of instruction you send to a synthesizer.
Cutting out 10s (while keeping it as a midi file) can prove to be tricky, because the instructions can include repetitions, or jumping back to a previous block etc.
 
1 members found this post helpful.
Old 01-23-2022, 06:20 AM   #8
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Thumbs up

Quote:
Originally Posted by ondoho View Post
Midi isn't an audio format per se, it's a set of instruction you send to a synthesizer.
Cutting out 10s (while keeping it as a midi file) can prove to be tricky, because the instructions can include repetitions, or jumping back to a previous block etc.
Thanks for the info. I may leave it be.
 
Old 01-23-2022, 06:39 AM   #9
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
From post #5

Get a .mid
Code:
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0"

curl -A "$agent" https://www.midiworld.com/download/3964 -o rd.mid

file rd.mid
rd.mid: Standard MIDI data (format 1) using 13 tracks at 1/120
Dump to PCM
Code:
ffmpeg -i rd.mid -vn rd.wav

file rd.wav
rd.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz
Get first 10 sec.
Code:
ffmpeg -i rd.wav -t 00:00:10 -vn -c:a copy rd2.wav

ffprobe rd2.wav
...
Duration: 00:00:10.01, bitrate: 1411 kb/s
  Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 2 channels, s16, 1411 kb/s
10 different ways that you could do that.

Also saw these
https://github.com/gcunhase/wav2midi2wav
https://anyconv.com/wav-to-midi-converter/
 
2 members found this post helpful.
Old 01-24-2022, 09:23 AM   #10
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Hi teckk.

Code:
ffmpeg -i rd.mid -vn rd.wav
outputs

Code:
rd.mid: Invalid data found when processing input
 
Old 01-24-2022, 11:03 AM   #11
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
What is the output of
Code:
file rd.mid

ffprobe rd.mid
Or it could be that you are using a ffmpeg with different compile options than what I am.

I have:
Code:
ffmpeg -codecs
...
 D.V.L. mv30                 MidiVid 3.0
 D.VIL. mvc1                 Silicon Graphics Motion Video Compressor 1
 D.VIL. mvc2                 Silicon Graphics Motion Video Compressor 2
 D.V.L. mvdv                 MidiVid VQ
 D.VIL. mvha                 MidiVid Archive Codec
 ...
Code:
ffmpeg
ffmpeg version n4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11.1.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
 
Old 01-24-2022, 11:26 AM   #12
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Code:
file rd.mid
Code:
rd.mid: Standard MIDI data (format 1) using 13 tracks at 1/120
Code:
ffprobe rd.mid
Code:
ffprobe version 4.3.3-0+deb11u1 Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
rd.mid: Invalid data found when processing input
Code:
...
D.V.L. mv30                 MidiVid 3.0
D.VIL. mvc1                 Silicon Graphics Motion Video Compressor 1
D.VIL. mvc2                 Silicon Graphics Motion Video Compressor 2
D.V.L. mvdv                 MidiVid VQ
D.VIL. mvha                 MidiVid Archive Codec
...
 
Old 01-24-2022, 12:02 PM   #13
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
Looks like the ffmpeg that you are using does not like .mid files.
You have timidity in your repos?

Looks like it's ancient, but so is midi.
http://timidity.sourceforge.net/
https://archlinux.org/packages/commu...64/timidity++/

https://www.instructables.com/Ubuntu-BASH-MIDI-to-WAV/
http://linux-sound.org/midi.html
https://www.fluidsynth.org/
http://www.tedfelix.com/linux/linux-midi.html
https://github.com/gcunhase/wav2midi2wav

Good luck, whatever you come up with.
 
Old 01-25-2022, 08:36 AM   #14
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,728

Original Poster
Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
Thumbs up

Thanks again, teckk. That's too much to deal with for my use case. Hopefully others will find it of use.
 
  


Reply

Tags
.mid, midi, trim



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sdl_mixer has the worst midi possible! Any patches for alsa hardware midi access? Holering Programming 5 06-18-2013 04:16 PM
convert total no of seconds in the format hour minutes and seconds suchi_s Programming 15 03-15-2011 11:34 AM
[SOLVED] Experiencing freezing up to 5 seconds every 10 seconds, could these be the problem? Switch7 Slackware 10 11-16-2009 04:36 PM
hdparm power save, 15 seconds of spin, 5 seconds of rest... Romanus81 Linux - Laptop and Netbook 1 01-01-2009 05:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration