User Tools

Site Tools


public:it:ffmpeg

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
public:it:ffmpeg [2022/11/13 15:54] philpublic:it:ffmpeg [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== ffmepg ====== 
  
- 
-  * https://gist.github.com/papamoose/957f0874f76141fef90d2f7205ca5f86 
-  * [[https://tdarr.io/| Tdarr.io - Distributed video conversion (automatic) ]] 
-  * [[https://ffmpeg.org/ffmpeg.html| man page ]] 
-  * [[https://ffmpeg.org/ffmpeg-all.html|All Options]] 
-  * [[https://docs.nvidia.com/video-technologies/video-codec-sdk/ffmpeg-with-nvidia-gpu/|ffmpeg with Nvidia GPU]] 
-  * https://www.ramugedia.com/how-encode-decode-hevc-h-265-by-intel-quick-sync-video-hw--qsv- 
-  * https://trac.ffmpeg.org/wiki/Hardware/QuickSync 
-  * https://gist.github.com/andrearug/ee461152acfbbd3f52b3bb9ffb55b6b8 
-  *  
-  * https://geoffruddock.com/bulk-compress-videos-x265-with-ffmpeg/ 
-  * https://slhck.info/video/2017/02/24/crf-guide.html 
-  * https://netflixtechblog.com/a-large-scale-comparison-of-x264-x265-and-libvpx-a-sneak-peek-2e81e88f8b0f 
-  * https://www.youtube.com/watch?v=wi1BefrfTos 
-  * https://video.stackexchange.com/questions/14907/how-to-downsample-4k-to-1080p-using-ffmpeg-while-maintaining-the-quality 
- 
- 
-===== Build ===== 
- 
-  * https://github.com/markus-perl/ffmpeg-build-script 
- 
-=====  Manipulating audio channels  ===== 
- 
-  * https://trac.ffmpeg.org/wiki/AudioChannelManipulation#a5.1stereo 
-  * https://superuser.com/a/1616102 
-  * https://datatracker.ietf.org/doc/html/rfc7845#section-5.1.1.5 
- 
-==== 5.1 Surround downmix to stereo ==== 
-FL, FC, FR, BL, BR, LFE -> FL, FR 
-<code> 
--ac 2 \ 
--af "pan=stereo|FL = 0.374107*FC + 0.529067*FL + 0.458186*BL + 0.264534*BR + 0.374107*LFE |FR = 0.374107*FC + 0.529067*FR + 0.458186*BR + 0.264534*BL + 0.374107*LFE" \ 
-</code> 
- 
- 
-==== 7.1 downmix to stereo ==== 
-FL, FC, FR, SL, SR, BL, BR, LFE -> FL, FR 
-<code> 
--ac 2 \ 
--af "pan=stereo|FL = 0.274804*FC + 0.388631*FL + 0.336565*SL + 0.194316*SR + 0.336565*BL + 0.194316*BR + 0.274804*LFE | FR = 0.274804*FC + 0.388631*FR + 0.336565*SR + 0.194316*SL + 0.336565*BR + 0.194316*BL + 0.274804*LFE" \ 
-</code> 
- 
- 
-==== 6.1 downmix to stereo==== 
-FL, FC, FR, SL, SR, BC, LFE -> FL, FR 
-<code> 
--ac 2 \ 
--af "pan=stereo|FL = 0.321953*FC + 0.455310*FL + 0.394310*SL + 0.227655*SR + 278819*BC + 0.321953*LFE | FR = 0.321953*FC + 0.455310*FR + 0.394310*SR + 0.227655*SL + 278819*BC + 0.321953*LFE" \ 
-</code> 
- 
-==== 5.0 downmix to stereo ==== 
-FL, FC, FR, BL, BR -> FL, FR 
-<code> 
--ac 2 \ 
--af "pan=stereo|FL = 0.460186*FC + 0.650802*FL + 0.563611*BL + 0.325401*BR | FR = 0.460186*FC + 0.650802*FR + 0.563611*BR + 0.325401*BL" \ 
-</code> 
- 
-==== Quadraphonic Channel downmix to stereo==== 
-FL, FR, BL, BR -> FL, FR 
-<code> 
--ac 2 \ 
--af "pan=stereo|FL = 0.422650*FL + 0.366025*BL + 0.211325*BR | FR = 0.422650*FR + 0.366025*BR + 0.211325*BL" \ 
-</code> 
- 
-==== Linear Surround Channel downmix to stereo ==== 
-FL, FC, FR -> FL, FR 
-<code> 
--ac 2 \ 
--af "pan=stereo|FL = 0.414214*FC + 0.585786*FL | FR = 0.414214*FC + 0.585786*FR" \ 
-</code> 
- 
-===== Scaling ===== 
- 
-==== QSV Scale to 1080p ==== 
- 
-Quality with QSV as not good at all, though this could have been my fault. 
-<code> 
-ffmpeg \ 
-  -y \ 
-  -hwaccel qsv \ 
-  -qsv_device /dev/dri/card0 \ 
-  -c:v hevc_qsv \ 
-  -i input.mkv \ 
-  -c:v hevc_qsv \ 
-  -vf 'scale_qsv=w=1920' \ 
-  -preset slow \ 
-  -global_quality 25 \ 
-  -c:a copy \ 
-  -c:s copy \ 
-  output.mkv 
-</code> 
- 
- 
-==== 4k to 1080p ==== 
- 
-  * libx264 
-  * libx265 
- 
-<code> 
-ffmpeg \ 
-  -i MyMovie_4K.mkv \ 
-  -vf scale=1920:-1 \ 
-  -c:v libx265 \ 
-  -preset veryslow \ 
-  -c:a copy \ 
-  MyMovie_1080p.mkv 
-</code> 
- 
-Not sure if these are necessary. 
-<code> 
--crf 28 
-</code> 
- 
- 
-===== Subtitles ===== 
- 
-==== MKV Embed soft subtitles ==== 
-  * [[https://gist.github.com/kurlov/32cbe841ea9d2b299e15297e54ae8971]] 
-<code> 
-ffmpeg \ 
-  -i in.mkv \ 
-  -f srt \ 
-  -i in.srt \ 
-  -map 0:0 \ 
-  -map 0:1 \ 
-  -map 1:0 \ 
-  -c:v copy \ 
-  -c:a copy \ 
-  -c:s srt \ 
-  out.mkv 
-</code> 
- 
-==== MKV hardcode subtitles ==== 
- 
-http://diantokam.blogspot.com/2016/12/adding-subtitle-and-scaling-film-using.html 
- 
-<code> 
-ffmpeg \ 
-  -i "input.mkv" \ 
-  -vf subtitles=fullsubs.srt \ 
-  "output.mkv" 
-</code> 
- 
- 
-==== MKV to MP4 hardcode subtitles and downmix 5.1 to stereo ==== 
- 
-<code> 
-  # export english subs 
-  ffmpeg \ 
-    -y \ 
-    -i "./${name}" \ 
-    -map 0:s:0 \ 
-    eng.srt 
- 
-  # create a version with hardsubs 
-  # si=0 
-  ffmpeg \ 
-    -y \ 
-    -i "./${name}" \ 
-    -vf subtitles="${name}":si=0 \ 
-    -ac 2 \ 
-    -af "pan=stereo|FL = 0.374107*FC + 0.529067*FL + 0.458186*BL + 0.264534*BR + 0.374107*LFE |FR = 0.374107*FC + 0.529067*FR + 0.458186*BR + 0.264534*BL + 0.374107*LFE" \ 
-    -c:a aac \ 
-    "${name}-hardsubs.mp4" 
- 
-</code> 
-==== Delay subtitle by 1 second ==== 
- 
-<code> 
-ffmpeg \ 
-  -itsoffset -1 \ 
-  -i full8.srt \ 
-  -c copy \ 
-  full8_delayed.srt 
-</code> 
- 
- 
- 
- 
- 
- 
-====== Video Streaming ====== 
- 
-https://hub.docker.com/r/tiangolo/nginx-rtmp 
-https://www.nginx.com/blog/video-streaming-for-remote-learning-with-nginx/ 
- 
- 
-  ffmpeg -h encoder=hevc_qsv 
- 
- 
-====== Clips ====== 
- 
- 
-<code> 
-ffmpeg \ 
-  -i  input.mkv \ 
-  -ss 29:36 \ 
-  -to 29:50 \ 
-  -c:v copy \ 
-  -c:a aac \ 
-  output.mp4 
-</code> 
- 
- 
- 
-====== h264 to hevc using nvenc ====== 
- 
-  - Install docker 
-  - Install nvidia docker: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html 
-  - Docker ffmpeg image: https://hub.docker.com/r/jrottenberg/ffmpeg 
- 
-<code> 
-docker run \ 
-  -v $(pwd):$(pwd) \ 
-  -w $(pwd) \ 
-  --runtime=nvidia jrottenberg/ffmpeg:4.1-nvidia \ 
-  -hwaccel cuvid \ 
-  -c:v h264_cuvid \ 
-  -i input.mkv \ 
-  -c:v hevc_nvenc \ 
-  -c:a copy \ 
-  -c:s copy \ 
-  -preset slow \ 
-  output_hevc.mkv 
-</code> 
- 
- 
-====== Errors ====== 
- 
-===== Error creating a NVDEC decoder ===== 
- 
-<code> 
-[h264 @ 0x56028de15ec0] Error creating a NVDEC decoder: 1 
-[h264 @ 0x56028de15ec0] Using more than 32 (34) decode surfaces might cause nvdec to fail. 
-[h264 @ 0x56028de15ec0] Try lowering the amount of threads. Using 16 right now. 
-[h264 @ 0x56028de15ec0] Failed setup for format cuda: hwaccel initialisation returned error. 
-</code> 
- 
-  * https://ffmpeg.org/pipermail/ffmpeg-user/2019-June/044610.html 
- 
-> Note that cuda hwaccel is an alias to the newer nvdec implementation, and to my knowledge, has no way of setting up decoder surface limits. 
- 
-> Here's a workaround you can try: 
- 
-<code> 
-ffmpeg \ 
-  -threads 4 \ 
-  -hide_banner \ 
-  -c:v h264_cuvid \ 
-  -surfaces 8 \ 
-  -nostats \ 
-  -i rtmp://<ip>:<port>/myapp/mystream \ 
-  -filter_complex [0]fps=fps=1[s0] \ 
-  -map [s0] \ 
-  -f rawvideo \ 
-  -pix_fmt rgb24 pipe 
-</code> 
- 
-> Two changes: 
-> 
-> 1: Call up the h264_cuvid decoder directly, and apply a surface limit count of 8. This should be adequate. 
-> 2: Limit the thread count. 
- 
- 
-===== Non-monotonous DTS in output stream ===== 
- 
-None of this worked. 
- 
-  * https://stackoverflow.com/a/48874015 
- 
-<code> 
-[matroska @ 0x55a1a3738340] Non-monotonous DTS in output stream 0:1; previous: 490791, current: 490731; changing to 490791. This may result in incorrect timestamps in the output file. 
-</code> 
- 
-Try ''%%-use_wallclock_as_timestamps 1%%'' and ''%%-fflags +genpts%%'' 
- 
- 
-===== FFMPEG: Too many packets buffered for output stream 0:1 ===== 
- 
-  * https://stackoverflow.com/a/65501876 
- 
-Add the following after the input file: 
-<code> 
--max_muxing_queue_size 9999 
-</code> 
- 
-===== Subtitle codec 96257 is not supported ===== 
-<code> 
-[matroska @ 0x55e337388d80] Subtitle codec 96257 is not supported. 
-Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented 
-Error initializing output stream 0:1 --  
-Conversion failed! 
-</code> 
- 
-https://video.stackexchange.com/a/17009 
- 
-> stream apparently is a CEA-608 subtitle stream, which during the days of analog television signal transmission was caption data embedded within the video data. Apparently FFmpeg can extract it but can't mux it to a new container. 
- 
-It doesn't seem like there's a whole lot that can be done. 
- 
-===== Subtitle codec 94213 is not supported ===== 
- 
-  * https://www.reddit.com/r/ffmpeg/comments/r2toyz/mp4_to_mkv_conversion_problem/ 
- 
-Convert the subtitles to SRT. 
-<code> 
--c:s srt 
-</code> 
- 
- 
-===== Video uses a non-standard and wasteful way to store B-frames  ===== 
- 
-If you are encoding you can ignore this message. If you are copying ''%%-c:v copy%%'' the stream you should follow the advice below. 
- 
-[mpeg4 @ 0x5607fe47e0c0] Video uses a non-standard and wasteful way to store B-frames ('packed B-frames'). Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it. 
- 
-  * https://superuser.com/a/1099571 
- 
-> B-frames are a frame type used in video compression to represent frames of a video. B-frames can use information from both previous and future frames to represent each video frame. 
-> 
-> Older DivX-encoded videos commonly use an ugly method called packed bitstream which puts several video frames into a single AVI chunk. Packed bitstream isn't standard MPEG-4, uses more space, requires more CPU power to encode/decode, and (most importantly) may cause problems if copied into another container type. This is the main reason for the warning. 
-> 
->Since you're re-encoding the video instead of just copying it, you should be fine. If you wanted to keep the original video, but copy it into another type of container (say MP4 or MKV), it'd be best to unpack the B-frames first using the FFmpeg filter mpeg4_unpack_bframes. 
-> 
-> You could unpack the B-frames with something simple like 
- 
-<code> 
-ffmpeg -i INPUT.avi -codec copy -bsf:v mpeg4_unpack_bframes OUTPUT.avi 
-</code> 
public/it/ffmpeg.1668376466.txt.gz · Last modified: 2022/11/13 15:54 by phil