Edit videos from ubuntu comand line


To split a video in parts use the following syntax:

ffmpeg -i original_video.mp4 -ss 00:00:00 -t 00:03:38  -vcodec copy -acodec copy part1.mp4
ffmpeg -i original_video.mp4 -ss 00:05:20 -t 00:00:15  -vcodec copy -acodec copy part2.mp4

The previous commands will extract into part1 and part2 two videos of 3:38 and 0:15 long. Taken at the starting points 00:00 and 05:20. This process done from a video file called original_video.mp4.

If you want to merge these two parts together. Write into a file the following lines:
file part1.mp4
file part2.mp4

So if you execute cat ifile.txt you will see the previous two lines.
Next. Run the merge of them with:
ffmpeg -f concat -safe 0 -i ifile.txt -c copy part1_and_part2.mp4


Later, you can edit the audio with audacity and reduce noise. Export the audio file as only_audio.mp3.
To merge the processed audio with the video do as follows:
MP4Box part1_and_part2.mp4 -single 1 -out video_only.mp4
MP4Box video_only.mp4 -add only_audio.mp3
mv video_only.mp4 video_and_proc_audio.mp3

If you want to flip the video use for vertical, horizontal flip and both respectively:
ffmpeg -i normal_video.mp4 -vf vflip -c:a copy vflip.mp4
ffmpeg -i normal_video.mp4 -vf hflip -c:a copy hflip.mp4
ffmpeg -i normal_video.mp4 -vf "vflip,hflip" -c:a copy vhflip.mp4

Rotate a video clockwise:
ffmpeg -i v.mp4 -vf "transpose=1" -strict -2 vcw.mp4

Rotate a video counter clockwise:
ffmpeg -i v.mp4 -vf "transpose=2" -strict -2 vccw.mp4

Join two videos next to each other spatially (not in time):
ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack -strict -2  joint.mp4

Convert webm video to mp4:
ffmpeg -i video.webm  -strict -2 output_video.mp4

Extract mp3 from video (Not tested from me):
ffmpeg -i VIDEOFILE -acodec libmp3lame -metadata TITLE="Name of Song" OUTPUTFILE.mp3
(Ref: https://askubuntu.com/questions/41749/how-can-i-extract-audio-track-from-video-file-and-save-it-as-mp3)

Add audio to video
ffmpeg -i v.mp4 -i audio.mp3 -codec copy -shortest video_and_audio.mp4


Download youtube videos audio only:
#First see available formats
youtube-dl your_url -F

One working format is m4a which is option 140 so later
youtube-dl your_url -f 140

#Downsample the resolution/quality of a video:
ffmpeg -i input_video.mp4 -strict -2 -vf scale=iw/2:-1 output_name.mp4




Some references:
https://askubuntu.com/questions/160869/need-to-downsample-video-to-a-lower-resolution
https://unix.stackexchange.com/questions/233832/merge-two-video-clips-into-one-placing-them-next-to-each-other
https://www.ostechnix.com/how-to-rotate-videos-using-ffmpeg-from-commandline/
https://stackoverflow.com/questions/11779490/how-to-add-a-new-audio-not-mixing-into-a-video-using-ffmpeg

Comentarios

Entradas populares de este blog

Can't mount external hdd in ubuntu