Video Editing / Conversion

Shell scripts and utilites for editing/converting videos.

Installing Utilities.
apt install mencoder ffmpeg mkvtoolnix imagemagick avconv libavcodec-extra-53 libav-tools

Snippets

Splitting MKV Files into Smaller MKV’s Based on Timestamps

mkvmerge -o out.file --split timecodes:00:42:06.000,01:22:20.000 in.file

Cut and Direct Copy Video to New File

mencoder [-ss 00:00:00] -endpos 00:15:00 -oac copy -ovc copy in.file -o out.file
ffmpeg -i input.wmv -ss 00:00:00.000 -t 00:15:00.000 -acodec copy -vcodec copy output.wmv

Strip metadata (metadata that is not required)

Ffmpeg -map_metadata -1

Generate Copies at One Second Intervals (For Bad Encodes)

for x in `seq -w 5 15`;do mencoder -oac copy -ovc copy -ss 11:${x} -endpos 14:00 in.file -o out-${x}.file;done

Merge Video Files into a Single File

mencoder -oac copy -ovc copy [-noskip] [hr-edl-seek] in1.file in2.file inX.file -o out.file

Insert a Video into a MKV Container (No Video Conversion – Preferred)

mkvmerge -o out.mkv in.file

Insert and Convert a Video into a MKV Container (Re-encodes Video Than Insert)

mencoder in.file -o out.mkv -of lavf -oac copy -ovc lavc

Insert and Convert Videos in a Directory to MKV Containers

find . -name "*.flv" -exec mencoder {} -o {}.mkv -of lavf -oac copy -ovc lavc \;

Convert Entire Directory to MKV Containers

find . -type f -exec mkvmerge -o {}.mkv {} \;

Convert Animated GIF to AVI/MPG

convert image.gif output%05d.png
convert -delay 12 -quality 100 output*png final_movie.mpg
ffmpeg -r 9 -i output%05d.png final_movie.avi

Combine multiple video parts into one video

mkvmerge -o out.mkv 1.file + 2.file + 3.file + 4.file + 5.file

Rip MP3 Audio from FLV File

avconv -i {FLV FILE} output.mp3

Convert FLV to MKV Container

ffmpeg -i {FLV FILE} -vcodec copy -acodec copy out.mkv

Convert webm to mkv

ffmpeg -i your_input_filename.webm -qscale 0 your_outfile_name.mkv

Use ffmpeg to download and stitch stream together

Use ffmpeg to download and stitch stream together.
ffmpeg -i https://{URI}.m3u8 -c:v copy -c:a copy -f mpegts output.ts

ffmpeg Convert Minimizing Quality Loss

Convert file stripping metadata and enabling skipping and scrubbing in video.

ffmpeg -i example.mp4 -ss 00:00:10.000 -t 00:51:29.000 -crf 15 -movflags +faststart -pix_fmt yuv420p -map_metadata -1 out.mp4

Download M3U8 Playlist

For videos that are sitched together in short increments, usually TS (video stream).

Turn on developer tools (Chrome):

  • ⋮ › More Tools › Developer Tools

  • Load Video URL.

  • Developer Tools › Network › All

  • Filter by m3u8.

  • Determine stream URL to use.

  • {RMB} › Copy › Copy link address

References

  1. mencoder online manual

  2. mencoder selecting codecs

  3. mencoder for merging video files

  4. mencoder for video editing

  5. mencoder how to trim and split

  6. ffmpeg for slicing video files (1)

  7. ffmpeg for slicing video files (2)

  8. Convert static images to video files

  9. Convert animated GIF’s to video files (1)

  10. Convert animated GIF’s to video files (2)

  11. Convert animated GIF’s to video files (3)

  12. Splitting MKV’s into smaller MKV’s

  13. Combining multiple videos parts into one file

  14. Extract part of video

  15. Get frame number in VLC

  16. Stream Netflix videos at 1080p in Linux