How to download multiple videos from an input ".txt" file with ".m3u8" links through FFMPEG and GPU acceleration - ffmpeg

I have a file .txt which contains multiple source links like:
https://videosource1.m3u8
https://videosource2.m3u8
.
.
.
And I want to download all of them using FFMPEG with a script/bash or any for/while cycle.
I tried with this command but with no success, knowing I'm using GPU acceleration:
for %i in (path_txt_file\file.txt\*.m3u8) do ffmpeg -i "%i" -c:v hevc_nvenc -rc constqp -qp 31 -c:a aac -b:a 64k -ac 1 "output_path\%~ni.mp4"

Related

FFMPEG Growing Input files

I'm having issues with piping the ffmpeg out to the ffmpeg input. I have tried as below
ffmpeg -i "y:\3000012936-TXMHD.mxf" -vcodec copy -acodec copy -f mpegts pipe:1 | ffmpeg -re -i pipe:0 -pix_fmt yuv420p -vsync 1 -map 0:v:0 -map 0:a:0 -c:a aac -c:v libx264 -use_template 1 -use_timeline 1 -init_seg_name "init-stream$RepresentationID$-$Bandwidth$.mp4" -media_seg_name "chunk-stream$RepresentationID$-$Number%05d$.$ext$" -b:v 1500k -b:a 128k -ac 2 -profile:v main -level:v 3.0 -s 1920x1080 -r 25 -vsync passthrough -increment_tc 1 -adaptation_sets "id=0,streams=v id=1,streams=a" -g 100 -keyint_min 100 -seg_duration 5 -frag_duration 5 -dash_segment_type auto -f dash "stream.mpd"
But I'm getting an error:
Conversion failed! av_interleaved_write_frame(): Broken pipe Error
writing trailer of pipe:1: Broken pipe
The input file is MXF, and output is going to be MPEG DASH. The reason to do the piping is because the input file is a growing mxf file. If i do it without piping the ffmpeg just closes before the mxf file is written completely.
Why not let ffmpeg read the file at the same framerate as the source media? If ffmpeg reads at the same speed as the file is written then it will never catch up and close the output.
ffmpeg -re -i "y:\3000012936-TXMHD.mxf" . . . . . . . .
There needs to be enough data on the source before you start ffmpeg. In case of network drives there could be a delay between writing data and that data being available over the network.

How to I convert all audio tracks to eac3 and keep all subtitles?

I'm not familiar with ffmpeg, but came across this script that takes in the file and creates an output with eac3 audio.
#!/bin/sh
echo "Dolby Digital Plus Muxer"
echo "Developed by #kdcloudy, not affiliated with Dolby Laboratories"
echo "Enter the file name to be converted: "
read filepath
if [! -d $filepath]
then
exit $err
fi
ffmpeg -i $filepath -vn ddp.eac3
ffmpeg -i $filepath -i ddp.eac3 -vcodec copy -c:a eac3 -map 0:s -map 0:v:0 -map 1:a:0 output.mp4
rm ddp.eac3
I'd like to know what to modify in this code to ensure all the subtitles are copied from the original file and all the available audio tracks are converted to eac3 and added to the output.mp4 file.
For the subtitles copying I tried -map but couldn't get it to work. Thanks for the help!
You only need one ffmpeg command:
ffmpeg -i input.mkv -map 0 -c:v copy -c:a eac3 -c:s copy output.mkv
-map 0 Selects all streams. Otherwise only one stream per stream type will be selected. See FFmpeg Wiki: Map for more into on -map.
-c:v copy Stream copy all video.
-c:a eac3 Encodes all audio to E-AC-3.
-c:s copy Stream copy all subtitles.
For compatibility this assumes that the input and output are both Matroska (.mkv).
That script is not great. Here's a cleaner, simpler version (not that I think a script is necessary for this):
#!/bin/bash
# Usage: ./eac3 input.mkv output.mkv
ffmpeg -i "$1" -map 0 -c:v copy -c:a eac3 -c:s copy "$2"
If you want to convert a whole directory see How do you convert an entire directory with ffmpeg?

How to convert an MP3 file to an Ogg Opus file?

Is there a converter that can convert MP3 files to Ogg Opus?
Can you recommend one that can do it?
So far I've tried Adobe Audition, Xilisoft Audio Converter Pro, WinAVI Video Converter, and Aimersoft Video Converter Pro. None of them was useful.
The easiest option is a command like this
ffmpeg -i input.mp3 -c:a libopus output.opus
But there is a selection of parameters you can tweak, all documented here.
E.g. I use the following command to compress audiobooks/podcasts (the resulting ~32 kbps OPUS files sound indistinguishable from 192 kbps MP3):
ffmpeg -i input.mp3 -c:a libopus -b:a 32k -vbr on -compression_level 10 -frame_duration 60 -application voip output.opus
-b:a 32k sets bitrate to 32 kbps (or about 35 kbps in case of VBR), it can be reasonable to use 128k to compress music given a lossless (or a 320k MP3) original or 64k to compress music given a 192k MP3 original
-vbr on turns variable bitrate mode on (may increase quality at cost of a using some additional kbits for some seconds)
-compression_level 10 commands to favour quality over compression speed
-frame_duration 60 increases quality at cost of 40 additional milliseconds of latency
-application voip asks to do the best possible to save speech intelligibility, use -application audio for music
You can convert a set of many files this way in bash:
for f in *.mp3; do ffmpeg -i "$f" -c:a libopus "${f%.*}.opus"; done
Convert MP3 files in all subfolders recursively and utilizing all CPU
NOTE: FFmpeg multithread -thread n argument is ignored when encoding OPUS files.
Preparing
Install GNU parallel, FFmpeg, and MP3 with Opus codecs
sudo apt install -y parallel ffmpeg libmp3lame libopus
Usage
Recursive and using all CPUs:
find -iname "*.mp3" -type f Find all MP3 files in whole directory
parallel -I% --max-args 1 Prepare parallel to use % char as argument for file path saving
-c:a opus Set OPUS as encoder
-strict -2 Enable FFmpeg to work with OPUS encoder
-b:a 128K -vbr on Set OPUS at 128 KB/s (VBR) that is enough to store stereo music
-map_metadata 0 Copy tags from MP3 to OPUS file
-compression_level 10 Favour quality over compression speed
-y Overwrite OPUS file if already exists
touch -r % %.opus Use MP3 file's times instead of newly created files
rm -vf % Remove MP3 file
find -iname "*.mp3" -type f | parallel -I% --max-args 1 \
"ffmpeg -i % -strict -2 -c:a opus -b:a 128K -vbr on -map_metadata 0 -compression_level 10 -y %.opus;touch -r % %.opus;rm -vf %"
NOTE: Don't use -frame_duration argument for mixing audio purposes
Try ffmpeg with -acodec libopus

getting file name from for %%i variable

I had a script that converts all mkvs in a folder to mp4s using ffmpeg. The downside is that it left the .mkv extension and just added .mp4 (eg: file.mkv.mkp4). I know %~n can be used to get a name without the extension, but I can't seem to figure it out.
Here's my original script:
for %%i IN (*.mkv) DO (ffmpeg -y -ss 00:00:00 -threads 6 -i "%%i" -vcodec copy -f mp4 -strict experimental -acodec aac -ab 128k -ac 2 "%%i.mp4")
Here's what I've tried:
for %%i IN (*.mkv) DO (ffmpeg -y -ss 00:00:00 -threads 6 -i "%~ni.mkv" -vcodec copy -f mp4 -strict experimental -acodec aac -ab 128k -ac 2 "%~ni.mp4")
Percent signs of loop variables must be doubled in batch scripts, so you have to use %%~ni instead of %~ni. See the Examples section in the documentation.

FFMpeg Batch Image + Multiple Audio to video

Im trying to do the following with FFMpeg I want to create multiple videos with one image and different audio files (music albums). These are my own albums so I have rights to do so before you ask. I have 100's of audio files to stick up on youtube.
Is there a way I can create this in batch so i can just load one image (album cover) and multiple audio files (the album tracks) and get videos to the tracks length automatically?
Appreciate any help
i use this portion of code to do the conversion for my YouTube video:
for %%a in ("*.*")
do
"C:\ffmpeg\bin\ffmpeg" -loop 1 -i "C:\ffmpg\bin\input.jpg" -i "%%a" -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -vf scale=854:480 -c:a aac -shortest -strict experimental -b:a 192k -shortest "C:\mp4\%%~na.mp4"
pause
"C:\ffmpeg\bin\ffmpeg" the folder of codec
"C:\ffmpg\bin\input.jpg" image path
"C:\mp4\%%~na.mp4" output folder
-vf scale=854:480 you can specify the resolution of your video 16:9 for youtube video
-c:a aac -shortest use aac codec, by specify -shortest the video length will match the audio length
if there an error use libvo_aacenc instead of aac codec like that:
-c:a libvo_aacenc -shortest -strict experimental
i hope that help
Im trying almost same thing, look how ive done:
#echo off
set /P format="Type the Video Format: "
for %i in (*.%format) <<<< geting not a reconiezed by CMD
do #echo file '%i' > Lista-%format%.txt
mylist=Lista-%format%.txt
ffmpeg.exe -i %mylist% -vf scale=480:320 output-%mylist%.%format%

Resources