Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
12-03-2021, 03:01 PM
#1
Member
Registered: Jun 2009
Posts: 110
Rep:
want a batch convert ts to mp4. I have this code, it doesn't work
hi,
I am hoping to find something to run in the linux mint terminal that will convert all of the .ts files that it finds to .mp4 in a directory.
while searching google I found this:
------------------------------------------------------------------------
for %%f in (*.ts) do (
ffmpeg -i "%%f" -c:v h264_nvenc -c:a copy "%%f.mp4"
)
pause
------------------------------------------------------------------------
when I ran it in the terminal, I got this:
ed@ed-MS-7759 ~/Desktop/jsdtd $ for %%f in (*.ts) do (
bash: syntax error near unexpected token `('
ed@ed-MS-7759 ~/Desktop/jsdtd $ ffmpeg -i "%%f" -c:v h264_nvenc -c:a copy "%%f.mp4"
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
%%f: No such file or directory
ed@ed-MS-7759 ~/Desktop/jsdtd $ )
bash: syntax error near unexpected token `)'
ed@ed-MS-7759 ~/Desktop/jsdtd $
ed@ed-MS-7759 ~/Desktop/jsdtd $ pause
the questions I have:
what does the groupings of %%f (three instances) mean, individually?
do I need to substitute the first %%f with absolute path, in this case /home/ed/Desktop/jsdtd?
is there anything else wrong with the code?
do I need to make a .sh file to use this?
thanks
12-03-2021, 05:03 PM
#2
Moderator
Registered: Aug 2002
Posts: 25,691
Code:
for %%f in (*.ts) do (
ffmpeg -i "%%f" -c:v h264_nvenc -c:a copy "%%f.mp4"
)
pause
This is a Windows/DOS batch file which does not work on linux. A quick conversion to bash...
Code:
for f in *.ts; do
ffmpeg -i "$f" -c:v h264_nvenc -c:a copy "$(basename -- "$f" .ts).mp4"
done
12-03-2021, 05:22 PM
#3
Member
Registered: Jun 2009
Posts: 110
Original Poster
Rep:
hello michaelk,
there's probably something wrong on my end.
this is what happened:
ed@ed-MS-7759 ~/Desktop/jsdtd $ for f in *.ts; do
> ffmpeg -i "$f" -c:v h264_nvenc -c:a copy "$(basename -- "$f" .ts).mp4"
> done
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mpegts, from 'erjyr.ts':
Duration: 00:39:59.40, start: 1.400000, bitrate: 616 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 428x240 [SAR 1:1 DAR 107:60], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 52 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
Cannot load libcuda.so.1
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mpegts, from 'ryyk.ts':
Duration: 00:57:23.76, start: 1.400000, bitrate: 250 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 576x432, 15 fps, 60 tbr, 90k tbn, 30 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 43 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
Cannot load libcuda.so.1
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
ed@ed-MS-7759 ~/Desktop/jsdtd $
12-03-2021, 05:43 PM
#4
Member
Registered: Jun 2009
Posts: 110
Original Poster
Rep:
I see this in the terminal output:
Cannot load libcuda.so.1
my google search suggests it's part of the cuda package, so I installed the latest libcuda
ed@ed-MS-7759 ~/Desktop/jsdtd $ for f in *.ts; do ffmpeg -i "$f" -c:v h264_nvenc -c:a copy "$(basename -- "$f" .ts).mp4"; done
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mpegts, from 'erjyr.ts':
Duration: 00:39:59.40, start: 1.400000, bitrate: 616 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 428x240 [SAR 1:1 DAR 107:60], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 52 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264_nvenc @ 0x32a72e0] Cannot init CUDA
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
ffmpeg version 3.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mpegts, from 'ryyk.ts':
Duration: 00:57:23.76, start: 1.400000, bitrate: 250 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 576x432, 15 fps, 60 tbr, 90k tbn, 30 tbc
Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, mono, fltp, 43 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_nvenc))
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[h264_nvenc @ 0x3251500] Cannot init CUDA
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
ed@ed-MS-7759 ~/Desktop/jsdtd $
thanks for the reply michaelk, it was worth a shot. it made a file, the file just wouldn't play
12-03-2021, 06:18 PM
#5
Moderator
Registered: Aug 2002
Posts: 25,691
I have not played with ffmpeg in a long time try this on a single file.
ffmpeg -i input.ts -c:v libx264 -c:a copy output.mp4
12-03-2021, 08:42 PM
#6
Member
Registered: Jun 2009
Posts: 110
Original Poster
Rep:
I captured the terminal output that I considered relevant. it did work. nice job.
frame=71910 fps=273 q=-1.0 Lsize= 78820kB time=00:39:59.33 bitrate= 269.1kbits/s dup=2453 drop=0 speed=9.12x
video:62527kB audio:14258kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.650616%
[libx264 @ 0x3dfa2a0] frame I:392 Avg QP:20.56 size: 10253
[libx264 @ 0x3dfa2a0] frame P:18430 Avg QP:23.53 size: 2090
[libx264 @ 0x3dfa2a0] frame B:53088 Avg QP:29.27 size: 405
[libx264 @ 0x3dfa2a0] consecutive B-frames: 0.9% 1.3% 2.1% 95.7%
[libx264 @ 0x3dfa2a0] mb I I16..4: 6.5% 57.3% 36.1%
[libx264 @ 0x3dfa2a0] mb P I16..4: 1.6% 5.8% 1.3% P16..4: 38.6% 21.4% 9.8% 0.0% 0.0% skip:21.5%
[libx264 @ 0x3dfa2a0] mb B I16..4: 0.1% 0.4% 0.1% B16..8: 37.3% 4.7% 0.7% direct: 0.7% skip:56.0% L0:41.4% L1:52.4% BI: 6.3%
[libx264 @ 0x3dfa2a0] 8x8 transform intra:65.1% inter:74.5%
[libx264 @ 0x3dfa2a0] coded y,uvDC,uvAC intra: 64.0% 70.7% 20.4% inter: 8.7% 7.5% 0.1%
[libx264 @ 0x3dfa2a0] i16 v,h,dc,p: 29% 19% 6% 45%
[libx264 @ 0x3dfa2a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 18% 13% 6% 8% 9% 9% 10% 8%
[libx264 @ 0x3dfa2a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 17% 10% 7% 9% 9% 9% 8% 6%
[libx264 @ 0x3dfa2a0] i8c dc,h,v,p: 52% 19% 22% 7%
[libx264 @ 0x3dfa2a0] Weighted P-Frames: Y:0.5% UV:0.1%
[libx264 @ 0x3dfa2a0] ref P L0: 63.1% 16.1% 15.5% 5.3% 0.0%
[libx264 @ 0x3dfa2a0] ref B L0: 91.6% 6.3% 2.1%
[libx264 @ 0x3dfa2a0] ref B L1: 96.5% 3.5%
[libx264 @ 0x3dfa2a0] kb/s:213.48
ed@ed-MS-7759 ~/Desktop/herhb $
12-04-2021, 09:00 AM
#7
LQ Guru
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
I would recommend something like this.
Code:
#Array of vids
vids=(file1.ts file2.ts file3.ts file4.ts)
#Loop through them
for v in "${vids[@]}"; do
#Example: 24fps, 768x432 x264 vid, copy audio, into a mp4 container, same name as input
ffmpeg -i "$v" -c:a copy -c:v libx264 -crf 18 -preset slow -maxrate 3000k -bufsize 1M -r 24 -s 768x432 ${v%.*}.mp4
done
All times are GMT -5. The time now is 05:58 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News