LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 12-03-2021, 03:01 PM   #1
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Rep: Reputation: 15
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
 
Old 12-03-2021, 05:03 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,691

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
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
 
Old 12-03-2021, 05:22 PM   #3
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Original Poster
Rep: Reputation: 15
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 $
 
Old 12-03-2021, 05:43 PM   #4
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Original Poster
Rep: Reputation: 15
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
 
Old 12-03-2021, 06:18 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,691

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
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
 
Old 12-03-2021, 08:42 PM   #6
ejames82
Member
 
Registered: Jun 2009
Posts: 110

Original Poster
Rep: Reputation: 15
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 $
 
Old 12-04-2021, 09:00 AM   #7
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] 10d6:1101 Actions Semiconductor Co., Ltd D-Wave 2GB MP4 Player / AK1025 MP3/MP4 RandomTroll Linux - Hardware 2 07-07-2019 10:51 AM
10d6:1101 Actions Semiconductor Co., Ltd D-Wave 2GB MP4 Player / AK1025 MP3/MP4 Player T RandomTroll General 5 07-19-2018 10:42 PM
Help: Batch convert from MKV & embed subtitles to MP4 alhatmy Linux - Software 4 06-27-2017 04:41 PM
converter for mp4, I-Pods and other portable mp4's ? stefan_rogin2000 Linux - Software 5 03-26-2008 02:43 AM
FFMPEG vs MPLAYER vs MENCODER and batch conversions to MP4 ? AngusM Linux - Software 2 11-08-2006 08:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration