Skip to content

Instantly share code, notes, and snippets.

@tuxdna
Last active January 17, 2023 23:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tuxdna/1a1f18ff09f950549f9aa12b09f0a23c to your computer and use it in GitHub Desktop.
Save tuxdna/1a1f18ff09f950549f9aa12b09f0a23c to your computer and use it in GitHub Desktop.
Audio / Video fingerprinting

How to stream a file over RTSP protocol using VLC?

$ cvlc file.mp3 --rtsp-host localhost
   --sout '#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100}:rtp{sdp=rtsp://:8554'
   --sout-keep

Now play it :

$ mplayer "rtsp://localhost:8554/"
$ ffplay "rtsp://localhost:8554/"
$ vlc "rtsp://localhost:8554/"

How to truncate a media file using ffmpeg?

Example: Copy first 10 seconds of the file:

$ ffmpeg -i input.mp3 -acodec copy -t 00:00:10 output.mp3

Description of M3U files:

http://en.wikipedia.org/wiki/M3U

Install PyAV

sudo apt-get install -y libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libavresample-dev  libavfilter-dev libpostproc-dev

FFMPEG read/write A/V files:

https://www.reddit.com/r/Python/comments/1ns10y/python_ffmpeg_read_and_write_any_audiovideo/

$ cat playlist.m3u8 
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=63000,CODECS="mp4a.40.5"
http://hls2.addictradio.net/addictrock_aac_hls/playlist.m3u8?listeningSessionID=5434033cc4e63719_6799700_ioruvMJo_00000000YNr&downloadSessionID=0


$ wget -c "http://hls2.addictradio.net/addictrock_aac_hls/playlist.m3u8?listeningSessionID=5434033cc4e63719_6799700_ioruvMJo_00000000YNr&downloadSessionID=0"

$ cat playlist.m3u8\?listeningSessionID\=5434033cc4e63719_6799700_ioruvMJo_00000000YNr\&downloadSessionID\=0 
#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10,title="Ignorance",artist="Paramore"
http://hlscdn1.addictradio.net/addictrock_aac_hls/bJ7HoHj2wCj-215529-9984.aac
#EXTINF:10,title="Ignorance",artist="Paramore"
http://hlscdn1.addictradio.net/addictrock_aac_hls/XRrVcNBCRxf-215530-9984.aac
#EXTINF:10,title="Ignorance",artist="Paramore"
http://hlscdn1.addictradio.net/addictrock_aac_hls/Z3aJzfXFZH7-215531-10031.aac


$ wget -c "http://hlscdn1.addictradio.net/addictrock_aac_hls/bJ7HoHj2wCj-215529-9984.aac"
$ ffplay bJ7HoHj2wCj-215529-9984.aac

Stream examples

https://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8

$ wget -c --no-check-certificate "https://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"
$ wget -c --no-check-certificate "https://devimages.apple.com/iphone/samples/bipbop/gear1/fileSequence0.ts"
$ file fileSequence0.ts 
fileSequence0.ts: MPEG transport stream data

Setting up Xuggler

http://www.xuggle.com/downloads

Read video frames in Python using FFMPEG:

https://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/

Read audio video frames in Python using FFMPEG:

https://zulko.github.io/blog/2013/10/04/read-and-write-audio-files-in-python-using-ffmpeg/

on Ubuntu install extra codecs:
$ sudo aptitude install libavutil-extra-51
Now ffmpeg automatically does the conversion to correct format. Choose bit rage using -b option.
$ ffmpeg -i video.flv -b 128K audio-128k.mp3
on Fedora
$ sudo yum install -y ffmpeg lame-libs
$ ffmpeg -i video.flv -b 128K audio-128k.mp3
$ ffmpeg -i video.flv -b:a 128K audio-128k.mp3
Convert all FLAC files to MP3 in the current folder:
$ for f in *.flac ; do ffmpeg -i "$f" "$f".mp3; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment