Youtube video und audio separat downloaden und mit ffmpeg mergen

Sound, Digitalkameras, TV+Video und Spiele.
Antworten
mino23
Beiträge: 64
Registriert: 15.07.2019 18:49:51

Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von mino23 » 19.06.2022 12:31:10

Ich weiß wie ich mit youtube-dl oder yt-dlp automatisch downloaden und automatisch mergen kann. Leider spielt mein DVB-T Tuner nur das Video ab, aber nicht den Ton, wenn ich das mit yt-dlp gemergte mp4 Video abspielen möchte. Der vlc spielt Video und Ton ab. Mit *.mkv als Kontainer habe ich das gleich Problem.

Deswegen möchte ich Video und Audio separat downloaden und mit ffmpeg mergen.

An den von Youtube angebotenen vor-gemerged'ten mp4 Videos (22) bin ich nicht interessiert. Die gehen nur bis 1280x720. Ich möchte das Video in 1920x1080 mp4 Videoformat und dazu das passende Audio. Ich weiß nicht was das passende Audioformat ist, aber ich denke es ist m4a, wenn ich als Ausgabe *.mp4 haben möchte.

Kann mir bitte jemand einen Tipp geben, wie ich das mit ffmpeg merge und welches Audioformat ich downloaden muß?

soundrolf
Beiträge: 265
Registriert: 21.07.2009 13:50:22
Lizenz eigener Beiträge: GNU General Public License
Wohnort: Köln

Re: Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von soundrolf » 19.06.2022 12:54:46

Der Youtube Downloader zeigt dir einiges an.
Mit diesem Befehl:

Code: Alles auswählen

yt-dlp --help
zum Beispiel für Audio
Post-Processing Options:
-x, --extract-audio Convert video files to audio-only files (requires
ffmpeg and ffprobe)
--audio-format FORMAT Specify audio format to convert the audio to when -x
is used. Currently supported formats are: best
(default) or one of aac, flac, mp3, m4a, opus,
vorbis, wav, alac
--audio-quality QUALITY Specify ffmpeg audio quality to use when converting
the audio with -x. Insert a value between 0 (best)
and 10 (worst) for VBR or a specific bitrate like
128K (default 5)
--remux-video FORMAT Remux the video into another container if necessary
(currently supported: mp4, mkv, flv, webm, mov, avi,
mka, ogg, aac, flac, mp3, m4a, opus, vorbis, wav,
alac). If target container does not support the
video/audio codec, remuxing will fail. You can
specify multiple rules; Eg. "aac>m4a/mov>mp4/mkv"
will remux aac to m4a, mov to mp4 and anything else
to mkv.
--recode-video FORMAT Re-encode the video into another format if re-
encoding is necessary. The syntax and supported
formats are the same as --remux-video
--postprocessor-args NAME:ARGS Give these arguments to the postprocessors. Specify
the postprocessor/executable name and the arguments
separated by a colon ":" to give the argument to the
specified postprocessor/executable. Supported PP are:
Merger, ModifyChapters, SplitChapters, ExtractAudio,
VideoRemuxer, VideoConvertor, Metadata,
EmbedSubtitle, EmbedThumbnail, SubtitlesConvertor,
ThumbnailsConvertor, FixupStretched, FixupM4a,
FixupM3u8, FixupTimestamp and FixupDuration. The
supported executables are: AtomicParsley, FFmpeg and
FFprobe. You can also specify "PP+EXE:ARGS" to give
the arguments to the specified executable only when
being used by the specified postprocessor.
Additionally, for ffmpeg/ffprobe, "_i"/"_o" can be
appended to the prefix optionally followed by a
number to pass the argument before the specified
input/output file. Eg: --ppa "Merger+ffmpeg_i1:-v
quiet". You can use this option multiple times to
give different arguments to different postprocessors.
(Alias: --ppa)
Gruß soundrolf

mino23
Beiträge: 64
Registriert: 15.07.2019 18:49:51

Re: Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von mino23 » 19.06.2022 16:01:47

soundrolf hat geschrieben: ↑ zum Beitrag ↑
19.06.2022 12:54:46
Der Youtube Downloader zeigt dir einiges an.
Mit diesem Befehl:

Code: Alles auswählen

yt-dlp --help
zum Beispiel für Audio
Post-Processing Options:
-x, --extract-audio Convert video files to audio-only files (requires
ffmpeg and ffprobe)
--audio-format FORMAT Specify audio format to convert the audio to when -x
is used. Currently supported formats are: best
(default) or one of aac, flac, mp3, m4a, opus,
vorbis, wav, alac
--audio-quality QUALITY Specify ffmpeg audio quality to use when converting
the audio with -x. Insert a value between 0 (best)
and 10 (worst) for VBR or a specific bitrate like
128K (default 5)
--remux-video FORMAT Remux the video into another container if necessary
(currently supported: mp4, mkv, flv, webm, mov, avi,
mka, ogg, aac, flac, mp3, m4a, opus, vorbis, wav,
alac). If target container does not support the
video/audio codec, remuxing will fail. You can
specify multiple rules; Eg. "aac>m4a/mov>mp4/mkv"
will remux aac to m4a, mov to mp4 and anything else
to mkv.
--recode-video FORMAT Re-encode the video into another format if re-
encoding is necessary. The syntax and supported
formats are the same as --remux-video
--postprocessor-args NAME:ARGS Give these arguments to the postprocessors. Specify
the postprocessor/executable name and the arguments
separated by a colon ":" to give the argument to the
specified postprocessor/executable. Supported PP are:
Merger, ModifyChapters, SplitChapters, ExtractAudio,
VideoRemuxer, VideoConvertor, Metadata,
EmbedSubtitle, EmbedThumbnail, SubtitlesConvertor,
ThumbnailsConvertor, FixupStretched, FixupM4a,
FixupM3u8, FixupTimestamp and FixupDuration. The
supported executables are: AtomicParsley, FFmpeg and
FFprobe. You can also specify "PP+EXE:ARGS" to give
the arguments to the specified executable only when
being used by the specified postprocessor.
Additionally, for ffmpeg/ffprobe, "_i"/"_o" can be
appended to the prefix optionally followed by a
number to pass the argument before the specified
input/output file. Eg: --ppa "Merger+ffmpeg_i1:-v
quiet". You can use this option multiple times to
give different arguments to different postprocessors.
(Alias: --ppa)
Gruß soundrolf
Genau das wollte ich vermeiden, weil - ich schrieb es in meinem Eingangspost - ich das bereits getestet habe und es hat nicht funktioniert. Ich habe jetzt nicht alle Optionen getestet, das dauert sicherlch Manntage, aber die Optionen die ich testete, ergaben bei mir ein video bei dem der Ton von meinem DVB-T Tuner nicht abgespielt wird. Deswegen wollte ich das einzeln Downloaden.

Eigentlich muß ich nur wissen, ob m4a as Audiodatei OK ist. Den Teil mit ffmpeg kläre ich danach sicherlich selbst. Danke für den Tipp mit --help. :)

tobo
Beiträge: 1990
Registriert: 10.12.2008 10:51:41

Re: Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von tobo » 19.06.2022 16:45:27

mino23 hat geschrieben: ↑ zum Beitrag ↑
19.06.2022 16:01:47
Eigentlich muß ich nur wissen, ob m4a as Audiodatei OK ist. Den Teil mit ffmpeg kläre ich danach sicherlich selbst. Danke für den Tipp mit --help. :)
m4a ist nur eine Dateiendung, wo dann meistens ein AAC-Audio drin steckt. Aber ja, m4a ist ok. Im Übrigen benutzen youtube-dl und yt-dlp intern (wenn nicht anders konfiguriert) ffmpeg zum Zusammenführen der Spuren...

MaGe
Beiträge: 1715
Registriert: 01.06.2014 17:12:16

Re: Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von MaGe » 19.06.2022 16:51:56

mino23 hat geschrieben: Eigentlich muß ich nur wissen, ob m4a as Audiodatei OK ist [...]

Code: Alles auswählen

 yt-dlp -F https://www.youtube.com/watch?v=WLXhoFfV-YI 
Zeigt dir den inhalt

Muster:

Code: Alles auswählen

 yt-dlp -f 136+140 https://www.youtube.com/watch?v=WLXhoFfV-YI 
wobei f136 das Video ist .mp4 = h264
wobei f140 das Audio ist .m4a = acc



gruss MaGe
Wir müssen uns vor der Klimaerwärmung nicht fürchten.
Uns rottet die soziale Kälte viel früher aus.

MaGe
Beiträge: 1715
Registriert: 01.06.2014 17:12:16

Re: Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von MaGe » 25.06.2022 11:13:09

mino23 hat geschrieben: Bei *.mp4 und *.m4a zu mp4 wird die Audiospur neu codiert und die Datei ist unwesentlich kleiner. [...]
Bei mir nicht!
Muster: Video,Audio,getrennt

Code: Alles auswählen

 time ffmpeg -i *.mp4 -i *.m4a -c copy JAMES_BOND-Trailer.mp4 
real 0m0,162s



gruss MaGe
Wir müssen uns vor der Klimaerwärmung nicht fürchten.
Uns rottet die soziale Kälte viel früher aus.

Willi411
Beiträge: 22
Registriert: 08.04.2022 17:08:16

Re: Youtube video und audio separat downloaden und mit ffmpeg mergen

Beitrag von Willi411 » 30.07.2022 17:58:46

Hallo!

Da ich auch öfters Video und Audio zusammenfügen muß, da HD-Videos bei youtube-dl oft die Tonspur nicht enthalten, hatte ich mir mal ein kleines Script gemacht. Du mußt dafür aber noch "yad" installieren:

Code: Alles auswählen

#!/bin/bash

IFS="|"

if [ -e $HOME/.audio_und_video_zusammenfuegen ]
then
   verzeichnis=`cat $HOME/.audio_und_video_zusammenfuegen`
   cd "$verzeichnis"
fi

verzeichnis=`yad --width 800 --height 650 --center --title "Ziel-Verzeichnis wählen:" --file --directory`

case $? in
 1) exit ;;
esac

echo "$verzeichnis" > $HOME/.audio_und_video_zusammenfuegen

cd "$verzeichnis"


yad --button "Start" --button Beenden \
--title "Audio und Video zusammenfügen" \
--form --center --align=right --width 600 \
--field "Audio-Datei wählen:":FL " " \
--field "Video-Datei wählen:":FL " " \
--field "Seitenverhältnis":CB 'Seitenverhältnis beibehalten!4:3!16:9' > .einlesen.tmp


case $? in
 1) rm .einlesen.tmp; exit ;;
esac

audio=`cut -d"|" -f1 .einlesen.tmp`
video=`cut -d"|" -f2 .einlesen.tmp`
aspect=`cut -d"|" -f3 .einlesen.tmp`
i=-i

dateiname=`echo $video | cut -d"." -f1`
dateiname=`echo $dateiname | rev | cut -d"/" -f1 | rev`

endung=`echo $video | rev | cut -d"." -f1 | rev`

audio1=`echo $audio | rev | cut -d"/" -f1 | rev`


if [ "$audio1" = " " ]
then
 audio=""
 i=""
fi


case $aspect in
  "Seitenverhältnis beibehalten") aspect1= aspect2= ;;
  "4:3") aspect1="-aspect" aspect2="1.3333" ;;
  "16:9") aspect1="-aspect" aspect2="1.7777" ;;
esac




# xterm -T "Kopiervorgang mit [q] beenden" -geometry 1111x20 -e 
ffmpeg -i $video $i $audio \
-c copy \
$aspect1 $aspect2 \
-threads:1 4 \
$dateiname"_"$(date +%H-%M-%S).$endung

rm .einlesen.tmp


exit
Die Dateinamen von Audio und Video sollten am besten keine Leerzeichen, Punkte, Ausrufungszeichen oder andere "Sonderzeichen" enthalten.

Antworten