Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Видео и аудио: обработка и кодирование (http://forum.oszone.net/forumdisplay.php?f=45)
-   -   ffmpeg pipe (http://forum.oszone.net/showthread.php?t=352007)

bredych 28-09-2022 00:16 2993183

ffmpeg pipe
 
хотел в одной строке обьединить фильтры смены размера (навесить pad) и убрать лого (не какого-нибудь пиратства ради, просто видео дико прыгает, глаза кровавятся, а стаб за лого цепляется, рывками еще хуже делает). Вложил через запятую как
Код:

-vf "pad=1280:720:(ow-iw)/2:(oh-ih)/2, delogo x=110:y=330:w=220:y=330"
- не может словить входной поток для второго фильтра. То есть, так нельзя.
А лишнюю перекодировку не хочется: и так качество не фонтан, а по 4 перекодировки в процессе обработки - это явно убийство и без того плохого качества ролика..
Собсно вопрос: можно-ли как-то перенаправить поток из первого фильтра во второй без закодирования, чтоб он его сразу обработал и обошелся одной кодировкой?
Как-нибудь пайпнуть раскодированный поток.
Просто пайп из ффмпега в ффмпег - это в сети видел. А вот так, чтоб не кодировать лишний раз? Можно?

bredych 28-09-2022 00:58 2993184

пока наиболее близкое, что словил, это How can I pipe data losslessly to and from FFmpeg?

первый вариант
Example:

ffmpeg -s 1280x720 -f rawvideo -i /dev/zero -ar 48000 -ac 2 -f s16le -i \
/dev/zero -c copy -f nut pipe:1 | ffmpeg -y -i pipe:0 -c copy -f nut /dev/null

I see no reason why anyone would do this. Also, there are very few reasons to pipe from ffmpeg to ffmpeg when you can most likely just use one ffmpeg process to do whatever you want.
What the options do:

-s 1280x720 -f rawvideo – Options to describe the input since /dev/zero is not a typical input format and therefore these additional options are required.

-i /dev/zero – The video input. It is being used in this example to generate a video stream out of "nothing". This was used in the example because the question asker refused to provide any information about the inputs being used.

-ar 48000 -ac 2 -f s16le – Options to describe the input since /dev/zero is not a typical audio format.

-i /dev/zero – The audio input. It is being used in this example to generate an audio stream out of "nothing".

-c copy – Stream copy, or re-mux, the inputs to the output. No re-encoding is being performed so the process is lossless. It is unknown if stream copying is acceptable to the question asker or not. Maybe re-encoding is desired instead?

-f nut – You need to tell ffmpeg what format to use for the pipe. Nut is a container format. See ffmpeg -formats for a complete list. Another flexible format is -f matroska, but it is impossible to suggest an appropriate or specific output container format to use without more info from the question asker.

pipe:1 – Use the pipe protocol to output to stdout. Alternatively, the number can be omitted (just pipe:) and by default the stdout file descriptor will be used for writing and stdin will be used for reading.


второй вариант
I would use pcm instead of flac in the pipe, because it takes far less time to process (PCM is raw audio, FLAC takes lots of time to encode).

Anyway, here's how I would do it.

ffmpeg -i <input video file/stream> -vcodec rawvideo -acodec pcm_s16le pipe:1 | ffmpeg -f rawvideo -i - -vcodec <video output codec> -acodec <audio output codec> -vb <video bitrate if applicable> -ab <audio bitrate if applicable> <final-output-filename>

This worked for me when I last tried, but my goal was to pipe ffmpeg into ffplay, which is a slightly different process.

example:

This pipes a video from ffmpeg to another instance as raw video output and 16 bit little-endian PCM (both lossless unless you have 24 bit PCM, then substitute pcm_s24le.) It then converts them to h.264 in the second instance, with the fraunhoefer AAC library from the Android project (libfaac is more commonly included in ffmpeg builds. You can replace it with this instead.)

ffmpeg -i montypythonsflyingcircus-s1e1.avi -vcodec rawvideo -acodec pcm_s16le pipe:1 | ffmpeg -i - -vcodec libx264 -acodec libfdk_aac -vb 1200k -ab 96k mpfc-s1e01-output.mkv

If this doesn't pipe the subtitles, you can always rip them to SRT's and then mux them back in later, or add them to the pipes above easily.


но и там ругаются, что не пашет..

И FFmpeg - feeding output of encode operation to filter
Скрытый текст


Filters need decoded frames, so the encoded output can't be used directly. You can pipe it to another ffmpeg process.

ffmpeg -i input.mp4 -map 0:v -map 0:v -map 0:v -c:v libx264 -b:v:0 10000k -b:v:1 5000k -b:v:2 2000k -f nut - | ffmpeg -i input.mp4 -f nut -i -filter_complex "[1:v:0][0:v]psnr;[1:v:1][0:v]psnr;[1:v:2][0:v]psnr" -f null -

To avoid decoding the video twice, use

ffmpeg -i input.mp4 -map 0:v -map 0:v -map 0:v -map 0:v -c:v libx264 -c:v:3 rawvideo -b:v:0 10000k -b:v:1 5000k -b:v:2 2000k -f nut - | ffmpeg -f nut -i -filter_complex "[1:v:0][1:v:3]psnr;[1:v:1][1:v:3]psnr;[1:v:2][1:v:3]psnr" -f null -


bredych 28-09-2022 01:19 2993185

получившееся у меня
Код:

ffmpeg -i 1280-704.mov -vf "pad=1280:720:(ow-iw)/2:(oh-ih)/2" -c:v libx264 -c:v:rawvideo -f nut pipe: | ffmpeg -f nut -i pipe:0 -filter_complex "delogo=x=102:y=514:w=110:h=514" -c:v libx264 -crf 21 -c:a copy out.mp4
ругается на

Код:

[NULL @ 00000000028400c0] Unable to find a suitable output format for 'nut'
nut: Invalid argument
[nut @ 00000000005aba80] No main startcode found.
pipe:0: Invalid data found when processing input

И кирдык...

Amigos 28-09-2022 07:10 2993187

Цитата:

Цитата bredych
А лишнюю перекодировку не хочется: и так качество не фонтан »

Если вы уж так трясётесь за качество, то используйте для промежуточных шагов lossless кодеки, их не мало, а единственный их недостаток "нужно дофига места" для современных многотерабайтных носителей не сильно болезненный.

Ну или mJpeg кодеки, там потери есть, но на убитом видео вы этого не ощутите.

bredych 28-09-2022 09:40 2993192

Цитата:

Цитата Amigos
Если вы уж так трясётесь за качество, »

стандартная обработка видеопотока включает как минимум переформатирование размера до стандартного (возможно, обрезка, масштаб, пад), установка сар/дар, склейка, фейдауты, дешейк или стаб.
Если стаб не справляется, то еще и делого. Если бледное, то еще и кривые/контрасты. Иногда по маске. И после этого еще заливка в сеть, где оно еще раз перекодируется с еще одним мылом.
Если всё лепить отдельными стадиями - получается пластилин, который только в мусорку без вариантов. Потому что можно - обьединяю. Минимум 3 стадии (плюс перекодировка в сети) обьединить невозможно.
Остальное хотелось бы без перекодировок по возможности. Потому хотелось бы решения про пайп, а не "зачем вам оно, вам оно не надо" :)


Время: 22:27.

Время: 22:27.
© OSzone.net 2001-