Cannot grep out status line (terminal playback time) from mpv - linux

essentially I'm trying to just run mpv on a video, and after you quit you get some information about the video.
Example:
(+) Video --vid=1 (*) (hevc 1920x1080 60.000fps)
(+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p
AV: 00:00:01 / 00:12:32 (0%) A-V: 0.000
Exiting... (Quit)
I would like to grep out the AV line, however this line is added before/afterwards (I'm not exactly sure). When running mpv video_file | grep AV
The video would play and the terminal would give this little status line
(Paused) AV: 00:00:02 / 00:00:57 (5%) A-V: 0.000 (random example video, different to the first one)
However after closing mpv there is no output, and its further confirmed when running
mpv video_file >> test.txt
giving an output of
(+) Video --vid=1 (*) (hevc 1920x1080 60.000fps)
(+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [pulse] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p
Exiting... (Quit)
suggesting that it places the AV line outside of the output, between VO line and the space line.
Soooo like how would I grep out this line?

Related

FFmpeg - Crossfading inputs with a duration < 1s creates an empty output

I am trying to crossfade a silent input with a music to delay the moment when the music starts to play.
I built the command using fluent-ffmpeg so I could choose the duration of the silent input through my program. The duration of the crossfade is calculated according to the duration of the 2 inputs, and equals 0 if one of them is too short.
Below is an example of the resulting command:
ffmpeg -f lavfi -i anullsrc=r=44100 -i music.mp3 -y -filter_complex [0]atrim=duration=0.28[atrim_0];[atrim_0][1]acrossfade=d=0:c1=tri:c2=tri[final] -map [final] output.mp3
However, this command creates an empty output file when the duration of the silent input is inferior to 1 second, regardless of which music input is next. Using the same command with a trim duration > 1 second creates a valid output with the silence and the music.
I have tried to look through the FFmpeg debug report but couldn't really see what was wrong.
Below is an excerpt of the debug log report:
Input file #0 (anullsrc=r=44100):
Input stream #0:0 (audio): 14 packets read (28672 bytes); 14 frames decoded (14336 samples);
Total: 14 packets (28672 bytes) demuxed
Input file #1 (music.mp3):
Input stream #1:0 (audio): 504 packets read (210651 bytes); 504 frames decoded (578372 samples);
Total: 504 packets (210651 bytes) demuxed
Output file #0 (output.mp3):
Output stream #0:0 (audio): 0 frames encoded (0 samples); 0 packets muxed (0 bytes);
Total: 0 packets (0 bytes) muxed
Any idea what could cause this?
PS: I am using FFmpeg 4.4, and the same command with FFmpeg 4.2 lead to a segmentation fault. Don't know if this can be of any help
acrossfade can accept crossfade duration through two exclusive options: nb_samples (default: 44100) and duration (default: 0). When the latter isn't set, the former is used. So, in your command, acrossfade uses a crossfade duration of 44100 samples or 1 second. The filter needs both inputs to be at least as long as the crossfade duration.
However, in your case, it seems you just want to do two things: fade in the audio and maybe delay it. Just use afade for that.
ffmpeg -i music.mp3 -y -af afade=d=1:curve=tri,adelay=0.28s:all=1 output.mp3
This will fade-in the music over one second and delay the start by 0.28s.

FFmpeg - how to set output sample_size

Trying to create a simple command line player for .dsf (DSD audio) files, and output to an alsa device that supports up to 24-bit 192 kHz sample rate. The following command almost works and it does play the track. Examining the bold text below, the dsf input file is converted to 24-bit/192 kHz, but the output is then truncated to 16-bit 192 kHz (pcm_s16le i.e, 16 bit little endian).
ffmpeg -i '01 - Sweet Georgia Brown.dsf' -f alsa hw:0,0
After displaying the ffmpeg banner and song metadata (tags), here is the result, bold is my emphasis:
Duration: 00:05:14.83, start: 0.000000, bitrate: 9234 kb/s
Stream #0:0: Audio: flac, 192000 Hz, stereo, s32 (24 bit)
Stream mapping:
Stream #0:0 -> #0:0 (flac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, alsa, to 'hw:0,0':
Since I can play this and many other tracks at full resolution using another player (foobar2000) it seems there might be an option in the encoder which is part of FFmpeg: Lavf57.83.100 I can find no information in any of the FFmpeg documentation that helps. Tried finding options in FFplay and even guessing using other FFmpeg options like this example.
ffmpeg -sample_fmt s24 -i '01 - Sweet Georgia Brown.dsf' -f alsa hw:0,0 ***** same results.
I'm stuck. Any suggestions?
Environment: Linux Mint 19.2, 64-bit, ASUS Xonar STXii sound card.
Each output format or device has a default encoder registered for each media type it accepts. ALSA accepts audio and its default encoder is 16-bit signed PCM.
You can change the encoder by specifying one.
ffmpeg -i '01 - Sweet Georgia Brown.dsf' -c:a pcm_s24le -f alsa hw:0,0

convert MOV to mp4 using transcode

I want to convert a MOV from my Casio cam to mp4 using transcode. Why transcode? Because I also want to deshake the video in the same step.
When I use
ffmpeg -i in.MOV out.mp4
it works. When using
transcode -J stabilize -i in.MOV
or
transcode -J transform -i in.MOV -y ffmpeg -F mpeg4 -o out.mp4
I get hundreds of these errors:
[ffmpeg_audio] Error: avcodec_open2 failed
[adpcm_ima_wav # 0x1f7f180] Only 4-bit ADPCM IMA WAV files are supported
This looks to me as if transcode uses ffmpeg internally.
I could use ffmpeg to make it mp4 first and then use transcode to stabilize the video, but then it would be re-encoded twice which I would like to avoid.
This is what mplayer says about my MOV file:
MPlayer2 2.0-701-gd4c5b7f-2ubuntu2 (C) 2000-2012 MPlayer Team
Cannot open file '/home/koem/.mplayer/input.conf': No such file or directory
Failed to open /home/koem/.mplayer/input.conf.
Cannot open file '/etc/mplayer/input.conf': No such file or directory
Failed to open /etc/mplayer/input.conf.
Playing 1-original.MOV.
Detected file format: QuickTime / MOV (libavformat)
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (adpcm_ima_wav), -aid 0, -alang eng
Clip info:
major_brand: qt
minor_version: 537921536
compatible_brands: qt caqv
creation_time: 2017-01-02 23:31:38
Load subtitles in .
Failed to open VDPAU backend libvdpau_i965.so: cannot open shared object file: No such file or directory
[vdpau] Error when calling vdp_device_create_x11: 1
[ass] auto-open
Selected video codec: H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [libavcodec]
Selected audio codec: ADPCM IMA WAV [libavcodec]
AUDIO: 44100 Hz, 2 ch, s16le, 352.8 kbit/25.00% (ratio: 44100->176400)
AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample)
Starting playback...
VIDEO: 1920x1080 29.970 fps 15940.0 kbps (1992.5 kB/s)
VO: [xv] 1920x1080 => 1920x1080 Planar YV12
Colorspace details not fully supported by selected vo.
A: 1.1 V: 1.1 A-V: -0.000 ct: 0.000 0/ 0 16% 8% 1.6% 0 0
Exiting... (Quit)
How can I make it work with transcode without using ffmpeg first?
FFmpeg has a deshake as well as a stabilization filter. Get a new binary if yours doesn't.
To continue with your existing binaries, run
ffmpeg -i in.MOV -vcodec copy out.mp4
This will skip video re-encoding.

mplayer output 4 audio channels to jack

I am struggling with getting mplayer to reproduce a 4 audio channel wav file.
I created a 4chn audio file.
Want mplayer to player, and output it to jack.
The problem is that i am only able to get in jack 2 mplayer channels.
if I do:
mplayer -ao jack -channels 4 test_4chan_2.wav
mplayer plays and responds:
laying test_4chan_2.wav.
libavformat version 54.6.100 (internal)
Audio only file format detected.
Load subtitles in ./
==========================================================================
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 44100 Hz, 4 ch, s16le, 2822.4 kbit/100.00% (ratio: 352800->352800)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)
==========================================================================
AO: [jack] 44100Hz 2ch floatle (4 bytes per sample)
Video: no video
Starting playback...
and jack has only the following outputs:
system:capture_1
system:capture_2
system:playback_1
system:playback_2
MPlayer [14434]:out_0
MPlayer [14434]:out_1
So it seems that mplayer recognizes that the input file as 4ch
but on AO: [jack] only 2ch appear
if I try the same with ecasound:
ecasound -f 16,4,44100 -i test_4chan_2.wav -o jack
in Jack ecasoud appears with 4 outputs
system:capture_1
system:capture_2
system:playback_1
system:playback_2
ecasound:out_1
ecasound:out_2
ecasound:out_3
ecasound:out_4
Do you have any idea of what could I be doing wrong??
I am running Debian (Jessy) and mplayer 1.1-4.7
Thanks a lot
Solved. Only need to upgrade mplayer to 4.8, in Debian Sid.
And
mplayer -channels 4 -ao jack:noconnect 4chn_file.wav
did the trick.
The -ao jack:noconnect means:
-ao audio-output: jack
noconnect: prevent mplayer to make 1-to-1 connections. As I have 2 different stereo audio sound cards, mplayer was only giving me 2 channels. And this option disables that start behavior.
hope it will be of help to someone else ,)

How to join webcam FLVs

I want my website to join some webcam recordings in FLV files (like this one). This needs to be done on Linux without user input. How do I do this? For simplicity's sake, I'll use the same flv as both inputs in hope of getting a flv that plays the same thing twice in a row.
That should be easy enough, right? There's even a full code example in the ffmpeg FAQ.
Well, pipes seem to be giving me problems (both on my mac running Leopard and on Ubuntu 8.04) so let's keep it simple and use normal files. Also, if I don't specify a rate of 15 fps, the visual part plays extremely fast. The example script thus becomes:
ffmpeg -i input.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 \
- > temp.a < /dev/null
ffmpeg -i input.flv -an -f yuv4mpegpipe - > temp.v < /dev/null
cat temp.v temp.v > all.v
cat temp.a temp.a > all.a
ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 44100 -i all.a \
-f yuv4mpegpipe -i all.v -sameq -y output.flv
Well, using this will work for the audio, but I only get the video the first time around. This seems to be the case for any flv I throw as input.flv, including the movie teasers that come with red5.
a) Why doesn't the example script work as advertised, in particular why do I not get all the video I'm expecting?
b) Why do I have to specify a framerate while Wimpy player can play the flv at the right speed?
The only way I found to join two flvs was to use mencoder. Problem is, mencoder doesn't seem to join flvs:
mencoder input.flv input.flv -o output.flv -of lavf -oac copy \
-ovc lavc -lavcopts vcodec=flv
I get a Floating point exception...
MEncoder 1.0rc2-4.0.1 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Xeon(R) CPU 5150 # 2.66GHz (Family: 6, Model: 15, Stepping: 6)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2
success: format: 0 data: 0x0 - 0x45b2f
libavformat file format detected.
[flv # 0x697160]Unsupported audio codec (6)
[flv # 0x697160]Could not find codec parameters (Audio: 0x0006, 22050 Hz, mono)
[lavf] Video stream found, -vid 0
[lavf] Audio stream found, -aid 1
VIDEO: [FLV1] 240x180 0bpp 1000.000 fps 0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:44 fourcc:0x31564C46 size:240x180 fps:1000.00 ftime:=0.0010
** MUXER_LAVF *****************************************************************
REMEMBER: MEncoder's libavformat muxing is presently broken and can generate
INCORRECT files in the presence of B frames. Moreover, due to bugs MPlayer
will play these INCORRECT files as if nothing were wrong!
*******************************************************************************
OK, exit
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffflv] vfm: ffmpeg (FFmpeg Flash video)
==========================================================================
audiocodec: framecopy (format=6 chans=1 rate=22050 bits=16 B/s=0 sample-0)
VDec: vo config request - 240 x 180 (preferred colorspace: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
videocodec: libavcodec (240x180 fourcc=31564c46 [FLV1])
VIDEO CODEC ID: 22
AUDIO CODEC ID: 10007, TAG: 0
Writing header...
[NULL # 0x67d110]codec not compatible with flv
Floating point exception
c) Is there a way for mencoder to decode and encode flvs correctly?
So the only way I've found so far to join flvs, is to use ffmpeg to go back and forth between flv and avi, and use mencoder to join the avis:
ffmpeg -i input.flv -vcodec rawvideo -acodec pcm_s16le -r 15 file.avi
mencoder -o output.avi -oac copy -ovc copy -noskip file.avi file.avi
ffmpeg -i output.avi output.flv
d) There must be a better way to achieve this... Which one?
e) Because of the problem of the framerate, though, only flvs with constant framerate (like the one I recorded through facebook) will be converted correctly to avis, but this won't work for the flvs I seem to be recording (like this one or this one). Is there a way to do this for these flvs too?
Any help would be very appreciated.
I thought it would be a nice learning exercise to rewrite it in Ruby.
It was.
Six months later and three gems later, here's the released product.
I'll still be working a bit on it, but it works.
You'll encounter a very subtle problem here because most video and audio formats (especially in ordinary containers) use "global headers," meaning at the start of the file they have a single header which specifies compression information (like width, height, etc) for the whole file. Concatting two streams will clearly fail, as it will now have two headers instead of one and the muxer may not like this. Converting to AVI probably is resolving the issue in your case because mencoder has code to concat AVIs--that code properly handles the header issue.
After posting my question on mencoder's mailing list, trying other things, I resorted to write my own tool! I started from flvtool and after some digging in the code and writing about 40 lines of code, it works, with no loss in quality (since there is no transcoding).
I'll release it asap, in the meantime anyone interested can contact me.
dont know if this will actually work but try using this command :
cat yourVideos/*.flv >> big.flv
this will probably damage meta information so after executing that command use "flvtool" (ruby script you can find it with google) to fix it.

Resources