#-map_metadata -1 -map_chapters “-1” -c:v copy -c:a copy
Explore tagged Tumblr posts
world-of-lang · 23 days ago
Text
ridiculous
62 notes · View notes
bearchan · 8 years ago
Text
Use ffmpeg to extract mp3 from mkv
Extract Audio (whole)
ffmpeg -i video.mp4 -f mp3 -ab 192000 -vn music.mp3
The -i option in the above command is simple: it is the path to the input file. The second option -f mp3 tells ffmpeg that the ouput is in mp3 format. The third option i.e -ab 192000 tells ffmpeg that we want the output to be encoded at 192Kbps and -vn tells ffmpeg that we dont want video. The last param is the name of the output file.
Extract subtitle
ffmpeg -i Movie.mkv -map 0:s:0 subs.srt
(if) Some unspecified codec of subtitles (e.g. some WebVTT but incorrectly packed in SRT):
Tumblr media Tumblr media
ffmpeg -scodec srt -i Movie.mkv -map 0:s:0 subs.vtt
Burn a subtitle to a video
text based:
./ffmpeg -i input.mkv -c:a ac3 -ac 2 -c:v libx264 -vf subtitles=input.mkv:force_style='Fontsize=24' -max_muxing_queue_size 800 output.mp4
text based subtitle with a background:
./ffmpeg -i input.mp4 -filter_complex "subtitles=input.srt:force_style='Fontsize=24,OutlineColour=&H00000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20'" output.mp4
picture based:
./ffmpeg -i input.mkv -filter_complex "[0:v][0:s]overlay[v]" -map "[v]" -map 0:a -map_metadata -1 -c:a ac3 -ac 2 -c:v libx264 -max_muxing_queue_size 800 output.mp4
picture based with display-height correction:
./ffmpeg -i input.mkv -filter_complex "[0:v][0:s]overlay=x=(main_w-overlay_w)/2:y=-200[v]" -map "[v]" -map 0:a -map_metadata -1 -c:a ac3 -ac 2 -c:v libx264 -max_muxing_queue_size 800 output.mp4
Trim Clip
ffmpeg -i file.mkv -ss 00:00:20 -to 00:00:40 -c copy file-2.mkv
Convert mkv to mp4
ffmpeg -i LostInTranslation.mkv -codec copy LostInTranslation.mp4
Convert 10-bit to 8bit
./ffmpeg -i input.mp4 -c:v libx264 -pix_fmt yuv420p output.mp4
Deinterlacing interlaced (Scan type)
./ffmpeg -i input.mp4 -c:v libx264 -vf yadif output.mp4
yadif for "yet another deinterlacing filter"
Bypass the copyright (unverified)
ffmpeg -y -i input.mp4 -af "pan=stereo|c0<c0+0*c1|c1<c0+0*c1,aeval=val(0)|-val(1),volume=1.6" -filter_complex "scale=1280:720,setdar=16/9" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1400k -profile:v main -level 3.1 -acodec ac3 -b:a 128k -ar 44100 -threads 0 -preset superfast output.mp4
Batch conversion by using parameter expansion
for i in *.mp4; do ffmpeg -i "$i" "${i%.*}.mp4"; done
Batch clean-up alternative audio & subtitle streams
for i in *.mp4; ffmpeg -i "$i" -map 0:v:0 -map 0:a:0 -map 0:s:1 -c copy "${i%.*}.mkv"; done
⚠️use -c copy for NO re-encoding!! (otherwise, some other issues like vobsub which is not support by ffmpeg may cause extra problems)
Scale and pad to fit a specific aspect
ffmpeg -i input -vf "scale=w=1280:h=720:force_original_aspect_ratio=1,pad=1280:720:(ow-iw)/2:(oh-ih)/2" output
Therefore, batch scale and bypass
for i in *.mp4 *.mov; do ffmpeg -y -i "$i" -af "pan=stereo|c0<c0+0*c1|c1<c0+0*c1,aeval=val(0)|-val(1),volume=1.6" -filter_complex "scale=w=1280:h=720:force_original_aspect_ratio=1,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -acodec ac3 -b:a 128k -ar 44100 -threads 0 "${i%.*}-by.mp4"; done
batch crop and add a fade-out to the end of the video
ffmpeg -i input.mov -vf "crop=600:in_h:110:0,fade=type=out:duration=2:start_time=58" -af "afade=out:st=58:d=2" -c:v libx264 -crf 22 -preset veryslow output1.mp4
faster version(fade audio only)
ffmpeg -i input.mp4 -af "afade=out:st=58:d=5" -vcodec copy output.mp4
“could not find tag for codec truehd“
./ffmpeg -i input.mkv -c:a aac -ac 2 -vcodec copy output.mp4
⚠️embedded subtitle error
Q: codec 94213 is not supported A: use -sn to ignore the subtitle copying
Too many packets buffered for output stream 0:1.
Not a bug. The file has somewhat sparse video or audio frames, and increasing the packet queue size helps:
ffmpeg -i too_many_packets_buffered_example.mp4 -max_muxing_queue_size 400 out.mp4
🔇No audio in QuickTime (and probably in iPhone as well)
Issue: the format/codec is out of Apple’s specifications, e.g. 5.1 channels Solution: use -ac 2 to restrain the channels of the audio
ffmpeg -i YOUR-INPUT.wmv -s qvga -b 384k -vcodec libx264 -r 23.976 -acodec libfaac -ac 2 -ar 44100 -ab 64k -vpre baseline -crf 22 -deinterlace -o YOUR-OUTPUT.MP4
Can’t edit the video in Mac/iPhone (even Save As..)
⚠️ The Native FFmpeg AAC Encoder is so bad, it will make the video not-edit-able! Please use AC3.
(Optional for ac3) use -b:a 128k for aac or use -ab 128k(for ac3) and -ar 44100 to restrain the bitrate and the samplerate of audio. AND add -map_metadata -1 and -map_chapters -1 to strip all unnecessary metas
The command of a clean conversion should be:
ffmpeg -i input.mkv -map_metadata -1 -map_chapters -1 -c:a ac3 -ac 2 -ar 44100 -c:v libx264 -max_muxing_queue_size 800 output.mp4
Download a blob url video
Tumblr media
Option 1. If you have VLC player installed, feed the URL to VLC using "Open Network Stream..." menu option. I'm not going to go into details on this part here, there are a number of comprehensive guides in many places, for example, here. If the page doesn't work, you can always google another one by "vlc download online video".
Option 2. If you are more into command line, use FFMPEG or your own script, as directed in this SuperUser question.
ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i "http://s6.vidshare.tv/hls/pdommq4tlsm4f4kmledsh5d5fcn27i35msjxqw62lfflut5bgaqhb5kirb5q/index-v1-a1.m3u8" -c copy video.mp4
Correct the aspect of a video
Some videos are cramped into a 4:3 format (e.g. Survivor S20) to fulfill DVD requirements. As it’s original aspect(like 16:9) will be displayed/”restored” by a DAR flag(”display Aspect ratio” for display devices).
However, some devices may not automatically apply this parameter and therefore cause an UX issue. Therefore, we would like to permanently change it’s meta from the videos.
I’ve tried so many ways, including change it’s metadata, aspect ratio and “video properties” from MKVToolNix, but either of that works.
Finally, I have to use an expensive way to “scale” it back to the correct resolution: (however, the procedure took about 1s-to-1s rendering which was too expensive thus I have to let it go)
Tumblr media
ffmpeg -i input.mp4 -vf scale=1280:720,setsar=1/1 output.mp4
0 notes